1 /*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)lookup.c 4.3 (Berkeley) 04/17/91";
10 #endif /* not lint */
11
12 # include "e.h"
13 #include "e.def"
14
15 #define TBLSIZE 100
16
17 tbl *keytbl[TBLSIZE]; /* key words */
18 tbl *restbl[TBLSIZE]; /* reserved words */
19 tbl *deftbl[TBLSIZE]; /* user-defined names */
20
21 struct {
22 char *key;
23 int keyval;
24 } keyword[] ={
25 "sub", SUB,
26 "sup", SUP,
27 ".EN", EOF,
28 "from", FROM,
29 "to", TO,
30 "sum", SUM,
31 "hat", HAT,
32 "vec", VEC,
33 "dyad", DYAD,
34 "dot", DOT,
35 "dotdot", DOTDOT,
36 "bar", BAR,
37 "tilde", TILDE,
38 "under", UNDER,
39 "prod", PROD,
40 "int", INT,
41 "integral", INT,
42 "union", UNION,
43 "inter", INTER,
44 "pile", PILE,
45 "lpile", LPILE,
46 "cpile", CPILE,
47 "rpile", RPILE,
48 "over", OVER,
49 "sqrt", SQRT,
50 "above", ABOVE,
51 "size", SIZE,
52 "font", FONT,
53 "fat", FAT,
54 "roman", ROMAN,
55 "italic", ITALIC,
56 "bold", BOLD,
57 "left", LEFT,
58 "right", RIGHT,
59 "delim", DELIM,
60 "define", DEFINE,
61
62 #ifdef NEQN /* make ndefine synonym for define, tdefine a no-op */
63
64 "tdefine", TDEFINE,
65 "ndefine", DEFINE,
66
67 #else /* tdefine = define, ndefine = no-op */
68
69 "tdefine", DEFINE,
70 "ndefine", NDEFINE,
71
72 #endif
73
74 "gsize", GSIZE,
75 ".gsize", GSIZE,
76 "gfont", GFONT,
77 "include", INCLUDE,
78 "up", UP,
79 "down", DOWN,
80 "fwd", FWD,
81 "back", BACK,
82 "mark", MARK,
83 "lineup", LINEUP,
84 "matrix", MATRIX,
85 "col", COL,
86 "lcol", LCOL,
87 "ccol", CCOL,
88 "rcol", RCOL,
89 0, 0
90 };
91
92 struct {
93 char *res;
94 char *resval;
95 } resword[] ={
96 ">=", "\\(>=",
97 "<=", "\\(<=",
98 "==", "\\(==",
99 "!=", "\\(!=",
100 "+-", "\\(+-",
101 "->", "\\(->",
102 "<-", "\\(<-",
103 "inf", "\\(if",
104 "infinity", "\\(if",
105 "partial", "\\(pd",
106 "half", "\\f1\\(12\\fP",
107 "prime", "\\f1\\(fm\\fP",
108 "dollar", "\\f1$\\fP",
109 "nothing", "",
110 "times", "\\(mu",
111 "del", "\\(gr",
112 "grad", "\\(gr",
113 #ifdef NEQN
114 "<<", "<<",
115 ">>", ">>",
116 "approx", "~\b\\d~\\u",
117 "cdot", "\\v'-.5'.\\v'.5'",
118 "...", "...",
119 ",...,", ",...,",
120 #else
121 "<<", "<\\h'-.3m'<",
122 ">>", ">\\h'-.3m'>",
123 "approx", "\\v'-.2m'\\z\\(ap\\v'.25m'\\(ap\\v'-.05m'",
124 "cdot", "\\v'-.3m'.\\v'.3m'",
125 "...", "\\v'-.3m'\\ .\\ .\\ .\\ \\v'.3m'",
126 ",...,", ",\\ .\\ .\\ .\\ ,\\|",
127 #endif
128
129 "alpha", "\\(*a",
130 "beta", "\\(*b",
131 "gamma", "\\(*g",
132 "GAMMA", "\\(*G",
133 "delta", "\\(*d",
134 "DELTA", "\\(*D",
135 "epsilon", "\\(*e",
136 "EPSILON", "\\f1E\\fP",
137 "omega", "\\(*w",
138 "OMEGA", "\\(*W",
139 "lambda", "\\(*l",
140 "LAMBDA", "\\(*L",
141 "mu", "\\(*m",
142 "nu", "\\(*n",
143 "theta", "\\(*h",
144 "THETA", "\\(*H",
145 "phi", "\\(*f",
146 "PHI", "\\(*F",
147 "pi", "\\(*p",
148 "PI", "\\(*P",
149 "sigma", "\\(*s",
150 "SIGMA", "\\(*S",
151 "xi", "\\(*c",
152 "XI", "\\(*C",
153 "zeta", "\\(*z",
154 "iota", "\\(*i",
155 "eta", "\\(*y",
156 "kappa", "\\(*k",
157 "rho", "\\(*r",
158 "tau", "\\(*t",
159 "omicron", "\\(*o",
160 "upsilon", "\\(*u",
161 "UPSILON", "\\(*U",
162 "psi", "\\(*q",
163 "PSI", "\\(*Q",
164 "chi", "\\(*x",
165 "and", "\\f1and\\fP",
166 "for", "\\f1for\\fP",
167 "if", "\\f1if\\fP",
168 "Re", "\\f1Re\\fP",
169 "Im", "\\f1Im\\fP",
170 "sin", "\\f1sin\\fP",
171 "cos", "\\f1cos\\fP",
172 "tan", "\\f1tan\\fP",
173 "sec", "\\f1sec\\fP",
174 "csc", "\\f1csc\\fP",
175 "arc", "\\f1arc\\fP",
176 "asin", "\\f1asin\\fP",
177 "acos", "\\f1acos\\fP",
178 "atan", "\\f1atan\\fP",
179 "asec", "\\f1asec\\fP",
180 "acsc", "\\f1acsc\\fP",
181 "sinh", "\\f1sinh\\fP",
182 "coth", "\\f1coth\\fP",
183 "tanh", "\\f1tanh\\fP",
184 "cosh", "\\f1cosh\\fP",
185 "lim", "\\f1lim\\fP",
186 "log", "\\f1log\\fP",
187 "max", "\\f1max\\fP",
188 "min", "\\f1min\\fP",
189 "ln", "\\f1ln\\fP",
190 "exp", "\\f1exp\\fP",
191 "det", "\\f1det\\fP",
192 0, 0
193 };
194
lookup(tblp,name,defn)195 tbl *lookup(tblp, name, defn) /* find name in tbl. if defn non-null, install */
196 tbl **tblp;
197 char *name, *defn;
198 {
199 register tbl *p;
200 register int h;
201 register char *s = name;
202 char *malloc();
203
204 for (h = 0; *s != '\0'; )
205 h += *s++;
206 h %= TBLSIZE;
207
208 for (p = tblp[h]; p != NULL; p = p->next)
209 if (strcmp(name, p->name) == 0) { /* found it */
210 if (defn != NULL)
211 p->defn = defn;
212 return(p);
213 }
214 /* didn't find it */
215 if (defn == NULL)
216 return(NULL);
217 p = (tbl *) malloc(sizeof (tbl));
218 if (p == NULL)
219 error(FATAL, "out of space in lookup");
220 p->name = name;
221 p->defn = defn;
222 p->next = tblp[h];
223 tblp[h] = p;
224 return(p);
225 }
226
init_tbl()227 init_tbl() /* initialize all tables */
228 {
229 int i;
230
231 for (i = 0; keyword[i].key != NULL; i++)
232 lookup(keytbl, keyword[i].key, keyword[i].keyval);
233 for (i = 0; resword[i].res != NULL; i++)
234 lookup(restbl, resword[i].res, resword[i].resval);
235 }
236