blob: 5122ed2d839abbe2bdf28608c47f957b2288b16b [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
23extern int zconflex(void);
24static void zconfprint(const char *err, ...);
Roman Zippela02f0572005-11-08 21:34:53 -080025static void zconf_error(const char *err, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static void zconferror(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%}
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030034%expect 30
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
65%token <id>T_RANGE
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030066%token <id>T_VISIBLE
Roman Zippelf6a88aa2006-06-08 22:12:44 -070067%token <id>T_OPTION
Roman Zippel3370f9f2005-11-08 21:34:52 -080068%token <id>T_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -070069%token <string> T_WORD
70%token <string> T_WORD_QUOTE
71%token T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010072%token T_LESS
73%token T_LESS_EQUAL
74%token T_GREATER
75%token T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070076%token T_CLOSE_PAREN
77%token T_OPEN_PAREN
Roman Zippel3370f9f2005-11-08 21:34:52 -080078%token T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80%left T_OR
81%left T_AND
82%left T_EQUAL T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010083%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070084%nonassoc T_NOT
85
86%type <string> prompt
Linus Torvalds1da177e2005-04-16 15:20:36 -070087%type <symbol> symbol
88%type <expr> expr
89%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080090%type <id> end
91%type <id> option_name
92%type <menu> if_entry menu_entry choice_entry
Roman Zippel5a1aa8a2008-02-29 05:11:50 +010093%type <string> symbol_option_arg word_opt
Roman Zippela02f0572005-11-08 21:34:53 -080094
95%destructor {
96 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
97 $$->file->name, $$->lineno);
98 if (current_menu == $$)
99 menu_end_menu();
100} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Josh Triplett1456edb2009-10-15 11:03:20 -0700102%{
103/* Include zconf.hash.c here so it can see the token constants. */
104#include "zconf.hash.c"
105%}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107%%
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400108input: nl start | start;
109
Ulf Magnussond0c1ba12017-10-08 19:11:21 +0200110start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list;
111
112/* mainmenu entry */
113
114mainmenu_stmt: T_MAINMENU prompt nl
115{
116 menu_add_prompt(P_MENU, $2, NULL);
117};
118
119/* Default main menu, if there's no mainmenu entry */
120
121no_mainmenu_stmt: /* empty */
122{
123 /*
124 * Hack: Keep the main menu title on the heap so we can safely free it
125 * later regardless of whether it comes from the 'prompt' in
126 * mainmenu_stmt or here
127 */
128 menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL);
129};
130
Roman Zippela02f0572005-11-08 21:34:53 -0800131
132stmt_list:
133 /* empty */
134 | stmt_list common_stmt
135 | stmt_list choice_stmt
136 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800137 | stmt_list end { zconf_error("unexpected end statement"); }
138 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
139 | stmt_list option_name error T_EOL
140{
141 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
142}
143 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144;
145
Roman Zippela02f0572005-11-08 21:34:53 -0800146option_name:
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300147 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148;
149
Roman Zippela02f0572005-11-08 21:34:53 -0800150common_stmt:
151 T_EOL
152 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 | comment_stmt
154 | config_stmt
155 | menuconfig_stmt
156 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800157;
158
159option_error:
160 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
161 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162;
163
164
165/* config/menuconfig entry */
166
167config_entry_start: T_CONFIG T_WORD T_EOL
168{
169 struct symbol *sym = sym_lookup($2, 0);
170 sym->flags |= SYMBOL_OPTIONAL;
171 menu_add_entry(sym);
172 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
173};
174
175config_stmt: config_entry_start config_option_list
176{
177 menu_end_entry();
178 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
179};
180
181menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
182{
183 struct symbol *sym = sym_lookup($2, 0);
184 sym->flags |= SYMBOL_OPTIONAL;
185 menu_add_entry(sym);
186 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
187};
188
189menuconfig_stmt: menuconfig_entry_start config_option_list
190{
191 if (current_entry->prompt)
192 current_entry->prompt->type = P_MENU;
193 else
194 zconfprint("warning: menuconfig statement without prompt");
195 menu_end_entry();
196 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
197};
198
199config_option_list:
200 /* empty */
201 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700202 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 | config_option_list depends
204 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800205 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 | config_option_list T_EOL
207;
208
Roman Zippel3370f9f2005-11-08 21:34:52 -0800209config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800211 menu_set_type($1->stype);
212 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
213 zconf_curname(), zconf_lineno(),
214 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215};
216
217config_option: T_PROMPT prompt if_expr T_EOL
218{
219 menu_add_prompt(P_PROMPT, $2, $3);
220 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
221};
222
223config_option: T_DEFAULT expr if_expr T_EOL
224{
225 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800226 if ($1->stype != S_UNKNOWN)
227 menu_set_type($1->stype);
228 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
229 zconf_curname(), zconf_lineno(),
230 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231};
232
233config_option: T_SELECT T_WORD if_expr T_EOL
234{
235 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
236 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
237};
238
239config_option: T_RANGE symbol symbol if_expr T_EOL
240{
241 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
242 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
243};
244
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700245symbol_option: T_OPTION symbol_option_list T_EOL
246;
247
248symbol_option_list:
249 /* empty */
250 | symbol_option_list T_WORD symbol_option_arg
251{
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400252 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700253 if (id && id->flags & TF_OPTION)
254 menu_add_option(id->token, $3);
255 else
256 zconfprint("warning: ignoring unknown option %s", $2);
257 free($2);
258};
259
260symbol_option_arg:
261 /* empty */ { $$ = NULL; }
262 | T_EQUAL prompt { $$ = $2; }
263;
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265/* choice entry */
266
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100267choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100269 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
270 sym->flags |= SYMBOL_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 menu_add_entry(sym);
272 menu_add_expr(P_CHOICE, NULL, NULL);
273 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
274};
275
276choice_entry: choice choice_option_list
277{
Roman Zippela02f0572005-11-08 21:34:53 -0800278 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279};
280
281choice_end: end
282{
283 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
284 menu_end_menu();
285 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
286 }
287};
288
Roman Zippela02f0572005-11-08 21:34:53 -0800289choice_stmt: choice_entry choice_block choice_end
290;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292choice_option_list:
293 /* empty */
294 | choice_option_list choice_option
295 | choice_option_list depends
296 | choice_option_list help
297 | choice_option_list T_EOL
Roman Zippela02f0572005-11-08 21:34:53 -0800298 | choice_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299;
300
301choice_option: T_PROMPT prompt if_expr T_EOL
302{
303 menu_add_prompt(P_PROMPT, $2, $3);
304 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
305};
306
Roman Zippel3370f9f2005-11-08 21:34:52 -0800307choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800309 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
310 menu_set_type($1->stype);
311 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
312 zconf_curname(), zconf_lineno(),
313 $1->stype);
314 } else
315 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316};
317
318choice_option: T_OPTIONAL T_EOL
319{
320 current_entry->sym->flags |= SYMBOL_OPTIONAL;
321 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
322};
323
324choice_option: T_DEFAULT T_WORD if_expr T_EOL
325{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800326 if ($1->stype == S_UNKNOWN) {
327 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
328 printd(DEBUG_PARSE, "%s:%d:default\n",
329 zconf_curname(), zconf_lineno());
330 } else
331 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332};
333
334choice_block:
335 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800336 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337;
338
339/* if entry */
340
Roman Zippela02f0572005-11-08 21:34:53 -0800341if_entry: T_IF expr nl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
343 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
344 menu_add_entry(NULL);
345 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800346 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347};
348
349if_end: end
350{
351 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
352 menu_end_menu();
353 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
354 }
355};
356
Roman Zippela02f0572005-11-08 21:34:53 -0800357if_stmt: if_entry if_block if_end
358;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360if_block:
361 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800362 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 | if_block menu_stmt
364 | if_block choice_stmt
365;
366
367/* menu entry */
368
369menu: T_MENU prompt T_EOL
370{
371 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200372 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
374};
375
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300376menu_entry: menu visibility_list depends_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Roman Zippela02f0572005-11-08 21:34:53 -0800378 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379};
380
381menu_end: end
382{
383 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
384 menu_end_menu();
385 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
386 }
387};
388
Roman Zippela02f0572005-11-08 21:34:53 -0800389menu_stmt: menu_entry menu_block menu_end
390;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392menu_block:
393 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800394 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 | menu_block menu_stmt
396 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397;
398
Roman Zippela02f0572005-11-08 21:34:53 -0800399source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800402 zconf_nextfile($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403};
404
405/* comment entry */
406
407comment: T_COMMENT prompt T_EOL
408{
409 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200410 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
412};
413
414comment_stmt: comment depends_list
415{
416 menu_end_entry();
417};
418
419/* help option */
420
421help_start: T_HELP T_EOL
422{
423 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
424 zconf_starthelp();
425};
426
427help: help_start T_HELPTEXT
428{
Sam Ravnborg03d29122007-07-21 00:00:36 +0200429 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430};
431
432/* depends option */
433
Roman Zippela02f0572005-11-08 21:34:53 -0800434depends_list:
435 /* empty */
436 | depends_list depends
437 | depends_list T_EOL
438 | depends_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439;
440
441depends: T_DEPENDS T_ON expr T_EOL
442{
443 menu_add_dep($3);
444 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445};
446
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300447/* visibility option */
448
449visibility_list:
450 /* empty */
451 | visibility_list visible
452 | visibility_list T_EOL
453;
454
455visible: T_VISIBLE if_expr
456{
457 menu_add_visibility($2);
458};
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460/* prompt statement */
461
462prompt_stmt_opt:
463 /* empty */
464 | prompt if_expr
465{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200466 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467};
468
469prompt: T_WORD
470 | T_WORD_QUOTE
471;
472
Roman Zippela02f0572005-11-08 21:34:53 -0800473end: T_ENDMENU T_EOL { $$ = $1; }
474 | T_ENDCHOICE T_EOL { $$ = $1; }
475 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476;
477
Roman Zippela02f0572005-11-08 21:34:53 -0800478nl:
479 T_EOL
480 | nl T_EOL
481;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483if_expr: /* empty */ { $$ = NULL; }
484 | T_IF expr { $$ = $2; }
485;
486
487expr: symbol { $$ = expr_alloc_symbol($1); }
Jan Beulich31847b62015-06-15 13:00:21 +0100488 | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
489 | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
490 | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
491 | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
493 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
494 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
495 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
496 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
497 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
498;
499
500symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100501 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502;
503
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100504word_opt: /* empty */ { $$ = NULL; }
505 | T_WORD
506
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507%%
508
509void conf_parse(const char *name)
510{
Ulf Magnussond0c1ba12017-10-08 19:11:21 +0200511 const char *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 struct symbol *sym;
513 int i;
514
515 zconf_initscan(name);
516
517 sym_init();
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200518 _menu_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Roman Zippela02f0572005-11-08 21:34:53 -0800520 if (getenv("ZCONF_DEBUG"))
521 zconfdebug = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 zconfparse();
523 if (zconfnerrs)
524 exit(1);
Yann E. MORIN6902dcc2013-09-03 17:07:18 +0200525 if (!modules_sym)
526 modules_sym = sym_find( "n" );
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400527
Ulf Magnussond0c1ba12017-10-08 19:11:21 +0200528 tmp = rootmenu.prompt->text;
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400529 rootmenu.prompt->text = _(rootmenu.prompt->text);
530 rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
Ulf Magnussond0c1ba12017-10-08 19:11:21 +0200531 free((char*)tmp);
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 menu_finalize(&rootmenu);
534 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200535 if (sym_check_deps(sym))
536 zconfnerrs++;
Masahiro Yamadabb66fc62014-06-10 19:08:13 +0900537 }
Sam Ravnborg5447d342007-05-06 09:20:10 +0200538 if (zconfnerrs)
539 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800540 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
Josh Triplett65166572009-10-15 12:13:36 -0700543static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 switch (token) {
546 case T_MENU: return "menu";
547 case T_ENDMENU: return "endmenu";
548 case T_CHOICE: return "choice";
549 case T_ENDCHOICE: return "endchoice";
550 case T_IF: return "if";
551 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800552 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300553 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 }
555 return "<token>";
556}
557
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400558static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Roman Zippela02f0572005-11-08 21:34:53 -0800560 if (id->token != endtoken) {
561 zconf_error("unexpected '%s' within %s block",
562 kconf_id_strings + id->name, zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 zconfnerrs++;
564 return false;
565 }
566 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800567 zconf_error("'%s' in different file than '%s'",
568 kconf_id_strings + id->name, zconf_tokenname(starttoken));
569 fprintf(stderr, "%s:%d: location of the '%s'\n",
570 current_menu->file->name, current_menu->lineno,
571 zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 zconfnerrs++;
573 return false;
574 }
575 return true;
576}
577
578static void zconfprint(const char *err, ...)
579{
580 va_list ap;
581
Roman Zippela02f0572005-11-08 21:34:53 -0800582 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
583 va_start(ap, err);
584 vfprintf(stderr, err, ap);
585 va_end(ap);
586 fprintf(stderr, "\n");
587}
588
589static void zconf_error(const char *err, ...)
590{
591 va_list ap;
592
593 zconfnerrs++;
594 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 va_start(ap, err);
596 vfprintf(stderr, err, ap);
597 va_end(ap);
598 fprintf(stderr, "\n");
599}
600
601static void zconferror(const char *err)
602{
603 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
Josh Triplett65166572009-10-15 12:13:36 -0700606static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
608 const char *p;
609 int len;
610
611 putc('"', out);
612 while ((p = strchr(str, '"'))) {
613 len = p - str;
614 if (len)
615 fprintf(out, "%.*s", len, str);
616 fputs("\\\"", out);
617 str = p + 1;
618 }
619 fputs(str, out);
620 putc('"', out);
621}
622
Josh Triplett65166572009-10-15 12:13:36 -0700623static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624{
625 struct symbol *sym = menu->sym;
626 struct property *prop;
627
628 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800629 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800631 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 switch (sym->type) {
633 case S_BOOLEAN:
634 fputs(" boolean\n", out);
635 break;
636 case S_TRISTATE:
637 fputs(" tristate\n", out);
638 break;
639 case S_STRING:
640 fputs(" string\n", out);
641 break;
642 case S_INT:
643 fputs(" integer\n", out);
644 break;
645 case S_HEX:
646 fputs(" hex\n", out);
647 break;
648 default:
649 fputs(" ???\n", out);
650 break;
651 }
652 for (prop = sym->prop; prop; prop = prop->next) {
653 if (prop->menu != menu)
654 continue;
655 switch (prop->type) {
656 case P_PROMPT:
657 fputs(" prompt ", out);
658 print_quoted_string(out, prop->text);
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_DEFAULT:
666 fputs( " default ", out);
667 expr_fprint(prop->expr, out);
668 if (!expr_is_yes(prop->visible.expr)) {
669 fputs(" if ", out);
670 expr_fprint(prop->visible.expr, out);
671 }
672 fputc('\n', out);
673 break;
674 case P_CHOICE:
675 fputs(" #choice value\n", out);
676 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800677 case P_SELECT:
678 fputs( " select ", out);
679 expr_fprint(prop->expr, out);
680 fputc('\n', out);
681 break;
682 case P_RANGE:
683 fputs( " range ", out);
684 expr_fprint(prop->expr, out);
685 fputc('\n', out);
686 break;
687 case P_MENU:
688 fputs( " menu ", out);
689 print_quoted_string(out, prop->text);
690 fputc('\n', out);
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"