| 5 |
|
* Table lookup routines |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
– |
#include "copyright.h" |
| 9 |
– |
|
| 8 |
|
#include <stdio.h> |
| 9 |
|
#include <stdlib.h> |
| 10 |
+ |
|
| 11 |
|
#include "lookup.h" |
| 12 |
|
|
| 14 |
– |
#ifdef NOSTRUCTASS |
| 15 |
– |
#define copystruct(d,s) bcopy((char *)(s),(char *)(d),sizeof(*(d))) |
| 16 |
– |
#else |
| 17 |
– |
#define copystruct(d,s) (*(d) = *(s)) |
| 18 |
– |
#endif |
| 13 |
|
|
| 20 |
– |
|
| 14 |
|
int |
| 15 |
|
lu_init(tbl, nel) /* initialize tbl for at least nel elements */ |
| 16 |
|
register LUTAB *tbl; |
| 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 |
< |
copystruct(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 |
+ |
} |
| 131 |
|
free((void *)le); |
| 132 |
|
goto tryagain; /* should happen only once! */ |
| 133 |
|
} |
| 154 |
|
int |
| 155 |
|
lu_doall(tbl, f) /* loop through all valid table entries */ |
| 156 |
|
register LUTAB *tbl; |
| 157 |
< |
int (*f)(); |
| 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) |
| 163 |
> |
if (tp->data != NULL) { |
| 164 |
|
if (f != NULL) |
| 165 |
|
rval += (*f)(tp); |
| 166 |
|
else |
| 167 |
|
rval++; |
| 168 |
+ |
} |
| 169 |
|
return(rval); |
| 170 |
|
} |
| 171 |
|
|