Sync usage with man page.
[netbsd-mini2440.git] / usr.bin / menuc / parse.y
bloba772602a3e3c5f63ffb04dc2901f755fd076d253
1 /* $NetBSD: parse.y,v 1.14 2004/08/02 21:29:07 dsl Exp $ */
3 /*
4 * Copyright 1997 Piermont Information Systems Inc.
5 * All rights reserved.
7 * Written by Philip A. Nelson for Piermont Information Systems Inc.
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. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software develooped for the NetBSD Project by
20 * Piermont Information Systems Inc.
21 * 4. The name of Piermont Information Systems Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
25 * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE.
42 #include <stdio.h>
43 #include "defs.h"
45 static id_rec *cur_menu;
46 static optn_info *cur_optn;
50 %union {
51 char *s_value;
52 int i_value;
53 optn_info *optn_value;
54 action a_value;
58 %token <i_value> X Y W H NO BOX SUB HELP MENU NEXT EXIT ACTION ENDWIN OPTION
59 %token <i_value> TITLE DEFAULT DISPLAY ERROR EXITSTRING ALLOW DYNAMIC MENUS
60 SCROLLABLE SHORTCUT CLEAR MESSAGES ALWAYS SCROLL
61 %token <s_value> STRING NAME CODE INT_CONST CHAR_CONST
63 %type <s_value> init_code system helpstr text
64 %type <optn_value> option option_list
65 %type <i_value> act_opt
66 %type <a_value> action exitact
68 %start system
72 system : init_code menu_list
73 { check_defined();
74 if (!had_errors)
75 write_menu_file($1);
79 init_code : /* empty */ { $$ = ""; }
80 | CODE
83 menu_list : /* empty */
84 | menu_list menu_def
85 | menu_list default_def
86 | menu_list initerror_def
87 | menu_list dynamic_def
88 | menu_list msgxlat_def
91 dynamic_def : ALLOW DYNAMIC MENUS ';'
92 { do_dynamic = 1; }
94 msgxlat_def : ALLOW DYNAMIC MESSAGES ';'
95 { do_msgxlat = 1; }
97 initerror_def : ERROR action ';'
98 { error_act = $2; }
100 default_def : DEFAULT
101 { cur_menu = &default_menu; }
102 opt opt_list ";"
104 menu_def : MENU NAME
105 { cur_menu = get_menu ($2);
106 if (cur_menu->info != NULL)
107 yyerror ("Menu %s defined twice", $2);
108 else {
109 cur_menu->info =
110 (menu_info *) malloc (sizeof (menu_info));
111 *(cur_menu->info) = default_info;
114 opts ";" dispact option_list exitact helpstr
115 { optn_info *t;
116 cur_menu->info->optns = NULL;
117 while ($7 != NULL) {
118 t = $7;
119 $7 = $7->next;
120 t->next = cur_menu->info->optns;
121 cur_menu->info->optns = t;
122 cur_menu->info->numopt++;
127 opts : /* empty */
128 | opt_list
131 opt_list : "," opt
132 | opt_list "," opt
135 text : NAME | STRING
137 opt : NO EXIT { cur_menu->info->mopt |= MC_NOEXITOPT; }
138 | EXIT { cur_menu->info->mopt &= ~MC_NOEXITOPT; }
139 | NO BOX { cur_menu->info->mopt |= MC_NOBOX; }
140 | BOX { cur_menu->info->mopt &= ~MC_NOBOX; }
141 | NO SCROLLABLE { cur_menu->info->mopt &= ~MC_SCROLL; }
142 | SCROLLABLE { cur_menu->info->mopt |= MC_SCROLL; }
143 | NO SHORTCUT { cur_menu->info->mopt |= MC_NOSHORTCUT; }
144 | SHORTCUT { cur_menu->info->mopt &= ~MC_NOSHORTCUT; }
145 | NO CLEAR { cur_menu->info->mopt |= MC_NOCLEAR; }
146 | CLEAR { cur_menu->info->mopt &= ~MC_NOCLEAR; }
147 | NO DEFAULT EXIT { cur_menu->info->mopt &= ~MC_DFLTEXIT; }
148 | DEFAULT EXIT { cur_menu->info->mopt |= MC_DFLTEXIT; }
149 | NO ALWAYS SCROLL { cur_menu->info->mopt &= ~MC_ALWAYS_SCROLL; }
150 | ALWAYS SCROLL { cur_menu->info->mopt |= MC_ALWAYS_SCROLL; }
151 | NO SUB MENU { cur_menu->info->mopt &= ~MC_SUBMENU; }
152 | SUB MENU { cur_menu->info->mopt |= MC_SUBMENU; }
153 | X "=" INT_CONST { cur_menu->info->x = atoi($3); }
154 | Y "=" INT_CONST { cur_menu->info->y = atoi($3); }
155 | W "=" INT_CONST { cur_menu->info->w = atoi($3); }
156 | H "=" INT_CONST { cur_menu->info->h = atoi($3); }
157 | TITLE text { cur_menu->info->title = $2; }
158 | EXITSTRING text { cur_menu->info->exitstr = $2;
159 cur_menu->info->mopt &= ~MC_NOEXITOPT; }
162 option_list : option
163 | option_list option { $2->next = $1; $$ = $2; }
166 option : OPTION
167 { cur_optn = (optn_info *) malloc (sizeof(optn_info));
168 cur_optn->menu = -1;
169 cur_optn->name = NULL;
170 cur_optn->name_is_code = FALSE;
171 cur_optn->issub = FALSE;
172 cur_optn->doexit = FALSE;
173 cur_optn->optact.code = "";
174 cur_optn->optact.endwin = FALSE;
175 cur_optn->next = NULL;
177 option_legend ","
178 elem_list ";"
179 { $$ = cur_optn; }
182 option_legend : text { cur_optn->name = $1; }
183 | CODE { cur_optn->name = $1; cur_optn->name_is_code = TRUE;}
185 elem_list : elem
186 | elem_list "," elem
189 elem : NEXT MENU NAME
190 { id_rec *t = get_menu ($3);
191 if (cur_optn->menu != -1)
192 yyerror ("Double sub/next menu definition");
193 else {
194 cur_optn->menu = t->menu_no;
197 | SUB MENU NAME
198 { id_rec *t = get_menu ($3);
199 if (cur_optn->menu != -1)
200 yyerror ("Double sub/next menu definition");
201 else {
202 cur_optn->menu = t->menu_no;
203 cur_optn->issub = TRUE;
206 | action { cur_optn->optact = $1; }
207 | EXIT { cur_optn->doexit = TRUE; }
210 action : ACTION act_opt CODE
211 { $$.code = $3;
212 $$.endwin = $2;
216 act_opt : /* empty */ { $$ = 0; }
217 | "(" ENDWIN ")" { $$ = 1; }
220 dispact : /* empty */ { cur_menu->info->postact.code = ""; }
221 | DISPLAY action ";" { cur_menu->info->postact = $2; }
225 exitact : /* empty */ { cur_menu->info->exitact.code = ""; }
226 | EXIT action ";" { cur_menu->info->exitact = $2; }
229 helpstr : /* empty */ { cur_menu->info->helpstr = NULL; }
230 | HELP CODE ";" { asprintf(&cur_menu->info->helpstr, "\"%s\"", $2); }
231 | HELP text ";" { cur_menu->info->helpstr = $2; }