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