xref: /csrg-svn/usr.sbin/sendmail/src/stab.c (revision 4103)
1 # include "sendmail.h"
2 
3 static char SccsId[] = "@(#)stab.c	3.5	08/10/81";
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 **	Notes:
24 **		Obviously, this deserves a better algorithm.  But
25 **		for the moment......
26 */
27 
28 static STAB	*SymTab;
29 
30 STAB *
31 stab(name, type, op)
32 	char *name;
33 	int type;
34 	int op;
35 {
36 	register STAB *s = SymTab;
37 	register STAB **ps = &SymTab;
38 	extern bool sameword();
39 
40 # ifdef DEBUG
41 	if (Debug > 4)
42 		printf("STAB: %s %d ", name, type);
43 # endif DEBUG
44 
45 	while (s != NULL && !sameword(name, s->s_name) && s->s_type != type)
46 	{
47 		ps = &s->s_next;
48 		s = s->s_next;
49 	}
50 	if (s != NULL || op == ST_FIND)
51 	{
52 # ifdef DEBUG
53 		if (Debug > 4)
54 		{
55 			if (s == NULL)
56 				printf("not found\n");
57 			else
58 				printf("type %d class %x\n", s->s_type, s->s_class);
59 		}
60 # endif DEBUG
61 		return (s);
62 	}
63 
64 # ifdef DEBUG
65 	if (Debug > 4)
66 		printf("entered\n");
67 # endif DEBUG
68 
69 	/* make new entry */
70 	s = (STAB *) xalloc(sizeof *s);
71 	clear((char *) s, sizeof *s);
72 	s->s_name = newstr(name);
73 	makelower(s->s_name);
74 	s->s_type = type;
75 
76 	/* and link it in */
77 	*ps = s;
78 
79 	return (s);
80 }
81