source: menu/zconf.y@ 72e9e68

ablfs-more legacy trunk
Last change on this file since 72e9e68 was a705708, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Merged menuconfig code from experimental.
Added clfs2 symlink (required by menuconfig)

  • Property mode set to 100644
File size: 14.4 KB
Line 
1%{
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
28static struct menu *current_menu, *current_entry;
29
30#define YYERROR_VERBOSE
31%}
32%expect 40
33
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
51%token T_MENUCONFIG
52%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
62%token T_DEF_TRISTATE
63%token T_BOOLEAN
64%token T_DEF_BOOLEAN
65%token T_STRING
66%token T_INT
67%token T_HEX
68%token <string> T_WORD
69%token <string> T_WORD_QUOTE
70%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
76%token T_SELECT
77%token T_RANGE
78
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
114 | menuconfig_stmt
115 | source_stmt
116 | nl_or_eof
117;
118
119
120/* config/menuconfig entry */
121
122config_entry_start: T_CONFIG T_WORD T_EOL
123{
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
130config_stmt: config_entry_start config_option_list
131{
132 menu_end_entry();
133 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
134};
135
136menuconfig_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
154config_option_list:
155 /* empty */
156 | config_option_list config_option
157 | config_option_list depends
158 | config_option_list help
159 | config_option_list T_EOL
160;
161
162config_option: T_TRISTATE prompt_stmt_opt T_EOL
163{
164 menu_set_type(S_TRISTATE);
165 printd(DEBUG_PARSE, "%s:%d:tristate\n", zconf_curname(), zconf_lineno());
166};
167
168config_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
176{
177 menu_set_type(S_BOOLEAN);
178 printd(DEBUG_PARSE, "%s:%d:boolean\n", zconf_curname(), zconf_lineno());
179};
180
181config_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
189{
190 menu_set_type(S_INT);
191 printd(DEBUG_PARSE, "%s:%d:int\n", zconf_curname(), zconf_lineno());
192};
193
194config_option: T_HEX prompt_stmt_opt T_EOL
195{
196 menu_set_type(S_HEX);
197 printd(DEBUG_PARSE, "%s:%d:hex\n", zconf_curname(), zconf_lineno());
198};
199
200config_option: T_STRING prompt_stmt_opt T_EOL
201{
202 menu_set_type(S_STRING);
203 printd(DEBUG_PARSE, "%s:%d:string\n", zconf_curname(), zconf_lineno());
204};
205
206config_option: T_PROMPT prompt if_expr T_EOL
207{
208 menu_add_prompt(P_PROMPT, $2, $3);
209 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
210};
211
212config_option: T_DEFAULT expr if_expr T_EOL
213{
214 menu_add_expr(P_DEFAULT, $2, $3);
215 printd(DEBUG_PARSE, "%s:%d:default\n", zconf_curname(), zconf_lineno());
216};
217
218config_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
230/* choice entry */
231
232choice: T_CHOICE T_EOL
233{
234 struct symbol *sym = sym_lookup(NULL, 0);
235 sym->flags |= SYMBOL_CHOICE;
236 menu_add_entry(sym);
237 menu_add_expr(P_CHOICE, NULL, NULL);
238 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
239};
240
241choice_entry: choice choice_option_list
242{
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:
256 choice_entry choice_block choice_end
257 | 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 */
265 | choice_option_list choice_option
266 | choice_option_list depends
267 | choice_option_list help
268 | choice_option_list T_EOL
269;
270
271choice_option: T_PROMPT prompt if_expr T_EOL
272{
273 menu_add_prompt(P_PROMPT, $2, $3);
274 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
275};
276
277choice_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
290{
291 current_entry->sym->flags |= SYMBOL_OPTIONAL;
292 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
293};
294
295choice_option: T_DEFAULT T_WORD if_expr T_EOL
296{
297 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
298 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
308if: T_IF expr T_EOL
309{
310 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
311 menu_add_entry(NULL);
312 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:
326 if if_block if_end
327 | if if_block
328{
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
342menu: T_MENU prompt T_EOL
343{
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
349menu_entry: menu depends_list
350{
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:
364 menu_entry menu_block menu_end
365 | 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
379source: T_SOURCE prompt T_EOL
380{
381 $$ = $2;
382 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
383};
384
385source_stmt: source
386{
387 zconf_nextfile($1);
388};
389
390/* comment entry */
391
392comment: T_COMMENT prompt T_EOL
393{
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
399comment_stmt: comment depends_list
400{
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 */
420 | depends_list depends
421 | depends_list T_EOL
422;
423
424depends: T_DEPENDS T_ON expr T_EOL
425{
426 menu_add_dep($3);
427 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
428}
429 | T_DEPENDS expr T_EOL
430{
431 menu_add_dep($2);
432 printd(DEBUG_PARSE, "%s:%d:depends\n", zconf_curname(), zconf_lineno());
433}
434 | T_REQUIRES expr T_EOL
435{
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 */
444 | prompt if_expr
445{
446 menu_add_prop(P_PROMPT, $1, NULL, $2);
447};
448
449prompt: T_WORD
450 | T_WORD_QUOTE
451;
452
453end: T_ENDMENU nl_or_eof { $$ = T_ENDMENU; }
454 | T_ENDCHOICE nl_or_eof { $$ = T_ENDCHOICE; }
455 | T_ENDIF nl_or_eof { $$ = T_ENDIF; }
456;
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); }
475 | T_WORD_QUOTE { $$ = sym_lookup($1, 1); free($1); }
476;
477
478%%
479
480void conf_parse(const char *name)
481{
482 struct symbol *sym;
483 int i;
484
485 zconf_initscan(name);
486
487 sym_init();
488 menu_init();
489 modules_sym = sym_lookup("MODULES", 0);
490 rootmenu.prompt = menu_add_prop(P_MENU, "JHALFS Configuration", NULL, NULL);
491
492 //zconfdebug = 1;
493 zconfparse();
494 if (zconfnerrs)
495 exit(1);
496 menu_finalize(&rootmenu);
497 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 }
503
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>";
518}
519
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
540 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno() + 1);
541 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{
549 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
550}
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
574 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 }
598 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);
605 if (!expr_is_yes(prop->visible.expr)) {
606 fputs(" if ", out);
607 expr_fprint(prop->visible.expr, out);
608 }
609 fputc('\n', out);
610 break;
611 case P_DEFAULT:
612 fputs( " default ", out);
613 expr_fprint(prop->expr, out);
614 if (!expr_is_yes(prop->visible.expr)) {
615 fputs(" if ", out);
616 expr_fprint(prop->visible.expr, out);
617 }
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{
639 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) {
649 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;
659 default:
660 ;
661 }
662 if (!expr_is_yes(prop->visible.expr)) {
663 fputs(" depends ", out);
664 expr_fprint(prop->visible.expr, out);
665 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"
686#include "util.c"
687#include "confdata.c"
688#include "expr.c"
689#include "symbol.c"
690#include "menu.c"
Note: See TracBrowser for help on using the repository browser.