5 |
|
* Table lookup routines |
6 |
|
*/ |
7 |
|
|
8 |
– |
#include "copyright.h" |
9 |
– |
|
8 |
|
#include <stdio.h> |
9 |
|
#include <stdlib.h> |
10 |
+ |
#include <string.h> |
11 |
|
|
12 |
|
#include "lookup.h" |
13 |
|
|
14 |
+ |
extern int |
15 |
+ |
lu_strcmp( |
16 |
+ |
const void *s1, |
17 |
+ |
const void *s2 |
18 |
+ |
) |
19 |
+ |
{ |
20 |
+ |
return strcmp((const char*)s1,(const char*)s2); |
21 |
+ |
} |
22 |
|
|
23 |
< |
int |
24 |
< |
lu_init(tbl, nel) /* initialize tbl for at least nel elements */ |
25 |
< |
register LUTAB *tbl; |
26 |
< |
int nel; |
23 |
> |
extern int |
24 |
> |
lu_init( /* initialize tbl for at least nel elements */ |
25 |
> |
register LUTAB *tbl, |
26 |
> |
int nel |
27 |
> |
) |
28 |
|
{ |
29 |
|
static int hsiztab[] = { |
30 |
|
31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381, |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
< |
unsigned long |
51 |
< |
lu_shash(s) /* hash a nul-terminated string */ |
52 |
< |
char *s; |
50 |
> |
extern unsigned long |
51 |
> |
lu_shash( /* hash a nul-terminated string */ |
52 |
> |
const void *s |
53 |
> |
) |
54 |
|
{ |
55 |
|
static unsigned char shuffle[256] = { |
56 |
|
0, 157, 58, 215, 116, 17, 174, 75, 232, 133, 34, |
80 |
|
}; |
81 |
|
register int i = 0; |
82 |
|
register unsigned long h = 0; |
83 |
< |
register unsigned char *t = (unsigned char *)s; |
83 |
> |
register unsigned const char *t = (unsigned const char *)s; |
84 |
|
|
85 |
|
while (*t) |
86 |
|
h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
< |
LUENT * |
93 |
< |
lu_find(tbl, key) /* find a table entry */ |
94 |
< |
register LUTAB *tbl; |
95 |
< |
char *key; |
92 |
> |
extern LUENT * |
93 |
> |
lu_find( /* find a table entry */ |
94 |
> |
register LUTAB *tbl, |
95 |
> |
const char *key |
96 |
> |
) |
97 |
|
{ |
98 |
|
unsigned long hval; |
99 |
|
int i, n; |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
< |
void |
149 |
< |
lu_delete(tbl, key) /* delete a table entry */ |
150 |
< |
register LUTAB *tbl; |
151 |
< |
char *key; |
148 |
> |
extern void |
149 |
> |
lu_delete( /* delete a table entry */ |
150 |
> |
register LUTAB *tbl, |
151 |
> |
const char *key |
152 |
> |
) |
153 |
|
{ |
154 |
|
register LUENT *le; |
155 |
|
|
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
< |
int |
168 |
< |
lu_doall(tbl, f) /* loop through all valid table entries */ |
169 |
< |
register LUTAB *tbl; |
170 |
< |
int (*f)(); |
167 |
> |
extern int |
168 |
> |
lu_doall( /* loop through all valid table entries */ |
169 |
> |
register const LUTAB *tbl, |
170 |
> |
//int (*f)(const LUENT *) |
171 |
> |
lut_doallf_t *f, |
172 |
> |
void *p |
173 |
> |
) |
174 |
|
{ |
175 |
|
int rval = 0; |
176 |
< |
register LUENT *tp; |
176 |
> |
register const LUENT *tp; |
177 |
|
|
178 |
|
for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; ) |
179 |
|
if (tp->data != NULL) { |
180 |
< |
if (f != NULL) |
181 |
< |
rval += (*f)(tp); |
182 |
< |
else |
180 |
> |
if (f != NULL) { |
181 |
> |
int r = (*f)(tp, p); |
182 |
> |
if (r < 0) |
183 |
> |
return(-1); |
184 |
> |
rval += r; |
185 |
> |
} else |
186 |
|
rval++; |
187 |
|
} |
188 |
|
return(rval); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
< |
void |
193 |
< |
lu_done(tbl) /* free table and contents */ |
194 |
< |
register LUTAB *tbl; |
192 |
> |
extern void |
193 |
> |
lu_done( /* free table and contents */ |
194 |
> |
register LUTAB *tbl |
195 |
> |
) |
196 |
|
{ |
197 |
|
register LUENT *tp; |
198 |
|
|