xref: /csrg-svn/usr.sbin/sendmail/src/stab.c (revision 10690)
14057Seric # include "sendmail.h"
24057Seric 
3*10690Seric SCCSID(@(#)stab.c	3.14		02/02/83);
44057Seric 
54057Seric /*
64057Seric **  STAB -- manage the symbol table
74057Seric **
84057Seric **	Parameters:
94057Seric **		name -- the name to be looked up or inserted.
104103Seric **		type -- the type of symbol.
114057Seric **		op -- what to do:
124057Seric **			ST_ENTER -- enter the name if not
134057Seric **				already present.
144057Seric **			ST_FIND -- find it only.
154057Seric **
164057Seric **	Returns:
174057Seric **		pointer to a STAB entry for this name.
184057Seric **		NULL if not found and not entered.
194057Seric **
204057Seric **	Side Effects:
214057Seric **		can update the symbol table.
224057Seric */
234057Seric 
244151Seric # define STABSIZE	400
254057Seric 
264151Seric static STAB	*SymTab[STABSIZE];
274151Seric 
284057Seric STAB *
294103Seric stab(name, type, op)
304057Seric 	char *name;
314103Seric 	int type;
324057Seric 	int op;
334057Seric {
344151Seric 	register STAB *s;
354151Seric 	register STAB **ps;
364058Seric 	extern bool sameword();
374151Seric 	register int hfunc;
384151Seric 	register char *p;
394319Seric 	extern char lower();
404057Seric 
414075Seric # ifdef DEBUG
427677Seric 	if (tTd(36, 5))
434103Seric 		printf("STAB: %s %d ", name, type);
444075Seric # endif DEBUG
454075Seric 
464151Seric 	/*
474151Seric 	**  Compute the hashing function
484151Seric 	**
494151Seric 	**	We could probably do better....
504151Seric 	*/
514151Seric 
524151Seric 	hfunc = type;
534151Seric 	for (p = name; *p != '\0'; p++)
544446Seric 		hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
554151Seric 
564151Seric # ifdef DEBUG
577677Seric 	if (tTd(36, 9))
584151Seric 		printf("(hfunc=%d) ", hfunc);
594151Seric # endif DEBUG
604151Seric 
614151Seric 	ps = &SymTab[hfunc];
624151Seric 	while ((s = *ps) != NULL && (!sameword(name, s->s_name) || s->s_type != type))
634057Seric 		ps = &s->s_next;
644151Seric 
654151Seric 	/*
664151Seric 	**  Dispose of the entry.
674151Seric 	*/
684151Seric 
694057Seric 	if (s != NULL || op == ST_FIND)
704075Seric 	{
714075Seric # ifdef DEBUG
727677Seric 		if (tTd(36, 5))
734075Seric 		{
744075Seric 			if (s == NULL)
754075Seric 				printf("not found\n");
764075Seric 			else
77*10690Seric 			{
78*10690Seric 				long *lp = (long *) s->s_class;
79*10690Seric 
80*10690Seric 				printf("type %d val %lx %lx %lx %lx\n",
81*10690Seric 					s->s_type, lp[0], lp[1], lp[2], lp[3]);
82*10690Seric 			}
834075Seric 		}
844075Seric # endif DEBUG
854057Seric 		return (s);
864075Seric 	}
874057Seric 
884151Seric 	/*
894151Seric 	**  Make a new entry and link it in.
904151Seric 	*/
914151Seric 
924075Seric # ifdef DEBUG
937677Seric 	if (tTd(36, 5))
944075Seric 		printf("entered\n");
954075Seric # endif DEBUG
964075Seric 
974057Seric 	/* make new entry */
984057Seric 	s = (STAB *) xalloc(sizeof *s);
994103Seric 	clear((char *) s, sizeof *s);
1004057Seric 	s->s_name = newstr(name);
1014058Seric 	makelower(s->s_name);
1024103Seric 	s->s_type = type;
1034057Seric 
1044151Seric 	/* link it in */
1054057Seric 	*ps = s;
1064057Seric 
1074057Seric 	return (s);
1084057Seric }
109