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