fort not included in "all" or "install" until f77 copy of sources
[unix-history] / usr / src / old / ratfor / rlook.c
CommitLineData
1be0fe39
CC
1Original BTL Ratfor System for 4.2
2/* @(#)rlook.c 1.1 (Berkeley) %G% */
3#define NULL 0
4#define EOS 0
5#define HSHSIZ 101
6struct nlist {
7 char *name;
8 char *def;
9 int ydef;
10 struct nlist *next;
11};
12
13struct nlist *hshtab[HSHSIZ];
14struct nlist *lookup();
15char *install();
16char *malloc();
17char *copy();
18int hshval;
19
20struct nlist *lookup(str)
21char *str;
22{
23 register char *s1, *s2;
24 register struct nlist *np;
25 static struct nlist nodef;
26
27 s1 = str;
28 for (hshval = 0; *s1; )
29 hshval += *s1++;
30 hshval %= HSHSIZ;
31 for (np = hshtab[hshval]; np!=NULL; np = np->next) {
32 s1 = str;
33 s2 = np->name;
34 while (*s1++ == *s2)
35 if (*s2++ == EOS)
36 return(np);
37 }
38 return(&nodef);
39}
40
41char *install(nam, val, tran)
42char *nam, *val;
43int tran;
44{
45 register struct nlist *np;
46
47 if ((np = lookup(nam))->name == NULL) {
48 np = (struct nlist *)malloc(sizeof(*np));
49 np->name = copy(nam);
50 np->def = copy(val);
51 np->ydef = tran;
52 np->next = hshtab[hshval];
53 hshtab[hshval] = np;
54 return(np->def);
55 }
56 free(np->def);
57 np->def = copy(val);
58 return(np->def);
59}
60
61char *copy(s)
62register char *s;
63{
64 register char *p, *s1;
65
66 p = s1 = (char *) malloc((unsigned)strlen(s)+1);
67 while (*s1++ = *s++);
68 return(p);
69}