blob: 3b7ebd363e7e8e5bad1d360f48c269b58f71d2e0 [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 Yamadac3d22872018-12-11 20:01:01 +090073%token T_COLON_EQUAL
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090074%token T_DEFAULT
Masahiro Yamadace2164a2018-12-11 20:01:00 +090075%token T_DEFCONFIG_LIST
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090076%token T_DEF_BOOL
77%token T_DEF_TRISTATE
78%token T_HEX
79%token T_INT
Masahiro Yamadace2164a2018-12-11 20:01:00 +090080%token T_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -070081%token T_OPEN_PAREN
Masahiro Yamadace2164a2018-12-11 20:01:00 +090082%token T_OPTION
Masahiro Yamadac3d22872018-12-11 20:01:01 +090083%token T_PLUS_EQUAL
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090084%token T_STRING
85%token T_TRISTATE
Roman Zippel3370f9f2005-11-08 21:34:52 -080086%token T_EOL
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +090087%token <string> T_VARIABLE
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +090088%token <string> T_ASSIGN_VAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90%left T_OR
91%left T_AND
92%left T_EQUAL T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010093%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070094%nonassoc T_NOT
95
96%type <string> prompt
Ulf Magnusson26e47a32017-10-08 19:11:18 +020097%type <symbol> nonconst_symbol
Linus Torvalds1da177e2005-04-16 15:20:36 -070098%type <symbol> symbol
Masahiro Yamada3c8f3172018-12-11 20:00:59 +090099%type <type> type logic_type default
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100%type <expr> expr
101%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -0800102%type <id> end
Roman Zippela02f0572005-11-08 21:34:53 -0800103%type <menu> if_entry menu_entry choice_entry
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900104%type <string> word_opt assign_val
Masahiro Yamadac3d22872018-12-11 20:01:01 +0900105%type <flavor> assign_op
Roman Zippela02f0572005-11-08 21:34:53 -0800106
107%destructor {
108 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
109 $$->file->name, $$->lineno);
110 if (current_menu == $$)
111 menu_end_menu();
112} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Josh Triplett1456edb2009-10-15 11:03:20 -0700114%{
Ulf Magnussonc8734432017-10-05 05:06:48 +0200115/* Include kconf_id.c here so it can see the token constants. */
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700116#include "kconf_id.c"
Josh Triplett1456edb2009-10-15 11:03:20 -0700117%}
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119%%
Masahiro Yamadacc66bca2018-12-11 20:00:49 +0900120input: mainmenu_stmt stmt_list | stmt_list;
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200121
122/* mainmenu entry */
123
Masahiro Yamada56869d42018-08-09 15:47:06 +0900124mainmenu_stmt: T_MAINMENU prompt T_EOL
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200125{
126 menu_add_prompt(P_MENU, $2, NULL);
127};
128
Roman Zippela02f0572005-11-08 21:34:53 -0800129stmt_list:
130 /* empty */
131 | stmt_list common_stmt
132 | stmt_list choice_stmt
133 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800134 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
Roman Zippela02f0572005-11-08 21:34:53 -0800135 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136;
137
Roman Zippela02f0572005-11-08 21:34:53 -0800138common_stmt:
Masahiro Yamadacc66bca2018-12-11 20:00:49 +0900139 if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 | comment_stmt
141 | config_stmt
142 | menuconfig_stmt
143 | source_stmt
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900144 | assignment_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800145;
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/* config/menuconfig entry */
148
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200149config_entry_start: T_CONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200151 $2->flags |= SYMBOL_OPTIONAL;
152 menu_add_entry($2);
153 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154};
155
156config_stmt: config_entry_start config_option_list
157{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
159};
160
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200161menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200163 $2->flags |= SYMBOL_OPTIONAL;
164 menu_add_entry($2);
165 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166};
167
168menuconfig_stmt: menuconfig_entry_start config_option_list
169{
170 if (current_entry->prompt)
171 current_entry->prompt->type = P_MENU;
172 else
173 zconfprint("warning: menuconfig statement without prompt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
175};
176
177config_option_list:
178 /* empty */
179 | config_option_list config_option
180 | config_option_list depends
181 | config_option_list help
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182;
183
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900184config_option: type prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900186 menu_set_type($1);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800187 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
188 zconf_curname(), zconf_lineno(),
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900189 $1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190};
191
192config_option: T_PROMPT prompt if_expr T_EOL
193{
194 menu_add_prompt(P_PROMPT, $2, $3);
195 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
196};
197
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900198config_option: default expr if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
200 menu_add_expr(P_DEFAULT, $2, $3);
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900201 if ($1 != S_UNKNOWN)
202 menu_set_type($1);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800203 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
204 zconf_curname(), zconf_lineno(),
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900205 $1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206};
207
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200208config_option: T_SELECT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200210 menu_add_symbol(P_SELECT, $2, $3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
212};
213
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200214config_option: T_IMPLY nonconst_symbol if_expr T_EOL
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500215{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200216 menu_add_symbol(P_IMPLY, $2, $3);
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500217 printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
218};
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220config_option: T_RANGE symbol symbol if_expr T_EOL
221{
222 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
223 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
224};
225
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900226config_option: T_OPTION T_MODULES T_EOL
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700227{
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900228 menu_add_option_modules();
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700229};
230
Masahiro Yamadace2164a2018-12-11 20:01:00 +0900231config_option: T_OPTION T_DEFCONFIG_LIST T_EOL
232{
233 menu_add_option_defconfig_list();
234};
235
236config_option: T_OPTION T_ALLNOCONFIG_Y T_EOL
237{
238 menu_add_option_allnoconfig_y();
239};
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241/* choice entry */
242
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100243choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100245 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
Dirk Gouders693359f2018-07-03 14:43:31 +0200246 sym->flags |= SYMBOL_NO_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 menu_add_entry(sym);
248 menu_add_expr(P_CHOICE, NULL, NULL);
Masahiro Yamadabf0bbdc2018-02-20 20:40:29 +0900249 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
251};
252
253choice_entry: choice choice_option_list
254{
Roman Zippela02f0572005-11-08 21:34:53 -0800255 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
257
258choice_end: end
259{
260 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
261 menu_end_menu();
262 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
263 }
264};
265
Roman Zippela02f0572005-11-08 21:34:53 -0800266choice_stmt: choice_entry choice_block choice_end
267;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269choice_option_list:
270 /* empty */
271 | choice_option_list choice_option
272 | choice_option_list depends
273 | choice_option_list help
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274;
275
276choice_option: T_PROMPT prompt if_expr T_EOL
277{
278 menu_add_prompt(P_PROMPT, $2, $3);
279 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
280};
281
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900282choice_option: logic_type prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900284 menu_set_type($1);
285 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
286 zconf_curname(), zconf_lineno(), $1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287};
288
289choice_option: T_OPTIONAL T_EOL
290{
291 current_entry->sym->flags |= SYMBOL_OPTIONAL;
292 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
293};
294
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200295choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900297 menu_add_symbol(P_DEFAULT, $2, $3);
298 printd(DEBUG_PARSE, "%s:%d:default\n",
299 zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300};
301
Masahiro Yamada3c8f3172018-12-11 20:00:59 +0900302type:
303 logic_type
304 | T_INT { $$ = S_INT; }
305 | T_HEX { $$ = S_HEX; }
306 | T_STRING { $$ = S_STRING; }
307
308logic_type:
309 T_BOOL { $$ = S_BOOLEAN; }
310 | T_TRISTATE { $$ = S_TRISTATE; }
311
312default:
313 T_DEFAULT { $$ = S_UNKNOWN; }
314 | T_DEF_BOOL { $$ = S_BOOLEAN; }
315 | T_DEF_TRISTATE { $$ = S_TRISTATE; }
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317choice_block:
318 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800319 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320;
321
322/* if entry */
323
Dirk Goudersb2d00d72018-06-21 15:30:54 +0200324if_entry: T_IF expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
326 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
327 menu_add_entry(NULL);
328 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800329 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330};
331
332if_end: end
333{
334 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
335 menu_end_menu();
336 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
337 }
338};
339
Masahiro Yamada48917962018-12-11 20:00:54 +0900340if_stmt: if_entry stmt_list if_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341;
342
343/* menu entry */
344
345menu: T_MENU prompt T_EOL
346{
347 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200348 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
350};
351
Masahiro Yamada1f31be92018-12-11 20:00:56 +0900352menu_entry: menu menu_option_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Roman Zippela02f0572005-11-08 21:34:53 -0800354 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355};
356
357menu_end: end
358{
359 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
360 menu_end_menu();
361 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
362 }
363};
364
Masahiro Yamada94d4e1b2018-12-11 20:00:55 +0900365menu_stmt: menu_entry stmt_list menu_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366;
367
Masahiro Yamada1f31be92018-12-11 20:00:56 +0900368menu_option_list:
369 /* empty */
370 | menu_option_list visible
371 | menu_option_list depends
372;
373
Roman Zippela02f0572005-11-08 21:34:53 -0800374source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800377 zconf_nextfile($2);
Ulf Magnusson24161a62017-10-08 19:11:19 +0200378 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379};
380
381/* comment entry */
382
383comment: T_COMMENT prompt T_EOL
384{
385 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200386 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
388};
389
Masahiro Yamada4b5ec812018-12-11 20:00:57 +0900390comment_stmt: comment comment_option_list
391;
392
393comment_option_list:
394 /* empty */
395 | comment_option_list depends
Ulf Magnussondf60f4b2017-10-09 00:14:48 +0200396;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398/* help option */
399
400help_start: T_HELP T_EOL
401{
402 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
403 zconf_starthelp();
404};
405
406help: help_start T_HELPTEXT
407{
Ulf Magnusson6479f322018-01-12 07:47:47 +0100408 if (current_entry->help) {
409 free(current_entry->help);
410 zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
411 current_entry->sym->name ?: "<choice>");
412 }
Ulf Magnusson1b9eda22018-01-31 10:34:30 +0100413
414 /* Is the help text empty or all whitespace? */
415 if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
416 zconfprint("warning: '%s' defined with blank help text",
417 current_entry->sym->name ?: "<choice>");
418
Sam Ravnborg03d29122007-07-21 00:00:36 +0200419 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420};
421
422/* depends option */
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424depends: T_DEPENDS T_ON expr T_EOL
425{
426 menu_add_dep($3);
427 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428};
429
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300430/* visibility option */
Masahiro Yamada413cd192018-12-11 20:00:46 +0900431visible: T_VISIBLE if_expr T_EOL
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300432{
433 menu_add_visibility($2);
434};
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/* prompt statement */
437
438prompt_stmt_opt:
439 /* empty */
440 | prompt if_expr
441{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200442 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443};
444
445prompt: T_WORD
446 | T_WORD_QUOTE
447;
448
Roman Zippela02f0572005-11-08 21:34:53 -0800449end: T_ENDMENU T_EOL { $$ = $1; }
450 | T_ENDCHOICE T_EOL { $$ = $1; }
451 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452;
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454if_expr: /* empty */ { $$ = NULL; }
455 | T_IF expr { $$ = $2; }
456;
457
458expr: symbol { $$ = expr_alloc_symbol($1); }
Jan Beulich31847b62015-06-15 13:00:21 +0100459 | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
460 | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
461 | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
462 | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
464 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
465 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
466 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
467 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
468 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
469;
470
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200471/* For symbol definitions, selects, etc., where quotes are not accepted */
472nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
473
474symbol: nonconst_symbol
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100475 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476;
477
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100478word_opt: /* empty */ { $$ = NULL; }
479 | T_WORD
480
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900481/* assignment statement */
482
Masahiro Yamadac3d22872018-12-11 20:01:01 +0900483assignment_stmt: T_VARIABLE assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
484
485assign_op:
486 T_EQUAL { $$ = VAR_RECURSIVE; }
487 | T_COLON_EQUAL { $$ = VAR_SIMPLE; }
488 | T_PLUS_EQUAL { $$ = VAR_APPEND; }
489;
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900490
491assign_val:
492 /* empty */ { $$ = xstrdup(""); };
493 | T_ASSIGN_VAL
494;
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496%%
497
498void conf_parse(const char *name)
499{
500 struct symbol *sym;
501 int i;
502
503 zconf_initscan(name);
504
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200505 _menu_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Roman Zippela02f0572005-11-08 21:34:53 -0800507 if (getenv("ZCONF_DEBUG"))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900508 yydebug = 1;
509 yyparse();
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900510
511 /* Variables are expanded in the parse phase. We can free them here. */
512 variable_all_del();
513
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900514 if (yynerrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 exit(1);
Yann E. MORIN6902dcc2013-09-03 17:07:18 +0200516 if (!modules_sym)
517 modules_sym = sym_find( "n" );
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400518
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900519 if (!menu_has_prompt(&rootmenu)) {
520 current_entry = &rootmenu;
Masahiro Yamada137c0112018-05-28 18:21:44 +0900521 menu_add_prompt(P_MENU, "Main menu", NULL);
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900522 }
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 menu_finalize(&rootmenu);
525 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200526 if (sym_check_deps(sym))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900527 yynerrs++;
Masahiro Yamadabb66fc62014-06-10 19:08:13 +0900528 }
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900529 if (yynerrs)
Sam Ravnborg5447d342007-05-06 09:20:10 +0200530 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800531 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Josh Triplett65166572009-10-15 12:13:36 -0700534static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
536 switch (token) {
537 case T_MENU: return "menu";
538 case T_ENDMENU: return "endmenu";
539 case T_CHOICE: return "choice";
540 case T_ENDCHOICE: return "endchoice";
541 case T_IF: return "if";
542 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800543 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300544 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 }
546 return "<token>";
547}
548
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400549static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550{
Roman Zippela02f0572005-11-08 21:34:53 -0800551 if (id->token != endtoken) {
552 zconf_error("unexpected '%s' within %s block",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700553 id->name, zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900554 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return false;
556 }
557 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800558 zconf_error("'%s' in different file than '%s'",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700559 id->name, zconf_tokenname(starttoken));
Roman Zippela02f0572005-11-08 21:34:53 -0800560 fprintf(stderr, "%s:%d: location of the '%s'\n",
561 current_menu->file->name, current_menu->lineno,
562 zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900563 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 return false;
565 }
566 return true;
567}
568
569static void zconfprint(const char *err, ...)
570{
571 va_list ap;
572
Roman Zippela02f0572005-11-08 21:34:53 -0800573 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
574 va_start(ap, err);
575 vfprintf(stderr, err, ap);
576 va_end(ap);
577 fprintf(stderr, "\n");
578}
579
580static void zconf_error(const char *err, ...)
581{
582 va_list ap;
583
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900584 yynerrs++;
Roman Zippela02f0572005-11-08 21:34:53 -0800585 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 va_start(ap, err);
587 vfprintf(stderr, err, ap);
588 va_end(ap);
589 fprintf(stderr, "\n");
590}
591
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900592static void yyerror(const char *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
594 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
Josh Triplett65166572009-10-15 12:13:36 -0700597static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
599 const char *p;
600 int len;
601
602 putc('"', out);
603 while ((p = strchr(str, '"'))) {
604 len = p - str;
605 if (len)
606 fprintf(out, "%.*s", len, str);
607 fputs("\\\"", out);
608 str = p + 1;
609 }
610 fputs(str, out);
611 putc('"', out);
612}
613
Josh Triplett65166572009-10-15 12:13:36 -0700614static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
616 struct symbol *sym = menu->sym;
617 struct property *prop;
618
619 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800620 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800622 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 switch (sym->type) {
624 case S_BOOLEAN:
Masahiro Yamadab92d8042017-12-16 00:38:02 +0900625 fputs(" bool\n", out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 break;
627 case S_TRISTATE:
628 fputs(" tristate\n", out);
629 break;
630 case S_STRING:
631 fputs(" string\n", out);
632 break;
633 case S_INT:
634 fputs(" integer\n", out);
635 break;
636 case S_HEX:
637 fputs(" hex\n", out);
638 break;
639 default:
640 fputs(" ???\n", out);
641 break;
642 }
643 for (prop = sym->prop; prop; prop = prop->next) {
644 if (prop->menu != menu)
645 continue;
646 switch (prop->type) {
647 case P_PROMPT:
648 fputs(" prompt ", out);
649 print_quoted_string(out, prop->text);
650 if (!expr_is_yes(prop->visible.expr)) {
651 fputs(" if ", out);
652 expr_fprint(prop->visible.expr, out);
653 }
654 fputc('\n', out);
655 break;
656 case P_DEFAULT:
657 fputs( " default ", out);
658 expr_fprint(prop->expr, out);
659 if (!expr_is_yes(prop->visible.expr)) {
660 fputs(" if ", out);
661 expr_fprint(prop->visible.expr, out);
662 }
663 fputc('\n', out);
664 break;
665 case P_CHOICE:
666 fputs(" #choice value\n", out);
667 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800668 case P_SELECT:
669 fputs( " select ", out);
670 expr_fprint(prop->expr, out);
671 fputc('\n', out);
672 break;
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500673 case P_IMPLY:
674 fputs( " imply ", out);
675 expr_fprint(prop->expr, out);
676 fputc('\n', out);
677 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800678 case P_RANGE:
679 fputs( " range ", out);
680 expr_fprint(prop->expr, out);
681 fputc('\n', out);
682 break;
683 case P_MENU:
684 fputs( " menu ", out);
685 print_quoted_string(out, prop->text);
686 fputc('\n', out);
687 break;
Dirk Goudersecd53ac2018-06-22 21:27:38 +0200688 case P_SYMBOL:
689 fputs( " symbol ", out);
690 fprintf(out, "%s\n", prop->sym->name);
691 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 default:
693 fprintf(out, " unknown prop %d!\n", prop->type);
694 break;
695 }
696 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200697 if (menu->help) {
698 int len = strlen(menu->help);
699 while (menu->help[--len] == '\n')
700 menu->help[len] = 0;
701 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
705void zconfdump(FILE *out)
706{
707 struct property *prop;
708 struct symbol *sym;
709 struct menu *menu;
710
711 menu = rootmenu.list;
712 while (menu) {
713 if ((sym = menu->sym))
714 print_symbol(out, menu);
715 else if ((prop = menu->prompt)) {
716 switch (prop->type) {
717 case P_COMMENT:
718 fputs("\ncomment ", out);
719 print_quoted_string(out, prop->text);
720 fputs("\n", out);
721 break;
722 case P_MENU:
723 fputs("\nmenu ", out);
724 print_quoted_string(out, prop->text);
725 fputs("\n", out);
726 break;
727 default:
728 ;
729 }
730 if (!expr_is_yes(prop->visible.expr)) {
731 fputs(" depends ", out);
732 expr_fprint(prop->visible.expr, out);
733 fputc('\n', out);
734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
736
737 if (menu->list)
738 menu = menu->list;
739 else if (menu->next)
740 menu = menu->next;
741 else while ((menu = menu->parent)) {
742 if (menu->prompt && menu->prompt->type == P_MENU)
743 fputs("\nendmenu\n", out);
744 if (menu->next) {
745 menu = menu->next;
746 break;
747 }
748 }
749 }
750}
751
Arnaud Lacombe378dbb22011-05-23 02:08:52 -0400752#include "zconf.lex.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753#include "util.c"
754#include "confdata.c"
755#include "expr.c"
756#include "symbol.c"
757#include "menu.c"
Masahiro Yamada104daea2018-05-28 18:21:40 +0900758#include "preprocess.c"