Add sdpd(8) (Bluetooth Service Discovery Protocol daemon) and sdpquery(1)
[dragonfly.git] / usr.bin / doscmd / dispatch.h
blob45b1a97f0d17ef671a1d6a3b600ae2cef564e40c
1 /*
2 ** Copyright (c) 1996
3 ** Michael Smith. All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY Michael Smith ``AS IS'' AND
15 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL Michael Smith BE LIABLE
18 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 ** SUCH DAMAGE.
26 ** $FreeBSD: src/usr.bin/doscmd/dispatch.h,v 1.2.2.1 2001/08/02 02:17:15 obrien Exp $
27 ** $DragonFly: src/usr.bin/doscmd/dispatch.h,v 1.2 2003/06/17 04:29:25 dillon Exp $
31 ** Interrupt dispatcher assistants.
36 ** Declare a static, initialised array of these, with one
37 ** entry per function/subfunction.
39 ** The last element should be a dummy with a 'func' of -1
41 struct intfunc_table
43 int func; /* interrupt function number */
44 int subfunc; /* subfunction number */
45 int (* handler)(regcontext_t *REGS);/* handling function */
46 const char *desc; /* textual description */
48 #define IFT_NOSUBFUNC -1
52 ** Declare a static array of 256 integers to use as a fast lookup
53 ** into the table of handlers.
55 ** Call this function to initialise the lookup. Note that the table
56 ** must be arranged with all handlers for a given function together, and
57 ** that the handler listed with IFT_NOSUBFUNC should be last.
59 static inline void
60 intfunc_init(struct intfunc_table table[], int idx[])
62 int hn;
64 for (hn = 0; hn < 256; hn++) /* initialise all no-handler state */
65 idx[hn] = -1; /* default to no handler */
67 for (hn = 0; table[hn].func >= 0; hn++) /* walk list of handlers and add references */
68 if (idx[table[hn].func] == -1 ) /* reference first handler */
69 idx[table[hn].func] = hn;
73 ** Call this to get an index matching the function/subfunction
74 ** described by (sc), or -1 if none exist
76 static inline int
77 intfunc_find(struct intfunc_table table[], int idx[], int func, int subfunc)
79 int ent = idx[func]; /* look for handler */
81 while ((ent >= 0) && /* scan entries for function */
82 (table[ent].func == func)) {
84 if ((table[ent].subfunc == IFT_NOSUBFUNC) || /* handles all */
85 (table[ent].subfunc == subfunc)) { /* handles this one */
86 return(ent);
88 ent++;
90 return(-1);
94 ** A slower lookup for a set of function handlers, but one that requires
95 ** no initialisation calls.
96 ** Again, handlers with IFT_NOSUBFUNC should be listed after any with
97 ** specific subfunction values.
99 static inline int
100 intfunc_search(struct intfunc_table table[], int func, int subfunc)
102 int ent;
104 for (ent = 0; table[ent].func >= 0; ent++)
105 if ((table[ent].func == func) && /* matches required function */
106 ((table[ent].subfunc == IFT_NOSUBFUNC) || table[ent].subfunc == subfunc))
107 return(ent);
108 return(-1);