1 # include "sendmail.h" 2 3 static char SccsId[] = "@(#)stab.c 3.7 08/17/81"; 4 5 /* 6 ** STAB -- manage the symbol table 7 ** 8 ** Parameters: 9 ** name -- the name to be looked up or inserted. 10 ** type -- the type of symbol. 11 ** op -- what to do: 12 ** ST_ENTER -- enter the name if not 13 ** already present. 14 ** ST_FIND -- find it only. 15 ** 16 ** Returns: 17 ** pointer to a STAB entry for this name. 18 ** NULL if not found and not entered. 19 ** 20 ** Side Effects: 21 ** can update the symbol table. 22 */ 23 24 # define STABSIZE 400 25 26 static STAB *SymTab[STABSIZE]; 27 28 STAB * 29 stab(name, type, op) 30 char *name; 31 int type; 32 int op; 33 { 34 register STAB *s; 35 register STAB **ps; 36 extern bool sameword(); 37 register int hfunc; 38 register char *p; 39 40 # ifdef DEBUG 41 if (Debug > 4) 42 printf("STAB: %s %d ", name, type); 43 # endif DEBUG 44 45 /* 46 ** Compute the hashing function 47 ** 48 ** We could probably do better.... 49 */ 50 51 hfunc = type; 52 for (p = name; *p != '\0'; p++) 53 hfunc = ((hfunc << 7) | lower(*p)) % STABSIZE; 54 55 # ifdef DEBUG 56 if (Debug > 15) 57 printf("(hfunc=%d) ", hfunc); 58 # endif DEBUG 59 60 ps = &SymTab[hfunc]; 61 while ((s = *ps) != NULL && (!sameword(name, s->s_name) || s->s_type != type)) 62 { 63 ps = &s->s_next; 64 s = s->s_next; 65 } 66 67 /* 68 ** Dispose of the entry. 69 */ 70 71 if (s != NULL || op == ST_FIND) 72 { 73 # ifdef DEBUG 74 if (Debug > 4) 75 { 76 if (s == NULL) 77 printf("not found\n"); 78 else 79 printf("type %d val %x\n", s->s_type, s->s_class); 80 } 81 # endif DEBUG 82 return (s); 83 } 84 85 /* 86 ** Make a new entry and link it in. 87 */ 88 89 # ifdef DEBUG 90 if (Debug > 4) 91 printf("entered\n"); 92 # endif DEBUG 93 94 /* make new entry */ 95 s = (STAB *) xalloc(sizeof *s); 96 clear((char *) s, sizeof *s); 97 s->s_name = newstr(name); 98 makelower(s->s_name); 99 s->s_type = type; 100 101 /* link it in */ 102 *ps = s; 103 104 return (s); 105 } 106