1: # include "sendmail.h"
2:
3: SCCSID(@(#)stab.c 4.1 7/25/83);
4:
5: /*
6: ** STAB -- manage the symbol table
7: **
8: ** Parameters:
9: ** name -- the name to be looked up or inserted.
10: ** type -- the type of symbol.
11: ** op -- what to do:
12: ** ST_ENTER -- enter the name if not
13: ** already present.
14: ** ST_FIND -- find it only.
15: **
16: ** Returns:
17: ** pointer to a STAB entry for this name.
18: ** NULL if not found and not entered.
19: **
20: ** Side Effects:
21: ** can update the symbol table.
22: */
23:
24: # define STABSIZE 400
25:
26: static STAB *SymTab[STABSIZE];
27:
28: STAB *
29: stab(name, type, op)
30: char *name;
31: int type;
32: int op;
33: {
34: register STAB *s;
35: register STAB **ps;
36: extern bool sameword();
37: register int hfunc;
38: register char *p;
39: extern char lower();
40:
41: # ifdef DEBUG
42: if (tTd(36, 5))
43: printf("STAB: %s %d ", name, type);
44: # endif DEBUG
45:
46: /*
47: ** Compute the hashing function
48: **
49: ** We could probably do better....
50: */
51:
52: hfunc = type;
53: for (p = name; *p != '\0'; p++)
54: hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
55:
56: # ifdef DEBUG
57: if (tTd(36, 9))
58: printf("(hfunc=%d) ", hfunc);
59: # endif DEBUG
60:
61: ps = &SymTab[hfunc];
62: while ((s = *ps) != NULL && (!sameword(name, s->s_name) || s->s_type != type))
63: ps = &s->s_next;
64:
65: /*
66: ** Dispose of the entry.
67: */
68:
69: if (s != NULL || op == ST_FIND)
70: {
71: # ifdef DEBUG
72: if (tTd(36, 5))
73: {
74: if (s == NULL)
75: printf("not found\n");
76: else
77: {
78: long *lp = (long *) s->s_class;
79:
80: printf("type %d val %lx %lx %lx %lx\n",
81: s->s_type, lp[0], lp[1], lp[2], lp[3]);
82: }
83: }
84: # endif DEBUG
85: return (s);
86: }
87:
88: /*
89: ** Make a new entry and link it in.
90: */
91:
92: # ifdef DEBUG
93: if (tTd(36, 5))
94: printf("entered\n");
95: # endif DEBUG
96:
97: /* make new entry */
98: s = (STAB *) xalloc(sizeof *s);
99: clear((char *) s, sizeof *s);
100: s->s_name = newstr(name);
101: makelower(s->s_name);
102: s->s_type = type;
103:
104: /* link it in */
105: *ps = s;
106:
107: return (s);
108: }
Defined functions
stab
defined in line
28; used 10 times
Defined variables
Defined macros