mconf.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. /*
  2. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3. * Released under the terms of the GNU GPL v2.0.
  4. *
  5. * Introduced single menu mode (show all sub-menus in one large tree).
  6. * 2002-11-06 Petr Baudis <pasky@ucw.cz>
  7. *
  8. * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  9. */
  10. #include <ctype.h>
  11. #include <errno.h>
  12. #include <fcntl.h>
  13. #include <limits.h>
  14. #include <stdarg.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <unistd.h>
  18. #include <locale.h>
  19. #define LKC_DIRECT_LINK
  20. #include "lkc.h"
  21. #include "lxdialog/dialog.h"
  22. static const char mconf_readme[] = N_(
  23. "Overview\n"
  24. "--------\n"
  25. "Some features may be built directly into uClibc. Some features\n"
  26. "may be completely removed altogether. There are also certain\n"
  27. "parameters which are not really features, but must be\n"
  28. "entered in as decimal or hexadecimal numbers or possibly text.\n"
  29. "\n"
  30. "Menu items beginning with following braces represent features that\n"
  31. " [ ] can be built in or removed\n"
  32. " < > can be built in, modularized or removed\n"
  33. " { } can be built in or modularized (selected by other feature)\n"
  34. " - - are selected by other feature,\n"
  35. "while *, M or whitespace inside braces means to build in, build as\n"
  36. "a module or to exclude the feature respectively.\n"
  37. "\n"
  38. "To change any of these features, highlight it with the cursor\n"
  39. "keys and press <Y> to build it in, <M> to make it a module or\n"
  40. "<N> to removed it. You may also press the <Space Bar> to cycle\n"
  41. "through the available options (ie. Y->N->M->Y).\n"
  42. "\n"
  43. "Some additional keyboard hints:\n"
  44. "\n"
  45. "Menus\n"
  46. "----------\n"
  47. "o Use the Up/Down arrow keys (cursor keys) to highlight the item\n"
  48. " you wish to change or submenu wish to select and press <Enter>.\n"
  49. " Submenus are designated by \"--->\".\n"
  50. "\n"
  51. " Shortcut: Press the option's highlighted letter (hotkey).\n"
  52. " Pressing a hotkey more than once will sequence\n"
  53. " through all visible items which use that hotkey.\n"
  54. "\n"
  55. " You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n"
  56. " unseen options into view.\n"
  57. "\n"
  58. "o To exit a menu use the cursor keys to highlight the <Exit> button\n"
  59. " and press <ENTER>.\n"
  60. "\n"
  61. " Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n"
  62. " using those letters. You may press a single <ESC>, but\n"
  63. " there is a delayed response which you may find annoying.\n"
  64. "\n"
  65. " Also, the <TAB> and cursor keys will cycle between <Select>,\n"
  66. " <Exit> and <Help>\n"
  67. "\n"
  68. "o To get help with an item, use the cursor keys to highlight <Help>\n"
  69. " and Press <ENTER>.\n"
  70. "\n"
  71. " Shortcut: Press <H> or <?>.\n"
  72. "\n"
  73. "\n"
  74. "Radiolists (Choice lists)\n"
  75. "-----------\n"
  76. "o Use the cursor keys to select the option you wish to set and press\n"
  77. " <S> or the <SPACE BAR>.\n"
  78. "\n"
  79. " Shortcut: Press the first letter of the option you wish to set then\n"
  80. " press <S> or <SPACE BAR>.\n"
  81. "\n"
  82. "o To see available help for the item, use the cursor keys to highlight\n"
  83. " <Help> and Press <ENTER>.\n"
  84. "\n"
  85. " Shortcut: Press <H> or <?>.\n"
  86. "\n"
  87. " Also, the <TAB> and cursor keys will cycle between <Select> and\n"
  88. " <Help>\n"
  89. "\n"
  90. "\n"
  91. "Data Entry\n"
  92. "-----------\n"
  93. "o Enter the requested information and press <ENTER>\n"
  94. " If you are entering hexadecimal values, it is not necessary to\n"
  95. " add the '0x' prefix to the entry.\n"
  96. "\n"
  97. "o For help, use the <TAB> or cursor keys to highlight the help option\n"
  98. " and press <ENTER>. You can try <TAB><H> as well.\n"
  99. "\n"
  100. "\n"
  101. "Text Box (Help Window)\n"
  102. "--------\n"
  103. "o Use the cursor keys to scroll up/down/left/right. The VI editor\n"
  104. " keys h,j,k,l function here as do <SPACE BAR> and <B> for those\n"
  105. " who are familiar with less and lynx.\n"
  106. "\n"
  107. "o Press <E>, <X>, <Enter> or <Esc><Esc> to exit.\n"
  108. "\n"
  109. "\n"
  110. "Alternate Configuration Files\n"
  111. "-----------------------------\n"
  112. "Menuconfig supports the use of alternate configuration files for\n"
  113. "those who, for various reasons, find it necessary to switch\n"
  114. "between different configurations.\n"
  115. "\n"
  116. "At the end of the main menu you will find two options. One is\n"
  117. "for saving the current configuration to a file of your choosing.\n"
  118. "The other option is for loading a previously saved alternate\n"
  119. "configuration.\n"
  120. "\n"
  121. "Even if you don't use alternate configuration files, but you\n"
  122. "find during a Menuconfig session that you have completely messed\n"
  123. "up your settings, you may use the \"Load Alternate...\" option to\n"
  124. "restore your previously saved settings from \".config\" without\n"
  125. "restarting Menuconfig.\n"
  126. "\n"
  127. "Other information\n"
  128. "-----------------\n"
  129. "If you use Menuconfig in an XTERM window make sure you have your\n"
  130. "$TERM variable set to point to a xterm definition which supports color.\n"
  131. "Otherwise, Menuconfig will look rather bad. Menuconfig will not\n"
  132. "display correctly in a RXVT window because rxvt displays only one\n"
  133. "intensity of color, bright.\n"
  134. "\n"
  135. "Menuconfig will display larger menus on screens or xterms which are\n"
  136. "set to display more than the standard 25 row by 80 column geometry.\n"
  137. "In order for this to work, the \"stty size\" command must be able to\n"
  138. "display the screen's current row and column geometry. I STRONGLY\n"
  139. "RECOMMEND that you make sure you do NOT have the shell variables\n"
  140. "LINES and COLUMNS exported into your environment. Some distributions\n"
  141. "export those variables via /etc/profile. Some ncurses programs can\n"
  142. "become confused when those variables (LINES & COLUMNS) don't reflect\n"
  143. "the true screen size.\n"
  144. "\n"
  145. "Optional personality available\n"
  146. "------------------------------\n"
  147. "If you prefer to have all of the options listed in a single\n"
  148. "menu, rather than the default multimenu hierarchy, run the menuconfig\n"
  149. "with MENUCONFIG_MODE environment variable set to single_menu. Example:\n"
  150. "\n"
  151. "make MENUCONFIG_MODE=single_menu menuconfig\n"
  152. "\n"
  153. "<Enter> will then unroll the appropriate category, or enfold it if it\n"
  154. "is already unrolled.\n"
  155. "\n"
  156. "Note that this mode can eventually be a little more CPU expensive\n"
  157. "(especially with a larger number of unrolled categories) than the\n"
  158. "default mode.\n"
  159. "\n"
  160. "Different color themes available\n"
  161. "--------------------------------\n"
  162. "It is possible to select different color themes using the variable\n"
  163. "MENUCONFIG_COLOR. To select a theme use:\n"
  164. "\n"
  165. "make MENUCONFIG_COLOR=<theme> menuconfig\n"
  166. "\n"
  167. "Available themes are\n"
  168. " mono => selects colors suitable for monochrome displays\n"
  169. " blackbg => selects a color scheme with black background\n"
  170. " classic => theme with blue background. The classic look\n"
  171. " bluetitle => a LCD friendly version of classic. (default)\n"
  172. "\n"),
  173. menu_instructions[] = N_(
  174. "Arrow keys navigate the menu. "
  175. "<Enter> selects submenus --->. "
  176. "Highlighted letters are hotkeys. "
  177. "Pressing <Y> selectes a feature, while <N> will exclude a feature. "
  178. "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
  179. "Legend: [*] feature is selected [ ] feature is excluded"),
  180. radiolist_instructions[] = N_(
  181. "Use the arrow keys to navigate this window or "
  182. "press the hotkey of the item you wish to select "
  183. "followed by the <SPACE BAR>. "
  184. "Press <?> for additional information about this option."),
  185. inputbox_instructions_int[] = N_(
  186. "Please enter a decimal value. "
  187. "Fractions will not be accepted. "
  188. "Use the <TAB> key to move from the input field to the buttons below it."),
  189. inputbox_instructions_hex[] = N_(
  190. "Please enter a hexadecimal value. "
  191. "Use the <TAB> key to move from the input field to the buttons below it."),
  192. inputbox_instructions_string[] = N_(
  193. "Please enter a string value. "
  194. "Use the <TAB> key to move from the input field to the buttons below it."),
  195. setmod_text[] = N_(
  196. "This feature depends on another which has been configured as a module.\n"
  197. "As a result, this feature will be built as a module."),
  198. nohelp_text[] = N_(
  199. "There is no help available for this option.\n"),
  200. load_config_text[] = N_(
  201. "Enter the name of the configuration file you wish to load. "
  202. "Accept the name shown to restore the configuration you "
  203. "last retrieved. Leave blank to abort."),
  204. load_config_help[] = N_(
  205. "\n"
  206. "For various reasons, one may wish to keep several different\n"
  207. "configurations available on a single machine.\n"
  208. "\n"
  209. "If you have saved a previous configuration in a file other than the\n"
  210. "default, entering the name of the file here will allow you\n"
  211. "to modify that configuration.\n"
  212. "\n"
  213. "If you are uncertain, then you have probably never used alternate\n"
  214. "configuration files. You should therefor leave this blank to abort.\n"),
  215. save_config_text[] = N_(
  216. "Enter a filename to which this configuration should be saved "
  217. "as an alternate. Leave blank to abort."),
  218. save_config_help[] = N_(
  219. "\n"
  220. "For various reasons, one may wish to keep different\n"
  221. "configurations available on a single machine.\n"
  222. "\n"
  223. "Entering a file name here will allow you to later retrieve, modify\n"
  224. "and use the current configuration as an alternate to whatever\n"
  225. "configuration options you have selected at that time.\n"
  226. "\n"
  227. "If you are uncertain what all this means then you should probably\n"
  228. "leave this blank.\n"),
  229. search_help[] = N_(
  230. "\n"
  231. "Search for CONFIG_ symbols and display their relations.\n"
  232. "Regular expressions are allowed.\n"
  233. "Example: search for \"^FOO\"\n"
  234. "Result:\n"
  235. "-----------------------------------------------------------------\n"
  236. "Symbol: FOO [=m]\n"
  237. "Prompt: Foo bus is used to drive the bar HW\n"
  238. "Defined at drivers/pci/Kconfig:47\n"
  239. "Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
  240. "Location:\n"
  241. " -> Bus options (PCI, PCMCIA, EISA, MCA, ISA)\n"
  242. " -> PCI support (PCI [=y])\n"
  243. " -> PCI access mode (<choice> [=y])\n"
  244. "Selects: LIBCRC32\n"
  245. "Selected by: BAR\n"
  246. "-----------------------------------------------------------------\n"
  247. "o The line 'Prompt:' shows the text used in the menu structure for\n"
  248. " this CONFIG_ symbol\n"
  249. "o The 'Defined at' line tell at what file / line number the symbol\n"
  250. " is defined\n"
  251. "o The 'Depends on:' line tell what symbols needs to be defined for\n"
  252. " this symbol to be visible in the menu (selectable)\n"
  253. "o The 'Location:' lines tell where in the menu structure this symbol\n"
  254. " is located\n"
  255. " A location followed by a [=y] indicate that this is a selectable\n"
  256. " menu item - and current value is displayed inside brackets.\n"
  257. "o The 'Selects:' line tell what symbol will be automatically\n"
  258. " selected if this symbol is selected (y or m)\n"
  259. "o The 'Selected by' line tell what symbol has selected this symbol\n"
  260. "\n"
  261. "Only relevant lines are shown.\n"
  262. "\n\n"
  263. "Search examples:\n"
  264. "Examples: USB => find all CONFIG_ symbols containing USB\n"
  265. " ^USB => find all CONFIG_ symbols starting with USB\n"
  266. " USB$ => find all CONFIG_ symbols ending with USB\n"
  267. "\n");
  268. static int indent;
  269. static struct menu *current_menu;
  270. static int child_count;
  271. static int single_menu_mode;
  272. static void conf(struct menu *menu);
  273. static void conf_choice(struct menu *menu);
  274. static void conf_string(struct menu *menu);
  275. static void conf_load(void);
  276. static void conf_save(void);
  277. static void show_textbox(const char *title, const char *text, int r, int c);
  278. static void show_helptext(const char *title, const char *text);
  279. static void show_help(struct menu *menu);
  280. static void get_prompt_str(struct gstr *r, struct property *prop)
  281. {
  282. int i, j;
  283. struct menu *submenu[8], *menu;
  284. str_printf(r, _("Prompt: %s\n"), _(prop->text));
  285. str_printf(r, _(" Defined at %s:%d\n"), prop->menu->file->name,
  286. prop->menu->lineno);
  287. if (!expr_is_yes(prop->visible.expr)) {
  288. str_append(r, _(" Depends on: "));
  289. expr_gstr_print(prop->visible.expr, r);
  290. str_append(r, "\n");
  291. }
  292. menu = prop->menu->parent;
  293. for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent)
  294. submenu[i++] = menu;
  295. if (i > 0) {
  296. str_printf(r, _(" Location:\n"));
  297. for (j = 4; --i >= 0; j += 2) {
  298. menu = submenu[i];
  299. str_printf(r, "%*c-> %s", j, ' ', _(menu_get_prompt(menu)));
  300. if (menu->sym) {
  301. str_printf(r, " (%s [=%s])", menu->sym->name ?
  302. menu->sym->name : _("<choice>"),
  303. sym_get_string_value(menu->sym));
  304. }
  305. str_append(r, "\n");
  306. }
  307. }
  308. }
  309. static void get_symbol_str(struct gstr *r, struct symbol *sym)
  310. {
  311. bool hit;
  312. struct property *prop;
  313. if (sym && sym->name)
  314. str_printf(r, "Symbol: %s [=%s]\n", sym->name,
  315. sym_get_string_value(sym));
  316. for_all_prompts(sym, prop)
  317. get_prompt_str(r, prop);
  318. hit = false;
  319. for_all_properties(sym, prop, P_SELECT) {
  320. if (!hit) {
  321. str_append(r, " Selects: ");
  322. hit = true;
  323. } else
  324. str_printf(r, " && ");
  325. expr_gstr_print(prop->expr, r);
  326. }
  327. if (hit)
  328. str_append(r, "\n");
  329. if (sym->rev_dep.expr) {
  330. str_append(r, _(" Selected by: "));
  331. expr_gstr_print(sym->rev_dep.expr, r);
  332. str_append(r, "\n");
  333. }
  334. str_append(r, "\n\n");
  335. }
  336. static struct gstr get_relations_str(struct symbol **sym_arr)
  337. {
  338. struct symbol *sym;
  339. struct gstr res = str_new();
  340. int i;
  341. for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
  342. get_symbol_str(&res, sym);
  343. if (!i)
  344. str_append(&res, _("No matches found.\n"));
  345. return res;
  346. }
  347. static char filename[PATH_MAX+1];
  348. static void set_config_filename(const char *config_filename)
  349. {
  350. static char menu_backtitle[PATH_MAX+128];
  351. int size;
  352. struct symbol *sym;
  353. sym = sym_lookup("VERSION", 0);
  354. sym_calc_value(sym);
  355. size = snprintf(menu_backtitle, sizeof(menu_backtitle),
  356. _("%s - uClibc v%s Configuration"),
  357. config_filename, sym_get_string_value(sym));
  358. if (size >= sizeof(menu_backtitle))
  359. menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
  360. set_dialog_backtitle(menu_backtitle);
  361. size = snprintf(filename, sizeof(filename), "%s", config_filename);
  362. if (size >= sizeof(filename))
  363. filename[sizeof(filename)-1] = '\0';
  364. }
  365. static void search_conf(void)
  366. {
  367. struct symbol **sym_arr;
  368. struct gstr res;
  369. char *dialog_input;
  370. int dres;
  371. again:
  372. dialog_clear();
  373. dres = dialog_inputbox(_("Search Configuration Parameter"),
  374. _("Enter CONFIG_ (sub)string to search for "
  375. "(with or without \"CONFIG\")"),
  376. 10, 75, "");
  377. switch (dres) {
  378. case 0:
  379. break;
  380. case 1:
  381. show_helptext(_("Search Configuration"), search_help);
  382. goto again;
  383. default:
  384. return;
  385. }
  386. /* strip CONFIG_ if necessary */
  387. dialog_input = dialog_input_result;
  388. if (strncasecmp(dialog_input_result, "CONFIG_", 7) == 0)
  389. dialog_input += 7;
  390. sym_arr = sym_re_search(dialog_input);
  391. res = get_relations_str(sym_arr);
  392. free(sym_arr);
  393. show_textbox(_("Search Results"), str_get(&res), 0, 0);
  394. str_free(&res);
  395. }
  396. static void build_conf(struct menu *menu)
  397. {
  398. struct symbol *sym;
  399. struct property *prop;
  400. struct menu *child;
  401. int type, tmp, doint = 2;
  402. tristate val;
  403. char ch;
  404. if (!menu_is_visible(menu))
  405. return;
  406. sym = menu->sym;
  407. prop = menu->prompt;
  408. if (!sym) {
  409. if (prop && menu != current_menu) {
  410. const char *prompt = menu_get_prompt(menu);
  411. switch (prop->type) {
  412. case P_MENU:
  413. child_count++;
  414. prompt = _(prompt);
  415. if (single_menu_mode) {
  416. item_make("%s%*c%s",
  417. menu->data ? "-->" : "++>",
  418. indent + 1, ' ', prompt);
  419. } else
  420. item_make(" %*c%s --->", indent + 1, ' ', prompt);
  421. item_set_tag('m');
  422. item_set_data(menu);
  423. if (single_menu_mode && menu->data)
  424. goto conf_childs;
  425. return;
  426. case P_COMMENT:
  427. if (prompt) {
  428. child_count++;
  429. item_make(" %*c*** %s ***", indent + 1, ' ', _(prompt));
  430. item_set_tag(':');
  431. item_set_data(menu);
  432. }
  433. break;
  434. default:
  435. if (prompt) {
  436. child_count++;
  437. item_make("---%*c%s", indent + 1, ' ', _(prompt));
  438. item_set_tag(':');
  439. item_set_data(menu);
  440. }
  441. }
  442. } else
  443. doint = 0;
  444. goto conf_childs;
  445. }
  446. type = sym_get_type(sym);
  447. if (sym_is_choice(sym)) {
  448. struct symbol *def_sym = sym_get_choice_value(sym);
  449. struct menu *def_menu = NULL;
  450. child_count++;
  451. for (child = menu->list; child; child = child->next) {
  452. if (menu_is_visible(child) && child->sym == def_sym)
  453. def_menu = child;
  454. }
  455. val = sym_get_tristate_value(sym);
  456. if (sym_is_changable(sym)) {
  457. switch (type) {
  458. case S_BOOLEAN:
  459. item_make("[%c]", val == no ? ' ' : '*');
  460. break;
  461. case S_TRISTATE:
  462. switch (val) {
  463. case yes: ch = '*'; break;
  464. case mod: ch = 'M'; break;
  465. default: ch = ' '; break;
  466. }
  467. item_make("<%c>", ch);
  468. break;
  469. }
  470. item_set_tag('t');
  471. item_set_data(menu);
  472. } else {
  473. item_make(" ");
  474. item_set_tag(def_menu ? 't' : ':');
  475. item_set_data(menu);
  476. }
  477. item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
  478. if (val == yes) {
  479. if (def_menu) {
  480. item_add_str(" (%s)", _(menu_get_prompt(def_menu)));
  481. item_add_str(" --->");
  482. if (def_menu->list) {
  483. indent += 2;
  484. build_conf(def_menu);
  485. indent -= 2;
  486. }
  487. }
  488. return;
  489. }
  490. } else {
  491. if (menu == current_menu) {
  492. item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
  493. item_set_tag(':');
  494. item_set_data(menu);
  495. goto conf_childs;
  496. }
  497. child_count++;
  498. val = sym_get_tristate_value(sym);
  499. if (sym_is_choice_value(sym) && val == yes) {
  500. item_make(" ");
  501. item_set_tag(':');
  502. item_set_data(menu);
  503. } else {
  504. switch (type) {
  505. case S_BOOLEAN:
  506. if (sym_is_changable(sym))
  507. item_make("[%c]", val == no ? ' ' : '*');
  508. else
  509. item_make("-%c-", val == no ? ' ' : '*');
  510. item_set_tag('t');
  511. item_set_data(menu);
  512. break;
  513. case S_TRISTATE:
  514. switch (val) {
  515. case yes: ch = '*'; break;
  516. case mod: ch = 'M'; break;
  517. default: ch = ' '; break;
  518. }
  519. if (sym_is_changable(sym)) {
  520. if (sym->rev_dep.tri == mod)
  521. item_make("{%c}", ch);
  522. else
  523. item_make("<%c>", ch);
  524. } else
  525. item_make("-%c-", ch);
  526. item_set_tag('t');
  527. item_set_data(menu);
  528. break;
  529. default:
  530. tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
  531. item_make("(%s)", sym_get_string_value(sym));
  532. tmp = indent - tmp + 4;
  533. if (tmp < 0)
  534. tmp = 0;
  535. item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)),
  536. (sym_has_value(sym) || !sym_is_changable(sym)) ?
  537. "" : _(" (NEW)"));
  538. item_set_tag('s');
  539. item_set_data(menu);
  540. goto conf_childs;
  541. }
  542. }
  543. item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)),
  544. (sym_has_value(sym) || !sym_is_changable(sym)) ?
  545. "" : _(" (NEW)"));
  546. if (menu->prompt->type == P_MENU) {
  547. item_add_str(" --->");
  548. return;
  549. }
  550. }
  551. conf_childs:
  552. indent += doint;
  553. for (child = menu->list; child; child = child->next)
  554. build_conf(child);
  555. indent -= doint;
  556. }
  557. static void conf(struct menu *menu)
  558. {
  559. struct menu *submenu;
  560. const char *prompt = menu_get_prompt(menu);
  561. struct symbol *sym;
  562. struct menu *active_menu = NULL;
  563. int res;
  564. int s_scroll = 0;
  565. while (1) {
  566. item_reset();
  567. current_menu = menu;
  568. build_conf(menu);
  569. if (!child_count)
  570. break;
  571. if (menu == &rootmenu) {
  572. item_make("--- ");
  573. item_set_tag(':');
  574. item_make(_(" Load an Alternate Configuration File"));
  575. item_set_tag('L');
  576. item_make(_(" Save an Alternate Configuration File"));
  577. item_set_tag('S');
  578. }
  579. dialog_clear();
  580. res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
  581. _(menu_instructions),
  582. active_menu, &s_scroll);
  583. if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
  584. break;
  585. if (!item_activate_selected())
  586. continue;
  587. if (!item_tag())
  588. continue;
  589. submenu = item_data();
  590. active_menu = item_data();
  591. if (submenu)
  592. sym = submenu->sym;
  593. else
  594. sym = NULL;
  595. switch (res) {
  596. case 0:
  597. switch (item_tag()) {
  598. case 'm':
  599. if (single_menu_mode)
  600. submenu->data = (void *) (long) !submenu->data;
  601. else
  602. conf(submenu);
  603. break;
  604. case 't':
  605. if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
  606. conf_choice(submenu);
  607. else if (submenu->prompt->type == P_MENU)
  608. conf(submenu);
  609. break;
  610. case 's':
  611. conf_string(submenu);
  612. break;
  613. case 'L':
  614. conf_load();
  615. break;
  616. case 'S':
  617. conf_save();
  618. break;
  619. }
  620. break;
  621. case 2:
  622. if (sym)
  623. show_help(submenu);
  624. else
  625. show_helptext(_("README"), _(mconf_readme));
  626. break;
  627. case 3:
  628. if (item_is_tag('t')) {
  629. if (sym_set_tristate_value(sym, yes))
  630. break;
  631. if (sym_set_tristate_value(sym, mod))
  632. show_textbox(NULL, setmod_text, 6, 74);
  633. }
  634. break;
  635. case 4:
  636. if (item_is_tag('t'))
  637. sym_set_tristate_value(sym, no);
  638. break;
  639. case 5:
  640. if (item_is_tag('t'))
  641. sym_set_tristate_value(sym, mod);
  642. break;
  643. case 6:
  644. if (item_is_tag('t'))
  645. sym_toggle_tristate_value(sym);
  646. else if (item_is_tag('m'))
  647. conf(submenu);
  648. break;
  649. case 7:
  650. search_conf();
  651. break;
  652. }
  653. }
  654. }
  655. static void show_textbox(const char *title, const char *text, int r, int c)
  656. {
  657. dialog_clear();
  658. dialog_textbox(title, text, r, c);
  659. }
  660. static void show_helptext(const char *title, const char *text)
  661. {
  662. show_textbox(title, text, 0, 0);
  663. }
  664. static void show_help(struct menu *menu)
  665. {
  666. struct gstr help = str_new();
  667. struct symbol *sym = menu->sym;
  668. if (menu_has_help(menu))
  669. {
  670. if (sym->name) {
  671. str_printf(&help, "%s:\n\n", sym->name);
  672. }
  673. str_append(&help, _(menu_get_help(menu)));
  674. str_append(&help, "\n");
  675. } else if (menu_has_help(sym->prop->menu->parent)) {
  676. str_append(&help, _(menu_get_help(sym->prop->menu->parent)));
  677. str_append(&help, "\n");
  678. } else {
  679. str_append(&help, nohelp_text);
  680. }
  681. get_symbol_str(&help, sym);
  682. show_helptext(_(menu_get_prompt(menu)), str_get(&help));
  683. str_free(&help);
  684. }
  685. static void conf_choice(struct menu *menu)
  686. {
  687. const char *prompt = _(menu_get_prompt(menu));
  688. struct menu *child;
  689. struct symbol *active;
  690. active = sym_get_choice_value(menu->sym);
  691. while (1) {
  692. int res;
  693. int selected;
  694. item_reset();
  695. current_menu = menu;
  696. for (child = menu->list; child; child = child->next) {
  697. if (!menu_is_visible(child))
  698. continue;
  699. item_make("%s", _(menu_get_prompt(child)));
  700. item_set_data(child);
  701. if (child->sym == active)
  702. item_set_selected(1);
  703. if (child->sym == sym_get_choice_value(menu->sym))
  704. item_set_tag('X');
  705. }
  706. dialog_clear();
  707. res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
  708. _(radiolist_instructions),
  709. 15, 70, 6);
  710. selected = item_activate_selected();
  711. switch (res) {
  712. case 0:
  713. if (selected) {
  714. child = item_data();
  715. sym_set_tristate_value(child->sym, yes);
  716. }
  717. return;
  718. case 1:
  719. if (selected) {
  720. child = item_data();
  721. show_help(child);
  722. active = child->sym;
  723. } else
  724. show_help(menu);
  725. break;
  726. case KEY_ESC:
  727. return;
  728. case -ERRDISPLAYTOOSMALL:
  729. return;
  730. }
  731. }
  732. }
  733. static void conf_string(struct menu *menu)
  734. {
  735. const char *prompt = menu_get_prompt(menu);
  736. while (1) {
  737. int res;
  738. const char *heading;
  739. switch (sym_get_type(menu->sym)) {
  740. case S_INT:
  741. heading = _(inputbox_instructions_int);
  742. break;
  743. case S_HEX:
  744. heading = _(inputbox_instructions_hex);
  745. break;
  746. case S_STRING:
  747. heading = _(inputbox_instructions_string);
  748. break;
  749. default:
  750. heading = _("Internal mconf error!");
  751. }
  752. dialog_clear();
  753. res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
  754. heading, 10, 75,
  755. sym_get_string_value(menu->sym));
  756. switch (res) {
  757. case 0:
  758. if (sym_set_string_value(menu->sym, dialog_input_result))
  759. return;
  760. show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
  761. break;
  762. case 1:
  763. show_help(menu);
  764. break;
  765. case KEY_ESC:
  766. return;
  767. }
  768. }
  769. }
  770. static void conf_load(void)
  771. {
  772. while (1) {
  773. int res;
  774. dialog_clear();
  775. res = dialog_inputbox(NULL, load_config_text,
  776. 11, 55, filename);
  777. switch(res) {
  778. case 0:
  779. if (!dialog_input_result[0])
  780. return;
  781. if (!conf_read(dialog_input_result)) {
  782. set_config_filename(dialog_input_result);
  783. sym_set_change_count(1);
  784. return;
  785. }
  786. show_textbox(NULL, _("File does not exist!"), 5, 38);
  787. break;
  788. case 1:
  789. show_helptext(_("Load Alternate Configuration"), load_config_help);
  790. break;
  791. case KEY_ESC:
  792. return;
  793. }
  794. }
  795. }
  796. static void conf_save(void)
  797. {
  798. while (1) {
  799. int res;
  800. dialog_clear();
  801. res = dialog_inputbox(NULL, save_config_text,
  802. 11, 55, filename);
  803. switch(res) {
  804. case 0:
  805. if (!dialog_input_result[0])
  806. return;
  807. if (!conf_write(dialog_input_result)) {
  808. set_config_filename(dialog_input_result);
  809. return;
  810. }
  811. show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60);
  812. break;
  813. case 1:
  814. show_helptext(_("Save Alternate Configuration"), save_config_help);
  815. break;
  816. case KEY_ESC:
  817. return;
  818. }
  819. }
  820. }
  821. int main(int ac, char **av)
  822. {
  823. int saved_x, saved_y;
  824. char *mode;
  825. int res;
  826. setlocale(LC_ALL, "");
  827. bindtextdomain(PACKAGE, LOCALEDIR);
  828. textdomain(PACKAGE);
  829. conf_parse(av[1]);
  830. conf_read(NULL);
  831. mode = getenv("MENUCONFIG_MODE");
  832. if (mode) {
  833. if (!strcasecmp(mode, "single_menu"))
  834. single_menu_mode = 1;
  835. }
  836. getyx(stdscr, saved_y, saved_x);
  837. if (init_dialog(NULL)) {
  838. fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
  839. fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
  840. return 1;
  841. }
  842. set_config_filename(conf_get_configname());
  843. do {
  844. conf(&rootmenu);
  845. dialog_clear();
  846. if (conf_get_changed())
  847. res = dialog_yesno(NULL,
  848. _("Do you wish to save your "
  849. "new configuration?\n"
  850. "<ESC><ESC> to continue."),
  851. 6, 60);
  852. else
  853. res = -1;
  854. } while (res == KEY_ESC);
  855. end_dialog(saved_x, saved_y);
  856. switch (res) {
  857. case 0:
  858. if (conf_write(filename)) {
  859. fprintf(stderr, _("\n\n"
  860. "Error during writing of the configuration.\n"
  861. "Your configuration changes were NOT saved."
  862. "\n\n"));
  863. return 1;
  864. }
  865. case -1:
  866. printf(_("\n\n"
  867. "*** End of configuration.\n"
  868. "*** Execute 'make' to build or try 'make help'."
  869. "\n\n"));
  870. break;
  871. default:
  872. fprintf(stderr, _("\n\n"
  873. "Your configuration changes were NOT saved."
  874. "\n\n"));
  875. }
  876. return conf_write_autoconf();
  877. }