/[radius]/radius/lib/symtab.c
ViewVC logotype

Diff of /radius/lib/symtab.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by gray, Fri Aug 2 11:18:43 2002 UTC revision 1.4 by gray, Wed Apr 30 08:38:29 2003 UTC
# Line 1  Line 1 
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
# Line 51  static unsigned int hashval(unsigned cha Line 46  static unsigned int hashval(unsigned cha
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                    
# Line 67  symtab_create(esize, elfree) Line 60  symtab_create(esize, elfree)
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    
# Line 81  hashval(s, bias) Line 72  hashval(s, bias)
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]) {
# Line 97  _sym_add(symtab, h, sp) Line 85  _sym_add(symtab, h, sp)
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;
# Line 134  symtab_rehash(symtab) Line 121  symtab_rehash(symtab)
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;
# Line 159  sym_lookup_or_install(symtab, name, inst Line 143  sym_lookup_or_install(symtab, name, inst
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;
# Line 179  sym_install(symtab, name) Line 161  sym_install(symtab, name)
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) {
# Line 199  sym_next(sym) Line 178  sym_next(sym)
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);
# Line 213  alloc_sym(s, size) Line 190  alloc_sym(s, 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;
# Line 260  symtab_delete(symtab, sym) Line 235  symtab_delete(symtab, sym)
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;
# Line 290  symtab_clear(symtab) Line 263  symtab_clear(symtab)
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);
# Line 300  symtab_free(symtab) Line 272  symtab_free(symtab)
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;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26