# 2.11BSD#431 - /usr/src/usr.bin/ratfor/rlook.c

##### Functions

    copy              X
    install           X
    lookup            X

##### Variables

    hshtab            X
    hshval            X

##### Macros

    EOS               X
    HSHSIZ            X
    NULL              X

##### struct's

    nlist             X

       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

- in line 19, 51-52(2), 59

install defined in line 43; used 5 times

- in line 17
- in /usr/src/usr.bin/ratfor/r.h line 62
- in /usr/src/usr.bin/ratfor/rlex.c line 101-102(2), 246

lookup defined in line 22; used 5 times

- in line 16, 49
- in /usr/src/usr.bin/ratfor/r.h line 61
- in /usr/src/usr.bin/ratfor/rio.c line 88
- in /usr/src/usr.bin/ratfor/rlex.c line 182

#### Defined variables

hshtab defined in line 15; used 3 times

- in line 33, 54-55(2)

hshval defined in line 20; used 6 times

- in line 30-33(4), 54-55(2)

sccsid defined in line 2; never used

#### Defined struct's

nlist defined in line 8; used 16 times

- in line 12-16(6), 22-27(6), 47-50(4)

#### Defined macros

EOS defined in line 6; used 1 times

- in line 37

HSHSIZ defined in line 7; used 2 times

- in line 15, 32

NULL defined in line 5; used 2 times

- in line 33, 49

Last modified: 1987-02-17 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 978 |