Commit | Line | Data |
---|---|---|
0fc6e47b KB |
1 | /*- |
2 | * Copyright (c) 1980 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
1259848a | 6 | */ |
dfd13e7c | 7 | |
72fbef68 | 8 | #ifndef lint |
0fc6e47b KB |
9 | static char sccsid[] = "@(#)lookup.c 5.2 (Berkeley) %G%"; |
10 | #endif /* not lint */ | |
dfd13e7c PK |
11 | |
12 | #include "whoami.h" | |
13 | #include "0.h" | |
14 | ||
270467f1 KM |
15 | struct nl *disptab[077+1]; |
16 | ||
dfd13e7c PK |
17 | /* |
18 | * Lookup is called to | |
19 | * find a symbol in the | |
20 | * block structure symbol | |
21 | * table and returns a pointer to | |
22 | * its namelist entry. | |
23 | */ | |
24 | struct nl * | |
25 | lookup(s) | |
26 | register char *s; | |
27 | { | |
28 | register struct nl *p; | |
72fbef68 | 29 | register struct udinfo; |
dfd13e7c PK |
30 | |
31 | if (s == NIL) { | |
32 | nocascade(); | |
72fbef68 | 33 | return (NLNIL); |
dfd13e7c PK |
34 | } |
35 | p = lookup1(s); | |
72fbef68 | 36 | if (p == NLNIL) { |
dfd13e7c | 37 | derror("%s is undefined", s); |
72fbef68 | 38 | return (NLNIL); |
dfd13e7c PK |
39 | } |
40 | if (p->class == FVAR) { | |
41 | p = p->chain; | |
42 | bn--; | |
43 | } | |
44 | return (p); | |
45 | } | |
46 | ||
47 | #ifndef PI0 | |
48 | int flagwas; | |
49 | #endif | |
50 | /* | |
51 | * Lookup1 is an internal lookup. | |
52 | * It is not an error to call lookup1 | |
53 | * if the symbol is not defined. Also | |
54 | * lookup1 will return FVARs while | |
55 | * lookup never will, thus asgnop | |
56 | * calls it when it thinks you are | |
57 | * assigning to the function variable. | |
58 | */ | |
59 | ||
60 | struct nl * | |
61 | lookup1(s) | |
62 | register char *s; | |
63 | { | |
64 | register struct nl *p; | |
65 | #ifndef PI0 | |
66 | register struct nl *q; | |
67 | #endif | |
68 | register int i; | |
69 | ||
70 | if (s == NIL) | |
72fbef68 | 71 | return (NLNIL); |
dfd13e7c PK |
72 | bn = cbn; |
73 | #ifndef PI0 | |
74 | /* | |
75 | * We first check the field names | |
76 | * of the currently active with | |
77 | * statements (expensive since they | |
78 | * are not hashed). | |
79 | */ | |
72fbef68 | 80 | for (p = withlist; p != NLNIL; p = p->nl_next) { |
dfd13e7c | 81 | q = p->type; |
72fbef68 | 82 | if (q == NLNIL) |
dfd13e7c PK |
83 | continue; |
84 | if (reclook(q, s) != NIL) | |
85 | /* | |
86 | * Return the WITHPTR, lvalue understands. | |
87 | */ | |
88 | return (p); | |
89 | } | |
90 | #endif | |
91 | /* | |
92 | * Symbol table is a 64 way hash | |
93 | * on the low bits of the character | |
94 | * pointer value. (Simple, but effective) | |
95 | */ | |
96 | i = (int) s & 077; | |
72fbef68 | 97 | for (p = disptab[i]; p != NLNIL; p = p->nl_next) |
dfd13e7c PK |
98 | if (p->symbol == s && p->class != FIELD && p->class != BADUSE) { |
99 | bn = (p->nl_block & 037); | |
100 | #ifndef PI0 | |
101 | flagwas = p->nl_flags; | |
102 | p->nl_flags |= NUSED; | |
103 | #endif | |
104 | return (p); | |
105 | } | |
72fbef68 | 106 | return (NLNIL); |
dfd13e7c PK |
107 | } |
108 | ||
109 | #ifndef PI01 | |
110 | nlfund(sp) | |
111 | char *sp; | |
112 | { | |
113 | register struct nl *p; | |
114 | register int i; | |
115 | ||
116 | i = (int) sp & 077; | |
72fbef68 | 117 | for (p = disptab[i]; p != NLNIL; p = p->nl_next) |
dfd13e7c PK |
118 | if (p->symbol == sp && (p->nl_block & 037) == 0) |
119 | return (nloff(p)); | |
120 | return (0); | |
121 | } | |
122 | #endif |