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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines