blob: e482000bb93e0c27fa462e8d06ac2bf04249dcc3 [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%}
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35%union
36{
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 char *string;
Roman Zippela02f0572005-11-08 21:34:53 -080038 struct file *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 struct symbol *symbol;
40 struct expr *expr;
41 struct menu *menu;
Arnaud Lacombe61f956f2011-05-04 21:14:44 -040042 const struct kconf_id *id;
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090043 enum symbol_type type;
Masahiro Yamada1175c022018-05-28 18:21:50 +090044 enum variable_flavor flavor;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
Roman Zippel3370f9f2005-11-08 21:34:52 -080047%token <id>T_MAINMENU
48%token <id>T_MENU
49%token <id>T_ENDMENU
50%token <id>T_SOURCE
51%token <id>T_CHOICE
52%token <id>T_ENDCHOICE
53%token <id>T_COMMENT
54%token <id>T_CONFIG
55%token <id>T_MENUCONFIG
56%token <id>T_HELP
Linus Torvalds1da177e2005-04-16 15:20:36 -070057%token <string> T_HELPTEXT
Roman Zippel3370f9f2005-11-08 21:34:52 -080058%token <id>T_IF
59%token <id>T_ENDIF
60%token <id>T_DEPENDS
Roman Zippel3370f9f2005-11-08 21:34:52 -080061%token <id>T_OPTIONAL
62%token <id>T_PROMPT
Roman Zippel3370f9f2005-11-08 21:34:52 -080063%token <id>T_SELECT
Nicolas Pitre237e3ad2016-11-11 00:10:05 -050064%token <id>T_IMPLY
Roman Zippel3370f9f2005-11-08 21:34:52 -080065%token <id>T_RANGE
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030066%token <id>T_VISIBLE
Roman Zippel3370f9f2005-11-08 21:34:52 -080067%token <id>T_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -070068%token <string> T_WORD
69%token <string> T_WORD_QUOTE
Masahiro Yamadace2164a2018-12-11 20:01:00 +090070%token T_ALLNOCONFIG_Y
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090071%token T_BOOL
Linus Torvalds1da177e2005-04-16 15:20:36 -070072%token T_CLOSE_PAREN
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090073%token T_DEFAULT
Masahiro Yamadace2164a2018-12-11 20:01:00 +090074%token T_DEFCONFIG_LIST
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090075%token T_DEF_BOOL
76%token T_DEF_TRISTATE
77%token T_HEX
78%token T_INT
Masahiro Yamadace2164a2018-12-11 20:01:00 +090079%token T_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -070080%token T_OPEN_PAREN
Masahiro Yamadace2164a2018-12-11 20:01:00 +090081%token T_OPTION
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090082%token T_STRING
83%token T_TRISTATE
Roman Zippel3370f9f2005-11-08 21:34:52 -080084%token T_EOL
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +090085%token <string> T_VARIABLE
Masahiro Yamada1175c022018-05-28 18:21:50 +090086%token <flavor> T_ASSIGN
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +090087%token <string> T_ASSIGN_VAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89%left T_OR
90%left T_AND
91%left T_EQUAL T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010092%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070093%nonassoc T_NOT
94
95%type <string> prompt
Ulf Magnusson26e47a32017-10-08 19:11:18 +020096%type <symbol> nonconst_symbol
Linus Torvalds1da177e2005-04-16 15:20:36 -070097%type <symbol> symbol
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090098%type <type> type logic_type default
Linus Torvalds1da177e2005-04-16 15:20:36 -070099%type <expr> expr
100%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -0800101%type <id> end
Roman Zippela02f0572005-11-08 21:34:53 -0800102%type <menu> if_entry menu_entry choice_entry
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900103%type <string> word_opt assign_val
Roman Zippela02f0572005-11-08 21:34:53 -0800104
105%destructor {
106 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
107 $$->file->name, $$->lineno);
108 if (current_menu == $$)
109 menu_end_menu();
110} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Josh Triplett1456edb2009-10-15 11:03:20 -0700112%{
Ulf Magnussonc8734432017-10-05 05:06:48 +0200113/* Include kconf_id.c here so it can see the token constants. */
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700114#include "kconf_id.c"
Josh Triplett1456edb2009-10-15 11:03:20 -0700115%}
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117%%
Masahiro Yamadacc66bca2018-12-11 20:00:49 +0900118input: mainmenu_stmt stmt_list | stmt_list;
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200119
120/* mainmenu entry */
121
Masahiro Yamada56869d42018-08-09 15:47:06 +0900122mainmenu_stmt: T_MAINMENU prompt T_EOL
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200123{
124 menu_add_prompt(P_MENU, $2, NULL);
125};
126
Roman Zippela02f0572005-11-08 21:34:53 -0800127stmt_list:
128 /* empty */
129 | stmt_list common_stmt
130 | stmt_list choice_stmt
131 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800132 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
Roman Zippela02f0572005-11-08 21:34:53 -0800133 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134;
135
Roman Zippela02f0572005-11-08 21:34:53 -0800136common_stmt:
Masahiro Yamadacc66bca2018-12-11 20:00:49 +0900137 if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 | comment_stmt
139 | config_stmt
140 | menuconfig_stmt
141 | source_stmt
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900142 | assignment_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800143;
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* config/menuconfig entry */
146
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200147config_entry_start: T_CONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200149 $2->flags |= SYMBOL_OPTIONAL;
150 menu_add_entry($2);
151 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
154config_stmt: config_entry_start config_option_list
155{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
157};
158
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200159menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200161 $2->flags |= SYMBOL_OPTIONAL;
162 menu_add_entry($2);
163 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164};
165
166menuconfig_stmt: menuconfig_entry_start config_option_list
167{
168 if (current_entry->prompt)
169 current_entry->prompt->type = P_MENU;
170 else
171 zconfprint("warning: menuconfig statement without prompt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
173};
174
175config_option_list:
176 /* empty */
177 | config_option_list config_option
178 | config_option_list depends
179 | config_option_list help
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180;
181
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900182config_option: type prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183{
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900184 menu_set_type($1);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800185 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
186 zconf_curname(), zconf_lineno(),
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900187 $1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
190config_option: T_PROMPT prompt if_expr T_EOL
191{
192 menu_add_prompt(P_PROMPT, $2, $3);
193 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
194};
195
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900196config_option: default expr if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 menu_add_expr(P_DEFAULT, $2, $3);
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900199 if ($1 != S_UNKNOWN)
200 menu_set_type($1);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800201 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
202 zconf_curname(), zconf_lineno(),
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900203 $1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204};
205
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200206config_option: T_SELECT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200208 menu_add_symbol(P_SELECT, $2, $3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
210};
211
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200212config_option: T_IMPLY nonconst_symbol if_expr T_EOL
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500213{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200214 menu_add_symbol(P_IMPLY, $2, $3);
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500215 printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
216};
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218config_option: T_RANGE symbol symbol if_expr T_EOL
219{
220 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
221 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
222};
223
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900224config_option: T_OPTION T_MODULES T_EOL
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700225{
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900226 menu_add_option_modules();
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700227};
228
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900229config_option: T_OPTION T_DEFCONFIG_LIST T_EOL
230{
231 menu_add_option_defconfig_list();
232};
233
234config_option: T_OPTION T_ALLNOCONFIG_Y T_EOL
235{
236 menu_add_option_allnoconfig_y();
237};
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/* choice entry */
240
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100241choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100243 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
Dirk Gouders693359f2018-07-03 14:43:31 +0200244 sym->flags |= SYMBOL_NO_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 menu_add_entry(sym);
246 menu_add_expr(P_CHOICE, NULL, NULL);
Masahiro Yamadabf0bbdc2018-02-20 20:40:29 +0900247 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
249};
250
251choice_entry: choice choice_option_list
252{
Roman Zippela02f0572005-11-08 21:34:53 -0800253 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254};
255
256choice_end: end
257{
258 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
259 menu_end_menu();
260 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
261 }
262};
263
Roman Zippela02f0572005-11-08 21:34:53 -0800264choice_stmt: choice_entry choice_block choice_end
265;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267choice_option_list:
268 /* empty */
269 | choice_option_list choice_option
270 | choice_option_list depends
271 | choice_option_list help
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272;
273
274choice_option: T_PROMPT prompt if_expr T_EOL
275{
276 menu_add_prompt(P_PROMPT, $2, $3);
277 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
278};
279
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900280choice_option: logic_type prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900282 menu_set_type($1);
283 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
284 zconf_curname(), zconf_lineno(), $1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285};
286
287choice_option: T_OPTIONAL T_EOL
288{
289 current_entry->sym->flags |= SYMBOL_OPTIONAL;
290 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
291};
292
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200293choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900295 menu_add_symbol(P_DEFAULT, $2, $3);
296 printd(DEBUG_PARSE, "%s:%d:default\n",
297 zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298};
299
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900300type:
301 logic_type
302 | T_INT { $$ = S_INT; }
303 | T_HEX { $$ = S_HEX; }
304 | T_STRING { $$ = S_STRING; }
305
306logic_type:
307 T_BOOL { $$ = S_BOOLEAN; }
308 | T_TRISTATE { $$ = S_TRISTATE; }
309
310default:
311 T_DEFAULT { $$ = S_UNKNOWN; }
312 | T_DEF_BOOL { $$ = S_BOOLEAN; }
313 | T_DEF_TRISTATE { $$ = S_TRISTATE; }
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315choice_block:
316 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800317 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318;
319
320/* if entry */
321
Dirk Goudersb2d00d72018-06-21 15:30:54 +0200322if_entry: T_IF expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
324 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
325 menu_add_entry(NULL);
326 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800327 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328};
329
330if_end: end
331{
332 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
333 menu_end_menu();
334 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
335 }
336};
337
Masahiro Yamada48917962018-12-11 20:00:54 +0900338if_stmt: if_entry stmt_list if_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339;
340
341/* menu entry */
342
343menu: T_MENU prompt T_EOL
344{
345 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200346 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
348};
349
Masahiro Yamada1f31be92018-12-11 20:00:56 +0900350menu_entry: menu menu_option_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Roman Zippela02f0572005-11-08 21:34:53 -0800352 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353};
354
355menu_end: end
356{
357 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
358 menu_end_menu();
359 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
360 }
361};
362
Masahiro Yamada94d4e1b2018-12-11 20:00:55 +0900363menu_stmt: menu_entry stmt_list menu_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364;
365
Masahiro Yamada1f31be92018-12-11 20:00:56 +0900366menu_option_list:
367 /* empty */
368 | menu_option_list visible
369 | menu_option_list depends
370;
371
Roman Zippela02f0572005-11-08 21:34:53 -0800372source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800375 zconf_nextfile($2);
Ulf Magnusson24161a62017-10-08 19:11:19 +0200376 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377};
378
379/* comment entry */
380
381comment: T_COMMENT prompt T_EOL
382{
383 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200384 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
386};
387
Masahiro Yamada4b5ec812018-12-11 20:00:57 +0900388comment_stmt: comment comment_option_list
389;
390
391comment_option_list:
392 /* empty */
393 | comment_option_list depends
Ulf Magnussondf60f4b2017-10-09 00:14:48 +0200394;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396/* help option */
397
398help_start: T_HELP T_EOL
399{
400 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
401 zconf_starthelp();
402};
403
404help: help_start T_HELPTEXT
405{
Ulf Magnusson6479f322018-01-12 07:47:47 +0100406 if (current_entry->help) {
407 free(current_entry->help);
408 zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
409 current_entry->sym->name ?: "<choice>");
410 }
Ulf Magnusson1b9eda22018-01-31 10:34:30 +0100411
412 /* Is the help text empty or all whitespace? */
413 if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
414 zconfprint("warning: '%s' defined with blank help text",
415 current_entry->sym->name ?: "<choice>");
416
Sam Ravnborg03d29122007-07-21 00:00:36 +0200417 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418};
419
420/* depends option */
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422depends: T_DEPENDS T_ON expr T_EOL
423{
424 menu_add_dep($3);
425 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426};
427
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300428/* visibility option */
Masahiro Yamada413cd192018-12-11 20:00:46 +0900429visible: T_VISIBLE if_expr T_EOL
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300430{
431 menu_add_visibility($2);
432};
433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434/* prompt statement */
435
436prompt_stmt_opt:
437 /* empty */
438 | prompt if_expr
439{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200440 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441};
442
443prompt: T_WORD
444 | T_WORD_QUOTE
445;
446
Roman Zippela02f0572005-11-08 21:34:53 -0800447end: T_ENDMENU T_EOL { $$ = $1; }
448 | T_ENDCHOICE T_EOL { $$ = $1; }
449 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450;
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452if_expr: /* empty */ { $$ = NULL; }
453 | T_IF expr { $$ = $2; }
454;
455
456expr: symbol { $$ = expr_alloc_symbol($1); }
Jan Beulich31847b62015-06-15 13:00:21 +0100457 | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
458 | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
459 | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
460 | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
462 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
463 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
464 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
465 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
466 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
467;
468
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200469/* For symbol definitions, selects, etc., where quotes are not accepted */
470nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
471
472symbol: nonconst_symbol
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100473 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474;
475
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100476word_opt: /* empty */ { $$ = NULL; }
477 | T_WORD
478
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900479/* assignment statement */
480
Masahiro Yamada1175c022018-05-28 18:21:50 +0900481assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900482
483assign_val:
484 /* empty */ { $$ = xstrdup(""); };
485 | T_ASSIGN_VAL
486;
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488%%
489
490void conf_parse(const char *name)
491{
492 struct symbol *sym;
493 int i;
494
495 zconf_initscan(name);
496
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200497 _menu_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Roman Zippela02f0572005-11-08 21:34:53 -0800499 if (getenv("ZCONF_DEBUG"))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900500 yydebug = 1;
501 yyparse();
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900502
503 /* Variables are expanded in the parse phase. We can free them here. */
504 variable_all_del();
505
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900506 if (yynerrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 exit(1);
Yann E. MORIN6902dcc2013-09-03 17:07:18 +0200508 if (!modules_sym)
509 modules_sym = sym_find( "n" );
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400510
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900511 if (!menu_has_prompt(&rootmenu)) {
512 current_entry = &rootmenu;
Masahiro Yamada137c0112018-05-28 18:21:44 +0900513 menu_add_prompt(P_MENU, "Main menu", NULL);
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900514 }
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 menu_finalize(&rootmenu);
517 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200518 if (sym_check_deps(sym))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900519 yynerrs++;
Masahiro Yamadabb66fc62014-06-10 19:08:13 +0900520 }
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900521 if (yynerrs)
Sam Ravnborg5447d342007-05-06 09:20:10 +0200522 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800523 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524}
525
Josh Triplett65166572009-10-15 12:13:36 -0700526static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
528 switch (token) {
529 case T_MENU: return "menu";
530 case T_ENDMENU: return "endmenu";
531 case T_CHOICE: return "choice";
532 case T_ENDCHOICE: return "endchoice";
533 case T_IF: return "if";
534 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800535 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300536 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
538 return "<token>";
539}
540
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400541static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Roman Zippela02f0572005-11-08 21:34:53 -0800543 if (id->token != endtoken) {
544 zconf_error("unexpected '%s' within %s block",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700545 id->name, zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900546 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return false;
548 }
549 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800550 zconf_error("'%s' in different file than '%s'",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700551 id->name, zconf_tokenname(starttoken));
Roman Zippela02f0572005-11-08 21:34:53 -0800552 fprintf(stderr, "%s:%d: location of the '%s'\n",
553 current_menu->file->name, current_menu->lineno,
554 zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900555 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 return false;
557 }
558 return true;
559}
560
561static void zconfprint(const char *err, ...)
562{
563 va_list ap;
564
Roman Zippela02f0572005-11-08 21:34:53 -0800565 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
566 va_start(ap, err);
567 vfprintf(stderr, err, ap);
568 va_end(ap);
569 fprintf(stderr, "\n");
570}
571
572static void zconf_error(const char *err, ...)
573{
574 va_list ap;
575
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900576 yynerrs++;
Roman Zippela02f0572005-11-08 21:34:53 -0800577 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 va_start(ap, err);
579 vfprintf(stderr, err, ap);
580 va_end(ap);
581 fprintf(stderr, "\n");
582}
583
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900584static void yyerror(const char *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585{
586 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
Josh Triplett65166572009-10-15 12:13:36 -0700589static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
591 const char *p;
592 int len;
593
594 putc('"', out);
595 while ((p = strchr(str, '"'))) {
596 len = p - str;
597 if (len)
598 fprintf(out, "%.*s", len, str);
599 fputs("\\\"", out);
600 str = p + 1;
601 }
602 fputs(str, out);
603 putc('"', out);
604}
605
Josh Triplett65166572009-10-15 12:13:36 -0700606static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
608 struct symbol *sym = menu->sym;
609 struct property *prop;
610
611 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800612 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800614 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 switch (sym->type) {
616 case S_BOOLEAN:
Masahiro Yamadab92d8042017-12-16 00:38:02 +0900617 fputs(" bool\n", out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 break;
619 case S_TRISTATE:
620 fputs(" tristate\n", out);
621 break;
622 case S_STRING:
623 fputs(" string\n", out);
624 break;
625 case S_INT:
626 fputs(" integer\n", out);
627 break;
628 case S_HEX:
629 fputs(" hex\n", out);
630 break;
631 default:
632 fputs(" ???\n", out);
633 break;
634 }
635 for (prop = sym->prop; prop; prop = prop->next) {
636 if (prop->menu != menu)
637 continue;
638 switch (prop->type) {
639 case P_PROMPT:
640 fputs(" prompt ", out);
641 print_quoted_string(out, prop->text);
642 if (!expr_is_yes(prop->visible.expr)) {
643 fputs(" if ", out);
644 expr_fprint(prop->visible.expr, out);
645 }
646 fputc('\n', out);
647 break;
648 case P_DEFAULT:
649 fputs( " default ", out);
650 expr_fprint(prop->expr, out);
651 if (!expr_is_yes(prop->visible.expr)) {
652 fputs(" if ", out);
653 expr_fprint(prop->visible.expr, out);
654 }
655 fputc('\n', out);
656 break;
657 case P_CHOICE:
658 fputs(" #choice value\n", out);
659 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800660 case P_SELECT:
661 fputs( " select ", out);
662 expr_fprint(prop->expr, out);
663 fputc('\n', out);
664 break;
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500665 case P_IMPLY:
666 fputs( " imply ", out);
667 expr_fprint(prop->expr, out);
668 fputc('\n', out);
669 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800670 case P_RANGE:
671 fputs( " range ", out);
672 expr_fprint(prop->expr, out);
673 fputc('\n', out);
674 break;
675 case P_MENU:
676 fputs( " menu ", out);
677 print_quoted_string(out, prop->text);
678 fputc('\n', out);
679 break;
Dirk Goudersecd53ac2018-06-22 21:27:38 +0200680 case P_SYMBOL:
681 fputs( " symbol ", out);
682 fprintf(out, "%s\n", prop->sym->name);
683 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 default:
685 fprintf(out, " unknown prop %d!\n", prop->type);
686 break;
687 }
688 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200689 if (menu->help) {
690 int len = strlen(menu->help);
691 while (menu->help[--len] == '\n')
692 menu->help[len] = 0;
693 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
696
697void zconfdump(FILE *out)
698{
699 struct property *prop;
700 struct symbol *sym;
701 struct menu *menu;
702
703 menu = rootmenu.list;
704 while (menu) {
705 if ((sym = menu->sym))
706 print_symbol(out, menu);
707 else if ((prop = menu->prompt)) {
708 switch (prop->type) {
709 case P_COMMENT:
710 fputs("\ncomment ", out);
711 print_quoted_string(out, prop->text);
712 fputs("\n", out);
713 break;
714 case P_MENU:
715 fputs("\nmenu ", out);
716 print_quoted_string(out, prop->text);
717 fputs("\n", out);
718 break;
719 default:
720 ;
721 }
722 if (!expr_is_yes(prop->visible.expr)) {
723 fputs(" depends ", out);
724 expr_fprint(prop->visible.expr, out);
725 fputc('\n', out);
726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728
729 if (menu->list)
730 menu = menu->list;
731 else if (menu->next)
732 menu = menu->next;
733 else while ((menu = menu->parent)) {
734 if (menu->prompt && menu->prompt->type == P_MENU)
735 fputs("\nendmenu\n", out);
736 if (menu->next) {
737 menu = menu->next;
738 break;
739 }
740 }
741 }
742}
743
Arnaud Lacombe378dbb22011-05-23 02:08:52 -0400744#include "zconf.lex.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#include "util.c"
746#include "confdata.c"
747#include "expr.c"
748#include "symbol.c"
749#include "menu.c"
Masahiro Yamada104daea2018-05-28 18:21:40 +0900750#include "preprocess.c"