parser.y 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  4. */
  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. #include "lkc.h"
  13. #include "internal.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. static void yyerror(const char *err);
  19. static void zconfprint(const char *err, ...);
  20. static void zconf_error(const char *err, ...);
  21. static bool zconf_endtoken(const char *tokenname,
  22. const char *expected_tokenname);
  23. struct symbol *symbol_hash[SYMBOL_HASHSIZE];
  24. struct menu *current_menu, *current_entry;
  25. %}
  26. %union
  27. {
  28. char *string;
  29. struct symbol *symbol;
  30. struct expr *expr;
  31. struct menu *menu;
  32. enum symbol_type type;
  33. enum variable_flavor flavor;
  34. }
  35. %token <string> T_HELPTEXT
  36. %token <string> T_WORD
  37. %token <string> T_WORD_QUOTE
  38. %token T_BOOL
  39. %token T_CHOICE
  40. %token T_CLOSE_PAREN
  41. %token T_COLON_EQUAL
  42. %token T_COMMENT
  43. %token T_CONFIG
  44. %token T_DEFAULT
  45. %token T_DEF_BOOL
  46. %token T_DEF_TRISTATE
  47. %token T_DEPENDS
  48. %token T_ENDCHOICE
  49. %token T_ENDIF
  50. %token T_ENDMENU
  51. %token T_HELP
  52. %token T_HEX
  53. %token T_IF
  54. %token T_IMPLY
  55. %token T_INT
  56. %token T_MAINMENU
  57. %token T_MENU
  58. %token T_MENUCONFIG
  59. %token T_MODULES
  60. %token T_ON
  61. %token T_OPEN_PAREN
  62. %token T_OPTIONAL
  63. %token T_PLUS_EQUAL
  64. %token T_PROMPT
  65. %token T_RANGE
  66. %token T_RESET
  67. %token T_SELECT
  68. %token T_SOURCE
  69. %token T_STRING
  70. %token T_TRISTATE
  71. %token T_VISIBLE
  72. %token T_EOL
  73. %token <string> T_ASSIGN_VAL
  74. %left T_OR
  75. %left T_AND
  76. %left T_EQUAL T_UNEQUAL
  77. %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
  78. %nonassoc T_NOT
  79. %type <symbol> nonconst_symbol
  80. %type <symbol> symbol
  81. %type <type> type logic_type default
  82. %type <expr> expr
  83. %type <expr> if_expr
  84. %type <string> end
  85. %type <menu> if_entry menu_entry choice_entry
  86. %type <string> word_opt assign_val
  87. %type <flavor> assign_op
  88. %destructor {
  89. fprintf(stderr, "%s:%d: missing end statement for this entry\n",
  90. $$->file->name, $$->lineno);
  91. if (current_menu == $$)
  92. menu_end_menu();
  93. } if_entry menu_entry choice_entry
  94. %%
  95. input: mainmenu_stmt stmt_list | stmt_list;
  96. /* mainmenu entry */
  97. mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL
  98. {
  99. menu_add_prompt(P_MENU, $2, NULL);
  100. };
  101. stmt_list:
  102. /* empty */
  103. | stmt_list assignment_stmt
  104. | stmt_list choice_stmt
  105. | stmt_list comment_stmt
  106. | stmt_list config_stmt
  107. | stmt_list if_stmt
  108. | stmt_list menu_stmt
  109. | stmt_list menuconfig_stmt
  110. | stmt_list source_stmt
  111. | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
  112. | stmt_list error T_EOL { zconf_error("invalid statement"); }
  113. ;
  114. stmt_list_in_choice:
  115. /* empty */
  116. | stmt_list_in_choice comment_stmt
  117. | stmt_list_in_choice config_stmt
  118. | stmt_list_in_choice if_stmt_in_choice
  119. | stmt_list_in_choice error T_EOL { zconf_error("invalid statement"); }
  120. ;
  121. /* config/menuconfig entry */
  122. config_entry_start: T_CONFIG nonconst_symbol T_EOL
  123. {
  124. $2->flags |= SYMBOL_OPTIONAL;
  125. menu_add_entry($2);
  126. printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name);
  127. };
  128. config_stmt: config_entry_start config_option_list
  129. {
  130. printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
  131. };
  132. menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
  133. {
  134. $2->flags |= SYMBOL_OPTIONAL;
  135. menu_add_entry($2);
  136. printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name);
  137. };
  138. menuconfig_stmt: menuconfig_entry_start config_option_list
  139. {
  140. if (current_entry->prompt)
  141. current_entry->prompt->type = P_MENU;
  142. else
  143. zconfprint("warning: menuconfig statement without prompt");
  144. printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
  145. };
  146. config_option_list:
  147. /* empty */
  148. | config_option_list config_option
  149. | config_option_list depends
  150. | config_option_list help
  151. ;
  152. config_option: type prompt_stmt_opt T_EOL
  153. {
  154. menu_set_type($1);
  155. printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
  156. zconf_curname(), zconf_lineno(),
  157. $1);
  158. };
  159. config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
  160. {
  161. menu_add_prompt(P_PROMPT, $2, $3);
  162. printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
  163. };
  164. config_option: default expr if_expr T_EOL
  165. {
  166. menu_add_expr(P_DEFAULT, $2, $3);
  167. if ($1 != S_UNKNOWN)
  168. menu_set_type($1);
  169. printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
  170. zconf_curname(), zconf_lineno(),
  171. $1);
  172. };
  173. config_option: T_SELECT nonconst_symbol if_expr T_EOL
  174. {
  175. menu_add_symbol(P_SELECT, $2, $3);
  176. printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
  177. };
  178. config_option: T_IMPLY nonconst_symbol if_expr T_EOL
  179. {
  180. menu_add_symbol(P_IMPLY, $2, $3);
  181. printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno());
  182. };
  183. config_option: T_RANGE symbol symbol if_expr T_EOL
  184. {
  185. menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
  186. printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
  187. };
  188. config_option: T_MODULES T_EOL
  189. {
  190. if (modules_sym)
  191. zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'",
  192. current_entry->sym->name, modules_sym->name);
  193. modules_sym = current_entry->sym;
  194. };
  195. /* choice entry */
  196. choice: T_CHOICE word_opt T_EOL
  197. {
  198. struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
  199. sym->flags |= SYMBOL_NO_WRITE;
  200. menu_add_entry(sym);
  201. menu_add_expr(P_CHOICE, NULL, NULL);
  202. free($2);
  203. printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
  204. };
  205. choice_entry: choice choice_option_list
  206. {
  207. $$ = menu_add_menu();
  208. };
  209. choice_end: end
  210. {
  211. if (zconf_endtoken($1, "choice")) {
  212. menu_end_menu();
  213. printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
  214. }
  215. };
  216. choice_stmt: choice_entry stmt_list_in_choice choice_end
  217. ;
  218. choice_option_list:
  219. /* empty */
  220. | choice_option_list choice_option
  221. | choice_option_list depends
  222. | choice_option_list help
  223. ;
  224. choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
  225. {
  226. menu_add_prompt(P_PROMPT, $2, $3);
  227. printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
  228. };
  229. choice_option: logic_type prompt_stmt_opt T_EOL
  230. {
  231. menu_set_type($1);
  232. printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
  233. zconf_curname(), zconf_lineno(), $1);
  234. };
  235. choice_option: T_OPTIONAL T_EOL
  236. {
  237. current_entry->sym->flags |= SYMBOL_OPTIONAL;
  238. printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
  239. };
  240. choice_option: T_RESET if_expr T_EOL
  241. {
  242. menu_add_prop(P_RESET, NULL, $2);
  243. };
  244. choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
  245. {
  246. menu_add_symbol(P_DEFAULT, $2, $3);
  247. printd(DEBUG_PARSE, "%s:%d:default\n",
  248. zconf_curname(), zconf_lineno());
  249. };
  250. type:
  251. logic_type
  252. | T_INT { $$ = S_INT; }
  253. | T_HEX { $$ = S_HEX; }
  254. | T_STRING { $$ = S_STRING; }
  255. logic_type:
  256. T_BOOL { $$ = S_BOOLEAN; }
  257. | T_TRISTATE { $$ = S_TRISTATE; }
  258. default:
  259. T_DEFAULT { $$ = S_UNKNOWN; }
  260. | T_DEF_BOOL { $$ = S_BOOLEAN; }
  261. | T_DEF_TRISTATE { $$ = S_TRISTATE; }
  262. /* if entry */
  263. if_entry: T_IF expr T_EOL
  264. {
  265. printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
  266. menu_add_entry(NULL);
  267. menu_add_dep($2);
  268. $$ = menu_add_menu();
  269. };
  270. if_end: end
  271. {
  272. if (zconf_endtoken($1, "if")) {
  273. menu_end_menu();
  274. printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
  275. }
  276. };
  277. if_stmt: if_entry stmt_list if_end
  278. ;
  279. if_stmt_in_choice: if_entry stmt_list_in_choice if_end
  280. ;
  281. /* menu entry */
  282. menu: T_MENU T_WORD_QUOTE T_EOL
  283. {
  284. menu_add_entry(NULL);
  285. menu_add_prompt(P_MENU, $2, NULL);
  286. printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
  287. };
  288. menu_entry: menu menu_option_list
  289. {
  290. $$ = menu_add_menu();
  291. };
  292. menu_end: end
  293. {
  294. if (zconf_endtoken($1, "menu")) {
  295. menu_end_menu();
  296. printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
  297. }
  298. };
  299. menu_stmt: menu_entry stmt_list menu_end
  300. ;
  301. menu_option_list:
  302. /* empty */
  303. | menu_option_list visible
  304. | menu_option_list depends
  305. ;
  306. source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
  307. {
  308. printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
  309. zconf_nextfile($2);
  310. free($2);
  311. };
  312. /* comment entry */
  313. comment: T_COMMENT T_WORD_QUOTE T_EOL
  314. {
  315. menu_add_entry(NULL);
  316. menu_add_prompt(P_COMMENT, $2, NULL);
  317. printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
  318. };
  319. comment_stmt: comment comment_option_list
  320. ;
  321. comment_option_list:
  322. /* empty */
  323. | comment_option_list depends
  324. ;
  325. /* help option */
  326. help_start: T_HELP T_EOL
  327. {
  328. printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
  329. zconf_starthelp();
  330. };
  331. help: help_start T_HELPTEXT
  332. {
  333. /* Is the help text empty or all whitespace? */
  334. if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
  335. zconfprint("warning: '%s' defined with blank help text",
  336. current_entry->sym->name ?: "<choice>");
  337. current_entry->help = $2;
  338. };
  339. /* depends option */
  340. depends: T_DEPENDS T_ON expr T_EOL
  341. {
  342. menu_add_dep($3);
  343. printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
  344. };
  345. /* visibility option */
  346. visible: T_VISIBLE if_expr T_EOL
  347. {
  348. menu_add_visibility($2);
  349. };
  350. /* prompt statement */
  351. prompt_stmt_opt:
  352. /* empty */
  353. | T_WORD_QUOTE if_expr
  354. {
  355. menu_add_prompt(P_PROMPT, $1, $2);
  356. };
  357. end: T_ENDMENU T_EOL { $$ = "menu"; }
  358. | T_ENDCHOICE T_EOL { $$ = "choice"; }
  359. | T_ENDIF T_EOL { $$ = "if"; }
  360. ;
  361. if_expr: /* empty */ { $$ = NULL; }
  362. | T_IF expr { $$ = $2; }
  363. ;
  364. expr: symbol { $$ = expr_alloc_symbol($1); }
  365. | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
  366. | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
  367. | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
  368. | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
  369. | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
  370. | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
  371. | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
  372. | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
  373. | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
  374. | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
  375. ;
  376. /* For symbol definitions, selects, etc., where quotes are not accepted */
  377. nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
  378. symbol: nonconst_symbol
  379. | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
  380. ;
  381. word_opt: /* empty */ { $$ = NULL; }
  382. | T_WORD
  383. /* assignment statement */
  384. assignment_stmt: T_WORD assign_op assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); }
  385. assign_op:
  386. T_EQUAL { $$ = VAR_RECURSIVE; }
  387. | T_COLON_EQUAL { $$ = VAR_SIMPLE; }
  388. | T_PLUS_EQUAL { $$ = VAR_APPEND; }
  389. ;
  390. assign_val:
  391. /* empty */ { $$ = xstrdup(""); };
  392. | T_ASSIGN_VAL
  393. ;
  394. %%
  395. void conf_parse(const char *name)
  396. {
  397. struct symbol *sym;
  398. int i;
  399. zconf_initscan(name);
  400. _menu_init();
  401. #if YYDEBUG
  402. if (getenv("ZCONF_DEBUG"))
  403. yydebug = 1;
  404. #endif
  405. yyparse();
  406. /* Variables are expanded in the parse phase. We can free them here. */
  407. variable_all_del();
  408. if (yynerrs)
  409. exit(1);
  410. if (!modules_sym)
  411. modules_sym = sym_find( "n" );
  412. if (!menu_has_prompt(&rootmenu)) {
  413. current_entry = &rootmenu;
  414. menu_add_prompt(P_MENU, "Main menu", NULL);
  415. }
  416. menu_finalize(&rootmenu);
  417. for_all_symbols(i, sym) {
  418. if (sym_check_deps(sym))
  419. yynerrs++;
  420. }
  421. if (yynerrs)
  422. exit(1);
  423. conf_set_changed(true);
  424. }
  425. static bool zconf_endtoken(const char *tokenname,
  426. const char *expected_tokenname)
  427. {
  428. if (strcmp(tokenname, expected_tokenname)) {
  429. zconf_error("unexpected '%s' within %s block",
  430. tokenname, expected_tokenname);
  431. yynerrs++;
  432. return false;
  433. }
  434. if (current_menu->file != current_file) {
  435. zconf_error("'%s' in different file than '%s'",
  436. tokenname, expected_tokenname);
  437. fprintf(stderr, "%s:%d: location of the '%s'\n",
  438. current_menu->file->name, current_menu->lineno,
  439. expected_tokenname);
  440. yynerrs++;
  441. return false;
  442. }
  443. return true;
  444. }
  445. static void zconfprint(const char *err, ...)
  446. {
  447. va_list ap;
  448. fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
  449. va_start(ap, err);
  450. vfprintf(stderr, err, ap);
  451. va_end(ap);
  452. fprintf(stderr, "\n");
  453. }
  454. static void zconf_error(const char *err, ...)
  455. {
  456. va_list ap;
  457. yynerrs++;
  458. fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
  459. va_start(ap, err);
  460. vfprintf(stderr, err, ap);
  461. va_end(ap);
  462. fprintf(stderr, "\n");
  463. }
  464. static void yyerror(const char *err)
  465. {
  466. fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
  467. }
  468. static void print_quoted_string(FILE *out, const char *str)
  469. {
  470. const char *p;
  471. int len;
  472. putc('"', out);
  473. while ((p = strchr(str, '"'))) {
  474. len = p - str;
  475. if (len)
  476. fprintf(out, "%.*s", len, str);
  477. fputs("\\\"", out);
  478. str = p + 1;
  479. }
  480. fputs(str, out);
  481. putc('"', out);
  482. }
  483. static void print_symbol(FILE *out, struct menu *menu)
  484. {
  485. struct symbol *sym = menu->sym;
  486. struct property *prop;
  487. if (sym_is_choice(sym))
  488. fprintf(out, "\nchoice\n");
  489. else
  490. fprintf(out, "\nconfig %s\n", sym->name);
  491. switch (sym->type) {
  492. case S_BOOLEAN:
  493. fputs(" bool\n", out);
  494. break;
  495. case S_TRISTATE:
  496. fputs(" tristate\n", out);
  497. break;
  498. case S_STRING:
  499. fputs(" string\n", out);
  500. break;
  501. case S_INT:
  502. fputs(" integer\n", out);
  503. break;
  504. case S_HEX:
  505. fputs(" hex\n", out);
  506. break;
  507. default:
  508. fputs(" ???\n", out);
  509. break;
  510. }
  511. for (prop = sym->prop; prop; prop = prop->next) {
  512. if (prop->menu != menu)
  513. continue;
  514. switch (prop->type) {
  515. case P_PROMPT:
  516. fputs(" prompt ", out);
  517. print_quoted_string(out, prop->text);
  518. if (!expr_is_yes(prop->visible.expr)) {
  519. fputs(" if ", out);
  520. expr_fprint(prop->visible.expr, out);
  521. }
  522. fputc('\n', out);
  523. break;
  524. case P_DEFAULT:
  525. fputs( " default ", out);
  526. expr_fprint(prop->expr, out);
  527. if (!expr_is_yes(prop->visible.expr)) {
  528. fputs(" if ", out);
  529. expr_fprint(prop->visible.expr, out);
  530. }
  531. fputc('\n', out);
  532. break;
  533. case P_CHOICE:
  534. fputs(" #choice value\n", out);
  535. break;
  536. case P_SELECT:
  537. fputs( " select ", out);
  538. expr_fprint(prop->expr, out);
  539. fputc('\n', out);
  540. break;
  541. case P_IMPLY:
  542. fputs( " imply ", out);
  543. expr_fprint(prop->expr, out);
  544. fputc('\n', out);
  545. break;
  546. case P_RANGE:
  547. fputs( " range ", out);
  548. expr_fprint(prop->expr, out);
  549. fputc('\n', out);
  550. break;
  551. case P_MENU:
  552. fputs( " menu ", out);
  553. print_quoted_string(out, prop->text);
  554. fputc('\n', out);
  555. break;
  556. case P_SYMBOL:
  557. fputs( " symbol ", out);
  558. fprintf(out, "%s\n", prop->menu->sym->name);
  559. break;
  560. default:
  561. fprintf(out, " unknown prop %d!\n", prop->type);
  562. break;
  563. }
  564. }
  565. if (menu->help) {
  566. int len = strlen(menu->help);
  567. while (menu->help[--len] == '\n')
  568. menu->help[len] = 0;
  569. fprintf(out, " help\n%s\n", menu->help);
  570. }
  571. }
  572. void zconfdump(FILE *out)
  573. {
  574. struct property *prop;
  575. struct symbol *sym;
  576. struct menu *menu;
  577. menu = rootmenu.list;
  578. while (menu) {
  579. if ((sym = menu->sym))
  580. print_symbol(out, menu);
  581. else if ((prop = menu->prompt)) {
  582. switch (prop->type) {
  583. case P_COMMENT:
  584. fputs("\ncomment ", out);
  585. print_quoted_string(out, prop->text);
  586. fputs("\n", out);
  587. break;
  588. case P_MENU:
  589. fputs("\nmenu ", out);
  590. print_quoted_string(out, prop->text);
  591. fputs("\n", out);
  592. break;
  593. default:
  594. ;
  595. }
  596. if (!expr_is_yes(prop->visible.expr)) {
  597. fputs(" depends ", out);
  598. expr_fprint(prop->visible.expr, out);
  599. fputc('\n', out);
  600. }
  601. }
  602. if (menu->list)
  603. menu = menu->list;
  604. else if (menu->next)
  605. menu = menu->next;
  606. else while ((menu = menu->parent)) {
  607. if (menu->prompt && menu->prompt->type == P_MENU)
  608. fputs("\nendmenu\n", out);
  609. if (menu->next) {
  610. menu = menu->next;
  611. break;
  612. }
  613. }
  614. }
  615. }