xref: /original-bsd/usr.sbin/sendmail/src/stab.c (revision b8338845)
1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988 Regents of the University of California.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that the above copyright notice and this paragraph are
8  * duplicated in all such forms and that any documentation,
9  * advertising materials, and other materials related to such
10  * distribution and use acknowledge that the software was developed
11  * by the University of California, Berkeley.  The name of the
12  * University may not be used to endorse or promote products derived
13  * from this software without specific prior written permission.
14  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  */
18 
19 #ifndef lint
20 static char sccsid[] = "@(#)stab.c	5.6 (Berkeley) 01/01/89";
21 #endif /* not lint */
22 
23 # include "sendmail.h"
24 
25 /*
26 **  STAB -- manage the symbol table
27 **
28 **	Parameters:
29 **		name -- the name to be looked up or inserted.
30 **		type -- the type of symbol.
31 **		op -- what to do:
32 **			ST_ENTER -- enter the name if not
33 **				already present.
34 **			ST_FIND -- find it only.
35 **
36 **	Returns:
37 **		pointer to a STAB entry for this name.
38 **		NULL if not found and not entered.
39 **
40 **	Side Effects:
41 **		can update the symbol table.
42 */
43 
44 # define STABSIZE	400
45 
46 static STAB	*SymTab[STABSIZE];
47 
48 STAB *
49 stab(name, type, op)
50 	char *name;
51 	int type;
52 	int op;
53 {
54 	register STAB *s;
55 	register STAB **ps;
56 	register int hfunc;
57 	register char *p;
58 	extern char lower();
59 
60 	if (tTd(36, 5))
61 		printf("STAB: %s %d ", name, type);
62 
63 	/*
64 	**  Compute the hashing function
65 	**
66 	**	We could probably do better....
67 	*/
68 
69 	hfunc = type;
70 	for (p = name; *p != '\0'; p++)
71 		hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
72 
73 	if (tTd(36, 9))
74 		printf("(hfunc=%d) ", hfunc);
75 
76 	ps = &SymTab[hfunc];
77 	while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type))
78 		ps = &s->s_next;
79 
80 	/*
81 	**  Dispose of the entry.
82 	*/
83 
84 	if (s != NULL || op == ST_FIND)
85 	{
86 		if (tTd(36, 5))
87 		{
88 			if (s == NULL)
89 				printf("not found\n");
90 			else
91 			{
92 				long *lp = (long *) s->s_class;
93 
94 				printf("type %d val %lx %lx %lx %lx\n",
95 					s->s_type, lp[0], lp[1], lp[2], lp[3]);
96 			}
97 		}
98 		return (s);
99 	}
100 
101 	/*
102 	**  Make a new entry and link it in.
103 	*/
104 
105 	if (tTd(36, 5))
106 		printf("entered\n");
107 
108 	/* make new entry */
109 	s = (STAB *) xalloc(sizeof *s);
110 	bzero((char *) s, sizeof *s);
111 	s->s_name = newstr(name);
112 	makelower(s->s_name);
113 	s->s_type = type;
114 
115 	/* link it in */
116 	*ps = s;
117 
118 	return (s);
119 }
120