122713Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822713Sdist 922713Sdist #ifndef lint 10*60491Seric static char sccsid[] = "@(#)stab.c 6.2 (Berkeley) 05/27/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 } 110*60491Seric /* 111*60491Seric ** STABAPPLY -- apply function to all stab entries 112*60491Seric ** 113*60491Seric ** Parameters: 114*60491Seric ** func -- the function to apply. It will be given one 115*60491Seric ** parameter (the stab entry). 116*60491Seric ** 117*60491Seric ** Returns: 118*60491Seric ** none. 119*60491Seric */ 120*60491Seric 121*60491Seric void 122*60491Seric stabapply(func) 123*60491Seric void (*func)__P((STAB *)); 124*60491Seric { 125*60491Seric register STAB **shead; 126*60491Seric register STAB *s; 127*60491Seric 128*60491Seric for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++) 129*60491Seric { 130*60491Seric for (s = *shead; s != NULL; s = s->s_next) 131*60491Seric func(s); 132*60491Seric } 133*60491Seric } 134