1 # include "sendmail.h" 2 3 SCCSID(@(#)stab.c 3.13 08/08/82); 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 (tTd(36, 5)) 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)) & 077777) % STABSIZE; 55 56 # ifdef DEBUG 57 if (tTd(36, 9)) 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 ps = &s->s_next; 64 65 /* 66 ** Dispose of the entry. 67 */ 68 69 if (s != NULL || op == ST_FIND) 70 { 71 # ifdef DEBUG 72 if (tTd(36, 5)) 73 { 74 if (s == NULL) 75 printf("not found\n"); 76 else 77 printf("type %d val %lx\n", s->s_type, s->s_class); 78 } 79 # endif DEBUG 80 return (s); 81 } 82 83 /* 84 ** Make a new entry and link it in. 85 */ 86 87 # ifdef DEBUG 88 if (tTd(36, 5)) 89 printf("entered\n"); 90 # endif DEBUG 91 92 /* make new entry */ 93 s = (STAB *) xalloc(sizeof *s); 94 clear((char *) s, sizeof *s); 95 s->s_name = newstr(name); 96 makelower(s->s_name); 97 s->s_type = type; 98 99 /* link it in */ 100 *ps = s; 101 102 return (s); 103 } 104