1 /* $NetBSD: parse.y,v 1.16 2012/03/06 16:55:18 mbalmer 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 ALLOW DYNAMIC MENUS 56 SCROLLABLE SHORTCUT CLEAR MESSAGES ALWAYS SCROLL 57 %token <s_value> STRING NAME CODE INT_CONST CHAR_CONST 58 59 %type <s_value> init_code system helpstr text 60 %type <optn_value> option option_list 61 %type <i_value> act_opt 62 %type <a_value> action exitact 63 64 %start system 65 66 %% 67 68 system : init_code menu_list 69 { check_defined(); 70 if (!had_errors) 71 write_menu_file($1); 72 } 73 ; 74 75 init_code : /* empty */ { $$ = ""; } 76 | CODE 77 ; 78 79 menu_list : /* empty */ 80 | menu_list menu_def 81 | menu_list default_def 82 | menu_list initerror_def 83 | menu_list dynamic_def 84 | menu_list msgxlat_def 85 ; 86 87 dynamic_def : ALLOW DYNAMIC MENUS ';' 88 { do_dynamic = 1; } 89 90 msgxlat_def : ALLOW DYNAMIC MESSAGES ';' 91 { do_msgxlat = 1; } 92 93 initerror_def : ERROR action ';' 94 { error_act = $2; } 95 96 default_def : DEFAULT 97 { cur_menu = &default_menu; } 98 opt opt_list ";" 99 100 menu_def : MENU NAME 101 { cur_menu = get_menu ($2); 102 if (cur_menu->info != NULL) 103 yyerror ("Menu %s defined twice", $2); 104 else { 105 cur_menu->info = 106 (menu_info *) malloc (sizeof (menu_info)); 107 *(cur_menu->info) = default_info; 108 } 109 } 110 opts ";" dispact option_list exitact helpstr 111 { optn_info *t; 112 cur_menu->info->optns = NULL; 113 while ($7 != NULL) { 114 t = $7; 115 $7 = $7->next; 116 t->next = cur_menu->info->optns; 117 cur_menu->info->optns = t; 118 cur_menu->info->numopt++; 119 } 120 } 121 ; 122 123 opts : /* empty */ 124 | opt_list 125 ; 126 127 opt_list : "," opt 128 | opt_list "," opt 129 ; 130 131 text : NAME | STRING 132 133 opt : NO EXIT { cur_menu->info->mopt |= MC_NOEXITOPT; } 134 | EXIT { cur_menu->info->mopt &= ~MC_NOEXITOPT; } 135 | NO BOX { cur_menu->info->mopt |= MC_NOBOX; } 136 | BOX { cur_menu->info->mopt &= ~MC_NOBOX; } 137 | NO SCROLLABLE { cur_menu->info->mopt &= ~MC_SCROLL; } 138 | SCROLLABLE { cur_menu->info->mopt |= MC_SCROLL; } 139 | NO SHORTCUT { cur_menu->info->mopt |= MC_NOSHORTCUT; } 140 | SHORTCUT { cur_menu->info->mopt &= ~MC_NOSHORTCUT; } 141 | NO CLEAR { cur_menu->info->mopt |= MC_NOCLEAR; } 142 | CLEAR { cur_menu->info->mopt &= ~MC_NOCLEAR; } 143 | NO DEFAULT EXIT { cur_menu->info->mopt &= ~MC_DFLTEXIT; } 144 | DEFAULT EXIT { cur_menu->info->mopt |= MC_DFLTEXIT; } 145 | NO ALWAYS SCROLL { cur_menu->info->mopt &= ~MC_ALWAYS_SCROLL; } 146 | ALWAYS SCROLL { cur_menu->info->mopt |= MC_ALWAYS_SCROLL; } 147 | NO SUB MENU { cur_menu->info->mopt &= ~MC_SUBMENU; } 148 | SUB MENU { cur_menu->info->mopt |= MC_SUBMENU; } 149 | X "=" INT_CONST { cur_menu->info->x = atoi($3); } 150 | Y "=" INT_CONST { cur_menu->info->y = atoi($3); } 151 | W "=" INT_CONST { cur_menu->info->w = atoi($3); } 152 | H "=" INT_CONST { cur_menu->info->h = atoi($3); } 153 | TITLE text { cur_menu->info->title = $2; } 154 | EXITSTRING text { cur_menu->info->exitstr = $2; 155 cur_menu->info->mopt &= ~MC_NOEXITOPT; } 156 ; 157 158 option_list : option 159 | option_list option { $2->next = $1; $$ = $2; } 160 ; 161 162 option : OPTION 163 { cur_optn = (optn_info *) malloc (sizeof(optn_info)); 164 cur_optn->menu = -1; 165 cur_optn->name = NULL; 166 cur_optn->name_is_code = FALSE; 167 cur_optn->issub = FALSE; 168 cur_optn->doexit = FALSE; 169 cur_optn->optact.code = ""; 170 cur_optn->optact.endwin = FALSE; 171 cur_optn->next = NULL; 172 } 173 option_legend "," 174 elem_list ";" 175 { $$ = cur_optn; } 176 ; 177 178 option_legend : text { cur_optn->name = $1; } 179 | CODE { cur_optn->name = $1; cur_optn->name_is_code = TRUE;} 180 181 elem_list : elem 182 | elem_list "," elem 183 ; 184 185 elem : NEXT MENU NAME 186 { id_rec *t = get_menu ($3); 187 if (cur_optn->menu != -1) 188 yyerror ("Double sub/next menu definition"); 189 else { 190 cur_optn->menu = t->menu_no; 191 } 192 } 193 | SUB MENU NAME 194 { id_rec *t = get_menu ($3); 195 if (cur_optn->menu != -1) 196 yyerror ("Double sub/next menu definition"); 197 else { 198 cur_optn->menu = t->menu_no; 199 cur_optn->issub = TRUE; 200 } 201 } 202 | action { cur_optn->optact = $1; } 203 | EXIT { cur_optn->doexit = TRUE; } 204 ; 205 206 action : ACTION act_opt CODE 207 { $$.code = $3; 208 $$.endwin = $2; 209 } 210 ; 211 212 act_opt : /* empty */ { $$ = 0; } 213 | "(" ENDWIN ")" { $$ = 1; } 214 ; 215 216 dispact : /* empty */ { cur_menu->info->postact.code = ""; } 217 | DISPLAY action ";" { cur_menu->info->postact = $2; } 218 ; 219 220 221 exitact : /* empty */ { cur_menu->info->exitact.code = ""; } 222 | EXIT action ";" { cur_menu->info->exitact = $2; } 223 ; 224 225 helpstr : /* empty */ { cur_menu->info->helpstr = NULL; } 226 | HELP CODE ";" { asprintf(&cur_menu->info->helpstr, "\"%s\"", $2); } 227 | HELP text ";" { cur_menu->info->helpstr = $2; } 228 ; 229