10c874100SMasahiro Yamada // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
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>
18ba82f52eSBartosz Golaszewski #include <strings.h>
19564899f9SDavidlohr Bueso #include <signal.h>
201da177e4SLinus Torvalds #include <unistd.h>
211da177e4SLinus Torvalds
221da177e4SLinus Torvalds #include "lkc.h"
232982de69SSam Ravnborg #include "lxdialog/dialog.h"
241da177e4SLinus Torvalds
25694c49a7SSam Ravnborg static const char mconf_readme[] =
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"
162da8daff9SBhaskar Chowdhury
163da8daff9SBhaskar Chowdhury "Search\n"
164da8daff9SBhaskar Chowdhury "-------\n"
165da8daff9SBhaskar Chowdhury "Pressing the forward-slash (/) anywhere brings up a search dialog box.\n"
166da8daff9SBhaskar Chowdhury "\n"
167da8daff9SBhaskar Chowdhury
16845897213SSam Ravnborg "Different color themes available\n"
16945897213SSam Ravnborg "--------------------------------\n"
17045897213SSam Ravnborg "It is possible to select different color themes using the variable\n"
17145897213SSam Ravnborg "MENUCONFIG_COLOR. To select a theme use:\n"
17245897213SSam Ravnborg "\n"
17345897213SSam Ravnborg "make MENUCONFIG_COLOR=<theme> menuconfig\n"
17445897213SSam Ravnborg "\n"
17545897213SSam Ravnborg "Available themes are\n"
17645897213SSam Ravnborg " mono => selects colors suitable for monochrome displays\n"
17745897213SSam Ravnborg " blackbg => selects a color scheme with black background\n"
178350b5b76SSam Ravnborg " classic => theme with blue background. The classic look\n"
1798d9dfe82SMartin Walch " bluetitle => an LCD friendly version of classic. (default)\n"
180694c49a7SSam Ravnborg "\n",
181694c49a7SSam Ravnborg menu_instructions[] =
1821da177e4SLinus Torvalds "Arrow keys navigate the menu. "
1831278ebdbSDirk Gouders "<Enter> selects submenus ---> (or empty submenus ----). "
1841da177e4SLinus Torvalds "Highlighted letters are hotkeys. "
1851da177e4SLinus Torvalds "Pressing <Y> includes, <N> excludes, <M> modularizes features. "
1861da177e4SLinus Torvalds "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
187694c49a7SSam Ravnborg "Legend: [*] built-in [ ] excluded <M> module < > module capable",
188694c49a7SSam Ravnborg radiolist_instructions[] =
1891da177e4SLinus Torvalds "Use the arrow keys to navigate this window or "
1901da177e4SLinus Torvalds "press the hotkey of the item you wish to select "
1911da177e4SLinus Torvalds "followed by the <SPACE BAR>. "
192694c49a7SSam Ravnborg "Press <?> for additional information about this option.",
193694c49a7SSam Ravnborg inputbox_instructions_int[] =
1941da177e4SLinus Torvalds "Please enter a decimal value. "
1951da177e4SLinus Torvalds "Fractions will not be accepted. "
196694c49a7SSam Ravnborg "Use the <TAB> key to move from the input field to the buttons below it.",
197694c49a7SSam Ravnborg inputbox_instructions_hex[] =
1981da177e4SLinus Torvalds "Please enter a hexadecimal value. "
199694c49a7SSam Ravnborg "Use the <TAB> key to move from the input field to the buttons below it.",
200694c49a7SSam Ravnborg inputbox_instructions_string[] =
2011da177e4SLinus Torvalds "Please enter a string value. "
202694c49a7SSam Ravnborg "Use the <TAB> key to move from the input field to the buttons below it.",
203694c49a7SSam Ravnborg setmod_text[] =
2041da177e4SLinus Torvalds "This feature depends on another which has been configured as a module.\n"
205694c49a7SSam Ravnborg "As a result, this feature will be built as a module.",
206694c49a7SSam Ravnborg load_config_text[] =
2071da177e4SLinus Torvalds "Enter the name of the configuration file you wish to load. "
2081da177e4SLinus Torvalds "Accept the name shown to restore the configuration you "
209694c49a7SSam Ravnborg "last retrieved. Leave blank to abort.",
210694c49a7SSam Ravnborg load_config_help[] =
2111da177e4SLinus Torvalds "\n"
212652cf982SArnaud Lacombe "For various reasons, one may wish to keep several different\n"
2131da177e4SLinus Torvalds "configurations available on a single machine.\n"
2141da177e4SLinus Torvalds "\n"
2151da177e4SLinus Torvalds "If you have saved a previous configuration in a file other than the\n"
216652cf982SArnaud Lacombe "default one, entering its name here will allow you to modify that\n"
217652cf982SArnaud Lacombe "configuration.\n"
2181da177e4SLinus Torvalds "\n"
2191da177e4SLinus Torvalds "If you are uncertain, then you have probably never used alternate\n"
220694c49a7SSam Ravnborg "configuration files. You should therefore leave this blank to abort.\n",
221694c49a7SSam Ravnborg save_config_text[] =
2221da177e4SLinus Torvalds "Enter a filename to which this configuration should be saved "
223694c49a7SSam Ravnborg "as an alternate. Leave blank to abort.",
224694c49a7SSam Ravnborg save_config_help[] =
2251da177e4SLinus Torvalds "\n"
226652cf982SArnaud Lacombe "For various reasons, one may wish to keep different configurations\n"
227652cf982SArnaud Lacombe "available on a single machine.\n"
2281da177e4SLinus Torvalds "\n"
2291da177e4SLinus Torvalds "Entering a file name here will allow you to later retrieve, modify\n"
2301da177e4SLinus Torvalds "and use the current configuration as an alternate to whatever\n"
2311da177e4SLinus Torvalds "configuration options you have selected at that time.\n"
2321da177e4SLinus Torvalds "\n"
2331da177e4SLinus Torvalds "If you are uncertain what all this means then you should probably\n"
234694c49a7SSam Ravnborg "leave this blank.\n",
235694c49a7SSam Ravnborg search_help[] =
2361da177e4SLinus Torvalds "\n"
23759dfa24dSArnaud Lacombe "Search for symbols and display their relations.\n"
238503af334SRandy Dunlap "Regular expressions are allowed.\n"
2391da177e4SLinus Torvalds "Example: search for \"^FOO\"\n"
2401da177e4SLinus Torvalds "Result:\n"
2411da177e4SLinus Torvalds "-----------------------------------------------------------------\n"
2421da177e4SLinus Torvalds "Symbol: FOO [=m]\n"
2435e609addSBenjamin Poirier "Type : tristate\n"
2441da177e4SLinus Torvalds "Prompt: Foo bus is used to drive the bar HW\n"
2451da177e4SLinus Torvalds " Location:\n"
246bb8187d3SPaul Gortmaker " -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
2471da177e4SLinus Torvalds " -> PCI support (PCI [=y])\n"
2485e609addSBenjamin Poirier "(1) -> PCI access mode (<choice> [=y])\n"
2498d9dfe82SMartin Walch " Defined at drivers/pci/Kconfig:47\n"
2508d9dfe82SMartin Walch " Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
2511da177e4SLinus Torvalds " Selects: LIBCRC32\n"
2528d9dfe82SMartin Walch " Selected by: BAR [=n]\n"
2531da177e4SLinus Torvalds "-----------------------------------------------------------------\n"
2545e609addSBenjamin Poirier "o The line 'Type:' shows the type of the configuration option for\n"
255b92d804aSMasahiro Yamada " this symbol (bool, tristate, string, ...)\n"
2561da177e4SLinus Torvalds "o The line 'Prompt:' shows the text used in the menu structure for\n"
25759dfa24dSArnaud Lacombe " this symbol\n"
2588d9dfe82SMartin Walch "o The 'Defined at' line tells at what file / line number the symbol\n"
2591da177e4SLinus Torvalds " is defined\n"
2608d9dfe82SMartin Walch "o The 'Depends on:' line tells what symbols need to be defined for\n"
2611da177e4SLinus Torvalds " this symbol to be visible in the menu (selectable)\n"
2628d9dfe82SMartin Walch "o The 'Location:' lines tells where in the menu structure this symbol\n"
2631da177e4SLinus Torvalds " is located\n"
2645e609addSBenjamin Poirier " A location followed by a [=y] indicates that this is a\n"
2655e609addSBenjamin Poirier " selectable menu item - and the current value is displayed inside\n"
2665e609addSBenjamin Poirier " brackets.\n"
2675e609addSBenjamin Poirier " Press the key in the (#) prefix to jump directly to that\n"
2685e609addSBenjamin Poirier " location. You will be returned to the current search results\n"
2695e609addSBenjamin Poirier " after exiting this new menu.\n"
2708d9dfe82SMartin Walch "o The 'Selects:' line tells what symbols will be automatically\n"
2711da177e4SLinus Torvalds " selected if this symbol is selected (y or m)\n"
2728d9dfe82SMartin Walch "o The 'Selected by' line tells what symbol has selected this symbol\n"
2731da177e4SLinus Torvalds "\n"
2741da177e4SLinus Torvalds "Only relevant lines are shown.\n"
2751da177e4SLinus Torvalds "\n\n"
2761da177e4SLinus Torvalds "Search examples:\n"
27759dfa24dSArnaud Lacombe "Examples: USB => find all symbols containing USB\n"
27859dfa24dSArnaud Lacombe " ^USB => find all symbols starting with USB\n"
27959dfa24dSArnaud Lacombe " USB$ => find all symbols ending with USB\n"
280694c49a7SSam Ravnborg "\n";
2811da177e4SLinus Torvalds
2821da177e4SLinus Torvalds static int indent;
2831da177e4SLinus Torvalds static struct menu *current_menu;
2841da177e4SLinus Torvalds static int child_count;
2851da177e4SLinus Torvalds static int single_menu_mode;
28622c7eca6SLi Zefan static int show_all_options;
2876364fd0cSWang YanQing static int save_and_exit;
2880a1f00a1SMichal Marek static int silent;
289e14f1242SMasahiro Yamada static int jump_key_char;
2901da177e4SLinus Torvalds
2915e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_menu);
2921da177e4SLinus Torvalds
29395e30f95SSam Ravnborg static char filename[PATH_MAX+1];
set_config_filename(const char * config_filename)29495e30f95SSam Ravnborg static void set_config_filename(const char *config_filename)
29595e30f95SSam Ravnborg {
29695e30f95SSam Ravnborg static char menu_backtitle[PATH_MAX+128];
29795e30f95SSam Ravnborg
29868876c38SMasahiro Yamada snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s",
29968876c38SMasahiro Yamada config_filename, rootmenu.prompt->text);
30095e30f95SSam Ravnborg set_dialog_backtitle(menu_backtitle);
30195e30f95SSam Ravnborg
30268876c38SMasahiro Yamada snprintf(filename, sizeof(filename), "%s", config_filename);
30395e30f95SSam Ravnborg }
30495e30f95SSam Ravnborg
3059a69abf8SBenjamin Poirier struct subtitle_part {
3069a69abf8SBenjamin Poirier struct list_head entries;
3079a69abf8SBenjamin Poirier const char *text;
3089a69abf8SBenjamin Poirier };
3099a69abf8SBenjamin Poirier static LIST_HEAD(trail);
3109a69abf8SBenjamin Poirier
3119a69abf8SBenjamin Poirier static struct subtitle_list *subtitles;
set_subtitle(void)3129a69abf8SBenjamin Poirier static void set_subtitle(void)
3139a69abf8SBenjamin Poirier {
3149a69abf8SBenjamin Poirier struct subtitle_part *sp;
3159a69abf8SBenjamin Poirier struct subtitle_list *pos, *tmp;
3169a69abf8SBenjamin Poirier
3179a69abf8SBenjamin Poirier for (pos = subtitles; pos != NULL; pos = tmp) {
3189a69abf8SBenjamin Poirier tmp = pos->next;
3199a69abf8SBenjamin Poirier free(pos);
3209a69abf8SBenjamin Poirier }
3219a69abf8SBenjamin Poirier
3229a69abf8SBenjamin Poirier subtitles = NULL;
3239a69abf8SBenjamin Poirier list_for_each_entry(sp, &trail, entries) {
3249a69abf8SBenjamin Poirier if (sp->text) {
3259a69abf8SBenjamin Poirier if (pos) {
326e4e458b4SArjun Sreedharan pos->next = xcalloc(1, sizeof(*pos));
3279a69abf8SBenjamin Poirier pos = pos->next;
3289a69abf8SBenjamin Poirier } else {
329e4e458b4SArjun Sreedharan subtitles = pos = xcalloc(1, sizeof(*pos));
3309a69abf8SBenjamin Poirier }
3319a69abf8SBenjamin Poirier pos->text = sp->text;
3329a69abf8SBenjamin Poirier }
3339a69abf8SBenjamin Poirier }
3349a69abf8SBenjamin Poirier
3359a69abf8SBenjamin Poirier set_dialog_subtitles(subtitles);
3369a69abf8SBenjamin Poirier }
3379a69abf8SBenjamin Poirier
reset_subtitle(void)3389a69abf8SBenjamin Poirier static void reset_subtitle(void)
3399a69abf8SBenjamin Poirier {
3409a69abf8SBenjamin Poirier struct subtitle_list *pos, *tmp;
3419a69abf8SBenjamin Poirier
3429a69abf8SBenjamin Poirier for (pos = subtitles; pos != NULL; pos = tmp) {
3439a69abf8SBenjamin Poirier tmp = pos->next;
3449a69abf8SBenjamin Poirier free(pos);
3459a69abf8SBenjamin Poirier }
3469a69abf8SBenjamin Poirier subtitles = NULL;
3479a69abf8SBenjamin Poirier set_dialog_subtitles(subtitles);
3489a69abf8SBenjamin Poirier }
34995e30f95SSam Ravnborg
show_textbox_ext(const char * title,const char * text,int r,int c,int * vscroll,int * hscroll,int (* extra_key_cb)(int,size_t,size_t,void *),void * data)350e14f1242SMasahiro Yamada static int show_textbox_ext(const char *title, const char *text, int r, int c,
351e14f1242SMasahiro Yamada int *vscroll, int *hscroll,
352e14f1242SMasahiro Yamada int (*extra_key_cb)(int, size_t, size_t, void *),
353e14f1242SMasahiro Yamada void *data)
354fb318e54SMasahiro Yamada {
355fb318e54SMasahiro Yamada dialog_clear();
356e14f1242SMasahiro Yamada return dialog_textbox(title, text, r, c, vscroll, hscroll,
357e14f1242SMasahiro Yamada extra_key_cb, data);
358fb318e54SMasahiro Yamada }
359fb318e54SMasahiro Yamada
show_textbox(const char * title,const char * text,int r,int c)360fb318e54SMasahiro Yamada static void show_textbox(const char *title, const char *text, int r, int c)
361fb318e54SMasahiro Yamada {
362e14f1242SMasahiro Yamada show_textbox_ext(title, text, r, c, NULL, NULL, NULL, NULL);
363fb318e54SMasahiro Yamada }
364fb318e54SMasahiro Yamada
show_helptext(const char * title,const char * text)365fb318e54SMasahiro Yamada static void show_helptext(const char *title, const char *text)
366fb318e54SMasahiro Yamada {
367fb318e54SMasahiro Yamada show_textbox(title, text, 0, 0);
368fb318e54SMasahiro Yamada }
369fb318e54SMasahiro Yamada
show_help(struct menu * menu)370fb318e54SMasahiro Yamada static void show_help(struct menu *menu)
371fb318e54SMasahiro Yamada {
372fb318e54SMasahiro Yamada struct gstr help = str_new();
373fb318e54SMasahiro Yamada
374fb318e54SMasahiro Yamada help.max_width = getmaxx(stdscr) - 10;
375fb318e54SMasahiro Yamada menu_get_ext_help(menu, &help);
376fb318e54SMasahiro Yamada
377fb318e54SMasahiro Yamada show_helptext(menu_get_prompt(menu), str_get(&help));
378fb318e54SMasahiro Yamada str_free(&help);
379fb318e54SMasahiro Yamada }
380fb318e54SMasahiro Yamada
38195ac9b3bSBenjamin Poirier struct search_data {
382bad9955dSBenjamin Poirier struct list_head *head;
383e14f1242SMasahiro Yamada struct menu *target;
38495ac9b3bSBenjamin Poirier };
38595ac9b3bSBenjamin Poirier
next_jump_key(int key)386e14f1242SMasahiro Yamada static int next_jump_key(int key)
387e14f1242SMasahiro Yamada {
388e14f1242SMasahiro Yamada if (key < '1' || key > '9')
389e14f1242SMasahiro Yamada return '1';
390e14f1242SMasahiro Yamada
391e14f1242SMasahiro Yamada key++;
392e14f1242SMasahiro Yamada
393e14f1242SMasahiro Yamada if (key > '9')
394e14f1242SMasahiro Yamada key = '1';
395e14f1242SMasahiro Yamada
396e14f1242SMasahiro Yamada return key;
397e14f1242SMasahiro Yamada }
398e14f1242SMasahiro Yamada
handle_search_keys(int key,size_t start,size_t end,void * _data)399e14f1242SMasahiro Yamada static int handle_search_keys(int key, size_t start, size_t end, void *_data)
40095ac9b3bSBenjamin Poirier {
40195ac9b3bSBenjamin Poirier struct search_data *data = _data;
40295ac9b3bSBenjamin Poirier struct jump_key *pos;
403*356f0cb7SMasahiro Yamada int index = 0;
404e14f1242SMasahiro Yamada
405e14f1242SMasahiro Yamada if (key < '1' || key > '9')
406e14f1242SMasahiro Yamada return 0;
40795ac9b3bSBenjamin Poirier
408bad9955dSBenjamin Poirier list_for_each_entry(pos, data->head, entries) {
409*356f0cb7SMasahiro Yamada index = next_jump_key(index);
410*356f0cb7SMasahiro Yamada
411e14f1242SMasahiro Yamada if (pos->offset < start)
412e14f1242SMasahiro Yamada continue;
41395ac9b3bSBenjamin Poirier
414e14f1242SMasahiro Yamada if (pos->offset >= end)
415e14f1242SMasahiro Yamada break;
41695ac9b3bSBenjamin Poirier
417*356f0cb7SMasahiro Yamada if (key == index) {
418e14f1242SMasahiro Yamada data->target = pos->target;
419e14f1242SMasahiro Yamada return 1;
42095ac9b3bSBenjamin Poirier }
42195ac9b3bSBenjamin Poirier }
422e14f1242SMasahiro Yamada
423e14f1242SMasahiro Yamada return 0;
424e14f1242SMasahiro Yamada }
425e14f1242SMasahiro Yamada
get_jump_key_char(void)426e14f1242SMasahiro Yamada int get_jump_key_char(void)
427e14f1242SMasahiro Yamada {
428e14f1242SMasahiro Yamada jump_key_char = next_jump_key(jump_key_char);
429e14f1242SMasahiro Yamada
430e14f1242SMasahiro Yamada return jump_key_char;
43195ac9b3bSBenjamin Poirier }
43295ac9b3bSBenjamin Poirier
search_conf(void)4331da177e4SLinus Torvalds static void search_conf(void)
4341da177e4SLinus Torvalds {
4351da177e4SLinus Torvalds struct symbol **sym_arr;
4361da177e4SLinus Torvalds struct gstr res;
437337a275dSYann E. MORIN struct gstr title;
4380584f9f9SBernhard Walle char *dialog_input;
4395e609addSBenjamin Poirier int dres, vscroll = 0, hscroll = 0;
4405e609addSBenjamin Poirier bool again;
4419a69abf8SBenjamin Poirier struct gstr sttext;
4429a69abf8SBenjamin Poirier struct subtitle_part stpart;
4435e609addSBenjamin Poirier
444337a275dSYann E. MORIN title = str_new();
445694c49a7SSam Ravnborg str_printf( &title, "Enter (sub)string or regexp to search for "
446694c49a7SSam Ravnborg "(with or without \"%s\")", CONFIG_);
447337a275dSYann E. MORIN
4481da177e4SLinus Torvalds again:
449e94c5bdeSSam Ravnborg dialog_clear();
450694c49a7SSam Ravnborg dres = dialog_inputbox("Search Configuration Parameter",
451337a275dSYann E. MORIN str_get(&title),
4522982de69SSam Ravnborg 10, 75, "");
4532982de69SSam Ravnborg switch (dres) {
4541da177e4SLinus Torvalds case 0:
4551da177e4SLinus Torvalds break;
4561da177e4SLinus Torvalds case 1:
457694c49a7SSam Ravnborg show_helptext("Search Configuration", search_help);
4581da177e4SLinus Torvalds goto again;
4591da177e4SLinus Torvalds default:
460337a275dSYann E. MORIN str_free(&title);
4611da177e4SLinus Torvalds return;
4621da177e4SLinus Torvalds }
4631da177e4SLinus Torvalds
464ffb5957bSArnaud Lacombe /* strip the prefix if necessary */
4650584f9f9SBernhard Walle dialog_input = dialog_input_result;
466ffb5957bSArnaud Lacombe if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
467ffb5957bSArnaud Lacombe dialog_input += strlen(CONFIG_);
4680584f9f9SBernhard Walle
4699a69abf8SBenjamin Poirier sttext = str_new();
4709a69abf8SBenjamin Poirier str_printf(&sttext, "Search (%s)", dialog_input_result);
4719a69abf8SBenjamin Poirier stpart.text = str_get(&sttext);
4729a69abf8SBenjamin Poirier list_add_tail(&stpart.entries, &trail);
4739a69abf8SBenjamin Poirier
4740584f9f9SBernhard Walle sym_arr = sym_re_search(dialog_input);
4755e609addSBenjamin Poirier do {
476bad9955dSBenjamin Poirier LIST_HEAD(head);
47795ac9b3bSBenjamin Poirier struct search_data data = {
47895ac9b3bSBenjamin Poirier .head = &head,
47995ac9b3bSBenjamin Poirier };
480edb749f4SBenjamin Poirier struct jump_key *pos, *tmp;
4815e609addSBenjamin Poirier
482e14f1242SMasahiro Yamada jump_key_char = 0;
48395ac9b3bSBenjamin Poirier res = get_relations_str(sym_arr, &head);
4849a69abf8SBenjamin Poirier set_subtitle();
4854d980fd1SMasahiro Yamada dres = show_textbox_ext("Search Results", str_get(&res), 0, 0,
486e14f1242SMasahiro Yamada &vscroll, &hscroll,
487e14f1242SMasahiro Yamada handle_search_keys, &data);
4885e609addSBenjamin Poirier again = false;
489e14f1242SMasahiro Yamada if (dres >= '1' && dres <= '9') {
490e14f1242SMasahiro Yamada assert(data.target != NULL);
491e14f1242SMasahiro Yamada conf(data.target->parent, data.target);
4925e609addSBenjamin Poirier again = true;
4935e609addSBenjamin Poirier }
4941da177e4SLinus Torvalds str_free(&res);
495edb749f4SBenjamin Poirier list_for_each_entry_safe(pos, tmp, &head, entries)
496edb749f4SBenjamin Poirier free(pos);
4975e609addSBenjamin Poirier } while (again);
4985e609addSBenjamin Poirier free(sym_arr);
499337a275dSYann E. MORIN str_free(&title);
5009a69abf8SBenjamin Poirier list_del(trail.prev);
5019a69abf8SBenjamin Poirier str_free(&sttext);
5021da177e4SLinus Torvalds }
5031da177e4SLinus Torvalds
build_conf(struct menu * menu)5041da177e4SLinus Torvalds static void build_conf(struct menu *menu)
5051da177e4SLinus Torvalds {
5061da177e4SLinus Torvalds struct symbol *sym;
5071da177e4SLinus Torvalds struct property *prop;
5081da177e4SLinus Torvalds struct menu *child;
5091da177e4SLinus Torvalds int type, tmp, doint = 2;
5101da177e4SLinus Torvalds tristate val;
5111da177e4SLinus Torvalds char ch;
51222c7eca6SLi Zefan bool visible;
5131da177e4SLinus Torvalds
51422c7eca6SLi Zefan /*
51522c7eca6SLi Zefan * note: menu_is_visible() has side effect that it will
51622c7eca6SLi Zefan * recalc the value of the symbol.
51722c7eca6SLi Zefan */
51822c7eca6SLi Zefan visible = menu_is_visible(menu);
51922c7eca6SLi Zefan if (show_all_options && !menu_has_prompt(menu))
52022c7eca6SLi Zefan return;
52122c7eca6SLi Zefan else if (!show_all_options && !visible)
5221da177e4SLinus Torvalds return;
5231da177e4SLinus Torvalds
5241da177e4SLinus Torvalds sym = menu->sym;
5251da177e4SLinus Torvalds prop = menu->prompt;
5261da177e4SLinus Torvalds if (!sym) {
5271da177e4SLinus Torvalds if (prop && menu != current_menu) {
5281da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu);
5291da177e4SLinus Torvalds switch (prop->type) {
5301da177e4SLinus Torvalds case P_MENU:
5311da177e4SLinus Torvalds child_count++;
5321da177e4SLinus Torvalds if (single_menu_mode) {
5332982de69SSam Ravnborg item_make("%s%*c%s",
5341da177e4SLinus Torvalds menu->data ? "-->" : "++>",
5351da177e4SLinus Torvalds indent + 1, ' ', prompt);
5361da177e4SLinus Torvalds } else
5371278ebdbSDirk Gouders item_make(" %*c%s %s",
5381278ebdbSDirk Gouders indent + 1, ' ', prompt,
5391278ebdbSDirk Gouders menu_is_empty(menu) ? "----" : "--->");
5402982de69SSam Ravnborg item_set_tag('m');
5412982de69SSam Ravnborg item_set_data(menu);
5421da177e4SLinus Torvalds if (single_menu_mode && menu->data)
5431da177e4SLinus Torvalds goto conf_childs;
5441da177e4SLinus Torvalds return;
54548874077SSam Ravnborg case P_COMMENT:
54648874077SSam Ravnborg if (prompt) {
54748874077SSam Ravnborg child_count++;
548694c49a7SSam Ravnborg item_make(" %*c*** %s ***", indent + 1, ' ', prompt);
54948874077SSam Ravnborg item_set_tag(':');
55048874077SSam Ravnborg item_set_data(menu);
55148874077SSam Ravnborg }
55248874077SSam Ravnborg break;
5531da177e4SLinus Torvalds default:
5541da177e4SLinus Torvalds if (prompt) {
5551da177e4SLinus Torvalds child_count++;
556694c49a7SSam Ravnborg item_make("---%*c%s", indent + 1, ' ', prompt);
5572982de69SSam Ravnborg item_set_tag(':');
5582982de69SSam Ravnborg item_set_data(menu);
5591da177e4SLinus Torvalds }
5601da177e4SLinus Torvalds }
5611da177e4SLinus Torvalds } else
5621da177e4SLinus Torvalds doint = 0;
5631da177e4SLinus Torvalds goto conf_childs;
5641da177e4SLinus Torvalds }
5651da177e4SLinus Torvalds
5661da177e4SLinus Torvalds type = sym_get_type(sym);
5671da177e4SLinus Torvalds if (sym_is_choice(sym)) {
5681da177e4SLinus Torvalds struct symbol *def_sym = sym_get_choice_value(sym);
5691da177e4SLinus Torvalds struct menu *def_menu = NULL;
5701da177e4SLinus Torvalds
5711da177e4SLinus Torvalds child_count++;
5721da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) {
5731da177e4SLinus Torvalds if (menu_is_visible(child) && child->sym == def_sym)
5741da177e4SLinus Torvalds def_menu = child;
5751da177e4SLinus Torvalds }
5761da177e4SLinus Torvalds
5771da177e4SLinus Torvalds val = sym_get_tristate_value(sym);
578baa23ec8SMarco Ammon if (sym_is_changeable(sym)) {
5791da177e4SLinus Torvalds switch (type) {
5801da177e4SLinus Torvalds case S_BOOLEAN:
5812982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*');
5821da177e4SLinus Torvalds break;
5831da177e4SLinus Torvalds case S_TRISTATE:
5841da177e4SLinus Torvalds switch (val) {
5851da177e4SLinus Torvalds case yes: ch = '*'; break;
5861da177e4SLinus Torvalds case mod: ch = 'M'; break;
5871da177e4SLinus Torvalds default: ch = ' '; break;
5881da177e4SLinus Torvalds }
5892982de69SSam Ravnborg item_make("<%c>", ch);
5901da177e4SLinus Torvalds break;
5911da177e4SLinus Torvalds }
5922982de69SSam Ravnborg item_set_tag('t');
5932982de69SSam Ravnborg item_set_data(menu);
5941da177e4SLinus Torvalds } else {
5952982de69SSam Ravnborg item_make(" ");
5962982de69SSam Ravnborg item_set_tag(def_menu ? 't' : ':');
5972982de69SSam Ravnborg item_set_data(menu);
5981da177e4SLinus Torvalds }
5991da177e4SLinus Torvalds
600694c49a7SSam Ravnborg item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
6011da177e4SLinus Torvalds if (val == yes) {
6021da177e4SLinus Torvalds if (def_menu) {
603694c49a7SSam Ravnborg item_add_str(" (%s)", menu_get_prompt(def_menu));
6042982de69SSam Ravnborg item_add_str(" --->");
6051da177e4SLinus Torvalds if (def_menu->list) {
6061da177e4SLinus Torvalds indent += 2;
6071da177e4SLinus Torvalds build_conf(def_menu);
6081da177e4SLinus Torvalds indent -= 2;
6091da177e4SLinus Torvalds }
6102982de69SSam Ravnborg }
6111da177e4SLinus Torvalds return;
6121da177e4SLinus Torvalds }
6131da177e4SLinus Torvalds } else {
6141da177e4SLinus Torvalds if (menu == current_menu) {
615694c49a7SSam Ravnborg item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
6162982de69SSam Ravnborg item_set_tag(':');
6172982de69SSam Ravnborg item_set_data(menu);
6181da177e4SLinus Torvalds goto conf_childs;
6191da177e4SLinus Torvalds }
6201da177e4SLinus Torvalds child_count++;
6211da177e4SLinus Torvalds val = sym_get_tristate_value(sym);
6221da177e4SLinus Torvalds if (sym_is_choice_value(sym) && val == yes) {
6232982de69SSam Ravnborg item_make(" ");
6242982de69SSam Ravnborg item_set_tag(':');
6252982de69SSam Ravnborg item_set_data(menu);
6261da177e4SLinus Torvalds } else {
6271da177e4SLinus Torvalds switch (type) {
6281da177e4SLinus Torvalds case S_BOOLEAN:
629baa23ec8SMarco Ammon if (sym_is_changeable(sym))
6302982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*');
6311da177e4SLinus Torvalds else
632b5d609dbSMatej Laitl item_make("-%c-", val == no ? ' ' : '*');
6332982de69SSam Ravnborg item_set_tag('t');
6342982de69SSam Ravnborg item_set_data(menu);
6351da177e4SLinus Torvalds break;
6361da177e4SLinus Torvalds case S_TRISTATE:
6371da177e4SLinus Torvalds switch (val) {
6381da177e4SLinus Torvalds case yes: ch = '*'; break;
6391da177e4SLinus Torvalds case mod: ch = 'M'; break;
6401da177e4SLinus Torvalds default: ch = ' '; break;
6411da177e4SLinus Torvalds }
642baa23ec8SMarco Ammon if (sym_is_changeable(sym)) {
643b5d609dbSMatej Laitl if (sym->rev_dep.tri == mod)
644b5d609dbSMatej Laitl item_make("{%c}", ch);
6451da177e4SLinus Torvalds else
646b5d609dbSMatej Laitl item_make("<%c>", ch);
647b5d609dbSMatej Laitl } else
648b5d609dbSMatej Laitl item_make("-%c-", ch);
6492982de69SSam Ravnborg item_set_tag('t');
6502982de69SSam Ravnborg item_set_data(menu);
6511da177e4SLinus Torvalds break;
6521da177e4SLinus Torvalds default:
6532982de69SSam Ravnborg tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
6542982de69SSam Ravnborg item_make("(%s)", sym_get_string_value(sym));
6551da177e4SLinus Torvalds tmp = indent - tmp + 4;
6561da177e4SLinus Torvalds if (tmp < 0)
6571da177e4SLinus Torvalds tmp = 0;
658694c49a7SSam Ravnborg item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
659baa23ec8SMarco Ammon (sym_has_value(sym) || !sym_is_changeable(sym)) ?
660694c49a7SSam Ravnborg "" : " (NEW)");
6612982de69SSam Ravnborg item_set_tag('s');
6622982de69SSam Ravnborg item_set_data(menu);
6631da177e4SLinus Torvalds goto conf_childs;
6641da177e4SLinus Torvalds }
6651da177e4SLinus Torvalds }
666694c49a7SSam Ravnborg item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
667baa23ec8SMarco Ammon (sym_has_value(sym) || !sym_is_changeable(sym)) ?
668694c49a7SSam Ravnborg "" : " (NEW)");
6691da177e4SLinus Torvalds if (menu->prompt->type == P_MENU) {
6701278ebdbSDirk Gouders item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
6711da177e4SLinus Torvalds return;
6721da177e4SLinus Torvalds }
6731da177e4SLinus Torvalds }
6741da177e4SLinus Torvalds
6751da177e4SLinus Torvalds conf_childs:
6761da177e4SLinus Torvalds indent += doint;
6771da177e4SLinus Torvalds for (child = menu->list; child; child = child->next)
6781da177e4SLinus Torvalds build_conf(child);
6791da177e4SLinus Torvalds indent -= doint;
6801da177e4SLinus Torvalds }
6811da177e4SLinus Torvalds
conf_choice(struct menu * menu)6821da177e4SLinus Torvalds static void conf_choice(struct menu *menu)
6831da177e4SLinus Torvalds {
684694c49a7SSam Ravnborg const char *prompt = menu_get_prompt(menu);
6851da177e4SLinus Torvalds struct menu *child;
6861da177e4SLinus Torvalds struct symbol *active;
6871da177e4SLinus Torvalds
6881da177e4SLinus Torvalds active = sym_get_choice_value(menu->sym);
6891da177e4SLinus Torvalds while (1) {
6902982de69SSam Ravnborg int res;
6912982de69SSam Ravnborg int selected;
6922982de69SSam Ravnborg item_reset();
6931da177e4SLinus Torvalds
6941da177e4SLinus Torvalds current_menu = menu;
6951da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) {
6961da177e4SLinus Torvalds if (!menu_is_visible(child))
6971da177e4SLinus Torvalds continue;
698af6c1598SPeter Korsgaard if (child->sym)
699694c49a7SSam Ravnborg item_make("%s", menu_get_prompt(child));
700af6c1598SPeter Korsgaard else {
701694c49a7SSam Ravnborg item_make("*** %s ***", menu_get_prompt(child));
702af6c1598SPeter Korsgaard item_set_tag(':');
703af6c1598SPeter Korsgaard }
7042982de69SSam Ravnborg item_set_data(child);
7052982de69SSam Ravnborg if (child->sym == active)
7062982de69SSam Ravnborg item_set_selected(1);
7071da177e4SLinus Torvalds if (child->sym == sym_get_choice_value(menu->sym))
7082982de69SSam Ravnborg item_set_tag('X');
7091da177e4SLinus Torvalds }
710e94c5bdeSSam Ravnborg dialog_clear();
711694c49a7SSam Ravnborg res = dialog_checklist(prompt ? prompt : "Main Menu",
712694c49a7SSam Ravnborg radiolist_instructions,
713ff7b0c2cSSedat Dilek MENUBOX_HEIGTH_MIN,
714ff7b0c2cSSedat Dilek MENUBOX_WIDTH_MIN,
715ff7b0c2cSSedat Dilek CHECKLIST_HEIGTH_MIN);
7162982de69SSam Ravnborg selected = item_activate_selected();
7172982de69SSam Ravnborg switch (res) {
7181da177e4SLinus Torvalds case 0:
7192982de69SSam Ravnborg if (selected) {
7202982de69SSam Ravnborg child = item_data();
721af6c1598SPeter Korsgaard if (!child->sym)
722af6c1598SPeter Korsgaard break;
723af6c1598SPeter Korsgaard
7241da177e4SLinus Torvalds sym_set_tristate_value(child->sym, yes);
7252982de69SSam Ravnborg }
7261da177e4SLinus Torvalds return;
7271da177e4SLinus Torvalds case 1:
7282982de69SSam Ravnborg if (selected) {
7292982de69SSam Ravnborg child = item_data();
7301da177e4SLinus Torvalds show_help(child);
7311da177e4SLinus Torvalds active = child->sym;
7321da177e4SLinus Torvalds } else
7331da177e4SLinus Torvalds show_help(menu);
7341da177e4SLinus Torvalds break;
735f3cbcdc9SSam Ravnborg case KEY_ESC:
7361da177e4SLinus Torvalds return;
737c8dc68adSSam Ravnborg case -ERRDISPLAYTOOSMALL:
738c8dc68adSSam Ravnborg return;
7391da177e4SLinus Torvalds }
7401da177e4SLinus Torvalds }
7411da177e4SLinus Torvalds }
7421da177e4SLinus Torvalds
conf_string(struct menu * menu)7431da177e4SLinus Torvalds static void conf_string(struct menu *menu)
7441da177e4SLinus Torvalds {
7451da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu);
7461da177e4SLinus Torvalds
7471da177e4SLinus Torvalds while (1) {
7482982de69SSam Ravnborg int res;
749c4143a83SSam Ravnborg const char *heading;
7502982de69SSam Ravnborg
7511da177e4SLinus Torvalds switch (sym_get_type(menu->sym)) {
7521da177e4SLinus Torvalds case S_INT:
753694c49a7SSam Ravnborg heading = inputbox_instructions_int;
7541da177e4SLinus Torvalds break;
7551da177e4SLinus Torvalds case S_HEX:
756694c49a7SSam Ravnborg heading = inputbox_instructions_hex;
7571da177e4SLinus Torvalds break;
7581da177e4SLinus Torvalds case S_STRING:
759694c49a7SSam Ravnborg heading = inputbox_instructions_string;
7601da177e4SLinus Torvalds break;
7611da177e4SLinus Torvalds default:
762694c49a7SSam Ravnborg heading = "Internal mconf error!";
7631da177e4SLinus Torvalds }
764e94c5bdeSSam Ravnborg dialog_clear();
765694c49a7SSam Ravnborg res = dialog_inputbox(prompt ? prompt : "Main Menu",
7662982de69SSam Ravnborg heading, 10, 75,
7672982de69SSam Ravnborg sym_get_string_value(menu->sym));
7682982de69SSam Ravnborg switch (res) {
7691da177e4SLinus Torvalds case 0:
7702982de69SSam Ravnborg if (sym_set_string_value(menu->sym, dialog_input_result))
7711da177e4SLinus Torvalds return;
772694c49a7SSam Ravnborg show_textbox(NULL, "You have made an invalid entry.", 5, 43);
7731da177e4SLinus Torvalds break;
7741da177e4SLinus Torvalds case 1:
7751da177e4SLinus Torvalds show_help(menu);
7761da177e4SLinus Torvalds break;
777f3cbcdc9SSam Ravnborg case KEY_ESC:
7781da177e4SLinus Torvalds return;
7791da177e4SLinus Torvalds }
7801da177e4SLinus Torvalds }
7811da177e4SLinus Torvalds }
7821da177e4SLinus Torvalds
conf_load(void)7831da177e4SLinus Torvalds static void conf_load(void)
7841da177e4SLinus Torvalds {
7851da177e4SLinus Torvalds
7861da177e4SLinus Torvalds while (1) {
7872982de69SSam Ravnborg int res;
788e94c5bdeSSam Ravnborg dialog_clear();
7892982de69SSam Ravnborg res = dialog_inputbox(NULL, load_config_text,
7902982de69SSam Ravnborg 11, 55, filename);
7912982de69SSam Ravnborg switch(res) {
7921da177e4SLinus Torvalds case 0:
7932982de69SSam Ravnborg if (!dialog_input_result[0])
7941da177e4SLinus Torvalds return;
79595e30f95SSam Ravnborg if (!conf_read(dialog_input_result)) {
79695e30f95SSam Ravnborg set_config_filename(dialog_input_result);
7975ee54659SMasahiro Yamada conf_set_changed(true);
7981da177e4SLinus Torvalds return;
79995e30f95SSam Ravnborg }
800694c49a7SSam Ravnborg show_textbox(NULL, "File does not exist!", 5, 38);
8011da177e4SLinus Torvalds break;
8021da177e4SLinus Torvalds case 1:
803694c49a7SSam Ravnborg show_helptext("Load Alternate Configuration", load_config_help);
8041da177e4SLinus Torvalds break;
805f3cbcdc9SSam Ravnborg case KEY_ESC:
8061da177e4SLinus Torvalds return;
8071da177e4SLinus Torvalds }
8081da177e4SLinus Torvalds }
8091da177e4SLinus Torvalds }
8101da177e4SLinus Torvalds
conf_save(void)8111da177e4SLinus Torvalds static void conf_save(void)
8121da177e4SLinus Torvalds {
8131da177e4SLinus Torvalds while (1) {
8142982de69SSam Ravnborg int res;
815e94c5bdeSSam Ravnborg dialog_clear();
8162982de69SSam Ravnborg res = dialog_inputbox(NULL, save_config_text,
8172982de69SSam Ravnborg 11, 55, filename);
8182982de69SSam Ravnborg switch(res) {
8191da177e4SLinus Torvalds case 0:
8202982de69SSam Ravnborg if (!dialog_input_result[0])
8211da177e4SLinus Torvalds return;
82295e30f95SSam Ravnborg if (!conf_write(dialog_input_result)) {
82395e30f95SSam Ravnborg set_config_filename(dialog_input_result);
8241da177e4SLinus Torvalds return;
82595e30f95SSam Ravnborg }
826580c5b3eSMasahiro Yamada show_textbox(NULL, "Can't create file!", 5, 60);
8271da177e4SLinus Torvalds break;
8281da177e4SLinus Torvalds case 1:
829694c49a7SSam Ravnborg show_helptext("Save Alternate Configuration", save_config_help);
8301da177e4SLinus Torvalds break;
831f3cbcdc9SSam Ravnborg case KEY_ESC:
8321da177e4SLinus Torvalds return;
8331da177e4SLinus Torvalds }
8341da177e4SLinus Torvalds }
8351da177e4SLinus Torvalds }
8361da177e4SLinus Torvalds
conf(struct menu * menu,struct menu * active_menu)837fb318e54SMasahiro Yamada static void conf(struct menu *menu, struct menu *active_menu)
838fb318e54SMasahiro Yamada {
839fb318e54SMasahiro Yamada struct menu *submenu;
840fb318e54SMasahiro Yamada const char *prompt = menu_get_prompt(menu);
841fb318e54SMasahiro Yamada struct subtitle_part stpart;
842fb318e54SMasahiro Yamada struct symbol *sym;
843fb318e54SMasahiro Yamada int res;
844fb318e54SMasahiro Yamada int s_scroll = 0;
845fb318e54SMasahiro Yamada
846fb318e54SMasahiro Yamada if (menu != &rootmenu)
847fb318e54SMasahiro Yamada stpart.text = menu_get_prompt(menu);
848fb318e54SMasahiro Yamada else
849fb318e54SMasahiro Yamada stpart.text = NULL;
850fb318e54SMasahiro Yamada list_add_tail(&stpart.entries, &trail);
851fb318e54SMasahiro Yamada
852fb318e54SMasahiro Yamada while (1) {
853fb318e54SMasahiro Yamada item_reset();
854fb318e54SMasahiro Yamada current_menu = menu;
855fb318e54SMasahiro Yamada build_conf(menu);
856fb318e54SMasahiro Yamada if (!child_count)
857fb318e54SMasahiro Yamada break;
858fb318e54SMasahiro Yamada set_subtitle();
859fb318e54SMasahiro Yamada dialog_clear();
860fb318e54SMasahiro Yamada res = dialog_menu(prompt ? prompt : "Main Menu",
861fb318e54SMasahiro Yamada menu_instructions,
862fb318e54SMasahiro Yamada active_menu, &s_scroll);
863fb318e54SMasahiro Yamada if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
864fb318e54SMasahiro Yamada break;
865fb318e54SMasahiro Yamada if (item_count() != 0) {
866fb318e54SMasahiro Yamada if (!item_activate_selected())
867fb318e54SMasahiro Yamada continue;
868fb318e54SMasahiro Yamada if (!item_tag())
869fb318e54SMasahiro Yamada continue;
870fb318e54SMasahiro Yamada }
871fb318e54SMasahiro Yamada submenu = item_data();
872fb318e54SMasahiro Yamada active_menu = item_data();
873fb318e54SMasahiro Yamada if (submenu)
874fb318e54SMasahiro Yamada sym = submenu->sym;
875fb318e54SMasahiro Yamada else
876fb318e54SMasahiro Yamada sym = NULL;
877fb318e54SMasahiro Yamada
878fb318e54SMasahiro Yamada switch (res) {
879fb318e54SMasahiro Yamada case 0:
880fb318e54SMasahiro Yamada switch (item_tag()) {
881fb318e54SMasahiro Yamada case 'm':
882fb318e54SMasahiro Yamada if (single_menu_mode)
883fb318e54SMasahiro Yamada submenu->data = (void *) (long) !submenu->data;
884fb318e54SMasahiro Yamada else
885fb318e54SMasahiro Yamada conf(submenu, NULL);
886fb318e54SMasahiro Yamada break;
887fb318e54SMasahiro Yamada case 't':
888fb318e54SMasahiro Yamada if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
889fb318e54SMasahiro Yamada conf_choice(submenu);
890fb318e54SMasahiro Yamada else if (submenu->prompt->type == P_MENU)
891fb318e54SMasahiro Yamada conf(submenu, NULL);
892fb318e54SMasahiro Yamada break;
893fb318e54SMasahiro Yamada case 's':
894fb318e54SMasahiro Yamada conf_string(submenu);
895fb318e54SMasahiro Yamada break;
896fb318e54SMasahiro Yamada }
897fb318e54SMasahiro Yamada break;
898fb318e54SMasahiro Yamada case 2:
899fb318e54SMasahiro Yamada if (sym)
900fb318e54SMasahiro Yamada show_help(submenu);
901fb318e54SMasahiro Yamada else {
902fb318e54SMasahiro Yamada reset_subtitle();
903fb318e54SMasahiro Yamada show_helptext("README", mconf_readme);
904fb318e54SMasahiro Yamada }
905fb318e54SMasahiro Yamada break;
906fb318e54SMasahiro Yamada case 3:
907fb318e54SMasahiro Yamada reset_subtitle();
908fb318e54SMasahiro Yamada conf_save();
909fb318e54SMasahiro Yamada break;
910fb318e54SMasahiro Yamada case 4:
911fb318e54SMasahiro Yamada reset_subtitle();
912fb318e54SMasahiro Yamada conf_load();
913fb318e54SMasahiro Yamada break;
914fb318e54SMasahiro Yamada case 5:
915fb318e54SMasahiro Yamada if (item_is_tag('t')) {
916fb318e54SMasahiro Yamada if (sym_set_tristate_value(sym, yes))
917fb318e54SMasahiro Yamada break;
918fb318e54SMasahiro Yamada if (sym_set_tristate_value(sym, mod))
919fb318e54SMasahiro Yamada show_textbox(NULL, setmod_text, 6, 74);
920fb318e54SMasahiro Yamada }
921fb318e54SMasahiro Yamada break;
922fb318e54SMasahiro Yamada case 6:
923fb318e54SMasahiro Yamada if (item_is_tag('t'))
924fb318e54SMasahiro Yamada sym_set_tristate_value(sym, no);
925fb318e54SMasahiro Yamada break;
926fb318e54SMasahiro Yamada case 7:
927fb318e54SMasahiro Yamada if (item_is_tag('t'))
928fb318e54SMasahiro Yamada sym_set_tristate_value(sym, mod);
929fb318e54SMasahiro Yamada break;
930fb318e54SMasahiro Yamada case 8:
931fb318e54SMasahiro Yamada if (item_is_tag('t'))
932fb318e54SMasahiro Yamada sym_toggle_tristate_value(sym);
933fb318e54SMasahiro Yamada else if (item_is_tag('m'))
934fb318e54SMasahiro Yamada conf(submenu, NULL);
935fb318e54SMasahiro Yamada break;
936fb318e54SMasahiro Yamada case 9:
937fb318e54SMasahiro Yamada search_conf();
938fb318e54SMasahiro Yamada break;
939fb318e54SMasahiro Yamada case 10:
940fb318e54SMasahiro Yamada show_all_options = !show_all_options;
941fb318e54SMasahiro Yamada break;
942fb318e54SMasahiro Yamada }
943fb318e54SMasahiro Yamada }
944fb318e54SMasahiro Yamada
945fb318e54SMasahiro Yamada list_del(trail.prev);
946fb318e54SMasahiro Yamada }
947fb318e54SMasahiro Yamada
conf_message_callback(const char * s)948fb318e54SMasahiro Yamada static void conf_message_callback(const char *s)
949fb318e54SMasahiro Yamada {
950fb318e54SMasahiro Yamada if (save_and_exit) {
951fb318e54SMasahiro Yamada if (!silent)
952fb318e54SMasahiro Yamada printf("%s", s);
953fb318e54SMasahiro Yamada } else {
954fb318e54SMasahiro Yamada show_textbox(NULL, s, 6, 60);
955fb318e54SMasahiro Yamada }
956fb318e54SMasahiro Yamada }
957fb318e54SMasahiro Yamada
handle_exit(void)958564899f9SDavidlohr Bueso static int handle_exit(void)
959564899f9SDavidlohr Bueso {
960564899f9SDavidlohr Bueso int res;
961564899f9SDavidlohr Bueso
9626364fd0cSWang YanQing save_and_exit = 1;
9639a69abf8SBenjamin Poirier reset_subtitle();
964564899f9SDavidlohr Bueso dialog_clear();
965564899f9SDavidlohr Bueso if (conf_get_changed())
966564899f9SDavidlohr Bueso res = dialog_yesno(NULL,
967694c49a7SSam Ravnborg "Do you wish to save your new configuration?\n"
968694c49a7SSam Ravnborg "(Press <ESC><ESC> to continue kernel configuration.)",
969564899f9SDavidlohr Bueso 6, 60);
970564899f9SDavidlohr Bueso else
971564899f9SDavidlohr Bueso res = -1;
972564899f9SDavidlohr Bueso
973564899f9SDavidlohr Bueso end_dialog(saved_x, saved_y);
974564899f9SDavidlohr Bueso
975564899f9SDavidlohr Bueso switch (res) {
976564899f9SDavidlohr Bueso case 0:
977564899f9SDavidlohr Bueso if (conf_write(filename)) {
978694c49a7SSam Ravnborg fprintf(stderr, "\n\n"
979564899f9SDavidlohr Bueso "Error while writing of the configuration.\n"
980564899f9SDavidlohr Bueso "Your configuration changes were NOT saved."
981694c49a7SSam Ravnborg "\n\n");
982564899f9SDavidlohr Bueso return 1;
983564899f9SDavidlohr Bueso }
98400c864f8SMasahiro Yamada conf_write_autoconf(0);
985564899f9SDavidlohr Bueso /* fall through */
986564899f9SDavidlohr Bueso case -1:
9870a1f00a1SMichal Marek if (!silent)
988694c49a7SSam Ravnborg printf("\n\n"
989564899f9SDavidlohr Bueso "*** End of the configuration.\n"
990564899f9SDavidlohr Bueso "*** Execute 'make' to start the build or try 'make help'."
991694c49a7SSam Ravnborg "\n\n");
992564899f9SDavidlohr Bueso res = 0;
993564899f9SDavidlohr Bueso break;
994564899f9SDavidlohr Bueso default:
9950a1f00a1SMichal Marek if (!silent)
996694c49a7SSam Ravnborg fprintf(stderr, "\n\n"
997564899f9SDavidlohr Bueso "Your configuration changes were NOT saved."
998694c49a7SSam Ravnborg "\n\n");
99930c4eaafSLi Zefan if (res != KEY_ESC)
1000c55ac154SWang YanQing res = 0;
1001564899f9SDavidlohr Bueso }
1002564899f9SDavidlohr Bueso
1003564899f9SDavidlohr Bueso return res;
1004564899f9SDavidlohr Bueso }
1005564899f9SDavidlohr Bueso
sig_handler(int signo)1006564899f9SDavidlohr Bueso static void sig_handler(int signo)
1007564899f9SDavidlohr Bueso {
1008564899f9SDavidlohr Bueso exit(handle_exit());
1009564899f9SDavidlohr Bueso }
1010564899f9SDavidlohr Bueso
main(int ac,char ** av)10111da177e4SLinus Torvalds int main(int ac, char **av)
10121da177e4SLinus Torvalds {
10131da177e4SLinus Torvalds char *mode;
10142982de69SSam Ravnborg int res;
10151da177e4SLinus Torvalds
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)) {
1034694c49a7SSam Ravnborg fprintf(stderr, "Your display is too small to run Menuconfig!\n");
1035694c49a7SSam Ravnborg fprintf(stderr, "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