Annotation of 41BSD/cmd/eqn/lookup.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.