122713Sdist /* 2*34921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 633731Sbostic * Redistribution and use in source and binary forms are permitted 7*34921Sbostic * provided that the above copyright notice and this paragraph are 8*34921Sbostic * duplicated in all such forms and that any documentation, 9*34921Sbostic * advertising materials, and other materials related to such 10*34921Sbostic * distribution and use acknowledge that the software was developed 11*34921Sbostic * by the University of California, Berkeley. The name of the 12*34921Sbostic * University may not be used to endorse or promote products derived 13*34921Sbostic * from this software without specific prior written permission. 14*34921Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 15*34921Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 16*34921Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1733731Sbostic */ 1822713Sdist 1922713Sdist #ifndef lint 20*34921Sbostic static char sccsid[] = "@(#)stab.c 5.5 (Berkeley) 06/30/88"; 2133731Sbostic #endif /* not lint */ 2222713Sdist 234057Seric # include "sendmail.h" 244057Seric 254057Seric /* 264057Seric ** STAB -- manage the symbol table 274057Seric ** 284057Seric ** Parameters: 294057Seric ** name -- the name to be looked up or inserted. 304103Seric ** type -- the type of symbol. 314057Seric ** op -- what to do: 324057Seric ** ST_ENTER -- enter the name if not 334057Seric ** already present. 344057Seric ** ST_FIND -- find it only. 354057Seric ** 364057Seric ** Returns: 374057Seric ** pointer to a STAB entry for this name. 384057Seric ** NULL if not found and not entered. 394057Seric ** 404057Seric ** Side Effects: 414057Seric ** can update the symbol table. 424057Seric */ 434057Seric 444151Seric # define STABSIZE 400 454057Seric 464151Seric static STAB *SymTab[STABSIZE]; 474151Seric 484057Seric STAB * 494103Seric stab(name, type, op) 504057Seric char *name; 514103Seric int type; 524057Seric int op; 534057Seric { 544151Seric register STAB *s; 554151Seric register STAB **ps; 564151Seric register int hfunc; 574151Seric register char *p; 584319Seric extern char lower(); 594057Seric 604075Seric # ifdef DEBUG 617677Seric if (tTd(36, 5)) 624103Seric printf("STAB: %s %d ", name, type); 634075Seric # endif DEBUG 644075Seric 654151Seric /* 664151Seric ** Compute the hashing function 674151Seric ** 684151Seric ** We could probably do better.... 694151Seric */ 704151Seric 714151Seric hfunc = type; 724151Seric for (p = name; *p != '\0'; p++) 734446Seric hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE; 744151Seric 754151Seric # ifdef DEBUG 767677Seric if (tTd(36, 9)) 774151Seric printf("(hfunc=%d) ", hfunc); 784151Seric # endif DEBUG 794151Seric 804151Seric ps = &SymTab[hfunc]; 8133725Sbostic while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type)) 824057Seric ps = &s->s_next; 834151Seric 844151Seric /* 854151Seric ** Dispose of the entry. 864151Seric */ 874151Seric 884057Seric if (s != NULL || op == ST_FIND) 894075Seric { 904075Seric # ifdef DEBUG 917677Seric if (tTd(36, 5)) 924075Seric { 934075Seric if (s == NULL) 944075Seric printf("not found\n"); 954075Seric else 9610690Seric { 9710690Seric long *lp = (long *) s->s_class; 9810690Seric 9910690Seric printf("type %d val %lx %lx %lx %lx\n", 10010690Seric s->s_type, lp[0], lp[1], lp[2], lp[3]); 10110690Seric } 1024075Seric } 1034075Seric # endif DEBUG 1044057Seric return (s); 1054075Seric } 1064057Seric 1074151Seric /* 1084151Seric ** Make a new entry and link it in. 1094151Seric */ 1104151Seric 1114075Seric # ifdef DEBUG 1127677Seric if (tTd(36, 5)) 1134075Seric printf("entered\n"); 1144075Seric # endif DEBUG 1154075Seric 1164057Seric /* make new entry */ 1174057Seric s = (STAB *) xalloc(sizeof *s); 11816882Seric bzero((char *) s, sizeof *s); 1194057Seric s->s_name = newstr(name); 1204058Seric makelower(s->s_name); 1214103Seric s->s_type = type; 1224057Seric 1234151Seric /* link it in */ 1244057Seric *ps = s; 1254057Seric 1264057Seric return (s); 1274057Seric } 128