*** empty log message ***
[arla.git] / ydr / symbol.c
blobb58f57725fdcea872bd51652c5efee16b5474da0
1 /*
2 * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 RCSID("$Id$");
37 #endif
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include "sym.h"
43 #include <hash.h>
44 #include <roken.h>
46 static Hashtab *hashtab;
48 static int
49 symcmp (void *a, void *b)
51 Symbol *sa = (Symbol *)a;
52 Symbol *sb = (Symbol *)b;
54 return strcmp (sa->name, sb->name);
57 static unsigned
58 symhash (void *a)
60 Symbol *sa = (Symbol *)a;
62 return hashadd (sa->name);
65 #define HASHTABSIZE 149
67 void
68 initsym (void)
70 hashtab = hashtabnew (HASHTABSIZE, symcmp, symhash);
73 Symbol *
74 addsym (char *name)
76 Symbol tmp;
77 Symbol *sym;
79 tmp.name = name;
80 sym = (Symbol *)hashtabsearch (hashtab, (void *)&tmp);
81 if (sym == NULL) {
82 sym = (Symbol *)emalloc (sizeof (Symbol));
83 sym->name = name;
84 sym->type = YDR_TUNDEFINED;
85 sym->attrs = NULL;
86 hashtabadd (hashtab, sym);
88 return sym;
91 Symbol *
92 findsym (char *name)
94 Symbol tmp;
96 tmp.name = name;
97 return (Symbol *)hashtabsearch (hashtab, (void *)&tmp);
100 static Bool __attribute__ ((unused))
101 printsymbol (void *ptr, void *arg)
103 Symbol *s = (Symbol *)ptr;
105 switch (s->type) {
106 case YDR_TUNDEFINED :
107 printf ("undefined ");
108 break;
109 case YDR_TSTRUCT :
110 printf ("struct ");
111 break;
112 case YDR_TENUM :
113 printf ("enum ");
114 break;
115 case YDR_TENUMVAL :
116 printf ("enumval ");
117 break;
118 case YDR_TCONST :
119 printf ("const ");
120 break;
121 case YDR_TTYPEDEF :
122 printf ("typedef ");
123 break;
124 default :
125 abort ();
127 puts (s->name);
129 return FALSE;
132 void
133 symiterate (Bool (*func)(void *, void *), void *arg)
135 hashtabforeach (hashtab, func, arg);