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

Defined functions

copy defined in line 63; used 4 times
install defined in line 43; used 5 times
lookup defined in line 22; used 5 times

Defined variables

hshtab defined in line 15; used 3 times
hshval defined in line 20; used 6 times
sccsid defined in line 2; never used

Defined struct's

nlist defined in line 8; used 16 times

Defined macros

EOS defined in line 6; used 1 times
  • in line 37
HSHSIZ defined in line 7; used 2 times
NULL defined in line 5; used 2 times
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2234
Valid CSS Valid XHTML 1.0 Strict