14057Seric # include "sendmail.h" 24057Seric 3*4319Seric static char SccsId[] = "@(#)stab.c 3.8 09/06/81"; 44057Seric 54057Seric /* 64057Seric ** STAB -- manage the symbol table 74057Seric ** 84057Seric ** Parameters: 94057Seric ** name -- the name to be looked up or inserted. 104103Seric ** type -- the type of symbol. 114057Seric ** op -- what to do: 124057Seric ** ST_ENTER -- enter the name if not 134057Seric ** already present. 144057Seric ** ST_FIND -- find it only. 154057Seric ** 164057Seric ** Returns: 174057Seric ** pointer to a STAB entry for this name. 184057Seric ** NULL if not found and not entered. 194057Seric ** 204057Seric ** Side Effects: 214057Seric ** can update the symbol table. 224057Seric */ 234057Seric 244151Seric # define STABSIZE 400 254057Seric 264151Seric static STAB *SymTab[STABSIZE]; 274151Seric 284057Seric STAB * 294103Seric stab(name, type, op) 304057Seric char *name; 314103Seric int type; 324057Seric int op; 334057Seric { 344151Seric register STAB *s; 354151Seric register STAB **ps; 364058Seric extern bool sameword(); 374151Seric register int hfunc; 384151Seric register char *p; 39*4319Seric extern char lower(); 404057Seric 414075Seric # ifdef DEBUG 424075Seric if (Debug > 4) 434103Seric printf("STAB: %s %d ", name, type); 444075Seric # endif DEBUG 454075Seric 464151Seric /* 474151Seric ** Compute the hashing function 484151Seric ** 494151Seric ** We could probably do better.... 504151Seric */ 514151Seric 524151Seric hfunc = type; 534151Seric for (p = name; *p != '\0'; p++) 544151Seric hfunc = ((hfunc << 7) | lower(*p)) % STABSIZE; 554151Seric 564151Seric # ifdef DEBUG 574151Seric if (Debug > 15) 584151Seric printf("(hfunc=%d) ", hfunc); 594151Seric # endif DEBUG 604151Seric 614151Seric ps = &SymTab[hfunc]; 624151Seric while ((s = *ps) != NULL && (!sameword(name, s->s_name) || s->s_type != type)) 634057Seric { 644057Seric ps = &s->s_next; 654057Seric s = s->s_next; 664057Seric } 674151Seric 684151Seric /* 694151Seric ** Dispose of the entry. 704151Seric */ 714151Seric 724057Seric if (s != NULL || op == ST_FIND) 734075Seric { 744075Seric # ifdef DEBUG 754075Seric if (Debug > 4) 764075Seric { 774075Seric if (s == NULL) 784075Seric printf("not found\n"); 794075Seric else 804151Seric printf("type %d val %x\n", s->s_type, s->s_class); 814075Seric } 824075Seric # endif DEBUG 834057Seric return (s); 844075Seric } 854057Seric 864151Seric /* 874151Seric ** Make a new entry and link it in. 884151Seric */ 894151Seric 904075Seric # ifdef DEBUG 914075Seric if (Debug > 4) 924075Seric printf("entered\n"); 934075Seric # endif DEBUG 944075Seric 954057Seric /* make new entry */ 964057Seric s = (STAB *) xalloc(sizeof *s); 974103Seric clear((char *) s, sizeof *s); 984057Seric s->s_name = newstr(name); 994058Seric makelower(s->s_name); 1004103Seric s->s_type = type; 1014057Seric 1024151Seric /* link it in */ 1034057Seric *ps = s; 1044057Seric 1054057Seric return (s); 1064057Seric } 107