zconf.y 16 KB

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