xref: /csrg-svn/usr.sbin/sendmail/src/stab.c (revision 22713)
1*22713Sdist /*
2*22713Sdist **  Sendmail
3*22713Sdist **  Copyright (c) 1983  Eric P. Allman
4*22713Sdist **  Berkeley, California
5*22713Sdist **
6*22713Sdist **  Copyright (c) 1983 Regents of the University of California.
7*22713Sdist **  All rights reserved.  The Berkeley software License Agreement
8*22713Sdist **  specifies the terms and conditions for redistribution.
9*22713Sdist */
10*22713Sdist 
11*22713Sdist #ifndef lint
12*22713Sdist static char	SccsId[] = "@(#)stab.c	5.1 (Berkeley) 06/07/85";
13*22713Sdist #endif not lint
14*22713Sdist 
154057Seric # include "sendmail.h"
164057Seric 
17*22713Sdist SCCSID(@(#)stab.c	5.1		06/07/85);
184057Seric 
194057Seric /*
204057Seric **  STAB -- manage the symbol table
214057Seric **
224057Seric **	Parameters:
234057Seric **		name -- the name to be looked up or inserted.
244103Seric **		type -- the type of symbol.
254057Seric **		op -- what to do:
264057Seric **			ST_ENTER -- enter the name if not
274057Seric **				already present.
284057Seric **			ST_FIND -- find it only.
294057Seric **
304057Seric **	Returns:
314057Seric **		pointer to a STAB entry for this name.
324057Seric **		NULL if not found and not entered.
334057Seric **
344057Seric **	Side Effects:
354057Seric **		can update the symbol table.
364057Seric */
374057Seric 
384151Seric # define STABSIZE	400
394057Seric 
404151Seric static STAB	*SymTab[STABSIZE];
414151Seric 
424057Seric STAB *
434103Seric stab(name, type, op)
444057Seric 	char *name;
454103Seric 	int type;
464057Seric 	int op;
474057Seric {
484151Seric 	register STAB *s;
494151Seric 	register STAB **ps;
504058Seric 	extern bool sameword();
514151Seric 	register int hfunc;
524151Seric 	register char *p;
534319Seric 	extern char lower();
544057Seric 
554075Seric # ifdef DEBUG
567677Seric 	if (tTd(36, 5))
574103Seric 		printf("STAB: %s %d ", name, type);
584075Seric # endif DEBUG
594075Seric 
604151Seric 	/*
614151Seric 	**  Compute the hashing function
624151Seric 	**
634151Seric 	**	We could probably do better....
644151Seric 	*/
654151Seric 
664151Seric 	hfunc = type;
674151Seric 	for (p = name; *p != '\0'; p++)
684446Seric 		hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
694151Seric 
704151Seric # ifdef DEBUG
717677Seric 	if (tTd(36, 9))
724151Seric 		printf("(hfunc=%d) ", hfunc);
734151Seric # endif DEBUG
744151Seric 
754151Seric 	ps = &SymTab[hfunc];
764151Seric 	while ((s = *ps) != NULL && (!sameword(name, s->s_name) || s->s_type != type))
774057Seric 		ps = &s->s_next;
784151Seric 
794151Seric 	/*
804151Seric 	**  Dispose of the entry.
814151Seric 	*/
824151Seric 
834057Seric 	if (s != NULL || op == ST_FIND)
844075Seric 	{
854075Seric # ifdef DEBUG
867677Seric 		if (tTd(36, 5))
874075Seric 		{
884075Seric 			if (s == NULL)
894075Seric 				printf("not found\n");
904075Seric 			else
9110690Seric 			{
9210690Seric 				long *lp = (long *) s->s_class;
9310690Seric 
9410690Seric 				printf("type %d val %lx %lx %lx %lx\n",
9510690Seric 					s->s_type, lp[0], lp[1], lp[2], lp[3]);
9610690Seric 			}
974075Seric 		}
984075Seric # endif DEBUG
994057Seric 		return (s);
1004075Seric 	}
1014057Seric 
1024151Seric 	/*
1034151Seric 	**  Make a new entry and link it in.
1044151Seric 	*/
1054151Seric 
1064075Seric # ifdef DEBUG
1077677Seric 	if (tTd(36, 5))
1084075Seric 		printf("entered\n");
1094075Seric # endif DEBUG
1104075Seric 
1114057Seric 	/* make new entry */
1124057Seric 	s = (STAB *) xalloc(sizeof *s);
11316882Seric 	bzero((char *) s, sizeof *s);
1144057Seric 	s->s_name = newstr(name);
1154058Seric 	makelower(s->s_name);
1164103Seric 	s->s_type = type;
1174057Seric 
1184151Seric 	/* link it in */
1194057Seric 	*ps = s;
1204057Seric 
1214057Seric 	return (s);
1224057Seric }
123