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