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