xref: /openbmc/linux/scripts/kconfig/mconf.c (revision e4e458b4)
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;
2821da177e4SLinus Torvalds 
2835e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_menu);
2841da177e4SLinus Torvalds static void conf_choice(struct menu *menu);
2851da177e4SLinus Torvalds static void conf_string(struct menu *menu);
2861da177e4SLinus Torvalds static void conf_load(void);
2871da177e4SLinus Torvalds static void conf_save(void);
28895ac9b3bSBenjamin Poirier static int show_textbox_ext(const char *title, char *text, int r, int c,
28995ac9b3bSBenjamin Poirier 			    int *keys, int *vscroll, int *hscroll,
29095ac9b3bSBenjamin Poirier 			    update_text_fn update_text, void *data);
2911da177e4SLinus Torvalds static void show_textbox(const char *title, const char *text, int r, int c);
2921da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text);
2931da177e4SLinus Torvalds static void show_help(struct menu *menu);
2941da177e4SLinus Torvalds 
29595e30f95SSam Ravnborg static char filename[PATH_MAX+1];
29695e30f95SSam Ravnborg static void set_config_filename(const char *config_filename)
29795e30f95SSam Ravnborg {
29895e30f95SSam Ravnborg 	static char menu_backtitle[PATH_MAX+128];
29995e30f95SSam Ravnborg 	int size;
30095e30f95SSam Ravnborg 
30195e30f95SSam Ravnborg 	size = snprintf(menu_backtitle, sizeof(menu_backtitle),
3020954828fSArnaud Lacombe 			"%s - %s", config_filename, rootmenu.prompt->text);
30395e30f95SSam Ravnborg 	if (size >= sizeof(menu_backtitle))
30495e30f95SSam Ravnborg 		menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
30595e30f95SSam Ravnborg 	set_dialog_backtitle(menu_backtitle);
30695e30f95SSam Ravnborg 
30795e30f95SSam Ravnborg 	size = snprintf(filename, sizeof(filename), "%s", config_filename);
30895e30f95SSam Ravnborg 	if (size >= sizeof(filename))
30995e30f95SSam Ravnborg 		filename[sizeof(filename)-1] = '\0';
31095e30f95SSam Ravnborg }
31195e30f95SSam Ravnborg 
3129a69abf8SBenjamin Poirier struct subtitle_part {
3139a69abf8SBenjamin Poirier 	struct list_head entries;
3149a69abf8SBenjamin Poirier 	const char *text;
3159a69abf8SBenjamin Poirier };
3169a69abf8SBenjamin Poirier static LIST_HEAD(trail);
3179a69abf8SBenjamin Poirier 
3189a69abf8SBenjamin Poirier static struct subtitle_list *subtitles;
3199a69abf8SBenjamin Poirier static void set_subtitle(void)
3209a69abf8SBenjamin Poirier {
3219a69abf8SBenjamin Poirier 	struct subtitle_part *sp;
3229a69abf8SBenjamin Poirier 	struct subtitle_list *pos, *tmp;
3239a69abf8SBenjamin Poirier 
3249a69abf8SBenjamin Poirier 	for (pos = subtitles; pos != NULL; pos = tmp) {
3259a69abf8SBenjamin Poirier 		tmp = pos->next;
3269a69abf8SBenjamin Poirier 		free(pos);
3279a69abf8SBenjamin Poirier 	}
3289a69abf8SBenjamin Poirier 
3299a69abf8SBenjamin Poirier 	subtitles = NULL;
3309a69abf8SBenjamin Poirier 	list_for_each_entry(sp, &trail, entries) {
3319a69abf8SBenjamin Poirier 		if (sp->text) {
3329a69abf8SBenjamin Poirier 			if (pos) {
333e4e458b4SArjun Sreedharan 				pos->next = xcalloc(1, sizeof(*pos));
3349a69abf8SBenjamin Poirier 				pos = pos->next;
3359a69abf8SBenjamin Poirier 			} else {
336e4e458b4SArjun Sreedharan 				subtitles = pos = xcalloc(1, sizeof(*pos));
3379a69abf8SBenjamin Poirier 			}
3389a69abf8SBenjamin Poirier 			pos->text = sp->text;
3399a69abf8SBenjamin Poirier 		}
3409a69abf8SBenjamin Poirier 	}
3419a69abf8SBenjamin Poirier 
3429a69abf8SBenjamin Poirier 	set_dialog_subtitles(subtitles);
3439a69abf8SBenjamin Poirier }
3449a69abf8SBenjamin Poirier 
3459a69abf8SBenjamin Poirier static void reset_subtitle(void)
3469a69abf8SBenjamin Poirier {
3479a69abf8SBenjamin Poirier 	struct subtitle_list *pos, *tmp;
3489a69abf8SBenjamin Poirier 
3499a69abf8SBenjamin Poirier 	for (pos = subtitles; pos != NULL; pos = tmp) {
3509a69abf8SBenjamin Poirier 		tmp = pos->next;
3519a69abf8SBenjamin Poirier 		free(pos);
3529a69abf8SBenjamin Poirier 	}
3539a69abf8SBenjamin Poirier 	subtitles = NULL;
3549a69abf8SBenjamin Poirier 	set_dialog_subtitles(subtitles);
3559a69abf8SBenjamin Poirier }
35695e30f95SSam Ravnborg 
35795ac9b3bSBenjamin Poirier struct search_data {
358bad9955dSBenjamin Poirier 	struct list_head *head;
35995ac9b3bSBenjamin Poirier 	struct menu **targets;
36095ac9b3bSBenjamin Poirier 	int *keys;
36195ac9b3bSBenjamin Poirier };
36295ac9b3bSBenjamin Poirier 
36395ac9b3bSBenjamin Poirier static void update_text(char *buf, size_t start, size_t end, void *_data)
36495ac9b3bSBenjamin Poirier {
36595ac9b3bSBenjamin Poirier 	struct search_data *data = _data;
36695ac9b3bSBenjamin Poirier 	struct jump_key *pos;
36795ac9b3bSBenjamin Poirier 	int k = 0;
36895ac9b3bSBenjamin Poirier 
369bad9955dSBenjamin Poirier 	list_for_each_entry(pos, data->head, entries) {
37095ac9b3bSBenjamin Poirier 		if (pos->offset >= start && pos->offset < end) {
37195ac9b3bSBenjamin Poirier 			char header[4];
37295ac9b3bSBenjamin Poirier 
37395ac9b3bSBenjamin Poirier 			if (k < JUMP_NB) {
37495ac9b3bSBenjamin Poirier 				int key = '0' + (pos->index % JUMP_NB) + 1;
37595ac9b3bSBenjamin Poirier 
37695ac9b3bSBenjamin Poirier 				sprintf(header, "(%c)", key);
37795ac9b3bSBenjamin Poirier 				data->keys[k] = key;
37895ac9b3bSBenjamin Poirier 				data->targets[k] = pos->target;
37995ac9b3bSBenjamin Poirier 				k++;
38095ac9b3bSBenjamin Poirier 			} else {
38195ac9b3bSBenjamin Poirier 				sprintf(header, "   ");
38295ac9b3bSBenjamin Poirier 			}
38395ac9b3bSBenjamin Poirier 
38495ac9b3bSBenjamin Poirier 			memcpy(buf + pos->offset, header, sizeof(header) - 1);
38595ac9b3bSBenjamin Poirier 		}
38695ac9b3bSBenjamin Poirier 	}
38795ac9b3bSBenjamin Poirier 	data->keys[k] = 0;
38895ac9b3bSBenjamin Poirier }
38995ac9b3bSBenjamin Poirier 
3901da177e4SLinus Torvalds static void search_conf(void)
3911da177e4SLinus Torvalds {
3921da177e4SLinus Torvalds 	struct symbol **sym_arr;
3931da177e4SLinus Torvalds 	struct gstr res;
394337a275dSYann E. MORIN 	struct gstr title;
3950584f9f9SBernhard Walle 	char *dialog_input;
3965e609addSBenjamin Poirier 	int dres, vscroll = 0, hscroll = 0;
3975e609addSBenjamin Poirier 	bool again;
3989a69abf8SBenjamin Poirier 	struct gstr sttext;
3999a69abf8SBenjamin Poirier 	struct subtitle_part stpart;
4005e609addSBenjamin Poirier 
401337a275dSYann E. MORIN 	title = str_new();
402f6eb6e46SYann E. MORIN 	str_printf( &title, _("Enter (sub)string or regexp to search for "
403f6eb6e46SYann E. MORIN 			      "(with or without \"%s\")"), CONFIG_);
404337a275dSYann E. MORIN 
4051da177e4SLinus Torvalds again:
406e94c5bdeSSam Ravnborg 	dialog_clear();
4072982de69SSam Ravnborg 	dres = dialog_inputbox(_("Search Configuration Parameter"),
408337a275dSYann E. MORIN 			      str_get(&title),
4092982de69SSam Ravnborg 			      10, 75, "");
4102982de69SSam Ravnborg 	switch (dres) {
4111da177e4SLinus Torvalds 	case 0:
4121da177e4SLinus Torvalds 		break;
4131da177e4SLinus Torvalds 	case 1:
4143b9fa093SArnaldo Carvalho de Melo 		show_helptext(_("Search Configuration"), search_help);
4151da177e4SLinus Torvalds 		goto again;
4161da177e4SLinus Torvalds 	default:
417337a275dSYann E. MORIN 		str_free(&title);
4181da177e4SLinus Torvalds 		return;
4191da177e4SLinus Torvalds 	}
4201da177e4SLinus Torvalds 
421ffb5957bSArnaud Lacombe 	/* strip the prefix if necessary */
4220584f9f9SBernhard Walle 	dialog_input = dialog_input_result;
423ffb5957bSArnaud Lacombe 	if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
424ffb5957bSArnaud Lacombe 		dialog_input += strlen(CONFIG_);
4250584f9f9SBernhard Walle 
4269a69abf8SBenjamin Poirier 	sttext = str_new();
4279a69abf8SBenjamin Poirier 	str_printf(&sttext, "Search (%s)", dialog_input_result);
4289a69abf8SBenjamin Poirier 	stpart.text = str_get(&sttext);
4299a69abf8SBenjamin Poirier 	list_add_tail(&stpart.entries, &trail);
4309a69abf8SBenjamin Poirier 
4310584f9f9SBernhard Walle 	sym_arr = sym_re_search(dialog_input);
4325e609addSBenjamin Poirier 	do {
433bad9955dSBenjamin Poirier 		LIST_HEAD(head);
43495ac9b3bSBenjamin Poirier 		struct menu *targets[JUMP_NB];
43595ac9b3bSBenjamin Poirier 		int keys[JUMP_NB + 1], i;
43695ac9b3bSBenjamin Poirier 		struct search_data data = {
43795ac9b3bSBenjamin Poirier 			.head = &head,
43895ac9b3bSBenjamin Poirier 			.targets = targets,
43995ac9b3bSBenjamin Poirier 			.keys = keys,
44095ac9b3bSBenjamin Poirier 		};
441edb749f4SBenjamin Poirier 		struct jump_key *pos, *tmp;
4425e609addSBenjamin Poirier 
44395ac9b3bSBenjamin Poirier 		res = get_relations_str(sym_arr, &head);
4449a69abf8SBenjamin Poirier 		set_subtitle();
44595ac9b3bSBenjamin Poirier 		dres = show_textbox_ext(_("Search Results"), (char *)
44695ac9b3bSBenjamin Poirier 					str_get(&res), 0, 0, keys, &vscroll,
44795ac9b3bSBenjamin Poirier 					&hscroll, &update_text, (void *)
44895ac9b3bSBenjamin Poirier 					&data);
4495e609addSBenjamin Poirier 		again = false;
45095ac9b3bSBenjamin Poirier 		for (i = 0; i < JUMP_NB && keys[i]; i++)
4515e609addSBenjamin Poirier 			if (dres == keys[i]) {
45295ac9b3bSBenjamin Poirier 				conf(targets[i]->parent, targets[i]);
4535e609addSBenjamin Poirier 				again = true;
4545e609addSBenjamin Poirier 			}
4551da177e4SLinus Torvalds 		str_free(&res);
456edb749f4SBenjamin Poirier 		list_for_each_entry_safe(pos, tmp, &head, entries)
457edb749f4SBenjamin Poirier 			free(pos);
4585e609addSBenjamin Poirier 	} while (again);
4595e609addSBenjamin Poirier 	free(sym_arr);
460337a275dSYann E. MORIN 	str_free(&title);
4619a69abf8SBenjamin Poirier 	list_del(trail.prev);
4629a69abf8SBenjamin Poirier 	str_free(&sttext);
4631da177e4SLinus Torvalds }
4641da177e4SLinus Torvalds 
4651da177e4SLinus Torvalds static void build_conf(struct menu *menu)
4661da177e4SLinus Torvalds {
4671da177e4SLinus Torvalds 	struct symbol *sym;
4681da177e4SLinus Torvalds 	struct property *prop;
4691da177e4SLinus Torvalds 	struct menu *child;
4701da177e4SLinus Torvalds 	int type, tmp, doint = 2;
4711da177e4SLinus Torvalds 	tristate val;
4721da177e4SLinus Torvalds 	char ch;
47322c7eca6SLi Zefan 	bool visible;
4741da177e4SLinus Torvalds 
47522c7eca6SLi Zefan 	/*
47622c7eca6SLi Zefan 	 * note: menu_is_visible() has side effect that it will
47722c7eca6SLi Zefan 	 * recalc the value of the symbol.
47822c7eca6SLi Zefan 	 */
47922c7eca6SLi Zefan 	visible = menu_is_visible(menu);
48022c7eca6SLi Zefan 	if (show_all_options && !menu_has_prompt(menu))
48122c7eca6SLi Zefan 		return;
48222c7eca6SLi Zefan 	else if (!show_all_options && !visible)
4831da177e4SLinus Torvalds 		return;
4841da177e4SLinus Torvalds 
4851da177e4SLinus Torvalds 	sym = menu->sym;
4861da177e4SLinus Torvalds 	prop = menu->prompt;
4871da177e4SLinus Torvalds 	if (!sym) {
4881da177e4SLinus Torvalds 		if (prop && menu != current_menu) {
4891da177e4SLinus Torvalds 			const char *prompt = menu_get_prompt(menu);
4901da177e4SLinus Torvalds 			switch (prop->type) {
4911da177e4SLinus Torvalds 			case P_MENU:
4921da177e4SLinus Torvalds 				child_count++;
493413f006bSEGRY Gabor 				prompt = _(prompt);
4941da177e4SLinus Torvalds 				if (single_menu_mode) {
4952982de69SSam Ravnborg 					item_make("%s%*c%s",
4961da177e4SLinus Torvalds 						  menu->data ? "-->" : "++>",
4971da177e4SLinus Torvalds 						  indent + 1, ' ', prompt);
4981da177e4SLinus Torvalds 				} else
4991278ebdbSDirk Gouders 					item_make("   %*c%s  %s",
5001278ebdbSDirk Gouders 						  indent + 1, ' ', prompt,
5011278ebdbSDirk Gouders 						  menu_is_empty(menu) ? "----" : "--->");
5022982de69SSam Ravnborg 				item_set_tag('m');
5032982de69SSam Ravnborg 				item_set_data(menu);
5041da177e4SLinus Torvalds 				if (single_menu_mode && menu->data)
5051da177e4SLinus Torvalds 					goto conf_childs;
5061da177e4SLinus Torvalds 				return;
50748874077SSam Ravnborg 			case P_COMMENT:
50848874077SSam Ravnborg 				if (prompt) {
50948874077SSam Ravnborg 					child_count++;
510413f006bSEGRY Gabor 					item_make("   %*c*** %s ***", indent + 1, ' ', _(prompt));
51148874077SSam Ravnborg 					item_set_tag(':');
51248874077SSam Ravnborg 					item_set_data(menu);
51348874077SSam Ravnborg 				}
51448874077SSam Ravnborg 				break;
5151da177e4SLinus Torvalds 			default:
5161da177e4SLinus Torvalds 				if (prompt) {
5171da177e4SLinus Torvalds 					child_count++;
518413f006bSEGRY Gabor 					item_make("---%*c%s", indent + 1, ' ', _(prompt));
5192982de69SSam Ravnborg 					item_set_tag(':');
5202982de69SSam Ravnborg 					item_set_data(menu);
5211da177e4SLinus Torvalds 				}
5221da177e4SLinus Torvalds 			}
5231da177e4SLinus Torvalds 		} else
5241da177e4SLinus Torvalds 			doint = 0;
5251da177e4SLinus Torvalds 		goto conf_childs;
5261da177e4SLinus Torvalds 	}
5271da177e4SLinus Torvalds 
5281da177e4SLinus Torvalds 	type = sym_get_type(sym);
5291da177e4SLinus Torvalds 	if (sym_is_choice(sym)) {
5301da177e4SLinus Torvalds 		struct symbol *def_sym = sym_get_choice_value(sym);
5311da177e4SLinus Torvalds 		struct menu *def_menu = NULL;
5321da177e4SLinus Torvalds 
5331da177e4SLinus Torvalds 		child_count++;
5341da177e4SLinus Torvalds 		for (child = menu->list; child; child = child->next) {
5351da177e4SLinus Torvalds 			if (menu_is_visible(child) && child->sym == def_sym)
5361da177e4SLinus Torvalds 				def_menu = child;
5371da177e4SLinus Torvalds 		}
5381da177e4SLinus Torvalds 
5391da177e4SLinus Torvalds 		val = sym_get_tristate_value(sym);
5401da177e4SLinus Torvalds 		if (sym_is_changable(sym)) {
5411da177e4SLinus Torvalds 			switch (type) {
5421da177e4SLinus Torvalds 			case S_BOOLEAN:
5432982de69SSam Ravnborg 				item_make("[%c]", val == no ? ' ' : '*');
5441da177e4SLinus Torvalds 				break;
5451da177e4SLinus Torvalds 			case S_TRISTATE:
5461da177e4SLinus Torvalds 				switch (val) {
5471da177e4SLinus Torvalds 				case yes: ch = '*'; break;
5481da177e4SLinus Torvalds 				case mod: ch = 'M'; break;
5491da177e4SLinus Torvalds 				default:  ch = ' '; break;
5501da177e4SLinus Torvalds 				}
5512982de69SSam Ravnborg 				item_make("<%c>", ch);
5521da177e4SLinus Torvalds 				break;
5531da177e4SLinus Torvalds 			}
5542982de69SSam Ravnborg 			item_set_tag('t');
5552982de69SSam Ravnborg 			item_set_data(menu);
5561da177e4SLinus Torvalds 		} else {
5572982de69SSam Ravnborg 			item_make("   ");
5582982de69SSam Ravnborg 			item_set_tag(def_menu ? 't' : ':');
5592982de69SSam Ravnborg 			item_set_data(menu);
5601da177e4SLinus Torvalds 		}
5611da177e4SLinus Torvalds 
562413f006bSEGRY Gabor 		item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
5631da177e4SLinus Torvalds 		if (val == yes) {
5641da177e4SLinus Torvalds 			if (def_menu) {
565413f006bSEGRY Gabor 				item_add_str(" (%s)", _(menu_get_prompt(def_menu)));
5662982de69SSam Ravnborg 				item_add_str("  --->");
5671da177e4SLinus Torvalds 				if (def_menu->list) {
5681da177e4SLinus Torvalds 					indent += 2;
5691da177e4SLinus Torvalds 					build_conf(def_menu);
5701da177e4SLinus Torvalds 					indent -= 2;
5711da177e4SLinus Torvalds 				}
5722982de69SSam Ravnborg 			}
5731da177e4SLinus Torvalds 			return;
5741da177e4SLinus Torvalds 		}
5751da177e4SLinus Torvalds 	} else {
5761da177e4SLinus Torvalds 		if (menu == current_menu) {
577413f006bSEGRY Gabor 			item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
5782982de69SSam Ravnborg 			item_set_tag(':');
5792982de69SSam Ravnborg 			item_set_data(menu);
5801da177e4SLinus Torvalds 			goto conf_childs;
5811da177e4SLinus Torvalds 		}
5821da177e4SLinus Torvalds 		child_count++;
5831da177e4SLinus Torvalds 		val = sym_get_tristate_value(sym);
5841da177e4SLinus Torvalds 		if (sym_is_choice_value(sym) && val == yes) {
5852982de69SSam Ravnborg 			item_make("   ");
5862982de69SSam Ravnborg 			item_set_tag(':');
5872982de69SSam Ravnborg 			item_set_data(menu);
5881da177e4SLinus Torvalds 		} else {
5891da177e4SLinus Torvalds 			switch (type) {
5901da177e4SLinus Torvalds 			case S_BOOLEAN:
5911da177e4SLinus Torvalds 				if (sym_is_changable(sym))
5922982de69SSam Ravnborg 					item_make("[%c]", val == no ? ' ' : '*');
5931da177e4SLinus Torvalds 				else
594b5d609dbSMatej Laitl 					item_make("-%c-", val == no ? ' ' : '*');
5952982de69SSam Ravnborg 				item_set_tag('t');
5962982de69SSam Ravnborg 				item_set_data(menu);
5971da177e4SLinus Torvalds 				break;
5981da177e4SLinus Torvalds 			case S_TRISTATE:
5991da177e4SLinus Torvalds 				switch (val) {
6001da177e4SLinus Torvalds 				case yes: ch = '*'; break;
6011da177e4SLinus Torvalds 				case mod: ch = 'M'; break;
6021da177e4SLinus Torvalds 				default:  ch = ' '; break;
6031da177e4SLinus Torvalds 				}
604b5d609dbSMatej Laitl 				if (sym_is_changable(sym)) {
605b5d609dbSMatej Laitl 					if (sym->rev_dep.tri == mod)
606b5d609dbSMatej Laitl 						item_make("{%c}", ch);
6071da177e4SLinus Torvalds 					else
608b5d609dbSMatej Laitl 						item_make("<%c>", ch);
609b5d609dbSMatej Laitl 				} else
610b5d609dbSMatej Laitl 					item_make("-%c-", ch);
6112982de69SSam Ravnborg 				item_set_tag('t');
6122982de69SSam Ravnborg 				item_set_data(menu);
6131da177e4SLinus Torvalds 				break;
6141da177e4SLinus Torvalds 			default:
6152982de69SSam Ravnborg 				tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
6162982de69SSam Ravnborg 				item_make("(%s)", sym_get_string_value(sym));
6171da177e4SLinus Torvalds 				tmp = indent - tmp + 4;
6181da177e4SLinus Torvalds 				if (tmp < 0)
6191da177e4SLinus Torvalds 					tmp = 0;
620413f006bSEGRY Gabor 				item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)),
6211da177e4SLinus Torvalds 					     (sym_has_value(sym) || !sym_is_changable(sym)) ?
622413f006bSEGRY Gabor 					     "" : _(" (NEW)"));
6232982de69SSam Ravnborg 				item_set_tag('s');
6242982de69SSam Ravnborg 				item_set_data(menu);
6251da177e4SLinus Torvalds 				goto conf_childs;
6261da177e4SLinus Torvalds 			}
6271da177e4SLinus Torvalds 		}
628413f006bSEGRY Gabor 		item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)),
6291da177e4SLinus Torvalds 			  (sym_has_value(sym) || !sym_is_changable(sym)) ?
630413f006bSEGRY Gabor 			  "" : _(" (NEW)"));
6311da177e4SLinus Torvalds 		if (menu->prompt->type == P_MENU) {
6321278ebdbSDirk Gouders 			item_add_str("  %s", menu_is_empty(menu) ? "----" : "--->");
6331da177e4SLinus Torvalds 			return;
6341da177e4SLinus Torvalds 		}
6351da177e4SLinus Torvalds 	}
6361da177e4SLinus Torvalds 
6371da177e4SLinus Torvalds conf_childs:
6381da177e4SLinus Torvalds 	indent += doint;
6391da177e4SLinus Torvalds 	for (child = menu->list; child; child = child->next)
6401da177e4SLinus Torvalds 		build_conf(child);
6411da177e4SLinus Torvalds 	indent -= doint;
6421da177e4SLinus Torvalds }
6431da177e4SLinus Torvalds 
6445e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_menu)
6451da177e4SLinus Torvalds {
6461da177e4SLinus Torvalds 	struct menu *submenu;
6471da177e4SLinus Torvalds 	const char *prompt = menu_get_prompt(menu);
6489a69abf8SBenjamin Poirier 	struct subtitle_part stpart;
6491da177e4SLinus Torvalds 	struct symbol *sym;
6502982de69SSam Ravnborg 	int res;
6512982de69SSam Ravnborg 	int s_scroll = 0;
6521da177e4SLinus Torvalds 
6539a69abf8SBenjamin Poirier 	if (menu != &rootmenu)
6549a69abf8SBenjamin Poirier 		stpart.text = menu_get_prompt(menu);
6559a69abf8SBenjamin Poirier 	else
6569a69abf8SBenjamin Poirier 		stpart.text = NULL;
6579a69abf8SBenjamin Poirier 	list_add_tail(&stpart.entries, &trail);
6589a69abf8SBenjamin Poirier 
6591da177e4SLinus Torvalds 	while (1) {
6602982de69SSam Ravnborg 		item_reset();
6611da177e4SLinus Torvalds 		current_menu = menu;
6621da177e4SLinus Torvalds 		build_conf(menu);
6631da177e4SLinus Torvalds 		if (!child_count)
6641da177e4SLinus Torvalds 			break;
6659a69abf8SBenjamin Poirier 		set_subtitle();
666e94c5bdeSSam Ravnborg 		dialog_clear();
667413f006bSEGRY Gabor 		res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
6682982de69SSam Ravnborg 				  _(menu_instructions),
6692982de69SSam Ravnborg 				  active_menu, &s_scroll);
670c8dc68adSSam Ravnborg 		if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
6711da177e4SLinus Torvalds 			break;
672063f4661SDirk Gouders 		if (item_count() != 0) {
6732982de69SSam Ravnborg 			if (!item_activate_selected())
6742982de69SSam Ravnborg 				continue;
6752982de69SSam Ravnborg 			if (!item_tag())
6761da177e4SLinus Torvalds 				continue;
677063f4661SDirk Gouders 		}
6782982de69SSam Ravnborg 		submenu = item_data();
6792982de69SSam Ravnborg 		active_menu = item_data();
680c8dc68adSSam Ravnborg 		if (submenu)
6811da177e4SLinus Torvalds 			sym = submenu->sym;
682c8dc68adSSam Ravnborg 		else
683c8dc68adSSam Ravnborg 			sym = NULL;
6841da177e4SLinus Torvalds 
6852982de69SSam Ravnborg 		switch (res) {
6861da177e4SLinus Torvalds 		case 0:
6872982de69SSam Ravnborg 			switch (item_tag()) {
6881da177e4SLinus Torvalds 			case 'm':
6891da177e4SLinus Torvalds 				if (single_menu_mode)
6901da177e4SLinus Torvalds 					submenu->data = (void *) (long) !submenu->data;
6911da177e4SLinus Torvalds 				else
6925e609addSBenjamin Poirier 					conf(submenu, NULL);
6931da177e4SLinus Torvalds 				break;
6941da177e4SLinus Torvalds 			case 't':
6951da177e4SLinus Torvalds 				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
6961da177e4SLinus Torvalds 					conf_choice(submenu);
6971da177e4SLinus Torvalds 				else if (submenu->prompt->type == P_MENU)
6985e609addSBenjamin Poirier 					conf(submenu, NULL);
6991da177e4SLinus Torvalds 				break;
7001da177e4SLinus Torvalds 			case 's':
7011da177e4SLinus Torvalds 				conf_string(submenu);
7021da177e4SLinus Torvalds 				break;
7031da177e4SLinus Torvalds 			}
7041da177e4SLinus Torvalds 			break;
7051da177e4SLinus Torvalds 		case 2:
7061da177e4SLinus Torvalds 			if (sym)
7071da177e4SLinus Torvalds 				show_help(submenu);
7089a69abf8SBenjamin Poirier 			else {
7099a69abf8SBenjamin Poirier 				reset_subtitle();
710413f006bSEGRY Gabor 				show_helptext(_("README"), _(mconf_readme));
7119a69abf8SBenjamin Poirier 			}
7121da177e4SLinus Torvalds 			break;
7131da177e4SLinus Torvalds 		case 3:
7149a69abf8SBenjamin Poirier 			reset_subtitle();
7156364fd0cSWang YanQing 			conf_save();
7166364fd0cSWang YanQing 			break;
7176364fd0cSWang YanQing 		case 4:
7189a69abf8SBenjamin Poirier 			reset_subtitle();
7196364fd0cSWang YanQing 			conf_load();
7206364fd0cSWang YanQing 			break;
7216364fd0cSWang YanQing 		case 5:
7222982de69SSam Ravnborg 			if (item_is_tag('t')) {
7231da177e4SLinus Torvalds 				if (sym_set_tristate_value(sym, yes))
7241da177e4SLinus Torvalds 					break;
7251da177e4SLinus Torvalds 				if (sym_set_tristate_value(sym, mod))
7261da177e4SLinus Torvalds 					show_textbox(NULL, setmod_text, 6, 74);
7271da177e4SLinus Torvalds 			}
7281da177e4SLinus Torvalds 			break;
7296364fd0cSWang YanQing 		case 6:
7302982de69SSam Ravnborg 			if (item_is_tag('t'))
7311da177e4SLinus Torvalds 				sym_set_tristate_value(sym, no);
7321da177e4SLinus Torvalds 			break;
7336364fd0cSWang YanQing 		case 7:
7342982de69SSam Ravnborg 			if (item_is_tag('t'))
7351da177e4SLinus Torvalds 				sym_set_tristate_value(sym, mod);
7361da177e4SLinus Torvalds 			break;
7376364fd0cSWang YanQing 		case 8:
7382982de69SSam Ravnborg 			if (item_is_tag('t'))
7391da177e4SLinus Torvalds 				sym_toggle_tristate_value(sym);
7402982de69SSam Ravnborg 			else if (item_is_tag('m'))
7415e609addSBenjamin Poirier 				conf(submenu, NULL);
7421da177e4SLinus Torvalds 			break;
7436364fd0cSWang YanQing 		case 9:
7441da177e4SLinus Torvalds 			search_conf();
7451da177e4SLinus Torvalds 			break;
7466364fd0cSWang YanQing 		case 10:
74722c7eca6SLi Zefan 			show_all_options = !show_all_options;
74822c7eca6SLi Zefan 			break;
7491da177e4SLinus Torvalds 		}
7501da177e4SLinus Torvalds 	}
7519a69abf8SBenjamin Poirier 
7529a69abf8SBenjamin Poirier 	list_del(trail.prev);
7531da177e4SLinus Torvalds }
7541da177e4SLinus Torvalds 
75595ac9b3bSBenjamin Poirier static int show_textbox_ext(const char *title, char *text, int r, int c, int
75695ac9b3bSBenjamin Poirier 			    *keys, int *vscroll, int *hscroll, update_text_fn
75795ac9b3bSBenjamin Poirier 			    update_text, void *data)
7581da177e4SLinus Torvalds {
759e94c5bdeSSam Ravnborg 	dialog_clear();
76095ac9b3bSBenjamin Poirier 	return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
76195ac9b3bSBenjamin Poirier 			      update_text, data);
762537ddae7SBenjamin Poirier }
763537ddae7SBenjamin Poirier 
764537ddae7SBenjamin Poirier static void show_textbox(const char *title, const char *text, int r, int c)
765537ddae7SBenjamin Poirier {
76695ac9b3bSBenjamin Poirier 	show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
76795ac9b3bSBenjamin Poirier 			 NULL, NULL);
7681da177e4SLinus Torvalds }
7691da177e4SLinus Torvalds 
7701da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text)
7711da177e4SLinus Torvalds {
7721da177e4SLinus Torvalds 	show_textbox(title, text, 0, 0);
7731da177e4SLinus Torvalds }
7741da177e4SLinus Torvalds 
7756364fd0cSWang YanQing static void conf_message_callback(const char *fmt, va_list ap)
7766364fd0cSWang YanQing {
7776364fd0cSWang YanQing 	char buf[PATH_MAX+1];
7786364fd0cSWang YanQing 
7796364fd0cSWang YanQing 	vsnprintf(buf, sizeof(buf), fmt, ap);
7806364fd0cSWang YanQing 	if (save_and_exit)
7816364fd0cSWang YanQing 		printf("%s", buf);
7826364fd0cSWang YanQing 	else
7836364fd0cSWang YanQing 		show_textbox(NULL, buf, 6, 60);
7846364fd0cSWang YanQing }
7856364fd0cSWang YanQing 
7861da177e4SLinus Torvalds static void show_help(struct menu *menu)
7871da177e4SLinus Torvalds {
7881da177e4SLinus Torvalds 	struct gstr help = str_new();
7891da177e4SLinus Torvalds 
790da60fbbcSVadim Bendebury (вб) 	help.max_width = getmaxx(stdscr) - 10;
7911d525e7cSCheng Renquan 	menu_get_ext_help(menu, &help);
7921d525e7cSCheng Renquan 
793413f006bSEGRY Gabor 	show_helptext(_(menu_get_prompt(menu)), str_get(&help));
7941da177e4SLinus Torvalds 	str_free(&help);
7951da177e4SLinus Torvalds }
7961da177e4SLinus Torvalds 
7971da177e4SLinus Torvalds static void conf_choice(struct menu *menu)
7981da177e4SLinus Torvalds {
799413f006bSEGRY Gabor 	const char *prompt = _(menu_get_prompt(menu));
8001da177e4SLinus Torvalds 	struct menu *child;
8011da177e4SLinus Torvalds 	struct symbol *active;
8021da177e4SLinus Torvalds 
8031da177e4SLinus Torvalds 	active = sym_get_choice_value(menu->sym);
8041da177e4SLinus Torvalds 	while (1) {
8052982de69SSam Ravnborg 		int res;
8062982de69SSam Ravnborg 		int selected;
8072982de69SSam Ravnborg 		item_reset();
8081da177e4SLinus Torvalds 
8091da177e4SLinus Torvalds 		current_menu = menu;
8101da177e4SLinus Torvalds 		for (child = menu->list; child; child = child->next) {
8111da177e4SLinus Torvalds 			if (!menu_is_visible(child))
8121da177e4SLinus Torvalds 				continue;
813af6c1598SPeter Korsgaard 			if (child->sym)
814413f006bSEGRY Gabor 				item_make("%s", _(menu_get_prompt(child)));
815af6c1598SPeter Korsgaard 			else {
816af6c1598SPeter Korsgaard 				item_make("*** %s ***", _(menu_get_prompt(child)));
817af6c1598SPeter Korsgaard 				item_set_tag(':');
818af6c1598SPeter Korsgaard 			}
8192982de69SSam Ravnborg 			item_set_data(child);
8202982de69SSam Ravnborg 			if (child->sym == active)
8212982de69SSam Ravnborg 				item_set_selected(1);
8221da177e4SLinus Torvalds 			if (child->sym == sym_get_choice_value(menu->sym))
8232982de69SSam Ravnborg 				item_set_tag('X');
8241da177e4SLinus Torvalds 		}
825e94c5bdeSSam Ravnborg 		dialog_clear();
826413f006bSEGRY Gabor 		res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
8272982de69SSam Ravnborg 					_(radiolist_instructions),
828ff7b0c2cSSedat Dilek 					MENUBOX_HEIGTH_MIN,
829ff7b0c2cSSedat Dilek 					MENUBOX_WIDTH_MIN,
830ff7b0c2cSSedat Dilek 					CHECKLIST_HEIGTH_MIN);
8312982de69SSam Ravnborg 		selected = item_activate_selected();
8322982de69SSam Ravnborg 		switch (res) {
8331da177e4SLinus Torvalds 		case 0:
8342982de69SSam Ravnborg 			if (selected) {
8352982de69SSam Ravnborg 				child = item_data();
836af6c1598SPeter Korsgaard 				if (!child->sym)
837af6c1598SPeter Korsgaard 					break;
838af6c1598SPeter Korsgaard 
8391da177e4SLinus Torvalds 				sym_set_tristate_value(child->sym, yes);
8402982de69SSam Ravnborg 			}
8411da177e4SLinus Torvalds 			return;
8421da177e4SLinus Torvalds 		case 1:
8432982de69SSam Ravnborg 			if (selected) {
8442982de69SSam Ravnborg 				child = item_data();
8451da177e4SLinus Torvalds 				show_help(child);
8461da177e4SLinus Torvalds 				active = child->sym;
8471da177e4SLinus Torvalds 			} else
8481da177e4SLinus Torvalds 				show_help(menu);
8491da177e4SLinus Torvalds 			break;
850f3cbcdc9SSam Ravnborg 		case KEY_ESC:
8511da177e4SLinus Torvalds 			return;
852c8dc68adSSam Ravnborg 		case -ERRDISPLAYTOOSMALL:
853c8dc68adSSam Ravnborg 			return;
8541da177e4SLinus Torvalds 		}
8551da177e4SLinus Torvalds 	}
8561da177e4SLinus Torvalds }
8571da177e4SLinus Torvalds 
8581da177e4SLinus Torvalds static void conf_string(struct menu *menu)
8591da177e4SLinus Torvalds {
8601da177e4SLinus Torvalds 	const char *prompt = menu_get_prompt(menu);
8611da177e4SLinus Torvalds 
8621da177e4SLinus Torvalds 	while (1) {
8632982de69SSam Ravnborg 		int res;
864c4143a83SSam Ravnborg 		const char *heading;
8652982de69SSam Ravnborg 
8661da177e4SLinus Torvalds 		switch (sym_get_type(menu->sym)) {
8671da177e4SLinus Torvalds 		case S_INT:
8682982de69SSam Ravnborg 			heading = _(inputbox_instructions_int);
8691da177e4SLinus Torvalds 			break;
8701da177e4SLinus Torvalds 		case S_HEX:
8712982de69SSam Ravnborg 			heading = _(inputbox_instructions_hex);
8721da177e4SLinus Torvalds 			break;
8731da177e4SLinus Torvalds 		case S_STRING:
8742982de69SSam Ravnborg 			heading = _(inputbox_instructions_string);
8751da177e4SLinus Torvalds 			break;
8761da177e4SLinus Torvalds 		default:
877413f006bSEGRY Gabor 			heading = _("Internal mconf error!");
8781da177e4SLinus Torvalds 		}
879e94c5bdeSSam Ravnborg 		dialog_clear();
880413f006bSEGRY Gabor 		res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
8812982de69SSam Ravnborg 				      heading, 10, 75,
8822982de69SSam Ravnborg 				      sym_get_string_value(menu->sym));
8832982de69SSam Ravnborg 		switch (res) {
8841da177e4SLinus Torvalds 		case 0:
8852982de69SSam Ravnborg 			if (sym_set_string_value(menu->sym, dialog_input_result))
8861da177e4SLinus Torvalds 				return;
8873b9fa093SArnaldo Carvalho de Melo 			show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
8881da177e4SLinus Torvalds 			break;
8891da177e4SLinus Torvalds 		case 1:
8901da177e4SLinus Torvalds 			show_help(menu);
8911da177e4SLinus Torvalds 			break;
892f3cbcdc9SSam Ravnborg 		case KEY_ESC:
8931da177e4SLinus Torvalds 			return;
8941da177e4SLinus Torvalds 		}
8951da177e4SLinus Torvalds 	}
8961da177e4SLinus Torvalds }
8971da177e4SLinus Torvalds 
8981da177e4SLinus Torvalds static void conf_load(void)
8991da177e4SLinus Torvalds {
9001da177e4SLinus Torvalds 
9011da177e4SLinus Torvalds 	while (1) {
9022982de69SSam Ravnborg 		int res;
903e94c5bdeSSam Ravnborg 		dialog_clear();
9042982de69SSam Ravnborg 		res = dialog_inputbox(NULL, load_config_text,
9052982de69SSam Ravnborg 				      11, 55, filename);
9062982de69SSam Ravnborg 		switch(res) {
9071da177e4SLinus Torvalds 		case 0:
9082982de69SSam Ravnborg 			if (!dialog_input_result[0])
9091da177e4SLinus Torvalds 				return;
91095e30f95SSam Ravnborg 			if (!conf_read(dialog_input_result)) {
91195e30f95SSam Ravnborg 				set_config_filename(dialog_input_result);
91236ef805bSSam Ravnborg 				sym_set_change_count(1);
9131da177e4SLinus Torvalds 				return;
91495e30f95SSam Ravnborg 			}
9153b9fa093SArnaldo Carvalho de Melo 			show_textbox(NULL, _("File does not exist!"), 5, 38);
9161da177e4SLinus Torvalds 			break;
9171da177e4SLinus Torvalds 		case 1:
9183b9fa093SArnaldo Carvalho de Melo 			show_helptext(_("Load Alternate Configuration"), load_config_help);
9191da177e4SLinus Torvalds 			break;
920f3cbcdc9SSam Ravnborg 		case KEY_ESC:
9211da177e4SLinus Torvalds 			return;
9221da177e4SLinus Torvalds 		}
9231da177e4SLinus Torvalds 	}
9241da177e4SLinus Torvalds }
9251da177e4SLinus Torvalds 
9261da177e4SLinus Torvalds static void conf_save(void)
9271da177e4SLinus Torvalds {
9281da177e4SLinus Torvalds 	while (1) {
9292982de69SSam Ravnborg 		int res;
930e94c5bdeSSam Ravnborg 		dialog_clear();
9312982de69SSam Ravnborg 		res = dialog_inputbox(NULL, save_config_text,
9322982de69SSam Ravnborg 				      11, 55, filename);
9332982de69SSam Ravnborg 		switch(res) {
9341da177e4SLinus Torvalds 		case 0:
9352982de69SSam Ravnborg 			if (!dialog_input_result[0])
9361da177e4SLinus Torvalds 				return;
93795e30f95SSam Ravnborg 			if (!conf_write(dialog_input_result)) {
93895e30f95SSam Ravnborg 				set_config_filename(dialog_input_result);
9391da177e4SLinus Torvalds 				return;
94095e30f95SSam Ravnborg 			}
9413b9fa093SArnaldo Carvalho de Melo 			show_textbox(NULL, _("Can't create file!  Probably a nonexistent directory."), 5, 60);
9421da177e4SLinus Torvalds 			break;
9431da177e4SLinus Torvalds 		case 1:
9443b9fa093SArnaldo Carvalho de Melo 			show_helptext(_("Save Alternate Configuration"), save_config_help);
9451da177e4SLinus Torvalds 			break;
946f3cbcdc9SSam Ravnborg 		case KEY_ESC:
9471da177e4SLinus Torvalds 			return;
9481da177e4SLinus Torvalds 		}
9491da177e4SLinus Torvalds 	}
9501da177e4SLinus Torvalds }
9511da177e4SLinus Torvalds 
952564899f9SDavidlohr Bueso static int handle_exit(void)
953564899f9SDavidlohr Bueso {
954564899f9SDavidlohr Bueso 	int res;
955564899f9SDavidlohr Bueso 
9566364fd0cSWang YanQing 	save_and_exit = 1;
9579a69abf8SBenjamin Poirier 	reset_subtitle();
958564899f9SDavidlohr Bueso 	dialog_clear();
959564899f9SDavidlohr Bueso 	if (conf_get_changed())
960564899f9SDavidlohr Bueso 		res = dialog_yesno(NULL,
961564899f9SDavidlohr Bueso 				   _("Do you wish to save your new configuration?\n"
96213763916SDirk Gouders 				     "(Press <ESC><ESC> to continue kernel configuration.)"),
963564899f9SDavidlohr Bueso 				   6, 60);
964564899f9SDavidlohr Bueso 	else
965564899f9SDavidlohr Bueso 		res = -1;
966564899f9SDavidlohr Bueso 
967564899f9SDavidlohr Bueso 	end_dialog(saved_x, saved_y);
968564899f9SDavidlohr Bueso 
969564899f9SDavidlohr Bueso 	switch (res) {
970564899f9SDavidlohr Bueso 	case 0:
971564899f9SDavidlohr Bueso 		if (conf_write(filename)) {
972564899f9SDavidlohr Bueso 			fprintf(stderr, _("\n\n"
973564899f9SDavidlohr Bueso 					  "Error while writing of the configuration.\n"
974564899f9SDavidlohr Bueso 					  "Your configuration changes were NOT saved."
975564899f9SDavidlohr Bueso 					  "\n\n"));
976564899f9SDavidlohr Bueso 			return 1;
977564899f9SDavidlohr Bueso 		}
978564899f9SDavidlohr Bueso 		/* fall through */
979564899f9SDavidlohr Bueso 	case -1:
980564899f9SDavidlohr Bueso 		printf(_("\n\n"
981564899f9SDavidlohr Bueso 			 "*** End of the configuration.\n"
982564899f9SDavidlohr Bueso 			 "*** Execute 'make' to start the build or try 'make help'."
983564899f9SDavidlohr Bueso 			 "\n\n"));
984564899f9SDavidlohr Bueso 		res = 0;
985564899f9SDavidlohr Bueso 		break;
986564899f9SDavidlohr Bueso 	default:
987564899f9SDavidlohr Bueso 		fprintf(stderr, _("\n\n"
988564899f9SDavidlohr Bueso 				  "Your configuration changes were NOT saved."
989564899f9SDavidlohr Bueso 				  "\n\n"));
99030c4eaafSLi Zefan 		if (res != KEY_ESC)
991c55ac154SWang YanQing 			res = 0;
992564899f9SDavidlohr Bueso 	}
993564899f9SDavidlohr Bueso 
994564899f9SDavidlohr Bueso 	return res;
995564899f9SDavidlohr Bueso }
996564899f9SDavidlohr Bueso 
997564899f9SDavidlohr Bueso static void sig_handler(int signo)
998564899f9SDavidlohr Bueso {
999564899f9SDavidlohr Bueso 	exit(handle_exit());
1000564899f9SDavidlohr Bueso }
1001564899f9SDavidlohr Bueso 
10021da177e4SLinus Torvalds int main(int ac, char **av)
10031da177e4SLinus Torvalds {
10041da177e4SLinus Torvalds 	char *mode;
10052982de69SSam Ravnborg 	int res;
10061da177e4SLinus Torvalds 
10073b9fa093SArnaldo Carvalho de Melo 	setlocale(LC_ALL, "");
10083b9fa093SArnaldo Carvalho de Melo 	bindtextdomain(PACKAGE, LOCALEDIR);
10093b9fa093SArnaldo Carvalho de Melo 	textdomain(PACKAGE);
10103b9fa093SArnaldo Carvalho de Melo 
1011564899f9SDavidlohr Bueso 	signal(SIGINT, sig_handler);
1012564899f9SDavidlohr Bueso 
10131da177e4SLinus Torvalds 	conf_parse(av[1]);
10141da177e4SLinus Torvalds 	conf_read(NULL);
10151da177e4SLinus Torvalds 
10161da177e4SLinus Torvalds 	mode = getenv("MENUCONFIG_MODE");
10171da177e4SLinus Torvalds 	if (mode) {
10181da177e4SLinus Torvalds 		if (!strcasecmp(mode, "single_menu"))
10191da177e4SLinus Torvalds 			single_menu_mode = 1;
10201da177e4SLinus Torvalds 	}
10211da177e4SLinus Torvalds 
102209af091fSLadislav Michl 	if (init_dialog(NULL)) {
102309af091fSLadislav Michl 		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
102409af091fSLadislav Michl 		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
102509af091fSLadislav Michl 		return 1;
102609af091fSLadislav Michl 	}
102709af091fSLadislav Michl 
1028d802b50fSSam Ravnborg 	set_config_filename(conf_get_configname());
10296364fd0cSWang YanQing 	conf_set_message_callback(conf_message_callback);
1030f3cbcdc9SSam Ravnborg 	do {
10315e609addSBenjamin Poirier 		conf(&rootmenu, NULL);
1032564899f9SDavidlohr Bueso 		res = handle_exit();
1033f3cbcdc9SSam Ravnborg 	} while (res == KEY_ESC);
1034b3214293SKarsten Wiese 
1035564899f9SDavidlohr Bueso 	return res;
10361da177e4SLinus Torvalds }
1037