xref: /csrg-svn/usr.sbin/sendmail/src/stab.c (revision 33731)
122713Sdist /*
2*33731Sbostic  * Copyright (c) 1988 Regents of the University of California.
3*33731Sbostic  * All rights reserved.
4*33731Sbostic  *
5*33731Sbostic  * Redistribution and use in source and binary forms are permitted
6*33731Sbostic  * provided that this notice is preserved and that due credit is given
7*33731Sbostic  * to the University of California at Berkeley. The name of the University
8*33731Sbostic  * may not be used to endorse or promote products derived from this
9*33731Sbostic  * software without specific prior written permission. This software
10*33731Sbostic  * is provided ``as is'' without express or implied warranty.
11*33731Sbostic  *
12*33731Sbostic  *  Sendmail
13*33731Sbostic  *  Copyright (c) 1983  Eric P. Allman
14*33731Sbostic  *  Berkeley, California
15*33731Sbostic  */
1622713Sdist 
1722713Sdist #ifndef lint
18*33731Sbostic static char sccsid[] = "@(#)stab.c	5.4 (Berkeley) 03/13/88";
19*33731Sbostic #endif /* not lint */
2022713Sdist 
214057Seric # include "sendmail.h"
224057Seric 
234057Seric /*
244057Seric **  STAB -- manage the symbol table
254057Seric **
264057Seric **	Parameters:
274057Seric **		name -- the name to be looked up or inserted.
284103Seric **		type -- the type of symbol.
294057Seric **		op -- what to do:
304057Seric **			ST_ENTER -- enter the name if not
314057Seric **				already present.
324057Seric **			ST_FIND -- find it only.
334057Seric **
344057Seric **	Returns:
354057Seric **		pointer to a STAB entry for this name.
364057Seric **		NULL if not found and not entered.
374057Seric **
384057Seric **	Side Effects:
394057Seric **		can update the symbol table.
404057Seric */
414057Seric 
424151Seric # define STABSIZE	400
434057Seric 
444151Seric static STAB	*SymTab[STABSIZE];
454151Seric 
464057Seric STAB *
474103Seric stab(name, type, op)
484057Seric 	char *name;
494103Seric 	int type;
504057Seric 	int op;
514057Seric {
524151Seric 	register STAB *s;
534151Seric 	register STAB **ps;
544151Seric 	register int hfunc;
554151Seric 	register char *p;
564319Seric 	extern char lower();
574057Seric 
584075Seric # ifdef DEBUG
597677Seric 	if (tTd(36, 5))
604103Seric 		printf("STAB: %s %d ", name, type);
614075Seric # endif DEBUG
624075Seric 
634151Seric 	/*
644151Seric 	**  Compute the hashing function
654151Seric 	**
664151Seric 	**	We could probably do better....
674151Seric 	*/
684151Seric 
694151Seric 	hfunc = type;
704151Seric 	for (p = name; *p != '\0'; p++)
714446Seric 		hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
724151Seric 
734151Seric # ifdef DEBUG
747677Seric 	if (tTd(36, 9))
754151Seric 		printf("(hfunc=%d) ", hfunc);
764151Seric # endif DEBUG
774151Seric 
784151Seric 	ps = &SymTab[hfunc];
7933725Sbostic 	while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type))
804057Seric 		ps = &s->s_next;
814151Seric 
824151Seric 	/*
834151Seric 	**  Dispose of the entry.
844151Seric 	*/
854151Seric 
864057Seric 	if (s != NULL || op == ST_FIND)
874075Seric 	{
884075Seric # ifdef DEBUG
897677Seric 		if (tTd(36, 5))
904075Seric 		{
914075Seric 			if (s == NULL)
924075Seric 				printf("not found\n");
934075Seric 			else
9410690Seric 			{
9510690Seric 				long *lp = (long *) s->s_class;
9610690Seric 
9710690Seric 				printf("type %d val %lx %lx %lx %lx\n",
9810690Seric 					s->s_type, lp[0], lp[1], lp[2], lp[3]);
9910690Seric 			}
1004075Seric 		}
1014075Seric # endif DEBUG
1024057Seric 		return (s);
1034075Seric 	}
1044057Seric 
1054151Seric 	/*
1064151Seric 	**  Make a new entry and link it in.
1074151Seric 	*/
1084151Seric 
1094075Seric # ifdef DEBUG
1107677Seric 	if (tTd(36, 5))
1114075Seric 		printf("entered\n");
1124075Seric # endif DEBUG
1134075Seric 
1144057Seric 	/* make new entry */
1154057Seric 	s = (STAB *) xalloc(sizeof *s);
11616882Seric 	bzero((char *) s, sizeof *s);
1174057Seric 	s->s_name = newstr(name);
1184058Seric 	makelower(s->s_name);
1194103Seric 	s->s_type = type;
1204057Seric 
1214151Seric 	/* link it in */
1224057Seric 	*ps = s;
1234057Seric 
1244057Seric 	return (s);
1254057Seric }
126