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
23 extern
int zconflex
(void);
24 static void zconfprint
(const char *err
, ...
);
25 static void zconf_error
(const char *err
, ...
);
26 static void zconferror
(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
92 %type
<id
> option_name
93 %type
<menu
> if_entry menu_entry choice_entry
94 %type
<string> symbol_option_arg word_opt
97 fprintf
(stderr
, "%s:%d: missing end statement for this entry\n",
98 $$
->file
->name
, $$
->lineno
);
99 if
(current_menu
== $$
)
101 } if_entry menu_entry choice_entry
104 /* Include zconf.hash.c here so it can see the token constants. */
105 #include "zconf.hash.c"
109 input: nl start | start
;
111 start: mainmenu_stmt stmt_list | stmt_list
;
115 | stmt_list common_stmt
116 | stmt_list choice_stmt
117 | stmt_list menu_stmt
118 | stmt_list end
{ zconf_error
("unexpected end statement"); }
119 | stmt_list T_WORD
error T_EOL
{ zconf_error
("unknown statement \"%s\"", $2); }
120 | stmt_list option_name
error T_EOL
122 zconf_error
("unexpected option \"%s\"", kconf_id_strings
+ $2->name
);
124 | stmt_list
error T_EOL
{ zconf_error
("invalid statement"); }
128 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
141 T_WORD
error T_EOL
{ zconf_error
("unknown option \"%s\"", $1); }
142 |
error T_EOL
{ zconf_error
("invalid option"); }
146 /* config/menuconfig entry */
148 config_entry_start: T_CONFIG T_WORD T_EOL
150 struct symbol
*sym
= sym_lookup
($2, 0);
151 sym
->flags |
= SYMBOL_OPTIONAL
;
153 printd
(DEBUG_PARSE
, "%s:%d:config %s\n", zconf_curname
(), zconf_lineno
(), $2);
156 config_stmt: config_entry_start config_option_list
159 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
162 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
164 struct symbol
*sym
= sym_lookup
($2, 0);
165 sym
->flags |
= SYMBOL_OPTIONAL
;
167 printd
(DEBUG_PARSE
, "%s:%d:menuconfig %s\n", zconf_curname
(), zconf_lineno
(), $2);
170 menuconfig_stmt: menuconfig_entry_start config_option_list
172 if
(current_entry
->prompt
)
173 current_entry
->prompt
->type
= P_MENU
;
175 zconfprint
("warning: menuconfig statement without prompt");
177 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
182 | config_option_list config_option
183 | config_option_list symbol_option
184 | config_option_list depends
185 | config_option_list help
186 | config_option_list option_error
187 | config_option_list T_EOL
190 config_option: T_TYPE prompt_stmt_opt T_EOL
192 menu_set_type
($1->stype
);
193 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
194 zconf_curname
(), zconf_lineno
(),
198 config_option: T_PROMPT prompt if_expr T_EOL
200 menu_add_prompt
(P_PROMPT
, $2, $3);
201 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
204 config_option: T_DEFAULT expr if_expr T_EOL
206 menu_add_expr
(P_DEFAULT
, $2, $3);
207 if
($1->stype
!= S_UNKNOWN
)
208 menu_set_type
($1->stype
);
209 printd
(DEBUG_PARSE
, "%s:%d:default(%u)\n",
210 zconf_curname
(), zconf_lineno
(),
214 config_option: T_SELECT T_WORD if_expr T_EOL
216 menu_add_symbol
(P_SELECT
, sym_lookup
($2, 0), $3);
217 printd
(DEBUG_PARSE
, "%s:%d:select\n", zconf_curname
(), zconf_lineno
());
220 config_option: T_IMPLY T_WORD if_expr T_EOL
222 menu_add_symbol
(P_IMPLY
, sym_lookup
($2, 0), $3);
223 printd
(DEBUG_PARSE
, "%s:%d:imply\n", zconf_curname
(), zconf_lineno
());
226 config_option: T_RANGE symbol symbol if_expr T_EOL
228 menu_add_expr
(P_RANGE
, expr_alloc_comp
(E_RANGE
,$2, $3), $4);
229 printd
(DEBUG_PARSE
, "%s:%d:range\n", zconf_curname
(), zconf_lineno
());
232 symbol_option: T_OPTION symbol_option_list T_EOL
237 | symbol_option_list T_WORD symbol_option_arg
239 const struct kconf_id
*id
= kconf_id_lookup
($2, strlen
($2));
240 if
(id
&& id
->flags
& TF_OPTION
)
241 menu_add_option
(id
->token
, $3);
243 zconfprint
("warning: ignoring unknown option %s", $2);
248 /* empty */ { $$
= NULL
; }
249 | T_EQUAL prompt
{ $$
= $2; }
254 choice: T_CHOICE word_opt T_EOL
256 struct symbol
*sym
= sym_lookup
($2, SYMBOL_CHOICE
);
257 sym
->flags |
= SYMBOL_AUTO
;
259 menu_add_expr
(P_CHOICE
, NULL
, NULL
);
260 printd
(DEBUG_PARSE
, "%s:%d:choice\n", zconf_curname
(), zconf_lineno
());
263 choice_entry: choice choice_option_list
265 $$
= menu_add_menu
();
270 if
(zconf_endtoken
($1, T_CHOICE
, T_ENDCHOICE
)) {
272 printd
(DEBUG_PARSE
, "%s:%d:endchoice\n", zconf_curname
(), zconf_lineno
());
276 choice_stmt: choice_entry choice_block choice_end
281 | choice_option_list choice_option
282 | choice_option_list depends
283 | choice_option_list help
284 | choice_option_list T_EOL
285 | choice_option_list option_error
288 choice_option: T_PROMPT prompt if_expr T_EOL
290 menu_add_prompt
(P_PROMPT
, $2, $3);
291 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
294 choice_option: T_TYPE prompt_stmt_opt T_EOL
296 if
($1->stype
== S_BOOLEAN ||
$1->stype
== S_TRISTATE
) {
297 menu_set_type
($1->stype
);
298 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
299 zconf_curname
(), zconf_lineno
(),
305 choice_option: T_OPTIONAL T_EOL
307 current_entry
->sym
->flags |
= SYMBOL_OPTIONAL
;
308 printd
(DEBUG_PARSE
, "%s:%d:optional\n", zconf_curname
(), zconf_lineno
());
311 choice_option: T_DEFAULT T_WORD if_expr T_EOL
313 if
($1->stype
== S_UNKNOWN
) {
314 menu_add_symbol
(P_DEFAULT
, sym_lookup
($2, 0), $3);
315 printd
(DEBUG_PARSE
, "%s:%d:default\n",
316 zconf_curname
(), zconf_lineno
());
323 | choice_block common_stmt
328 if_entry: T_IF expr nl
330 printd
(DEBUG_PARSE
, "%s:%d:if\n", zconf_curname
(), zconf_lineno
());
331 menu_add_entry
(NULL
);
333 $$
= menu_add_menu
();
338 if
(zconf_endtoken
($1, T_IF
, T_ENDIF
)) {
340 printd
(DEBUG_PARSE
, "%s:%d:endif\n", zconf_curname
(), zconf_lineno
());
344 if_stmt: if_entry if_block if_end
349 | if_block common_stmt
351 | if_block choice_stmt
356 mainmenu_stmt: T_MAINMENU prompt nl
358 menu_add_prompt
(P_MENU
, $2, NULL
);
363 menu: T_MENU prompt T_EOL
365 menu_add_entry
(NULL
);
366 menu_add_prompt
(P_MENU
, $2, NULL
);
367 printd
(DEBUG_PARSE
, "%s:%d:menu\n", zconf_curname
(), zconf_lineno
());
370 menu_entry: menu visibility_list depends_list
372 $$
= menu_add_menu
();
377 if
(zconf_endtoken
($1, T_MENU
, T_ENDMENU
)) {
379 printd
(DEBUG_PARSE
, "%s:%d:endmenu\n", zconf_curname
(), zconf_lineno
());
383 menu_stmt: menu_entry menu_block menu_end
388 | menu_block common_stmt
389 | menu_block menu_stmt
390 | menu_block choice_stmt
393 source_stmt: T_SOURCE prompt T_EOL
395 printd
(DEBUG_PARSE
, "%s:%d:source %s\n", zconf_curname
(), zconf_lineno
(), $2);
401 comment: T_COMMENT prompt T_EOL
403 menu_add_entry
(NULL
);
404 menu_add_prompt
(P_COMMENT
, $2, NULL
);
405 printd
(DEBUG_PARSE
, "%s:%d:comment\n", zconf_curname
(), zconf_lineno
());
408 comment_stmt: comment depends_list
415 help_start: T_HELP T_EOL
417 printd
(DEBUG_PARSE
, "%s:%d:help\n", zconf_curname
(), zconf_lineno
());
421 help: help_start T_HELPTEXT
423 current_entry
->help
= $2;
430 | depends_list depends
432 | depends_list option_error
435 depends: T_DEPENDS T_ON expr T_EOL
438 printd
(DEBUG_PARSE
, "%s:%d:depends on\n", zconf_curname
(), zconf_lineno
());
441 /* visibility option */
445 | visibility_list visible
446 | visibility_list T_EOL
449 visible: T_VISIBLE if_expr
451 menu_add_visibility
($2);
454 /* prompt statement */
460 menu_add_prompt
(P_PROMPT
, $1, $2);
467 end: T_ENDMENU T_EOL
{ $$
= $1; }
468 | T_ENDCHOICE T_EOL
{ $$
= $1; }
469 | T_ENDIF T_EOL
{ $$
= $1; }
477 if_expr: /* empty */ { $$
= NULL
; }
478 | T_IF expr
{ $$
= $2; }
481 expr: symbol
{ $$
= expr_alloc_symbol
($1); }
482 | symbol T_LESS symbol
{ $$
= expr_alloc_comp
(E_LTH
, $1, $3); }
483 | symbol T_LESS_EQUAL symbol
{ $$
= expr_alloc_comp
(E_LEQ
, $1, $3); }
484 | symbol T_GREATER symbol
{ $$
= expr_alloc_comp
(E_GTH
, $1, $3); }
485 | symbol T_GREATER_EQUAL symbol
{ $$
= expr_alloc_comp
(E_GEQ
, $1, $3); }
486 | symbol T_EQUAL symbol
{ $$
= expr_alloc_comp
(E_EQUAL
, $1, $3); }
487 | symbol T_UNEQUAL symbol
{ $$
= expr_alloc_comp
(E_UNEQUAL
, $1, $3); }
488 | T_OPEN_PAREN expr T_CLOSE_PAREN
{ $$
= $2; }
489 | T_NOT expr
{ $$
= expr_alloc_one
(E_NOT
, $2); }
490 | expr T_OR expr
{ $$
= expr_alloc_two
(E_OR
, $1, $3); }
491 | expr T_AND expr
{ $$
= expr_alloc_two
(E_AND
, $1, $3); }
494 symbol: T_WORD
{ $$
= sym_lookup
($1, 0); free
($1); }
495 | T_WORD_QUOTE
{ $$
= sym_lookup
($1, SYMBOL_CONST
); free
($1); }
498 word_opt: /* empty */ { $$
= NULL
; }
503 void conf_parse
(const char *name
)
508 zconf_initscan
(name
);
512 rootmenu.prompt
= menu_add_prompt
(P_MENU
, "Linux Kernel Configuration", NULL
);
514 if
(getenv
("ZCONF_DEBUG"))
520 modules_sym
= sym_find
( "n" );
522 rootmenu.prompt
->text
= _
(rootmenu.prompt
->text
);
523 rootmenu.prompt
->text
= sym_expand_string_value
(rootmenu.prompt
->text
);
525 menu_finalize
(&rootmenu
);
526 for_all_symbols
(i
, sym
) {
527 if
(sym_check_deps
(sym
))
532 sym_set_change_count
(1);
535 static const char *zconf_tokenname
(int token
)
538 case T_MENU
: return
"menu";
539 case T_ENDMENU
: return
"endmenu";
540 case T_CHOICE
: return
"choice";
541 case T_ENDCHOICE
: return
"endchoice";
542 case T_IF
: return
"if";
543 case T_ENDIF
: return
"endif";
544 case T_DEPENDS
: return
"depends";
545 case T_VISIBLE
: return
"visible";
550 static bool zconf_endtoken
(const struct kconf_id
*id
, int starttoken
, int endtoken
)
552 if
(id
->token
!= endtoken
) {
553 zconf_error
("unexpected '%s' within %s block",
554 kconf_id_strings
+ id
->name
, zconf_tokenname
(starttoken
));
558 if
(current_menu
->file
!= current_file
) {
559 zconf_error
("'%s' in different file than '%s'",
560 kconf_id_strings
+ id
->name
, zconf_tokenname
(starttoken
));
561 fprintf
(stderr
, "%s:%d: location of the '%s'\n",
562 current_menu
->file
->name
, current_menu
->lineno
,
563 zconf_tokenname
(starttoken
));
570 static void zconfprint
(const char *err
, ...
)
574 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
576 vfprintf
(stderr
, err
, ap
);
578 fprintf
(stderr
, "\n");
581 static void zconf_error
(const char *err
, ...
)
586 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
588 vfprintf
(stderr
, err
, ap
);
590 fprintf
(stderr
, "\n");
593 static void zconferror
(const char *err
)
595 fprintf
(stderr
, "%s:%d: %s\n", zconf_curname
(), zconf_lineno
() + 1, err
);
598 static void print_quoted_string
(FILE *out
, const char *str
)
604 while
((p
= strchr
(str
, '"'))) {
607 fprintf
(out
, "%.*s", len
, str
);
615 static void print_symbol
(FILE *out
, struct menu
*menu
)
617 struct symbol
*sym
= menu
->sym
;
618 struct property
*prop
;
620 if
(sym_is_choice
(sym
))
621 fprintf
(out
, "\nchoice\n");
623 fprintf
(out
, "\nconfig %s\n", sym
->name
);
626 fputs
(" boolean\n", out
);
629 fputs
(" tristate\n", out
);
632 fputs
(" string\n", out
);
635 fputs
(" integer\n", out
);
638 fputs
(" hex\n", out
);
641 fputs
(" ???\n", out
);
644 for
(prop
= sym
->prop
; prop
; prop
= prop
->next
) {
645 if
(prop
->menu
!= menu
)
647 switch
(prop
->type
) {
649 fputs
(" prompt ", out
);
650 print_quoted_string
(out
, prop
->text
);
651 if
(!expr_is_yes
(prop
->visible.expr
)) {
653 expr_fprint
(prop
->visible.expr
, out
);
658 fputs
( " default ", out
);
659 expr_fprint
(prop
->expr
, out
);
660 if
(!expr_is_yes
(prop
->visible.expr
)) {
662 expr_fprint
(prop
->visible.expr
, out
);
667 fputs
(" #choice value\n", out
);
670 fputs
( " select ", out
);
671 expr_fprint
(prop
->expr
, out
);
675 fputs
( " imply ", out
);
676 expr_fprint
(prop
->expr
, out
);
680 fputs
( " range ", out
);
681 expr_fprint
(prop
->expr
, out
);
685 fputs
( " menu ", out
);
686 print_quoted_string
(out
, prop
->text
);
690 fprintf
(out
, " unknown prop %d!\n", prop
->type
);
695 int len
= strlen
(menu
->help
);
696 while
(menu
->help
[--len
] == '\n')
698 fprintf
(out
, " help\n%s\n", menu
->help
);
702 void zconfdump
(FILE *out
)
704 struct property
*prop
;
708 menu
= rootmenu.list
;
710 if
((sym
= menu
->sym
))
711 print_symbol
(out
, menu
);
712 else if
((prop
= menu
->prompt
)) {
713 switch
(prop
->type
) {
715 fputs
("\ncomment ", out
);
716 print_quoted_string
(out
, prop
->text
);
720 fputs
("\nmenu ", out
);
721 print_quoted_string
(out
, prop
->text
);
727 if
(!expr_is_yes
(prop
->visible.expr
)) {
728 fputs
(" depends ", out
);
729 expr_fprint
(prop
->visible.expr
, out
);
738 else while
((menu
= menu
->parent
)) {
739 if
(menu
->prompt
&& menu
->prompt
->type
== P_MENU
)
740 fputs
("\nendmenu\n", out
);
749 #include "zconf.lex.c"
751 #include "confdata.c"