lookup.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include "e.h"
  2. #include "y.tab.h"
  3. tbl *keytbl[TBLSIZE]; /* key words */
  4. tbl *restbl[TBLSIZE]; /* reserved words */
  5. tbl *deftbl[TBLSIZE]; /* user-defined names */
  6. struct keyword {
  7. char *key;
  8. int keyval;
  9. } keyword[] ={
  10. "sub", SUB,
  11. "sup", SUP,
  12. ".EN", DOTEN,
  13. ".EQ", DOTEQ,
  14. "from", FROM,
  15. "to", TO,
  16. "sum", SUM,
  17. "hat", HAT,
  18. "vec", VEC,
  19. "dyad", DYAD,
  20. "dot", DOT,
  21. "dotdot", DOTDOT,
  22. "bar", BAR,
  23. "lowbar", LOWBAR,
  24. "highbar", HIGHBAR,
  25. "tilde", TILDE,
  26. "utilde", UTILDE,
  27. "under", UNDER,
  28. "prod", PROD,
  29. "int", INT,
  30. "integral", INT,
  31. "union", UNION,
  32. "inter", INTER,
  33. "matrix", MATRIX,
  34. "col", COL,
  35. "lcol", LCOL,
  36. "ccol", CCOL,
  37. "rcol", RCOL,
  38. "pile", COL, /* synonyms ... */
  39. "lpile", LCOL,
  40. "cpile", CCOL,
  41. "rpile", RCOL,
  42. "over", OVER,
  43. "sqrt", SQRT,
  44. "above", ABOVE,
  45. "size", SIZE,
  46. "font", FONT,
  47. "fat", FAT,
  48. "roman", ROMAN,
  49. "italic", ITALIC,
  50. "bold", BOLD,
  51. "left", LEFT,
  52. "right", RIGHT,
  53. "delim", DELIM,
  54. "define", DEFINE,
  55. "tdefine", DEFINE,
  56. "ndefine", NDEFINE,
  57. "ifdef", IFDEF,
  58. "gsize", GSIZE,
  59. ".gsize", GSIZE,
  60. "gfont", GFONT,
  61. "include", INCLUDE,
  62. "copy", INCLUDE,
  63. "space", SPACE,
  64. "up", UP,
  65. "down", DOWN,
  66. "fwd", FWD,
  67. "back", BACK,
  68. "mark", MARK,
  69. "lineup", LINEUP,
  70. 0, 0
  71. };
  72. struct resword {
  73. char *res;
  74. char *resval;
  75. } resword[] ={
  76. ">=", "\\(>=",
  77. "<=", "\\(<=",
  78. "==", "\\(==",
  79. "!=", "\\(!=",
  80. "+-", "\\(+-",
  81. "->", "\\(->",
  82. "<-", "\\(<-",
  83. "inf", "\\(if",
  84. "infinity", "\\(if",
  85. "partial", "\\(pd",
  86. "half", "\\f1\\(12\\fP",
  87. "prime", "\\f1\\v'.5m'\\s+3\\(fm\\s-3\\v'-.5m'\\fP",
  88. "dollar", "\\f1$\\fP",
  89. "nothing", "",
  90. "times", "\\(mu",
  91. "del", "\\(gr",
  92. "grad", "\\(gr",
  93. "approx", "\\v'-.2m'\\z\\(ap\\v'.25m'\\(ap\\v'-.05m'",
  94. "cdot", "\\v'-.3m'.\\v'.3m'",
  95. "...", "\\v'-.25m'\\ .\\ .\\ .\\ \\v'.25m'",
  96. ",...,", "\\f1,\\fP\\ .\\ .\\ .\\ \\f1,\\fP\\|",
  97. "alpha", "α",
  98. "ALPHA", "Α",
  99. "beta", "β",
  100. "BETA", "Β",
  101. "gamma", "γ",
  102. "GAMMA", "Γ",
  103. "delta", "δ",
  104. "DELTA", "Δ",
  105. "epsilon", "ε",
  106. "EPSILON", "Ε",
  107. "omega", "ω",
  108. "OMEGA", "Ω",
  109. "lambda", "λ",
  110. "LAMBDA", "Λ",
  111. "mu", "μ",
  112. "MU", "Μ",
  113. "nu", "ν",
  114. "NU", "Ν",
  115. "theta", "θ",
  116. "THETA", "Θ",
  117. "phi", "φ",
  118. "PHI", "Φ",
  119. "pi", "π",
  120. "PI", "Π",
  121. "sigma", "σ",
  122. "SIGMA", "Σ",
  123. "xi", "ξ",
  124. "XI", "Ξ",
  125. "zeta", "ζ",
  126. "ZETA", "Ζ",
  127. "iota", "ι",
  128. "IOTA", "Ι",
  129. "eta", "η",
  130. "ETA", "Η",
  131. "kappa", "κ",
  132. "KAPPA", "Κ",
  133. "rho", "ρ",
  134. "RHO", "Ρ",
  135. "tau", "τ",
  136. "TAU", "Τ",
  137. "omicron", "ο",
  138. "OMICRON", "Ο",
  139. "upsilon", "υ",
  140. "UPSILON", "Υ",
  141. "psi", "ψ",
  142. "PSI", "Ψ",
  143. "chi", "χ",
  144. "CHI", "Χ",
  145. "and", "\\f1and\\fP",
  146. "for", "\\f1for\\fP",
  147. "if", "\\f1if\\fP",
  148. "Re", "\\f1Re\\fP",
  149. "Im", "\\f1Im\\fP",
  150. "sin", "\\f1sin\\fP",
  151. "cos", "\\f1cos\\fP",
  152. "tan", "\\f1tan\\fP",
  153. "arc", "\\f1arc\\fP",
  154. "sinh", "\\f1sinh\\fP",
  155. "coth", "\\f1coth\\fP",
  156. "tanh", "\\f1tanh\\fP",
  157. "cosh", "\\f1cosh\\fP",
  158. "lim", "\\f1lim\\fP",
  159. "log", "\\f1log\\fP",
  160. "ln", "\\f1ln\\fP",
  161. "max", "\\f1max\\fP",
  162. "min", "\\f1min\\fP",
  163. "exp", "\\f1exp\\fP",
  164. "det", "\\f1det\\fP",
  165. 0, 0
  166. };
  167. int hash(char *s)
  168. {
  169. register unsigned int h;
  170. for (h = 0; *s != '\0'; )
  171. h += *s++;
  172. h %= TBLSIZE;
  173. return h;
  174. }
  175. tbl *lookup(tbl **tblp, char *name) /* find name in tbl */
  176. {
  177. register tbl *p;
  178. for (p = tblp[hash(name)]; p != NULL; p = p->next)
  179. if (strcmp(name, p->name) == 0)
  180. return(p);
  181. return(NULL);
  182. }
  183. void install(tbl **tblp, char *name, char *cval, int ival) /* install name, vals in tblp */
  184. {
  185. register tbl *p;
  186. int h;
  187. if ((p = lookup(tblp, name)) == NULL) {
  188. p = (tbl *) malloc(sizeof(tbl));
  189. if (p == NULL)
  190. ERROR "out of space in install" FATAL;
  191. h = hash(name); /* bad visibility here */
  192. p->name = name;
  193. p->next = tblp[h];
  194. tblp[h] = p;
  195. }
  196. p->cval = cval;
  197. p->ival = ival;
  198. }
  199. void init_tbl(void) /* initialize tables */
  200. {
  201. int i;
  202. extern int init_tune(void);
  203. for (i = 0; keyword[i].key != NULL; i++)
  204. install(keytbl, keyword[i].key, (char *) 0, keyword[i].keyval);
  205. for (i = 0; resword[i].res != NULL; i++)
  206. install(restbl, resword[i].res, resword[i].resval, 0);
  207. init_tune(); /* tuning table done in tuning.c */
  208. }