1 # include "sendmail.h" 2 3 static char SccsId[] = "@(#)stab.c 3.8 09/06/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 extern char lower(); 40 41 # ifdef DEBUG 42 if (Debug > 4) 43 printf("STAB: %s %d ", name, type); 44 # endif DEBUG 45 46 /* 47 ** Compute the hashing function 48 ** 49 ** We could probably do better.... 50 */ 51 52 hfunc = type; 53 for (p = name; *p != '\0'; p++) 54 hfunc = ((hfunc << 7) | lower(*p)) % STABSIZE; 55 56 # ifdef DEBUG 57 if (Debug > 15) 58 printf("(hfunc=%d) ", hfunc); 59 # endif DEBUG 60 61 ps = &SymTab[hfunc]; 62 while ((s = *ps) != NULL && (!sameword(name, s->s_name) || s->s_type != type)) 63 { 64 ps = &s->s_next; 65 s = s->s_next; 66 } 67 68 /* 69 ** Dispose of the entry. 70 */ 71 72 if (s != NULL || op == ST_FIND) 73 { 74 # ifdef DEBUG 75 if (Debug > 4) 76 { 77 if (s == NULL) 78 printf("not found\n"); 79 else 80 printf("type %d val %x\n", s->s_type, s->s_class); 81 } 82 # endif DEBUG 83 return (s); 84 } 85 86 /* 87 ** Make a new entry and link it in. 88 */ 89 90 # ifdef DEBUG 91 if (Debug > 4) 92 printf("entered\n"); 93 # endif DEBUG 94 95 /* make new entry */ 96 s = (STAB *) xalloc(sizeof *s); 97 clear((char *) s, sizeof *s); 98 s->s_name = newstr(name); 99 makelower(s->s_name); 100 s->s_type = type; 101 102 /* link it in */ 103 *ps = s; 104 105 return (s); 106 } 107