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