2
0

zconf.y 16 KB

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