xref: /original-bsd/usr.sbin/sendmail/src/stab.c (revision 6cca134b)
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.5 (Berkeley) 06/30/88";
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 # ifdef DEBUG
61 	if (tTd(36, 5))
62 		printf("STAB: %s %d ", name, type);
63 # endif DEBUG
64 
65 	/*
66 	**  Compute the hashing function
67 	**
68 	**	We could probably do better....
69 	*/
70 
71 	hfunc = type;
72 	for (p = name; *p != '\0'; p++)
73 		hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
74 
75 # ifdef DEBUG
76 	if (tTd(36, 9))
77 		printf("(hfunc=%d) ", hfunc);
78 # endif DEBUG
79 
80 	ps = &SymTab[hfunc];
81 	while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type))
82 		ps = &s->s_next;
83 
84 	/*
85 	**  Dispose of the entry.
86 	*/
87 
88 	if (s != NULL || op == ST_FIND)
89 	{
90 # ifdef DEBUG
91 		if (tTd(36, 5))
92 		{
93 			if (s == NULL)
94 				printf("not found\n");
95 			else
96 			{
97 				long *lp = (long *) s->s_class;
98 
99 				printf("type %d val %lx %lx %lx %lx\n",
100 					s->s_type, lp[0], lp[1], lp[2], lp[3]);
101 			}
102 		}
103 # endif DEBUG
104 		return (s);
105 	}
106 
107 	/*
108 	**  Make a new entry and link it in.
109 	*/
110 
111 # ifdef DEBUG
112 	if (tTd(36, 5))
113 		printf("entered\n");
114 # endif DEBUG
115 
116 	/* make new entry */
117 	s = (STAB *) xalloc(sizeof *s);
118 	bzero((char *) s, sizeof *s);
119 	s->s_name = newstr(name);
120 	makelower(s->s_name);
121 	s->s_type = type;
122 
123 	/* link it in */
124 	*ps = s;
125 
126 	return (s);
127 }
128