xref: /csrg-svn/usr.sbin/sendmail/src/stab.c (revision 4058)
1 # include "sendmail.h"
2 
3 static char SccsId[] = "@(#)stab.c	3.2	08/08/81";
4 
5 /*
6 **  STAB -- manage the symbol table
7 **
8 **	Parameters:
9 **		name -- the name to be looked up or inserted.
10 **		op -- what to do:
11 **			ST_ENTER -- enter the name if not
12 **				already present.
13 **			ST_FIND -- find it only.
14 **
15 **	Returns:
16 **		pointer to a STAB entry for this name.
17 **		NULL if not found and not entered.
18 **
19 **	Side Effects:
20 **		can update the symbol table.
21 **
22 **	Notes:
23 **		Obviously, this deserves a better algorithm.  But
24 **		for the moment......
25 */
26 
27 static STAB	*SymTab;
28 
29 STAB *
30 stab(name, op)
31 	char *name;
32 	int op;
33 {
34 	register STAB *s = SymTab;
35 	register STAB **ps = &SymTab;
36 	extern char *newstr();
37 	extern bool sameword();
38 
39 	while (s != NULL && sameword(name, s->s_name))
40 	{
41 		ps = &s->s_next;
42 		s = s->s_next;
43 	}
44 	if (s != NULL || op == ST_FIND)
45 		return (s);
46 
47 	/* make new entry */
48 	s = (STAB *) xalloc(sizeof *s);
49 	s->s_name = newstr(name);
50 	makelower(s->s_name);
51 	s->s_type = 0;
52 	s->s_class = 0;
53 	s->s_next = NULL;
54 
55 	/* and link it in */
56 	*ps = s;
57 
58 	return (s);
59 }
60