122713Sdist /* 222713Sdist ** Sendmail 322713Sdist ** Copyright (c) 1983 Eric P. Allman 422713Sdist ** Berkeley, California 522713Sdist ** 622713Sdist ** Copyright (c) 1983 Regents of the University of California. 722713Sdist ** All rights reserved. The Berkeley software License Agreement 822713Sdist ** specifies the terms and conditions for redistribution. 922713Sdist */ 1022713Sdist 1122713Sdist #ifndef lint 12*33725Sbostic static char SccsId[] = "@(#)stab.c 5.3 (Berkeley) 03/13/88"; 1322713Sdist #endif not lint 1422713Sdist 154057Seric # include "sendmail.h" 164057Seric 174057Seric /* 184057Seric ** STAB -- manage the symbol table 194057Seric ** 204057Seric ** Parameters: 214057Seric ** name -- the name to be looked up or inserted. 224103Seric ** type -- the type of symbol. 234057Seric ** op -- what to do: 244057Seric ** ST_ENTER -- enter the name if not 254057Seric ** already present. 264057Seric ** ST_FIND -- find it only. 274057Seric ** 284057Seric ** Returns: 294057Seric ** pointer to a STAB entry for this name. 304057Seric ** NULL if not found and not entered. 314057Seric ** 324057Seric ** Side Effects: 334057Seric ** can update the symbol table. 344057Seric */ 354057Seric 364151Seric # define STABSIZE 400 374057Seric 384151Seric static STAB *SymTab[STABSIZE]; 394151Seric 404057Seric STAB * 414103Seric stab(name, type, op) 424057Seric char *name; 434103Seric int type; 444057Seric int op; 454057Seric { 464151Seric register STAB *s; 474151Seric register STAB **ps; 484151Seric register int hfunc; 494151Seric register char *p; 504319Seric extern char lower(); 514057Seric 524075Seric # ifdef DEBUG 537677Seric if (tTd(36, 5)) 544103Seric printf("STAB: %s %d ", name, type); 554075Seric # endif DEBUG 564075Seric 574151Seric /* 584151Seric ** Compute the hashing function 594151Seric ** 604151Seric ** We could probably do better.... 614151Seric */ 624151Seric 634151Seric hfunc = type; 644151Seric for (p = name; *p != '\0'; p++) 654446Seric hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE; 664151Seric 674151Seric # ifdef DEBUG 687677Seric if (tTd(36, 9)) 694151Seric printf("(hfunc=%d) ", hfunc); 704151Seric # endif DEBUG 714151Seric 724151Seric ps = &SymTab[hfunc]; 73*33725Sbostic while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type)) 744057Seric ps = &s->s_next; 754151Seric 764151Seric /* 774151Seric ** Dispose of the entry. 784151Seric */ 794151Seric 804057Seric if (s != NULL || op == ST_FIND) 814075Seric { 824075Seric # ifdef DEBUG 837677Seric if (tTd(36, 5)) 844075Seric { 854075Seric if (s == NULL) 864075Seric printf("not found\n"); 874075Seric else 8810690Seric { 8910690Seric long *lp = (long *) s->s_class; 9010690Seric 9110690Seric printf("type %d val %lx %lx %lx %lx\n", 9210690Seric s->s_type, lp[0], lp[1], lp[2], lp[3]); 9310690Seric } 944075Seric } 954075Seric # endif DEBUG 964057Seric return (s); 974075Seric } 984057Seric 994151Seric /* 1004151Seric ** Make a new entry and link it in. 1014151Seric */ 1024151Seric 1034075Seric # ifdef DEBUG 1047677Seric if (tTd(36, 5)) 1054075Seric printf("entered\n"); 1064075Seric # endif DEBUG 1074075Seric 1084057Seric /* make new entry */ 1094057Seric s = (STAB *) xalloc(sizeof *s); 11016882Seric bzero((char *) s, sizeof *s); 1114057Seric s->s_name = newstr(name); 1124058Seric makelower(s->s_name); 1134103Seric s->s_type = type; 1144057Seric 1154151Seric /* link it in */ 1164057Seric *ps = s; 1174057Seric 1184057Seric return (s); 1194057Seric } 120