home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gle / gle / keyword.c < prev    next >
C/C++ Source or Header  |  1992-11-29  |  4KB  |  192 lines

  1. #include "all.h"
  2.  
  3.  
  4. /*------------------------------------------------------------------*/
  5. /*      Find the KEY WORD *cp, and return it's number       */
  6. /*------------------------------------------------------------------*/
  7.  
  8. /* You can add a function, you MUST place it in alphabetical order  */
  9. /* and give it the next unused index number                */
  10. /*  up to 64         *** 50 is RESERVED for assignment *** */
  11.  
  12. #define NKEYS (sizeof mkeywfn / sizeof(struct mkeyw))
  13. struct mkeyw { char *word; int index;  } mkeywfn[] = {
  14.       "!",        53
  15.     , "ALINE",    1
  16.     , "AMOVE",    2
  17.     , "ARC",    3
  18.     , "ARCTO",    4
  19.     , "Assignment", 51
  20.     , "BEGIN",     5
  21.     , "BEZIER",    6
  22.     , "BIGFILE",    58
  23.     , "BOX",    7
  24.     , "CALL",    52
  25.     , "CIRCLE",    8
  26.     , "CLOSEPATH",    9
  27.     , "CURVE",    10
  28.     , "DEFINE",    11
  29.     , "DEFMARKER",    60
  30.     , "DFONT",    12
  31.     , "DRAW",    56
  32.     , "ELSE",    13
  33.     , "END",    14
  34.     , "FCLOSE",    15
  35.     , "FILL",    16
  36.     , "FOPEN",    17
  37.     , "FOR",    18
  38.     , "FREAD",    61
  39.     , "FREADLN",    62
  40.     , "FWRITE",    63
  41.     , "FWRITELN",    64
  42.     , "GOTO",    19
  43.     , "GRESTORE",    54
  44.     , "GSAVE",    20
  45.     , "ICON",    21
  46.     , "IF",        22
  47.     , "INCLUDE",    23
  48.     , "INPUT",     24
  49.     , "JOIN",    25
  50.     , "MARKER",    26
  51.     , "MOVE",    27
  52.     , "NARC",    28
  53.     , "NEWPATH",    29
  54.     , "NEXT",    30
  55.     , "PIE",    31
  56.     , "PLOTTER",    57
  57.     , "POSTSCRIPT",    55
  58.     , "PRINT",    32
  59.     , "RBEZIER",    33
  60.     , "REGION",    34
  61.     , "RETURN",    50
  62.     , "REVERSE",    35
  63.     , "RLINE",    36
  64.     , "RMOVE",    37
  65.     , "ROT",    38
  66.     , "ROTATE",    38
  67.     , "SAVE",    39
  68.     , "SCALE",    40
  69.     , "SET",    41
  70.     , "SIZE",     42
  71.     , "STROKE",    43
  72.     , "SUB",    44
  73.     , "TEXT",    45
  74.     , "TEXTDEF",    59
  75.     , "TRAN",    46
  76.     , "TRANSLATE",    46
  77.     , "UNTIL",    47
  78.     , "WHILE",    48
  79.     , "WRITE",    49
  80. };
  81. int binsearchk(char *word, struct mkeyw tab[], int n);
  82.  
  83. cmd_name(int idx, char **cp)
  84. {
  85.     int i;
  86.     int k;
  87.     static char *kp;
  88.     static char fail[]="Keyword not found";
  89.     if (kp==NULL) kp = myallocz(80);
  90.     for (i=0;i<NKEYS;i++) {
  91.         if (mkeywfn[i].index==idx) {
  92.             strcpy(kp,mkeywfn[i].word);
  93.             *cp = kp;
  94.             return;
  95.         }
  96.     }
  97.     *cp = &fail[0];
  98. }
  99. find_mkey(char *cp, int *idx)
  100. {
  101.     int i;
  102.     i = binsearchk(cp,mkeywfn,NKEYS);
  103.     /* printf("I %d, cmd {%s} \n",i,cp); */
  104.     if (i==-1) { *idx = 0; return;}
  105.     *idx = mkeywfn[i].index;
  106. }
  107.  
  108. /*------------------------------------------------------------------*/
  109. /* Simple binary search                         */
  110. /*------------------------------------------------------------------*/
  111. binsearchk(char *word, struct mkeyw tab[], int n)
  112. {
  113.     int cond,low,high,mid;
  114.     low = 0;
  115.     high = n-1;
  116.     while (low <= high) {
  117.         mid = (low+high) / 2;
  118.         if ((cond = strcmp(word,tab[mid].word)) < 0)
  119.             high = mid - 1;
  120.         else if (cond > 0)
  121.             low = mid + 1;
  122.         else
  123.             return mid;
  124.     }
  125.     return -1;
  126. }
  127.  
  128.  
  129. /*-------------------------------------------------------------------------*/
  130. /* This is for the tex primitives */
  131.  
  132. #include "tex.h"
  133. struct mkeyw tkeywfn[] = {
  134.        "^",            tp_sup
  135.      , "_",            tp_sub
  136.     , "accent",        tp_accent
  137.     , "char",        tp_char
  138.     , "chardef",        tp_chardef
  139.     , "def",        tp_def
  140.     , "defbegin",        tp_defbegin
  141.     , "delcode",        tp_delcode
  142.     , "delimiter",        tp_delimiter
  143.     , "frac",        tp_frac
  144.      , "hfill",        tp_hfill
  145.     , "left",        tp_left
  146.     , "linegap",        tp_linegap
  147.     , "lineskip",        tp_lineskip
  148.     , "mathchar",        tp_mathchar
  149.     , "mathchardef",    tp_mathchardef
  150.     , "mathcode",        tp_mathcode
  151.     , "movexy",        tp_movexy
  152.     , "newline",         tp_newline
  153.     , "nolimits",        tp_nolimits
  154.     , "overbrace",        tp_overbrace
  155.     , "overline",        tp_overline
  156.      , "parskip",        tp_parskip
  157.     , "presave",        tp_presave
  158.     , "right",        tp_right
  159.     , "rule",        tp_rule
  160.     , "setfont",        tp_setfont
  161.     , "sethei",        tp_sethei
  162.     , "setstretch",        tp_setstretch
  163.     , "sfont",        tp_sfont
  164.     , "ssfont",        tp_ssfont
  165.     , "sub",        tp_sub
  166.     , "sup",        tp_sup
  167.     , "tfont",        tp_tfont
  168.     , "underbrace",        tp_underbrace
  169.     , "underline",        tp_underline
  170. };
  171.  
  172. #define NTKEYS (sizeof tkeywfn / sizeof(struct mkeyw))
  173. find_primcmd(char *cp)
  174. {
  175.     int i;
  176.     i = binsearchk(cp,tkeywfn,NTKEYS);
  177.     if (i==-1) return 0;
  178.     return tkeywfn[i].index;
  179. }
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.