Home | History | Annotate | Line # | Download | only in menuc
parse.y revision 1.17
      1  1.17   martin /*	$NetBSD: parse.y,v 1.17 2018/11/21 20:04:48 martin Exp $	*/
      2   1.1     phil 
      3   1.1     phil /*
      4   1.1     phil  * Copyright 1997 Piermont Information Systems Inc.
      5   1.1     phil  * All rights reserved.
      6   1.1     phil  *
      7   1.1     phil  * Written by Philip A. Nelson for Piermont Information Systems Inc.
      8   1.1     phil  *
      9   1.1     phil  * Redistribution and use in source and binary forms, with or without
     10   1.1     phil  * modification, are permitted provided that the following conditions
     11   1.1     phil  * are met:
     12   1.1     phil  * 1. Redistributions of source code must retain the above copyright
     13   1.1     phil  *    notice, this list of conditions and the following disclaimer.
     14   1.1     phil  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1     phil  *    notice, this list of conditions and the following disclaimer in the
     16   1.1     phil  *    documentation and/or other materials provided with the distribution.
     17  1.16  mbalmer  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
     18   1.1     phil  *    or promote products derived from this software without specific prior
     19   1.1     phil  *    written permission.
     20   1.1     phil  *
     21   1.1     phil  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
     22   1.1     phil  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23   1.1     phil  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24   1.1     phil  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
     25   1.1     phil  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26   1.1     phil  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27   1.1     phil  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28   1.1     phil  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29   1.1     phil  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30   1.1     phil  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     31   1.1     phil  * THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1     phil  *
     33   1.1     phil  */
     34   1.1     phil 
     35   1.1     phil 
     36   1.1     phil %{
     37   1.1     phil 
     38   1.1     phil #include <stdio.h>
     39   1.1     phil #include "defs.h"
     40   1.1     phil 
     41   1.1     phil static id_rec *cur_menu;
     42   1.1     phil static optn_info *cur_optn;
     43   1.1     phil 
     44   1.1     phil %}
     45   1.1     phil 
     46   1.1     phil %union {
     47   1.1     phil 	char *s_value;
     48   1.1     phil 	int   i_value;
     49   1.1     phil 	optn_info *optn_value;
     50   1.1     phil 	action a_value;
     51   1.1     phil }
     52   1.1     phil 
     53   1.1     phil 
     54   1.3     phil %token <i_value> X Y W H NO BOX SUB HELP MENU NEXT EXIT ACTION ENDWIN OPTION
     55  1.17   martin %token <i_value> TITLE DEFAULT DISPLAY ERROR EXITSTRING EXPAND ALLOW DYNAMIC
     56  1.17   martin 		 MENUS SCROLLABLE SHORTCUT CLEAR MESSAGES ALWAYS SCROLL
     57   1.1     phil %token <s_value> STRING NAME CODE INT_CONST CHAR_CONST
     58   1.1     phil 
     59  1.11      dsl %type <s_value> init_code system helpstr text
     60   1.1     phil %type <optn_value> option option_list
     61   1.1     phil %type <i_value> act_opt
     62   1.1     phil %type <a_value> action exitact
     63   1.1     phil 
     64   1.1     phil %start system
     65   1.1     phil 
     66   1.1     phil %%
     67   1.1     phil 
     68   1.1     phil system : init_code menu_list
     69   1.1     phil 	 { check_defined();
     70   1.1     phil 	   if (!had_errors)
     71   1.1     phil 		   write_menu_file($1);
     72   1.1     phil 	 }
     73   1.1     phil        ;
     74   1.1     phil 
     75   1.1     phil init_code : /* empty */ { $$ = ""; }
     76   1.1     phil 	  | CODE
     77   1.1     phil 	  ;
     78   1.1     phil 
     79   1.1     phil menu_list :  /* empty */
     80   1.1     phil 	  |  menu_list menu_def
     81   1.1     phil 	  |  menu_list default_def
     82   1.2     phil 	  |  menu_list initerror_def
     83  1.17   martin 	  |  menu_list expand_def
     84   1.5     phil 	  |  menu_list dynamic_def
     85  1.12      dsl 	  |  menu_list msgxlat_def
     86   1.1     phil 	  ;
     87   1.5     phil 
     88   1.6     phil dynamic_def : ALLOW DYNAMIC MENUS ';'
     89   1.5     phil 		{ do_dynamic = 1; }
     90  1.12      dsl 
     91  1.17   martin expand_def : ALLOW EXPAND ';'
     92  1.17   martin 		{ do_expands = 1; }
     93  1.17   martin 
     94  1.12      dsl msgxlat_def : ALLOW DYNAMIC MESSAGES ';'
     95  1.12      dsl 		{ do_msgxlat = 1; }
     96   1.2     phil 
     97   1.2     phil initerror_def : ERROR action ';'
     98   1.2     phil 		{ error_act = $2; }
     99   1.1     phil 
    100   1.1     phil default_def : DEFAULT
    101   1.1     phil 		{ cur_menu = &default_menu; }
    102   1.1     phil 	      opt opt_list ";"
    103   1.1     phil 
    104   1.1     phil menu_def  :  MENU NAME
    105   1.1     phil 		{ cur_menu = get_menu ($2);
    106   1.1     phil 		  if (cur_menu->info != NULL)
    107   1.1     phil 			  yyerror ("Menu %s defined twice", $2);
    108   1.1     phil 		  else {
    109   1.1     phil 			  cur_menu->info =
    110   1.1     phil 				  (menu_info *) malloc (sizeof (menu_info));
    111   1.1     phil 			  *(cur_menu->info) = default_info;
    112   1.1     phil 		  }
    113   1.1     phil 		}
    114  1.17   martin 	     opts ";" expaction dispact option_list exitact helpstr
    115   1.1     phil 		{ optn_info *t;
    116   1.1     phil 		  cur_menu->info->optns = NULL;
    117  1.17   martin 		  while ($8 != NULL) {
    118  1.17   martin 			  t = $8;
    119  1.17   martin 			  $8 = $8->next;
    120   1.1     phil 			  t->next = cur_menu->info->optns;
    121   1.1     phil 			  cur_menu->info->optns = t;
    122   1.1     phil 			  cur_menu->info->numopt++;
    123   1.1     phil 		  }
    124   1.1     phil 		}
    125   1.1     phil 	  ;
    126   1.1     phil 
    127   1.1     phil opts	  : /* empty */
    128   1.1     phil 	  | opt_list
    129   1.1     phil 	  ;
    130   1.1     phil 
    131   1.1     phil opt_list  : "," opt
    132   1.1     phil 	  | opt_list "," opt
    133   1.1     phil 	  ;
    134   1.1     phil 
    135  1.11      dsl text	  : NAME | STRING
    136  1.11      dsl 
    137  1.14      dsl opt	  : NO EXIT		{ cur_menu->info->mopt |= MC_NOEXITOPT; }
    138  1.14      dsl 	  | EXIT		{ cur_menu->info->mopt &= ~MC_NOEXITOPT; }
    139  1.14      dsl 	  | NO BOX		{ cur_menu->info->mopt |= MC_NOBOX; }
    140  1.14      dsl 	  | BOX			{ cur_menu->info->mopt &= ~MC_NOBOX; }
    141  1.14      dsl 	  | NO SCROLLABLE	{ cur_menu->info->mopt &= ~MC_SCROLL; }
    142  1.14      dsl 	  | SCROLLABLE		{ cur_menu->info->mopt |= MC_SCROLL; }
    143  1.14      dsl 	  | NO SHORTCUT 	{ cur_menu->info->mopt |= MC_NOSHORTCUT; }
    144  1.14      dsl 	  | SHORTCUT 		{ cur_menu->info->mopt &= ~MC_NOSHORTCUT; }
    145  1.14      dsl 	  | NO CLEAR 		{ cur_menu->info->mopt |= MC_NOCLEAR; }
    146  1.14      dsl 	  | CLEAR 		{ cur_menu->info->mopt &= ~MC_NOCLEAR; }
    147  1.14      dsl 	  | NO DEFAULT EXIT	{ cur_menu->info->mopt &= ~MC_DFLTEXIT; }
    148  1.14      dsl 	  | DEFAULT EXIT 	{ cur_menu->info->mopt |= MC_DFLTEXIT; }
    149  1.14      dsl 	  | NO ALWAYS SCROLL	{ cur_menu->info->mopt &= ~MC_ALWAYS_SCROLL; }
    150  1.14      dsl 	  | ALWAYS SCROLL 	{ cur_menu->info->mopt |= MC_ALWAYS_SCROLL; }
    151  1.14      dsl 	  | NO SUB MENU		{ cur_menu->info->mopt &= ~MC_SUBMENU; }
    152  1.14      dsl 	  | SUB MENU 		{ cur_menu->info->mopt |= MC_SUBMENU; }
    153   1.1     phil 	  | X "=" INT_CONST	{ cur_menu->info->x = atoi($3); }
    154   1.1     phil 	  | Y "=" INT_CONST	{ cur_menu->info->y = atoi($3); }
    155   1.1     phil 	  | W "=" INT_CONST	{ cur_menu->info->w = atoi($3); }
    156   1.1     phil 	  | H "=" INT_CONST	{ cur_menu->info->h = atoi($3); }
    157  1.11      dsl 	  | TITLE text	 	{ cur_menu->info->title = $2; }
    158  1.11      dsl 	  | EXITSTRING text	{ cur_menu->info->exitstr = $2;
    159  1.14      dsl 				  cur_menu->info->mopt &= ~MC_NOEXITOPT; }
    160   1.1     phil 	  ;
    161   1.1     phil 
    162   1.1     phil option_list : option
    163   1.1     phil 	  | option_list option  { $2->next = $1; $$ = $2; }
    164   1.1     phil 	  ;
    165   1.1     phil 
    166  1.15      dsl option	  : OPTION
    167   1.1     phil 		{ cur_optn = (optn_info *) malloc (sizeof(optn_info));
    168   1.1     phil 		  cur_optn->menu = -1;
    169  1.15      dsl 		  cur_optn->name = NULL;
    170  1.15      dsl 		  cur_optn->name_is_code = FALSE;
    171   1.1     phil 		  cur_optn->issub = FALSE;
    172   1.1     phil 		  cur_optn->doexit = FALSE;
    173   1.1     phil 		  cur_optn->optact.code = "";
    174   1.1     phil 		  cur_optn->optact.endwin = FALSE;
    175   1.1     phil 		  cur_optn->next = NULL;
    176   1.1     phil 		}
    177  1.15      dsl 	    option_legend ","
    178   1.1     phil 	    elem_list ";"
    179   1.1     phil 		{ $$ = cur_optn; }
    180   1.1     phil 	  ;
    181   1.1     phil 
    182  1.15      dsl option_legend : text	{ cur_optn->name = $1; }
    183  1.15      dsl 	  | CODE	{ cur_optn->name = $1; cur_optn->name_is_code = TRUE;}
    184  1.15      dsl 
    185   1.1     phil elem_list : elem
    186   1.1     phil 	  | elem_list "," elem
    187   1.1     phil 	  ;
    188   1.1     phil 
    189   1.1     phil elem	  : NEXT MENU NAME
    190   1.1     phil 		{ id_rec *t = get_menu ($3);
    191   1.1     phil 		  if (cur_optn->menu != -1)
    192   1.1     phil 			  yyerror ("Double sub/next menu definition");
    193   1.1     phil 		  else {
    194   1.1     phil 			  cur_optn->menu = t->menu_no;
    195   1.1     phil 		  }
    196   1.1     phil 		}
    197   1.1     phil 	  | SUB MENU NAME
    198   1.1     phil 		{ id_rec *t = get_menu ($3);
    199   1.1     phil 		  if (cur_optn->menu != -1)
    200   1.1     phil 			  yyerror ("Double sub/next menu definition");
    201   1.1     phil 		  else {
    202   1.1     phil 			  cur_optn->menu = t->menu_no;
    203   1.1     phil 			  cur_optn->issub = TRUE;
    204   1.1     phil 		  }
    205   1.1     phil 		}
    206   1.1     phil 	  | action	{ cur_optn->optact = $1; }
    207   1.1     phil 	  | EXIT	{ cur_optn->doexit = TRUE; }
    208   1.1     phil 	  ;
    209   1.1     phil 
    210   1.1     phil action	  : ACTION act_opt CODE
    211   1.1     phil 		{ $$.code = $3;
    212   1.1     phil 		  $$.endwin = $2;
    213   1.1     phil 		}
    214   1.1     phil 	  ;
    215   1.1     phil 
    216   1.1     phil act_opt	  : /* empty */		{ $$ = 0; }
    217   1.1     phil 	  | "(" ENDWIN ")"	{ $$ = 1; }
    218   1.1     phil 	  ;
    219   1.1     phil 
    220  1.17   martin expaction : /* empty */ 	{ cur_menu->info->expact.code = ""; }
    221  1.17   martin 	  | EXPAND action ";"	{ if (!do_expands) yyerror ("Menu expands "
    222  1.17   martin 	  						     "not enabled");
    223  1.17   martin 	  			  cur_menu->info->expact = $2; }
    224  1.17   martin 	  ;
    225  1.17   martin 
    226   1.1     phil dispact	  : /* empty */ 	{ cur_menu->info->postact.code = ""; }
    227   1.1     phil 	  | DISPLAY action ";"	{ cur_menu->info->postact = $2; }
    228   1.1     phil 	  ;
    229   1.1     phil 
    230   1.1     phil 
    231   1.1     phil exitact	  : /* empty */ 	{ cur_menu->info->exitact.code = ""; }
    232   1.1     phil 	  | EXIT action	";"	{ cur_menu->info->exitact = $2; }
    233   1.1     phil 	  ;
    234   1.1     phil 
    235   1.3     phil helpstr	  : /* empty */ 	{ cur_menu->info->helpstr = NULL; }
    236  1.14      dsl 	  | HELP CODE ";" 	{ asprintf(&cur_menu->info->helpstr, "\"%s\"", $2); }
    237  1.14      dsl 	  | HELP text ";" 	{ cur_menu->info->helpstr = $2; }
    238   1.3     phil 	  ;
    239