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