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