1: #define NULL 0
   2: #define EOS 0
   3: #define HSHSIZ  101
   4: struct  nlist {
   5:     char    *name;
   6:     char    *def;
   7:     int ydef;
   8:     struct  nlist *next;
   9: };
  10: 
  11: struct  nlist   *hshtab[HSHSIZ];
  12: struct nlist    *lookup();
  13: char    *install();
  14: char    *malloc();
  15: char    *copy();
  16: int hshval;
  17: 
  18: struct nlist *lookup(str)
  19: char *str;
  20: {
  21:     register char *s1, *s2;
  22:     register struct nlist *np;
  23:     static struct nlist nodef;
  24: 
  25:     s1 = str;
  26:     for (hshval = 0; *s1; )
  27:         hshval += *s1++;
  28:     hshval %= HSHSIZ;
  29:     for (np = hshtab[hshval]; np!=NULL; np = np->next) {
  30:         s1 = str;
  31:         s2 = np->name;
  32:         while (*s1++ == *s2)
  33:             if (*s2++ == EOS)
  34:                 return(np);
  35:     }
  36:     return(&nodef);
  37: }
  38: 
  39: char *install(nam, val, tran)
  40: char *nam, *val;
  41: int tran;
  42: {
  43:     register struct nlist *np;
  44: 
  45:     if ((np = lookup(nam))->name == NULL) {
  46:         np = (struct nlist *)malloc(sizeof(*np));
  47:         np->name = copy(nam);
  48:         np->def = copy(val);
  49:         np->ydef = tran;
  50:         np->next = hshtab[hshval];
  51:         hshtab[hshval] = np;
  52:         return(np->def);
  53:     }
  54:     free(np->def);
  55:     np->def = copy(val);
  56:     return(np->def);
  57: }
  58: 
  59: char *copy(s)
  60: register char *s;
  61: {
  62:     register char *p, *s1;
  63: 
  64:     p = s1 = (char *) malloc((unsigned)strlen(s)+1);
  65:     while (*s1++ = *s++);
  66:     return(p);
  67: }

Defined functions

copy defined in line 59; used 4 times
install defined in line 39; used 5 times
lookup defined in line 18; used 5 times

Defined variables

hshtab defined in line 11; used 3 times
hshval defined in line 16; used 6 times

Defined struct's

nlist defined in line 4; used 16 times

Defined macros

EOS defined in line 2; used 1 times
  • in line 33
HSHSIZ defined in line 3; used 2 times
NULL defined in line 1; used 2 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 780
Valid CSS Valid XHTML 1.0 Strict