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

Defined functions

Defined variables

SymTab defined in line 44; used 1 times
  • in line 78
sccsid defined in line 18; never used

Defined macros

STABSIZE defined in line 42; used 2 times
Last modified: 1988-09-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2321
Valid CSS Valid XHTML 1.0 Strict