ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/lookup.c
(Generate patch)

Comparing ray/src/common/lookup.c (file contents):
Revision 2.5 by gwlarson, Thu Sep 3 14:22:23 1998 UTC vs.
Revision 2.16 by schorsch, Wed Jun 7 17:52:03 2006 UTC

# Line 1 | Line 1
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 + #include <string.h>
11 +
12   #include "lookup.h"
13  
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
14 > extern int
15 > lu_strcmp(
16 >        const void *s1,
17 >        const void *s2
18 > )
19 > {
20 >        return strcmp((const char*)s1,(const char*)s2);
21 > }
22  
23 < #define MEM_PTR         char *
24 <
25 < extern MEM_PTR  calloc();
26 <
27 <
25 < int
26 < lu_init(tbl, nel)               /* initialize tbl for at least nel elements */
27 < register LUTAB  *tbl;
28 < int     nel;
23 > extern int
24 > lu_init(                /* initialize tbl for at least nel elements */
25 >        register LUTAB  *tbl,
26 >        int     nel
27 > )
28   {
29          static int  hsiztab[] = {
30                  31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
# Line 48 | Line 47 | int    nel;
47   }
48  
49  
50 < unsigned long
51 < lu_shash(s)                     /* hash a nul-terminated string */
52 < char    *s;
50 > extern unsigned long
51 > lu_shash(                       /* hash a nul-terminated string */
52 >        const void      *s
53 > )
54   {
55          static unsigned char shuffle[256] = {
56                  0, 157, 58, 215, 116, 17, 174, 75, 232, 133, 34,
# Line 80 | Line 80 | char   *s;
80          };
81          register int    i = 0;
82          register unsigned long  h = 0;
83 <        register unsigned char *t = (unsigned char *)s;
83 >        register unsigned const char *t = (unsigned const char *)s;
84  
85          while (*t)
86                  h ^= (unsigned long)shuffle[*t++] << ((i+=11) & 0xf);
# Line 89 | Line 89 | char   *s;
89   }
90  
91  
92 < LUENT *
93 < lu_find(tbl, key)               /* find a table entry */
94 < register LUTAB  *tbl;
95 < char    *key;
92 > extern LUENT *
93 > lu_find(                /* find a table entry */
94 >        register LUTAB  *tbl,
95 >        const char      *key
96 > )
97   {
98          unsigned long   hval;
99          int     i, n;
# Line 133 | Line 134 | tryagain:
134           * recursive call to lu_find().
135           */
136          while (ndx--)
137 <                if (le[ndx].key != NULL)
137 >                if (le[ndx].key != NULL) {
138                          if (le[ndx].data != NULL)
139 <                                copystruct(lu_find(tbl,le[ndx].key), &le[ndx]);
139 >                                *lu_find(tbl,le[ndx].key) = le[ndx];
140                          else if (tbl->freek != NULL)
141                                  (*tbl->freek)(le[ndx].key);
142 <        free((MEM_PTR)le);
142 >                }
143 >        free((void *)le);
144          goto tryagain;                  /* should happen only once! */
145   }
146  
147  
148 < void
149 < lu_delete(tbl, key)             /* delete a table entry */
150 < register LUTAB  *tbl;
151 < char    *key;
148 > extern void
149 > lu_delete(              /* delete a table entry */
150 >        register LUTAB  *tbl,
151 >        const char      *key
152 > )
153   {
154          register LUENT  *le;
155  
# Line 161 | Line 164 | char   *key;
164   }
165  
166  
167 < int
168 < lu_doall(tbl, f)                /* loop through all valid table entries */
169 < register LUTAB  *tbl;
170 < int     (*f)();
167 > extern int
168 > lu_doall(               /* loop through all valid table entries */
169 >        register const LUTAB    *tbl,
170 >        //int   (*f)(const LUENT *)
171 >        lut_doallf_t *f,
172 >        void *p
173 > )
174   {
175          int     rval = 0;
176 <        register LUENT  *tp;
176 >        register const LUENT    *tp;
177  
178          for (tp = tbl->tabl + tbl->tsiz; tp-- > tbl->tabl; )
179 <                if (tp->data != NULL)
180 <                        if (f != NULL)
181 <                                rval += (*f)(tp);
182 <                        else
179 >                if (tp->data != NULL) {
180 >                        if (f != NULL) {
181 >                                int     r = (*f)(tp, p);
182 >                                if (r < 0)
183 >                                        return(-1);
184 >                                rval += r;
185 >                        } else
186                                  rval++;
187 +                }
188          return(rval);
189   }
190  
191  
192 < void
193 < lu_done(tbl)                    /* free table and contents */
194 < register LUTAB  *tbl;
192 > extern void
193 > lu_done(                        /* free table and contents */
194 >        register LUTAB  *tbl
195 > )
196   {
197          register LUENT  *tp;
198  
# Line 194 | Line 205 | register LUTAB *tbl;
205                          if (tp->data != NULL && tbl->freed != NULL)
206                                  (*tbl->freed)(tp->data);
207                  }
208 <        free((MEM_PTR)tbl->tabl);
208 >        free((void *)tbl->tabl);
209          tbl->tabl = NULL;
210          tbl->tsiz = 0;
211          tbl->ndel = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines