Commit | Line | Data |
---|---|---|
1be0fe39 | 1 | Original BTL Ratfor System for 4.2 |
476fcd16 SL |
2 | #ifndef lint |
3 | static 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 | |
9 | struct nlist { | |
10 | char *name; | |
11 | char *def; | |
12 | int ydef; | |
13 | struct nlist *next; | |
14 | }; | |
15 | ||
16 | struct nlist *hshtab[HSHSIZ]; | |
17 | struct nlist *lookup(); | |
18 | char *install(); | |
19 | char *malloc(); | |
20 | char *copy(); | |
21 | int hshval; | |
22 | ||
23 | struct nlist *lookup(str) | |
24 | char *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 | ||
44 | char *install(nam, val, tran) | |
45 | char *nam, *val; | |
46 | int 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 | ||
64 | char *copy(s) | |
65 | register 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 | } |