blob: 22e318c1d3d17416943c487d54ede0ab24b794fd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001%{
2/*
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
5 */
6
7#include <ctype.h>
8#include <stdarg.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <stdbool.h>
13
Roman Zippel7a884882005-11-08 21:34:51 -080014#include "lkc.h"
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
17
18#define PRINTD 0x0001
19#define DEBUG_PARSE 0x0002
20
21int cdebug = PRINTD;
22
Masahiro Yamada765f4cd2018-01-12 00:50:50 +090023int yylex(void);
24static void yyerror(const char *err);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static void zconfprint(const char *err, ...);
Roman Zippela02f0572005-11-08 21:34:53 -080026static void zconf_error(const char *err, ...);
Arnaud Lacombe61f956f2011-05-04 21:14:44 -040027static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Andi Kleene66f25d2010-01-13 17:02:44 +010029struct symbol *symbol_hash[SYMBOL_HASHSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31static struct menu *current_menu, *current_entry;
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033%}
Nicolas Pitre237e3ad2016-11-11 00:10:05 -050034%expect 32
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36%union
37{
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 char *string;
Roman Zippela02f0572005-11-08 21:34:53 -080039 struct file *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 struct symbol *symbol;
41 struct expr *expr;
42 struct menu *menu;
Arnaud Lacombe61f956f2011-05-04 21:14:44 -040043 const struct kconf_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
Roman Zippel3370f9f2005-11-08 21:34:52 -080046%token <id>T_MAINMENU
47%token <id>T_MENU
48%token <id>T_ENDMENU
49%token <id>T_SOURCE
50%token <id>T_CHOICE
51%token <id>T_ENDCHOICE
52%token <id>T_COMMENT
53%token <id>T_CONFIG
54%token <id>T_MENUCONFIG
55%token <id>T_HELP
Linus Torvalds1da177e2005-04-16 15:20:36 -070056%token <string> T_HELPTEXT
Roman Zippel3370f9f2005-11-08 21:34:52 -080057%token <id>T_IF
58%token <id>T_ENDIF
59%token <id>T_DEPENDS
Roman Zippel3370f9f2005-11-08 21:34:52 -080060%token <id>T_OPTIONAL
61%token <id>T_PROMPT
62%token <id>T_TYPE
63%token <id>T_DEFAULT
64%token <id>T_SELECT
Nicolas Pitre237e3ad2016-11-11 00:10:05 -050065%token <id>T_IMPLY
Roman Zippel3370f9f2005-11-08 21:34:52 -080066%token <id>T_RANGE
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030067%token <id>T_VISIBLE
Roman Zippelf6a88aa2006-06-08 22:12:44 -070068%token <id>T_OPTION
Roman Zippel3370f9f2005-11-08 21:34:52 -080069%token <id>T_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -070070%token <string> T_WORD
71%token <string> T_WORD_QUOTE
72%token T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010073%token T_LESS
74%token T_LESS_EQUAL
75%token T_GREATER
76%token T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070077%token T_CLOSE_PAREN
78%token T_OPEN_PAREN
Roman Zippel3370f9f2005-11-08 21:34:52 -080079%token T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81%left T_OR
82%left T_AND
83%left T_EQUAL T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010084%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070085%nonassoc T_NOT
86
87%type <string> prompt
Ulf Magnusson26e47a32017-10-08 19:11:18 +020088%type <symbol> nonconst_symbol
Linus Torvalds1da177e2005-04-16 15:20:36 -070089%type <symbol> symbol
90%type <expr> expr
91%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080092%type <id> end
93%type <id> option_name
94%type <menu> if_entry menu_entry choice_entry
Roman Zippel5a1aa8a2008-02-29 05:11:50 +010095%type <string> symbol_option_arg word_opt
Roman Zippela02f0572005-11-08 21:34:53 -080096
97%destructor {
98 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
99 $$->file->name, $$->lineno);
100 if (current_menu == $$)
101 menu_end_menu();
102} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Josh Triplett1456edb2009-10-15 11:03:20 -0700104%{
Ulf Magnussonc8734432017-10-05 05:06:48 +0200105/* Include kconf_id.c here so it can see the token constants. */
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700106#include "kconf_id.c"
Josh Triplett1456edb2009-10-15 11:03:20 -0700107%}
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109%%
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400110input: nl start | start;
111
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900112start: mainmenu_stmt stmt_list | stmt_list;
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200113
114/* mainmenu entry */
115
116mainmenu_stmt: T_MAINMENU prompt nl
117{
118 menu_add_prompt(P_MENU, $2, NULL);
119};
120
Roman Zippela02f0572005-11-08 21:34:53 -0800121stmt_list:
122 /* empty */
123 | stmt_list common_stmt
124 | stmt_list choice_stmt
125 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800126 | stmt_list end { zconf_error("unexpected end statement"); }
127 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
128 | stmt_list option_name error T_EOL
129{
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700130 zconf_error("unexpected option \"%s\"", $2->name);
Roman Zippela02f0572005-11-08 21:34:53 -0800131}
132 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133;
134
Roman Zippela02f0572005-11-08 21:34:53 -0800135option_name:
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500136 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137;
138
Roman Zippela02f0572005-11-08 21:34:53 -0800139common_stmt:
140 T_EOL
141 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 | comment_stmt
143 | config_stmt
144 | menuconfig_stmt
145 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800146;
147
148option_error:
149 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
150 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151;
152
153
154/* config/menuconfig entry */
155
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200156config_entry_start: T_CONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200158 $2->flags |= SYMBOL_OPTIONAL;
159 menu_add_entry($2);
160 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161};
162
163config_stmt: config_entry_start config_option_list
164{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
166};
167
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200168menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200170 $2->flags |= SYMBOL_OPTIONAL;
171 menu_add_entry($2);
172 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
175menuconfig_stmt: menuconfig_entry_start config_option_list
176{
177 if (current_entry->prompt)
178 current_entry->prompt->type = P_MENU;
179 else
180 zconfprint("warning: menuconfig statement without prompt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
182};
183
184config_option_list:
185 /* empty */
186 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700187 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 | config_option_list depends
189 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800190 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 | config_option_list T_EOL
192;
193
Roman Zippel3370f9f2005-11-08 21:34:52 -0800194config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800196 menu_set_type($1->stype);
197 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
198 zconf_curname(), zconf_lineno(),
199 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
202config_option: T_PROMPT prompt if_expr T_EOL
203{
204 menu_add_prompt(P_PROMPT, $2, $3);
205 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
206};
207
208config_option: T_DEFAULT expr if_expr T_EOL
209{
210 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800211 if ($1->stype != S_UNKNOWN)
212 menu_set_type($1->stype);
213 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
214 zconf_curname(), zconf_lineno(),
215 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216};
217
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200218config_option: T_SELECT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200220 menu_add_symbol(P_SELECT, $2, $3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
222};
223
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200224config_option: T_IMPLY nonconst_symbol if_expr T_EOL
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500225{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200226 menu_add_symbol(P_IMPLY, $2, $3);
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500227 printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
228};
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230config_option: T_RANGE symbol symbol if_expr T_EOL
231{
232 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
233 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
234};
235
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700236symbol_option: T_OPTION symbol_option_list T_EOL
237;
238
239symbol_option_list:
240 /* empty */
241 | symbol_option_list T_WORD symbol_option_arg
242{
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400243 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
Ulf Magnussonbc28fe12017-10-08 19:11:20 +0200244 if (id && id->flags & TF_OPTION) {
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700245 menu_add_option(id->token, $3);
Ulf Magnussonbc28fe12017-10-08 19:11:20 +0200246 free($3);
247 }
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700248 else
249 zconfprint("warning: ignoring unknown option %s", $2);
250 free($2);
251};
252
253symbol_option_arg:
254 /* empty */ { $$ = NULL; }
255 | T_EQUAL prompt { $$ = $2; }
256;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* choice entry */
259
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100260choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100262 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
263 sym->flags |= SYMBOL_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 menu_add_entry(sym);
265 menu_add_expr(P_CHOICE, NULL, NULL);
Masahiro Yamadabf0bbdc2018-02-20 20:40:29 +0900266 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
268};
269
270choice_entry: choice choice_option_list
271{
Roman Zippela02f0572005-11-08 21:34:53 -0800272 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273};
274
275choice_end: end
276{
277 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
278 menu_end_menu();
279 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
280 }
281};
282
Roman Zippela02f0572005-11-08 21:34:53 -0800283choice_stmt: choice_entry choice_block choice_end
284;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286choice_option_list:
287 /* empty */
288 | choice_option_list choice_option
289 | choice_option_list depends
290 | choice_option_list help
291 | choice_option_list T_EOL
Roman Zippela02f0572005-11-08 21:34:53 -0800292 | choice_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293;
294
295choice_option: T_PROMPT prompt if_expr T_EOL
296{
297 menu_add_prompt(P_PROMPT, $2, $3);
298 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
299};
300
Roman Zippel3370f9f2005-11-08 21:34:52 -0800301choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800303 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
304 menu_set_type($1->stype);
305 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
306 zconf_curname(), zconf_lineno(),
307 $1->stype);
308 } else
309 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310};
311
312choice_option: T_OPTIONAL T_EOL
313{
314 current_entry->sym->flags |= SYMBOL_OPTIONAL;
315 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
316};
317
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200318choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800320 if ($1->stype == S_UNKNOWN) {
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200321 menu_add_symbol(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800322 printd(DEBUG_PARSE, "%s:%d:default\n",
323 zconf_curname(), zconf_lineno());
324 } else
325 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326};
327
328choice_block:
329 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800330 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331;
332
333/* if entry */
334
Roman Zippela02f0572005-11-08 21:34:53 -0800335if_entry: T_IF expr nl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
337 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
338 menu_add_entry(NULL);
339 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800340 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341};
342
343if_end: end
344{
345 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
346 menu_end_menu();
347 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
348 }
349};
350
Roman Zippela02f0572005-11-08 21:34:53 -0800351if_stmt: if_entry if_block if_end
352;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354if_block:
355 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800356 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 | if_block menu_stmt
358 | if_block choice_stmt
359;
360
361/* menu entry */
362
363menu: T_MENU prompt T_EOL
364{
365 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200366 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
368};
369
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300370menu_entry: menu visibility_list depends_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Roman Zippela02f0572005-11-08 21:34:53 -0800372 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373};
374
375menu_end: end
376{
377 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
378 menu_end_menu();
379 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
380 }
381};
382
Roman Zippela02f0572005-11-08 21:34:53 -0800383menu_stmt: menu_entry menu_block menu_end
384;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386menu_block:
387 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800388 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 | menu_block menu_stmt
390 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391;
392
Roman Zippela02f0572005-11-08 21:34:53 -0800393source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800396 zconf_nextfile($2);
Ulf Magnusson24161a62017-10-08 19:11:19 +0200397 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398};
399
400/* comment entry */
401
402comment: T_COMMENT prompt T_EOL
403{
404 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200405 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
407};
408
409comment_stmt: comment depends_list
Ulf Magnussondf60f4b2017-10-09 00:14:48 +0200410;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412/* help option */
413
414help_start: T_HELP T_EOL
415{
416 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
417 zconf_starthelp();
418};
419
420help: help_start T_HELPTEXT
421{
Ulf Magnusson6479f322018-01-12 07:47:47 +0100422 if (current_entry->help) {
423 free(current_entry->help);
424 zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
425 current_entry->sym->name ?: "<choice>");
426 }
Ulf Magnusson1b9eda22018-01-31 10:34:30 +0100427
428 /* Is the help text empty or all whitespace? */
429 if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
430 zconfprint("warning: '%s' defined with blank help text",
431 current_entry->sym->name ?: "<choice>");
432
Sam Ravnborg03d29122007-07-21 00:00:36 +0200433 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434};
435
436/* depends option */
437
Roman Zippela02f0572005-11-08 21:34:53 -0800438depends_list:
439 /* empty */
440 | depends_list depends
441 | depends_list T_EOL
442 | depends_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443;
444
445depends: T_DEPENDS T_ON expr T_EOL
446{
447 menu_add_dep($3);
448 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449};
450
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300451/* visibility option */
452
453visibility_list:
454 /* empty */
455 | visibility_list visible
456 | visibility_list T_EOL
457;
458
459visible: T_VISIBLE if_expr
460{
461 menu_add_visibility($2);
462};
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/* prompt statement */
465
466prompt_stmt_opt:
467 /* empty */
468 | prompt if_expr
469{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200470 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471};
472
473prompt: T_WORD
474 | T_WORD_QUOTE
475;
476
Roman Zippela02f0572005-11-08 21:34:53 -0800477end: T_ENDMENU T_EOL { $$ = $1; }
478 | T_ENDCHOICE T_EOL { $$ = $1; }
479 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480;
481
Roman Zippela02f0572005-11-08 21:34:53 -0800482nl:
483 T_EOL
484 | nl T_EOL
485;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487if_expr: /* empty */ { $$ = NULL; }
488 | T_IF expr { $$ = $2; }
489;
490
491expr: symbol { $$ = expr_alloc_symbol($1); }
Jan Beulich31847b62015-06-15 13:00:21 +0100492 | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
493 | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
494 | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
495 | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
497 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
498 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
499 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
500 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
501 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
502;
503
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200504/* For symbol definitions, selects, etc., where quotes are not accepted */
505nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
506
507symbol: nonconst_symbol
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100508 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509;
510
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100511word_opt: /* empty */ { $$ = NULL; }
512 | T_WORD
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514%%
515
516void conf_parse(const char *name)
517{
518 struct symbol *sym;
519 int i;
520
521 zconf_initscan(name);
522
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200523 _menu_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Roman Zippela02f0572005-11-08 21:34:53 -0800525 if (getenv("ZCONF_DEBUG"))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900526 yydebug = 1;
527 yyparse();
528 if (yynerrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 exit(1);
Yann E. MORIN6902dcc2013-09-03 17:07:18 +0200530 if (!modules_sym)
531 modules_sym = sym_find( "n" );
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400532
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900533 if (!menu_has_prompt(&rootmenu)) {
534 current_entry = &rootmenu;
535 menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
536 }
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 menu_finalize(&rootmenu);
539 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200540 if (sym_check_deps(sym))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900541 yynerrs++;
Masahiro Yamadabb66fc62014-06-10 19:08:13 +0900542 }
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900543 if (yynerrs)
Sam Ravnborg5447d342007-05-06 09:20:10 +0200544 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800545 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
Josh Triplett65166572009-10-15 12:13:36 -0700548static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
550 switch (token) {
551 case T_MENU: return "menu";
552 case T_ENDMENU: return "endmenu";
553 case T_CHOICE: return "choice";
554 case T_ENDCHOICE: return "endchoice";
555 case T_IF: return "if";
556 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800557 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300558 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560 return "<token>";
561}
562
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400563static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Roman Zippela02f0572005-11-08 21:34:53 -0800565 if (id->token != endtoken) {
566 zconf_error("unexpected '%s' within %s block",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700567 id->name, zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900568 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 return false;
570 }
571 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800572 zconf_error("'%s' in different file than '%s'",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700573 id->name, zconf_tokenname(starttoken));
Roman Zippela02f0572005-11-08 21:34:53 -0800574 fprintf(stderr, "%s:%d: location of the '%s'\n",
575 current_menu->file->name, current_menu->lineno,
576 zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900577 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 return false;
579 }
580 return true;
581}
582
583static void zconfprint(const char *err, ...)
584{
585 va_list ap;
586
Roman Zippela02f0572005-11-08 21:34:53 -0800587 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
588 va_start(ap, err);
589 vfprintf(stderr, err, ap);
590 va_end(ap);
591 fprintf(stderr, "\n");
592}
593
594static void zconf_error(const char *err, ...)
595{
596 va_list ap;
597
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900598 yynerrs++;
Roman Zippela02f0572005-11-08 21:34:53 -0800599 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 va_start(ap, err);
601 vfprintf(stderr, err, ap);
602 va_end(ap);
603 fprintf(stderr, "\n");
604}
605
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900606static void yyerror(const char *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
608 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609}
610
Josh Triplett65166572009-10-15 12:13:36 -0700611static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
613 const char *p;
614 int len;
615
616 putc('"', out);
617 while ((p = strchr(str, '"'))) {
618 len = p - str;
619 if (len)
620 fprintf(out, "%.*s", len, str);
621 fputs("\\\"", out);
622 str = p + 1;
623 }
624 fputs(str, out);
625 putc('"', out);
626}
627
Josh Triplett65166572009-10-15 12:13:36 -0700628static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
630 struct symbol *sym = menu->sym;
631 struct property *prop;
632
633 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800634 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800636 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 switch (sym->type) {
638 case S_BOOLEAN:
Masahiro Yamadab92d8042017-12-16 00:38:02 +0900639 fputs(" bool\n", out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 break;
641 case S_TRISTATE:
642 fputs(" tristate\n", out);
643 break;
644 case S_STRING:
645 fputs(" string\n", out);
646 break;
647 case S_INT:
648 fputs(" integer\n", out);
649 break;
650 case S_HEX:
651 fputs(" hex\n", out);
652 break;
653 default:
654 fputs(" ???\n", out);
655 break;
656 }
657 for (prop = sym->prop; prop; prop = prop->next) {
658 if (prop->menu != menu)
659 continue;
660 switch (prop->type) {
661 case P_PROMPT:
662 fputs(" prompt ", out);
663 print_quoted_string(out, prop->text);
664 if (!expr_is_yes(prop->visible.expr)) {
665 fputs(" if ", out);
666 expr_fprint(prop->visible.expr, out);
667 }
668 fputc('\n', out);
669 break;
670 case P_DEFAULT:
671 fputs( " default ", out);
672 expr_fprint(prop->expr, out);
673 if (!expr_is_yes(prop->visible.expr)) {
674 fputs(" if ", out);
675 expr_fprint(prop->visible.expr, out);
676 }
677 fputc('\n', out);
678 break;
679 case P_CHOICE:
680 fputs(" #choice value\n", out);
681 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800682 case P_SELECT:
683 fputs( " select ", out);
684 expr_fprint(prop->expr, out);
685 fputc('\n', out);
686 break;
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500687 case P_IMPLY:
688 fputs( " imply ", out);
689 expr_fprint(prop->expr, out);
690 fputc('\n', out);
691 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800692 case P_RANGE:
693 fputs( " range ", out);
694 expr_fprint(prop->expr, out);
695 fputc('\n', out);
696 break;
697 case P_MENU:
698 fputs( " menu ", out);
699 print_quoted_string(out, prop->text);
700 fputc('\n', out);
701 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 default:
703 fprintf(out, " unknown prop %d!\n", prop->type);
704 break;
705 }
706 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200707 if (menu->help) {
708 int len = strlen(menu->help);
709 while (menu->help[--len] == '\n')
710 menu->help[len] = 0;
711 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715void zconfdump(FILE *out)
716{
717 struct property *prop;
718 struct symbol *sym;
719 struct menu *menu;
720
721 menu = rootmenu.list;
722 while (menu) {
723 if ((sym = menu->sym))
724 print_symbol(out, menu);
725 else if ((prop = menu->prompt)) {
726 switch (prop->type) {
727 case P_COMMENT:
728 fputs("\ncomment ", out);
729 print_quoted_string(out, prop->text);
730 fputs("\n", out);
731 break;
732 case P_MENU:
733 fputs("\nmenu ", out);
734 print_quoted_string(out, prop->text);
735 fputs("\n", out);
736 break;
737 default:
738 ;
739 }
740 if (!expr_is_yes(prop->visible.expr)) {
741 fputs(" depends ", out);
742 expr_fprint(prop->visible.expr, out);
743 fputc('\n', out);
744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
746
747 if (menu->list)
748 menu = menu->list;
749 else if (menu->next)
750 menu = menu->next;
751 else while ((menu = menu->parent)) {
752 if (menu->prompt && menu->prompt->type == P_MENU)
753 fputs("\nendmenu\n", out);
754 if (menu->next) {
755 menu = menu->next;
756 break;
757 }
758 }
759 }
760}
761
Arnaud Lacombe378dbb22011-05-23 02:08:52 -0400762#include "zconf.lex.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763#include "util.c"
764#include "confdata.c"
765#include "expr.c"
766#include "symbol.c"
767#include "menu.c"
Masahiro Yamada104daea2018-05-28 18:21:40 +0900768#include "preprocess.c"