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