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