3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
14 #define LKC_DIRECT_LINK
17 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
20 #define DEBUG_PARSE 0x0002
24 extern int zconflex(void);
25 static void zconfprint(const char *err, ...);
26 static void zconf_error(const char *err, ...);
27 static void zconferror(const char *err);
28 static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken);
30 struct symbol *symbol_hash[257];
32 static struct menu *current_menu, *current_entry;
36 #define YYERROR_VERBOSE
45 struct symbol *symbol;
56 %token <id>T_ENDCHOICE
59 %token <id>T_MENUCONFIG
61 %token <string> T_HELPTEXT
73 %token <string> T_WORD
74 %token <string> T_WORD_QUOTE
82 %left T_EQUAL T_UNEQUAL
90 %type <id> option_name
91 %type <menu> if_entry menu_entry choice_entry
92 %type <string> symbol_option_arg word_opt
95 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
96 $$->file->name, $$->lineno);
97 if (current_menu == $$)
99 } if_entry menu_entry choice_entry
102 /* Include zconf.hash.c here so it can see the token constants. */
103 #include "zconf.hash.c"
111 | stmt_list common_stmt
112 | stmt_list choice_stmt
113 | stmt_list menu_stmt
114 | stmt_list T_MAINMENU prompt nl
115 | stmt_list end { zconf_error("unexpected end statement"); }
116 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
117 | stmt_list option_name error T_EOL
119 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
121 | stmt_list error T_EOL { zconf_error("invalid statement"); }
125 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT
138 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
139 | error T_EOL { zconf_error("invalid option"); }
143 /* config/menuconfig entry */
145 config_entry_start: T_CONFIG T_WORD T_EOL
147 struct symbol *sym = sym_lookup($2, 0);
148 sym->flags |= SYMBOL_OPTIONAL;
150 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
153 config_stmt: config_entry_start config_option_list
156 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
159 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
161 struct symbol *sym = sym_lookup($2, 0);
162 sym->flags |= SYMBOL_OPTIONAL;
164 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
167 menuconfig_stmt: menuconfig_entry_start config_option_list
169 if (current_entry->prompt)
170 current_entry->prompt->type = P_MENU;
172 zconfprint("warning: menuconfig statement without prompt");
174 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
179 | config_option_list config_option
180 | config_option_list symbol_option
181 | config_option_list depends
182 | config_option_list help
183 | config_option_list option_error
184 | config_option_list T_EOL
187 config_option: T_TYPE prompt_stmt_opt T_EOL
189 menu_set_type($1->stype);
190 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
191 zconf_curname(), zconf_lineno(),
195 config_option: T_PROMPT prompt if_expr T_EOL
197 menu_add_prompt(P_PROMPT, $2, $3);
198 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
201 config_option: T_DEFAULT expr if_expr T_EOL
203 menu_add_expr(P_DEFAULT, $2, $3);
204 if ($1->stype != S_UNKNOWN)
205 menu_set_type($1->stype);
206 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
207 zconf_curname(), zconf_lineno(),
211 config_option: T_SELECT T_WORD if_expr T_EOL
213 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
214 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
217 config_option: T_RANGE symbol symbol if_expr T_EOL
219 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
220 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
223 symbol_option: T_OPTION symbol_option_list T_EOL
228 | symbol_option_list T_WORD symbol_option_arg
230 struct kconf_id *id = kconf_id_lookup($2, strlen($2));
231 if (id && id->flags & TF_OPTION)
232 menu_add_option(id->token, $3);
234 zconfprint("warning: ignoring unknown option %s", $2);
239 /* empty */ { $$ = NULL; }
240 | T_EQUAL prompt { $$ = $2; }
245 choice: T_CHOICE word_opt T_EOL
247 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
248 sym->flags |= SYMBOL_AUTO;
250 menu_add_expr(P_CHOICE, NULL, NULL);
251 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
254 choice_entry: choice choice_option_list
256 $$ = menu_add_menu();
261 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
263 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
267 choice_stmt: choice_entry choice_block choice_end
272 | choice_option_list choice_option
273 | choice_option_list depends
274 | choice_option_list help
275 | choice_option_list T_EOL
276 | choice_option_list option_error
279 choice_option: T_PROMPT prompt if_expr T_EOL
281 menu_add_prompt(P_PROMPT, $2, $3);
282 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
285 choice_option: T_TYPE prompt_stmt_opt T_EOL
287 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
288 menu_set_type($1->stype);
289 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
290 zconf_curname(), zconf_lineno(),
296 choice_option: T_OPTIONAL T_EOL
298 current_entry->sym->flags |= SYMBOL_OPTIONAL;
299 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
302 choice_option: T_DEFAULT T_WORD if_expr T_EOL
304 if ($1->stype == S_UNKNOWN) {
305 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
306 printd(DEBUG_PARSE, "%s:%d:default\n",
307 zconf_curname(), zconf_lineno());
314 | choice_block common_stmt
319 if_entry: T_IF expr nl
321 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
322 menu_add_entry(NULL);
324 $$ = menu_add_menu();
329 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
331 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
335 if_stmt: if_entry if_block if_end
340 | if_block common_stmt
342 | if_block choice_stmt
347 menu: T_MENU prompt T_EOL
349 menu_add_entry(NULL);
350 menu_add_prompt(P_MENU, $2, NULL);
351 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
354 menu_entry: menu depends_list
356 $$ = menu_add_menu();
361 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
363 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
367 menu_stmt: menu_entry menu_block menu_end
372 | menu_block common_stmt
373 | menu_block menu_stmt
374 | menu_block choice_stmt
377 source_stmt: T_SOURCE prompt T_EOL
379 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
385 comment: T_COMMENT prompt T_EOL
387 menu_add_entry(NULL);
388 menu_add_prompt(P_COMMENT, $2, NULL);
389 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
392 comment_stmt: comment depends_list
399 help_start: T_HELP T_EOL
401 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
405 help: help_start T_HELPTEXT
407 current_entry->help = $2;
414 | depends_list depends
416 | depends_list option_error
419 depends: T_DEPENDS T_ON expr T_EOL
422 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
425 /* prompt statement */
431 menu_add_prompt(P_PROMPT, $1, $2);
438 end: T_ENDMENU T_EOL { $$ = $1; }
439 | T_ENDCHOICE T_EOL { $$ = $1; }
440 | T_ENDIF T_EOL { $$ = $1; }
448 if_expr: /* empty */ { $$ = NULL; }
449 | T_IF expr { $$ = $2; }
452 expr: symbol { $$ = expr_alloc_symbol($1); }
453 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
454 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
455 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
456 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
457 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
458 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
461 symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
462 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
465 word_opt: /* empty */ { $$ = NULL; }
470 void conf_parse(const char *name)
475 zconf_initscan(name);
479 modules_sym = sym_lookup(NULL, 0);
480 modules_sym->type = S_BOOLEAN;
481 modules_sym->flags |= SYMBOL_AUTO;
482 rootmenu.prompt = menu_add_prompt(P_MENU, "CARL9170 Firmware Configuration", NULL);
485 if (getenv("ZCONF_DEBUG"))
491 if (!modules_sym->prop) {
492 struct property *prop;
494 prop = prop_alloc(P_DEFAULT, modules_sym);
495 prop->expr = expr_alloc_symbol(sym_lookup("MODULES", 0));
497 menu_finalize(&rootmenu);
498 for_all_symbols(i, sym) {
499 if (sym_check_deps(sym))
504 sym_set_change_count(1);
507 static const char *zconf_tokenname(int 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 case T_DEPENDS: return "depends";
521 static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken)
523 if (id->token != endtoken) {
524 zconf_error("unexpected '%s' within %s block",
525 kconf_id_strings + id->name, zconf_tokenname(starttoken));
529 if (current_menu->file != current_file) {
530 zconf_error("'%s' in different file than '%s'",
531 kconf_id_strings + id->name, zconf_tokenname(starttoken));
532 fprintf(stderr, "%s:%d: location of the '%s'\n",
533 current_menu->file->name, current_menu->lineno,
534 zconf_tokenname(starttoken));
541 static void zconfprint(const char *err, ...)
545 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
547 vfprintf(stderr, err, ap);
549 fprintf(stderr, "\n");
552 static void zconf_error(const char *err, ...)
557 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
559 vfprintf(stderr, err, ap);
561 fprintf(stderr, "\n");
564 static void zconferror(const char *err)
567 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
571 static void print_quoted_string(FILE *out, const char *str)
577 while ((p = strchr(str, '"'))) {
580 fprintf(out, "%.*s", len, str);
588 static void print_symbol(FILE *out, struct menu *menu)
590 struct symbol *sym = menu->sym;
591 struct property *prop;
593 if (sym_is_choice(sym))
594 fprintf(out, "choice\n");
596 fprintf(out, "config %s\n", sym->name);
599 fputs(" boolean\n", out);
602 fputs(" tristate\n", out);
605 fputs(" string\n", out);
608 fputs(" integer\n", out);
611 fputs(" hex\n", out);
614 fputs(" ???\n", out);
617 for (prop = sym->prop; prop; prop = prop->next) {
618 if (prop->menu != menu)
620 switch (prop->type) {
622 fputs(" prompt ", out);
623 print_quoted_string(out, prop->text);
624 if (!expr_is_yes(prop->visible.expr)) {
626 expr_fprint(prop->visible.expr, out);
631 fputs( " default ", out);
632 expr_fprint(prop->expr, out);
633 if (!expr_is_yes(prop->visible.expr)) {
635 expr_fprint(prop->visible.expr, out);
640 fputs(" #choice value\n", out);
643 fprintf(out, " unknown prop %d!\n", prop->type);
648 int len = strlen(menu->help);
649 while (menu->help[--len] == '\n')
651 fprintf(out, " help\n%s\n", menu->help);
656 void zconfdump(FILE *out)
658 struct property *prop;
662 menu = rootmenu.list;
664 if ((sym = menu->sym))
665 print_symbol(out, menu);
666 else if ((prop = menu->prompt)) {
667 switch (prop->type) {
669 fputs("\ncomment ", out);
670 print_quoted_string(out, prop->text);
674 fputs("\nmenu ", out);
675 print_quoted_string(out, prop->text);
681 if (!expr_is_yes(prop->visible.expr)) {
682 fputs(" depends ", out);
683 expr_fprint(prop->visible.expr, out);
693 else while ((menu = menu->parent)) {
694 if (menu->prompt && menu->prompt->type == P_MENU)
695 fputs("\nendmenu\n", out);
704 #include "lex.zconf.c"
706 #include "confdata.c"