Commit | Line | Data |
---|---|---|
1be0fe39 CC |
1 | Original 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 | |
6 | struct nlist { | |
7 | char *name; | |
8 | char *def; | |
9 | int ydef; | |
10 | struct nlist *next; | |
11 | }; | |
12 | ||
13 | struct nlist *hshtab[HSHSIZ]; | |
14 | struct nlist *lookup(); | |
15 | char *install(); | |
16 | char *malloc(); | |
17 | char *copy(); | |
18 | int hshval; | |
19 | ||
20 | struct nlist *lookup(str) | |
21 | char *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 | ||
41 | char *install(nam, val, tran) | |
42 | char *nam, *val; | |
43 | int 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 | ||
61 | char *copy(s) | |
62 | register 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 | } |