lookup.c 4.5 KB

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