| 1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Table lookup routines |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
+ |
#include "copyright.h" |
| 9 |
+ |
|
| 10 |
|
#include <stdio.h> |
| 11 |
+ |
#include <stdlib.h> |
| 12 |
+ |
|
| 13 |
|
#include "lookup.h" |
| 14 |
|
|
| 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 |
| 15 |
|
|
| 20 |
– |
#define MEM_PTR char * |
| 21 |
– |
|
| 22 |
– |
extern MEM_PTR calloc(); |
| 23 |
– |
|
| 24 |
– |
|
| 16 |
|
int |
| 17 |
|
lu_init(tbl, nel) /* initialize tbl for at least nel elements */ |
| 18 |
|
register LUTAB *tbl; |
| 124 |
|
* recursive call to lu_find(). |
| 125 |
|
*/ |
| 126 |
|
while (ndx--) |
| 127 |
< |
if (le[ndx].key != NULL) |
| 127 |
> |
if (le[ndx].key != NULL) { |
| 128 |
|
if (le[ndx].data != NULL) |
| 129 |
< |
copystruct(lu_find(tbl,le[ndx].key), &le[ndx]); |
| 129 |
> |
*lu_find(tbl,le[ndx].key) = le[ndx]; |
| 130 |
|
else if (tbl->freek != NULL) |
| 131 |
|
(*tbl->freek)(le[ndx].key); |
| 132 |
< |
free((MEM_PTR)le); |
| 132 |
> |
} |
| 133 |
> |
free((void *)le); |
| 134 |
|
goto tryagain; /* should happen only once! */ |
| 135 |
|
} |
| 136 |
|
|
| 156 |
|
int |
| 157 |
|
lu_doall(tbl, f) /* loop through all valid table entries */ |
| 158 |
|
register LUTAB *tbl; |
| 159 |
< |
int (*f)(); |
| 159 |
> |
int (*f)(LUENT *); |
| 160 |
|
{ |
| 161 |
|
int rval = 0; |
| 162 |
|
register LUENT *tp; |
| 163 |
|
|
| 164 |
|
for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; ) |
| 165 |
< |
if (tp->data != NULL) |
| 165 |
> |
if (tp->data != NULL) { |
| 166 |
|
if (f != NULL) |
| 167 |
|
rval += (*f)(tp); |
| 168 |
|
else |
| 169 |
|
rval++; |
| 170 |
+ |
} |
| 171 |
|
return(rval); |
| 172 |
|
} |
| 173 |
|
|
| 187 |
|
if (tp->data != NULL && tbl->freed != NULL) |
| 188 |
|
(*tbl->freed)(tp->data); |
| 189 |
|
} |
| 190 |
< |
free((MEM_PTR)tbl->tabl); |
| 190 |
> |
free((void *)tbl->tabl); |
| 191 |
|
tbl->tabl = NULL; |
| 192 |
|
tbl->tsiz = 0; |
| 193 |
|
tbl->ndel = 0; |