1 |
/* This file is part of GNU RADIUS. |
/* This file is part of GNU Radius. |
2 |
Copyright (C) 2000,2001, Sergey Poznyakoff |
Copyright (C) 2000,2001,2002,2003 Sergey Poznyakoff |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Radius is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
7 |
(at your option) any later version. |
(at your option) any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Radius is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software Foundation, |
along with GNU Radius; if not, write to the Free Software Foundation, |
16 |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
|
#ifndef lint |
|
|
static char rcsid[] = |
|
|
"@(#) $Id$"; |
|
|
#endif |
|
|
|
|
18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
19 |
# include <config.h> |
# include <config.h> |
20 |
#endif |
#endif |
46 |
static void _sym_add(Symtab *symtab, unsigned h, Symbol *sp); |
static void _sym_add(Symtab *symtab, unsigned h, Symbol *sp); |
47 |
|
|
48 |
Symtab * |
Symtab * |
49 |
symtab_create(esize, elfree) |
symtab_create(unsigned esize, int (*elfree)()) |
|
unsigned esize; |
|
|
int (*elfree)(); |
|
50 |
{ |
{ |
51 |
Symtab *symtab; |
Symtab *symtab; |
52 |
|
|
60 |
} |
} |
61 |
|
|
62 |
unsigned int |
unsigned int |
63 |
hashval(s, bias) |
hashval(unsigned char *s, unsigned bias) |
|
unsigned char *s; |
|
|
unsigned bias; |
|
64 |
{ |
{ |
65 |
unsigned h = 0; |
unsigned h = 0; |
66 |
|
|
72 |
} |
} |
73 |
|
|
74 |
void |
void |
75 |
_sym_add(symtab, h, sp) |
_sym_add(Symtab *symtab, unsigned h, Symbol *sp) |
|
Symtab *symtab; |
|
|
unsigned h; |
|
|
Symbol *sp; |
|
76 |
{ |
{ |
77 |
sp->next = NULL; |
sp->next = NULL; |
78 |
if (symtab->sym[h]) { |
if (symtab->sym[h]) { |
85 |
} |
} |
86 |
|
|
87 |
int |
int |
88 |
symtab_rehash(symtab) |
symtab_rehash(Symtab *symtab) |
|
Symtab *symtab; |
|
89 |
{ |
{ |
90 |
Symbol **old_table = symtab->sym; |
Symbol **old_table = symtab->sym; |
91 |
int i; |
int i; |
121 |
} |
} |
122 |
|
|
123 |
void * |
void * |
124 |
sym_lookup_or_install(symtab, name, install) |
sym_lookup_or_install(Symtab *symtab, char *name, int install) |
|
Symtab *symtab; |
|
|
char *name; |
|
|
int install; |
|
125 |
{ |
{ |
126 |
if (symtab->sym) { |
if (symtab->sym) { |
127 |
Symbol *sp; |
Symbol *sp; |
143 |
} |
} |
144 |
|
|
145 |
void * |
void * |
146 |
sym_install(symtab, name) |
sym_install(Symtab *symtab, char *name) |
|
Symtab *symtab; |
|
|
char *name; |
|
147 |
{ |
{ |
148 |
Symbol *sp; |
Symbol *sp; |
149 |
unsigned int h; |
unsigned int h; |
161 |
} |
} |
162 |
|
|
163 |
void * |
void * |
164 |
sym_lookup(symtab, name) |
sym_lookup(Symtab *symtab, char *name) |
|
Symtab *symtab; |
|
|
char *name; |
|
165 |
{ |
{ |
166 |
return sym_lookup_or_install(symtab, name, 0); |
return sym_lookup_or_install(symtab, name, 0); |
167 |
} |
} |
168 |
|
|
169 |
void * |
void * |
170 |
sym_next(sym) |
sym_next(Symbol *sym) |
|
Symbol *sym; |
|
171 |
{ |
{ |
172 |
char *name = sym->name; |
char *name = sym->name; |
173 |
for (sym = sym->next; sym; sym = sym->next) { |
for (sym = sym->next; sym; sym = sym->next) { |
178 |
} |
} |
179 |
|
|
180 |
Symbol * |
Symbol * |
181 |
alloc_sym(s, size) |
alloc_sym(char *s, unsigned size) |
|
char *s; |
|
|
unsigned size; |
|
182 |
{ |
{ |
183 |
Symbol *ptr; |
Symbol *ptr; |
184 |
ptr = mem_alloc(size); |
ptr = mem_alloc(size); |
190 |
* Delete the symbol `sym' from symtab. |
* Delete the symbol `sym' from symtab. |
191 |
*/ |
*/ |
192 |
int |
int |
193 |
symtab_delete(symtab, sym) |
symtab_delete(Symtab *symtab, Symbol *sym) |
|
Symtab *symtab; |
|
|
Symbol *sym; |
|
194 |
{ |
{ |
195 |
Symbol *sp, *prev; |
Symbol *sp, *prev; |
196 |
unsigned h; |
unsigned h; |
235 |
} |
} |
236 |
|
|
237 |
void |
void |
238 |
sym_free(sp) |
sym_free(Symbol *sp) |
|
Symbol *sp; |
|
239 |
{ |
{ |
240 |
efree(sp->name); |
efree(sp->name); |
241 |
mem_free(sp); |
mem_free(sp); |
242 |
} |
} |
243 |
|
|
244 |
void |
void |
245 |
symtab_clear(symtab) |
symtab_clear(Symtab *symtab) |
|
Symtab *symtab; |
|
246 |
{ |
{ |
247 |
int i; |
int i; |
248 |
Symbol *sp, *next; |
Symbol *sp, *next; |
263 |
} |
} |
264 |
|
|
265 |
void |
void |
266 |
symtab_free(symtab) |
symtab_free(Symtab **symtab) |
|
Symtab **symtab; |
|
267 |
{ |
{ |
268 |
symtab_clear(*symtab); |
symtab_clear(*symtab); |
269 |
efree((*symtab)->sym); |
efree((*symtab)->sym); |
272 |
} |
} |
273 |
|
|
274 |
void |
void |
275 |
symtab_iterate(symtab, fn, closure) |
symtab_iterate(Symtab *symtab, int (*fn)(), void *closure) |
|
Symtab *symtab; |
|
|
int (*fn)(); |
|
|
void *closure; |
|
276 |
{ |
{ |
277 |
int i; |
int i; |
278 |
Symbol *sym, *next; |
Symbol *sym, *next; |