3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
14 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
17 #define DEBUG_PARSE 0x0002
21 extern
int zconflex
(void);
22 static void zconfprint
(const char *err
, ...
);
23 static void zconferror
(const char *err
);
24 static bool zconf_endtoken
(int token
, int starttoken
, int endtoken
);
26 struct symbol
*symbol_hash
[257];
28 static struct menu
*current_menu
, *current_entry
;
30 #define YYERROR_VERBOSE
38 struct symbol
*symbol
;
53 %token
<string> T_HELPTEXT
68 %token
<string> T_WORD
69 %token
<string> T_WORD_QUOTE
81 %left T_EQUAL T_UNEQUAL
92 #define LKC_DIRECT_LINK
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; }
120 /* config/menuconfig entry */
122 config_entry_start: T_CONFIG T_WORD T_EOL
124 struct symbol
*sym
= sym_lookup
($2, 0);
125 sym
->flags |
= SYMBOL_OPTIONAL
;
127 printd
(DEBUG_PARSE
, "%s:%d:config %s\n", zconf_curname
(), zconf_lineno
(), $2);
130 config_stmt: config_entry_start config_option_list
133 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
136 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
138 struct symbol
*sym
= sym_lookup
($2, 0);
139 sym
->flags |
= SYMBOL_OPTIONAL
;
141 printd
(DEBUG_PARSE
, "%s:%d:menuconfig %s\n", zconf_curname
(), zconf_lineno
(), $2);
144 menuconfig_stmt: menuconfig_entry_start config_option_list
146 if
(current_entry
->prompt
)
147 current_entry
->prompt
->type
= P_MENU
;
149 zconfprint
("warning: menuconfig statement without prompt");
151 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
156 | config_option_list config_option
157 | config_option_list depends
158 | config_option_list help
159 | config_option_list T_EOL
162 config_option: T_TRISTATE prompt_stmt_opt T_EOL
164 menu_set_type
(S_TRISTATE
);
165 printd
(DEBUG_PARSE
, "%s:%d:tristate\n", zconf_curname
(), zconf_lineno
());
168 config_option: T_DEF_TRISTATE expr if_expr T_EOL
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
());
175 config_option: T_BOOLEAN prompt_stmt_opt T_EOL
177 menu_set_type
(S_BOOLEAN
);
178 printd
(DEBUG_PARSE
, "%s:%d:boolean\n", zconf_curname
(), zconf_lineno
());
181 config_option: T_DEF_BOOLEAN expr if_expr T_EOL
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
());
188 config_option: T_INT prompt_stmt_opt T_EOL
190 menu_set_type
(S_INT
);
191 printd
(DEBUG_PARSE
, "%s:%d:int\n", zconf_curname
(), zconf_lineno
());
194 config_option: T_HEX prompt_stmt_opt T_EOL
196 menu_set_type
(S_HEX
);
197 printd
(DEBUG_PARSE
, "%s:%d:hex\n", zconf_curname
(), zconf_lineno
());
200 config_option: T_STRING prompt_stmt_opt T_EOL
202 menu_set_type
(S_STRING
);
203 printd
(DEBUG_PARSE
, "%s:%d:string\n", zconf_curname
(), zconf_lineno
());
206 config_option: T_PROMPT prompt if_expr T_EOL
208 menu_add_prompt
(P_PROMPT
, $2, $3);
209 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
212 config_option: T_DEFAULT expr if_expr T_EOL
214 menu_add_expr
(P_DEFAULT
, $2, $3);
215 printd
(DEBUG_PARSE
, "%s:%d:default\n", zconf_curname
(), zconf_lineno
());
218 config_option: T_SELECT T_WORD if_expr T_EOL
220 menu_add_symbol
(P_SELECT
, sym_lookup
($2, 0), $3);
221 printd
(DEBUG_PARSE
, "%s:%d:select\n", zconf_curname
(), zconf_lineno
());
224 config_option: T_RANGE symbol symbol if_expr T_EOL
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
());
232 choice: T_CHOICE T_EOL
234 struct symbol
*sym
= sym_lookup
(NULL
, 0);
235 sym
->flags |
= SYMBOL_CHOICE
;
237 menu_add_expr
(P_CHOICE
, NULL
, NULL
);
238 printd
(DEBUG_PARSE
, "%s:%d:choice\n", zconf_curname
(), zconf_lineno
());
241 choice_entry: choice choice_option_list
249 if
(zconf_endtoken
($1, T_CHOICE
, T_ENDCHOICE
)) {
251 printd
(DEBUG_PARSE
, "%s:%d:endchoice\n", zconf_curname
(), zconf_lineno
());
256 choice_entry choice_block choice_end
257 | choice_entry choice_block
259 printf
("%s:%d: missing 'endchoice' for this 'choice' statement\n", current_menu
->file
->name
, current_menu
->lineno
);
265 | choice_option_list choice_option
266 | choice_option_list depends
267 | choice_option_list help
268 | choice_option_list T_EOL
271 choice_option: T_PROMPT prompt if_expr T_EOL
273 menu_add_prompt
(P_PROMPT
, $2, $3);
274 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
277 choice_option: T_TRISTATE prompt_stmt_opt T_EOL
279 menu_set_type
(S_TRISTATE
);
280 printd
(DEBUG_PARSE
, "%s:%d:tristate\n", zconf_curname
(), zconf_lineno
());
283 choice_option: T_BOOLEAN prompt_stmt_opt T_EOL
285 menu_set_type
(S_BOOLEAN
);
286 printd
(DEBUG_PARSE
, "%s:%d:boolean\n", zconf_curname
(), zconf_lineno
());
289 choice_option: T_OPTIONAL T_EOL
291 current_entry
->sym
->flags |
= SYMBOL_OPTIONAL
;
292 printd
(DEBUG_PARSE
, "%s:%d:optional\n", zconf_curname
(), zconf_lineno
());
295 choice_option: T_DEFAULT T_WORD if_expr T_EOL
297 menu_add_symbol
(P_DEFAULT
, sym_lookup
($2, 0), $3);
298 printd
(DEBUG_PARSE
, "%s:%d:default\n", zconf_curname
(), zconf_lineno
());
303 | choice_block common_block
310 printd
(DEBUG_PARSE
, "%s:%d:if\n", zconf_curname
(), zconf_lineno
());
311 menu_add_entry
(NULL
);
319 if
(zconf_endtoken
($1, T_IF
, T_ENDIF
)) {
321 printd
(DEBUG_PARSE
, "%s:%d:endif\n", zconf_curname
(), zconf_lineno
());
329 printf
("%s:%d: missing 'endif' for this 'if' statement\n", current_menu
->file
->name
, current_menu
->lineno
);
335 | if_block common_block
337 | if_block choice_stmt
342 menu: T_MENU prompt T_EOL
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
());
349 menu_entry: menu depends_list
357 if
(zconf_endtoken
($1, T_MENU
, T_ENDMENU
)) {
359 printd
(DEBUG_PARSE
, "%s:%d:endmenu\n", zconf_curname
(), zconf_lineno
());
364 menu_entry menu_block menu_end
365 | menu_entry menu_block
367 printf
("%s:%d: missing 'endmenu' for this 'menu' statement\n", current_menu
->file
->name
, current_menu
->lineno
);
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; }
379 source: T_SOURCE prompt T_EOL
382 printd
(DEBUG_PARSE
, "%s:%d:source %s\n", zconf_curname
(), zconf_lineno
(), $2);
392 comment: T_COMMENT prompt T_EOL
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
());
399 comment_stmt: comment depends_list
406 help_start: T_HELP T_EOL
408 printd
(DEBUG_PARSE
, "%s:%d:help\n", zconf_curname
(), zconf_lineno
());
412 help: help_start T_HELPTEXT
414 current_entry
->sym
->help
= $2;
419 depends_list: /* empty */
420 | depends_list depends
424 depends: T_DEPENDS T_ON expr T_EOL
427 printd
(DEBUG_PARSE
, "%s:%d:depends on\n", zconf_curname
(), zconf_lineno
());
429 | T_DEPENDS expr T_EOL
432 printd
(DEBUG_PARSE
, "%s:%d:depends\n", zconf_curname
(), zconf_lineno
());
434 | T_REQUIRES expr T_EOL
437 printd
(DEBUG_PARSE
, "%s:%d:requires\n", zconf_curname
(), zconf_lineno
());
440 /* prompt statement */
446 menu_add_prop
(P_PROMPT
, $1, NULL
, $2);
453 end: T_ENDMENU nl_or_eof
{ $$
= T_ENDMENU
; }
454 | T_ENDCHOICE nl_or_eof
{ $$
= T_ENDCHOICE
; }
455 | T_ENDIF nl_or_eof
{ $$
= T_ENDIF
; }
461 if_expr: /* empty */ { $$
= NULL
; }
462 | T_IF expr
{ $$
= $2; }
465 expr: 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); }
474 symbol: T_WORD
{ $$
= sym_lookup
($1, 0); free
($1); }
475 | T_WORD_QUOTE
{ $$
= sym_lookup
($1, 1); free
($1); }
480 void conf_parse
(const char *name
)
485 zconf_initscan
(name
);
489 modules_sym
= sym_lookup
("MODULES", 0);
490 rootmenu.prompt
= menu_add_prop
(P_MENU
, "Buildroot Configuration", NULL
, NULL
);
496 menu_finalize
(&rootmenu
);
497 for_all_symbols
(i
, sym
) {
498 if
(!(sym
->flags
& SYMBOL_CHECKED
) && sym_check_deps
(sym
))
501 sym
->flags |
= SYMBOL_CHECK_DONE
;
504 sym_change_count
= 1;
507 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";
520 static bool zconf_endtoken
(int token
, int starttoken
, int endtoken
)
522 if
(token
!= endtoken
) {
523 zconfprint
("unexpected '%s' within %s block", zconf_tokenname
(token
), zconf_tokenname
(starttoken
));
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
));
536 static void zconfprint
(const char *err
, ...
)
540 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
() + 1);
542 vfprintf
(stderr
, err
, ap
);
544 fprintf
(stderr
, "\n");
547 static void zconferror
(const char *err
)
549 fprintf
(stderr
, "%s:%d: %s\n", zconf_curname
(), zconf_lineno
() + 1, err
);
552 void print_quoted_string
(FILE *out
, const char *str
)
558 while
((p
= strchr
(str
, '"'))) {
561 fprintf
(out
, "%.*s", len
, str
);
569 void print_symbol
(FILE *out
, struct menu
*menu
)
571 struct symbol
*sym
= menu
->sym
;
572 struct property
*prop
;
574 if
(sym_is_choice
(sym
))
575 fprintf
(out
, "choice\n");
577 fprintf
(out
, "config %s\n", sym
->name
);
580 fputs
(" boolean\n", out
);
583 fputs
(" tristate\n", out
);
586 fputs
(" string\n", out
);
589 fputs
(" integer\n", out
);
592 fputs
(" hex\n", out
);
595 fputs
(" ???\n", out
);
598 for
(prop
= sym
->prop
; prop
; prop
= prop
->next
) {
599 if
(prop
->menu
!= menu
)
601 switch
(prop
->type
) {
603 fputs
(" prompt ", out
);
604 print_quoted_string
(out
, prop
->text
);
605 if
(!expr_is_yes
(prop
->visible.expr
)) {
607 expr_fprint
(prop
->visible.expr
, out
);
612 fputs
( " default ", out
);
613 expr_fprint
(prop
->expr
, out
);
614 if
(!expr_is_yes
(prop
->visible.expr
)) {
616 expr_fprint
(prop
->visible.expr
, out
);
621 fputs
(" #choice value\n", out
);
624 fprintf
(out
, " unknown prop %d!\n", prop
->type
);
629 int len
= strlen
(sym
->help
);
630 while
(sym
->help
[--len
] == '\n')
632 fprintf
(out
, " help\n%s\n", sym
->help
);
637 void zconfdump
(FILE *out
)
639 struct property
*prop
;
643 menu
= rootmenu.list
;
645 if
((sym
= menu
->sym
))
646 print_symbol
(out
, menu
);
647 else if
((prop
= menu
->prompt
)) {
648 switch
(prop
->type
) {
650 fputs
("\ncomment ", out
);
651 print_quoted_string
(out
, prop
->text
);
655 fputs
("\nmenu ", out
);
656 print_quoted_string
(out
, prop
->text
);
662 if
(!expr_is_yes
(prop
->visible.expr
)) {
663 fputs
(" depends ", out
);
664 expr_fprint
(prop
->visible.expr
, out
);
674 else while
((menu
= menu
->parent
)) {
675 if
(menu
->prompt
&& menu
->prompt
->type
== P_MENU
)
676 fputs
("\nendmenu\n", out
);
685 #include "lex.zconf.c"
687 #include "confdata.c"