blob: 7cc824454e5429ebd17bab6fb463a49b611b19e6 [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 Yamada1175c022018-05-28 18:21:50 +090043 enum variable_flavor flavor;
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
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +090080%token <string> T_VARIABLE
Masahiro Yamada1175c022018-05-28 18:21:50 +090081%token <flavor> T_ASSIGN
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +090082%token <string> T_ASSIGN_VAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84%left T_OR
85%left T_AND
86%left T_EQUAL T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010087%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070088%nonassoc T_NOT
89
90%type <string> prompt
Ulf Magnusson26e47a32017-10-08 19:11:18 +020091%type <symbol> nonconst_symbol
Linus Torvalds1da177e2005-04-16 15:20:36 -070092%type <symbol> symbol
93%type <expr> expr
94%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080095%type <id> end
Roman Zippela02f0572005-11-08 21:34:53 -080096%type <menu> if_entry menu_entry choice_entry
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +090097%type <string> symbol_option_arg word_opt assign_val
Roman Zippela02f0572005-11-08 21:34:53 -080098
99%destructor {
100 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
101 $$->file->name, $$->lineno);
102 if (current_menu == $$)
103 menu_end_menu();
104} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Josh Triplett1456edb2009-10-15 11:03:20 -0700106%{
Ulf Magnussonc8734432017-10-05 05:06:48 +0200107/* Include kconf_id.c here so it can see the token constants. */
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700108#include "kconf_id.c"
Josh Triplett1456edb2009-10-15 11:03:20 -0700109%}
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111%%
Masahiro Yamadacc66bca2018-12-11 20:00:49 +0900112input: mainmenu_stmt stmt_list | stmt_list;
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200113
114/* mainmenu entry */
115
Masahiro Yamada56869d42018-08-09 15:47:06 +0900116mainmenu_stmt: T_MAINMENU prompt T_EOL
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200117{
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 T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
Roman Zippela02f0572005-11-08 21:34:53 -0800127 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128;
129
Roman Zippela02f0572005-11-08 21:34:53 -0800130common_stmt:
Masahiro Yamadacc66bca2018-12-11 20:00:49 +0900131 if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 | comment_stmt
133 | config_stmt
134 | menuconfig_stmt
135 | source_stmt
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900136 | assignment_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800137;
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/* config/menuconfig entry */
140
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200141config_entry_start: T_CONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200143 $2->flags |= SYMBOL_OPTIONAL;
144 menu_add_entry($2);
145 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146};
147
148config_stmt: config_entry_start config_option_list
149{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
151};
152
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200153menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200155 $2->flags |= SYMBOL_OPTIONAL;
156 menu_add_entry($2);
157 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158};
159
160menuconfig_stmt: menuconfig_entry_start config_option_list
161{
162 if (current_entry->prompt)
163 current_entry->prompt->type = P_MENU;
164 else
165 zconfprint("warning: menuconfig statement without prompt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
167};
168
169config_option_list:
170 /* empty */
171 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700172 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 | config_option_list depends
174 | config_option_list help
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175;
176
Roman Zippel3370f9f2005-11-08 21:34:52 -0800177config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800179 menu_set_type($1->stype);
180 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
181 zconf_curname(), zconf_lineno(),
182 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183};
184
185config_option: T_PROMPT prompt if_expr T_EOL
186{
187 menu_add_prompt(P_PROMPT, $2, $3);
188 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
189};
190
191config_option: T_DEFAULT expr if_expr T_EOL
192{
193 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800194 if ($1->stype != S_UNKNOWN)
195 menu_set_type($1->stype);
196 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
197 zconf_curname(), zconf_lineno(),
198 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200201config_option: T_SELECT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200203 menu_add_symbol(P_SELECT, $2, $3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
205};
206
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200207config_option: T_IMPLY nonconst_symbol if_expr T_EOL
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500208{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200209 menu_add_symbol(P_IMPLY, $2, $3);
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500210 printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
211};
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213config_option: T_RANGE symbol symbol if_expr T_EOL
214{
215 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
216 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
217};
218
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700219symbol_option: T_OPTION symbol_option_list T_EOL
220;
221
222symbol_option_list:
223 /* empty */
224 | symbol_option_list T_WORD symbol_option_arg
225{
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400226 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
Ulf Magnussonbc28fe12017-10-08 19:11:20 +0200227 if (id && id->flags & TF_OPTION) {
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700228 menu_add_option(id->token, $3);
Ulf Magnussonbc28fe12017-10-08 19:11:20 +0200229 free($3);
230 }
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700231 else
232 zconfprint("warning: ignoring unknown option %s", $2);
233 free($2);
234};
235
236symbol_option_arg:
237 /* empty */ { $$ = NULL; }
238 | T_EQUAL prompt { $$ = $2; }
239;
240
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
Roman Zippel3370f9f2005-11-08 21:34:52 -0800282choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800284 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
285 menu_set_type($1->stype);
286 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
287 zconf_curname(), zconf_lineno(),
288 $1->stype);
289 } else
290 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291};
292
293choice_option: T_OPTIONAL T_EOL
294{
295 current_entry->sym->flags |= SYMBOL_OPTIONAL;
296 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
297};
298
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200299choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800301 if ($1->stype == S_UNKNOWN) {
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200302 menu_add_symbol(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800303 printd(DEBUG_PARSE, "%s:%d:default\n",
304 zconf_curname(), zconf_lineno());
305 } else
306 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307};
308
309choice_block:
310 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800311 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312;
313
314/* if entry */
315
Dirk Goudersb2d00d72018-06-21 15:30:54 +0200316if_entry: T_IF expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
319 menu_add_entry(NULL);
320 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800321 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322};
323
324if_end: end
325{
326 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
327 menu_end_menu();
328 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
329 }
330};
331
Masahiro Yamada48917962018-12-11 20:00:54 +0900332if_stmt: if_entry stmt_list if_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333;
334
335/* menu entry */
336
337menu: T_MENU prompt T_EOL
338{
339 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200340 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
342};
343
Masahiro Yamada1f31be92018-12-11 20:00:56 +0900344menu_entry: menu menu_option_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Roman Zippela02f0572005-11-08 21:34:53 -0800346 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347};
348
349menu_end: end
350{
351 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
352 menu_end_menu();
353 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
354 }
355};
356
Masahiro Yamada94d4e1b2018-12-11 20:00:55 +0900357menu_stmt: menu_entry stmt_list menu_end
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358;
359
Masahiro Yamada1f31be92018-12-11 20:00:56 +0900360menu_option_list:
361 /* empty */
362 | menu_option_list visible
363 | menu_option_list depends
364;
365
Roman Zippela02f0572005-11-08 21:34:53 -0800366source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800369 zconf_nextfile($2);
Ulf Magnusson24161a62017-10-08 19:11:19 +0200370 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371};
372
373/* comment entry */
374
375comment: T_COMMENT prompt T_EOL
376{
377 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200378 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
380};
381
382comment_stmt: comment depends_list
Ulf Magnussondf60f4b2017-10-09 00:14:48 +0200383;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385/* help option */
386
387help_start: T_HELP T_EOL
388{
389 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
390 zconf_starthelp();
391};
392
393help: help_start T_HELPTEXT
394{
Ulf Magnusson6479f322018-01-12 07:47:47 +0100395 if (current_entry->help) {
396 free(current_entry->help);
397 zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
398 current_entry->sym->name ?: "<choice>");
399 }
Ulf Magnusson1b9eda22018-01-31 10:34:30 +0100400
401 /* Is the help text empty or all whitespace? */
402 if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
403 zconfprint("warning: '%s' defined with blank help text",
404 current_entry->sym->name ?: "<choice>");
405
Sam Ravnborg03d29122007-07-21 00:00:36 +0200406 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407};
408
409/* depends option */
410
Roman Zippela02f0572005-11-08 21:34:53 -0800411depends_list:
412 /* empty */
413 | depends_list depends
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414;
415
416depends: T_DEPENDS T_ON expr T_EOL
417{
418 menu_add_dep($3);
419 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420};
421
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300422/* visibility option */
Masahiro Yamada413cd192018-12-11 20:00:46 +0900423visible: T_VISIBLE if_expr T_EOL
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300424{
425 menu_add_visibility($2);
426};
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/* prompt statement */
429
430prompt_stmt_opt:
431 /* empty */
432 | prompt if_expr
433{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200434 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435};
436
437prompt: T_WORD
438 | T_WORD_QUOTE
439;
440
Roman Zippela02f0572005-11-08 21:34:53 -0800441end: T_ENDMENU T_EOL { $$ = $1; }
442 | T_ENDCHOICE T_EOL { $$ = $1; }
443 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444;
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446if_expr: /* empty */ { $$ = NULL; }
447 | T_IF expr { $$ = $2; }
448;
449
450expr: symbol { $$ = expr_alloc_symbol($1); }
Jan Beulich31847b62015-06-15 13:00:21 +0100451 | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
452 | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
453 | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
454 | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
456 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
457 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
458 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
459 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
460 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
461;
462
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200463/* For symbol definitions, selects, etc., where quotes are not accepted */
464nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
465
466symbol: nonconst_symbol
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100467 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468;
469
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100470word_opt: /* empty */ { $$ = NULL; }
471 | T_WORD
472
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900473/* assignment statement */
474
Masahiro Yamada1175c022018-05-28 18:21:50 +0900475assignment_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 +0900476
477assign_val:
478 /* empty */ { $$ = xstrdup(""); };
479 | T_ASSIGN_VAL
480;
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482%%
483
484void conf_parse(const char *name)
485{
486 struct symbol *sym;
487 int i;
488
489 zconf_initscan(name);
490
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200491 _menu_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Roman Zippela02f0572005-11-08 21:34:53 -0800493 if (getenv("ZCONF_DEBUG"))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900494 yydebug = 1;
495 yyparse();
Masahiro Yamada9ced3bd2018-05-28 18:21:49 +0900496
497 /* Variables are expanded in the parse phase. We can free them here. */
498 variable_all_del();
499
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900500 if (yynerrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 exit(1);
Yann E. MORIN6902dcc2013-09-03 17:07:18 +0200502 if (!modules_sym)
503 modules_sym = sym_find( "n" );
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400504
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900505 if (!menu_has_prompt(&rootmenu)) {
506 current_entry = &rootmenu;
Masahiro Yamada137c0112018-05-28 18:21:44 +0900507 menu_add_prompt(P_MENU, "Main menu", NULL);
Masahiro Yamada96d8e482018-05-28 18:21:42 +0900508 }
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 menu_finalize(&rootmenu);
511 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200512 if (sym_check_deps(sym))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900513 yynerrs++;
Masahiro Yamadabb66fc62014-06-10 19:08:13 +0900514 }
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900515 if (yynerrs)
Sam Ravnborg5447d342007-05-06 09:20:10 +0200516 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800517 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518}
519
Josh Triplett65166572009-10-15 12:13:36 -0700520static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
522 switch (token) {
523 case T_MENU: return "menu";
524 case T_ENDMENU: return "endmenu";
525 case T_CHOICE: return "choice";
526 case T_ENDCHOICE: return "endchoice";
527 case T_IF: return "if";
528 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800529 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300530 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 }
532 return "<token>";
533}
534
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400535static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
Roman Zippela02f0572005-11-08 21:34:53 -0800537 if (id->token != endtoken) {
538 zconf_error("unexpected '%s' within %s block",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700539 id->name, zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900540 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 return false;
542 }
543 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800544 zconf_error("'%s' in different file than '%s'",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700545 id->name, zconf_tokenname(starttoken));
Roman Zippela02f0572005-11-08 21:34:53 -0800546 fprintf(stderr, "%s:%d: location of the '%s'\n",
547 current_menu->file->name, current_menu->lineno,
548 zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900549 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 return false;
551 }
552 return true;
553}
554
555static void zconfprint(const char *err, ...)
556{
557 va_list ap;
558
Roman Zippela02f0572005-11-08 21:34:53 -0800559 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
560 va_start(ap, err);
561 vfprintf(stderr, err, ap);
562 va_end(ap);
563 fprintf(stderr, "\n");
564}
565
566static void zconf_error(const char *err, ...)
567{
568 va_list ap;
569
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900570 yynerrs++;
Roman Zippela02f0572005-11-08 21:34:53 -0800571 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 va_start(ap, err);
573 vfprintf(stderr, err, ap);
574 va_end(ap);
575 fprintf(stderr, "\n");
576}
577
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900578static void yyerror(const char *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
580 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
Josh Triplett65166572009-10-15 12:13:36 -0700583static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
585 const char *p;
586 int len;
587
588 putc('"', out);
589 while ((p = strchr(str, '"'))) {
590 len = p - str;
591 if (len)
592 fprintf(out, "%.*s", len, str);
593 fputs("\\\"", out);
594 str = p + 1;
595 }
596 fputs(str, out);
597 putc('"', out);
598}
599
Josh Triplett65166572009-10-15 12:13:36 -0700600static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
602 struct symbol *sym = menu->sym;
603 struct property *prop;
604
605 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800606 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800608 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 switch (sym->type) {
610 case S_BOOLEAN:
Masahiro Yamadab92d8042017-12-16 00:38:02 +0900611 fputs(" bool\n", out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 break;
613 case S_TRISTATE:
614 fputs(" tristate\n", out);
615 break;
616 case S_STRING:
617 fputs(" string\n", out);
618 break;
619 case S_INT:
620 fputs(" integer\n", out);
621 break;
622 case S_HEX:
623 fputs(" hex\n", out);
624 break;
625 default:
626 fputs(" ???\n", out);
627 break;
628 }
629 for (prop = sym->prop; prop; prop = prop->next) {
630 if (prop->menu != menu)
631 continue;
632 switch (prop->type) {
633 case P_PROMPT:
634 fputs(" prompt ", out);
635 print_quoted_string(out, prop->text);
636 if (!expr_is_yes(prop->visible.expr)) {
637 fputs(" if ", out);
638 expr_fprint(prop->visible.expr, out);
639 }
640 fputc('\n', out);
641 break;
642 case P_DEFAULT:
643 fputs( " default ", out);
644 expr_fprint(prop->expr, out);
645 if (!expr_is_yes(prop->visible.expr)) {
646 fputs(" if ", out);
647 expr_fprint(prop->visible.expr, out);
648 }
649 fputc('\n', out);
650 break;
651 case P_CHOICE:
652 fputs(" #choice value\n", out);
653 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800654 case P_SELECT:
655 fputs( " select ", out);
656 expr_fprint(prop->expr, out);
657 fputc('\n', out);
658 break;
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500659 case P_IMPLY:
660 fputs( " imply ", out);
661 expr_fprint(prop->expr, out);
662 fputc('\n', out);
663 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800664 case P_RANGE:
665 fputs( " range ", out);
666 expr_fprint(prop->expr, out);
667 fputc('\n', out);
668 break;
669 case P_MENU:
670 fputs( " menu ", out);
671 print_quoted_string(out, prop->text);
672 fputc('\n', out);
673 break;
Dirk Goudersecd53ac2018-06-22 21:27:38 +0200674 case P_SYMBOL:
675 fputs( " symbol ", out);
676 fprintf(out, "%s\n", prop->sym->name);
677 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 default:
679 fprintf(out, " unknown prop %d!\n", prop->type);
680 break;
681 }
682 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200683 if (menu->help) {
684 int len = strlen(menu->help);
685 while (menu->help[--len] == '\n')
686 menu->help[len] = 0;
687 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691void zconfdump(FILE *out)
692{
693 struct property *prop;
694 struct symbol *sym;
695 struct menu *menu;
696
697 menu = rootmenu.list;
698 while (menu) {
699 if ((sym = menu->sym))
700 print_symbol(out, menu);
701 else if ((prop = menu->prompt)) {
702 switch (prop->type) {
703 case P_COMMENT:
704 fputs("\ncomment ", out);
705 print_quoted_string(out, prop->text);
706 fputs("\n", out);
707 break;
708 case P_MENU:
709 fputs("\nmenu ", out);
710 print_quoted_string(out, prop->text);
711 fputs("\n", out);
712 break;
713 default:
714 ;
715 }
716 if (!expr_is_yes(prop->visible.expr)) {
717 fputs(" depends ", out);
718 expr_fprint(prop->visible.expr, out);
719 fputc('\n', out);
720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722
723 if (menu->list)
724 menu = menu->list;
725 else if (menu->next)
726 menu = menu->next;
727 else while ((menu = menu->parent)) {
728 if (menu->prompt && menu->prompt->type == P_MENU)
729 fputs("\nendmenu\n", out);
730 if (menu->next) {
731 menu = menu->next;
732 break;
733 }
734 }
735 }
736}
737
Arnaud Lacombe378dbb22011-05-23 02:08:52 -0400738#include "zconf.lex.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#include "util.c"
740#include "confdata.c"
741#include "expr.c"
742#include "symbol.c"
743#include "menu.c"
Masahiro Yamada104daea2018-05-28 18:21:40 +0900744#include "preprocess.c"