--- ray/src/common/lookup.c 2003/07/21 22:30:17 2.10 +++ ray/src/common/lookup.c 2014/02/09 00:08:18 2.19 @@ -1,29 +1,29 @@ #ifndef lint -static const char RCSid[] = "$Id: lookup.c,v 2.10 2003/07/21 22:30:17 schorsch Exp $"; +static const char RCSid[] = "$Id: lookup.c,v 2.19 2014/02/09 00:08:18 greg Exp $"; #endif /* * Table lookup routines */ -#include "copyright.h" - #include #include +#include #include "lookup.h" int -lu_init(tbl, nel) /* initialize tbl for at least nel elements */ -register LUTAB *tbl; -int nel; +lu_init( /* initialize tbl for at least nel elements */ + LUTAB *tbl, + int nel +) { static int hsiztab[] = { 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381, 32749, 65521, 131071, 262139, 524287, 1048573, 2097143, 4194301, 8388593, 0 }; - register int *hsp; + int *hsp; nel += nel>>1; /* 66% occupancy */ for (hsp = hsiztab; *hsp; hsp++) @@ -40,8 +40,9 @@ int nel; unsigned long -lu_shash(s) /* hash a nul-terminated string */ -char *s; +lu_shash( /* hash a nul-terminated string */ + const char *s +) { static unsigned char shuffle[256] = { 0, 157, 58, 215, 116, 17, 174, 75, 232, 133, 34, @@ -69,9 +70,9 @@ char *s; 106, 7, 164, 65, 222, 123, 24, 181, 82, 239, 140, 41, 198, 99 }; - register int i = 0; - register unsigned long h = 0; - register unsigned char *t = (unsigned char *)s; + int i = 0; + unsigned long h = 0; + unsigned const char *t = (unsigned const char *)s; while (*t) h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf); @@ -81,14 +82,15 @@ char *s; LUENT * -lu_find(tbl, key) /* find a table entry */ -register LUTAB *tbl; -char *key; +lu_find( /* find a table entry */ + LUTAB *tbl, + const char *key +) { unsigned long hval; int i, n; - register int ndx; - register LUENT *le; + int ndx; + LUENT *le; /* look up object */ if (tbl->tsiz == 0 && !lu_init(tbl, 1)) return(NULL); @@ -136,11 +138,12 @@ tryagain: void -lu_delete(tbl, key) /* delete a table entry */ -register LUTAB *tbl; -char *key; +lu_delete( /* delete a table entry */ + LUTAB *tbl, + const char *key +) { - register LUENT *le; + LUENT *le; if ((le = lu_find(tbl, key)) == NULL) return; @@ -154,18 +157,24 @@ char *key; int -lu_doall(tbl, f) /* loop through all valid table entries */ -register LUTAB *tbl; -int (*f)(); +lu_doall( /* loop through all valid table entries */ + const LUTAB *tbl, + /* int (*f)(const LUENT *, void *) */ + lut_doallf_t *f, + void *p +) { int rval = 0; - register LUENT *tp; + const LUENT *tp; for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; ) if (tp->data != NULL) { - if (f != NULL) - rval += (*f)(tp); - else + if (f != NULL) { + int r = (*f)(tp, p); + if (r < 0) + return(-1); + rval += r; + } else rval++; } return(rval); @@ -173,10 +182,11 @@ int (*f)(); void -lu_done(tbl) /* free table and contents */ -register LUTAB *tbl; +lu_done( /* free table and contents */ + LUTAB *tbl +) { - register LUENT *tp; + LUENT *tp; if (!tbl->tsiz) return;