blob: 21ce883e5d9ed73f5da535fcfc39dc6515916b6b [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
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200112start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list;
113
114/* mainmenu entry */
115
116mainmenu_stmt: T_MAINMENU prompt nl
117{
118 menu_add_prompt(P_MENU, $2, NULL);
119};
120
121/* Default main menu, if there's no mainmenu entry */
122
123no_mainmenu_stmt: /* empty */
124{
125 /*
126 * Hack: Keep the main menu title on the heap so we can safely free it
127 * later regardless of whether it comes from the 'prompt' in
128 * mainmenu_stmt or here
129 */
130 menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL);
131};
132
Roman Zippela02f0572005-11-08 21:34:53 -0800133
134stmt_list:
135 /* empty */
136 | stmt_list common_stmt
137 | stmt_list choice_stmt
138 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800139 | stmt_list end { zconf_error("unexpected end statement"); }
140 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
141 | stmt_list option_name error T_EOL
142{
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700143 zconf_error("unexpected option \"%s\"", $2->name);
Roman Zippela02f0572005-11-08 21:34:53 -0800144}
145 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146;
147
Roman Zippela02f0572005-11-08 21:34:53 -0800148option_name:
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500149 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 -0700150;
151
Roman Zippela02f0572005-11-08 21:34:53 -0800152common_stmt:
153 T_EOL
154 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 | comment_stmt
156 | config_stmt
157 | menuconfig_stmt
158 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800159;
160
161option_error:
162 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
163 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164;
165
166
167/* config/menuconfig entry */
168
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200169config_entry_start: T_CONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200171 $2->flags |= SYMBOL_OPTIONAL;
172 menu_add_entry($2);
173 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174};
175
176config_stmt: config_entry_start config_option_list
177{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
179};
180
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200181menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200183 $2->flags |= SYMBOL_OPTIONAL;
184 menu_add_entry($2);
185 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186};
187
188menuconfig_stmt: menuconfig_entry_start config_option_list
189{
190 if (current_entry->prompt)
191 current_entry->prompt->type = P_MENU;
192 else
193 zconfprint("warning: menuconfig statement without prompt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
195};
196
197config_option_list:
198 /* empty */
199 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700200 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 | config_option_list depends
202 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800203 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 | config_option_list T_EOL
205;
206
Roman Zippel3370f9f2005-11-08 21:34:52 -0800207config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800209 menu_set_type($1->stype);
210 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
211 zconf_curname(), zconf_lineno(),
212 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213};
214
215config_option: T_PROMPT prompt if_expr T_EOL
216{
217 menu_add_prompt(P_PROMPT, $2, $3);
218 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
219};
220
221config_option: T_DEFAULT expr if_expr T_EOL
222{
223 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800224 if ($1->stype != S_UNKNOWN)
225 menu_set_type($1->stype);
226 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
227 zconf_curname(), zconf_lineno(),
228 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229};
230
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200231config_option: T_SELECT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200233 menu_add_symbol(P_SELECT, $2, $3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
235};
236
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200237config_option: T_IMPLY nonconst_symbol if_expr T_EOL
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500238{
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200239 menu_add_symbol(P_IMPLY, $2, $3);
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500240 printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
241};
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243config_option: T_RANGE symbol symbol if_expr T_EOL
244{
245 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
246 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
247};
248
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700249symbol_option: T_OPTION symbol_option_list T_EOL
250;
251
252symbol_option_list:
253 /* empty */
254 | symbol_option_list T_WORD symbol_option_arg
255{
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400256 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
Ulf Magnussonbc28fe12017-10-08 19:11:20 +0200257 if (id && id->flags & TF_OPTION) {
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700258 menu_add_option(id->token, $3);
Ulf Magnussonbc28fe12017-10-08 19:11:20 +0200259 free($3);
260 }
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700261 else
262 zconfprint("warning: ignoring unknown option %s", $2);
263 free($2);
264};
265
266symbol_option_arg:
267 /* empty */ { $$ = NULL; }
268 | T_EQUAL prompt { $$ = $2; }
269;
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/* choice entry */
272
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100273choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100275 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
276 sym->flags |= SYMBOL_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 menu_add_entry(sym);
278 menu_add_expr(P_CHOICE, NULL, NULL);
279 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
280};
281
282choice_entry: choice choice_option_list
283{
Roman Zippela02f0572005-11-08 21:34:53 -0800284 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285};
286
287choice_end: end
288{
289 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
290 menu_end_menu();
291 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
292 }
293};
294
Roman Zippela02f0572005-11-08 21:34:53 -0800295choice_stmt: choice_entry choice_block choice_end
296;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298choice_option_list:
299 /* empty */
300 | choice_option_list choice_option
301 | choice_option_list depends
302 | choice_option_list help
303 | choice_option_list T_EOL
Roman Zippela02f0572005-11-08 21:34:53 -0800304 | choice_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305;
306
307choice_option: T_PROMPT prompt if_expr T_EOL
308{
309 menu_add_prompt(P_PROMPT, $2, $3);
310 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
311};
312
Roman Zippel3370f9f2005-11-08 21:34:52 -0800313choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800315 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
316 menu_set_type($1->stype);
317 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
318 zconf_curname(), zconf_lineno(),
319 $1->stype);
320 } else
321 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322};
323
324choice_option: T_OPTIONAL T_EOL
325{
326 current_entry->sym->flags |= SYMBOL_OPTIONAL;
327 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
328};
329
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200330choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800332 if ($1->stype == S_UNKNOWN) {
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200333 menu_add_symbol(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800334 printd(DEBUG_PARSE, "%s:%d:default\n",
335 zconf_curname(), zconf_lineno());
336 } else
337 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338};
339
340choice_block:
341 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800342 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343;
344
345/* if entry */
346
Roman Zippela02f0572005-11-08 21:34:53 -0800347if_entry: T_IF expr nl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
350 menu_add_entry(NULL);
351 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800352 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353};
354
355if_end: end
356{
357 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
358 menu_end_menu();
359 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
360 }
361};
362
Roman Zippela02f0572005-11-08 21:34:53 -0800363if_stmt: if_entry if_block if_end
364;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366if_block:
367 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800368 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 | if_block menu_stmt
370 | if_block choice_stmt
371;
372
373/* menu entry */
374
375menu: T_MENU prompt T_EOL
376{
377 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200378 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
380};
381
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300382menu_entry: menu visibility_list depends_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Roman Zippela02f0572005-11-08 21:34:53 -0800384 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385};
386
387menu_end: end
388{
389 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
390 menu_end_menu();
391 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
392 }
393};
394
Roman Zippela02f0572005-11-08 21:34:53 -0800395menu_stmt: menu_entry menu_block menu_end
396;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398menu_block:
399 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800400 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 | menu_block menu_stmt
402 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403;
404
Roman Zippela02f0572005-11-08 21:34:53 -0800405source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800408 zconf_nextfile($2);
Ulf Magnusson24161a62017-10-08 19:11:19 +0200409 free($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410};
411
412/* comment entry */
413
414comment: T_COMMENT prompt T_EOL
415{
416 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200417 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
419};
420
421comment_stmt: comment depends_list
Ulf Magnussondf60f4b2017-10-09 00:14:48 +0200422;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424/* help option */
425
426help_start: T_HELP T_EOL
427{
428 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
429 zconf_starthelp();
430};
431
432help: help_start T_HELPTEXT
433{
Ulf Magnusson6479f322018-01-12 07:47:47 +0100434 if (current_entry->help) {
435 free(current_entry->help);
436 zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
437 current_entry->sym->name ?: "<choice>");
438 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200439 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440};
441
442/* depends option */
443
Roman Zippela02f0572005-11-08 21:34:53 -0800444depends_list:
445 /* empty */
446 | depends_list depends
447 | depends_list T_EOL
448 | depends_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449;
450
451depends: T_DEPENDS T_ON expr T_EOL
452{
453 menu_add_dep($3);
454 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455};
456
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300457/* visibility option */
458
459visibility_list:
460 /* empty */
461 | visibility_list visible
462 | visibility_list T_EOL
463;
464
465visible: T_VISIBLE if_expr
466{
467 menu_add_visibility($2);
468};
469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470/* prompt statement */
471
472prompt_stmt_opt:
473 /* empty */
474 | prompt if_expr
475{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200476 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477};
478
479prompt: T_WORD
480 | T_WORD_QUOTE
481;
482
Roman Zippela02f0572005-11-08 21:34:53 -0800483end: T_ENDMENU T_EOL { $$ = $1; }
484 | T_ENDCHOICE T_EOL { $$ = $1; }
485 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486;
487
Roman Zippela02f0572005-11-08 21:34:53 -0800488nl:
489 T_EOL
490 | nl T_EOL
491;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493if_expr: /* empty */ { $$ = NULL; }
494 | T_IF expr { $$ = $2; }
495;
496
497expr: symbol { $$ = expr_alloc_symbol($1); }
Jan Beulich31847b62015-06-15 13:00:21 +0100498 | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
499 | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
500 | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
501 | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
503 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
504 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
505 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
506 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
507 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
508;
509
Ulf Magnusson26e47a32017-10-08 19:11:18 +0200510/* For symbol definitions, selects, etc., where quotes are not accepted */
511nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
512
513symbol: nonconst_symbol
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100514 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515;
516
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100517word_opt: /* empty */ { $$ = NULL; }
518 | T_WORD
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520%%
521
522void conf_parse(const char *name)
523{
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200524 const char *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 struct symbol *sym;
526 int i;
527
528 zconf_initscan(name);
529
530 sym_init();
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200531 _menu_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Roman Zippela02f0572005-11-08 21:34:53 -0800533 if (getenv("ZCONF_DEBUG"))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900534 yydebug = 1;
535 yyparse();
536 if (yynerrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 exit(1);
Yann E. MORIN6902dcc2013-09-03 17:07:18 +0200538 if (!modules_sym)
539 modules_sym = sym_find( "n" );
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400540
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200541 tmp = rootmenu.prompt->text;
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400542 rootmenu.prompt->text = _(rootmenu.prompt->text);
543 rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
Ulf Magnusson0724a7c2017-10-08 19:11:21 +0200544 free((char*)tmp);
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 menu_finalize(&rootmenu);
547 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200548 if (sym_check_deps(sym))
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900549 yynerrs++;
Masahiro Yamadabb66fc62014-06-10 19:08:13 +0900550 }
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900551 if (yynerrs)
Sam Ravnborg5447d342007-05-06 09:20:10 +0200552 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800553 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554}
555
Josh Triplett65166572009-10-15 12:13:36 -0700556static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 switch (token) {
559 case T_MENU: return "menu";
560 case T_ENDMENU: return "endmenu";
561 case T_CHOICE: return "choice";
562 case T_ENDCHOICE: return "endchoice";
563 case T_IF: return "if";
564 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800565 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300566 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
568 return "<token>";
569}
570
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400571static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
Roman Zippela02f0572005-11-08 21:34:53 -0800573 if (id->token != endtoken) {
574 zconf_error("unexpected '%s' within %s block",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700575 id->name, zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900576 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 return false;
578 }
579 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800580 zconf_error("'%s' in different file than '%s'",
Linus Torvaldsbb3290d2017-08-19 10:17:02 -0700581 id->name, zconf_tokenname(starttoken));
Roman Zippela02f0572005-11-08 21:34:53 -0800582 fprintf(stderr, "%s:%d: location of the '%s'\n",
583 current_menu->file->name, current_menu->lineno,
584 zconf_tokenname(starttoken));
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900585 yynerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return false;
587 }
588 return true;
589}
590
591static void zconfprint(const char *err, ...)
592{
593 va_list ap;
594
Roman Zippela02f0572005-11-08 21:34:53 -0800595 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
596 va_start(ap, err);
597 vfprintf(stderr, err, ap);
598 va_end(ap);
599 fprintf(stderr, "\n");
600}
601
602static void zconf_error(const char *err, ...)
603{
604 va_list ap;
605
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900606 yynerrs++;
Roman Zippela02f0572005-11-08 21:34:53 -0800607 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 va_start(ap, err);
609 vfprintf(stderr, err, ap);
610 va_end(ap);
611 fprintf(stderr, "\n");
612}
613
Masahiro Yamada765f4cd2018-01-12 00:50:50 +0900614static void yyerror(const char *err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
616 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
Josh Triplett65166572009-10-15 12:13:36 -0700619static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
621 const char *p;
622 int len;
623
624 putc('"', out);
625 while ((p = strchr(str, '"'))) {
626 len = p - str;
627 if (len)
628 fprintf(out, "%.*s", len, str);
629 fputs("\\\"", out);
630 str = p + 1;
631 }
632 fputs(str, out);
633 putc('"', out);
634}
635
Josh Triplett65166572009-10-15 12:13:36 -0700636static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 struct symbol *sym = menu->sym;
639 struct property *prop;
640
641 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800642 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800644 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 switch (sym->type) {
646 case S_BOOLEAN:
Masahiro Yamadab92d8042017-12-16 00:38:02 +0900647 fputs(" bool\n", out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 break;
649 case S_TRISTATE:
650 fputs(" tristate\n", out);
651 break;
652 case S_STRING:
653 fputs(" string\n", out);
654 break;
655 case S_INT:
656 fputs(" integer\n", out);
657 break;
658 case S_HEX:
659 fputs(" hex\n", out);
660 break;
661 default:
662 fputs(" ???\n", out);
663 break;
664 }
665 for (prop = sym->prop; prop; prop = prop->next) {
666 if (prop->menu != menu)
667 continue;
668 switch (prop->type) {
669 case P_PROMPT:
670 fputs(" prompt ", out);
671 print_quoted_string(out, prop->text);
672 if (!expr_is_yes(prop->visible.expr)) {
673 fputs(" if ", out);
674 expr_fprint(prop->visible.expr, out);
675 }
676 fputc('\n', out);
677 break;
678 case P_DEFAULT:
679 fputs( " default ", out);
680 expr_fprint(prop->expr, out);
681 if (!expr_is_yes(prop->visible.expr)) {
682 fputs(" if ", out);
683 expr_fprint(prop->visible.expr, out);
684 }
685 fputc('\n', out);
686 break;
687 case P_CHOICE:
688 fputs(" #choice value\n", out);
689 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800690 case P_SELECT:
691 fputs( " select ", out);
692 expr_fprint(prop->expr, out);
693 fputc('\n', out);
694 break;
Nicolas Pitre237e3ad2016-11-11 00:10:05 -0500695 case P_IMPLY:
696 fputs( " imply ", out);
697 expr_fprint(prop->expr, out);
698 fputc('\n', out);
699 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800700 case P_RANGE:
701 fputs( " range ", out);
702 expr_fprint(prop->expr, out);
703 fputc('\n', out);
704 break;
705 case P_MENU:
706 fputs( " menu ", out);
707 print_quoted_string(out, prop->text);
708 fputc('\n', out);
709 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 default:
711 fprintf(out, " unknown prop %d!\n", prop->type);
712 break;
713 }
714 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200715 if (menu->help) {
716 int len = strlen(menu->help);
717 while (menu->help[--len] == '\n')
718 menu->help[len] = 0;
719 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
723void zconfdump(FILE *out)
724{
725 struct property *prop;
726 struct symbol *sym;
727 struct menu *menu;
728
729 menu = rootmenu.list;
730 while (menu) {
731 if ((sym = menu->sym))
732 print_symbol(out, menu);
733 else if ((prop = menu->prompt)) {
734 switch (prop->type) {
735 case P_COMMENT:
736 fputs("\ncomment ", out);
737 print_quoted_string(out, prop->text);
738 fputs("\n", out);
739 break;
740 case P_MENU:
741 fputs("\nmenu ", out);
742 print_quoted_string(out, prop->text);
743 fputs("\n", out);
744 break;
745 default:
746 ;
747 }
748 if (!expr_is_yes(prop->visible.expr)) {
749 fputs(" depends ", out);
750 expr_fprint(prop->visible.expr, out);
751 fputc('\n', out);
752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
754
755 if (menu->list)
756 menu = menu->list;
757 else if (menu->next)
758 menu = menu->next;
759 else while ((menu = menu->parent)) {
760 if (menu->prompt && menu->prompt->type == P_MENU)
761 fputs("\nendmenu\n", out);
762 if (menu->next) {
763 menu = menu->next;
764 break;
765 }
766 }
767 }
768}
769
Arnaud Lacombe378dbb22011-05-23 02:08:52 -0400770#include "zconf.lex.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771#include "util.c"
772#include "confdata.c"
773#include "expr.c"
774#include "symbol.c"
775#include "menu.c"