dpost.ps: increase linewidth to match groff
[troff.git] / eqn / lookup.c
blob7e5fa89fd83d36a27aaf70b0c68fa70f00aee4d9
1 #include "e.h"
2 #include "y.tab.h"
4 tbl *keytbl[TBLSIZE]; /* key words */
5 tbl *restbl[TBLSIZE]; /* reserved words */
6 tbl *deftbl[TBLSIZE]; /* user-defined names */
8 struct keyword {
9 char *key;
10 int keyval;
11 } keyword[] ={
12 "sub", SUB,
13 "sup", SUP,
14 ".EN", DOTEN,
15 ".EQ", DOTEQ,
16 "from", FROM,
17 "to", TO,
18 "sum", SUM,
19 "hat", HAT,
20 "vec", VEC,
21 "dyad", DYAD,
22 "dot", DOT,
23 "dotdot", DOTDOT,
24 "bar", BAR,
25 "lowbar", LOWBAR,
26 "highbar", HIGHBAR,
27 "tilde", TILDE,
28 "utilde", UTILDE,
29 "under", UNDER,
30 "prod", PROD,
31 "int", INT,
32 "integral", INT,
33 "union", UNION,
34 "inter", INTER,
35 "matrix", MATRIX,
36 "col", COL,
37 "lcol", LCOL,
38 "ccol", CCOL,
39 "rcol", RCOL,
40 "pile", COL, /* synonyms ... */
41 "lpile", LCOL,
42 "cpile", CCOL,
43 "rpile", RCOL,
44 "over", OVER,
45 "sqrt", SQRT,
46 "above", ABOVE,
47 "size", SIZE,
48 "font", FONT,
49 "fat", FAT,
50 "roman", ROMAN,
51 "italic", ITALIC,
52 "bold", BOLD,
53 "left", LEFT,
54 "right", RIGHT,
55 "delim", DELIM,
56 "define", DEFINE,
57 "tdefine", DEFINE,
58 "ndefine", NDEFINE,
59 "ifdef", IFDEF,
60 "gsize", GSIZE,
61 ".gsize", GSIZE,
62 "gfont", GFONT,
63 "include", INCLUDE,
64 "copy", INCLUDE,
65 "space", SPACE,
66 "up", UP,
67 "down", DOWN,
68 "fwd", FWD,
69 "back", BACK,
70 "mark", MARK,
71 "lineup", LINEUP,
72 0, 0
75 struct resword {
76 char *res;
77 char *resval;
78 } resword[] ={
79 ">=", "\\(>=",
80 "<=", "\\(<=",
81 "==", "\\(==",
82 "!=", "\\(!=",
83 "+-", "\\(+-",
84 "->", "\\(->",
85 "<-", "\\(<-",
86 "inf", "\\(if",
87 "infinity", "\\(if",
88 "partial", "\\(pd",
89 "half", "\\f1\\(12\\fP",
90 "prime", "\\f1\\v'.5m'\\s+3\\(fm\\s-3\\v'-.5m'\\fP",
91 "dollar", "\\f1$\\fP",
92 "nothing", "",
93 "times", "\\(mu",
94 "del", "\\(gr",
95 "grad", "\\(gr",
96 "approx", "\\v'-.2m'\\z\\(ap\\v'.25m'\\(ap\\v'-.05m'",
97 "cdot", "\\v'-.3m'.\\v'.3m'",
98 "...", "\\v'-.25m'\\ .\\ .\\ .\\ \\v'.25m'",
99 ",...,", "\\f1,\\fP\\ .\\ .\\ .\\ \\f1,\\fP\\|",
100 "alpha", "\\(*a",
101 "ALPHA", "\\(*A",
102 "beta", "\\(*b",
103 "BETA", "\\(*B",
104 "gamma", "\\(*g",
105 "GAMMA", "\\(*G",
106 "delta", "\\(*d",
107 "DELTA", "\\(*D",
108 "epsilon", "\\(*e",
109 "EPSILON", "\\(*E",
110 "omega", "\\(*w",
111 "OMEGA", "\\(*W",
112 "lambda", "\\(*l",
113 "LAMBDA", "\\(*L",
114 "mu", "\\(*m",
115 "MU", "\\(*M",
116 "nu", "\\(*n",
117 "NU", "\\(*N",
118 "theta", "\\(*h",
119 "THETA", "\\(*H",
120 "phi", "\\(*f",
121 "PHI", "\\(*F",
122 "pi", "\\(*p",
123 "PI", "\\(*P",
124 "sigma", "\\(*s",
125 "SIGMA", "\\(*S",
126 "xi", "\\(*c",
127 "XI", "\\(*C",
128 "zeta", "\\(*z",
129 "ZETA", "\\(*Z",
130 "iota", "\\(*i",
131 "IOTA", "\\(*I",
132 "eta", "\\(*y",
133 "ETA", "\\(*Y",
134 "kappa", "\\(*k",
135 "KAPPA", "\\(*K",
136 "rho", "\\(*r",
137 "RHO", "\\(*R",
138 "tau", "\\(*t",
139 "TAU", "\\(*T",
140 "omicron", "\\(*o",
141 "OMICRON", "\\(*O",
142 "upsilon", "\\(*u",
143 "UPSILON", "\\(*U",
144 "psi", "\\(*q",
145 "PSI", "\\(*Q",
146 "chi", "\\(*x",
147 "CHI", "\\(*X",
148 "and", "\\f1and\\fP",
149 "for", "\\f1for\\fP",
150 "if", "\\f1if\\fP",
151 "Re", "\\f1Re\\fP",
152 "Im", "\\f1Im\\fP",
153 "sin", "\\f1sin\\fP",
154 "cos", "\\f1cos\\fP",
155 "tan", "\\f1tan\\fP",
156 "arc", "\\f1arc\\fP",
157 "sinh", "\\f1sinh\\fP",
158 "coth", "\\f1coth\\fP",
159 "tanh", "\\f1tanh\\fP",
160 "cosh", "\\f1cosh\\fP",
161 "lim", "\\f1lim\\fP",
162 "log", "\\f1log\\fP",
163 "ln", "\\f1ln\\fP",
164 "max", "\\f1max\\fP",
165 "min", "\\f1min\\fP",
166 "exp", "\\f1exp\\fP",
167 "det", "\\f1det\\fP",
168 0, 0
171 int hash(char *s)
173 register unsigned int h;
175 for (h = 0; *s != '\0'; )
176 h += *s++;
177 h %= TBLSIZE;
178 return h;
181 tbl *lookup(tbl **tblp, char *name) /* find name in tbl */
183 register tbl *p;
185 for (p = tblp[hash(name)]; p != NULL; p = p->next)
186 if (strcmp(name, p->name) == 0)
187 return(p);
188 return(NULL);
191 void install(tbl **tblp, char *name, char *cval, int ival) /* install name, vals in tblp */
193 register tbl *p;
194 int h;
196 if ((p = lookup(tblp, name)) == NULL) {
197 p = (tbl *) malloc(sizeof(tbl));
198 if (p == NULL)
199 ERROR "out of space in install" FATAL;
200 h = hash(name); /* bad visibility here */
201 p->name = name;
202 p->next = tblp[h];
203 tblp[h] = p;
205 p->cval = cval;
206 p->ival = ival;
209 void init_tbl(void) /* initialize tables */
211 int i;
212 extern int init_tune(void);
214 for (i = 0; keyword[i].key != NULL; i++)
215 install(keytbl, keyword[i].key, (char *) 0, keyword[i].keyval);
216 for (i = 0; resword[i].res != NULL; i++)
217 install(restbl, resword[i].res, resword[i].resval, 0);
218 init_tune(); /* tuning table done in tuning.c */