1 /* $Id: symtab.c,v 1.9 2006-05-10 08:13:22 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
34 struct strentry *next;
40 struct strentry *ar[STR_HASH];
43 struct strtab *strtab_mk (void)
46 struct strtab *p = (struct strtab *) xmalloc (sizeof (*p));
47 for (i=0; i<STR_HASH; i++)
52 int strtab_src (struct strtab *t, const char *name, void ***infop)
58 for (i=0; name[i]; i++)
59 hash += hash*65519 + name[i];
60 hash = hash % STR_HASH;
61 for (e = t->ar[hash]; e; e = e->next)
62 if (!strcmp(e->name, name))
67 e = (struct strentry *) xmalloc (sizeof(*e));
68 e->name = (char *) xmalloc (strlen(name)+1);
69 strcpy (e->name, name);
70 e->next = t->ar[hash];
76 void strtab_del (struct strtab *t,
77 void (*func)(const char *name, void *info, void *data),
81 struct strentry *e, *e1;
83 for (i = 0; i<STR_HASH; i++)
84 for (e = t->ar[i]; e; e = e1)
87 (*func)(e->name, e->info, data);
96 * indent-tabs-mode: nil
98 * vim: shiftwidth=4 tabstop=8 expandtab