3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
16 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
19 #define DEBUG_PARSE 0x0002
24 static void yyerror(const char *err
);
25 static void zconfprint
(const char *err
, ...
);
26 static void zconf_error
(const char *err
, ...
);
27 static bool zconf_endtoken
(const struct kconf_id
*id
, int starttoken
, int endtoken
);
29 struct symbol
*symbol_hash
[SYMBOL_HASHSIZE
];
31 static struct menu
*current_menu
, *current_entry
;
40 struct symbol
*symbol
;
43 const struct kconf_id
*id
;
51 %token
<id
>T_ENDCHOICE
54 %token
<id
>T_MENUCONFIG
56 %token
<string> T_HELPTEXT
70 %token
<string> T_WORD
71 %token
<string> T_WORD_QUOTE
76 %token T_GREATER_EQUAL
83 %left T_EQUAL T_UNEQUAL
84 %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
88 %type
<symbol
> nonconst_symbol
93 %type
<id
> option_name
94 %type
<menu
> if_entry menu_entry choice_entry
95 %type
<string> symbol_option_arg word_opt
98 fprintf
(stderr
, "%s:%d: missing end statement for this entry\n",
99 $$
->file
->name
, $$
->lineno
);
100 if
(current_menu
== $$
)
102 } if_entry menu_entry choice_entry
105 /* Include kconf_id.c here so it can see the token constants. */
106 #include "kconf_id.c"
110 input: nl start | start
;
112 start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list
;
116 mainmenu_stmt: T_MAINMENU prompt nl
118 menu_add_prompt
(P_MENU
, $2, NULL
);
121 /* Default main menu, if there's no mainmenu entry */
123 no_mainmenu_stmt: /* empty */
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
130 menu_add_prompt
(P_MENU
, strdup
("Linux Kernel Configuration"), NULL
);
136 | stmt_list common_stmt
137 | stmt_list choice_stmt
138 | stmt_list menu_stmt
139 | 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
143 zconf_error
("unexpected option \"%s\"", $2->name
);
145 | stmt_list
error T_EOL
{ zconf_error
("invalid statement"); }
149 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
162 T_WORD
error T_EOL
{ zconf_error
("unknown option \"%s\"", $1); }
163 |
error T_EOL
{ zconf_error
("invalid option"); }
167 /* config/menuconfig entry */
169 config_entry_start: T_CONFIG nonconst_symbol T_EOL
171 $2->flags |
= SYMBOL_OPTIONAL
;
173 printd
(DEBUG_PARSE
, "%s:%d:config %s\n", zconf_curname
(), zconf_lineno
(), $2->name
);
176 config_stmt: config_entry_start config_option_list
178 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
181 menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
183 $2->flags |
= SYMBOL_OPTIONAL
;
185 printd
(DEBUG_PARSE
, "%s:%d:menuconfig %s\n", zconf_curname
(), zconf_lineno
(), $2->name
);
188 menuconfig_stmt: menuconfig_entry_start config_option_list
190 if
(current_entry
->prompt
)
191 current_entry
->prompt
->type
= P_MENU
;
193 zconfprint
("warning: menuconfig statement without prompt");
194 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
199 | config_option_list config_option
200 | config_option_list symbol_option
201 | config_option_list depends
202 | config_option_list help
203 | config_option_list option_error
204 | config_option_list T_EOL
207 config_option: T_TYPE prompt_stmt_opt T_EOL
209 menu_set_type
($1->stype
);
210 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
211 zconf_curname
(), zconf_lineno
(),
215 config_option: T_PROMPT prompt if_expr T_EOL
217 menu_add_prompt
(P_PROMPT
, $2, $3);
218 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
221 config_option: T_DEFAULT expr if_expr T_EOL
223 menu_add_expr
(P_DEFAULT
, $2, $3);
224 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
(),
231 config_option: T_SELECT nonconst_symbol if_expr T_EOL
233 menu_add_symbol
(P_SELECT
, $2, $3);
234 printd
(DEBUG_PARSE
, "%s:%d:select\n", zconf_curname
(), zconf_lineno
());
237 config_option: T_IMPLY nonconst_symbol if_expr T_EOL
239 menu_add_symbol
(P_IMPLY
, $2, $3);
240 printd
(DEBUG_PARSE
, "%s:%d:imply\n", zconf_curname
(), zconf_lineno
());
243 config_option: T_RANGE symbol symbol if_expr T_EOL
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
());
249 symbol_option: T_OPTION symbol_option_list T_EOL
254 | symbol_option_list T_WORD symbol_option_arg
256 const struct kconf_id
*id
= kconf_id_lookup
($2, strlen
($2));
257 if
(id
&& id
->flags
& TF_OPTION
) {
258 menu_add_option
(id
->token
, $3);
262 zconfprint
("warning: ignoring unknown option %s", $2);
267 /* empty */ { $$
= NULL
; }
268 | T_EQUAL prompt
{ $$
= $2; }
273 choice: T_CHOICE word_opt T_EOL
275 struct symbol
*sym
= sym_lookup
($2, SYMBOL_CHOICE
);
276 sym
->flags |
= SYMBOL_AUTO
;
278 menu_add_expr
(P_CHOICE
, NULL
, NULL
);
279 printd
(DEBUG_PARSE
, "%s:%d:choice\n", zconf_curname
(), zconf_lineno
());
282 choice_entry: choice choice_option_list
284 $$
= menu_add_menu
();
289 if
(zconf_endtoken
($1, T_CHOICE
, T_ENDCHOICE
)) {
291 printd
(DEBUG_PARSE
, "%s:%d:endchoice\n", zconf_curname
(), zconf_lineno
());
295 choice_stmt: choice_entry choice_block choice_end
300 | choice_option_list choice_option
301 | choice_option_list depends
302 | choice_option_list help
303 | choice_option_list T_EOL
304 | choice_option_list option_error
307 choice_option: T_PROMPT prompt if_expr T_EOL
309 menu_add_prompt
(P_PROMPT
, $2, $3);
310 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
313 choice_option: T_TYPE prompt_stmt_opt T_EOL
315 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
(),
324 choice_option: T_OPTIONAL T_EOL
326 current_entry
->sym
->flags |
= SYMBOL_OPTIONAL
;
327 printd
(DEBUG_PARSE
, "%s:%d:optional\n", zconf_curname
(), zconf_lineno
());
330 choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
332 if
($1->stype
== S_UNKNOWN
) {
333 menu_add_symbol
(P_DEFAULT
, $2, $3);
334 printd
(DEBUG_PARSE
, "%s:%d:default\n",
335 zconf_curname
(), zconf_lineno
());
342 | choice_block common_stmt
347 if_entry: T_IF expr nl
349 printd
(DEBUG_PARSE
, "%s:%d:if\n", zconf_curname
(), zconf_lineno
());
350 menu_add_entry
(NULL
);
352 $$
= menu_add_menu
();
357 if
(zconf_endtoken
($1, T_IF
, T_ENDIF
)) {
359 printd
(DEBUG_PARSE
, "%s:%d:endif\n", zconf_curname
(), zconf_lineno
());
363 if_stmt: if_entry if_block if_end
368 | if_block common_stmt
370 | if_block choice_stmt
375 menu: T_MENU prompt T_EOL
377 menu_add_entry
(NULL
);
378 menu_add_prompt
(P_MENU
, $2, NULL
);
379 printd
(DEBUG_PARSE
, "%s:%d:menu\n", zconf_curname
(), zconf_lineno
());
382 menu_entry: menu visibility_list depends_list
384 $$
= menu_add_menu
();
389 if
(zconf_endtoken
($1, T_MENU
, T_ENDMENU
)) {
391 printd
(DEBUG_PARSE
, "%s:%d:endmenu\n", zconf_curname
(), zconf_lineno
());
395 menu_stmt: menu_entry menu_block menu_end
400 | menu_block common_stmt
401 | menu_block menu_stmt
402 | menu_block choice_stmt
405 source_stmt: T_SOURCE prompt T_EOL
407 printd
(DEBUG_PARSE
, "%s:%d:source %s\n", zconf_curname
(), zconf_lineno
(), $2);
414 comment: T_COMMENT prompt T_EOL
416 menu_add_entry
(NULL
);
417 menu_add_prompt
(P_COMMENT
, $2, NULL
);
418 printd
(DEBUG_PARSE
, "%s:%d:comment\n", zconf_curname
(), zconf_lineno
());
421 comment_stmt: comment depends_list
426 help_start: T_HELP T_EOL
428 printd
(DEBUG_PARSE
, "%s:%d:help\n", zconf_curname
(), zconf_lineno
());
432 help: help_start T_HELPTEXT
434 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>");
440 /* Is the help text empty or all whitespace? */
441 if
($2[strspn
($2, " \f\n\r\t\v")] == '\0')
442 zconfprint
("warning: '%s' defined with blank help text",
443 current_entry
->sym
->name ?
: "<choice>");
445 current_entry
->help
= $2;
452 | depends_list depends
454 | depends_list option_error
457 depends: T_DEPENDS T_ON expr T_EOL
460 printd
(DEBUG_PARSE
, "%s:%d:depends on\n", zconf_curname
(), zconf_lineno
());
463 /* visibility option */
467 | visibility_list visible
468 | visibility_list T_EOL
471 visible: T_VISIBLE if_expr
473 menu_add_visibility
($2);
476 /* prompt statement */
482 menu_add_prompt
(P_PROMPT
, $1, $2);
489 end: T_ENDMENU T_EOL
{ $$
= $1; }
490 | T_ENDCHOICE T_EOL
{ $$
= $1; }
491 | T_ENDIF T_EOL
{ $$
= $1; }
499 if_expr: /* empty */ { $$
= NULL
; }
500 | T_IF expr
{ $$
= $2; }
503 expr: symbol
{ $$
= expr_alloc_symbol
($1); }
504 | symbol T_LESS symbol
{ $$
= expr_alloc_comp
(E_LTH
, $1, $3); }
505 | symbol T_LESS_EQUAL symbol
{ $$
= expr_alloc_comp
(E_LEQ
, $1, $3); }
506 | symbol T_GREATER symbol
{ $$
= expr_alloc_comp
(E_GTH
, $1, $3); }
507 | symbol T_GREATER_EQUAL symbol
{ $$
= expr_alloc_comp
(E_GEQ
, $1, $3); }
508 | symbol T_EQUAL symbol
{ $$
= expr_alloc_comp
(E_EQUAL
, $1, $3); }
509 | symbol T_UNEQUAL symbol
{ $$
= expr_alloc_comp
(E_UNEQUAL
, $1, $3); }
510 | T_OPEN_PAREN expr T_CLOSE_PAREN
{ $$
= $2; }
511 | T_NOT expr
{ $$
= expr_alloc_one
(E_NOT
, $2); }
512 | expr T_OR expr
{ $$
= expr_alloc_two
(E_OR
, $1, $3); }
513 | expr T_AND expr
{ $$
= expr_alloc_two
(E_AND
, $1, $3); }
516 /* For symbol definitions, selects, etc., where quotes are not accepted */
517 nonconst_symbol: T_WORD
{ $$
= sym_lookup
($1, 0); free
($1); };
519 symbol: nonconst_symbol
520 | T_WORD_QUOTE
{ $$
= sym_lookup
($1, SYMBOL_CONST
); free
($1); }
523 word_opt: /* empty */ { $$
= NULL
; }
528 void conf_parse
(const char *name
)
534 zconf_initscan
(name
);
539 if
(getenv
("ZCONF_DEBUG"))
545 modules_sym
= sym_find
( "n" );
547 tmp
= rootmenu.prompt
->text
;
548 rootmenu.prompt
->text
= _
(rootmenu.prompt
->text
);
549 rootmenu.prompt
->text
= sym_expand_string_value
(rootmenu.prompt
->text
);
552 menu_finalize
(&rootmenu
);
553 for_all_symbols
(i
, sym
) {
554 if
(sym_check_deps
(sym
))
559 sym_set_change_count
(1);
562 static const char *zconf_tokenname
(int token
)
565 case T_MENU
: return
"menu";
566 case T_ENDMENU
: return
"endmenu";
567 case T_CHOICE
: return
"choice";
568 case T_ENDCHOICE
: return
"endchoice";
569 case T_IF
: return
"if";
570 case T_ENDIF
: return
"endif";
571 case T_DEPENDS
: return
"depends";
572 case T_VISIBLE
: return
"visible";
577 static bool zconf_endtoken
(const struct kconf_id
*id
, int starttoken
, int endtoken
)
579 if
(id
->token
!= endtoken
) {
580 zconf_error
("unexpected '%s' within %s block",
581 id
->name
, zconf_tokenname
(starttoken
));
585 if
(current_menu
->file
!= current_file
) {
586 zconf_error
("'%s' in different file than '%s'",
587 id
->name
, zconf_tokenname
(starttoken
));
588 fprintf
(stderr
, "%s:%d: location of the '%s'\n",
589 current_menu
->file
->name
, current_menu
->lineno
,
590 zconf_tokenname
(starttoken
));
597 static void zconfprint
(const char *err
, ...
)
601 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
603 vfprintf
(stderr
, err
, ap
);
605 fprintf
(stderr
, "\n");
608 static void zconf_error
(const char *err
, ...
)
613 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
615 vfprintf
(stderr
, err
, ap
);
617 fprintf
(stderr
, "\n");
620 static void yyerror(const char *err
)
622 fprintf
(stderr
, "%s:%d: %s\n", zconf_curname
(), zconf_lineno
() + 1, err
);
625 static void print_quoted_string
(FILE *out
, const char *str
)
631 while
((p
= strchr
(str
, '"'))) {
634 fprintf
(out
, "%.*s", len
, str
);
642 static void print_symbol
(FILE *out
, struct menu
*menu
)
644 struct symbol
*sym
= menu
->sym
;
645 struct property
*prop
;
647 if
(sym_is_choice
(sym
))
648 fprintf
(out
, "\nchoice\n");
650 fprintf
(out
, "\nconfig %s\n", sym
->name
);
653 fputs
(" bool\n", out
);
656 fputs
(" tristate\n", out
);
659 fputs
(" string\n", out
);
662 fputs
(" integer\n", out
);
665 fputs
(" hex\n", out
);
668 fputs
(" ???\n", out
);
671 for
(prop
= sym
->prop
; prop
; prop
= prop
->next
) {
672 if
(prop
->menu
!= menu
)
674 switch
(prop
->type
) {
676 fputs
(" prompt ", out
);
677 print_quoted_string
(out
, prop
->text
);
678 if
(!expr_is_yes
(prop
->visible.expr
)) {
680 expr_fprint
(prop
->visible.expr
, out
);
685 fputs
( " default ", out
);
686 expr_fprint
(prop
->expr
, out
);
687 if
(!expr_is_yes
(prop
->visible.expr
)) {
689 expr_fprint
(prop
->visible.expr
, out
);
694 fputs
(" #choice value\n", out
);
697 fputs
( " select ", out
);
698 expr_fprint
(prop
->expr
, out
);
702 fputs
( " imply ", out
);
703 expr_fprint
(prop
->expr
, out
);
707 fputs
( " range ", out
);
708 expr_fprint
(prop
->expr
, out
);
712 fputs
( " menu ", out
);
713 print_quoted_string
(out
, prop
->text
);
717 fprintf
(out
, " unknown prop %d!\n", prop
->type
);
722 int len
= strlen
(menu
->help
);
723 while
(menu
->help
[--len
] == '\n')
725 fprintf
(out
, " help\n%s\n", menu
->help
);
729 void zconfdump
(FILE *out
)
731 struct property
*prop
;
735 menu
= rootmenu.list
;
737 if
((sym
= menu
->sym
))
738 print_symbol
(out
, menu
);
739 else if
((prop
= menu
->prompt
)) {
740 switch
(prop
->type
) {
742 fputs
("\ncomment ", out
);
743 print_quoted_string
(out
, prop
->text
);
747 fputs
("\nmenu ", out
);
748 print_quoted_string
(out
, prop
->text
);
754 if
(!expr_is_yes
(prop
->visible.expr
)) {
755 fputs
(" depends ", out
);
756 expr_fprint
(prop
->visible.expr
, out
);
765 else while
((menu
= menu
->parent
)) {
766 if
(menu
->prompt
&& menu
->prompt
->type
== P_MENU
)
767 fputs
("\nendmenu\n", out
);
776 #include "zconf.lex.c"
778 #include "confdata.c"