blob: d9b96ba8e38caf6e3cf083b012272bd4ef041827 [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#define LKC_DIRECT_LINK
15#include "lkc.h"
16
17#include "zconf.hash.c"
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
20
21#define PRINTD 0x0001
22#define DEBUG_PARSE 0x0002
23
24int cdebug = PRINTD;
25
26extern int zconflex(void);
27static void zconfprint(const char *err, ...);
Roman Zippela02f0572005-11-08 21:34:53 -080028static void zconf_error(const char *err, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static void zconferror(const char *err);
Roman Zippela02f0572005-11-08 21:34:53 -080030static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32struct symbol *symbol_hash[257];
33
34static struct menu *current_menu, *current_entry;
35
Roman Zippela02f0572005-11-08 21:34:53 -080036#define YYDEBUG 0
37#if YYDEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define YYERROR_VERBOSE
Roman Zippela02f0572005-11-08 21:34:53 -080039#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070040%}
Roman Zippela02f0572005-11-08 21:34:53 -080041%expect 26
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43%union
44{
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 char *string;
Roman Zippela02f0572005-11-08 21:34:53 -080046 struct file *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 struct symbol *symbol;
48 struct expr *expr;
49 struct menu *menu;
Roman Zippel3370f9f2005-11-08 21:34:52 -080050 struct kconf_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Roman Zippel3370f9f2005-11-08 21:34:52 -080053%token <id>T_MAINMENU
54%token <id>T_MENU
55%token <id>T_ENDMENU
56%token <id>T_SOURCE
57%token <id>T_CHOICE
58%token <id>T_ENDCHOICE
59%token <id>T_COMMENT
60%token <id>T_CONFIG
61%token <id>T_MENUCONFIG
62%token <id>T_HELP
Linus Torvalds1da177e2005-04-16 15:20:36 -070063%token <string> T_HELPTEXT
Roman Zippel3370f9f2005-11-08 21:34:52 -080064%token <id>T_IF
65%token <id>T_ENDIF
66%token <id>T_DEPENDS
Roman Zippel3370f9f2005-11-08 21:34:52 -080067%token <id>T_OPTIONAL
68%token <id>T_PROMPT
69%token <id>T_TYPE
70%token <id>T_DEFAULT
71%token <id>T_SELECT
72%token <id>T_RANGE
Roman Zippelf6a88aa2006-06-08 22:12:44 -070073%token <id>T_OPTION
Roman Zippel3370f9f2005-11-08 21:34:52 -080074%token <id>T_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -070075%token <string> T_WORD
76%token <string> T_WORD_QUOTE
77%token T_UNEQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070078%token T_CLOSE_PAREN
79%token T_OPEN_PAREN
Roman Zippel3370f9f2005-11-08 21:34:52 -080080%token T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82%left T_OR
83%left T_AND
84%left T_EQUAL T_UNEQUAL
85%nonassoc T_NOT
86
87%type <string> prompt
Linus Torvalds1da177e2005-04-16 15:20:36 -070088%type <symbol> symbol
89%type <expr> expr
90%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080091%type <id> end
92%type <id> option_name
93%type <menu> if_entry menu_entry choice_entry
Roman Zippelf6a88aa2006-06-08 22:12:44 -070094%type <string> symbol_option_arg
Roman Zippela02f0572005-11-08 21:34:53 -080095
96%destructor {
97 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
98 $$->file->name, $$->lineno);
99 if (current_menu == $$)
100 menu_end_menu();
101} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103%%
Roman Zippela02f0572005-11-08 21:34:53 -0800104input: stmt_list;
105
106stmt_list:
107 /* empty */
108 | stmt_list common_stmt
109 | stmt_list choice_stmt
110 | stmt_list menu_stmt
111 | stmt_list T_MAINMENU prompt nl
112 | stmt_list end { zconf_error("unexpected end statement"); }
113 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
114 | stmt_list option_name error T_EOL
115{
116 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
117}
118 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119;
120
Roman Zippela02f0572005-11-08 21:34:53 -0800121option_name:
122 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123;
124
Roman Zippela02f0572005-11-08 21:34:53 -0800125common_stmt:
126 T_EOL
127 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 | comment_stmt
129 | config_stmt
130 | menuconfig_stmt
131 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800132;
133
134option_error:
135 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
136 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137;
138
139
140/* config/menuconfig entry */
141
142config_entry_start: T_CONFIG T_WORD T_EOL
143{
144 struct symbol *sym = sym_lookup($2, 0);
145 sym->flags |= SYMBOL_OPTIONAL;
146 menu_add_entry(sym);
147 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
148};
149
150config_stmt: config_entry_start config_option_list
151{
152 menu_end_entry();
153 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
154};
155
156menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
157{
158 struct symbol *sym = sym_lookup($2, 0);
159 sym->flags |= SYMBOL_OPTIONAL;
160 menu_add_entry(sym);
161 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
162};
163
164menuconfig_stmt: menuconfig_entry_start config_option_list
165{
166 if (current_entry->prompt)
167 current_entry->prompt->type = P_MENU;
168 else
169 zconfprint("warning: menuconfig statement without prompt");
170 menu_end_entry();
171 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
172};
173
174config_option_list:
175 /* empty */
176 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700177 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 | config_option_list depends
179 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800180 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 | config_option_list T_EOL
182;
183
Roman Zippel3370f9f2005-11-08 21:34:52 -0800184config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800186 menu_set_type($1->stype);
187 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
188 zconf_curname(), zconf_lineno(),
189 $1->stype);
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
198config_option: T_DEFAULT expr if_expr T_EOL
199{
200 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800201 if ($1->stype != S_UNKNOWN)
202 menu_set_type($1->stype);
203 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
204 zconf_curname(), zconf_lineno(),
205 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206};
207
208config_option: T_SELECT T_WORD if_expr T_EOL
209{
210 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
211 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
212};
213
214config_option: T_RANGE symbol symbol if_expr T_EOL
215{
216 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
217 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
218};
219
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700220symbol_option: T_OPTION symbol_option_list T_EOL
221;
222
223symbol_option_list:
224 /* empty */
225 | symbol_option_list T_WORD symbol_option_arg
226{
227 struct kconf_id *id = kconf_id_lookup($2, strlen($2));
228 if (id && id->flags & TF_OPTION)
229 menu_add_option(id->token, $3);
230 else
231 zconfprint("warning: ignoring unknown option %s", $2);
232 free($2);
233};
234
235symbol_option_arg:
236 /* empty */ { $$ = NULL; }
237 | T_EQUAL prompt { $$ = $2; }
238;
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/* choice entry */
241
242choice: T_CHOICE T_EOL
243{
244 struct symbol *sym = sym_lookup(NULL, 0);
245 sym->flags |= SYMBOL_CHOICE;
246 menu_add_entry(sym);
247 menu_add_expr(P_CHOICE, NULL, NULL);
248 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
249};
250
251choice_entry: choice choice_option_list
252{
Roman Zippela02f0572005-11-08 21:34:53 -0800253 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254};
255
256choice_end: end
257{
258 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
259 menu_end_menu();
260 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
261 }
262};
263
Roman Zippela02f0572005-11-08 21:34:53 -0800264choice_stmt: choice_entry choice_block choice_end
265;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267choice_option_list:
268 /* empty */
269 | choice_option_list choice_option
270 | choice_option_list depends
271 | choice_option_list help
272 | choice_option_list T_EOL
Roman Zippela02f0572005-11-08 21:34:53 -0800273 | choice_option_list option_error
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
299choice_option: T_DEFAULT T_WORD if_expr T_EOL
300{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800301 if ($1->stype == S_UNKNOWN) {
302 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
303 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
Roman Zippela02f0572005-11-08 21:34:53 -0800316if_entry: T_IF expr nl
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
Roman Zippela02f0572005-11-08 21:34:53 -0800332if_stmt: if_entry if_block if_end
333;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335if_block:
336 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800337 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 | if_block menu_stmt
339 | if_block choice_stmt
340;
341
342/* menu entry */
343
344menu: T_MENU prompt T_EOL
345{
346 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200347 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
349};
350
351menu_entry: menu depends_list
352{
Roman Zippela02f0572005-11-08 21:34:53 -0800353 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
356menu_end: end
357{
358 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
359 menu_end_menu();
360 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
361 }
362};
363
Roman Zippela02f0572005-11-08 21:34:53 -0800364menu_stmt: menu_entry menu_block menu_end
365;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367menu_block:
368 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800369 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 | menu_block menu_stmt
371 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372;
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378};
379
380/* comment entry */
381
382comment: T_COMMENT prompt T_EOL
383{
384 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200385 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
387};
388
389comment_stmt: comment depends_list
390{
391 menu_end_entry();
392};
393
394/* help option */
395
396help_start: T_HELP T_EOL
397{
398 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
399 zconf_starthelp();
400};
401
402help: help_start T_HELPTEXT
403{
Sam Ravnborg03d29122007-07-21 00:00:36 +0200404 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405};
406
407/* depends option */
408
Roman Zippela02f0572005-11-08 21:34:53 -0800409depends_list:
410 /* empty */
411 | depends_list depends
412 | depends_list T_EOL
413 | depends_list option_error
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
422/* prompt statement */
423
424prompt_stmt_opt:
425 /* empty */
426 | prompt if_expr
427{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200428 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429};
430
431prompt: T_WORD
432 | T_WORD_QUOTE
433;
434
Roman Zippela02f0572005-11-08 21:34:53 -0800435end: T_ENDMENU T_EOL { $$ = $1; }
436 | T_ENDCHOICE T_EOL { $$ = $1; }
437 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438;
439
Roman Zippela02f0572005-11-08 21:34:53 -0800440nl:
441 T_EOL
442 | nl T_EOL
443;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445if_expr: /* empty */ { $$ = NULL; }
446 | T_IF expr { $$ = $2; }
447;
448
449expr: symbol { $$ = expr_alloc_symbol($1); }
450 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
451 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
452 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
453 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
454 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
455 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
456;
457
458symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
459 | T_WORD_QUOTE { $$ = sym_lookup($1, 1); free($1); }
460;
461
462%%
463
464void conf_parse(const char *name)
465{
466 struct symbol *sym;
467 int i;
468
469 zconf_initscan(name);
470
471 sym_init();
472 menu_init();
Roman Zippelface4372006-06-08 22:12:45 -0700473 modules_sym = sym_lookup(NULL, 0);
474 modules_sym->type = S_BOOLEAN;
475 modules_sym->flags |= SYMBOL_AUTO;
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200476 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Roman Zippela02f0572005-11-08 21:34:53 -0800478#if YYDEBUG
479 if (getenv("ZCONF_DEBUG"))
480 zconfdebug = 1;
481#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 zconfparse();
483 if (zconfnerrs)
484 exit(1);
Roman Zippelface4372006-06-08 22:12:45 -0700485 if (!modules_sym->prop) {
486 struct property *prop;
487
488 prop = prop_alloc(P_DEFAULT, modules_sym);
489 prop->expr = expr_alloc_symbol(sym_lookup("MODULES", 0));
490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 menu_finalize(&rootmenu);
492 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200493 if (sym_check_deps(sym))
494 zconfnerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
Sam Ravnborg5447d342007-05-06 09:20:10 +0200496 if (zconfnerrs)
497 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800498 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
501const char *zconf_tokenname(int token)
502{
503 switch (token) {
504 case T_MENU: return "menu";
505 case T_ENDMENU: return "endmenu";
506 case T_CHOICE: return "choice";
507 case T_ENDCHOICE: return "endchoice";
508 case T_IF: return "if";
509 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800510 case T_DEPENDS: return "depends";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512 return "<token>";
513}
514
Roman Zippela02f0572005-11-08 21:34:53 -0800515static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Roman Zippela02f0572005-11-08 21:34:53 -0800517 if (id->token != endtoken) {
518 zconf_error("unexpected '%s' within %s block",
519 kconf_id_strings + id->name, zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 zconfnerrs++;
521 return false;
522 }
523 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800524 zconf_error("'%s' in different file than '%s'",
525 kconf_id_strings + id->name, zconf_tokenname(starttoken));
526 fprintf(stderr, "%s:%d: location of the '%s'\n",
527 current_menu->file->name, current_menu->lineno,
528 zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 zconfnerrs++;
530 return false;
531 }
532 return true;
533}
534
535static void zconfprint(const char *err, ...)
536{
537 va_list ap;
538
Roman Zippela02f0572005-11-08 21:34:53 -0800539 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
540 va_start(ap, err);
541 vfprintf(stderr, err, ap);
542 va_end(ap);
543 fprintf(stderr, "\n");
544}
545
546static void zconf_error(const char *err, ...)
547{
548 va_list ap;
549
550 zconfnerrs++;
551 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 va_start(ap, err);
553 vfprintf(stderr, err, ap);
554 va_end(ap);
555 fprintf(stderr, "\n");
556}
557
558static void zconferror(const char *err)
559{
Roman Zippela02f0572005-11-08 21:34:53 -0800560#if YYDEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Roman Zippela02f0572005-11-08 21:34:53 -0800562#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
565void print_quoted_string(FILE *out, const char *str)
566{
567 const char *p;
568 int len;
569
570 putc('"', out);
571 while ((p = strchr(str, '"'))) {
572 len = p - str;
573 if (len)
574 fprintf(out, "%.*s", len, str);
575 fputs("\\\"", out);
576 str = p + 1;
577 }
578 fputs(str, out);
579 putc('"', out);
580}
581
582void print_symbol(FILE *out, struct menu *menu)
583{
584 struct symbol *sym = menu->sym;
585 struct property *prop;
586
587 if (sym_is_choice(sym))
588 fprintf(out, "choice\n");
589 else
590 fprintf(out, "config %s\n", sym->name);
591 switch (sym->type) {
592 case S_BOOLEAN:
593 fputs(" boolean\n", out);
594 break;
595 case S_TRISTATE:
596 fputs(" tristate\n", out);
597 break;
598 case S_STRING:
599 fputs(" string\n", out);
600 break;
601 case S_INT:
602 fputs(" integer\n", out);
603 break;
604 case S_HEX:
605 fputs(" hex\n", out);
606 break;
607 default:
608 fputs(" ???\n", out);
609 break;
610 }
611 for (prop = sym->prop; prop; prop = prop->next) {
612 if (prop->menu != menu)
613 continue;
614 switch (prop->type) {
615 case P_PROMPT:
616 fputs(" prompt ", out);
617 print_quoted_string(out, prop->text);
618 if (!expr_is_yes(prop->visible.expr)) {
619 fputs(" if ", out);
620 expr_fprint(prop->visible.expr, out);
621 }
622 fputc('\n', out);
623 break;
624 case P_DEFAULT:
625 fputs( " default ", out);
626 expr_fprint(prop->expr, out);
627 if (!expr_is_yes(prop->visible.expr)) {
628 fputs(" if ", out);
629 expr_fprint(prop->visible.expr, out);
630 }
631 fputc('\n', out);
632 break;
633 case P_CHOICE:
634 fputs(" #choice value\n", out);
635 break;
636 default:
637 fprintf(out, " unknown prop %d!\n", prop->type);
638 break;
639 }
640 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200641 if (menu->help) {
642 int len = strlen(menu->help);
643 while (menu->help[--len] == '\n')
644 menu->help[len] = 0;
645 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
647 fputc('\n', out);
648}
649
650void zconfdump(FILE *out)
651{
652 struct property *prop;
653 struct symbol *sym;
654 struct menu *menu;
655
656 menu = rootmenu.list;
657 while (menu) {
658 if ((sym = menu->sym))
659 print_symbol(out, menu);
660 else if ((prop = menu->prompt)) {
661 switch (prop->type) {
662 case P_COMMENT:
663 fputs("\ncomment ", out);
664 print_quoted_string(out, prop->text);
665 fputs("\n", out);
666 break;
667 case P_MENU:
668 fputs("\nmenu ", out);
669 print_quoted_string(out, prop->text);
670 fputs("\n", out);
671 break;
672 default:
673 ;
674 }
675 if (!expr_is_yes(prop->visible.expr)) {
676 fputs(" depends ", out);
677 expr_fprint(prop->visible.expr, out);
678 fputc('\n', out);
679 }
680 fputs("\n", out);
681 }
682
683 if (menu->list)
684 menu = menu->list;
685 else if (menu->next)
686 menu = menu->next;
687 else while ((menu = menu->parent)) {
688 if (menu->prompt && menu->prompt->type == P_MENU)
689 fputs("\nendmenu\n", out);
690 if (menu->next) {
691 menu = menu->next;
692 break;
693 }
694 }
695 }
696}
697
698#include "lex.zconf.c"
699#include "util.c"
700#include "confdata.c"
701#include "expr.c"
702#include "symbol.c"
703#include "menu.c"