3 ** Michael Smith. All rights reserved.
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
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
26 ** $FreeBSD: src/usr.bin/doscmd/dispatch.h,v 1.2.2.1 2001/08/02 02:17:15 obrien Exp $
30 ** Interrupt dispatcher assistants.
35 ** Declare a static, initialised array of these, with one
36 ** entry per function/subfunction.
38 ** The last element should be a dummy with a 'func' of -1
42 int func; /* interrupt function number */
43 int subfunc; /* subfunction number */
44 int (* handler)(regcontext_t *REGS);/* handling function */
45 const char *desc; /* textual description */
47 #define IFT_NOSUBFUNC -1
51 ** Declare a static array of 256 integers to use as a fast lookup
52 ** into the table of handlers.
54 ** Call this function to initialise the lookup. Note that the table
55 ** must be arranged with all handlers for a given function together, and
56 ** that the handler listed with IFT_NOSUBFUNC should be last.
59 intfunc_init(struct intfunc_table table[], int idx[])
63 for (hn = 0; hn < 256; hn++) /* initialise all no-handler state */
64 idx[hn] = -1; /* default to no handler */
66 for (hn = 0; table[hn].func >= 0; hn++) /* walk list of handlers and add references */
67 if (idx[table[hn].func] == -1 ) /* reference first handler */
68 idx[table[hn].func] = hn;
72 ** Call this to get an index matching the function/subfunction
73 ** described by (sc), or -1 if none exist
76 intfunc_find(struct intfunc_table table[], int idx[], int func, int subfunc)
78 int ent = idx[func]; /* look for handler */
80 while ((ent >= 0) && /* scan entries for function */
81 (table[ent].func == func)) {
83 if ((table[ent].subfunc == IFT_NOSUBFUNC) || /* handles all */
84 (table[ent].subfunc == subfunc)) { /* handles this one */
93 ** A slower lookup for a set of function handlers, but one that requires
94 ** no initialisation calls.
95 ** Again, handlers with IFT_NOSUBFUNC should be listed after any with
96 ** specific subfunction values.
99 intfunc_search(struct intfunc_table table[], int func, int subfunc)
103 for (ent = 0; table[ent].func >= 0; ent++)
104 if ((table[ent].func == func) && /* matches required function */
105 ((table[ent].subfunc == IFT_NOSUBFUNC) || table[ent].subfunc == subfunc))