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 <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 |
– |
#define MEM_PTR char * |
21 |
– |
|
22 |
– |
extern MEM_PTR calloc(); |
23 |
– |
|
24 |
– |
|
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 |
< |
free((MEM_PTR)le); |
130 |
> |
} |
131 |
> |
free((void *)le); |
132 |
|
goto tryagain; /* should happen only once! */ |
133 |
|
} |
134 |
|
|
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 |
|
|
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; |