122713Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 3*62532Sbostic * Copyright (c) 1988, 1993 4*62532Sbostic * The Regents of the University of California. All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822713Sdist 922713Sdist #ifndef lint 10*62532Sbostic static char sccsid[] = "@(#)stab.c 8.1 (Berkeley) 06/07/93"; 1133731Sbostic #endif /* not lint */ 1222713Sdist 134057Seric # include "sendmail.h" 144057Seric 154057Seric /* 164057Seric ** STAB -- manage the symbol table 174057Seric ** 184057Seric ** Parameters: 194057Seric ** name -- the name to be looked up or inserted. 204103Seric ** type -- the type of symbol. 214057Seric ** op -- what to do: 224057Seric ** ST_ENTER -- enter the name if not 234057Seric ** already present. 244057Seric ** ST_FIND -- find it only. 254057Seric ** 264057Seric ** Returns: 274057Seric ** pointer to a STAB entry for this name. 284057Seric ** NULL if not found and not entered. 294057Seric ** 304057Seric ** Side Effects: 314057Seric ** can update the symbol table. 324057Seric */ 334057Seric 344151Seric # define STABSIZE 400 354057Seric 364151Seric static STAB *SymTab[STABSIZE]; 374151Seric 384057Seric STAB * 394103Seric stab(name, type, op) 404057Seric char *name; 414103Seric int type; 424057Seric int op; 434057Seric { 444151Seric register STAB *s; 454151Seric register STAB **ps; 464151Seric register int hfunc; 474151Seric register char *p; 484319Seric extern char lower(); 494057Seric 507677Seric if (tTd(36, 5)) 514103Seric printf("STAB: %s %d ", name, type); 524075Seric 534151Seric /* 544151Seric ** Compute the hashing function 554151Seric ** 564151Seric ** We could probably do better.... 574151Seric */ 584151Seric 594151Seric hfunc = type; 604151Seric for (p = name; *p != '\0'; p++) 614446Seric hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE; 624151Seric 637677Seric if (tTd(36, 9)) 644151Seric printf("(hfunc=%d) ", hfunc); 654151Seric 664151Seric ps = &SymTab[hfunc]; 6733725Sbostic while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type)) 684057Seric ps = &s->s_next; 694151Seric 704151Seric /* 714151Seric ** Dispose of the entry. 724151Seric */ 734151Seric 744057Seric if (s != NULL || op == ST_FIND) 754075Seric { 767677Seric if (tTd(36, 5)) 774075Seric { 784075Seric if (s == NULL) 794075Seric printf("not found\n"); 804075Seric else 8110690Seric { 8210690Seric long *lp = (long *) s->s_class; 8310690Seric 8410690Seric printf("type %d val %lx %lx %lx %lx\n", 8510690Seric s->s_type, lp[0], lp[1], lp[2], lp[3]); 8610690Seric } 874075Seric } 884057Seric return (s); 894075Seric } 904057Seric 914151Seric /* 924151Seric ** Make a new entry and link it in. 934151Seric */ 944151Seric 957677Seric if (tTd(36, 5)) 964075Seric printf("entered\n"); 974075Seric 984057Seric /* make new entry */ 994057Seric s = (STAB *) xalloc(sizeof *s); 10016882Seric bzero((char *) s, sizeof *s); 1014057Seric s->s_name = newstr(name); 1024058Seric makelower(s->s_name); 1034103Seric s->s_type = type; 1044057Seric 1054151Seric /* link it in */ 1064057Seric *ps = s; 1074057Seric 1084057Seric return (s); 1094057Seric } 11060491Seric /* 11160491Seric ** STABAPPLY -- apply function to all stab entries 11260491Seric ** 11360491Seric ** Parameters: 11460491Seric ** func -- the function to apply. It will be given one 11560491Seric ** parameter (the stab entry). 11660537Seric ** arg -- an arbitrary argument, passed to func. 11760491Seric ** 11860491Seric ** Returns: 11960491Seric ** none. 12060491Seric */ 12160491Seric 12260491Seric void 12360537Seric stabapply(func, arg) 12460537Seric void (*func)__P((STAB *, int)); 12560537Seric int arg; 12660491Seric { 12760491Seric register STAB **shead; 12860491Seric register STAB *s; 12960491Seric 13060491Seric for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++) 13160491Seric { 13260491Seric for (s = *shead; s != NULL; s = s->s_next) 13360537Seric { 13460537Seric if (tTd(38, 90)) 13560537Seric printf("stabapply: trying %d/%s\n", 13660537Seric s->s_type, s->s_name); 13760537Seric func(s, arg); 13860537Seric } 13960491Seric } 14060491Seric } 141