zconf.y 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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. #include <ctype.h>
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <stdbool.h>
  12. #define LKC_DIRECT_LINK
  13. #include "lkc.h"
  14. #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
  15. #define PRINTD 0x0001
  16. #define DEBUG_PARSE 0x0002
  17. int cdebug = PRINTD;
  18. extern int zconflex(void);
  19. static void zconfprint(const char *err, ...);
  20. static void zconf_error(const char *err, ...);
  21. static void zconferror(const char *err);
  22. static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken);
  23. struct symbol *symbol_hash[SYMBOL_HASHSIZE];
  24. static struct menu *current_menu, *current_entry;
  25. #define YYDEBUG 0
  26. #if YYDEBUG
  27. #define YYERROR_VERBOSE
  28. #endif
  29. %}
  30. %expect 30
  31. %union
  32. {
  33. char *string;
  34. struct file *file;
  35. struct symbol *symbol;
  36. struct expr *expr;
  37. struct menu *menu;
  38. struct kconf_id *id;
  39. }
  40. %token <id>T_MAINMENU
  41. %token <id>T_MENU
  42. %token <id>T_ENDMENU
  43. %token <id>T_SOURCE
  44. %token <id>T_CHOICE
  45. %token <id>T_ENDCHOICE
  46. %token <id>T_COMMENT
  47. %token <id>T_CONFIG
  48. %token <id>T_MENUCONFIG
  49. %token <id>T_HELP
  50. %token <string> T_HELPTEXT
  51. %token <id>T_IF
  52. %token <id>T_ENDIF
  53. %token <id>T_DEPENDS
  54. %token <id>T_OPTIONAL
  55. %token <id>T_PROMPT
  56. %token <id>T_TYPE
  57. %token <id>T_DEFAULT
  58. %token <id>T_SELECT
  59. %token <id>T_RANGE
  60. %token <id>T_VISIBLE
  61. %token <id>T_OPTION
  62. %token <id>T_ON
  63. %token <string> T_WORD
  64. %token <string> T_WORD_QUOTE
  65. %token T_UNEQUAL
  66. %token T_CLOSE_PAREN
  67. %token T_OPEN_PAREN
  68. %token T_EOL
  69. %left T_OR
  70. %left T_AND
  71. %left T_EQUAL T_UNEQUAL
  72. %nonassoc T_NOT
  73. %type <string> prompt
  74. %type <symbol> symbol
  75. %type <expr> expr
  76. %type <expr> if_expr
  77. %type <id> end
  78. %type <id> option_name
  79. %type <menu> if_entry menu_entry choice_entry
  80. %type <string> symbol_option_arg word_opt
  81. %destructor {
  82. fprintf(stderr, "%s:%d: missing end statement for this entry\n",
  83. $$->file->name, $$->lineno);
  84. if (current_menu == $$)
  85. menu_end_menu();
  86. } if_entry menu_entry choice_entry
  87. %{
  88. /* Include zconf.hash.c here so it can see the token constants. */
  89. #include "zconf.hash.c"
  90. %}
  91. %%
  92. input: nl start | start;
  93. start: mainmenu_stmt stmt_list | stmt_list;
  94. stmt_list:
  95. /* empty */
  96. | stmt_list common_stmt
  97. | stmt_list choice_stmt
  98. | stmt_list menu_stmt
  99. | stmt_list end { zconf_error("unexpected end statement"); }
  100. | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
  101. | stmt_list option_name error T_EOL
  102. {
  103. zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
  104. }
  105. | stmt_list error T_EOL { zconf_error("invalid statement"); }
  106. ;
  107. option_name:
  108. T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
  109. ;
  110. common_stmt:
  111. T_EOL
  112. | if_stmt
  113. | comment_stmt
  114. | config_stmt
  115. | menuconfig_stmt
  116. | source_stmt
  117. ;
  118. option_error:
  119. T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
  120. | error T_EOL { zconf_error("invalid option"); }
  121. ;
  122. /* config/menuconfig entry */
  123. config_entry_start: T_CONFIG T_WORD T_EOL
  124. {
  125. struct symbol *sym = sym_lookup($2, 0);
  126. sym->flags |= SYMBOL_OPTIONAL;
  127. menu_add_entry(sym);
  128. printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
  129. };
  130. config_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. menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
  136. {
  137. struct symbol *sym = sym_lookup($2, 0);
  138. sym->flags |= SYMBOL_OPTIONAL;
  139. menu_add_entry(sym);
  140. printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
  141. };
  142. menuconfig_stmt: menuconfig_entry_start config_option_list
  143. {
  144. if (current_entry->prompt)
  145. current_entry->prompt->type = P_MENU;
  146. else
  147. zconfprint("warning: menuconfig statement without prompt");
  148. menu_end_entry();
  149. printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
  150. };
  151. config_option_list:
  152. /* empty */
  153. | config_option_list config_option
  154. | config_option_list symbol_option
  155. | config_option_list depends
  156. | config_option_list help
  157. | config_option_list option_error
  158. | config_option_list T_EOL
  159. ;
  160. config_option: T_TYPE prompt_stmt_opt T_EOL
  161. {
  162. menu_set_type($1->stype);
  163. printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
  164. zconf_curname(), zconf_lineno(),
  165. $1->stype);
  166. };
  167. config_option: T_PROMPT prompt if_expr T_EOL
  168. {
  169. menu_add_prompt(P_PROMPT, $2, $3);
  170. printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
  171. };
  172. config_option: T_DEFAULT expr if_expr T_EOL
  173. {
  174. menu_add_expr(P_DEFAULT, $2, $3);
  175. if ($1->stype != S_UNKNOWN)
  176. menu_set_type($1->stype);
  177. printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
  178. zconf_curname(), zconf_lineno(),
  179. $1->stype);
  180. };
  181. config_option: T_SELECT T_WORD if_expr T_EOL
  182. {
  183. menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
  184. printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
  185. };
  186. config_option: T_RANGE symbol symbol if_expr T_EOL
  187. {
  188. menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
  189. printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
  190. };
  191. symbol_option: T_OPTION symbol_option_list T_EOL
  192. ;
  193. symbol_option_list:
  194. /* empty */
  195. | symbol_option_list T_WORD symbol_option_arg
  196. {
  197. struct kconf_id *id = kconf_id_lookup($2, strlen($2));
  198. if (id && id->flags & TF_OPTION)
  199. menu_add_option(id->token, $3);
  200. else
  201. zconfprint("warning: ignoring unknown option %s", $2);
  202. free($2);
  203. };
  204. symbol_option_arg:
  205. /* empty */ { $$ = NULL; }
  206. | T_EQUAL prompt { $$ = $2; }
  207. ;
  208. /* choice entry */
  209. choice: T_CHOICE word_opt T_EOL
  210. {
  211. struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
  212. sym->flags |= SYMBOL_AUTO;
  213. menu_add_entry(sym);
  214. menu_add_expr(P_CHOICE, NULL, NULL);
  215. printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
  216. };
  217. choice_entry: choice choice_option_list
  218. {
  219. $$ = menu_add_menu();
  220. };
  221. choice_end: end
  222. {
  223. if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
  224. menu_end_menu();
  225. printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
  226. }
  227. };
  228. choice_stmt: choice_entry choice_block choice_end
  229. ;
  230. choice_option_list:
  231. /* empty */
  232. | choice_option_list choice_option
  233. | choice_option_list depends
  234. | choice_option_list help
  235. | choice_option_list T_EOL
  236. | choice_option_list option_error
  237. ;
  238. choice_option: T_PROMPT prompt if_expr T_EOL
  239. {
  240. menu_add_prompt(P_PROMPT, $2, $3);
  241. printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
  242. };
  243. choice_option: T_TYPE prompt_stmt_opt T_EOL
  244. {
  245. if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
  246. menu_set_type($1->stype);
  247. printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
  248. zconf_curname(), zconf_lineno(),
  249. $1->stype);
  250. } else
  251. YYERROR;
  252. };
  253. choice_option: T_OPTIONAL T_EOL
  254. {
  255. current_entry->sym->flags |= SYMBOL_OPTIONAL;
  256. printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
  257. };
  258. choice_option: T_DEFAULT T_WORD if_expr T_EOL
  259. {
  260. if ($1->stype == S_UNKNOWN) {
  261. menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
  262. printd(DEBUG_PARSE, "%s:%d:default\n",
  263. zconf_curname(), zconf_lineno());
  264. } else
  265. YYERROR;
  266. };
  267. choice_block:
  268. /* empty */
  269. | choice_block common_stmt
  270. ;
  271. /* if entry */
  272. if_entry: T_IF expr nl
  273. {
  274. printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
  275. menu_add_entry(NULL);
  276. menu_add_dep($2);
  277. $$ = menu_add_menu();
  278. };
  279. if_end: end
  280. {
  281. if (zconf_endtoken($1, T_IF, T_ENDIF)) {
  282. menu_end_menu();
  283. printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
  284. }
  285. };
  286. if_stmt: if_entry if_block if_end
  287. ;
  288. if_block:
  289. /* empty */
  290. | if_block common_stmt
  291. | if_block menu_stmt
  292. | if_block choice_stmt
  293. ;
  294. /* mainmenu entry */
  295. mainmenu_stmt: T_MAINMENU prompt nl
  296. {
  297. menu_add_prompt(P_MENU, $2, NULL);
  298. };
  299. /* menu entry */
  300. menu: T_MENU prompt T_EOL
  301. {
  302. menu_add_entry(NULL);
  303. menu_add_prompt(P_MENU, $2, NULL);
  304. printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
  305. };
  306. menu_entry: menu visibility_list depends_list
  307. {
  308. $$ = menu_add_menu();
  309. };
  310. menu_end: end
  311. {
  312. if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
  313. menu_end_menu();
  314. printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
  315. }
  316. };
  317. menu_stmt: menu_entry menu_block menu_end
  318. ;
  319. menu_block:
  320. /* empty */
  321. | menu_block common_stmt
  322. | menu_block menu_stmt
  323. | menu_block choice_stmt
  324. ;
  325. source_stmt: T_SOURCE prompt T_EOL
  326. {
  327. printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
  328. zconf_nextfile($2);
  329. };
  330. /* comment entry */
  331. comment: T_COMMENT prompt T_EOL
  332. {
  333. menu_add_entry(NULL);
  334. menu_add_prompt(P_COMMENT, $2, NULL);
  335. printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
  336. };
  337. comment_stmt: comment depends_list
  338. {
  339. menu_end_entry();
  340. };
  341. /* help option */
  342. help_start: T_HELP T_EOL
  343. {
  344. printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
  345. zconf_starthelp();
  346. };
  347. help: help_start T_HELPTEXT
  348. {
  349. current_entry->help = $2;
  350. };
  351. /* depends option */
  352. depends_list:
  353. /* empty */
  354. | depends_list depends
  355. | depends_list T_EOL
  356. | depends_list option_error
  357. ;
  358. depends: T_DEPENDS T_ON expr T_EOL
  359. {
  360. menu_add_dep($3);
  361. printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
  362. };
  363. /* visibility option */
  364. visibility_list:
  365. /* empty */
  366. | visibility_list visible
  367. | visibility_list T_EOL
  368. ;
  369. visible: T_VISIBLE if_expr
  370. {
  371. menu_add_visibility($2);
  372. };
  373. /* prompt statement */
  374. prompt_stmt_opt:
  375. /* empty */
  376. | prompt if_expr
  377. {
  378. menu_add_prompt(P_PROMPT, $1, $2);
  379. };
  380. prompt: T_WORD
  381. | T_WORD_QUOTE
  382. ;
  383. end: T_ENDMENU T_EOL { $$ = $1; }
  384. | T_ENDCHOICE T_EOL { $$ = $1; }
  385. | T_ENDIF T_EOL { $$ = $1; }
  386. ;
  387. nl:
  388. T_EOL
  389. | nl T_EOL
  390. ;
  391. if_expr: /* empty */ { $$ = NULL; }
  392. | T_IF expr { $$ = $2; }
  393. ;
  394. expr: symbol { $$ = expr_alloc_symbol($1); }
  395. | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
  396. | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
  397. | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
  398. | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
  399. | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
  400. | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
  401. ;
  402. symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
  403. | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
  404. ;
  405. word_opt: /* empty */ { $$ = NULL; }
  406. | T_WORD
  407. %%
  408. void conf_parse(const char *name)
  409. {
  410. struct symbol *sym;
  411. int i;
  412. zconf_initscan(name);
  413. sym_init();
  414. _menu_init();
  415. modules_sym = sym_lookup(NULL, 0);
  416. modules_sym->type = S_BOOLEAN;
  417. modules_sym->flags |= SYMBOL_AUTO;
  418. rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
  419. #if YYDEBUG
  420. if (getenv("ZCONF_DEBUG"))
  421. zconfdebug = 1;
  422. #endif
  423. zconfparse();
  424. if (zconfnerrs)
  425. exit(1);
  426. if (!modules_sym->prop) {
  427. struct property *prop;
  428. prop = prop_alloc(P_DEFAULT, modules_sym);
  429. prop->expr = expr_alloc_symbol(sym_lookup("MODULES", 0));
  430. }
  431. rootmenu.prompt->text = _(rootmenu.prompt->text);
  432. rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
  433. menu_finalize(&rootmenu);
  434. for_all_symbols(i, sym) {
  435. if (sym_check_deps(sym))
  436. zconfnerrs++;
  437. }
  438. if (zconfnerrs)
  439. exit(1);
  440. sym_set_change_count(1);
  441. }
  442. static const char *zconf_tokenname(int token)
  443. {
  444. switch (token) {
  445. case T_MENU: return "menu";
  446. case T_ENDMENU: return "endmenu";
  447. case T_CHOICE: return "choice";
  448. case T_ENDCHOICE: return "endchoice";
  449. case T_IF: return "if";
  450. case T_ENDIF: return "endif";
  451. case T_DEPENDS: return "depends";
  452. case T_VISIBLE: return "visible";
  453. }
  454. return "<token>";
  455. }
  456. static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken)
  457. {
  458. if (id->token != endtoken) {
  459. zconf_error("unexpected '%s' within %s block",
  460. kconf_id_strings + id->name, zconf_tokenname(starttoken));
  461. zconfnerrs++;
  462. return false;
  463. }
  464. if (current_menu->file != current_file) {
  465. zconf_error("'%s' in different file than '%s'",
  466. kconf_id_strings + id->name, zconf_tokenname(starttoken));
  467. fprintf(stderr, "%s:%d: location of the '%s'\n",
  468. current_menu->file->name, current_menu->lineno,
  469. zconf_tokenname(starttoken));
  470. zconfnerrs++;
  471. return false;
  472. }
  473. return true;
  474. }
  475. static void zconfprint(const char *err, ...)
  476. {
  477. va_list ap;
  478. fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
  479. va_start(ap, err);
  480. vfprintf(stderr, err, ap);
  481. va_end(ap);
  482. fprintf(stderr, "\n");
  483. }
  484. static void zconf_error(const char *err, ...)
  485. {
  486. va_list ap;
  487. zconfnerrs++;
  488. fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
  489. va_start(ap, err);
  490. vfprintf(stderr, err, ap);
  491. va_end(ap);
  492. fprintf(stderr, "\n");
  493. }
  494. static void zconferror(const char *err)
  495. {
  496. #if YYDEBUG
  497. fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
  498. #endif
  499. }
  500. static void print_quoted_string(FILE *out, const char *str)
  501. {
  502. const char *p;
  503. int len;
  504. putc('"', out);
  505. while ((p = strchr(str, '"'))) {
  506. len = p - str;
  507. if (len)
  508. fprintf(out, "%.*s", len, str);
  509. fputs("\\\"", out);
  510. str = p + 1;
  511. }
  512. fputs(str, out);
  513. putc('"', out);
  514. }
  515. static void print_symbol(FILE *out, struct menu *menu)
  516. {
  517. struct symbol *sym = menu->sym;
  518. struct property *prop;
  519. if (sym_is_choice(sym))
  520. fprintf(out, "\nchoice\n");
  521. else
  522. fprintf(out, "\nconfig %s\n", sym->name);
  523. switch (sym->type) {
  524. case S_BOOLEAN:
  525. fputs(" boolean\n", out);
  526. break;
  527. case S_TRISTATE:
  528. fputs(" tristate\n", out);
  529. break;
  530. case S_STRING:
  531. fputs(" string\n", out);
  532. break;
  533. case S_INT:
  534. fputs(" integer\n", out);
  535. break;
  536. case S_HEX:
  537. fputs(" hex\n", out);
  538. break;
  539. default:
  540. fputs(" ???\n", out);
  541. break;
  542. }
  543. for (prop = sym->prop; prop; prop = prop->next) {
  544. if (prop->menu != menu)
  545. continue;
  546. switch (prop->type) {
  547. case P_PROMPT:
  548. fputs(" prompt ", out);
  549. print_quoted_string(out, prop->text);
  550. if (!expr_is_yes(prop->visible.expr)) {
  551. fputs(" if ", out);
  552. expr_fprint(prop->visible.expr, out);
  553. }
  554. fputc('\n', out);
  555. break;
  556. case P_DEFAULT:
  557. fputs( " default ", out);
  558. expr_fprint(prop->expr, out);
  559. if (!expr_is_yes(prop->visible.expr)) {
  560. fputs(" if ", out);
  561. expr_fprint(prop->visible.expr, out);
  562. }
  563. fputc('\n', out);
  564. break;
  565. case P_CHOICE:
  566. fputs(" #choice value\n", out);
  567. break;
  568. case P_SELECT:
  569. fputs( " select ", out);
  570. expr_fprint(prop->expr, out);
  571. fputc('\n', out);
  572. break;
  573. case P_RANGE:
  574. fputs( " range ", out);
  575. expr_fprint(prop->expr, out);
  576. fputc('\n', out);
  577. break;
  578. case P_MENU:
  579. fputs( " menu ", out);
  580. print_quoted_string(out, prop->text);
  581. fputc('\n', out);
  582. break;
  583. default:
  584. fprintf(out, " unknown prop %d!\n", prop->type);
  585. break;
  586. }
  587. }
  588. if (menu->help) {
  589. int len = strlen(menu->help);
  590. while (menu->help[--len] == '\n')
  591. menu->help[len] = 0;
  592. fprintf(out, " help\n%s\n", menu->help);
  593. }
  594. }
  595. void zconfdump(FILE *out)
  596. {
  597. struct property *prop;
  598. struct symbol *sym;
  599. struct menu *menu;
  600. menu = rootmenu.list;
  601. while (menu) {
  602. if ((sym = menu->sym))
  603. print_symbol(out, menu);
  604. else if ((prop = menu->prompt)) {
  605. switch (prop->type) {
  606. case P_COMMENT:
  607. fputs("\ncomment ", out);
  608. print_quoted_string(out, prop->text);
  609. fputs("\n", out);
  610. break;
  611. case P_MENU:
  612. fputs("\nmenu ", out);
  613. print_quoted_string(out, prop->text);
  614. fputs("\n", out);
  615. break;
  616. default:
  617. ;
  618. }
  619. if (!expr_is_yes(prop->visible.expr)) {
  620. fputs(" depends ", out);
  621. expr_fprint(prop->visible.expr, out);
  622. fputc('\n', out);
  623. }
  624. }
  625. if (menu->list)
  626. menu = menu->list;
  627. else if (menu->next)
  628. menu = menu->next;
  629. else while ((menu = menu->parent)) {
  630. if (menu->prompt && menu->prompt->type == P_MENU)
  631. fputs("\nendmenu\n", out);
  632. if (menu->next) {
  633. menu = menu->next;
  634. break;
  635. }
  636. }
  637. }
  638. }
  639. #include "lex.zconf.c"
  640. #include "util.c"
  641. #include "confdata.c"
  642. #include "expr.c"
  643. #include "symbol.c"
  644. #include "menu.c"