xref: /openbmc/linux/scripts/kconfig/mconf.c (revision 0a1f00a1)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
31da177e4SLinus Torvalds  * Released under the terms of the GNU GPL v2.0.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Introduced single menu mode (show all sub-menus in one large tree).
61da177e4SLinus Torvalds  * 2002-11-06 Petr Baudis <pasky@ucw.cz>
73b9fa093SArnaldo Carvalho de Melo  *
83b9fa093SArnaldo Carvalho de Melo  * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds #include <ctype.h>
121da177e4SLinus Torvalds #include <errno.h>
131da177e4SLinus Torvalds #include <fcntl.h>
141da177e4SLinus Torvalds #include <limits.h>
151da177e4SLinus Torvalds #include <stdarg.h>
161da177e4SLinus Torvalds #include <stdlib.h>
171da177e4SLinus Torvalds #include <string.h>
18564899f9SDavidlohr Bueso #include <signal.h>
191da177e4SLinus Torvalds #include <unistd.h>
20442ff702SJean-Christophe Dubois #include <locale.h>
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #include "lkc.h"
232982de69SSam Ravnborg #include "lxdialog/dialog.h"
241da177e4SLinus Torvalds 
253b9fa093SArnaldo Carvalho de Melo static const char mconf_readme[] = N_(
261da177e4SLinus Torvalds "Overview\n"
271da177e4SLinus Torvalds "--------\n"
288d9dfe82SMartin Walch "This interface lets you select features and parameters for the build.\n"
29652cf982SArnaud Lacombe "Features can either be built-in, modularized, or ignored. Parameters\n"
30652cf982SArnaud Lacombe "must be entered in as decimal or hexadecimal numbers or text.\n"
311da177e4SLinus Torvalds "\n"
32b5d609dbSMatej Laitl "Menu items beginning with following braces represent features that\n"
33b5d609dbSMatej Laitl "  [ ] can be built in or removed\n"
34b5d609dbSMatej Laitl "  < > can be built in, modularized or removed\n"
35b5d609dbSMatej Laitl "  { } can be built in or modularized (selected by other feature)\n"
36b5d609dbSMatej Laitl "  - - are selected by other feature,\n"
37b5d609dbSMatej Laitl "while *, M or whitespace inside braces means to build in, build as\n"
38b5d609dbSMatej Laitl "a module or to exclude the feature respectively.\n"
391da177e4SLinus Torvalds "\n"
401da177e4SLinus Torvalds "To change any of these features, highlight it with the cursor\n"
411da177e4SLinus Torvalds "keys and press <Y> to build it in, <M> to make it a module or\n"
428d9dfe82SMartin Walch "<N> to remove it.  You may also press the <Space Bar> to cycle\n"
438d9dfe82SMartin Walch "through the available options (i.e. Y->N->M->Y).\n"
441da177e4SLinus Torvalds "\n"
451da177e4SLinus Torvalds "Some additional keyboard hints:\n"
461da177e4SLinus Torvalds "\n"
471da177e4SLinus Torvalds "Menus\n"
481da177e4SLinus Torvalds "----------\n"
498d9dfe82SMartin Walch "o  Use the Up/Down arrow keys (cursor keys) to highlight the item you\n"
508d9dfe82SMartin Walch "   wish to change or the submenu you wish to select and press <Enter>.\n"
511278ebdbSDirk Gouders "   Submenus are designated by \"--->\", empty ones by \"----\".\n"
521da177e4SLinus Torvalds "\n"
531da177e4SLinus Torvalds "   Shortcut: Press the option's highlighted letter (hotkey).\n"
541da177e4SLinus Torvalds "             Pressing a hotkey more than once will sequence\n"
551da177e4SLinus Torvalds "             through all visible items which use that hotkey.\n"
561da177e4SLinus Torvalds "\n"
571da177e4SLinus Torvalds "   You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n"
581da177e4SLinus Torvalds "   unseen options into view.\n"
591da177e4SLinus Torvalds "\n"
601da177e4SLinus Torvalds "o  To exit a menu use the cursor keys to highlight the <Exit> button\n"
611da177e4SLinus Torvalds "   and press <ENTER>.\n"
621da177e4SLinus Torvalds "\n"
631da177e4SLinus Torvalds "   Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n"
641da177e4SLinus Torvalds "             using those letters.  You may press a single <ESC>, but\n"
651da177e4SLinus Torvalds "             there is a delayed response which you may find annoying.\n"
661da177e4SLinus Torvalds "\n"
671da177e4SLinus Torvalds "   Also, the <TAB> and cursor keys will cycle between <Select>,\n"
688d9dfe82SMartin Walch "   <Exit>, <Help>, <Save>, and <Load>.\n"
691da177e4SLinus Torvalds "\n"
701da177e4SLinus Torvalds "o  To get help with an item, use the cursor keys to highlight <Help>\n"
7122c7eca6SLi Zefan "   and press <ENTER>.\n"
721da177e4SLinus Torvalds "\n"
731da177e4SLinus Torvalds "   Shortcut: Press <H> or <?>.\n"
741da177e4SLinus Torvalds "\n"
75f9447c49SLi Zefan "o  To toggle the display of hidden options, press <Z>.\n"
7622c7eca6SLi Zefan "\n"
771da177e4SLinus Torvalds "\n"
781da177e4SLinus Torvalds "Radiolists  (Choice lists)\n"
791da177e4SLinus Torvalds "-----------\n"
801da177e4SLinus Torvalds "o  Use the cursor keys to select the option you wish to set and press\n"
811da177e4SLinus Torvalds "   <S> or the <SPACE BAR>.\n"
821da177e4SLinus Torvalds "\n"
831da177e4SLinus Torvalds "   Shortcut: Press the first letter of the option you wish to set then\n"
841da177e4SLinus Torvalds "             press <S> or <SPACE BAR>.\n"
851da177e4SLinus Torvalds "\n"
861da177e4SLinus Torvalds "o  To see available help for the item, use the cursor keys to highlight\n"
871da177e4SLinus Torvalds "   <Help> and Press <ENTER>.\n"
881da177e4SLinus Torvalds "\n"
891da177e4SLinus Torvalds "   Shortcut: Press <H> or <?>.\n"
901da177e4SLinus Torvalds "\n"
911da177e4SLinus Torvalds "   Also, the <TAB> and cursor keys will cycle between <Select> and\n"
921da177e4SLinus Torvalds "   <Help>\n"
931da177e4SLinus Torvalds "\n"
941da177e4SLinus Torvalds "\n"
951da177e4SLinus Torvalds "Data Entry\n"
961da177e4SLinus Torvalds "-----------\n"
971da177e4SLinus Torvalds "o  Enter the requested information and press <ENTER>\n"
981da177e4SLinus Torvalds "   If you are entering hexadecimal values, it is not necessary to\n"
991da177e4SLinus Torvalds "   add the '0x' prefix to the entry.\n"
1001da177e4SLinus Torvalds "\n"
1011da177e4SLinus Torvalds "o  For help, use the <TAB> or cursor keys to highlight the help option\n"
1021da177e4SLinus Torvalds "   and press <ENTER>.  You can try <TAB><H> as well.\n"
1031da177e4SLinus Torvalds "\n"
1041da177e4SLinus Torvalds "\n"
1051da177e4SLinus Torvalds "Text Box    (Help Window)\n"
1061da177e4SLinus Torvalds "--------\n"
1071da177e4SLinus Torvalds "o  Use the cursor keys to scroll up/down/left/right.  The VI editor\n"
1089d4792c9SBenjamin Poirier "   keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for\n"
1099d4792c9SBenjamin Poirier "   those who are familiar with less and lynx.\n"
1101da177e4SLinus Torvalds "\n"
1119d4792c9SBenjamin Poirier "o  Press <E>, <X>, <q>, <Enter> or <Esc><Esc> to exit.\n"
1121da177e4SLinus Torvalds "\n"
1131da177e4SLinus Torvalds "\n"
1141da177e4SLinus Torvalds "Alternate Configuration Files\n"
1151da177e4SLinus Torvalds "-----------------------------\n"
1161da177e4SLinus Torvalds "Menuconfig supports the use of alternate configuration files for\n"
1171da177e4SLinus Torvalds "those who, for various reasons, find it necessary to switch\n"
118652cf982SArnaud Lacombe "between different configurations.\n"
1191da177e4SLinus Torvalds "\n"
1208d9dfe82SMartin Walch "The <Save> button will let you save the current configuration to\n"
1218d9dfe82SMartin Walch "a file of your choosing.  Use the <Load> button to load a previously\n"
1228d9dfe82SMartin Walch "saved alternate configuration.\n"
1231da177e4SLinus Torvalds "\n"
1248d9dfe82SMartin Walch "Even if you don't use alternate configuration files, but you find\n"
1258d9dfe82SMartin Walch "during a Menuconfig session that you have completely messed up your\n"
1268d9dfe82SMartin Walch "settings, you may use the <Load> button to restore your previously\n"
1278d9dfe82SMartin Walch "saved settings from \".config\" without restarting Menuconfig.\n"
1281da177e4SLinus Torvalds "\n"
1291da177e4SLinus Torvalds "Other information\n"
1301da177e4SLinus Torvalds "-----------------\n"
1318d9dfe82SMartin Walch "If you use Menuconfig in an XTERM window, make sure you have your\n"
1328d9dfe82SMartin Walch "$TERM variable set to point to an xterm definition which supports\n"
1338d9dfe82SMartin Walch "color.  Otherwise, Menuconfig will look rather bad.  Menuconfig will\n"
1348d9dfe82SMartin Walch "not display correctly in an RXVT window because rxvt displays only one\n"
1351da177e4SLinus Torvalds "intensity of color, bright.\n"
1361da177e4SLinus Torvalds "\n"
1371da177e4SLinus Torvalds "Menuconfig will display larger menus on screens or xterms which are\n"
1381da177e4SLinus Torvalds "set to display more than the standard 25 row by 80 column geometry.\n"
1391da177e4SLinus Torvalds "In order for this to work, the \"stty size\" command must be able to\n"
1401da177e4SLinus Torvalds "display the screen's current row and column geometry.  I STRONGLY\n"
1411da177e4SLinus Torvalds "RECOMMEND that you make sure you do NOT have the shell variables\n"
1421da177e4SLinus Torvalds "LINES and COLUMNS exported into your environment.  Some distributions\n"
1431da177e4SLinus Torvalds "export those variables via /etc/profile.  Some ncurses programs can\n"
1441da177e4SLinus Torvalds "become confused when those variables (LINES & COLUMNS) don't reflect\n"
1451da177e4SLinus Torvalds "the true screen size.\n"
1461da177e4SLinus Torvalds "\n"
1471da177e4SLinus Torvalds "Optional personality available\n"
1481da177e4SLinus Torvalds "------------------------------\n"
1498d9dfe82SMartin Walch "If you prefer to have all of the options listed in a single menu,\n"
1508d9dfe82SMartin Walch "rather than the default multimenu hierarchy, run the menuconfig with\n"
151652cf982SArnaud Lacombe "MENUCONFIG_MODE environment variable set to single_menu. Example:\n"
1521da177e4SLinus Torvalds "\n"
1531da177e4SLinus Torvalds "make MENUCONFIG_MODE=single_menu menuconfig\n"
1541da177e4SLinus Torvalds "\n"
1551da177e4SLinus Torvalds "<Enter> will then unroll the appropriate category, or enfold it if it\n"
1561da177e4SLinus Torvalds "is already unrolled.\n"
1571da177e4SLinus Torvalds "\n"
1581da177e4SLinus Torvalds "Note that this mode can eventually be a little more CPU expensive\n"
1591da177e4SLinus Torvalds "(especially with a larger number of unrolled categories) than the\n"
16045897213SSam Ravnborg "default mode.\n"
16145897213SSam Ravnborg "\n"
16245897213SSam Ravnborg "Different color themes available\n"
16345897213SSam Ravnborg "--------------------------------\n"
16445897213SSam Ravnborg "It is possible to select different color themes using the variable\n"
16545897213SSam Ravnborg "MENUCONFIG_COLOR. To select a theme use:\n"
16645897213SSam Ravnborg "\n"
16745897213SSam Ravnborg "make MENUCONFIG_COLOR=<theme> menuconfig\n"
16845897213SSam Ravnborg "\n"
16945897213SSam Ravnborg "Available themes are\n"
17045897213SSam Ravnborg " mono       => selects colors suitable for monochrome displays\n"
17145897213SSam Ravnborg " blackbg    => selects a color scheme with black background\n"
172350b5b76SSam Ravnborg " classic    => theme with blue background. The classic look\n"
1738d9dfe82SMartin Walch " bluetitle  => an LCD friendly version of classic. (default)\n"
17445897213SSam Ravnborg "\n"),
1753b9fa093SArnaldo Carvalho de Melo menu_instructions[] = N_(
1761da177e4SLinus Torvalds 	"Arrow keys navigate the menu.  "
1771278ebdbSDirk Gouders 	"<Enter> selects submenus ---> (or empty submenus ----).  "
1781da177e4SLinus Torvalds 	"Highlighted letters are hotkeys.  "
1791da177e4SLinus Torvalds 	"Pressing <Y> includes, <N> excludes, <M> modularizes features.  "
1801da177e4SLinus Torvalds 	"Press <Esc><Esc> to exit, <?> for Help, </> for Search.  "
1813b9fa093SArnaldo Carvalho de Melo 	"Legend: [*] built-in  [ ] excluded  <M> module  < > module capable"),
1823b9fa093SArnaldo Carvalho de Melo radiolist_instructions[] = N_(
1831da177e4SLinus Torvalds 	"Use the arrow keys to navigate this window or "
1841da177e4SLinus Torvalds 	"press the hotkey of the item you wish to select "
1851da177e4SLinus Torvalds 	"followed by the <SPACE BAR>. "
1863b9fa093SArnaldo Carvalho de Melo 	"Press <?> for additional information about this option."),
1873b9fa093SArnaldo Carvalho de Melo inputbox_instructions_int[] = N_(
1881da177e4SLinus Torvalds 	"Please enter a decimal value. "
1891da177e4SLinus Torvalds 	"Fractions will not be accepted.  "
1903b9fa093SArnaldo Carvalho de Melo 	"Use the <TAB> key to move from the input field to the buttons below it."),
1913b9fa093SArnaldo Carvalho de Melo inputbox_instructions_hex[] = N_(
1921da177e4SLinus Torvalds 	"Please enter a hexadecimal value. "
1933b9fa093SArnaldo Carvalho de Melo 	"Use the <TAB> key to move from the input field to the buttons below it."),
1943b9fa093SArnaldo Carvalho de Melo inputbox_instructions_string[] = N_(
1951da177e4SLinus Torvalds 	"Please enter a string value. "
1963b9fa093SArnaldo Carvalho de Melo 	"Use the <TAB> key to move from the input field to the buttons below it."),
1973b9fa093SArnaldo Carvalho de Melo setmod_text[] = N_(
1981da177e4SLinus Torvalds 	"This feature depends on another which has been configured as a module.\n"
1993b9fa093SArnaldo Carvalho de Melo 	"As a result, this feature will be built as a module."),
2003b9fa093SArnaldo Carvalho de Melo load_config_text[] = N_(
2011da177e4SLinus Torvalds 	"Enter the name of the configuration file you wish to load.  "
2021da177e4SLinus Torvalds 	"Accept the name shown to restore the configuration you "
2033b9fa093SArnaldo Carvalho de Melo 	"last retrieved.  Leave blank to abort."),
2043b9fa093SArnaldo Carvalho de Melo load_config_help[] = N_(
2051da177e4SLinus Torvalds 	"\n"
206652cf982SArnaud Lacombe 	"For various reasons, one may wish to keep several different\n"
2071da177e4SLinus Torvalds 	"configurations available on a single machine.\n"
2081da177e4SLinus Torvalds 	"\n"
2091da177e4SLinus Torvalds 	"If you have saved a previous configuration in a file other than the\n"
210652cf982SArnaud Lacombe 	"default one, entering its name here will allow you to modify that\n"
211652cf982SArnaud Lacombe 	"configuration.\n"
2121da177e4SLinus Torvalds 	"\n"
2131da177e4SLinus Torvalds 	"If you are uncertain, then you have probably never used alternate\n"
214af901ca1SAndré Goddard Rosa 	"configuration files. You should therefore leave this blank to abort.\n"),
2153b9fa093SArnaldo Carvalho de Melo save_config_text[] = N_(
2161da177e4SLinus Torvalds 	"Enter a filename to which this configuration should be saved "
2173b9fa093SArnaldo Carvalho de Melo 	"as an alternate.  Leave blank to abort."),
2183b9fa093SArnaldo Carvalho de Melo save_config_help[] = N_(
2191da177e4SLinus Torvalds 	"\n"
220652cf982SArnaud Lacombe 	"For various reasons, one may wish to keep different configurations\n"
221652cf982SArnaud Lacombe 	"available on a single machine.\n"
2221da177e4SLinus Torvalds 	"\n"
2231da177e4SLinus Torvalds 	"Entering a file name here will allow you to later retrieve, modify\n"
2241da177e4SLinus Torvalds 	"and use the current configuration as an alternate to whatever\n"
2251da177e4SLinus Torvalds 	"configuration options you have selected at that time.\n"
2261da177e4SLinus Torvalds 	"\n"
2271da177e4SLinus Torvalds 	"If you are uncertain what all this means then you should probably\n"
2283b9fa093SArnaldo Carvalho de Melo 	"leave this blank.\n"),
2293b9fa093SArnaldo Carvalho de Melo search_help[] = N_(
2301da177e4SLinus Torvalds 	"\n"
23159dfa24dSArnaud Lacombe 	"Search for symbols and display their relations.\n"
232503af334SRandy Dunlap 	"Regular expressions are allowed.\n"
2331da177e4SLinus Torvalds 	"Example: search for \"^FOO\"\n"
2341da177e4SLinus Torvalds 	"Result:\n"
2351da177e4SLinus Torvalds 	"-----------------------------------------------------------------\n"
2361da177e4SLinus Torvalds 	"Symbol: FOO [=m]\n"
2375e609addSBenjamin Poirier 	"Type  : tristate\n"
2381da177e4SLinus Torvalds 	"Prompt: Foo bus is used to drive the bar HW\n"
2391da177e4SLinus Torvalds 	"  Location:\n"
240bb8187d3SPaul Gortmaker 	"    -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
2411da177e4SLinus Torvalds 	"      -> PCI support (PCI [=y])\n"
2425e609addSBenjamin Poirier 	"(1)     -> PCI access mode (<choice> [=y])\n"
2438d9dfe82SMartin Walch 	"  Defined at drivers/pci/Kconfig:47\n"
2448d9dfe82SMartin Walch 	"  Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
2451da177e4SLinus Torvalds 	"  Selects: LIBCRC32\n"
2468d9dfe82SMartin Walch 	"  Selected by: BAR [=n]\n"
2471da177e4SLinus Torvalds 	"-----------------------------------------------------------------\n"
2485e609addSBenjamin Poirier 	"o The line 'Type:' shows the type of the configuration option for\n"
2495e609addSBenjamin Poirier 	"  this symbol (boolean, tristate, string, ...)\n"
2501da177e4SLinus Torvalds 	"o The line 'Prompt:' shows the text used in the menu structure for\n"
25159dfa24dSArnaud Lacombe 	"  this symbol\n"
2528d9dfe82SMartin Walch 	"o The 'Defined at' line tells at what file / line number the symbol\n"
2531da177e4SLinus Torvalds 	"  is defined\n"
2548d9dfe82SMartin Walch 	"o The 'Depends on:' line tells what symbols need to be defined for\n"
2551da177e4SLinus Torvalds 	"  this symbol to be visible in the menu (selectable)\n"
2568d9dfe82SMartin Walch 	"o The 'Location:' lines tells where in the menu structure this symbol\n"
2571da177e4SLinus Torvalds 	"  is located\n"
2585e609addSBenjamin Poirier 	"    A location followed by a [=y] indicates that this is a\n"
2595e609addSBenjamin Poirier 	"    selectable menu item - and the current value is displayed inside\n"
2605e609addSBenjamin Poirier 	"    brackets.\n"
2615e609addSBenjamin Poirier 	"    Press the key in the (#) prefix to jump directly to that\n"
2625e609addSBenjamin Poirier 	"    location. You will be returned to the current search results\n"
2635e609addSBenjamin Poirier 	"    after exiting this new menu.\n"
2648d9dfe82SMartin Walch 	"o The 'Selects:' line tells what symbols will be automatically\n"
2651da177e4SLinus Torvalds 	"  selected if this symbol is selected (y or m)\n"
2668d9dfe82SMartin Walch 	"o The 'Selected by' line tells what symbol has selected this symbol\n"
2671da177e4SLinus Torvalds 	"\n"
2681da177e4SLinus Torvalds 	"Only relevant lines are shown.\n"
2691da177e4SLinus Torvalds 	"\n\n"
2701da177e4SLinus Torvalds 	"Search examples:\n"
27159dfa24dSArnaud Lacombe 	"Examples: USB	=> find all symbols containing USB\n"
27259dfa24dSArnaud Lacombe 	"          ^USB => find all symbols starting with USB\n"
27359dfa24dSArnaud Lacombe 	"          USB$ => find all symbols ending with USB\n"
2743b9fa093SArnaldo Carvalho de Melo 	"\n");
2751da177e4SLinus Torvalds 
2761da177e4SLinus Torvalds static int indent;
2771da177e4SLinus Torvalds static struct menu *current_menu;
2781da177e4SLinus Torvalds static int child_count;
2791da177e4SLinus Torvalds static int single_menu_mode;
28022c7eca6SLi Zefan static int show_all_options;
2816364fd0cSWang YanQing static int save_and_exit;
2820a1f00a1SMichal Marek static int silent;
2831da177e4SLinus Torvalds 
2845e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_menu);
2851da177e4SLinus Torvalds static void conf_choice(struct menu *menu);
2861da177e4SLinus Torvalds static void conf_string(struct menu *menu);
2871da177e4SLinus Torvalds static void conf_load(void);
2881da177e4SLinus Torvalds static void conf_save(void);
28995ac9b3bSBenjamin Poirier static int show_textbox_ext(const char *title, char *text, int r, int c,
29095ac9b3bSBenjamin Poirier 			    int *keys, int *vscroll, int *hscroll,
29195ac9b3bSBenjamin Poirier 			    update_text_fn update_text, void *data);
2921da177e4SLinus Torvalds static void show_textbox(const char *title, const char *text, int r, int c);
2931da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text);
2941da177e4SLinus Torvalds static void show_help(struct menu *menu);
2951da177e4SLinus Torvalds 
29695e30f95SSam Ravnborg static char filename[PATH_MAX+1];
29795e30f95SSam Ravnborg static void set_config_filename(const char *config_filename)
29895e30f95SSam Ravnborg {
29995e30f95SSam Ravnborg 	static char menu_backtitle[PATH_MAX+128];
30095e30f95SSam Ravnborg 	int size;
30195e30f95SSam Ravnborg 
30295e30f95SSam Ravnborg 	size = snprintf(menu_backtitle, sizeof(menu_backtitle),
3030954828fSArnaud Lacombe 			"%s - %s", config_filename, rootmenu.prompt->text);
30495e30f95SSam Ravnborg 	if (size >= sizeof(menu_backtitle))
30595e30f95SSam Ravnborg 		menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
30695e30f95SSam Ravnborg 	set_dialog_backtitle(menu_backtitle);
30795e30f95SSam Ravnborg 
30895e30f95SSam Ravnborg 	size = snprintf(filename, sizeof(filename), "%s", config_filename);
30995e30f95SSam Ravnborg 	if (size >= sizeof(filename))
31095e30f95SSam Ravnborg 		filename[sizeof(filename)-1] = '\0';
31195e30f95SSam Ravnborg }
31295e30f95SSam Ravnborg 
3139a69abf8SBenjamin Poirier struct subtitle_part {
3149a69abf8SBenjamin Poirier 	struct list_head entries;
3159a69abf8SBenjamin Poirier 	const char *text;
3169a69abf8SBenjamin Poirier };
3179a69abf8SBenjamin Poirier static LIST_HEAD(trail);
3189a69abf8SBenjamin Poirier 
3199a69abf8SBenjamin Poirier static struct subtitle_list *subtitles;
3209a69abf8SBenjamin Poirier static void set_subtitle(void)
3219a69abf8SBenjamin Poirier {
3229a69abf8SBenjamin Poirier 	struct subtitle_part *sp;
3239a69abf8SBenjamin Poirier 	struct subtitle_list *pos, *tmp;
3249a69abf8SBenjamin Poirier 
3259a69abf8SBenjamin Poirier 	for (pos = subtitles; pos != NULL; pos = tmp) {
3269a69abf8SBenjamin Poirier 		tmp = pos->next;
3279a69abf8SBenjamin Poirier 		free(pos);
3289a69abf8SBenjamin Poirier 	}
3299a69abf8SBenjamin Poirier 
3309a69abf8SBenjamin Poirier 	subtitles = NULL;
3319a69abf8SBenjamin Poirier 	list_for_each_entry(sp, &trail, entries) {
3329a69abf8SBenjamin Poirier 		if (sp->text) {
3339a69abf8SBenjamin Poirier 			if (pos) {
334e4e458b4SArjun Sreedharan 				pos->next = xcalloc(1, sizeof(*pos));
3359a69abf8SBenjamin Poirier 				pos = pos->next;
3369a69abf8SBenjamin Poirier 			} else {
337e4e458b4SArjun Sreedharan 				subtitles = pos = xcalloc(1, sizeof(*pos));
3389a69abf8SBenjamin Poirier 			}
3399a69abf8SBenjamin Poirier 			pos->text = sp->text;
3409a69abf8SBenjamin Poirier 		}
3419a69abf8SBenjamin Poirier 	}
3429a69abf8SBenjamin Poirier 
3439a69abf8SBenjamin Poirier 	set_dialog_subtitles(subtitles);
3449a69abf8SBenjamin Poirier }
3459a69abf8SBenjamin Poirier 
3469a69abf8SBenjamin Poirier static void reset_subtitle(void)
3479a69abf8SBenjamin Poirier {
3489a69abf8SBenjamin Poirier 	struct subtitle_list *pos, *tmp;
3499a69abf8SBenjamin Poirier 
3509a69abf8SBenjamin Poirier 	for (pos = subtitles; pos != NULL; pos = tmp) {
3519a69abf8SBenjamin Poirier 		tmp = pos->next;
3529a69abf8SBenjamin Poirier 		free(pos);
3539a69abf8SBenjamin Poirier 	}
3549a69abf8SBenjamin Poirier 	subtitles = NULL;
3559a69abf8SBenjamin Poirier 	set_dialog_subtitles(subtitles);
3569a69abf8SBenjamin Poirier }
35795e30f95SSam Ravnborg 
35895ac9b3bSBenjamin Poirier struct search_data {
359bad9955dSBenjamin Poirier 	struct list_head *head;
36095ac9b3bSBenjamin Poirier 	struct menu **targets;
36195ac9b3bSBenjamin Poirier 	int *keys;
36295ac9b3bSBenjamin Poirier };
36395ac9b3bSBenjamin Poirier 
36495ac9b3bSBenjamin Poirier static void update_text(char *buf, size_t start, size_t end, void *_data)
36595ac9b3bSBenjamin Poirier {
36695ac9b3bSBenjamin Poirier 	struct search_data *data = _data;
36795ac9b3bSBenjamin Poirier 	struct jump_key *pos;
36895ac9b3bSBenjamin Poirier 	int k = 0;
36995ac9b3bSBenjamin Poirier 
370bad9955dSBenjamin Poirier 	list_for_each_entry(pos, data->head, entries) {
37195ac9b3bSBenjamin Poirier 		if (pos->offset >= start && pos->offset < end) {
37295ac9b3bSBenjamin Poirier 			char header[4];
37395ac9b3bSBenjamin Poirier 
37495ac9b3bSBenjamin Poirier 			if (k < JUMP_NB) {
37595ac9b3bSBenjamin Poirier 				int key = '0' + (pos->index % JUMP_NB) + 1;
37695ac9b3bSBenjamin Poirier 
37795ac9b3bSBenjamin Poirier 				sprintf(header, "(%c)", key);
37895ac9b3bSBenjamin Poirier 				data->keys[k] = key;
37995ac9b3bSBenjamin Poirier 				data->targets[k] = pos->target;
38095ac9b3bSBenjamin Poirier 				k++;
38195ac9b3bSBenjamin Poirier 			} else {
38295ac9b3bSBenjamin Poirier 				sprintf(header, "   ");
38395ac9b3bSBenjamin Poirier 			}
38495ac9b3bSBenjamin Poirier 
38595ac9b3bSBenjamin Poirier 			memcpy(buf + pos->offset, header, sizeof(header) - 1);
38695ac9b3bSBenjamin Poirier 		}
38795ac9b3bSBenjamin Poirier 	}
38895ac9b3bSBenjamin Poirier 	data->keys[k] = 0;
38995ac9b3bSBenjamin Poirier }
39095ac9b3bSBenjamin Poirier 
3911da177e4SLinus Torvalds static void search_conf(void)
3921da177e4SLinus Torvalds {
3931da177e4SLinus Torvalds 	struct symbol **sym_arr;
3941da177e4SLinus Torvalds 	struct gstr res;
395337a275dSYann E. MORIN 	struct gstr title;
3960584f9f9SBernhard Walle 	char *dialog_input;
3975e609addSBenjamin Poirier 	int dres, vscroll = 0, hscroll = 0;
3985e609addSBenjamin Poirier 	bool again;
3999a69abf8SBenjamin Poirier 	struct gstr sttext;
4009a69abf8SBenjamin Poirier 	struct subtitle_part stpart;
4015e609addSBenjamin Poirier 
402337a275dSYann E. MORIN 	title = str_new();
403f6eb6e46SYann E. MORIN 	str_printf( &title, _("Enter (sub)string or regexp to search for "
404f6eb6e46SYann E. MORIN 			      "(with or without \"%s\")"), CONFIG_);
405337a275dSYann E. MORIN 
4061da177e4SLinus Torvalds again:
407e94c5bdeSSam Ravnborg 	dialog_clear();
4082982de69SSam Ravnborg 	dres = dialog_inputbox(_("Search Configuration Parameter"),
409337a275dSYann E. MORIN 			      str_get(&title),
4102982de69SSam Ravnborg 			      10, 75, "");
4112982de69SSam Ravnborg 	switch (dres) {
4121da177e4SLinus Torvalds 	case 0:
4131da177e4SLinus Torvalds 		break;
4141da177e4SLinus Torvalds 	case 1:
4153b9fa093SArnaldo Carvalho de Melo 		show_helptext(_("Search Configuration"), search_help);
4161da177e4SLinus Torvalds 		goto again;
4171da177e4SLinus Torvalds 	default:
418337a275dSYann E. MORIN 		str_free(&title);
4191da177e4SLinus Torvalds 		return;
4201da177e4SLinus Torvalds 	}
4211da177e4SLinus Torvalds 
422ffb5957bSArnaud Lacombe 	/* strip the prefix if necessary */
4230584f9f9SBernhard Walle 	dialog_input = dialog_input_result;
424ffb5957bSArnaud Lacombe 	if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
425ffb5957bSArnaud Lacombe 		dialog_input += strlen(CONFIG_);
4260584f9f9SBernhard Walle 
4279a69abf8SBenjamin Poirier 	sttext = str_new();
4289a69abf8SBenjamin Poirier 	str_printf(&sttext, "Search (%s)", dialog_input_result);
4299a69abf8SBenjamin Poirier 	stpart.text = str_get(&sttext);
4309a69abf8SBenjamin Poirier 	list_add_tail(&stpart.entries, &trail);
4319a69abf8SBenjamin Poirier 
4320584f9f9SBernhard Walle 	sym_arr = sym_re_search(dialog_input);
4335e609addSBenjamin Poirier 	do {
434bad9955dSBenjamin Poirier 		LIST_HEAD(head);
43595ac9b3bSBenjamin Poirier 		struct menu *targets[JUMP_NB];
43695ac9b3bSBenjamin Poirier 		int keys[JUMP_NB + 1], i;
43795ac9b3bSBenjamin Poirier 		struct search_data data = {
43895ac9b3bSBenjamin Poirier 			.head = &head,
43995ac9b3bSBenjamin Poirier 			.targets = targets,
44095ac9b3bSBenjamin Poirier 			.keys = keys,
44195ac9b3bSBenjamin Poirier 		};
442edb749f4SBenjamin Poirier 		struct jump_key *pos, *tmp;
4435e609addSBenjamin Poirier 
44495ac9b3bSBenjamin Poirier 		res = get_relations_str(sym_arr, &head);
4459a69abf8SBenjamin Poirier 		set_subtitle();
44695ac9b3bSBenjamin Poirier 		dres = show_textbox_ext(_("Search Results"), (char *)
44795ac9b3bSBenjamin Poirier 					str_get(&res), 0, 0, keys, &vscroll,
44895ac9b3bSBenjamin Poirier 					&hscroll, &update_text, (void *)
44995ac9b3bSBenjamin Poirier 					&data);
4505e609addSBenjamin Poirier 		again = false;
45195ac9b3bSBenjamin Poirier 		for (i = 0; i < JUMP_NB && keys[i]; i++)
4525e609addSBenjamin Poirier 			if (dres == keys[i]) {
45395ac9b3bSBenjamin Poirier 				conf(targets[i]->parent, targets[i]);
4545e609addSBenjamin Poirier 				again = true;
4555e609addSBenjamin Poirier 			}
4561da177e4SLinus Torvalds 		str_free(&res);
457edb749f4SBenjamin Poirier 		list_for_each_entry_safe(pos, tmp, &head, entries)
458edb749f4SBenjamin Poirier 			free(pos);
4595e609addSBenjamin Poirier 	} while (again);
4605e609addSBenjamin Poirier 	free(sym_arr);
461337a275dSYann E. MORIN 	str_free(&title);
4629a69abf8SBenjamin Poirier 	list_del(trail.prev);
4639a69abf8SBenjamin Poirier 	str_free(&sttext);
4641da177e4SLinus Torvalds }
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds static void build_conf(struct menu *menu)
4671da177e4SLinus Torvalds {
4681da177e4SLinus Torvalds 	struct symbol *sym;
4691da177e4SLinus Torvalds 	struct property *prop;
4701da177e4SLinus Torvalds 	struct menu *child;
4711da177e4SLinus Torvalds 	int type, tmp, doint = 2;
4721da177e4SLinus Torvalds 	tristate val;
4731da177e4SLinus Torvalds 	char ch;
47422c7eca6SLi Zefan 	bool visible;
4751da177e4SLinus Torvalds 
47622c7eca6SLi Zefan 	/*
47722c7eca6SLi Zefan 	 * note: menu_is_visible() has side effect that it will
47822c7eca6SLi Zefan 	 * recalc the value of the symbol.
47922c7eca6SLi Zefan 	 */
48022c7eca6SLi Zefan 	visible = menu_is_visible(menu);
48122c7eca6SLi Zefan 	if (show_all_options && !menu_has_prompt(menu))
48222c7eca6SLi Zefan 		return;
48322c7eca6SLi Zefan 	else if (!show_all_options && !visible)
4841da177e4SLinus Torvalds 		return;
4851da177e4SLinus Torvalds 
4861da177e4SLinus Torvalds 	sym = menu->sym;
4871da177e4SLinus Torvalds 	prop = menu->prompt;
4881da177e4SLinus Torvalds 	if (!sym) {
4891da177e4SLinus Torvalds 		if (prop && menu != current_menu) {
4901da177e4SLinus Torvalds 			const char *prompt = menu_get_prompt(menu);
4911da177e4SLinus Torvalds 			switch (prop->type) {
4921da177e4SLinus Torvalds 			case P_MENU:
4931da177e4SLinus Torvalds 				child_count++;
494413f006bSEGRY Gabor 				prompt = _(prompt);
4951da177e4SLinus Torvalds 				if (single_menu_mode) {
4962982de69SSam Ravnborg 					item_make("%s%*c%s",
4971da177e4SLinus Torvalds 						  menu->data ? "-->" : "++>",
4981da177e4SLinus Torvalds 						  indent + 1, ' ', prompt);
4991da177e4SLinus Torvalds 				} else
5001278ebdbSDirk Gouders 					item_make("   %*c%s  %s",
5011278ebdbSDirk Gouders 						  indent + 1, ' ', prompt,
5021278ebdbSDirk Gouders 						  menu_is_empty(menu) ? "----" : "--->");
5032982de69SSam Ravnborg 				item_set_tag('m');
5042982de69SSam Ravnborg 				item_set_data(menu);
5051da177e4SLinus Torvalds 				if (single_menu_mode && menu->data)
5061da177e4SLinus Torvalds 					goto conf_childs;
5071da177e4SLinus Torvalds 				return;
50848874077SSam Ravnborg 			case P_COMMENT:
50948874077SSam Ravnborg 				if (prompt) {
51048874077SSam Ravnborg 					child_count++;
511413f006bSEGRY Gabor 					item_make("   %*c*** %s ***", indent + 1, ' ', _(prompt));
51248874077SSam Ravnborg 					item_set_tag(':');
51348874077SSam Ravnborg 					item_set_data(menu);
51448874077SSam Ravnborg 				}
51548874077SSam Ravnborg 				break;
5161da177e4SLinus Torvalds 			default:
5171da177e4SLinus Torvalds 				if (prompt) {
5181da177e4SLinus Torvalds 					child_count++;
519413f006bSEGRY Gabor 					item_make("---%*c%s", indent + 1, ' ', _(prompt));
5202982de69SSam Ravnborg 					item_set_tag(':');
5212982de69SSam Ravnborg 					item_set_data(menu);
5221da177e4SLinus Torvalds 				}
5231da177e4SLinus Torvalds 			}
5241da177e4SLinus Torvalds 		} else
5251da177e4SLinus Torvalds 			doint = 0;
5261da177e4SLinus Torvalds 		goto conf_childs;
5271da177e4SLinus Torvalds 	}
5281da177e4SLinus Torvalds 
5291da177e4SLinus Torvalds 	type = sym_get_type(sym);
5301da177e4SLinus Torvalds 	if (sym_is_choice(sym)) {
5311da177e4SLinus Torvalds 		struct symbol *def_sym = sym_get_choice_value(sym);
5321da177e4SLinus Torvalds 		struct menu *def_menu = NULL;
5331da177e4SLinus Torvalds 
5341da177e4SLinus Torvalds 		child_count++;
5351da177e4SLinus Torvalds 		for (child = menu->list; child; child = child->next) {
5361da177e4SLinus Torvalds 			if (menu_is_visible(child) && child->sym == def_sym)
5371da177e4SLinus Torvalds 				def_menu = child;
5381da177e4SLinus Torvalds 		}
5391da177e4SLinus Torvalds 
5401da177e4SLinus Torvalds 		val = sym_get_tristate_value(sym);
5411da177e4SLinus Torvalds 		if (sym_is_changable(sym)) {
5421da177e4SLinus Torvalds 			switch (type) {
5431da177e4SLinus Torvalds 			case S_BOOLEAN:
5442982de69SSam Ravnborg 				item_make("[%c]", val == no ? ' ' : '*');
5451da177e4SLinus Torvalds 				break;
5461da177e4SLinus Torvalds 			case S_TRISTATE:
5471da177e4SLinus Torvalds 				switch (val) {
5481da177e4SLinus Torvalds 				case yes: ch = '*'; break;
5491da177e4SLinus Torvalds 				case mod: ch = 'M'; break;
5501da177e4SLinus Torvalds 				default:  ch = ' '; break;
5511da177e4SLinus Torvalds 				}
5522982de69SSam Ravnborg 				item_make("<%c>", ch);
5531da177e4SLinus Torvalds 				break;
5541da177e4SLinus Torvalds 			}
5552982de69SSam Ravnborg 			item_set_tag('t');
5562982de69SSam Ravnborg 			item_set_data(menu);
5571da177e4SLinus Torvalds 		} else {
5582982de69SSam Ravnborg 			item_make("   ");
5592982de69SSam Ravnborg 			item_set_tag(def_menu ? 't' : ':');
5602982de69SSam Ravnborg 			item_set_data(menu);
5611da177e4SLinus Torvalds 		}
5621da177e4SLinus Torvalds 
563413f006bSEGRY Gabor 		item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
5641da177e4SLinus Torvalds 		if (val == yes) {
5651da177e4SLinus Torvalds 			if (def_menu) {
566413f006bSEGRY Gabor 				item_add_str(" (%s)", _(menu_get_prompt(def_menu)));
5672982de69SSam Ravnborg 				item_add_str("  --->");
5681da177e4SLinus Torvalds 				if (def_menu->list) {
5691da177e4SLinus Torvalds 					indent += 2;
5701da177e4SLinus Torvalds 					build_conf(def_menu);
5711da177e4SLinus Torvalds 					indent -= 2;
5721da177e4SLinus Torvalds 				}
5732982de69SSam Ravnborg 			}
5741da177e4SLinus Torvalds 			return;
5751da177e4SLinus Torvalds 		}
5761da177e4SLinus Torvalds 	} else {
5771da177e4SLinus Torvalds 		if (menu == current_menu) {
578413f006bSEGRY Gabor 			item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
5792982de69SSam Ravnborg 			item_set_tag(':');
5802982de69SSam Ravnborg 			item_set_data(menu);
5811da177e4SLinus Torvalds 			goto conf_childs;
5821da177e4SLinus Torvalds 		}
5831da177e4SLinus Torvalds 		child_count++;
5841da177e4SLinus Torvalds 		val = sym_get_tristate_value(sym);
5851da177e4SLinus Torvalds 		if (sym_is_choice_value(sym) && val == yes) {
5862982de69SSam Ravnborg 			item_make("   ");
5872982de69SSam Ravnborg 			item_set_tag(':');
5882982de69SSam Ravnborg 			item_set_data(menu);
5891da177e4SLinus Torvalds 		} else {
5901da177e4SLinus Torvalds 			switch (type) {
5911da177e4SLinus Torvalds 			case S_BOOLEAN:
5921da177e4SLinus Torvalds 				if (sym_is_changable(sym))
5932982de69SSam Ravnborg 					item_make("[%c]", val == no ? ' ' : '*');
5941da177e4SLinus Torvalds 				else
595b5d609dbSMatej Laitl 					item_make("-%c-", val == no ? ' ' : '*');
5962982de69SSam Ravnborg 				item_set_tag('t');
5972982de69SSam Ravnborg 				item_set_data(menu);
5981da177e4SLinus Torvalds 				break;
5991da177e4SLinus Torvalds 			case S_TRISTATE:
6001da177e4SLinus Torvalds 				switch (val) {
6011da177e4SLinus Torvalds 				case yes: ch = '*'; break;
6021da177e4SLinus Torvalds 				case mod: ch = 'M'; break;
6031da177e4SLinus Torvalds 				default:  ch = ' '; break;
6041da177e4SLinus Torvalds 				}
605b5d609dbSMatej Laitl 				if (sym_is_changable(sym)) {
606b5d609dbSMatej Laitl 					if (sym->rev_dep.tri == mod)
607b5d609dbSMatej Laitl 						item_make("{%c}", ch);
6081da177e4SLinus Torvalds 					else
609b5d609dbSMatej Laitl 						item_make("<%c>", ch);
610b5d609dbSMatej Laitl 				} else
611b5d609dbSMatej Laitl 					item_make("-%c-", ch);
6122982de69SSam Ravnborg 				item_set_tag('t');
6132982de69SSam Ravnborg 				item_set_data(menu);
6141da177e4SLinus Torvalds 				break;
6151da177e4SLinus Torvalds 			default:
6162982de69SSam Ravnborg 				tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
6172982de69SSam Ravnborg 				item_make("(%s)", sym_get_string_value(sym));
6181da177e4SLinus Torvalds 				tmp = indent - tmp + 4;
6191da177e4SLinus Torvalds 				if (tmp < 0)
6201da177e4SLinus Torvalds 					tmp = 0;
621413f006bSEGRY Gabor 				item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)),
6221da177e4SLinus Torvalds 					     (sym_has_value(sym) || !sym_is_changable(sym)) ?
623413f006bSEGRY Gabor 					     "" : _(" (NEW)"));
6242982de69SSam Ravnborg 				item_set_tag('s');
6252982de69SSam Ravnborg 				item_set_data(menu);
6261da177e4SLinus Torvalds 				goto conf_childs;
6271da177e4SLinus Torvalds 			}
6281da177e4SLinus Torvalds 		}
629413f006bSEGRY Gabor 		item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)),
6301da177e4SLinus Torvalds 			  (sym_has_value(sym) || !sym_is_changable(sym)) ?
631413f006bSEGRY Gabor 			  "" : _(" (NEW)"));
6321da177e4SLinus Torvalds 		if (menu->prompt->type == P_MENU) {
6331278ebdbSDirk Gouders 			item_add_str("  %s", menu_is_empty(menu) ? "----" : "--->");
6341da177e4SLinus Torvalds 			return;
6351da177e4SLinus Torvalds 		}
6361da177e4SLinus Torvalds 	}
6371da177e4SLinus Torvalds 
6381da177e4SLinus Torvalds conf_childs:
6391da177e4SLinus Torvalds 	indent += doint;
6401da177e4SLinus Torvalds 	for (child = menu->list; child; child = child->next)
6411da177e4SLinus Torvalds 		build_conf(child);
6421da177e4SLinus Torvalds 	indent -= doint;
6431da177e4SLinus Torvalds }
6441da177e4SLinus Torvalds 
6455e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_menu)
6461da177e4SLinus Torvalds {
6471da177e4SLinus Torvalds 	struct menu *submenu;
6481da177e4SLinus Torvalds 	const char *prompt = menu_get_prompt(menu);
6499a69abf8SBenjamin Poirier 	struct subtitle_part stpart;
6501da177e4SLinus Torvalds 	struct symbol *sym;
6512982de69SSam Ravnborg 	int res;
6522982de69SSam Ravnborg 	int s_scroll = 0;
6531da177e4SLinus Torvalds 
6549a69abf8SBenjamin Poirier 	if (menu != &rootmenu)
6559a69abf8SBenjamin Poirier 		stpart.text = menu_get_prompt(menu);
6569a69abf8SBenjamin Poirier 	else
6579a69abf8SBenjamin Poirier 		stpart.text = NULL;
6589a69abf8SBenjamin Poirier 	list_add_tail(&stpart.entries, &trail);
6599a69abf8SBenjamin Poirier 
6601da177e4SLinus Torvalds 	while (1) {
6612982de69SSam Ravnborg 		item_reset();
6621da177e4SLinus Torvalds 		current_menu = menu;
6631da177e4SLinus Torvalds 		build_conf(menu);
6641da177e4SLinus Torvalds 		if (!child_count)
6651da177e4SLinus Torvalds 			break;
6669a69abf8SBenjamin Poirier 		set_subtitle();
667e94c5bdeSSam Ravnborg 		dialog_clear();
668413f006bSEGRY Gabor 		res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
6692982de69SSam Ravnborg 				  _(menu_instructions),
6702982de69SSam Ravnborg 				  active_menu, &s_scroll);
671c8dc68adSSam Ravnborg 		if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
6721da177e4SLinus Torvalds 			break;
673063f4661SDirk Gouders 		if (item_count() != 0) {
6742982de69SSam Ravnborg 			if (!item_activate_selected())
6752982de69SSam Ravnborg 				continue;
6762982de69SSam Ravnborg 			if (!item_tag())
6771da177e4SLinus Torvalds 				continue;
678063f4661SDirk Gouders 		}
6792982de69SSam Ravnborg 		submenu = item_data();
6802982de69SSam Ravnborg 		active_menu = item_data();
681c8dc68adSSam Ravnborg 		if (submenu)
6821da177e4SLinus Torvalds 			sym = submenu->sym;
683c8dc68adSSam Ravnborg 		else
684c8dc68adSSam Ravnborg 			sym = NULL;
6851da177e4SLinus Torvalds 
6862982de69SSam Ravnborg 		switch (res) {
6871da177e4SLinus Torvalds 		case 0:
6882982de69SSam Ravnborg 			switch (item_tag()) {
6891da177e4SLinus Torvalds 			case 'm':
6901da177e4SLinus Torvalds 				if (single_menu_mode)
6911da177e4SLinus Torvalds 					submenu->data = (void *) (long) !submenu->data;
6921da177e4SLinus Torvalds 				else
6935e609addSBenjamin Poirier 					conf(submenu, NULL);
6941da177e4SLinus Torvalds 				break;
6951da177e4SLinus Torvalds 			case 't':
6961da177e4SLinus Torvalds 				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
6971da177e4SLinus Torvalds 					conf_choice(submenu);
6981da177e4SLinus Torvalds 				else if (submenu->prompt->type == P_MENU)
6995e609addSBenjamin Poirier 					conf(submenu, NULL);
7001da177e4SLinus Torvalds 				break;
7011da177e4SLinus Torvalds 			case 's':
7021da177e4SLinus Torvalds 				conf_string(submenu);
7031da177e4SLinus Torvalds 				break;
7041da177e4SLinus Torvalds 			}
7051da177e4SLinus Torvalds 			break;
7061da177e4SLinus Torvalds 		case 2:
7071da177e4SLinus Torvalds 			if (sym)
7081da177e4SLinus Torvalds 				show_help(submenu);
7099a69abf8SBenjamin Poirier 			else {
7109a69abf8SBenjamin Poirier 				reset_subtitle();
711413f006bSEGRY Gabor 				show_helptext(_("README"), _(mconf_readme));
7129a69abf8SBenjamin Poirier 			}
7131da177e4SLinus Torvalds 			break;
7141da177e4SLinus Torvalds 		case 3:
7159a69abf8SBenjamin Poirier 			reset_subtitle();
7166364fd0cSWang YanQing 			conf_save();
7176364fd0cSWang YanQing 			break;
7186364fd0cSWang YanQing 		case 4:
7199a69abf8SBenjamin Poirier 			reset_subtitle();
7206364fd0cSWang YanQing 			conf_load();
7216364fd0cSWang YanQing 			break;
7226364fd0cSWang YanQing 		case 5:
7232982de69SSam Ravnborg 			if (item_is_tag('t')) {
7241da177e4SLinus Torvalds 				if (sym_set_tristate_value(sym, yes))
7251da177e4SLinus Torvalds 					break;
7261da177e4SLinus Torvalds 				if (sym_set_tristate_value(sym, mod))
7271da177e4SLinus Torvalds 					show_textbox(NULL, setmod_text, 6, 74);
7281da177e4SLinus Torvalds 			}
7291da177e4SLinus Torvalds 			break;
7306364fd0cSWang YanQing 		case 6:
7312982de69SSam Ravnborg 			if (item_is_tag('t'))
7321da177e4SLinus Torvalds 				sym_set_tristate_value(sym, no);
7331da177e4SLinus Torvalds 			break;
7346364fd0cSWang YanQing 		case 7:
7352982de69SSam Ravnborg 			if (item_is_tag('t'))
7361da177e4SLinus Torvalds 				sym_set_tristate_value(sym, mod);
7371da177e4SLinus Torvalds 			break;
7386364fd0cSWang YanQing 		case 8:
7392982de69SSam Ravnborg 			if (item_is_tag('t'))
7401da177e4SLinus Torvalds 				sym_toggle_tristate_value(sym);
7412982de69SSam Ravnborg 			else if (item_is_tag('m'))
7425e609addSBenjamin Poirier 				conf(submenu, NULL);
7431da177e4SLinus Torvalds 			break;
7446364fd0cSWang YanQing 		case 9:
7451da177e4SLinus Torvalds 			search_conf();
7461da177e4SLinus Torvalds 			break;
7476364fd0cSWang YanQing 		case 10:
74822c7eca6SLi Zefan 			show_all_options = !show_all_options;
74922c7eca6SLi Zefan 			break;
7501da177e4SLinus Torvalds 		}
7511da177e4SLinus Torvalds 	}
7529a69abf8SBenjamin Poirier 
7539a69abf8SBenjamin Poirier 	list_del(trail.prev);
7541da177e4SLinus Torvalds }
7551da177e4SLinus Torvalds 
75695ac9b3bSBenjamin Poirier static int show_textbox_ext(const char *title, char *text, int r, int c, int
75795ac9b3bSBenjamin Poirier 			    *keys, int *vscroll, int *hscroll, update_text_fn
75895ac9b3bSBenjamin Poirier 			    update_text, void *data)
7591da177e4SLinus Torvalds {
760e94c5bdeSSam Ravnborg 	dialog_clear();
76195ac9b3bSBenjamin Poirier 	return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
76295ac9b3bSBenjamin Poirier 			      update_text, data);
763537ddae7SBenjamin Poirier }
764537ddae7SBenjamin Poirier 
765537ddae7SBenjamin Poirier static void show_textbox(const char *title, const char *text, int r, int c)
766537ddae7SBenjamin Poirier {
76795ac9b3bSBenjamin Poirier 	show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
76895ac9b3bSBenjamin Poirier 			 NULL, NULL);
7691da177e4SLinus Torvalds }
7701da177e4SLinus Torvalds 
7711da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text)
7721da177e4SLinus Torvalds {
7731da177e4SLinus Torvalds 	show_textbox(title, text, 0, 0);
7741da177e4SLinus Torvalds }
7751da177e4SLinus Torvalds 
7766364fd0cSWang YanQing static void conf_message_callback(const char *fmt, va_list ap)
7776364fd0cSWang YanQing {
7786364fd0cSWang YanQing 	char buf[PATH_MAX+1];
7796364fd0cSWang YanQing 
7806364fd0cSWang YanQing 	vsnprintf(buf, sizeof(buf), fmt, ap);
7810a1f00a1SMichal Marek 	if (save_and_exit) {
7820a1f00a1SMichal Marek 		if (!silent)
7836364fd0cSWang YanQing 			printf("%s", buf);
7840a1f00a1SMichal Marek 	} else {
7856364fd0cSWang YanQing 		show_textbox(NULL, buf, 6, 60);
7866364fd0cSWang YanQing 	}
7870a1f00a1SMichal Marek }
7886364fd0cSWang YanQing 
7891da177e4SLinus Torvalds static void show_help(struct menu *menu)
7901da177e4SLinus Torvalds {
7911da177e4SLinus Torvalds 	struct gstr help = str_new();
7921da177e4SLinus Torvalds 
793da60fbbcSVadim Bendebury (вб) 	help.max_width = getmaxx(stdscr) - 10;
7941d525e7cSCheng Renquan 	menu_get_ext_help(menu, &help);
7951d525e7cSCheng Renquan 
796413f006bSEGRY Gabor 	show_helptext(_(menu_get_prompt(menu)), str_get(&help));
7971da177e4SLinus Torvalds 	str_free(&help);
7981da177e4SLinus Torvalds }
7991da177e4SLinus Torvalds 
8001da177e4SLinus Torvalds static void conf_choice(struct menu *menu)
8011da177e4SLinus Torvalds {
802413f006bSEGRY Gabor 	const char *prompt = _(menu_get_prompt(menu));
8031da177e4SLinus Torvalds 	struct menu *child;
8041da177e4SLinus Torvalds 	struct symbol *active;
8051da177e4SLinus Torvalds 
8061da177e4SLinus Torvalds 	active = sym_get_choice_value(menu->sym);
8071da177e4SLinus Torvalds 	while (1) {
8082982de69SSam Ravnborg 		int res;
8092982de69SSam Ravnborg 		int selected;
8102982de69SSam Ravnborg 		item_reset();
8111da177e4SLinus Torvalds 
8121da177e4SLinus Torvalds 		current_menu = menu;
8131da177e4SLinus Torvalds 		for (child = menu->list; child; child = child->next) {
8141da177e4SLinus Torvalds 			if (!menu_is_visible(child))
8151da177e4SLinus Torvalds 				continue;
816af6c1598SPeter Korsgaard 			if (child->sym)
817413f006bSEGRY Gabor 				item_make("%s", _(menu_get_prompt(child)));
818af6c1598SPeter Korsgaard 			else {
819af6c1598SPeter Korsgaard 				item_make("*** %s ***", _(menu_get_prompt(child)));
820af6c1598SPeter Korsgaard 				item_set_tag(':');
821af6c1598SPeter Korsgaard 			}
8222982de69SSam Ravnborg 			item_set_data(child);
8232982de69SSam Ravnborg 			if (child->sym == active)
8242982de69SSam Ravnborg 				item_set_selected(1);
8251da177e4SLinus Torvalds 			if (child->sym == sym_get_choice_value(menu->sym))
8262982de69SSam Ravnborg 				item_set_tag('X');
8271da177e4SLinus Torvalds 		}
828e94c5bdeSSam Ravnborg 		dialog_clear();
829413f006bSEGRY Gabor 		res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
8302982de69SSam Ravnborg 					_(radiolist_instructions),
831ff7b0c2cSSedat Dilek 					MENUBOX_HEIGTH_MIN,
832ff7b0c2cSSedat Dilek 					MENUBOX_WIDTH_MIN,
833ff7b0c2cSSedat Dilek 					CHECKLIST_HEIGTH_MIN);
8342982de69SSam Ravnborg 		selected = item_activate_selected();
8352982de69SSam Ravnborg 		switch (res) {
8361da177e4SLinus Torvalds 		case 0:
8372982de69SSam Ravnborg 			if (selected) {
8382982de69SSam Ravnborg 				child = item_data();
839af6c1598SPeter Korsgaard 				if (!child->sym)
840af6c1598SPeter Korsgaard 					break;
841af6c1598SPeter Korsgaard 
8421da177e4SLinus Torvalds 				sym_set_tristate_value(child->sym, yes);
8432982de69SSam Ravnborg 			}
8441da177e4SLinus Torvalds 			return;
8451da177e4SLinus Torvalds 		case 1:
8462982de69SSam Ravnborg 			if (selected) {
8472982de69SSam Ravnborg 				child = item_data();
8481da177e4SLinus Torvalds 				show_help(child);
8491da177e4SLinus Torvalds 				active = child->sym;
8501da177e4SLinus Torvalds 			} else
8511da177e4SLinus Torvalds 				show_help(menu);
8521da177e4SLinus Torvalds 			break;
853f3cbcdc9SSam Ravnborg 		case KEY_ESC:
8541da177e4SLinus Torvalds 			return;
855c8dc68adSSam Ravnborg 		case -ERRDISPLAYTOOSMALL:
856c8dc68adSSam Ravnborg 			return;
8571da177e4SLinus Torvalds 		}
8581da177e4SLinus Torvalds 	}
8591da177e4SLinus Torvalds }
8601da177e4SLinus Torvalds 
8611da177e4SLinus Torvalds static void conf_string(struct menu *menu)
8621da177e4SLinus Torvalds {
8631da177e4SLinus Torvalds 	const char *prompt = menu_get_prompt(menu);
8641da177e4SLinus Torvalds 
8651da177e4SLinus Torvalds 	while (1) {
8662982de69SSam Ravnborg 		int res;
867c4143a83SSam Ravnborg 		const char *heading;
8682982de69SSam Ravnborg 
8691da177e4SLinus Torvalds 		switch (sym_get_type(menu->sym)) {
8701da177e4SLinus Torvalds 		case S_INT:
8712982de69SSam Ravnborg 			heading = _(inputbox_instructions_int);
8721da177e4SLinus Torvalds 			break;
8731da177e4SLinus Torvalds 		case S_HEX:
8742982de69SSam Ravnborg 			heading = _(inputbox_instructions_hex);
8751da177e4SLinus Torvalds 			break;
8761da177e4SLinus Torvalds 		case S_STRING:
8772982de69SSam Ravnborg 			heading = _(inputbox_instructions_string);
8781da177e4SLinus Torvalds 			break;
8791da177e4SLinus Torvalds 		default:
880413f006bSEGRY Gabor 			heading = _("Internal mconf error!");
8811da177e4SLinus Torvalds 		}
882e94c5bdeSSam Ravnborg 		dialog_clear();
883413f006bSEGRY Gabor 		res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
8842982de69SSam Ravnborg 				      heading, 10, 75,
8852982de69SSam Ravnborg 				      sym_get_string_value(menu->sym));
8862982de69SSam Ravnborg 		switch (res) {
8871da177e4SLinus Torvalds 		case 0:
8882982de69SSam Ravnborg 			if (sym_set_string_value(menu->sym, dialog_input_result))
8891da177e4SLinus Torvalds 				return;
8903b9fa093SArnaldo Carvalho de Melo 			show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
8911da177e4SLinus Torvalds 			break;
8921da177e4SLinus Torvalds 		case 1:
8931da177e4SLinus Torvalds 			show_help(menu);
8941da177e4SLinus Torvalds 			break;
895f3cbcdc9SSam Ravnborg 		case KEY_ESC:
8961da177e4SLinus Torvalds 			return;
8971da177e4SLinus Torvalds 		}
8981da177e4SLinus Torvalds 	}
8991da177e4SLinus Torvalds }
9001da177e4SLinus Torvalds 
9011da177e4SLinus Torvalds static void conf_load(void)
9021da177e4SLinus Torvalds {
9031da177e4SLinus Torvalds 
9041da177e4SLinus Torvalds 	while (1) {
9052982de69SSam Ravnborg 		int res;
906e94c5bdeSSam Ravnborg 		dialog_clear();
9072982de69SSam Ravnborg 		res = dialog_inputbox(NULL, load_config_text,
9082982de69SSam Ravnborg 				      11, 55, filename);
9092982de69SSam Ravnborg 		switch(res) {
9101da177e4SLinus Torvalds 		case 0:
9112982de69SSam Ravnborg 			if (!dialog_input_result[0])
9121da177e4SLinus Torvalds 				return;
91395e30f95SSam Ravnborg 			if (!conf_read(dialog_input_result)) {
91495e30f95SSam Ravnborg 				set_config_filename(dialog_input_result);
91536ef805bSSam Ravnborg 				sym_set_change_count(1);
9161da177e4SLinus Torvalds 				return;
91795e30f95SSam Ravnborg 			}
9183b9fa093SArnaldo Carvalho de Melo 			show_textbox(NULL, _("File does not exist!"), 5, 38);
9191da177e4SLinus Torvalds 			break;
9201da177e4SLinus Torvalds 		case 1:
9213b9fa093SArnaldo Carvalho de Melo 			show_helptext(_("Load Alternate Configuration"), load_config_help);
9221da177e4SLinus Torvalds 			break;
923f3cbcdc9SSam Ravnborg 		case KEY_ESC:
9241da177e4SLinus Torvalds 			return;
9251da177e4SLinus Torvalds 		}
9261da177e4SLinus Torvalds 	}
9271da177e4SLinus Torvalds }
9281da177e4SLinus Torvalds 
9291da177e4SLinus Torvalds static void conf_save(void)
9301da177e4SLinus Torvalds {
9311da177e4SLinus Torvalds 	while (1) {
9322982de69SSam Ravnborg 		int res;
933e94c5bdeSSam Ravnborg 		dialog_clear();
9342982de69SSam Ravnborg 		res = dialog_inputbox(NULL, save_config_text,
9352982de69SSam Ravnborg 				      11, 55, filename);
9362982de69SSam Ravnborg 		switch(res) {
9371da177e4SLinus Torvalds 		case 0:
9382982de69SSam Ravnborg 			if (!dialog_input_result[0])
9391da177e4SLinus Torvalds 				return;
94095e30f95SSam Ravnborg 			if (!conf_write(dialog_input_result)) {
94195e30f95SSam Ravnborg 				set_config_filename(dialog_input_result);
9421da177e4SLinus Torvalds 				return;
94395e30f95SSam Ravnborg 			}
9443b9fa093SArnaldo Carvalho de Melo 			show_textbox(NULL, _("Can't create file!  Probably a nonexistent directory."), 5, 60);
9451da177e4SLinus Torvalds 			break;
9461da177e4SLinus Torvalds 		case 1:
9473b9fa093SArnaldo Carvalho de Melo 			show_helptext(_("Save Alternate Configuration"), save_config_help);
9481da177e4SLinus Torvalds 			break;
949f3cbcdc9SSam Ravnborg 		case KEY_ESC:
9501da177e4SLinus Torvalds 			return;
9511da177e4SLinus Torvalds 		}
9521da177e4SLinus Torvalds 	}
9531da177e4SLinus Torvalds }
9541da177e4SLinus Torvalds 
955564899f9SDavidlohr Bueso static int handle_exit(void)
956564899f9SDavidlohr Bueso {
957564899f9SDavidlohr Bueso 	int res;
958564899f9SDavidlohr Bueso 
9596364fd0cSWang YanQing 	save_and_exit = 1;
9609a69abf8SBenjamin Poirier 	reset_subtitle();
961564899f9SDavidlohr Bueso 	dialog_clear();
962564899f9SDavidlohr Bueso 	if (conf_get_changed())
963564899f9SDavidlohr Bueso 		res = dialog_yesno(NULL,
964564899f9SDavidlohr Bueso 				   _("Do you wish to save your new configuration?\n"
96513763916SDirk Gouders 				     "(Press <ESC><ESC> to continue kernel configuration.)"),
966564899f9SDavidlohr Bueso 				   6, 60);
967564899f9SDavidlohr Bueso 	else
968564899f9SDavidlohr Bueso 		res = -1;
969564899f9SDavidlohr Bueso 
970564899f9SDavidlohr Bueso 	end_dialog(saved_x, saved_y);
971564899f9SDavidlohr Bueso 
972564899f9SDavidlohr Bueso 	switch (res) {
973564899f9SDavidlohr Bueso 	case 0:
974564899f9SDavidlohr Bueso 		if (conf_write(filename)) {
975564899f9SDavidlohr Bueso 			fprintf(stderr, _("\n\n"
976564899f9SDavidlohr Bueso 					  "Error while writing of the configuration.\n"
977564899f9SDavidlohr Bueso 					  "Your configuration changes were NOT saved."
978564899f9SDavidlohr Bueso 					  "\n\n"));
979564899f9SDavidlohr Bueso 			return 1;
980564899f9SDavidlohr Bueso 		}
981564899f9SDavidlohr Bueso 		/* fall through */
982564899f9SDavidlohr Bueso 	case -1:
9830a1f00a1SMichal Marek 		if (!silent)
984564899f9SDavidlohr Bueso 			printf(_("\n\n"
985564899f9SDavidlohr Bueso 				 "*** End of the configuration.\n"
986564899f9SDavidlohr Bueso 				 "*** Execute 'make' to start the build or try 'make help'."
987564899f9SDavidlohr Bueso 				 "\n\n"));
988564899f9SDavidlohr Bueso 		res = 0;
989564899f9SDavidlohr Bueso 		break;
990564899f9SDavidlohr Bueso 	default:
9910a1f00a1SMichal Marek 		if (!silent)
992564899f9SDavidlohr Bueso 			fprintf(stderr, _("\n\n"
993564899f9SDavidlohr Bueso 					  "Your configuration changes were NOT saved."
994564899f9SDavidlohr Bueso 					  "\n\n"));
99530c4eaafSLi Zefan 		if (res != KEY_ESC)
996c55ac154SWang YanQing 			res = 0;
997564899f9SDavidlohr Bueso 	}
998564899f9SDavidlohr Bueso 
999564899f9SDavidlohr Bueso 	return res;
1000564899f9SDavidlohr Bueso }
1001564899f9SDavidlohr Bueso 
1002564899f9SDavidlohr Bueso static void sig_handler(int signo)
1003564899f9SDavidlohr Bueso {
1004564899f9SDavidlohr Bueso 	exit(handle_exit());
1005564899f9SDavidlohr Bueso }
1006564899f9SDavidlohr Bueso 
10071da177e4SLinus Torvalds int main(int ac, char **av)
10081da177e4SLinus Torvalds {
10091da177e4SLinus Torvalds 	char *mode;
10102982de69SSam Ravnborg 	int res;
10111da177e4SLinus Torvalds 
10123b9fa093SArnaldo Carvalho de Melo 	setlocale(LC_ALL, "");
10133b9fa093SArnaldo Carvalho de Melo 	bindtextdomain(PACKAGE, LOCALEDIR);
10143b9fa093SArnaldo Carvalho de Melo 	textdomain(PACKAGE);
10153b9fa093SArnaldo Carvalho de Melo 
1016564899f9SDavidlohr Bueso 	signal(SIGINT, sig_handler);
1017564899f9SDavidlohr Bueso 
10180a1f00a1SMichal Marek 	if (ac > 1 && strcmp(av[1], "-s") == 0) {
10190a1f00a1SMichal Marek 		silent = 1;
10200a1f00a1SMichal Marek 		/* Silence conf_read() until the real callback is set up */
10210a1f00a1SMichal Marek 		conf_set_message_callback(NULL);
10220a1f00a1SMichal Marek 		av++;
10230a1f00a1SMichal Marek 	}
10241da177e4SLinus Torvalds 	conf_parse(av[1]);
10251da177e4SLinus Torvalds 	conf_read(NULL);
10261da177e4SLinus Torvalds 
10271da177e4SLinus Torvalds 	mode = getenv("MENUCONFIG_MODE");
10281da177e4SLinus Torvalds 	if (mode) {
10291da177e4SLinus Torvalds 		if (!strcasecmp(mode, "single_menu"))
10301da177e4SLinus Torvalds 			single_menu_mode = 1;
10311da177e4SLinus Torvalds 	}
10321da177e4SLinus Torvalds 
103309af091fSLadislav Michl 	if (init_dialog(NULL)) {
103409af091fSLadislav Michl 		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
103509af091fSLadislav Michl 		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
103609af091fSLadislav Michl 		return 1;
103709af091fSLadislav Michl 	}
103809af091fSLadislav Michl 
1039d802b50fSSam Ravnborg 	set_config_filename(conf_get_configname());
10406364fd0cSWang YanQing 	conf_set_message_callback(conf_message_callback);
1041f3cbcdc9SSam Ravnborg 	do {
10425e609addSBenjamin Poirier 		conf(&rootmenu, NULL);
1043564899f9SDavidlohr Bueso 		res = handle_exit();
1044f3cbcdc9SSam Ravnborg 	} while (res == KEY_ESC);
1045b3214293SKarsten Wiese 
1046564899f9SDavidlohr Bueso 	return res;
10471da177e4SLinus Torvalds }
1048