1779fc935Sceastha /* 2779fc935Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3779fc935Sceastha * Use is subject to license terms. 4779fc935Sceastha */ 5779fc935Sceastha 67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 77c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate /* 107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 137c478bd9Sstevel@tonic-gate */ 147c478bd9Sstevel@tonic-gate 15779fc935Sceastha #pragma ident "%Z%%M% %I% %E% SMI" 167c478bd9Sstevel@tonic-gate 177c478bd9Sstevel@tonic-gate #include "e.h" 187c478bd9Sstevel@tonic-gate #include "e.def" 197c478bd9Sstevel@tonic-gate #include <locale.h> 207c478bd9Sstevel@tonic-gate 217c478bd9Sstevel@tonic-gate #define TBLSIZE 100 227c478bd9Sstevel@tonic-gate 237c478bd9Sstevel@tonic-gate tbl *keytbl[TBLSIZE]; /* key words */ 247c478bd9Sstevel@tonic-gate tbl *restbl[TBLSIZE]; /* reserved words */ 257c478bd9Sstevel@tonic-gate tbl *deftbl[TBLSIZE]; /* user-defined names */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate struct { 287c478bd9Sstevel@tonic-gate char *key; 297c478bd9Sstevel@tonic-gate int keyval; 307c478bd9Sstevel@tonic-gate } keyword[] = { 317c478bd9Sstevel@tonic-gate "sub", SUB, 327c478bd9Sstevel@tonic-gate "sup", SUP, 337c478bd9Sstevel@tonic-gate ".EN", EOF, 347c478bd9Sstevel@tonic-gate "from", FROM, 357c478bd9Sstevel@tonic-gate "to", TO, 367c478bd9Sstevel@tonic-gate "sum", SUM, 377c478bd9Sstevel@tonic-gate "hat", HAT, 387c478bd9Sstevel@tonic-gate "vec", VEC, 397c478bd9Sstevel@tonic-gate "dyad", DYAD, 407c478bd9Sstevel@tonic-gate "dot", DOT, 417c478bd9Sstevel@tonic-gate "dotdot", DOTDOT, 427c478bd9Sstevel@tonic-gate "bar", BAR, 437c478bd9Sstevel@tonic-gate "tilde", TILDE, 447c478bd9Sstevel@tonic-gate "under", UNDER, 457c478bd9Sstevel@tonic-gate "prod", PROD, 467c478bd9Sstevel@tonic-gate "int", INT, 477c478bd9Sstevel@tonic-gate "integral", INT, 487c478bd9Sstevel@tonic-gate "union", UNION, 497c478bd9Sstevel@tonic-gate "inter", INTER, 507c478bd9Sstevel@tonic-gate "pile", PILE, 517c478bd9Sstevel@tonic-gate "lpile", LPILE, 527c478bd9Sstevel@tonic-gate "cpile", CPILE, 537c478bd9Sstevel@tonic-gate "rpile", RPILE, 547c478bd9Sstevel@tonic-gate "over", OVER, 557c478bd9Sstevel@tonic-gate "sqrt", SQRT, 567c478bd9Sstevel@tonic-gate "above", ABOVE, 577c478bd9Sstevel@tonic-gate "size", SIZE, 587c478bd9Sstevel@tonic-gate "font", FONT, 597c478bd9Sstevel@tonic-gate "fat", FAT, 607c478bd9Sstevel@tonic-gate "roman", ROMAN, 617c478bd9Sstevel@tonic-gate "italic", ITALIC, 627c478bd9Sstevel@tonic-gate "bold", BOLD, 637c478bd9Sstevel@tonic-gate "left", LEFT, 647c478bd9Sstevel@tonic-gate "right", RIGHT, 657c478bd9Sstevel@tonic-gate "delim", DELIM, 667c478bd9Sstevel@tonic-gate "define", DEFINE, 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #ifdef NEQN /* make ndefine synonym for define, tdefine a no-op */ 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate "tdefine", TDEFINE, 717c478bd9Sstevel@tonic-gate "ndefine", DEFINE, 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #else /* tdefine = define, ndefine = no-op */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate "tdefine", DEFINE, 767c478bd9Sstevel@tonic-gate "ndefine", NDEFINE, 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate #endif 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate "gsize", GSIZE, 817c478bd9Sstevel@tonic-gate ".gsize", GSIZE, 827c478bd9Sstevel@tonic-gate "gfont", GFONT, 837c478bd9Sstevel@tonic-gate "include", INCLUDE, 847c478bd9Sstevel@tonic-gate "up", UP, 857c478bd9Sstevel@tonic-gate "down", DOWN, 867c478bd9Sstevel@tonic-gate "fwd", FWD, 877c478bd9Sstevel@tonic-gate "back", BACK, 887c478bd9Sstevel@tonic-gate "mark", MARK, 897c478bd9Sstevel@tonic-gate "lineup", LINEUP, 907c478bd9Sstevel@tonic-gate "matrix", MATRIX, 917c478bd9Sstevel@tonic-gate "col", COL, 927c478bd9Sstevel@tonic-gate "lcol", LCOL, 937c478bd9Sstevel@tonic-gate "ccol", CCOL, 947c478bd9Sstevel@tonic-gate "rcol", RCOL, 957c478bd9Sstevel@tonic-gate 0, 0 967c478bd9Sstevel@tonic-gate }; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate struct { 997c478bd9Sstevel@tonic-gate char *res; 1007c478bd9Sstevel@tonic-gate char *resval; 1017c478bd9Sstevel@tonic-gate } resword[] = { 1027c478bd9Sstevel@tonic-gate ">=", "\\(>=", 1037c478bd9Sstevel@tonic-gate "<=", "\\(<=", 1047c478bd9Sstevel@tonic-gate "==", "\\(==", 1057c478bd9Sstevel@tonic-gate "!=", "\\(!=", 1067c478bd9Sstevel@tonic-gate "+-", "\\(+-", 1077c478bd9Sstevel@tonic-gate "->", "\\(->", 1087c478bd9Sstevel@tonic-gate "<-", "\\(<-", 1097c478bd9Sstevel@tonic-gate "inf", "\\(if", 1107c478bd9Sstevel@tonic-gate "infinity", "\\(if", 1117c478bd9Sstevel@tonic-gate "partial", "\\(pd", 1127c478bd9Sstevel@tonic-gate "half", "\\f1\\(12\\fP", 1137c478bd9Sstevel@tonic-gate "prime", "\\f1\\(fm\\fP", 1147c478bd9Sstevel@tonic-gate "dollar", "\\f1$\\fP", 1157c478bd9Sstevel@tonic-gate "nothing", "", 1167c478bd9Sstevel@tonic-gate "times", "\\(mu", 1177c478bd9Sstevel@tonic-gate "del", "\\(gr", 1187c478bd9Sstevel@tonic-gate "grad", "\\(gr", 1197c478bd9Sstevel@tonic-gate #ifdef NEQN 1207c478bd9Sstevel@tonic-gate "<<", "<<", 1217c478bd9Sstevel@tonic-gate ">>", ">>", 1227c478bd9Sstevel@tonic-gate "approx", "~\b\\d~\\u", 1237c478bd9Sstevel@tonic-gate "cdot", "\\v'-.5'.\\v'.5'", 1247c478bd9Sstevel@tonic-gate "...", "...", 1257c478bd9Sstevel@tonic-gate ",...,", ",...,", 1267c478bd9Sstevel@tonic-gate #else 1277c478bd9Sstevel@tonic-gate "<<", "<\\h'-.3m'<", 1287c478bd9Sstevel@tonic-gate ">>", ">\\h'-.3m'>", 1297c478bd9Sstevel@tonic-gate "approx", "\\v'-.2m'\\z\\(ap\\v'.25m'\\(ap\\v'-.05m'", 1307c478bd9Sstevel@tonic-gate "cdot", "\\v'-.3m'.\\v'.3m'", 1317c478bd9Sstevel@tonic-gate "...", "\\v'-.3m'\\ .\\ .\\ .\\ \\v'.3m'", 1327c478bd9Sstevel@tonic-gate ",...,", ",\\ .\\ .\\ .\\ ,\\|", 1337c478bd9Sstevel@tonic-gate #endif 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate "alpha", "\\(*a", 1367c478bd9Sstevel@tonic-gate "beta", "\\(*b", 1377c478bd9Sstevel@tonic-gate "gamma", "\\(*g", 1387c478bd9Sstevel@tonic-gate "GAMMA", "\\(*G", 1397c478bd9Sstevel@tonic-gate "delta", "\\(*d", 1407c478bd9Sstevel@tonic-gate "DELTA", "\\(*D", 1417c478bd9Sstevel@tonic-gate "epsilon", "\\(*e", 1427c478bd9Sstevel@tonic-gate "EPSILON", "\\f1E\\fP", 1437c478bd9Sstevel@tonic-gate "omega", "\\(*w", 1447c478bd9Sstevel@tonic-gate "OMEGA", "\\(*W", 1457c478bd9Sstevel@tonic-gate "lambda", "\\(*l", 1467c478bd9Sstevel@tonic-gate "LAMBDA", "\\(*L", 1477c478bd9Sstevel@tonic-gate "mu", "\\(*m", 1487c478bd9Sstevel@tonic-gate "nu", "\\(*n", 1497c478bd9Sstevel@tonic-gate "theta", "\\(*h", 1507c478bd9Sstevel@tonic-gate "THETA", "\\(*H", 1517c478bd9Sstevel@tonic-gate "phi", "\\(*f", 1527c478bd9Sstevel@tonic-gate "PHI", "\\(*F", 1537c478bd9Sstevel@tonic-gate "pi", "\\(*p", 1547c478bd9Sstevel@tonic-gate "PI", "\\(*P", 1557c478bd9Sstevel@tonic-gate "sigma", "\\(*s", 1567c478bd9Sstevel@tonic-gate "SIGMA", "\\(*S", 1577c478bd9Sstevel@tonic-gate "xi", "\\(*c", 1587c478bd9Sstevel@tonic-gate "XI", "\\(*C", 1597c478bd9Sstevel@tonic-gate "zeta", "\\(*z", 1607c478bd9Sstevel@tonic-gate "iota", "\\(*i", 1617c478bd9Sstevel@tonic-gate "eta", "\\(*y", 1627c478bd9Sstevel@tonic-gate "kappa", "\\(*k", 1637c478bd9Sstevel@tonic-gate "rho", "\\(*r", 1647c478bd9Sstevel@tonic-gate "tau", "\\(*t", 1657c478bd9Sstevel@tonic-gate "omicron", "\\(*o", 1667c478bd9Sstevel@tonic-gate "upsilon", "\\(*u", 1677c478bd9Sstevel@tonic-gate "UPSILON", "\\(*U", 1687c478bd9Sstevel@tonic-gate "psi", "\\(*q", 1697c478bd9Sstevel@tonic-gate "PSI", "\\(*Q", 1707c478bd9Sstevel@tonic-gate "chi", "\\(*x", 1717c478bd9Sstevel@tonic-gate "and", "\\f1and\\fP", 1727c478bd9Sstevel@tonic-gate "for", "\\f1for\\fP", 1737c478bd9Sstevel@tonic-gate "if", "\\f1if\\fP", 1747c478bd9Sstevel@tonic-gate "Re", "\\f1Re\\fP", 1757c478bd9Sstevel@tonic-gate "Im", "\\f1Im\\fP", 1767c478bd9Sstevel@tonic-gate "sin", "\\f1sin\\fP", 1777c478bd9Sstevel@tonic-gate "cos", "\\f1cos\\fP", 1787c478bd9Sstevel@tonic-gate "tan", "\\f1tan\\fP", 1797c478bd9Sstevel@tonic-gate "sec", "\\f1sec\\fP", 1807c478bd9Sstevel@tonic-gate "csc", "\\f1csc\\fP", 1817c478bd9Sstevel@tonic-gate "arc", "\\f1arc\\fP", 1827c478bd9Sstevel@tonic-gate "asin", "\\f1asin\\fP", 1837c478bd9Sstevel@tonic-gate "acos", "\\f1acos\\fP", 1847c478bd9Sstevel@tonic-gate "atan", "\\f1atan\\fP", 1857c478bd9Sstevel@tonic-gate "asec", "\\f1asec\\fP", 1867c478bd9Sstevel@tonic-gate "acsc", "\\f1acsc\\fP", 1877c478bd9Sstevel@tonic-gate "sinh", "\\f1sinh\\fP", 1887c478bd9Sstevel@tonic-gate "coth", "\\f1coth\\fP", 1897c478bd9Sstevel@tonic-gate "tanh", "\\f1tanh\\fP", 1907c478bd9Sstevel@tonic-gate "cosh", "\\f1cosh\\fP", 1917c478bd9Sstevel@tonic-gate "lim", "\\f1lim\\fP", 1927c478bd9Sstevel@tonic-gate "log", "\\f1log\\fP", 1937c478bd9Sstevel@tonic-gate "max", "\\f1max\\fP", 1947c478bd9Sstevel@tonic-gate "min", "\\f1min\\fP", 1957c478bd9Sstevel@tonic-gate "ln", "\\f1ln\\fP", 1967c478bd9Sstevel@tonic-gate "exp", "\\f1exp\\fP", 1977c478bd9Sstevel@tonic-gate "det", "\\f1det\\fP", 1987c478bd9Sstevel@tonic-gate 0, 0 1997c478bd9Sstevel@tonic-gate }; 2007c478bd9Sstevel@tonic-gate 201779fc935Sceastha /* find name in tbl. if defn non-null, install */ 202779fc935Sceastha tbl * 203*b5cda42eSceastha lookup(tbl *tblp[], char *name, char *defn) 2047c478bd9Sstevel@tonic-gate { 205779fc935Sceastha tbl *p; 206779fc935Sceastha int h; 207779fc935Sceastha unsigned char *s = (unsigned char *)name; 2087c478bd9Sstevel@tonic-gate char *malloc(); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate for (h = 0; *s != '\0'; ) 2117c478bd9Sstevel@tonic-gate h += *s++; 2127c478bd9Sstevel@tonic-gate h %= TBLSIZE; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate for (p = tblp[h]; p != NULL; p = p->next) 2157c478bd9Sstevel@tonic-gate if (strcmp(name, p->name) == 0) { /* found it */ 2167c478bd9Sstevel@tonic-gate if (defn != NULL) 2177c478bd9Sstevel@tonic-gate p->defn = defn; 2187c478bd9Sstevel@tonic-gate return (p); 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate /* didn't find it */ 2217c478bd9Sstevel@tonic-gate if (defn == NULL) 2227c478bd9Sstevel@tonic-gate return (NULL); 2237c478bd9Sstevel@tonic-gate p = (tbl *) malloc(sizeof (tbl)); 2247c478bd9Sstevel@tonic-gate if (p == NULL) 225779fc935Sceastha error(FATAL, gettext("out of space in lookup"), NULL); 2267c478bd9Sstevel@tonic-gate p->name = name; 2277c478bd9Sstevel@tonic-gate p->defn = defn; 2287c478bd9Sstevel@tonic-gate p->next = tblp[h]; 2297c478bd9Sstevel@tonic-gate tblp[h] = p; 2307c478bd9Sstevel@tonic-gate return (p); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 233779fc935Sceastha void 234779fc935Sceastha init_tbl(void) /* initialize all tables */ 2357c478bd9Sstevel@tonic-gate { 2367c478bd9Sstevel@tonic-gate int i; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate for (i = 0; keyword[i].key != NULL; i++) 239779fc935Sceastha lookup(keytbl, keyword[i].key, (char *)keyword[i].keyval); 2407c478bd9Sstevel@tonic-gate for (i = 0; resword[i].res != NULL; i++) 2417c478bd9Sstevel@tonic-gate lookup(restbl, resword[i].res, resword[i].resval); 2427c478bd9Sstevel@tonic-gate } 243