zconf.y 17 KB

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