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