1 |
– |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Table lookup routines |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <stdlib.h> |
10 |
+ |
|
11 |
|
#include "lookup.h" |
12 |
|
|
14 |
– |
#ifndef MEM_PTR |
15 |
– |
#define MEM_PTR void * |
16 |
– |
#endif |
13 |
|
|
18 |
– |
extern MEM_PTR calloc(); |
19 |
– |
|
20 |
– |
|
14 |
|
int |
15 |
|
lu_init(tbl, nel) /* initialize tbl for at least nel elements */ |
16 |
|
register LUTAB *tbl; |
72 |
|
register unsigned char *t = (unsigned char *)s; |
73 |
|
|
74 |
|
while (*t) |
75 |
< |
h ^= (long)shuffle[*t++] << ((i+=11) & 0xf); |
75 |
> |
h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf); |
76 |
|
|
77 |
|
return(h); |
78 |
|
} |
122 |
|
* recursive call to lu_find(). |
123 |
|
*/ |
124 |
|
while (ndx--) |
125 |
< |
if (le[ndx].key != NULL) |
125 |
> |
if (le[ndx].key != NULL) { |
126 |
|
if (le[ndx].data != NULL) |
127 |
< |
*lu_find(tbl, le[ndx].key) = le[ndx]; |
127 |
> |
*lu_find(tbl,le[ndx].key) = le[ndx]; |
128 |
|
else if (tbl->freek != NULL) |
129 |
|
(*tbl->freek)(le[ndx].key); |
130 |
< |
free((MEM_PTR)le); |
130 |
> |
} |
131 |
> |
free((void *)le); |
132 |
|
goto tryagain; /* should happen only once! */ |
133 |
|
} |
134 |
|
|
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
+ |
int |
155 |
+ |
lu_doall(tbl, f) /* loop through all valid table entries */ |
156 |
+ |
register LUTAB *tbl; |
157 |
+ |
int (*f)(LUENT *); |
158 |
+ |
{ |
159 |
+ |
int rval = 0; |
160 |
+ |
register LUENT *tp; |
161 |
+ |
|
162 |
+ |
for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; ) |
163 |
+ |
if (tp->data != NULL) { |
164 |
+ |
if (f != NULL) |
165 |
+ |
rval += (*f)(tp); |
166 |
+ |
else |
167 |
+ |
rval++; |
168 |
+ |
} |
169 |
+ |
return(rval); |
170 |
+ |
} |
171 |
+ |
|
172 |
+ |
|
173 |
|
void |
174 |
|
lu_done(tbl) /* free table and contents */ |
175 |
|
register LUTAB *tbl; |
185 |
|
if (tp->data != NULL && tbl->freed != NULL) |
186 |
|
(*tbl->freed)(tp->data); |
187 |
|
} |
188 |
< |
free((MEM_PTR)tbl->tabl); |
188 |
> |
free((void *)tbl->tabl); |
189 |
|
tbl->tabl = NULL; |
190 |
|
tbl->tsiz = 0; |
191 |
|
tbl->ndel = 0; |