mconf.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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. #define _XOPEN_SOURCE 700
  11. /* On Darwin, this may be needed to get SIGWINCH: */
  12. #define _DARWIN_C_SOURCE 1
  13. #include <sys/ioctl.h>
  14. #include <sys/wait.h>
  15. #include <ctype.h>
  16. #include <errno.h>
  17. #include <fcntl.h>
  18. #include <limits.h>
  19. #include <signal.h>
  20. #include <stdarg.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <strings.h> /* for strcasecmp */
  24. #include <termios.h>
  25. #include <unistd.h>
  26. #include <locale.h>
  27. #ifndef SIGWINCH
  28. #define SIGWINCH 28
  29. #endif
  30. #define LKC_DIRECT_LINK
  31. #include "lkc.h"
  32. static char menu_backtitle[128];
  33. static const char mconf_readme[] = N_(
  34. "Overview\n"
  35. "--------\n"
  36. "Some features may be built directly into busybox.\n"
  37. "Some may be made into standalone applets. Some features\n"
  38. "may be completely removed altogether. There are also certain\n"
  39. "parameters which are not really features, but must be\n"
  40. "entered in as decimal or hexadecimal numbers or possibly text.\n"
  41. "\n"
  42. "Menu items beginning with [*], <M> or [ ] represent features\n"
  43. "configured to be built in, modularized or removed respectively.\n"
  44. "Pointed brackets <> represent module capable features.\n"
  45. "\n"
  46. "To change any of these features, highlight it with the cursor\n"
  47. "keys and press <Y> to build it in, <M> to make it a module or\n"
  48. "<N> to removed it. You may also press the <Space Bar> to cycle\n"
  49. "through the available options (ie. Y->N->M->Y).\n"
  50. "\n"
  51. "Some additional keyboard hints:\n"
  52. "\n"
  53. "Menus\n"
  54. "----------\n"
  55. "o Use the Up/Down arrow keys (cursor keys) to highlight the item\n"
  56. " you wish to change or submenu wish to select and press <Enter>.\n"
  57. " Submenus are designated by \"--->\".\n"
  58. "\n"
  59. " Shortcut: Press the option's highlighted letter (hotkey).\n"
  60. " Pressing a hotkey more than once will sequence\n"
  61. " through all visible items which use that hotkey.\n"
  62. "\n"
  63. " You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n"
  64. " unseen options into view.\n"
  65. "\n"
  66. "o To exit a menu use the cursor keys to highlight the <Exit> button\n"
  67. " and press <ENTER>.\n"
  68. "\n"
  69. " Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n"
  70. " using those letters. You may press a single <ESC>, but\n"
  71. " there is a delayed response which you may find annoying.\n"
  72. "\n"
  73. " Also, the <TAB> and cursor keys will cycle between <Select>,\n"
  74. " <Exit> and <Help>\n"
  75. "\n"
  76. "o To get help with an item, use the cursor keys to highlight <Help>\n"
  77. " and Press <ENTER>.\n"
  78. "\n"
  79. " Shortcut: Press <H> or <?>.\n"
  80. "\n"
  81. "\n"
  82. "Radiolists (Choice lists)\n"
  83. "-----------\n"
  84. "o Use the cursor keys to select the option you wish to set and press\n"
  85. " <S> or the <SPACE BAR>.\n"
  86. "\n"
  87. " Shortcut: Press the first letter of the option you wish to set then\n"
  88. " press <S> or <SPACE BAR>.\n"
  89. "\n"
  90. "o To see available help for the item, use the cursor keys to highlight\n"
  91. " <Help> and Press <ENTER>.\n"
  92. "\n"
  93. " Shortcut: Press <H> or <?>.\n"
  94. "\n"
  95. " Also, the <TAB> and cursor keys will cycle between <Select> and\n"
  96. " <Help>\n"
  97. "\n"
  98. "\n"
  99. "Data Entry\n"
  100. "-----------\n"
  101. "o Enter the requested information and press <ENTER>\n"
  102. " If you are entering hexadecimal values, it is not necessary to\n"
  103. " add the '0x' prefix to the entry.\n"
  104. "\n"
  105. "o For help, use the <TAB> or cursor keys to highlight the help option\n"
  106. " and press <ENTER>. You can try <TAB><H> as well.\n"
  107. "\n"
  108. "\n"
  109. "Text Box (Help Window)\n"
  110. "--------\n"
  111. "o Use the cursor keys to scroll up/down/left/right. The VI editor\n"
  112. " keys h,j,k,l function here as do <SPACE BAR> and <B> for those\n"
  113. " who are familiar with less and lynx.\n"
  114. "\n"
  115. "o Press <E>, <X>, <Enter> or <Esc><Esc> to exit.\n"
  116. "\n"
  117. "\n"
  118. "Alternate Configuration Files\n"
  119. "-----------------------------\n"
  120. "Menuconfig supports the use of alternate configuration files for\n"
  121. "those who, for various reasons, find it necessary to switch\n"
  122. "between different configurations.\n"
  123. "\n"
  124. "At the end of the main menu you will find two options. One is\n"
  125. "for saving the current configuration to a file of your choosing.\n"
  126. "The other option is for loading a previously saved alternate\n"
  127. "configuration.\n"
  128. "\n"
  129. "Even if you don't use alternate configuration files, but you\n"
  130. "find during a Menuconfig session that you have completely messed\n"
  131. "up your settings, you may use the \"Load Alternate...\" option to\n"
  132. "restore your previously saved settings from \".config\" without\n"
  133. "restarting Menuconfig.\n"
  134. "\n"
  135. "Other information\n"
  136. "-----------------\n"
  137. "If you use Menuconfig in an XTERM window make sure you have your\n"
  138. "$TERM variable set to point to a xterm definition which supports color.\n"
  139. "Otherwise, Menuconfig will look rather bad. Menuconfig will not\n"
  140. "display correctly in a RXVT window because rxvt displays only one\n"
  141. "intensity of color, bright.\n"
  142. "\n"
  143. "Menuconfig will display larger menus on screens or xterms which are\n"
  144. "set to display more than the standard 25 row by 80 column geometry.\n"
  145. "In order for this to work, the \"stty size\" command must be able to\n"
  146. "display the screen's current row and column geometry. I STRONGLY\n"
  147. "RECOMMEND that you make sure you do NOT have the shell variables\n"
  148. "LINES and COLUMNS exported into your environment. Some distributions\n"
  149. "export those variables via /etc/profile. Some ncurses programs can\n"
  150. "become confused when those variables (LINES & COLUMNS) don't reflect\n"
  151. "the true screen size.\n"
  152. "\n"
  153. "Optional personality available\n"
  154. "------------------------------\n"
  155. "If you prefer to have all of the options listed in a single\n"
  156. "menu, rather than the default multimenu hierarchy, run the menuconfig\n"
  157. "with MENUCONFIG_MODE environment variable set to single_menu. Example:\n"
  158. "\n"
  159. "make MENUCONFIG_MODE=single_menu menuconfig\n"
  160. "\n"
  161. "<Enter> will then unroll the appropriate category, or enfold it if it\n"
  162. "is already unrolled.\n"
  163. "\n"
  164. "Note that this mode can eventually be a little more CPU expensive\n"
  165. "(especially with a larger number of unrolled categories) than the\n"
  166. "default mode.\n"),
  167. menu_instructions[] = N_(
  168. "Arrow keys navigate the menu. "
  169. "<Enter> selects submenus --->. "
  170. "Highlighted letters are hotkeys. "
  171. "Pressing <Y> includes, <N> excludes, <M> modularizes features. "
  172. "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
  173. "Legend: [*] built-in [ ] excluded <M> module < > module capable"),
  174. radiolist_instructions[] = N_(
  175. "Use the arrow keys to navigate this window or "
  176. "press the hotkey of the item you wish to select "
  177. "followed by the <SPACE BAR>. "
  178. "Press <?> for additional information about this option."),
  179. inputbox_instructions_int[] = N_(
  180. "Please enter a decimal value. "
  181. "Fractions will not be accepted. "
  182. "Use the <TAB> key to move from the input field to the buttons below it."),
  183. inputbox_instructions_hex[] = N_(
  184. "Please enter a hexadecimal value. "
  185. "Use the <TAB> key to move from the input field to the buttons below it."),
  186. inputbox_instructions_string[] = N_(
  187. "Please enter a string value. "
  188. "Use the <TAB> key to move from the input field to the buttons below it."),
  189. setmod_text[] = N_(
  190. "This feature depends on another which has been configured as a module.\n"
  191. "As a result, this feature will be built as a module."),
  192. nohelp_text[] = N_(
  193. "There is no help available for this option.\n"),
  194. load_config_text[] = N_(
  195. "Enter the name of the configuration file you wish to load. "
  196. "Accept the name shown to restore the configuration you "
  197. "last retrieved. Leave blank to abort."),
  198. load_config_help[] = N_(
  199. "\n"
  200. "For various reasons, one may wish to keep several different\n"
  201. "configurations available on a single machine.\n"
  202. "\n"
  203. "If you have saved a previous configuration in a file other than\n"
  204. "default, entering the name of the file here will allow you\n"
  205. "to modify that configuration.\n"
  206. "\n"
  207. "If you are uncertain, then you have probably never used alternate\n"
  208. "configuration files. You should therefor leave this blank to abort.\n"),
  209. save_config_text[] = N_(
  210. "Enter a filename to which this configuration should be saved "
  211. "as an alternate. Leave blank to abort."),
  212. save_config_help[] = N_(
  213. "\n"
  214. "For various reasons, one may wish to keep different\n"
  215. "configurations available on a single machine.\n"
  216. "\n"
  217. "Entering a file name here will allow you to later retrieve, modify\n"
  218. "and use the current configuration as an alternate to whatever\n"
  219. "configuration options you have selected at that time.\n"
  220. "\n"
  221. "If you are uncertain what all this means then you should probably\n"
  222. "leave this blank.\n"),
  223. search_help[] = N_(
  224. "\n"
  225. "Search for CONFIG_ symbols and display their relations.\n"
  226. "Regular expressions are allowed.\n"
  227. "Example: search for \"^FOO\"\n"
  228. "Result:\n"
  229. "-----------------------------------------------------------------\n"
  230. "Symbol: FOO [=m]\n"
  231. "Prompt: Foo bus is used to drive the bar HW\n"
  232. "Defined at drivers/pci/Kconfig:47\n"
  233. "Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
  234. "Location:\n"
  235. " -> Bus options (PCI, PCMCIA, EISA, MCA, ISA)\n"
  236. " -> PCI support (PCI [=y])\n"
  237. " -> PCI access mode (<choice> [=y])\n"
  238. "Selects: LIBCRC32\n"
  239. "Selected by: BAR\n"
  240. "-----------------------------------------------------------------\n"
  241. "o The line 'Prompt:' shows the text used in the menu structure for\n"
  242. " this CONFIG_ symbol\n"
  243. "o The 'Defined at' line tell at what file / line number the symbol\n"
  244. " is defined\n"
  245. "o The 'Depends on:' line tell what symbols needs to be defined for\n"
  246. " this symbol to be visible in the menu (selectable)\n"
  247. "o The 'Location:' lines tell where in the menu structure this symbol\n"
  248. " is located\n"
  249. " A location followed by a [=y] indicate that this is a selectable\n"
  250. " menu item - and current value is displayed inside brackets.\n"
  251. "o The 'Selects:' line tell what symbol will be automatically\n"
  252. " selected if this symbol is selected (y or m)\n"
  253. "o The 'Selected by' line tell what symbol has selected this symbol\n"
  254. "\n"
  255. "Only relevant lines are shown.\n"
  256. "\n\n"
  257. "Search examples:\n"
  258. "Examples: USB => find all CONFIG_ symbols containing USB\n"
  259. " ^USB => find all CONFIG_ symbols starting with USB\n"
  260. " USB$ => find all CONFIG_ symbols ending with USB\n"
  261. "\n");
  262. static char buf[4096*10], *bufptr = buf;
  263. static char input_buf[4096];
  264. static const char filename[] = ".config";
  265. static char *args[1024], **argptr = args;
  266. static int indent;
  267. static struct termios ios_org;
  268. static int rows = 0, cols = 0;
  269. static struct menu *current_menu;
  270. static int child_count;
  271. static int do_resize;
  272. static int single_menu_mode;
  273. static void conf(struct menu *menu);
  274. static void conf_choice(struct menu *menu);
  275. static void conf_string(struct menu *menu);
  276. static void conf_load(void);
  277. static void conf_save(void);
  278. static void show_textbox(const char *title, const char *text, int r, int c);
  279. static void show_helptext(const char *title, const char *text);
  280. static void show_help(struct menu *menu);
  281. static void show_file(const char *filename, const char *title, int r, int c);
  282. static void cprint_init(void);
  283. static int cprint1(const char *fmt, ...);
  284. static void cprint_done(void);
  285. static int cprint(const char *fmt, ...);
  286. static void init_wsize(void)
  287. {
  288. struct winsize ws;
  289. char *env;
  290. if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) {
  291. rows = ws.ws_row;
  292. cols = ws.ws_col;
  293. }
  294. if (!rows) {
  295. env = getenv("LINES");
  296. if (env)
  297. rows = atoi(env);
  298. if (!rows)
  299. rows = 24;
  300. }
  301. if (!cols) {
  302. env = getenv("COLUMNS");
  303. if (env)
  304. cols = atoi(env);
  305. if (!cols)
  306. cols = 80;
  307. }
  308. if (rows < 19 || cols < 80) {
  309. fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
  310. fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
  311. exit(1);
  312. }
  313. rows -= 4;
  314. cols -= 5;
  315. }
  316. static void cprint_init(void)
  317. {
  318. bufptr = buf;
  319. argptr = args;
  320. memset(args, 0, sizeof(args));
  321. indent = 0;
  322. child_count = 0;
  323. cprint("./scripts/kconfig/lxdialog/lxdialog");
  324. cprint("--backtitle");
  325. cprint(menu_backtitle);
  326. }
  327. static int cprint1(const char *fmt, ...)
  328. {
  329. va_list ap;
  330. int res;
  331. if (!*argptr)
  332. *argptr = bufptr;
  333. va_start(ap, fmt);
  334. res = vsprintf(bufptr, fmt, ap);
  335. va_end(ap);
  336. bufptr += res;
  337. return res;
  338. }
  339. static void cprint_done(void)
  340. {
  341. *bufptr++ = 0;
  342. argptr++;
  343. }
  344. static int cprint(const char *fmt, ...)
  345. {
  346. va_list ap;
  347. int res;
  348. *argptr++ = bufptr;
  349. va_start(ap, fmt);
  350. res = vsprintf(bufptr, fmt, ap);
  351. va_end(ap);
  352. bufptr += res;
  353. *bufptr++ = 0;
  354. return res;
  355. }
  356. static void get_prompt_str(struct gstr *r, struct property *prop)
  357. {
  358. int i, j;
  359. struct menu *submenu[8], *menu;
  360. str_printf(r, "Prompt: %s\n", prop->text);
  361. str_printf(r, " Defined at %s:%d\n", prop->menu->file->name,
  362. prop->menu->lineno);
  363. if (!expr_is_yes(prop->visible.expr)) {
  364. str_append(r, " Depends on: ");
  365. expr_gstr_print(prop->visible.expr, r);
  366. str_append(r, "\n");
  367. }
  368. menu = prop->menu->parent;
  369. for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent)
  370. submenu[i++] = menu;
  371. if (i > 0) {
  372. str_printf(r, " Location:\n");
  373. for (j = 4; --i >= 0; j += 2) {
  374. menu = submenu[i];
  375. str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu));
  376. if (menu->sym) {
  377. str_printf(r, " (%s [=%s])", menu->sym->name ?
  378. menu->sym->name : "<choice>",
  379. sym_get_string_value(menu->sym));
  380. }
  381. str_append(r, "\n");
  382. }
  383. }
  384. }
  385. static void get_symbol_str(struct gstr *r, struct symbol *sym)
  386. {
  387. bool hit;
  388. struct property *prop;
  389. str_printf(r, "Symbol: %s [=%s]\n", sym->name,
  390. sym_get_string_value(sym));
  391. for_all_prompts(sym, prop)
  392. get_prompt_str(r, prop);
  393. hit = false;
  394. for_all_properties(sym, prop, P_SELECT) {
  395. if (!hit) {
  396. str_append(r, " Selects: ");
  397. hit = true;
  398. } else
  399. str_printf(r, " && ");
  400. expr_gstr_print(prop->expr, r);
  401. }
  402. if (hit)
  403. str_append(r, "\n");
  404. if (sym->rev_dep.expr) {
  405. str_append(r, " Selected by: ");
  406. expr_gstr_print(sym->rev_dep.expr, r);
  407. str_append(r, "\n");
  408. }
  409. str_append(r, "\n\n");
  410. }
  411. static struct gstr get_relations_str(struct symbol **sym_arr)
  412. {
  413. struct symbol *sym;
  414. struct gstr res = str_new();
  415. int i;
  416. for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
  417. get_symbol_str(&res, sym);
  418. if (!i)
  419. str_append(&res, "No matches found.\n");
  420. return res;
  421. }
  422. pid_t pid;
  423. #ifdef SIGWINCH
  424. static void winch_handler(int sig)
  425. {
  426. if (!do_resize) {
  427. kill(pid, SIGINT);
  428. do_resize = 1;
  429. }
  430. }
  431. #endif
  432. static int exec_conf(void)
  433. {
  434. int pipefd[2], stat, size;
  435. sigset_t sset, osset;
  436. sigemptyset(&sset);
  437. sigaddset(&sset, SIGINT);
  438. sigprocmask(SIG_BLOCK, &sset, &osset);
  439. signal(SIGINT, SIG_DFL);
  440. #ifdef SIGWINCH
  441. {
  442. struct sigaction sa;
  443. sa.sa_handler = winch_handler;
  444. sigemptyset(&sa.sa_mask);
  445. sa.sa_flags = SA_RESTART;
  446. sigaction(SIGWINCH, &sa, NULL);
  447. }
  448. #endif
  449. *argptr++ = NULL;
  450. pipe(pipefd);
  451. pid = fork();
  452. if (pid == 0) {
  453. sigprocmask(SIG_SETMASK, &osset, NULL);
  454. dup2(pipefd[1], 2);
  455. close(pipefd[0]);
  456. close(pipefd[1]);
  457. execv(args[0], args);
  458. _exit(EXIT_FAILURE);
  459. }
  460. close(pipefd[1]);
  461. bufptr = input_buf;
  462. while (1) {
  463. size = input_buf + sizeof(input_buf) - bufptr;
  464. size = read(pipefd[0], bufptr, size);
  465. if (size <= 0) {
  466. if (size < 0) {
  467. if (errno == EINTR || errno == EAGAIN)
  468. continue;
  469. perror("read");
  470. }
  471. break;
  472. }
  473. bufptr += size;
  474. }
  475. *bufptr++ = 0;
  476. close(pipefd[0]);
  477. waitpid(pid, &stat, 0);
  478. if (do_resize) {
  479. init_wsize();
  480. do_resize = 0;
  481. sigprocmask(SIG_SETMASK, &osset, NULL);
  482. return -1;
  483. }
  484. if (WIFSIGNALED(stat)) {
  485. printf("\finterrupted(%d)\n", WTERMSIG(stat));
  486. exit(1);
  487. }
  488. #if 0
  489. printf("\fexit state: %d\nexit data: '%s'\n", WEXITSTATUS(stat), input_buf);
  490. sleep(1);
  491. #endif
  492. sigpending(&sset);
  493. if (sigismember(&sset, SIGINT)) {
  494. printf("\finterrupted\n");
  495. exit(1);
  496. }
  497. sigprocmask(SIG_SETMASK, &osset, NULL);
  498. return WEXITSTATUS(stat);
  499. }
  500. static void search_conf(void)
  501. {
  502. struct symbol **sym_arr;
  503. int stat;
  504. struct gstr res;
  505. again:
  506. cprint_init();
  507. cprint("--title");
  508. cprint(_("Search Configuration Parameter"));
  509. cprint("--inputbox");
  510. cprint(_("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"));
  511. cprint("10");
  512. cprint("75");
  513. cprint("");
  514. stat = exec_conf();
  515. if (stat < 0)
  516. goto again;
  517. switch (stat) {
  518. case 0:
  519. break;
  520. case 1:
  521. show_helptext(_("Search Configuration"), search_help);
  522. goto again;
  523. default:
  524. return;
  525. }
  526. sym_arr = sym_re_search(input_buf);
  527. res = get_relations_str(sym_arr);
  528. free(sym_arr);
  529. show_textbox(_("Search Results"), str_get(&res), 0, 0);
  530. str_free(&res);
  531. }
  532. static void build_conf(struct menu *menu)
  533. {
  534. struct symbol *sym;
  535. struct property *prop;
  536. struct menu *child;
  537. int type, tmp, doint = 2;
  538. tristate val;
  539. char ch;
  540. if (!menu_is_visible(menu))
  541. return;
  542. sym = menu->sym;
  543. prop = menu->prompt;
  544. if (!sym) {
  545. if (prop && menu != current_menu) {
  546. const char *prompt = menu_get_prompt(menu);
  547. switch (prop->type) {
  548. case P_MENU:
  549. child_count++;
  550. cprint("m%p", menu);
  551. if (single_menu_mode) {
  552. cprint1("%s%*c%s",
  553. menu->data ? "-->" : "++>",
  554. indent + 1, ' ', prompt);
  555. } else
  556. cprint1(" %*c%s --->", indent + 1, ' ', prompt);
  557. cprint_done();
  558. if (single_menu_mode && menu->data)
  559. goto conf_childs;
  560. return;
  561. default:
  562. if (prompt) {
  563. child_count++;
  564. cprint(":%p", menu);
  565. cprint("---%*c%s", indent + 1, ' ', prompt);
  566. }
  567. }
  568. } else
  569. doint = 0;
  570. goto conf_childs;
  571. }
  572. type = sym_get_type(sym);
  573. if (sym_is_choice(sym)) {
  574. struct symbol *def_sym = sym_get_choice_value(sym);
  575. struct menu *def_menu = NULL;
  576. child_count++;
  577. for (child = menu->list; child; child = child->next) {
  578. if (menu_is_visible(child) && child->sym == def_sym)
  579. def_menu = child;
  580. }
  581. val = sym_get_tristate_value(sym);
  582. if (sym_is_changable(sym)) {
  583. cprint("t%p", menu);
  584. switch (type) {
  585. case S_BOOLEAN:
  586. cprint1("[%c]", val == no ? ' ' : '*');
  587. break;
  588. case S_TRISTATE:
  589. switch (val) {
  590. case yes: ch = '*'; break;
  591. case mod: ch = 'M'; break;
  592. default: ch = ' '; break;
  593. }
  594. cprint1("<%c>", ch);
  595. break;
  596. }
  597. } else {
  598. cprint("%c%p", def_menu ? 't' : ':', menu);
  599. cprint1(" ");
  600. }
  601. cprint1("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
  602. if (val == yes) {
  603. if (def_menu) {
  604. cprint1(" (%s)", menu_get_prompt(def_menu));
  605. cprint1(" --->");
  606. cprint_done();
  607. if (def_menu->list) {
  608. indent += 2;
  609. build_conf(def_menu);
  610. indent -= 2;
  611. }
  612. } else
  613. cprint_done();
  614. return;
  615. }
  616. cprint_done();
  617. } else {
  618. if (menu == current_menu) {
  619. cprint(":%p", menu);
  620. cprint("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
  621. goto conf_childs;
  622. }
  623. child_count++;
  624. val = sym_get_tristate_value(sym);
  625. if (sym_is_choice_value(sym) && val == yes) {
  626. cprint(":%p", menu);
  627. cprint1(" ");
  628. } else {
  629. switch (type) {
  630. case S_BOOLEAN:
  631. cprint("t%p", menu);
  632. if (sym_is_changable(sym))
  633. cprint1("[%c]", val == no ? ' ' : '*');
  634. else
  635. cprint1("---");
  636. break;
  637. case S_TRISTATE:
  638. cprint("t%p", menu);
  639. switch (val) {
  640. case yes: ch = '*'; break;
  641. case mod: ch = 'M'; break;
  642. default: ch = ' '; break;
  643. }
  644. if (sym_is_changable(sym))
  645. cprint1("<%c>", ch);
  646. else
  647. cprint1("---");
  648. break;
  649. default:
  650. cprint("s%p", menu);
  651. tmp = cprint1("(%s)", sym_get_string_value(sym));
  652. tmp = indent - tmp + 4;
  653. if (tmp < 0)
  654. tmp = 0;
  655. cprint1("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
  656. (sym_has_value(sym) || !sym_is_changable(sym)) ?
  657. "" : " (NEW)");
  658. cprint_done();
  659. goto conf_childs;
  660. }
  661. }
  662. cprint1("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
  663. (sym_has_value(sym) || !sym_is_changable(sym)) ?
  664. "" : " (NEW)");
  665. if (menu->prompt->type == P_MENU) {
  666. cprint1(" --->");
  667. cprint_done();
  668. return;
  669. }
  670. cprint_done();
  671. }
  672. conf_childs:
  673. indent += doint;
  674. for (child = menu->list; child; child = child->next)
  675. build_conf(child);
  676. indent -= doint;
  677. }
  678. static void conf(struct menu *menu)
  679. {
  680. struct menu *submenu;
  681. const char *prompt = menu_get_prompt(menu);
  682. struct symbol *sym;
  683. char active_entry[40];
  684. int stat, type, i;
  685. unlink("lxdialog.scrltmp");
  686. active_entry[0] = 0;
  687. while (1) {
  688. cprint_init();
  689. cprint("--title");
  690. cprint("%s", prompt ? prompt : _("Main Menu"));
  691. cprint("--menu");
  692. cprint(_(menu_instructions));
  693. cprint("%d", rows);
  694. cprint("%d", cols);
  695. cprint("%d", rows - 10);
  696. cprint("%s", active_entry);
  697. current_menu = menu;
  698. build_conf(menu);
  699. if (!child_count)
  700. break;
  701. if (menu == &rootmenu) {
  702. cprint(":");
  703. cprint("--- ");
  704. cprint("L");
  705. cprint(_(" Load an Alternate Configuration File"));
  706. cprint("S");
  707. cprint(_(" Save Configuration to an Alternate File"));
  708. }
  709. stat = exec_conf();
  710. if (stat < 0)
  711. continue;
  712. if (stat == 1 || stat == 255)
  713. break;
  714. type = input_buf[0];
  715. if (!type)
  716. continue;
  717. for (i = 0; input_buf[i] && !isspace(input_buf[i]); i++)
  718. ;
  719. if (i >= sizeof(active_entry))
  720. i = sizeof(active_entry) - 1;
  721. input_buf[i] = 0;
  722. strcpy(active_entry, input_buf);
  723. sym = NULL;
  724. submenu = NULL;
  725. if (sscanf(input_buf + 1, "%p", &submenu) == 1)
  726. sym = submenu->sym;
  727. switch (stat) {
  728. case 0:
  729. switch (type) {
  730. case 'm':
  731. if (single_menu_mode)
  732. submenu->data = (void *) (long) !submenu->data;
  733. else
  734. conf(submenu);
  735. break;
  736. case 't':
  737. if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
  738. conf_choice(submenu);
  739. else if (submenu->prompt->type == P_MENU)
  740. conf(submenu);
  741. break;
  742. case 's':
  743. conf_string(submenu);
  744. break;
  745. case 'L':
  746. conf_load();
  747. break;
  748. case 'S':
  749. conf_save();
  750. break;
  751. }
  752. break;
  753. case 2:
  754. if (sym)
  755. show_help(submenu);
  756. else
  757. show_helptext("README", _(mconf_readme));
  758. break;
  759. case 3:
  760. if (type == 't') {
  761. if (sym_set_tristate_value(sym, yes))
  762. break;
  763. if (sym_set_tristate_value(sym, mod))
  764. show_textbox(NULL, setmod_text, 6, 74);
  765. }
  766. break;
  767. case 4:
  768. if (type == 't')
  769. sym_set_tristate_value(sym, no);
  770. break;
  771. case 5:
  772. if (type == 't')
  773. sym_set_tristate_value(sym, mod);
  774. break;
  775. case 6:
  776. if (type == 't')
  777. sym_toggle_tristate_value(sym);
  778. else if (type == 'm')
  779. conf(submenu);
  780. break;
  781. case 7:
  782. search_conf();
  783. break;
  784. }
  785. }
  786. }
  787. static void show_textbox(const char *title, const char *text, int r, int c)
  788. {
  789. int fd;
  790. fd = creat(".help.tmp", 0777);
  791. write(fd, text, strlen(text));
  792. close(fd);
  793. show_file(".help.tmp", title, r, c);
  794. unlink(".help.tmp");
  795. }
  796. static void show_helptext(const char *title, const char *text)
  797. {
  798. show_textbox(title, text, 0, 0);
  799. }
  800. static void show_help(struct menu *menu)
  801. {
  802. struct gstr help = str_new();
  803. struct symbol *sym = menu->sym;
  804. if (sym->help)
  805. {
  806. if (sym->name) {
  807. str_printf(&help, "CONFIG_%s:\n\n", sym->name);
  808. str_append(&help, _(sym->help));
  809. str_append(&help, "\n");
  810. }
  811. } else {
  812. str_append(&help, nohelp_text);
  813. }
  814. get_symbol_str(&help, sym);
  815. show_helptext(menu_get_prompt(menu), str_get(&help));
  816. str_free(&help);
  817. }
  818. static void show_file(const char *filename, const char *title, int r, int c)
  819. {
  820. do {
  821. cprint_init();
  822. if (title) {
  823. cprint("--title");
  824. cprint("%s", title);
  825. }
  826. cprint("--textbox");
  827. cprint("%s", filename);
  828. cprint("%d", r ? r : rows);
  829. cprint("%d", c ? c : cols);
  830. } while (exec_conf() < 0);
  831. }
  832. static void conf_choice(struct menu *menu)
  833. {
  834. const char *prompt = menu_get_prompt(menu);
  835. struct menu *child;
  836. struct symbol *active;
  837. int stat;
  838. active = sym_get_choice_value(menu->sym);
  839. while (1) {
  840. cprint_init();
  841. cprint("--title");
  842. cprint("%s", prompt ? prompt : _("Main Menu"));
  843. cprint("--radiolist");
  844. cprint(_(radiolist_instructions));
  845. cprint("15");
  846. cprint("70");
  847. cprint("6");
  848. current_menu = menu;
  849. for (child = menu->list; child; child = child->next) {
  850. if (!menu_is_visible(child))
  851. continue;
  852. cprint("%p", child);
  853. cprint("%s", menu_get_prompt(child));
  854. if (child->sym == sym_get_choice_value(menu->sym))
  855. cprint("ON");
  856. else if (child->sym == active)
  857. cprint("SELECTED");
  858. else
  859. cprint("OFF");
  860. }
  861. stat = exec_conf();
  862. switch (stat) {
  863. case 0:
  864. if (sscanf(input_buf, "%p", &child) != 1)
  865. break;
  866. sym_set_tristate_value(child->sym, yes);
  867. return;
  868. case 1:
  869. if (sscanf(input_buf, "%p", &child) == 1) {
  870. show_help(child);
  871. active = child->sym;
  872. } else
  873. show_help(menu);
  874. break;
  875. case 255:
  876. return;
  877. }
  878. }
  879. }
  880. static void conf_string(struct menu *menu)
  881. {
  882. const char *prompt = menu_get_prompt(menu);
  883. int stat;
  884. while (1) {
  885. cprint_init();
  886. cprint("--title");
  887. cprint("%s", prompt ? prompt : _("Main Menu"));
  888. cprint("--inputbox");
  889. switch (sym_get_type(menu->sym)) {
  890. case S_INT:
  891. cprint(_(inputbox_instructions_int));
  892. break;
  893. case S_HEX:
  894. cprint(_(inputbox_instructions_hex));
  895. break;
  896. case S_STRING:
  897. cprint(_(inputbox_instructions_string));
  898. break;
  899. default:
  900. /* panic? */;
  901. }
  902. cprint("10");
  903. cprint("75");
  904. cprint("%s", sym_get_string_value(menu->sym));
  905. stat = exec_conf();
  906. switch (stat) {
  907. case 0:
  908. if (sym_set_string_value(menu->sym, input_buf))
  909. return;
  910. show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
  911. break;
  912. case 1:
  913. show_help(menu);
  914. break;
  915. case 255:
  916. return;
  917. }
  918. }
  919. }
  920. static void conf_load(void)
  921. {
  922. int stat;
  923. while (1) {
  924. cprint_init();
  925. cprint("--inputbox");
  926. cprint(load_config_text);
  927. cprint("11");
  928. cprint("55");
  929. cprint("%s", filename);
  930. stat = exec_conf();
  931. switch(stat) {
  932. case 0:
  933. if (!input_buf[0])
  934. return;
  935. if (!conf_read(input_buf))
  936. return;
  937. show_textbox(NULL, _("File does not exist!"), 5, 38);
  938. break;
  939. case 1:
  940. show_helptext(_("Load Alternate Configuration"), load_config_help);
  941. break;
  942. case 255:
  943. return;
  944. }
  945. }
  946. }
  947. static void conf_save(void)
  948. {
  949. int stat;
  950. while (1) {
  951. cprint_init();
  952. cprint("--inputbox");
  953. cprint(save_config_text);
  954. cprint("11");
  955. cprint("55");
  956. cprint("%s", filename);
  957. stat = exec_conf();
  958. switch(stat) {
  959. case 0:
  960. if (!input_buf[0])
  961. return;
  962. if (!conf_write(input_buf))
  963. return;
  964. show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60);
  965. break;
  966. case 1:
  967. show_helptext(_("Save Alternate Configuration"), save_config_help);
  968. break;
  969. case 255:
  970. return;
  971. }
  972. }
  973. }
  974. static void conf_cleanup(void)
  975. {
  976. tcsetattr(1, TCSAFLUSH, &ios_org);
  977. unlink(".help.tmp");
  978. unlink("lxdialog.scrltmp");
  979. }
  980. int main(int ac, char **av)
  981. {
  982. struct symbol *sym;
  983. char *mode;
  984. int stat;
  985. setlocale(LC_ALL, "");
  986. bindtextdomain(PACKAGE, LOCALEDIR);
  987. textdomain(PACKAGE);
  988. conf_parse(av[1]);
  989. conf_read(NULL);
  990. sym = sym_lookup("KERNELVERSION", 0);
  991. sym_calc_value(sym);
  992. sprintf(menu_backtitle, _("BusyBox %s Configuration"),
  993. sym_get_string_value(sym));
  994. mode = getenv("MENUCONFIG_MODE");
  995. if (mode) {
  996. if (!strcasecmp(mode, "single_menu"))
  997. single_menu_mode = 1;
  998. }
  999. tcgetattr(1, &ios_org);
  1000. atexit(conf_cleanup);
  1001. init_wsize();
  1002. conf(&rootmenu);
  1003. do {
  1004. cprint_init();
  1005. cprint("--yesno");
  1006. cprint(_("Do you wish to save your new configuration?"));
  1007. cprint("5");
  1008. cprint("60");
  1009. stat = exec_conf();
  1010. } while (stat < 0);
  1011. if (stat == 0) {
  1012. if (conf_write(NULL)) {
  1013. fprintf(stderr, _("\n\n"
  1014. "Error during writing of the configuration.\n"
  1015. "Your configuration changes were NOT saved."
  1016. "\n\n"));
  1017. return 1;
  1018. }
  1019. printf(_("\n\n"
  1020. "*** End of configuration.\n"
  1021. "*** Execute 'make' to build the project or try 'make help'."
  1022. "\n\n"));
  1023. } else {
  1024. fprintf(stderr, _("\n\n"
  1025. "Your configuration changes were NOT saved."
  1026. "\n\n"));
  1027. }
  1028. return 0;
  1029. }