1 /*
2 * Copyright (c) 1983, 1995 Eric P. Allman
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * %sccs.include.redist.c%
7 */
8
9 #ifndef lint
10 static char sccsid[] = "@(#)stab.c 8.2 (Berkeley) 04/21/95";
11 #endif /* not lint */
12
13 # include "sendmail.h"
14
15 /*
16 ** STAB -- manage the symbol table
17 **
18 ** Parameters:
19 ** name -- the name to be looked up or inserted.
20 ** type -- the type of symbol.
21 ** op -- what to do:
22 ** ST_ENTER -- enter the name if not
23 ** already present.
24 ** ST_FIND -- find it only.
25 **
26 ** Returns:
27 ** pointer to a STAB entry for this name.
28 ** NULL if not found and not entered.
29 **
30 ** Side Effects:
31 ** can update the symbol table.
32 */
33
34 # define STABSIZE 400
35
36 static STAB *SymTab[STABSIZE];
37
38 STAB *
stab(name,type,op)39 stab(name, type, op)
40 char *name;
41 int type;
42 int op;
43 {
44 register STAB *s;
45 register STAB **ps;
46 register int hfunc;
47 register char *p;
48 extern char lower();
49
50 if (tTd(36, 5))
51 printf("STAB: %s %d ", name, type);
52
53 /*
54 ** Compute the hashing function
55 **
56 ** We could probably do better....
57 */
58
59 hfunc = type;
60 for (p = name; *p != '\0'; p++)
61 hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
62
63 if (tTd(36, 9))
64 printf("(hfunc=%d) ", hfunc);
65
66 ps = &SymTab[hfunc];
67 while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type))
68 ps = &s->s_next;
69
70 /*
71 ** Dispose of the entry.
72 */
73
74 if (s != NULL || op == ST_FIND)
75 {
76 if (tTd(36, 5))
77 {
78 if (s == NULL)
79 printf("not found\n");
80 else
81 {
82 long *lp = (long *) s->s_class;
83
84 printf("type %d val %lx %lx %lx %lx\n",
85 s->s_type, lp[0], lp[1], lp[2], lp[3]);
86 }
87 }
88 return (s);
89 }
90
91 /*
92 ** Make a new entry and link it in.
93 */
94
95 if (tTd(36, 5))
96 printf("entered\n");
97
98 /* make new entry */
99 s = (STAB *) xalloc(sizeof *s);
100 bzero((char *) s, sizeof *s);
101 s->s_name = newstr(name);
102 makelower(s->s_name);
103 s->s_type = type;
104
105 /* link it in */
106 *ps = s;
107
108 return (s);
109 }
110 /*
111 ** STABAPPLY -- apply function to all stab entries
112 **
113 ** Parameters:
114 ** func -- the function to apply. It will be given one
115 ** parameter (the stab entry).
116 ** arg -- an arbitrary argument, passed to func.
117 **
118 ** Returns:
119 ** none.
120 */
121
122 void
123 stabapply(func, arg)
124 void (*func)__P((STAB *, int));
125 int arg;
126 {
127 register STAB **shead;
128 register STAB *s;
129
130 for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++)
131 {
132 for (s = *shead; s != NULL; s = s->s_next)
133 {
134 if (tTd(38, 90))
135 printf("stabapply: trying %d/%s\n",
136 s->s_type, s->s_name);
137 func(s, arg);
138 }
139 }
140 }
141