Annotation of researchv9/cmd/eqn/lookup.c, revision 1.1.1.1

1.1       root        1: # include "e.h"
                      2: #include "y.tab.h"
                      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",          DOTEN,
                     17:        ".EQ",          DOTEQ, 
                     18:        "from",         FROM, 
                     19:        "to",           TO, 
                     20:        "sum",          SUM, 
                     21:        "hat",          HAT, 
                     22:        "vec",          VEC, 
                     23:        "dyad",         DYAD, 
                     24:        "dot",          DOT, 
                     25:        "dotdot",       DOTDOT, 
                     26:        "bar",          BAR,
                     27:        "lowbar",       LOWBAR,
                     28:        "highbar",      HIGHBAR, 
                     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:        "matrix",       MATRIX, 
                     38:        "col",          COL, 
                     39:        "lcol",         LCOL, 
                     40:        "ccol",         CCOL, 
                     41:        "rcol",         RCOL, 
                     42:        "pile",         COL,    /* synonyms ... */ 
                     43:        "lpile",        LCOL, 
                     44:        "cpile",        CCOL, 
                     45:        "rpile",        RCOL, 
                     46:        "over",         OVER, 
                     47:        "sqrt",         SQRT, 
                     48:        "above",        ABOVE, 
                     49:        "size",         SIZE, 
                     50:        "font",         FONT, 
                     51:        "fat",          FAT, 
                     52:        "roman",        ROMAN, 
                     53:        "italic",       ITALIC, 
                     54:        "bold",         BOLD, 
                     55:        "left",         LEFT, 
                     56:        "right",        RIGHT, 
                     57:        "delim",        DELIM, 
                     58:        "define",       DEFINE, 
                     59: 
                     60: #ifdef NEQN    /* make ndefine synonym for define, tdefine a no-op */
                     61: 
                     62:        "tdefine",      TDEFINE,
                     63:        "ndefine",      DEFINE,
                     64: 
                     65: #else          /* tdefine = define, ndefine = no-op */
                     66: 
                     67:        "tdefine",      DEFINE, 
                     68:        "ndefine",      NDEFINE, 
                     69: 
                     70: #endif
                     71: 
                     72:        "ifdef",        IFDEF,
                     73:        "gsize",        GSIZE, 
                     74:        ".gsize",       GSIZE, 
                     75:        "gfont",        GFONT, 
                     76:        "include",      INCLUDE, 
                     77:        "copy",         INCLUDE, 
                     78:        "space",        SPACE,
                     79:        "up",           UP, 
                     80:        "down",         DOWN, 
                     81:        "fwd",          FWD, 
                     82:        "back",         BACK, 
                     83:        "mark",         MARK, 
                     84:        "lineup",       LINEUP, 
                     85:        0,      0
                     86: };
                     87: 
                     88: struct {
                     89:        char    *res;
                     90:        char    *resval;
                     91: } resword[]    ={
                     92:        ">=",           "\\(>=",
                     93:        "<=",           "\\(<=",
                     94:        "==",           "\\(==",
                     95:        "!=",           "\\(!=",
                     96:        "+-",           "\\(+-",
                     97:        "->",           "\\(->",
                     98:        "<-",           "\\(<-",
                     99:        "inf",          "\\(if",
                    100:        "infinity",     "\\(if",
                    101:        "partial",      "\\(pd",
                    102:        "half",         "\\f1\\(12\\fP",
                    103:        "prime",        "\\f1\\v'.5m'\\s+3\\(fm\\s-3\\v'-.5m'\\fP",
                    104:        "dollar",       "\\f1$\\fP",
                    105:        "nothing",      "",
                    106:        "times",        "\\(mu",
                    107:        "del",          "\\(gr",
                    108:        "grad",         "\\(gr",
                    109: 
                    110: #ifdef NEQN
                    111:        "<<",           "<<",
                    112:        ">>",           ">>",
                    113:        "approx",       "~\b\\d~\\u",
                    114:        "cdot",         "\\v'-.5'.\\v'.5'",
                    115:        "...",          "...",
                    116:        ",...,",        ",...,",
                    117: #else
                    118:        "<<",           "<\\h'-.3m'<",
                    119:        ">>",           ">\\h'-.3m'>",
                    120:        "approx",       "\\v'-.2m'\\z\\(ap\\v'.25m'\\(ap\\v'-.05m'",
                    121:        "cdot",         "\\v'-.3m'.\\v'.3m'",
                    122:        "...",          "\\v'-.3m'\\ .\\ .\\ .\\ \\v'.3m'",
                    123:        ",...,",        "\\f1,\\fP\\ .\\ .\\ .\\ \\f1,\\fP\\|",
                    124: #endif
                    125: 
                    126:        "alpha",        "\\(*a",
                    127:        "beta",         "\\(*b",
                    128:        "gamma",        "\\(*g",
                    129:        "GAMMA",        "\\(*G",
                    130:        "delta",        "\\(*d",
                    131:        "DELTA",        "\\(*D",
                    132:        "epsilon",      "\\(*e",
                    133:        "EPSILON",      "\\f1E\\fP",
                    134:        "omega",        "\\(*w",
                    135:        "OMEGA",        "\\(*W",
                    136:        "lambda",       "\\(*l",
                    137:        "LAMBDA",       "\\(*L",
                    138:        "mu",           "\\(*m",
                    139:        "nu",           "\\(*n",
                    140:        "theta",        "\\(*h",
                    141:        "THETA",        "\\(*H",
                    142:        "phi",          "\\(*f",
                    143:        "PHI",          "\\(*F",
                    144:        "pi",           "\\(*p",
                    145:        "PI",           "\\(*P",
                    146:        "sigma",        "\\(*s",
                    147:        "SIGMA",        "\\(*S",
                    148:        "xi",           "\\(*c",
                    149:        "XI",           "\\(*C",
                    150:        "zeta",         "\\(*z",
                    151:        "iota",         "\\(*i",
                    152:        "eta",          "\\(*y",
                    153:        "kappa",        "\\(*k",
                    154:        "rho",          "\\(*r",
                    155:        "tau",          "\\(*t",
                    156:        "omicron",      "\\(*o",
                    157:        "upsilon",      "\\(*u",
                    158:        "UPSILON",      "\\(*U",
                    159:        "psi",          "\\(*q",
                    160:        "PSI",          "\\(*Q",
                    161:        "chi",          "\\(*x",
                    162:        "and",          "\\f1and\\fP",
                    163:        "for",          "\\f1for\\fP",
                    164:        "if",           "\\f1if\\fP",
                    165:        "Re",           "\\f1Re\\fP",
                    166:        "Im",           "\\f1Im\\fP",
                    167:        "sin",          "\\f1sin\\fP",
                    168:        "cos",          "\\f1cos\\fP",
                    169:        "tan",          "\\f1tan\\fP",
                    170:        "arc",          "\\f1arc\\fP",
                    171:        "sinh",         "\\f1sinh\\fP",
                    172:        "coth",         "\\f1coth\\fP",
                    173:        "tanh",         "\\f1tanh\\fP",
                    174:        "cosh",         "\\f1cosh\\fP",
                    175:        "lim",          "\\f1lim\\fP",
                    176:        "log",          "\\f1log\\fP",
                    177:        "max",          "\\f1max\\fP",
                    178:        "min",          "\\f1min\\fP",
                    179:        "ln",           "\\f1ln\\fP",
                    180:        "exp",          "\\f1exp\\fP",
                    181:        "det",          "\\f1det\\fP",
                    182:        0,      0
                    183: };
                    184: 
                    185: tbl *lookup(tblp, name, defn)  /* find name in tbl. if defn non-null, install */
                    186:        tbl **tblp;
                    187:        char *name, *defn;
                    188: {
                    189:        register tbl *p;
                    190:        register int h;
                    191:        register char *s = name;
                    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.