blob: 5ebaf0a78f06e5903b4a0aa87b9c1ce6b38a706b [file] [log] [blame]
Eric Andersenc9f20d92002-12-05 08:41:41 +00001%{
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
14#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
15
16#define PRINTD 0x0001
17#define DEBUG_PARSE 0x0002
18
19int cdebug = PRINTD;
20
21extern int zconflex(void);
22static void zconfprint(const char *err, ...);
23static void zconferror(const char *err);
24static bool zconf_endtoken(int token, int starttoken, int endtoken);
25
26struct symbol *symbol_hash[257];
27
Peter Kjellerstedtbae38db2005-04-19 09:55:06 +000028static struct menu *current_menu, *current_entry;
29
Eric Andersenc9f20d92002-12-05 08:41:41 +000030#define YYERROR_VERBOSE
31%}
Eric Andersen72d8e442003-08-05 02:18:25 +000032%expect 40
Eric Andersenc9f20d92002-12-05 08:41:41 +000033
34%union
35{
36 int token;
37 char *string;
38 struct symbol *symbol;
39 struct expr *expr;
40 struct menu *menu;
41}
42
43%token T_MAINMENU
44%token T_MENU
45%token T_ENDMENU
46%token T_SOURCE
47%token T_CHOICE
48%token T_ENDCHOICE
49%token T_COMMENT
50%token T_CONFIG
Eric Andersen72d8e442003-08-05 02:18:25 +000051%token T_MENUCONFIG
Eric Andersenc9f20d92002-12-05 08:41:41 +000052%token T_HELP
53%token <string> T_HELPTEXT
54%token T_IF
55%token T_ENDIF
56%token T_DEPENDS
57%token T_REQUIRES
58%token T_OPTIONAL
59%token T_PROMPT
60%token T_DEFAULT
61%token T_TRISTATE
Eric Andersen72d8e442003-08-05 02:18:25 +000062%token T_DEF_TRISTATE
Eric Andersenc9f20d92002-12-05 08:41:41 +000063%token T_BOOLEAN
Eric Andersen72d8e442003-08-05 02:18:25 +000064%token T_DEF_BOOLEAN
65%token T_STRING
Eric Andersenc9f20d92002-12-05 08:41:41 +000066%token T_INT
67%token T_HEX
68%token <string> T_WORD
Eric Andersen72d8e442003-08-05 02:18:25 +000069%token <string> T_WORD_QUOTE
Eric Andersenc9f20d92002-12-05 08:41:41 +000070%token T_UNEQUAL
71%token T_EOF
72%token T_EOL
73%token T_CLOSE_PAREN
74%token T_OPEN_PAREN
75%token T_ON
Eric Andersen72d8e442003-08-05 02:18:25 +000076%token T_SELECT
77%token T_RANGE
Eric Andersenc9f20d92002-12-05 08:41:41 +000078
79%left T_OR
80%left T_AND
81%left T_EQUAL T_UNEQUAL
82%nonassoc T_NOT
83
84%type <string> prompt
85%type <string> source
86%type <symbol> symbol
87%type <expr> expr
88%type <expr> if_expr
89%type <token> end
90
91%{
92#define LKC_DIRECT_LINK
93#include "lkc.h"
94%}
95%%
96input: /* empty */
97 | input block
98;
99
100block: common_block
101 | choice_stmt
102 | menu_stmt
103 | T_MAINMENU prompt nl_or_eof
104 | T_ENDMENU { zconfprint("unexpected 'endmenu' statement"); }
105 | T_ENDIF { zconfprint("unexpected 'endif' statement"); }
106 | T_ENDCHOICE { zconfprint("unexpected 'endchoice' statement"); }
107 | error nl_or_eof { zconfprint("syntax error"); yyerrok; }
108;
109
110common_block:
111 if_stmt
112 | comment_stmt
113 | config_stmt
Eric Andersen72d8e442003-08-05 02:18:25 +0000114 | menuconfig_stmt
Eric Andersenc9f20d92002-12-05 08:41:41 +0000115 | source_stmt
116 | nl_or_eof
117;
118
119
Eric Andersen72d8e442003-08-05 02:18:25 +0000120/* config/menuconfig entry */
Eric Andersenc9f20d92002-12-05 08:41:41 +0000121
Eric Andersen72d8e442003-08-05 02:18:25 +0000122config_entry_start: T_CONFIG T_WORD T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000123{
124 struct symbol *sym = sym_lookup($2, 0);
125 sym->flags |= SYMBOL_OPTIONAL;
126 menu_add_entry(sym);
127 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
128};
129
Eric Andersen72d8e442003-08-05 02:18:25 +0000130config_stmt: config_entry_start config_option_list
Eric Andersenc9f20d92002-12-05 08:41:41 +0000131{
132 menu_end_entry();
133 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
134};
135
Eric Andersen72d8e442003-08-05 02:18:25 +0000136menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
137{
138 struct symbol *sym = sym_lookup($2, 0);
139 sym->flags |= SYMBOL_OPTIONAL;
140 menu_add_entry(sym);
141 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
142};
143
144menuconfig_stmt: menuconfig_entry_start config_option_list
145{
146 if (current_entry->prompt)
147 current_entry->prompt->type = P_MENU;
148 else
149 zconfprint("warning: menuconfig statement without prompt");
150 menu_end_entry();
151 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
152};
153
Eric Andersenc9f20d92002-12-05 08:41:41 +0000154config_option_list:
155 /* empty */
Eric Andersen72d8e442003-08-05 02:18:25 +0000156 | config_option_list config_option
157 | config_option_list depends
Eric Andersenc9f20d92002-12-05 08:41:41 +0000158 | config_option_list help
159 | config_option_list T_EOL
Eric Andersen72d8e442003-08-05 02:18:25 +0000160;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000161
Eric Andersen72d8e442003-08-05 02:18:25 +0000162config_option: T_TRISTATE prompt_stmt_opt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000163{
164 menu_set_type(S_TRISTATE);
165 printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno());
166};
167
Eric Andersen72d8e442003-08-05 02:18:25 +0000168config_option: T_DEF_TRISTATE expr if_expr T_EOL
169{
170 menu_add_expr(P_DEFAULT, $2, $3);
171 menu_set_type(S_TRISTATE);
172 printd(DEBUG_PARSE, "%s:%d:def_boolean\n", zconf_curname(), zconf_lineno());
173};
174
175config_option: T_BOOLEAN prompt_stmt_opt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000176{
177 menu_set_type(S_BOOLEAN);
178 printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno());
179};
180
Eric Andersen72d8e442003-08-05 02:18:25 +0000181config_option: T_DEF_BOOLEAN expr if_expr T_EOL
182{
183 menu_add_expr(P_DEFAULT, $2, $3);
184 menu_set_type(S_BOOLEAN);
185 printd(DEBUG_PARSE, "%s:%d:def_boolean\n", zconf_curname(), zconf_lineno());
186};
187
188config_option: T_INT prompt_stmt_opt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000189{
190 menu_set_type(S_INT);
191 printd(DEBUG_PARSE, "%s:%d:int\n", zconf_curname(), zconf_lineno());
192};
193
Eric Andersen72d8e442003-08-05 02:18:25 +0000194config_option: T_HEX prompt_stmt_opt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000195{
196 menu_set_type(S_HEX);
197 printd(DEBUG_PARSE, "%s:%d:hex\n", zconf_curname(), zconf_lineno());
198};
199
Eric Andersen72d8e442003-08-05 02:18:25 +0000200config_option: T_STRING prompt_stmt_opt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000201{
202 menu_set_type(S_STRING);
203 printd(DEBUG_PARSE, "%s:%d:string\n", zconf_curname(), zconf_lineno());
204};
205
Eric Andersen72d8e442003-08-05 02:18:25 +0000206config_option: T_PROMPT prompt if_expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000207{
Eric Andersen72d8e442003-08-05 02:18:25 +0000208 menu_add_prompt(P_PROMPT, $2, $3);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000209 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
210};
211
Eric Andersen72d8e442003-08-05 02:18:25 +0000212config_option: T_DEFAULT expr if_expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000213{
Eric Andersen72d8e442003-08-05 02:18:25 +0000214 menu_add_expr(P_DEFAULT, $2, $3);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000215 printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno());
216};
217
Eric Andersen72d8e442003-08-05 02:18:25 +0000218config_option: T_SELECT T_WORD if_expr T_EOL
219{
220 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
221 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
222};
223
224config_option: T_RANGE symbol symbol if_expr T_EOL
225{
226 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
227 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
228};
229
Eric Andersenc9f20d92002-12-05 08:41:41 +0000230/* choice entry */
231
Eric Andersen72d8e442003-08-05 02:18:25 +0000232choice: T_CHOICE T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000233{
234 struct symbol *sym = sym_lookup(NULL, 0);
235 sym->flags |= SYMBOL_CHOICE;
236 menu_add_entry(sym);
Eric Andersen72d8e442003-08-05 02:18:25 +0000237 menu_add_expr(P_CHOICE, NULL, NULL);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000238 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
239};
240
Eric Andersen72d8e442003-08-05 02:18:25 +0000241choice_entry: choice choice_option_list
Eric Andersenc9f20d92002-12-05 08:41:41 +0000242{
243 menu_end_entry();
244 menu_add_menu();
245};
246
247choice_end: end
248{
249 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
250 menu_end_menu();
251 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
252 }
253};
254
255choice_stmt:
Eric Andersen72d8e442003-08-05 02:18:25 +0000256 choice_entry choice_block choice_end
Eric Andersenc9f20d92002-12-05 08:41:41 +0000257 | choice_entry choice_block
258{
259 printf("%s:%d: missing 'endchoice' for this 'choice' statement\n", current_menu->file->name, current_menu->lineno);
260 zconfnerrs++;
261};
262
263choice_option_list:
264 /* empty */
Eric Andersen72d8e442003-08-05 02:18:25 +0000265 | choice_option_list choice_option
266 | choice_option_list depends
Eric Andersenc9f20d92002-12-05 08:41:41 +0000267 | choice_option_list help
268 | choice_option_list T_EOL
269;
270
Eric Andersen72d8e442003-08-05 02:18:25 +0000271choice_option: T_PROMPT prompt if_expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000272{
Eric Andersen72d8e442003-08-05 02:18:25 +0000273 menu_add_prompt(P_PROMPT, $2, $3);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000274 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
275};
276
Eric Andersen72d8e442003-08-05 02:18:25 +0000277choice_option: T_TRISTATE prompt_stmt_opt T_EOL
278{
279 menu_set_type(S_TRISTATE);
280 printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno());
281};
282
283choice_option: T_BOOLEAN prompt_stmt_opt T_EOL
284{
285 menu_set_type(S_BOOLEAN);
286 printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno());
287};
288
289choice_option: T_OPTIONAL T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000290{
291 current_entry->sym->flags |= SYMBOL_OPTIONAL;
292 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
293};
294
Eric Andersen72d8e442003-08-05 02:18:25 +0000295choice_option: T_DEFAULT T_WORD if_expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000296{
Eric Andersen72d8e442003-08-05 02:18:25 +0000297 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000298 printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno());
299};
300
301choice_block:
302 /* empty */
303 | choice_block common_block
304;
305
306/* if entry */
307
Eric Andersen72d8e442003-08-05 02:18:25 +0000308if: T_IF expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000309{
310 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
311 menu_add_entry(NULL);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000312 menu_add_dep($2);
313 menu_end_entry();
314 menu_add_menu();
315};
316
317if_end: end
318{
319 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
320 menu_end_menu();
321 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
322 }
323};
324
325if_stmt:
Eric Andersen72d8e442003-08-05 02:18:25 +0000326 if if_block if_end
327 | if if_block
Eric Andersenc9f20d92002-12-05 08:41:41 +0000328{
329 printf("%s:%d: missing 'endif' for this 'if' statement\n", current_menu->file->name, current_menu->lineno);
330 zconfnerrs++;
331};
332
333if_block:
334 /* empty */
335 | if_block common_block
336 | if_block menu_stmt
337 | if_block choice_stmt
338;
339
340/* menu entry */
341
Eric Andersen72d8e442003-08-05 02:18:25 +0000342menu: T_MENU prompt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000343{
344 menu_add_entry(NULL);
345 menu_add_prop(P_MENU, $2, NULL, NULL);
346 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
347};
348
Eric Andersen72d8e442003-08-05 02:18:25 +0000349menu_entry: menu depends_list
Eric Andersenc9f20d92002-12-05 08:41:41 +0000350{
351 menu_end_entry();
352 menu_add_menu();
353};
354
355menu_end: end
356{
357 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
358 menu_end_menu();
359 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
360 }
361};
362
363menu_stmt:
Eric Andersen72d8e442003-08-05 02:18:25 +0000364 menu_entry menu_block menu_end
Eric Andersenc9f20d92002-12-05 08:41:41 +0000365 | menu_entry menu_block
366{
367 printf("%s:%d: missing 'endmenu' for this 'menu' statement\n", current_menu->file->name, current_menu->lineno);
368 zconfnerrs++;
369};
370
371menu_block:
372 /* empty */
373 | menu_block common_block
374 | menu_block menu_stmt
375 | menu_block choice_stmt
376 | menu_block error T_EOL { zconfprint("invalid menu option"); yyerrok; }
377;
378
Eric Andersen72d8e442003-08-05 02:18:25 +0000379source: T_SOURCE prompt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000380{
381 $$ = $2;
382 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
383};
384
Eric Andersen72d8e442003-08-05 02:18:25 +0000385source_stmt: source
Eric Andersenc9f20d92002-12-05 08:41:41 +0000386{
387 zconf_nextfile($1);
388};
389
390/* comment entry */
391
Eric Andersen72d8e442003-08-05 02:18:25 +0000392comment: T_COMMENT prompt T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000393{
394 menu_add_entry(NULL);
395 menu_add_prop(P_COMMENT, $2, NULL, NULL);
396 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
397};
398
Eric Andersen72d8e442003-08-05 02:18:25 +0000399comment_stmt: comment depends_list
Eric Andersenc9f20d92002-12-05 08:41:41 +0000400{
401 menu_end_entry();
402};
403
404/* help option */
405
406help_start: T_HELP T_EOL
407{
408 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
409 zconf_starthelp();
410};
411
412help: help_start T_HELPTEXT
413{
414 current_entry->sym->help = $2;
415};
416
417/* depends option */
418
419depends_list: /* empty */
Eric Andersen72d8e442003-08-05 02:18:25 +0000420 | depends_list depends
Eric Andersenc9f20d92002-12-05 08:41:41 +0000421 | depends_list T_EOL
Eric Andersen72d8e442003-08-05 02:18:25 +0000422;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000423
Eric Andersen72d8e442003-08-05 02:18:25 +0000424depends: T_DEPENDS T_ON expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000425{
426 menu_add_dep($3);
427 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
428}
Eric Andersen72d8e442003-08-05 02:18:25 +0000429 | T_DEPENDS expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000430{
431 menu_add_dep($2);
432 printd(DEBUG_PARSE, "%s:%d:depends\n", zconf_curname(), zconf_lineno());
433}
Eric Andersen72d8e442003-08-05 02:18:25 +0000434 | T_REQUIRES expr T_EOL
Eric Andersenc9f20d92002-12-05 08:41:41 +0000435{
436 menu_add_dep($2);
437 printd(DEBUG_PARSE, "%s:%d:requires\n", zconf_curname(), zconf_lineno());
438};
439
440/* prompt statement */
441
442prompt_stmt_opt:
443 /* empty */
Eric Andersen72d8e442003-08-05 02:18:25 +0000444 | prompt if_expr
Eric Andersenc9f20d92002-12-05 08:41:41 +0000445{
Eric Andersen72d8e442003-08-05 02:18:25 +0000446 menu_add_prop(P_PROMPT, $1, NULL, $2);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000447};
448
449prompt: T_WORD
Eric Andersen72d8e442003-08-05 02:18:25 +0000450 | T_WORD_QUOTE
Eric Andersenc9f20d92002-12-05 08:41:41 +0000451;
452
Eric Andersen72d8e442003-08-05 02:18:25 +0000453end: T_ENDMENU nl_or_eof { $$ = T_ENDMENU; }
454 | T_ENDCHOICE nl_or_eof { $$ = T_ENDCHOICE; }
455 | T_ENDIF nl_or_eof { $$ = T_ENDIF; }
Eric Andersenc9f20d92002-12-05 08:41:41 +0000456;
457
458nl_or_eof:
459 T_EOL | T_EOF;
460
461if_expr: /* empty */ { $$ = NULL; }
462 | T_IF expr { $$ = $2; }
463;
464
465expr: symbol { $$ = expr_alloc_symbol($1); }
466 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
467 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
468 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
469 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
470 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
471 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
472;
473
474symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
Eric Andersen72d8e442003-08-05 02:18:25 +0000475 | T_WORD_QUOTE { $$ = sym_lookup($1, 1); free($1); }
Eric Andersenc9f20d92002-12-05 08:41:41 +0000476;
477
478%%
479
480void conf_parse(const char *name)
481{
Eric Andersen72d8e442003-08-05 02:18:25 +0000482 struct symbol *sym;
483 int i;
484
Eric Andersenc9f20d92002-12-05 08:41:41 +0000485 zconf_initscan(name);
486
487 sym_init();
488 menu_init();
Eric Andersen72d8e442003-08-05 02:18:25 +0000489 modules_sym = sym_lookup("MODULES", 0);
Eric Andersen70014802003-08-05 05:59:48 +0000490 rootmenu.prompt = menu_add_prop(P_MENU, "BusyBox Configuration", NULL, NULL);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000491
492 //zconfdebug = 1;
493 zconfparse();
494 if (zconfnerrs)
495 exit(1);
496 menu_finalize(&rootmenu);
Eric Andersen72d8e442003-08-05 02:18:25 +0000497 for_all_symbols(i, sym) {
498 if (!(sym->flags & SYMBOL_CHECKED) && sym_check_deps(sym))
499 printf("\n");
500 else
501 sym->flags |= SYMBOL_CHECK_DONE;
502 }
Eric Andersenc9f20d92002-12-05 08:41:41 +0000503
504 sym_change_count = 1;
505}
506
507const char *zconf_tokenname(int token)
508{
509 switch (token) {
510 case T_MENU: return "menu";
511 case T_ENDMENU: return "endmenu";
512 case T_CHOICE: return "choice";
513 case T_ENDCHOICE: return "endchoice";
514 case T_IF: return "if";
515 case T_ENDIF: return "endif";
516 }
517 return "<token>";
Eric Andersen72d8e442003-08-05 02:18:25 +0000518}
Eric Andersenc9f20d92002-12-05 08:41:41 +0000519
520static bool zconf_endtoken(int token, int starttoken, int endtoken)
521{
522 if (token != endtoken) {
523 zconfprint("unexpected '%s' within %s block", zconf_tokenname(token), zconf_tokenname(starttoken));
524 zconfnerrs++;
525 return false;
526 }
527 if (current_menu->file != current_file) {
528 zconfprint("'%s' in different file than '%s'", zconf_tokenname(token), zconf_tokenname(starttoken));
529 zconfprint("location of the '%s'", zconf_tokenname(starttoken));
530 zconfnerrs++;
531 return false;
532 }
533 return true;
534}
535
536static void zconfprint(const char *err, ...)
537{
538 va_list ap;
539
Eric Andersen72d8e442003-08-05 02:18:25 +0000540 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno() + 1);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000541 va_start(ap, err);
542 vfprintf(stderr, err, ap);
543 va_end(ap);
544 fprintf(stderr, "\n");
545}
546
547static void zconferror(const char *err)
548{
Eric Andersen72d8e442003-08-05 02:18:25 +0000549 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000550}
551
552void print_quoted_string(FILE *out, const char *str)
553{
554 const char *p;
555 int len;
556
557 putc('"', out);
558 while ((p = strchr(str, '"'))) {
559 len = p - str;
560 if (len)
561 fprintf(out, "%.*s", len, str);
562 fputs("\\\"", out);
563 str = p + 1;
564 }
565 fputs(str, out);
566 putc('"', out);
567}
568
569void print_symbol(FILE *out, struct menu *menu)
570{
571 struct symbol *sym = menu->sym;
572 struct property *prop;
573
Eric Andersenc9f20d92002-12-05 08:41:41 +0000574 if (sym_is_choice(sym))
575 fprintf(out, "choice\n");
576 else
577 fprintf(out, "config %s\n", sym->name);
578 switch (sym->type) {
579 case S_BOOLEAN:
580 fputs(" boolean\n", out);
581 break;
582 case S_TRISTATE:
583 fputs(" tristate\n", out);
584 break;
585 case S_STRING:
586 fputs(" string\n", out);
587 break;
588 case S_INT:
589 fputs(" integer\n", out);
590 break;
591 case S_HEX:
592 fputs(" hex\n", out);
593 break;
594 default:
595 fputs(" ???\n", out);
596 break;
597 }
Eric Andersenc9f20d92002-12-05 08:41:41 +0000598 for (prop = sym->prop; prop; prop = prop->next) {
599 if (prop->menu != menu)
600 continue;
601 switch (prop->type) {
602 case P_PROMPT:
603 fputs(" prompt ", out);
604 print_quoted_string(out, prop->text);
Eric Andersen72d8e442003-08-05 02:18:25 +0000605 if (!expr_is_yes(prop->visible.expr)) {
Eric Andersenc9f20d92002-12-05 08:41:41 +0000606 fputs(" if ", out);
Eric Andersen72d8e442003-08-05 02:18:25 +0000607 expr_fprint(prop->visible.expr, out);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000608 }
609 fputc('\n', out);
610 break;
611 case P_DEFAULT:
612 fputs( " default ", out);
Eric Andersen72d8e442003-08-05 02:18:25 +0000613 expr_fprint(prop->expr, out);
614 if (!expr_is_yes(prop->visible.expr)) {
Eric Andersenc9f20d92002-12-05 08:41:41 +0000615 fputs(" if ", out);
Eric Andersen72d8e442003-08-05 02:18:25 +0000616 expr_fprint(prop->visible.expr, out);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000617 }
618 fputc('\n', out);
619 break;
620 case P_CHOICE:
621 fputs(" #choice value\n", out);
622 break;
623 default:
624 fprintf(out, " unknown prop %d!\n", prop->type);
625 break;
626 }
627 }
628 if (sym->help) {
629 int len = strlen(sym->help);
630 while (sym->help[--len] == '\n')
631 sym->help[len] = 0;
632 fprintf(out, " help\n%s\n", sym->help);
633 }
634 fputc('\n', out);
635}
636
637void zconfdump(FILE *out)
638{
Eric Andersenc9f20d92002-12-05 08:41:41 +0000639 struct property *prop;
640 struct symbol *sym;
641 struct menu *menu;
642
643 menu = rootmenu.list;
644 while (menu) {
645 if ((sym = menu->sym))
646 print_symbol(out, menu);
647 else if ((prop = menu->prompt)) {
648 switch (prop->type) {
Eric Andersenc9f20d92002-12-05 08:41:41 +0000649 case P_COMMENT:
650 fputs("\ncomment ", out);
651 print_quoted_string(out, prop->text);
652 fputs("\n", out);
653 break;
654 case P_MENU:
655 fputs("\nmenu ", out);
656 print_quoted_string(out, prop->text);
657 fputs("\n", out);
658 break;
Eric Andersenc9f20d92002-12-05 08:41:41 +0000659 default:
660 ;
661 }
Eric Andersen72d8e442003-08-05 02:18:25 +0000662 if (!expr_is_yes(prop->visible.expr)) {
Eric Andersenc9f20d92002-12-05 08:41:41 +0000663 fputs(" depends ", out);
Eric Andersen72d8e442003-08-05 02:18:25 +0000664 expr_fprint(prop->visible.expr, out);
Eric Andersenc9f20d92002-12-05 08:41:41 +0000665 fputc('\n', out);
666 }
667 fputs("\n", out);
668 }
669
670 if (menu->list)
671 menu = menu->list;
672 else if (menu->next)
673 menu = menu->next;
674 else while ((menu = menu->parent)) {
675 if (menu->prompt && menu->prompt->type == P_MENU)
676 fputs("\nendmenu\n", out);
677 if (menu->next) {
678 menu = menu->next;
679 break;
680 }
681 }
682 }
683}
684
685#include "lex.zconf.c"
Peter Kjellerstedtbae38db2005-04-19 09:55:06 +0000686#include "util.c"
Eric Andersenc9f20d92002-12-05 08:41:41 +0000687#include "confdata.c"
688#include "expr.c"
689#include "symbol.c"
690#include "menu.c"