eqn: adjust the padding space around commas
[troff.git] / eqn / lookup.c
blob473824b2270ad31f949a9dd2fbe65ffd8e434f8b
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 "inf", "\\(if",
85 "infinity", "\\(if",
86 "partial", "\\(pd",
87 "half", "\\f1\\(12\\fP",
88 "prime", "\\f1\\v'.5m'\\s+3\\(fm\\s-3\\v'-.5m'\\fP",
89 "dollar", "\\f1$\\fP",
90 "nothing", "",
91 "times", "\\(mu",
92 "del", "\\(gr",
93 "grad", "\\(gr",
94 "approx", "\\v'-.2m'\\z\\(ap\\v'.25m'\\(ap\\v'-.05m'",
95 "cdot", "\\v'-.3m'.\\v'.3m'",
96 "...", "\\v'-.25m'\\ .\\ .\\ .\\ \\v'.25m'",
97 ",...,", "\\f1,\\fP\\ .\\ .\\ .\\ \\f1,\\fP\\|",
98 "alpha", "\\(*a",
99 "ALPHA", "\\(*A",
100 "beta", "\\(*b",
101 "BETA", "\\(*B",
102 "gamma", "\\(*g",
103 "GAMMA", "\\(*G",
104 "delta", "\\(*d",
105 "DELTA", "\\(*D",
106 "epsilon", "\\(*e",
107 "EPSILON", "\\(*E",
108 "omega", "\\(*w",
109 "OMEGA", "\\(*W",
110 "lambda", "\\(*l",
111 "LAMBDA", "\\(*L",
112 "mu", "\\(*m",
113 "MU", "\\(*M",
114 "nu", "\\(*n",
115 "NU", "\\(*N",
116 "theta", "\\(*h",
117 "THETA", "\\(*H",
118 "phi", "\\(*f",
119 "PHI", "\\(*F",
120 "pi", "\\(*p",
121 "PI", "\\(*P",
122 "sigma", "\\(*s",
123 "SIGMA", "\\(*S",
124 "xi", "\\(*c",
125 "XI", "\\(*C",
126 "zeta", "\\(*z",
127 "ZETA", "\\(*Z",
128 "iota", "\\(*i",
129 "IOTA", "\\(*I",
130 "eta", "\\(*y",
131 "ETA", "\\(*Y",
132 "kappa", "\\(*k",
133 "KAPPA", "\\(*K",
134 "rho", "\\(*r",
135 "RHO", "\\(*R",
136 "tau", "\\(*t",
137 "TAU", "\\(*T",
138 "omicron", "\\(*o",
139 "OMICRON", "\\(*O",
140 "upsilon", "\\(*u",
141 "UPSILON", "\\(*U",
142 "psi", "\\(*q",
143 "PSI", "\\(*Q",
144 "chi", "\\(*x",
145 "CHI", "\\(*X",
146 "and", "\\f1and\\fP",
147 "for", "\\f1for\\fP",
148 "if", "\\f1if\\fP",
149 "Re", "\\f1Re\\fP",
150 "Im", "\\f1Im\\fP",
151 "sin", "\\f1sin\\fP",
152 "cos", "\\f1cos\\fP",
153 "tan", "\\f1tan\\fP",
154 "arc", "\\f1arc\\fP",
155 "sinh", "\\f1sinh\\fP",
156 "coth", "\\f1coth\\fP",
157 "tanh", "\\f1tanh\\fP",
158 "cosh", "\\f1cosh\\fP",
159 "lim", "\\f1lim\\fP",
160 "log", "\\f1log\\fP",
161 "ln", "\\f1ln\\fP",
162 "max", "\\f1max\\fP",
163 "min", "\\f1min\\fP",
164 "exp", "\\f1exp\\fP",
165 "det", "\\f1det\\fP",
166 0, 0
169 int hash(char *s)
171 register unsigned int h;
173 for (h = 0; *s != '\0'; )
174 h += *s++;
175 h %= TBLSIZE;
176 return h;
179 tbl *lookup(tbl **tblp, char *name) /* find name in tbl */
181 register tbl *p;
183 for (p = tblp[hash(name)]; p != NULL; p = p->next)
184 if (strcmp(name, p->name) == 0)
185 return(p);
186 return(NULL);
189 void install(tbl **tblp, char *name, char *cval, int ival) /* install name, vals in tblp */
191 register tbl *p;
192 int h;
194 if ((p = lookup(tblp, name)) == NULL) {
195 p = (tbl *) malloc(sizeof(tbl));
196 if (p == NULL)
197 ERROR "out of space in install" FATAL;
198 h = hash(name); /* bad visibility here */
199 p->name = name;
200 p->next = tblp[h];
201 tblp[h] = p;
203 p->cval = cval;
204 p->ival = ival;
207 void init_tbl(void) /* initialize tables */
209 int i;
210 extern int init_tune(void);
212 for (i = 0; keyword[i].key != NULL; i++)
213 install(keytbl, keyword[i].key, (char *) 0, keyword[i].keyval);
214 for (i = 0; resword[i].res != NULL; i++)
215 install(restbl, resword[i].res, resword[i].resval, 0);
216 init_tune(); /* tuning table done in tuning.c */