home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume6 / glib / part11 / menutoc.c
Encoding:
C/C++ Source or Header  |  1989-05-14  |  29.7 KB  |  1,206 lines

  1. #define YY_DEFAULT_ACTION ECHO;
  2. #define FLEX_USE_ECS
  3. #define FLEX_USE_MECS
  4. /* A lexical scanner generated by flex */
  5.  
  6. /* macro definitions for compressed-table C/FTL programs generated by flex */
  7.  
  8. /* common macro definitions for C/FTL programs generated by flex */
  9.  
  10.  
  11. /* returned upon end-of-file */
  12. #define YY_END_TOK 0
  13.  
  14. /* action number for an "end-of-file was seen and yywrap indicated that we
  15.  * should continue processing"
  16.  */
  17. #define YY_NEW_FILE -1
  18.  
  19. /* action number for "the default action should be done" */
  20. #define YY_DO_DEFAULT -2
  21.  
  22. #ifndef BUFSIZ
  23. #include <stdio.h>
  24. #endif
  25.  
  26. #define YY_BUF_SIZE (BUFSIZ * 2) /* size of input buffer */
  27.  
  28. /* number of characters one rule can match.  One less than YY_BUF_SIZE to make
  29.  * sure we never access beyond the end of an array
  30.  */
  31. #define YY_BUF_MAX (YY_BUF_SIZE - 1)
  32.  
  33. /* we will never use more than the first YY_BUF_LIM + YY_MAX_LINE positions
  34.  * of the input buffer
  35.  */
  36. #ifndef YY_MAX_LINE
  37. #define YY_MAX_LINE BUFSIZ
  38. #endif
  39.  
  40. #define YY_BUF_LIM (YY_BUF_MAX - YY_MAX_LINE)
  41.  
  42. /* copy whatever the last rule matched to the standard output */
  43.  
  44. #define ECHO fputs( yytext, yyout )
  45.  
  46. /* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
  47.  * is returned in "result".
  48.  */
  49. #define YY_INPUT(buf,result,max_size) \
  50.     if ( (result = read( fileno(yyin), buf, max_size )) < 0 ) \
  51.         YY_FATAL_ERROR( "read() in flex scanner failed" );
  52. #define YY_NULL 0
  53.  
  54. /* macro used to output a character */
  55. #define YY_OUTPUT(c) putc( c, yyout );
  56.  
  57. /* report a fatal error */
  58. #define YY_FATAL_ERROR(msg) \
  59.     { \
  60.     fputs( msg, stderr ); \
  61.     putc( '\n', stderr ); \
  62.     exit( 1 ); \
  63.     }
  64.  
  65. /* returns the first character of the matched text */
  66. #define YY_FIRST_CHAR yy_ch_buf[yy_b_buf_p]
  67.  
  68. /* default yywrap function - always treat EOF as an EOF */
  69. #define yywrap() 1
  70.  
  71. /* enter a start condition.  This macro really ought to take a parameter,
  72.  * but we do it the disgusting crufty way that old Unix-lex does it
  73.  */
  74. #define BEGIN yy_start = 1 +
  75.  
  76. /* callable from YY_INPUT to set things up so that '%' will match.  Proper
  77.  * usage is "YY_SET_BOL(array,pos)"
  78.  */
  79. #define YY_SET_BOL(array,pos) array[pos - 1] = '\n';
  80.  
  81. /* default declaration of generated scanner - a define so the user can
  82.  * easily add parameters
  83.  */
  84. #define YY_DECL int yylex()
  85.  
  86. /* return all but the first 'n' matched characters back to the input stream */
  87. #define yyless(n) \
  88.     { \
  89.     YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */ \
  90.     yy_c_buf_p = yy_b_buf_p + n - 1; \
  91.     YY_DO_BEFORE_ACTION; /* set up yytext again */ \
  92.     }
  93.  
  94. /* code executed at the end of each rule */
  95. #define YY_BREAK break;
  96.  
  97. /* reinitializes everything except the current start condition.  The last
  98.  * input character is set to a newline so an initial beginning-of-line
  99.  * rule will match
  100.  */
  101. #define YY_INIT \
  102.     { \
  103.     yyleng = yy_c_buf_p = yy_e_buf_p = 0; \
  104.     yy_hold_char = yy_ch_buf[yy_c_buf_p] = '\n'; \
  105.     yytext = &yy_ch_buf[yy_c_buf_p]; \
  106.     yy_saw_eof = 0; \
  107.     }
  108.  
  109. /* returns the length of the matched text */
  110. #define YY_LENG (yy_c_buf_p - yy_b_buf_p + 1)
  111. /* done before the next pattern has been matched action */
  112. #define YY_DO_BEFORE_SCAN \
  113.     yytext[yyleng] = yy_hold_char;
  114.  
  115. /* done after the current pattern has been matched and before the corresponding action */
  116. #define YY_DO_BEFORE_ACTION \
  117.     yytext = &yy_ch_buf[yy_b_buf_p]; \
  118.     yyleng = YY_LENG; \
  119.     yy_hold_char = yytext[yyleng]; \
  120.     yytext[yyleng] = '\0';
  121.  
  122. /* find the next rule matched */
  123. #ifdef FLEX_REJECT_ENABLED
  124. #define REJECT \
  125.         { \
  126.     YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */ \
  127.         yy_c_buf_p = yy_full_match; /* restore possibly backed-over text */ \
  128.         ++yy_lp; \
  129.         goto find_rule; \
  130.         }
  131. #else
  132. #define REJECT YY_FATAL_ERROR( "REJECT used and scanner was not generated using -r" )
  133. #endif
  134.  
  135. # line 1 "menutoc.l"
  136. #define INITIAL 0
  137. # line 2 "menutoc.l"
  138. /* $Id: menutoc.c,v 1.6 89/05/06 17:13:36 lee Exp $
  139.  *    menutoc.l    -- Greg Lee, lee@uhccux.uhcc.hawaii.edu
  140.  *               February 1989
  141.  * $Author: lee $
  142.  * $Log:    menutoc.c,v $
  143.  * Revision 1.6  89/05/06  17:13:36  lee
  144.  * rel. to comp.sources.misc
  145.  * 
  146.  * Revision 1.6  89/05/06  09:51:46  lee
  147.  * Scott Snyder fixed a bug (see comment below)
  148.  * Mark Rinfret made a couple changes for Aztec C
  149.  * now emits some (INT16) casts for lint
  150.  * now emits #line directives
  151.  * 
  152.  * Revision 1.5  89/04/25  16:36:18  lee
  153.  * modifications:
  154.  * 
  155.  
  156.     Generate C language menu module for Glib from menu specification.
  157.  
  158. Compile:
  159.     flex menutoc.l
  160.     cc -o menutoc lex.yy.c
  161. or
  162.     lex menutoc.l
  163.     cc -o menutoc lex.yy.c -ll
  164.  
  165. Usage:
  166.     menutoc <file.menu >file.c
  167.  
  168. Description:
  169.  
  170. Menutoc simplifies constructing and modifying synthesizer-specific
  171. modules for Tim Thompson's Glib.  It allows the form of the on-screen
  172. menu to be specified as a picture in the menu source file, and generates
  173. 'setval' and 'getval' calls automatically.  This version works with
  174. the version of Glib modified by Michael Kesti.
  175.  
  176. [The original version of flex distributed on Usenet has a bug which
  177.  prevents setting the start state.  If this is a problem, you can
  178.  fix it by making two changes to flex's skeleton files:
  179.     CHANGE
  180.     static int yy_start;
  181.     TO
  182.     static int yy_start = 0;
  183.  
  184.     CHANGE
  185.         yy_start = 1;
  186.     TO
  187.         if (!yy_start) yy_start = 1;
  188. ]
  189.  
  190. The following characterization of how menutoc works is probably
  191. not entirely clear.  Look at the example k1single.menu and the
  192. source code to get a more exact idea.  The source k1single.menu
  193. gives the C file k1single.c after processing by menutoc.
  194.  
  195. The menu source file should contain five special preprocessor
  196. directives: '#MENU' (once), '#END' (once), '#O' (one for each
  197. label name), '#GETVAL' (once), and '#SETVAL' (once).  The source
  198. file has four sections:
  199.     (1) the portion before the '#MENU' directive is passed
  200.         through unchanged to the output,
  201.     (2) a picture of the screen menu is given between the
  202.         '#MENU' and '#END' directives,
  203.     (3) after the '#END' directive is C code with '#O' directives
  204.         which specify the data offsets of variables and with
  205.         '%%' or '@@' references to the screen locations for
  206.         variable values, and
  207.     (4) more C code containing somewhere the '#SETVAL' and
  208.         '#GETVAL' directives which cause a series of calls
  209.         to the 'setval' and 'getval' functions to be generated,
  210.         making use of the offset information given by the '#O'
  211.         directives in the preceding section.
  212.  
  213. The picture of the screen menu has constant strings in the position
  214. they will be output to the screen and '%' or '@' in each position
  215. where the current value of some variable is to be displayed by
  216. Glib.  The locations of the '%'s and '@'s are remembered in the
  217. order in which they are encountered (scanning left-to-right and
  218. top-to-bottom in the picture), then the corresponding row/column
  219. coordinates are substituted for '%%'s and '@@'s encountered in
  220. section 3 of the source file.  The '%'s and '@'s are stored
  221. independently so as to make it more convenient to specify menus
  222. that have two columns of values.
  223.  
  224. The '#O' specifications are given in the form:
  225.  
  226. #O <NAME> <TYPE> <POS> <MAX> <OFFSET> <MASK> <SHIFT> <ADHOC>
  227.  
  228. Such a line generates one "paraminfo" entry for an array, and some of
  229. the information is saved and made use of in generating 'setval' and
  230. 'getval' calls.  NAME is the name of a variable label (no caps); TYPE is
  231. the name of a vis-function used to display the current value on the
  232. screen; POS should be either '%%' or '@@', which will be replaced by row
  233. and column coordinates of the position to display the value; MAX is the
  234. maximum value the glib editor is to accept (the minimum is assumed to be
  235. 0); OFFSET is the offset of the byte containing the value in the data
  236. array.  (If OFFSET is negative, the (positive) value is taken to be the
  237. initial value rather than the offset.)
  238.  
  239. The NAME argument may begin with a digit specifying a repetition
  240. count.  It's a shortcut which is like giving several consecutive
  241. #O-lines for <NAME>1, <NAME>2, ...
  242.  
  243. The last three #O arguments are optional.  MASK is a number with 1-bits
  244. in positions holding the value for those cases where part of a byte is
  245. used for some other purpose.  SHIFT is the number of bits the bitfield
  246. is shifted left in the byte.  So, for instance, if the synth keeps a
  247. value in the 4th, 5th, and 6th bits, one would give '0x1C' for the MASK
  248. and '3' for SHIFT.  (Use caps for hex digits A-F.)
  249.  
  250. There is no systematic provision for values some of whose bits are found
  251. in one byte, some in another.  The ADHOC argument has the form
  252. '*<digit>' and is used in the example to provide for such a case.  The
  253. code below in this file was just made up ad hoc for two such cases I
  254. encountered with the Kawai K1.
  255.  
  256. */
  257.  
  258. /*
  259.  * Modified 4-13-89 by Scott Snyder:
  260.  *  1. Increased MAXVAL from 100 to 200 (for DX7).
  261.  *  2. Changed type of temps from 'unsigned char' to 'unsigned' (for DX7).
  262.  *  3. Added command line processing (since TMAKE doesn't support redirection).
  263.  *
  264.  * 4-19-18
  265.  *  Fixed bug with zero offsets.
  266.  */
  267.  
  268. #ifdef AZTEC_C
  269. long atol();
  270. # define strtol(a, b, c) atol(a)
  271. #endif
  272. #define MAXLINE 133
  273. #define MAXVAL 200
  274. #define MAXVSTRINGS 200
  275. #define MAXBUF 2000
  276.  
  277.     char *infname = "file.mnu";
  278.     int lcnt = 1;
  279.     int i, j, k, wcol=0, col=0, row=0;
  280.     char word[MAXLINE];
  281.     int wordp = 0;
  282.     int valpos[MAXVAL][2];
  283.     int valpos2[MAXVAL][2];
  284.     int valcnt = 0;
  285.     int valcnt2= 0;
  286.     int offset;
  287.     int nlist[MAXVSTRINGS][6];
  288.     int np = 0;
  289.     char buf[MAXBUF];
  290.     int bufp=0;
  291.     int multiple, special;
  292.         int vmin, vmax, vval, mask, vshift, vrow, vcol, iflag;
  293.     char visfunc[20];
  294.     int state;
  295. #define M 2
  296. #define IG 4
  297. #define VAL 6
  298. #define O 8
  299. #define P 10
  300. #define Q 12
  301. # line 160 "menutoc.l"
  302. #define YY_JAM 92
  303. #define YY_JAM_BASE 174
  304. #define YY_TEMPLATE 93
  305. static char l[93] =
  306.     {   0,
  307.        -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,   -2,
  308.        -2,   -2,   -2,   -2,   33,    9,    7,    8,    6,    5,
  309.         4,    9,    3,    2,    3,   23,   24,   23,   23,   23,
  310.        23,   12,   13,   14,   15,   16,   17,   33,   33,   33,
  311.        18,   33,    6,    0,    0,    0,    0,   30,   29,    0,
  312.         0,    0,    0,    0,    0,   13,   14,   15,   16,   19,
  313.        22,   21,   18,   20,    0,    0,   27,   28,    0,   11,
  314.         0,    0,    0,    0,    0,    0,    0,   10,    0,    0,
  315.         0,    0,    1,    0,    0,    0,    0,    0,   26,    0,
  316.        25,    0
  317.  
  318.     } ;
  319.  
  320. static char e[128] =
  321.     {   0,
  322.         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
  323.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  324.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  325.         1,    4,    1,    1,    5,    1,    6,    1,    1,    1,
  326.         1,    7,    1,    1,    8,    1,    1,    9,   10,   10,
  327.        10,   10,   10,   10,   10,   10,   10,    1,    1,    1,
  328.         1,    1,    1,   11,   12,   13,   13,   14,   15,   13,
  329.        16,    1,    1,    1,    1,   17,   18,   19,   20,    1,
  330.         1,    1,   21,   22,   23,   24,    1,    1,    1,    1,
  331.         1,   25,    1,    1,   26,    1,   27,   27,   27,   27,
  332.  
  333.        27,   27,   27,   27,   27,   27,   27,   27,   27,   27,
  334.        27,   27,   27,   27,   27,   27,   27,   27,   27,   28,
  335.        27,   27,    1,    1,    1,    1,    1
  336.     } ;
  337.  
  338. static char m[29] =
  339.     {   0,
  340.         1,    1,    1,    1,    1,    1,    1,    2,    3,    3,
  341.         1,    2,    2,    2,    2,    1,    1,    1,    1,    1,
  342.         1,    1,    1,    1,    1,    4,    4,    3
  343.     } ;
  344.  
  345. static short int b[104] =
  346.     {   0,
  347.         0,    0,    0,   10,  121,    2,   14,   37,    0,    9,
  348.        61,    0,   88,    0,  174,  174,  174,  174,  119,  174,
  349.       174,   20,  174,  174,   27,  174,  174,  116,  110,   27,
  350.       115,  174,    0,   28,    0,   42,  174,  114,  108,  107,
  351.       106,  102,  108,   45,   92,   48,   95,  174,  174,  103,
  352.        97,   51,   92,   52,   91,    0,   55,    0,   71,  174,
  353.       174,   97,   96,  174,   79,   67,   79,   73,   61,   72,
  354.        60,   73,   77,   56,   54,   53,   66,  174,   65,   52,
  355.        49,   55,  174,   34,   24,   31,   23,   20,  174,    5,
  356.       174,  174,  136,  140,  144,  148,  150,  152,  155,  158,
  357.  
  358.       162,  166,  170
  359.     } ;
  360.  
  361. static short int d[104] =
  362.     {   0,
  363.        93,   93,   94,   94,   95,   95,   96,   96,   93,   93,
  364.        93,   11,   93,   13,   92,   92,   92,   92,   92,   92,
  365.        92,   92,   92,   92,   92,   92,   92,   92,   92,   92,
  366.        92,   92,   97,   92,   98,   92,   92,   92,   92,   99,
  367.        99,   92,   92,   92,   92,   92,   92,   92,   92,   92,
  368.        92,   92,   92,   92,   92,   97,   92,   98,   92,   92,
  369.        92,   99,   99,   92,   92,   92,   92,   92,   92,   92,
  370.        92,   99,  100,   92,   92,   92,  100,   92,  101,   92,
  371.        92,  101,   92,   92,   92,  102,  103,  102,   92,  103,
  372.        92,-32767,   92,   92,   92,   92,   92,   92,   92,   92,
  373.  
  374.        92,   92,   92
  375.     } ;
  376.  
  377. static short int n[203] =
  378.     {   0,
  379.        92,   17,   18,   19,   24,   20,   25,   91,   32,   32,
  380.        21,   17,   18,   19,   22,   20,   27,   32,   32,   28,
  381.        21,   44,   89,   44,   29,   91,   33,   33,   46,   57,
  382.        46,   57,   50,   89,   45,   33,   33,   51,   30,   27,
  383.        87,   31,   28,   59,   47,   59,   44,   29,   44,   46,
  384.        86,   46,   52,   70,   52,   70,   57,   83,   57,   45,
  385.        85,   30,   34,   84,   34,   47,   53,   83,   78,   35,
  386.        35,   55,   59,   70,   59,   70,   81,   80,   79,   78,
  387.        72,   76,   75,   68,   67,   74,   35,   35,   35,   36,
  388.        37,   36,   73,   38,   39,   40,   41,   41,   42,   41,
  389.  
  390.        41,   41,   41,   92,   72,   71,   69,   68,   67,   66,
  391.        65,   43,   64,   92,   62,   41,   52,   61,   52,   60,
  392.        49,   48,   43,   24,   92,   92,   92,   92,   92,   92,
  393.        53,   92,   92,   92,   54,   55,   15,   15,   15,   15,
  394.        16,   16,   16,   16,   23,   23,   23,   23,   26,   26,
  395.        26,   26,   56,   56,   58,   58,   63,   63,   77,   77,
  396.        77,   77,   82,   82,   82,   82,   88,   88,   88,   88,
  397.        90,   90,   90,   90,   92,   92,   92,   92,   92,   92,
  398.        92,   92,   92,   92,   92,   92,   92,   92,   92,   92,
  399.        92,   92,   92,   92,   92,   92,   92,   92,   92,   92,
  400.  
  401.        92,   92
  402.     } ;
  403.  
  404. static short int c[203] =
  405.     {   0,
  406.         0,    3,    3,    3,    6,    3,    6,   90,    9,    9,
  407.         3,    4,    4,    4,    4,    4,    7,   10,   10,    7,
  408.         4,   22,   88,   22,    7,   87,    9,    9,   25,   34,
  409.        25,   34,   30,   86,   22,   10,   10,   30,    7,    8,
  410.        85,    8,    8,   36,   25,   36,   44,    8,   44,   46,
  411.        84,   46,   52,   54,   52,   54,   57,   82,   57,   44,
  412.        81,    8,   11,   80,   11,   46,   52,   79,   77,   11,
  413.        11,   52,   59,   70,   59,   70,   76,   75,   74,   73,
  414.        72,   71,   69,   68,   67,   66,   11,   11,   11,   13,
  415.        13,   13,   65,   13,   13,   13,   13,   13,   13,   13,
  416.  
  417.        13,   13,   13,   63,   62,   55,   53,   51,   50,   47,
  418.        45,   43,   42,   41,   40,   13,   31,   39,   31,   38,
  419.        29,   28,   19,    5,    0,    0,    0,    0,    0,    0,
  420.        31,    0,    0,    0,   31,   31,   93,   93,   93,   93,
  421.        94,   94,   94,   94,   95,   95,   95,   95,   96,   96,
  422.        96,   96,   97,   97,   98,   98,   99,   99,  100,  100,
  423.       100,  100,  101,  101,  101,  101,  102,  102,  102,  102,
  424.       103,  103,  103,  103,   92,   92,   92,   92,   92,   92,
  425.        92,   92,   92,   92,   92,   92,   92,   92,   92,   92,
  426.        92,   92,   92,   92,   92,   92,   92,   92,   92,   92,
  427.  
  428.        92,   92
  429.     } ;
  430.  
  431.  
  432. /* these declarations have to come after the section 1 code or lint gets
  433.  * confused about whether the variables are used
  434.  */
  435. FILE *yyin = stdin, *yyout = stdout;
  436.  
  437. /* these variables are all declared out here so that section 3 code can
  438.  * manipulate them
  439.  */
  440. static int yy_start = 0, yy_b_buf_p, yy_c_buf_p, yy_e_buf_p;
  441. static int yy_saw_eof, yy_init = 1;
  442.  
  443. /* yy_ch_buf has to be 1 character longer than YY_BUF_SIZE, since when
  444.  * setting up yytext we can try to put a '\0' just past the end of the
  445.  * matched text
  446.  */
  447. static char yy_ch_buf[YY_BUF_SIZE + 1];
  448. static int yy_st_buf[YY_BUF_SIZE];
  449. static char yy_hold_char;
  450. char *yytext;
  451. static int yyleng;
  452.  
  453. YY_DECL
  454.     {
  455.     int yy_n_chars, yy_lp, yy_iii, yy_buf_pos, yy_act;
  456. #ifdef FLEX_REJECT_ENABLED
  457.     int yy_full_match;
  458. #endif
  459.  
  460.  
  461.  
  462.  
  463.     if ( yy_init )
  464.     {
  465.     YY_INIT;
  466.     if (!yy_start) yy_start = 1;
  467.     yy_init = 0;
  468.     }
  469.  
  470.     goto get_next_token;
  471.  
  472. do_action:
  473.  
  474. #ifdef FLEX_REJECT_ENABLED
  475.     /* remember matched text in case we back up due to trailing context */
  476.     yy_full_match = yy_c_buf_p;
  477. #endif
  478.  
  479.     for ( ; ; )
  480.     {
  481.     YY_DO_BEFORE_ACTION
  482.  
  483. #ifdef FLEX_DEBUG
  484.     fprintf( stderr, "--accepting rule #%d\n", yy_act );
  485. #endif
  486.     switch ( yy_act )
  487.         {
  488. case 1:
  489. # line 162 "menutoc.l"
  490. { BEGIN(M); lcnt++; }
  491.     YY_BREAK
  492. case 2:
  493. # line 163 "menutoc.l"
  494. { ECHO; lcnt++; }
  495.     YY_BREAK
  496. case 3:
  497. # line 164 "menutoc.l"
  498. ECHO;
  499.     YY_BREAK
  500. case 4:
  501. # line 166 "menutoc.l"
  502. {    writeword();
  503.         if (valcnt2+1 >= MAXVAL) {
  504.             fprintf(stderr,"menutoc: too many @s in menu\n");
  505.             exit(1);
  506.         }
  507.         valpos2[valcnt2][0] = row;
  508.         valpos2[valcnt2++][1] = col;
  509.         col += 1;
  510. };
  511.     YY_BREAK
  512. case 5:
  513. # line 176 "menutoc.l"
  514. {    writeword();
  515.         if (valcnt+1 >= MAXVAL) {
  516.             fprintf(stderr,"menutoc: too many %%s in menu\n");
  517.             exit(1);
  518.         }
  519.         valpos[valcnt][0] = row;
  520.         valpos[valcnt++][1] = col;
  521.         col += 1;
  522. };
  523.     YY_BREAK
  524. case 6:
  525. # line 186 "menutoc.l"
  526. {    if (yyleng > 4) writeword();
  527.         else if (wordp) for (i=0; i<yyleng; i++) append(' ');
  528.         col += yyleng;
  529. };
  530.     YY_BREAK
  531. case 7:
  532. # line 191 "menutoc.l"
  533. {    writeword(); col = ((col + 8)/8)*8;
  534. };
  535.     YY_BREAK
  536. case 8:
  537. # line 194 "menutoc.l"
  538. {    writeword(); col = 0; row += 1; lcnt++;
  539. };
  540.     YY_BREAK
  541. case 9:
  542. # line 197 "menutoc.l"
  543. {        append(yytext[0]); col += 1;
  544. };
  545.     YY_BREAK
  546. case 10:
  547. # line 200 "menutoc.l"
  548. {
  549.         BEGIN(VAL); i = 0; j = 0; lcnt++;
  550.         printf("# line %d \"%s\"\n", lcnt, infname);
  551. };
  552.     YY_BREAK
  553. case 11:
  554. # line 205 "menutoc.l"
  555. {
  556.         if (np+1 >= MAXVSTRINGS) {
  557.             fprintf(stderr,"menutoc: too many VSTRINGs\n");
  558.             exit(1);
  559.         }
  560.         BEGIN(O);
  561.         multiple = special = 0;
  562.         vmax = offset = mask = vshift = vmin = vrow = vcol = iflag = 0;
  563.         state = 0;
  564. };
  565.     YY_BREAK
  566. case 12:
  567. # line 216 "menutoc.l"
  568. multiple = atoi(yytext);
  569.     YY_BREAK
  570. case 13:
  571. # line 218 "menutoc.l"
  572. {
  573.         if (bufp+yyleng >= MAXBUF) {
  574.             fprintf(stderr,"menutoc: out of storage room\n");
  575.             exit(1);
  576.         }
  577.         nlist[np][0] = bufp;
  578.         strcpy(buf+bufp, yytext);
  579.         bufp += yyleng+1;
  580.         BEGIN(P);
  581. };
  582.     YY_BREAK
  583. case 14:
  584. # line 229 "menutoc.l"
  585. ;
  586.     YY_BREAK
  587. case 15:
  588. # line 230 "menutoc.l"
  589. {
  590.         strcpy(visfunc, yytext);
  591.         if (yyleng >= 20) {
  592.             fprintf(stderr,"menutoc: vis name too long\n");
  593.             exit(1);
  594.         }
  595.         BEGIN(Q);
  596. };
  597.     YY_BREAK
  598. case 16:
  599. # line 239 "menutoc.l"
  600. ;
  601.     YY_BREAK
  602. case 17:
  603. # line 240 "menutoc.l"
  604. {    lcnt++;
  605.         if (special == 5) vmin = 1;
  606.         else vmin = 0;
  607.         if (offset < 0) vval = -offset;
  608.         else vval = 0;
  609.  
  610.         if (multiple) for (k=0; k<multiple; k++) {
  611.             printf("\"%s%d\",NULL,-1,-1,%d,%d,vis%s,%d,%d,%d,0,\n",
  612.                 buf+nlist[np][0], k+1, vrow, vcol, visfunc,
  613.                 vmin, vmax, vval);
  614.             if (k+1 < multiple) {
  615.             if (iflag) {
  616.                 if (i < valcnt) {
  617.                 vrow = valpos[i][0]; vcol = valpos[i++][1];
  618.                 } else
  619.                 fprintf(stderr,"menutoc: too many %%%%s\n");
  620.             } else
  621.                 if (j < valcnt2) {
  622.                 vrow = valpos2[j][0]; vcol = valpos2[j++][1];
  623.                 } else
  624.                 fprintf(stderr,"menutoc: too many @@s\n");
  625.             }
  626.         }
  627.         else
  628.             printf("\"%s\",NULL,-1,-1,%d,%d,vis%s,%d,%d,%d,0,\n",
  629.                 buf+nlist[np][0], vrow, vcol, visfunc,
  630.                 vmin, vmax, vval);
  631.         if (multiple)
  632.             printf("# line %d \"%s\"\n", lcnt, infname);
  633.         nlist[np][1] = offset;
  634.         nlist[np][2] = mask;
  635.         nlist[np][3] = vshift;
  636.         nlist[np][4] = multiple;
  637.         nlist[np][5] = special;
  638.         np++;
  639.         BEGIN(VAL);
  640. };
  641.     YY_BREAK
  642. case 18:
  643. # line 278 "menutoc.l"
  644. {
  645.         k = (int)strtol(yytext, (char **)NULL, 0);
  646.         switch (state) {
  647.           case 0: vmax = k;   break;
  648.           case 1: offset = k; break;
  649.           case 2: mask = k;   break;
  650.           case 3: vshift = k; break;
  651.           case 4: vmin = k;   break;
  652.                 }
  653.                 ++state;
  654. };
  655.     YY_BREAK
  656. case 19:
  657. # line 290 "menutoc.l"
  658. {    if (i < valcnt) {
  659.             vrow = valpos[i][0];
  660.             vcol = valpos[i][1];
  661.             i++;
  662.             iflag++;
  663.         }
  664.         else fprintf(stderr,"\nmenutoc: too many %%%%s\n");
  665. };
  666.     YY_BREAK
  667. case 20:
  668. # line 298 "menutoc.l"
  669. {    if (j < valcnt2) {
  670.             vrow = valpos2[j][0];
  671.             vcol = valpos2[j][1];
  672.             j++;
  673.         }
  674.         else fprintf(stderr,"\nmenutoc: too many @@s\n");
  675. };
  676.     YY_BREAK
  677. case 21:
  678. # line 305 "menutoc.l"
  679. {    vrow = -1;
  680.         vcol = -1;
  681. };
  682.     YY_BREAK
  683. case 22:
  684. # line 308 "menutoc.l"
  685. {
  686.         special = yytext[1] - '0';
  687. };
  688.     YY_BREAK
  689. case 23:
  690. # line 311 "menutoc.l"
  691. ECHO;
  692.     YY_BREAK
  693. case 24:
  694. # line 312 "menutoc.l"
  695. { ECHO; lcnt++; }
  696.     YY_BREAK
  697. case 25:
  698. # line 314 "menutoc.l"
  699. {
  700.         lcnt++;
  701.         /* make sure i,k will be used before declaring them */
  702.         for (k=0; k<np; k++)
  703.             if (nlist[k][1]>=0 && (nlist[k][5] || nlist[k][2])) {
  704.                 printf("\tINT16 i, k;\n\n");
  705.                 break;
  706.             }
  707.         for (k=0; k<np; k++) dosetval(k);
  708.         printf("# line %d \"%s\"\n", lcnt, infname);
  709. };
  710.     YY_BREAK
  711. case 26:
  712. # line 326 "menutoc.l"
  713. {
  714.         lcnt++;
  715.         /* make sure i,j,k will be used before declaring them */
  716.         for (k=0; k<np; k++)
  717.             if (nlist[k][1]>=0 && (nlist[k][5] || nlist[k][2])) {
  718.                 printf("\tINT16 i, j, k;\n\n");
  719.                 break;
  720.             }
  721.         for (k=0; k<np; k++) dogetval(k);
  722.         printf("# line %d \"%s\"\n", lcnt, infname);
  723. };
  724.     YY_BREAK
  725. case 27:
  726. # line 338 "menutoc.l"
  727. printf("%s", yytext+1);
  728.     YY_BREAK
  729. case 28:
  730. # line 339 "menutoc.l"
  731. printf("%s", yytext+1);
  732.     YY_BREAK
  733. case 29:
  734. # line 341 "menutoc.l"
  735. {    if (j < valcnt2) {
  736.             printf("%d, %d", valpos2[j][0], valpos2[j][1]);
  737.             j++;
  738.         }
  739.         else fprintf(stderr,"\nmenutoc: too many @@s\n");
  740. };
  741.     YY_BREAK
  742. case 30:
  743. # line 348 "menutoc.l"
  744. {    if (i < valcnt) {
  745.             printf("%d, %d", valpos[i][0], valpos[i][1]);
  746.             i++;
  747.         }
  748.         else fprintf(stderr,"\nmenutoc: too many %%%%s\n");
  749. };
  750.     YY_BREAK
  751. case 31:
  752. # line 355 "menutoc.l"
  753. ECHO;
  754.     YY_BREAK
  755. case 32:
  756. # line 356 "menutoc.l"
  757. { ECHO; lcnt++; }
  758.     YY_BREAK
  759. case 33:
  760. # line 358 "menutoc.l"
  761. YY_DEFAULT_ACTION;
  762.     YY_BREAK
  763.  
  764. case YY_NEW_FILE:
  765. break; /* begin reading from new file */
  766.  
  767. case YY_DO_DEFAULT:
  768. YY_DEFAULT_ACTION;
  769. break;
  770.  
  771. case YY_END_TOK:
  772. return ( YY_END_TOK );
  773.  
  774. default:
  775. YY_FATAL_ERROR( "fatal flex scanner internal error" );
  776.         }
  777.  
  778. get_next_token:
  779.     {
  780.     register int yy_curst;
  781.     register char yy_sym;
  782.  
  783.     YY_DO_BEFORE_SCAN
  784.  
  785.     /* set up to begin running DFA */
  786.  
  787.     yy_curst = yy_start;
  788.  
  789.     if ( yy_ch_buf[yy_c_buf_p] == '\n' )
  790.         ++yy_curst;
  791.  
  792.     /* yy_b_buf_p points to the position in yy_ch_buf
  793.      * of the start of the current run.
  794.      */
  795.  
  796.     yy_b_buf_p = yy_c_buf_p + 1;
  797.  
  798.     do /* until the machine jams */
  799.         {
  800.         if ( yy_c_buf_p == yy_e_buf_p )
  801.         { /* need more input */
  802.         if ( yy_e_buf_p >= YY_BUF_LIM )
  803.             { /* not enough room to do another read */
  804.             /* see if we can make some room for more chars */
  805.  
  806.             yy_n_chars = yy_e_buf_p - yy_b_buf_p;
  807.  
  808.             if ( yy_n_chars >= 0 )
  809.             /* shift down buffer to make room */
  810.             for ( yy_iii = 0; yy_iii <= yy_n_chars; ++yy_iii )
  811.                 {
  812.                 yy_buf_pos = yy_b_buf_p + yy_iii;
  813.                 yy_ch_buf[yy_iii] = yy_ch_buf[yy_buf_pos];
  814.                 yy_st_buf[yy_iii] = yy_st_buf[yy_buf_pos];
  815.                 }
  816.  
  817.             yy_b_buf_p = 0;
  818.             yy_e_buf_p = yy_n_chars;
  819.  
  820.             if ( yy_e_buf_p >= YY_BUF_LIM )
  821.             YY_FATAL_ERROR( "flex input buffer overflowed" );
  822.  
  823.             yy_c_buf_p = yy_e_buf_p;
  824.             }
  825.  
  826.         else if ( yy_saw_eof )
  827.             {
  828. saweof:            if ( yy_b_buf_p > yy_e_buf_p )
  829.             {
  830.             if ( yywrap() )
  831.                 {
  832.                 yy_act = YY_END_TOK;
  833.                 goto do_action;
  834.                 }
  835.             
  836.             else
  837.                 {
  838.                 YY_INIT;
  839.                 yy_act = YY_NEW_FILE;
  840.                 goto do_action;
  841.                 }
  842.             }
  843.  
  844.             else /* do a jam to eat up more input */
  845.             {
  846. #ifndef FLEX_INTERACTIVE_SCANNER
  847.             /* we're going to decrement yy_c_buf_p upon doing
  848.              * the jam.  In this case, that's wrong, since
  849.              * it points to the last non-jam character.  So
  850.              * we increment it now to counter the decrement.
  851.              */
  852.             ++yy_c_buf_p;
  853. #endif
  854.             break;
  855.             }
  856.             }
  857.  
  858.         YY_INPUT( (yy_ch_buf + yy_c_buf_p + 1), yy_n_chars,
  859.               YY_MAX_LINE );
  860.  
  861.         if ( yy_n_chars == YY_NULL )
  862.             {
  863.             if ( yy_saw_eof )
  864.     YY_FATAL_ERROR( "flex scanner saw EOF twice - shouldn't happen" );
  865.             yy_saw_eof = 1;
  866.             goto saweof;
  867.             }
  868.  
  869.         yy_e_buf_p += yy_n_chars;
  870.         }
  871.  
  872.         ++yy_c_buf_p;
  873.  
  874. #ifdef FLEX_USE_ECS
  875.         yy_sym = e[yy_ch_buf[yy_c_buf_p]];
  876. #else
  877.         yy_sym = yy_ch_buf[yy_c_buf_p];
  878. #endif
  879.  
  880. #ifdef FLEX_FULL_TABLE
  881.         yy_curst = n[yy_curst][yy_sym];
  882.  
  883. #else /* get next state from compressed table */
  884.  
  885.         while ( c[b[yy_curst] + yy_sym] != yy_curst )
  886.         {
  887.         yy_curst = d[yy_curst];
  888.  
  889. #ifdef FLEX_USE_MECS
  890.         /* we've arrange it so that templates are never chained
  891.          * to one another.  This means we can afford make a
  892.          * very simple test to see if we need to convert to
  893.          * yy_sym's meta-equivalence class without worrying
  894.          * about erroneously looking up the meta-equivalence
  895.          * class twice
  896.          */
  897.  
  898.         if ( yy_curst >= YY_TEMPLATE )
  899.             yy_sym = m[yy_sym];
  900. #endif
  901.         }
  902.  
  903.         yy_curst = n[b[yy_curst] + yy_sym];
  904.  
  905. #endif
  906.  
  907.         yy_st_buf[yy_c_buf_p] = yy_curst;
  908.  
  909.         }
  910. #ifdef FLEX_INTERACTIVE_SCANNER
  911.     while ( b[yy_curst] != YY_JAM_BASE );
  912. #else
  913.     while ( yy_curst != YY_JAM );
  914.     --yy_c_buf_p; /* put back character we jammed on */
  915.  
  916. #endif
  917.  
  918.     if ( yy_c_buf_p >= yy_b_buf_p )
  919.         { /* we matched some text */
  920.         yy_curst = yy_st_buf[yy_c_buf_p];
  921.         yy_lp = l[yy_curst];
  922.  
  923. #ifdef FLEX_REJECT_ENABLED
  924. find_rule: /* we branch to this label when doing a REJECT */
  925. #endif
  926.  
  927.         for ( ; ; ) /* until we find what rule we matched */
  928.         {
  929. #ifdef FLEX_REJECT_ENABLED
  930.         if ( yy_lp && yy_lp < l[yy_curst + 1] )
  931.             {
  932.             yy_act = a[yy_lp];
  933.             goto do_action; /* "continue 2" */
  934.             }
  935. #else
  936.         if ( yy_lp )
  937.             {
  938.             yy_act = yy_lp;
  939.             goto do_action; /* "continue 2" */
  940.             }
  941. #endif
  942.  
  943.         if ( --yy_c_buf_p < yy_b_buf_p )
  944.             break;
  945.  
  946.         yy_curst = yy_st_buf[yy_c_buf_p];
  947.         yy_lp = l[yy_curst];
  948.         }
  949.         }
  950.  
  951.     /* if we got this far, then we didn't find any accepting
  952.      * states
  953.      */
  954.  
  955.     /* so that the default applies to the first char read */
  956.     ++yy_c_buf_p;
  957.  
  958.     yy_act = YY_DO_DEFAULT;
  959.     }
  960.     }
  961.  
  962.     /*NOTREACHED*/
  963.     }
  964.  
  965.  
  966. static int unput( c )
  967. char c;
  968.  
  969.     {
  970.     YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */
  971.  
  972.     if ( yy_c_buf_p == 0 )
  973.     {
  974.     register int i;
  975.     register int yy_buf_pos = YY_BUF_MAX;
  976.  
  977.     for ( i = yy_e_buf_p; i >= yy_c_buf_p; --i )
  978.         {
  979.         yy_ch_buf[yy_buf_pos] = yy_ch_buf[i];
  980.         yy_st_buf[yy_buf_pos] = yy_st_buf[i];
  981.         --yy_buf_pos;
  982.         }
  983.  
  984.     yy_c_buf_p = YY_BUF_MAX - yy_e_buf_p;
  985.     yy_e_buf_p = YY_BUF_MAX;
  986.     }
  987.  
  988.     if ( yy_c_buf_p <= 0 )
  989.     YY_FATAL_ERROR( "flex scanner push-back overflow" );
  990.  
  991.     if ( yy_c_buf_p >= yy_b_buf_p && yy_ch_buf[yy_c_buf_p] == '\n' )
  992.     yy_ch_buf[yy_c_buf_p - 1] = '\n';
  993.  
  994.     yy_ch_buf[yy_c_buf_p--] = c;
  995.  
  996.     YY_DO_BEFORE_ACTION; /* set up yytext again */
  997.     }
  998.  
  999.  
  1000. static int input()
  1001.  
  1002.     {
  1003.     int c;
  1004.  
  1005.     YY_DO_BEFORE_SCAN
  1006.  
  1007.     if ( yy_c_buf_p == yy_e_buf_p )
  1008.     { /* need more input */
  1009.     int yy_n_chars;
  1010.  
  1011.     /* we can throw away the entire current buffer */
  1012.     if ( yy_saw_eof )
  1013.         {
  1014.         if ( yywrap() )
  1015.         return ( EOF );
  1016.  
  1017.         YY_INIT;
  1018.         }
  1019.  
  1020.     yy_b_buf_p = 0;
  1021.     YY_INPUT( yy_ch_buf, yy_n_chars, YY_MAX_LINE );
  1022.  
  1023.     if ( yy_n_chars == YY_NULL )
  1024.         {
  1025.         yy_saw_eof = 1;
  1026.  
  1027.         if ( yywrap() )
  1028.         return ( EOF );
  1029.  
  1030.         YY_INIT;
  1031.  
  1032.         return ( input() );
  1033.         }
  1034.  
  1035.     yy_c_buf_p = -1;
  1036.     yy_e_buf_p = yy_n_chars - 1;
  1037.     }
  1038.  
  1039.     c = yy_ch_buf[++yy_c_buf_p];
  1040.  
  1041.     YY_DO_BEFORE_ACTION;
  1042.  
  1043.     return ( c );
  1044.     }
  1045. # line 358 "menutoc.l"
  1046.  
  1047. dosetval(k)
  1048. int k;
  1049. {    int m;
  1050.  
  1051.     special  = nlist[k][5];
  1052.  
  1053.     if (special == 1 || special == 3) k++;
  1054.     else if (special == 2 || special == 4) k--;
  1055.  
  1056.     bufp     = nlist[k][0];
  1057.     offset   = nlist[k][1];
  1058.     mask     = nlist[k][2];
  1059.     vshift   = nlist[k][3];
  1060.     multiple = nlist[k][4];
  1061.  
  1062.     if (offset < 0) return;
  1063.  
  1064.     if (multiple) for (m = 1; m <= multiple; m++)
  1065.     {    outsetval(m); offset++;        }
  1066.     else    outsetval(0);
  1067. }
  1068.  
  1069. outsetval(m)
  1070. int m;
  1071. {
  1072.     if (!mask && !special) {
  1073.         printf("setval(\"%s", buf+bufp);
  1074.         if (m) printf("%d", m);
  1075.         printf("\",(INT16)data[RESERVESIZE+%d]);\n",offset);
  1076.         return;
  1077.     }
  1078.  
  1079.     printf("i = (INT16)data[RESERVESIZE+%d]; ", offset);
  1080.     if (mask) {
  1081.         printf("i &= %d; ", mask);
  1082.         if (vshift) printf("i >>= %d; ", vshift);
  1083.     }
  1084.  
  1085.     if (special == 2) printf("i += k << 1;\n");
  1086.     else if (special == 4) printf("i += k << 7;\n");
  1087.  
  1088.     if (special == 1 || special == 3) printf("k = i;\n");
  1089.     else {
  1090.         printf("setval(\"%s", buf+bufp);
  1091.         if (m) printf("%d", m);
  1092.         printf("\",i);\n");
  1093.     }
  1094. }
  1095.  
  1096. dogetval(k)
  1097. int k;
  1098. {    int m;
  1099.  
  1100.     bufp     = nlist[k][0];
  1101.     offset   = nlist[k][1];
  1102.     mask     = nlist[k][2];
  1103.     vshift   = nlist[k][3];
  1104.     multiple = nlist[k][4];
  1105.     special  = nlist[k][5];
  1106.  
  1107.     if (offset < 0) return;
  1108.  
  1109.     if (multiple) for (m = 1; m <= multiple; m++)
  1110.     {    outgetval(m); offset++;        }
  1111.     else    outgetval(0);
  1112. }
  1113.  
  1114. outgetval(m)
  1115. int m;
  1116. {
  1117.     if (!mask && !special) {
  1118.         printf("data[RESERVESIZE+%d] = ", offset);
  1119.         printf("getval(\"%s", buf+bufp);
  1120.         if (m) printf("%d", m);
  1121.         printf("\");\n");
  1122.         return;
  1123.     }
  1124.  
  1125.     if (special == 2 || special == 4)
  1126.         printf("i = k; ");
  1127.     else {
  1128.         printf("i = getval(\"%s", buf+bufp);
  1129.         if (m) printf("%d", m);
  1130.         printf("\"); ");
  1131.     }
  1132.  
  1133.     if (special == 1) printf("k = i >> 1; i &= 1;\n");
  1134.     else if (special == 3) printf("k = i >> 7; i &= 0x7f;\n");
  1135.  
  1136.     if (mask) {
  1137.         printf("j = data[RESERVESIZE+%d]; ", offset);
  1138.         if (vshift) printf("i <<= %d; ", vshift);
  1139.         printf("j &= ~%d; ", mask);
  1140.         printf("i = j|i; ");
  1141.     }
  1142.     printf("data[RESERVESIZE+%d] = i;\n", offset);
  1143. }
  1144.  
  1145. main(argc, argv)
  1146. int argc;
  1147. char **argv;
  1148. {    char *basename();
  1149.  
  1150.   if (argc > 1) {
  1151.     infname = basename(argv[1]);
  1152.     if (freopen(argv[1], "r", stdin) == NULL) {
  1153.       perror("Can't open input file");
  1154.       exit(1);
  1155.     }
  1156.   }
  1157.   if (argc > 2) {
  1158.     if (freopen(argv[2], "w", stdout) == NULL) {
  1159.       perror("Can't open output file");
  1160.       exit(1);
  1161.     }
  1162.   }
  1163.  
  1164.     word[0] = 0;
  1165.     BEGIN(IG);
  1166.     yylex();
  1167.     if (i < valcnt) fprintf(stderr,"\nmenutoc: not enough %%%%s\n");
  1168.     if (j < valcnt2) fprintf(stderr,"\nmenutoc: not enough @@s\n");
  1169.     exit(0);
  1170. }
  1171.  
  1172. char   *basename(s)
  1173. char   *s;
  1174. {
  1175.     char   *p;
  1176.     char   *strrchr();
  1177.  
  1178.     if (p = strrchr (s, '/'))
  1179.         return (++p);
  1180.     else
  1181.         return (s);
  1182. }
  1183.  
  1184. append(c)
  1185. char c;
  1186. {
  1187.     if (wordp+1 >= MAXLINE) {
  1188.         fprintf(stderr,"menutoc: string in menu too long\n");
  1189.         exit(1);
  1190.     }
  1191.     if (!wordp) wcol = col;
  1192.     word[wordp++] = c;
  1193.     word[wordp] = 0;
  1194. }
  1195.  
  1196. writeword()
  1197. {
  1198.     if (wordp) {
  1199.         while (word[--wordp] == ' ') ;
  1200.         word[++wordp] = 0;
  1201.         printf("%d,%d,\"%s\",\n", row, wcol, word);
  1202.         wordp = 0;
  1203.         word[wordp] = 0;
  1204.     }
  1205. }
  1206.