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 2540661621SMasahiro Yamada #define JUMP_NB 9 2640661621SMasahiro Yamada 27694c49a7SSam Ravnborg static const char mconf_readme[] = 281da177e4SLinus Torvalds "Overview\n" 291da177e4SLinus Torvalds "--------\n" 308d9dfe82SMartin Walch "This interface lets you select features and parameters for the build.\n" 31652cf982SArnaud Lacombe "Features can either be built-in, modularized, or ignored. Parameters\n" 32652cf982SArnaud Lacombe "must be entered in as decimal or hexadecimal numbers or text.\n" 331da177e4SLinus Torvalds "\n" 34b5d609dbSMatej Laitl "Menu items beginning with following braces represent features that\n" 35b5d609dbSMatej Laitl " [ ] can be built in or removed\n" 36b5d609dbSMatej Laitl " < > can be built in, modularized or removed\n" 37b5d609dbSMatej Laitl " { } can be built in or modularized (selected by other feature)\n" 38b5d609dbSMatej Laitl " - - are selected by other feature,\n" 39b5d609dbSMatej Laitl "while *, M or whitespace inside braces means to build in, build as\n" 40b5d609dbSMatej Laitl "a module or to exclude the feature respectively.\n" 411da177e4SLinus Torvalds "\n" 421da177e4SLinus Torvalds "To change any of these features, highlight it with the cursor\n" 431da177e4SLinus Torvalds "keys and press <Y> to build it in, <M> to make it a module or\n" 448d9dfe82SMartin Walch "<N> to remove it. You may also press the <Space Bar> to cycle\n" 458d9dfe82SMartin Walch "through the available options (i.e. Y->N->M->Y).\n" 461da177e4SLinus Torvalds "\n" 471da177e4SLinus Torvalds "Some additional keyboard hints:\n" 481da177e4SLinus Torvalds "\n" 491da177e4SLinus Torvalds "Menus\n" 501da177e4SLinus Torvalds "----------\n" 518d9dfe82SMartin Walch "o Use the Up/Down arrow keys (cursor keys) to highlight the item you\n" 528d9dfe82SMartin Walch " wish to change or the submenu you wish to select and press <Enter>.\n" 531278ebdbSDirk Gouders " Submenus are designated by \"--->\", empty ones by \"----\".\n" 541da177e4SLinus Torvalds "\n" 551da177e4SLinus Torvalds " Shortcut: Press the option's highlighted letter (hotkey).\n" 561da177e4SLinus Torvalds " Pressing a hotkey more than once will sequence\n" 571da177e4SLinus Torvalds " through all visible items which use that hotkey.\n" 581da177e4SLinus Torvalds "\n" 591da177e4SLinus Torvalds " You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n" 601da177e4SLinus Torvalds " unseen options into view.\n" 611da177e4SLinus Torvalds "\n" 621da177e4SLinus Torvalds "o To exit a menu use the cursor keys to highlight the <Exit> button\n" 631da177e4SLinus Torvalds " and press <ENTER>.\n" 641da177e4SLinus Torvalds "\n" 651da177e4SLinus Torvalds " Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n" 661da177e4SLinus Torvalds " using those letters. You may press a single <ESC>, but\n" 671da177e4SLinus Torvalds " there is a delayed response which you may find annoying.\n" 681da177e4SLinus Torvalds "\n" 691da177e4SLinus Torvalds " Also, the <TAB> and cursor keys will cycle between <Select>,\n" 708d9dfe82SMartin Walch " <Exit>, <Help>, <Save>, and <Load>.\n" 711da177e4SLinus Torvalds "\n" 721da177e4SLinus Torvalds "o To get help with an item, use the cursor keys to highlight <Help>\n" 7322c7eca6SLi Zefan " and press <ENTER>.\n" 741da177e4SLinus Torvalds "\n" 751da177e4SLinus Torvalds " Shortcut: Press <H> or <?>.\n" 761da177e4SLinus Torvalds "\n" 77f9447c49SLi Zefan "o To toggle the display of hidden options, press <Z>.\n" 7822c7eca6SLi Zefan "\n" 791da177e4SLinus Torvalds "\n" 801da177e4SLinus Torvalds "Radiolists (Choice lists)\n" 811da177e4SLinus Torvalds "-----------\n" 821da177e4SLinus Torvalds "o Use the cursor keys to select the option you wish to set and press\n" 831da177e4SLinus Torvalds " <S> or the <SPACE BAR>.\n" 841da177e4SLinus Torvalds "\n" 851da177e4SLinus Torvalds " Shortcut: Press the first letter of the option you wish to set then\n" 861da177e4SLinus Torvalds " press <S> or <SPACE BAR>.\n" 871da177e4SLinus Torvalds "\n" 881da177e4SLinus Torvalds "o To see available help for the item, use the cursor keys to highlight\n" 891da177e4SLinus Torvalds " <Help> and Press <ENTER>.\n" 901da177e4SLinus Torvalds "\n" 911da177e4SLinus Torvalds " Shortcut: Press <H> or <?>.\n" 921da177e4SLinus Torvalds "\n" 931da177e4SLinus Torvalds " Also, the <TAB> and cursor keys will cycle between <Select> and\n" 941da177e4SLinus Torvalds " <Help>\n" 951da177e4SLinus Torvalds "\n" 961da177e4SLinus Torvalds "\n" 971da177e4SLinus Torvalds "Data Entry\n" 981da177e4SLinus Torvalds "-----------\n" 991da177e4SLinus Torvalds "o Enter the requested information and press <ENTER>\n" 1001da177e4SLinus Torvalds " If you are entering hexadecimal values, it is not necessary to\n" 1011da177e4SLinus Torvalds " add the '0x' prefix to the entry.\n" 1021da177e4SLinus Torvalds "\n" 1031da177e4SLinus Torvalds "o For help, use the <TAB> or cursor keys to highlight the help option\n" 1041da177e4SLinus Torvalds " and press <ENTER>. You can try <TAB><H> as well.\n" 1051da177e4SLinus Torvalds "\n" 1061da177e4SLinus Torvalds "\n" 1071da177e4SLinus Torvalds "Text Box (Help Window)\n" 1081da177e4SLinus Torvalds "--------\n" 1091da177e4SLinus Torvalds "o Use the cursor keys to scroll up/down/left/right. The VI editor\n" 1109d4792c9SBenjamin Poirier " keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for\n" 1119d4792c9SBenjamin Poirier " those who are familiar with less and lynx.\n" 1121da177e4SLinus Torvalds "\n" 1139d4792c9SBenjamin Poirier "o Press <E>, <X>, <q>, <Enter> or <Esc><Esc> to exit.\n" 1141da177e4SLinus Torvalds "\n" 1151da177e4SLinus Torvalds "\n" 1161da177e4SLinus Torvalds "Alternate Configuration Files\n" 1171da177e4SLinus Torvalds "-----------------------------\n" 1181da177e4SLinus Torvalds "Menuconfig supports the use of alternate configuration files for\n" 1191da177e4SLinus Torvalds "those who, for various reasons, find it necessary to switch\n" 120652cf982SArnaud Lacombe "between different configurations.\n" 1211da177e4SLinus Torvalds "\n" 1228d9dfe82SMartin Walch "The <Save> button will let you save the current configuration to\n" 1238d9dfe82SMartin Walch "a file of your choosing. Use the <Load> button to load a previously\n" 1248d9dfe82SMartin Walch "saved alternate configuration.\n" 1251da177e4SLinus Torvalds "\n" 1268d9dfe82SMartin Walch "Even if you don't use alternate configuration files, but you find\n" 1278d9dfe82SMartin Walch "during a Menuconfig session that you have completely messed up your\n" 1288d9dfe82SMartin Walch "settings, you may use the <Load> button to restore your previously\n" 1298d9dfe82SMartin Walch "saved settings from \".config\" without restarting Menuconfig.\n" 1301da177e4SLinus Torvalds "\n" 1311da177e4SLinus Torvalds "Other information\n" 1321da177e4SLinus Torvalds "-----------------\n" 1338d9dfe82SMartin Walch "If you use Menuconfig in an XTERM window, make sure you have your\n" 1348d9dfe82SMartin Walch "$TERM variable set to point to an xterm definition which supports\n" 1358d9dfe82SMartin Walch "color. Otherwise, Menuconfig will look rather bad. Menuconfig will\n" 1368d9dfe82SMartin Walch "not display correctly in an RXVT window because rxvt displays only one\n" 1371da177e4SLinus Torvalds "intensity of color, bright.\n" 1381da177e4SLinus Torvalds "\n" 1391da177e4SLinus Torvalds "Menuconfig will display larger menus on screens or xterms which are\n" 1401da177e4SLinus Torvalds "set to display more than the standard 25 row by 80 column geometry.\n" 1411da177e4SLinus Torvalds "In order for this to work, the \"stty size\" command must be able to\n" 1421da177e4SLinus Torvalds "display the screen's current row and column geometry. I STRONGLY\n" 1431da177e4SLinus Torvalds "RECOMMEND that you make sure you do NOT have the shell variables\n" 1441da177e4SLinus Torvalds "LINES and COLUMNS exported into your environment. Some distributions\n" 1451da177e4SLinus Torvalds "export those variables via /etc/profile. Some ncurses programs can\n" 1461da177e4SLinus Torvalds "become confused when those variables (LINES & COLUMNS) don't reflect\n" 1471da177e4SLinus Torvalds "the true screen size.\n" 1481da177e4SLinus Torvalds "\n" 1491da177e4SLinus Torvalds "Optional personality available\n" 1501da177e4SLinus Torvalds "------------------------------\n" 1518d9dfe82SMartin Walch "If you prefer to have all of the options listed in a single menu,\n" 1528d9dfe82SMartin Walch "rather than the default multimenu hierarchy, run the menuconfig with\n" 153652cf982SArnaud Lacombe "MENUCONFIG_MODE environment variable set to single_menu. Example:\n" 1541da177e4SLinus Torvalds "\n" 1551da177e4SLinus Torvalds "make MENUCONFIG_MODE=single_menu menuconfig\n" 1561da177e4SLinus Torvalds "\n" 1571da177e4SLinus Torvalds "<Enter> will then unroll the appropriate category, or enfold it if it\n" 1581da177e4SLinus Torvalds "is already unrolled.\n" 1591da177e4SLinus Torvalds "\n" 1601da177e4SLinus Torvalds "Note that this mode can eventually be a little more CPU expensive\n" 1611da177e4SLinus Torvalds "(especially with a larger number of unrolled categories) than the\n" 16245897213SSam Ravnborg "default mode.\n" 16345897213SSam Ravnborg "\n" 164da8daff9SBhaskar Chowdhury 165da8daff9SBhaskar Chowdhury "Search\n" 166da8daff9SBhaskar Chowdhury "-------\n" 167da8daff9SBhaskar Chowdhury "Pressing the forward-slash (/) anywhere brings up a search dialog box.\n" 168da8daff9SBhaskar Chowdhury "\n" 169da8daff9SBhaskar Chowdhury 17045897213SSam Ravnborg "Different color themes available\n" 17145897213SSam Ravnborg "--------------------------------\n" 17245897213SSam Ravnborg "It is possible to select different color themes using the variable\n" 17345897213SSam Ravnborg "MENUCONFIG_COLOR. To select a theme use:\n" 17445897213SSam Ravnborg "\n" 17545897213SSam Ravnborg "make MENUCONFIG_COLOR=<theme> menuconfig\n" 17645897213SSam Ravnborg "\n" 17745897213SSam Ravnborg "Available themes are\n" 17845897213SSam Ravnborg " mono => selects colors suitable for monochrome displays\n" 17945897213SSam Ravnborg " blackbg => selects a color scheme with black background\n" 180350b5b76SSam Ravnborg " classic => theme with blue background. The classic look\n" 1818d9dfe82SMartin Walch " bluetitle => an LCD friendly version of classic. (default)\n" 182694c49a7SSam Ravnborg "\n", 183694c49a7SSam Ravnborg menu_instructions[] = 1841da177e4SLinus Torvalds "Arrow keys navigate the menu. " 1851278ebdbSDirk Gouders "<Enter> selects submenus ---> (or empty submenus ----). " 1861da177e4SLinus Torvalds "Highlighted letters are hotkeys. " 1871da177e4SLinus Torvalds "Pressing <Y> includes, <N> excludes, <M> modularizes features. " 1881da177e4SLinus Torvalds "Press <Esc><Esc> to exit, <?> for Help, </> for Search. " 189694c49a7SSam Ravnborg "Legend: [*] built-in [ ] excluded <M> module < > module capable", 190694c49a7SSam Ravnborg radiolist_instructions[] = 1911da177e4SLinus Torvalds "Use the arrow keys to navigate this window or " 1921da177e4SLinus Torvalds "press the hotkey of the item you wish to select " 1931da177e4SLinus Torvalds "followed by the <SPACE BAR>. " 194694c49a7SSam Ravnborg "Press <?> for additional information about this option.", 195694c49a7SSam Ravnborg inputbox_instructions_int[] = 1961da177e4SLinus Torvalds "Please enter a decimal value. " 1971da177e4SLinus Torvalds "Fractions will not be accepted. " 198694c49a7SSam Ravnborg "Use the <TAB> key to move from the input field to the buttons below it.", 199694c49a7SSam Ravnborg inputbox_instructions_hex[] = 2001da177e4SLinus Torvalds "Please enter a hexadecimal value. " 201694c49a7SSam Ravnborg "Use the <TAB> key to move from the input field to the buttons below it.", 202694c49a7SSam Ravnborg inputbox_instructions_string[] = 2031da177e4SLinus Torvalds "Please enter a string value. " 204694c49a7SSam Ravnborg "Use the <TAB> key to move from the input field to the buttons below it.", 205694c49a7SSam Ravnborg setmod_text[] = 2061da177e4SLinus Torvalds "This feature depends on another which has been configured as a module.\n" 207694c49a7SSam Ravnborg "As a result, this feature will be built as a module.", 208694c49a7SSam Ravnborg load_config_text[] = 2091da177e4SLinus Torvalds "Enter the name of the configuration file you wish to load. " 2101da177e4SLinus Torvalds "Accept the name shown to restore the configuration you " 211694c49a7SSam Ravnborg "last retrieved. Leave blank to abort.", 212694c49a7SSam Ravnborg load_config_help[] = 2131da177e4SLinus Torvalds "\n" 214652cf982SArnaud Lacombe "For various reasons, one may wish to keep several different\n" 2151da177e4SLinus Torvalds "configurations available on a single machine.\n" 2161da177e4SLinus Torvalds "\n" 2171da177e4SLinus Torvalds "If you have saved a previous configuration in a file other than the\n" 218652cf982SArnaud Lacombe "default one, entering its name here will allow you to modify that\n" 219652cf982SArnaud Lacombe "configuration.\n" 2201da177e4SLinus Torvalds "\n" 2211da177e4SLinus Torvalds "If you are uncertain, then you have probably never used alternate\n" 222694c49a7SSam Ravnborg "configuration files. You should therefore leave this blank to abort.\n", 223694c49a7SSam Ravnborg save_config_text[] = 2241da177e4SLinus Torvalds "Enter a filename to which this configuration should be saved " 225694c49a7SSam Ravnborg "as an alternate. Leave blank to abort.", 226694c49a7SSam Ravnborg save_config_help[] = 2271da177e4SLinus Torvalds "\n" 228652cf982SArnaud Lacombe "For various reasons, one may wish to keep different configurations\n" 229652cf982SArnaud Lacombe "available on a single machine.\n" 2301da177e4SLinus Torvalds "\n" 2311da177e4SLinus Torvalds "Entering a file name here will allow you to later retrieve, modify\n" 2321da177e4SLinus Torvalds "and use the current configuration as an alternate to whatever\n" 2331da177e4SLinus Torvalds "configuration options you have selected at that time.\n" 2341da177e4SLinus Torvalds "\n" 2351da177e4SLinus Torvalds "If you are uncertain what all this means then you should probably\n" 236694c49a7SSam Ravnborg "leave this blank.\n", 237694c49a7SSam Ravnborg search_help[] = 2381da177e4SLinus Torvalds "\n" 23959dfa24dSArnaud Lacombe "Search for symbols and display their relations.\n" 240503af334SRandy Dunlap "Regular expressions are allowed.\n" 2411da177e4SLinus Torvalds "Example: search for \"^FOO\"\n" 2421da177e4SLinus Torvalds "Result:\n" 2431da177e4SLinus Torvalds "-----------------------------------------------------------------\n" 2441da177e4SLinus Torvalds "Symbol: FOO [=m]\n" 2455e609addSBenjamin Poirier "Type : tristate\n" 2461da177e4SLinus Torvalds "Prompt: Foo bus is used to drive the bar HW\n" 2471da177e4SLinus Torvalds " Location:\n" 248bb8187d3SPaul Gortmaker " -> Bus options (PCI, PCMCIA, EISA, ISA)\n" 2491da177e4SLinus Torvalds " -> PCI support (PCI [=y])\n" 2505e609addSBenjamin Poirier "(1) -> PCI access mode (<choice> [=y])\n" 2518d9dfe82SMartin Walch " Defined at drivers/pci/Kconfig:47\n" 2528d9dfe82SMartin Walch " Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n" 2531da177e4SLinus Torvalds " Selects: LIBCRC32\n" 2548d9dfe82SMartin Walch " Selected by: BAR [=n]\n" 2551da177e4SLinus Torvalds "-----------------------------------------------------------------\n" 2565e609addSBenjamin Poirier "o The line 'Type:' shows the type of the configuration option for\n" 257b92d804aSMasahiro Yamada " this symbol (bool, tristate, string, ...)\n" 2581da177e4SLinus Torvalds "o The line 'Prompt:' shows the text used in the menu structure for\n" 25959dfa24dSArnaud Lacombe " this symbol\n" 2608d9dfe82SMartin Walch "o The 'Defined at' line tells at what file / line number the symbol\n" 2611da177e4SLinus Torvalds " is defined\n" 2628d9dfe82SMartin Walch "o The 'Depends on:' line tells what symbols need to be defined for\n" 2631da177e4SLinus Torvalds " this symbol to be visible in the menu (selectable)\n" 2648d9dfe82SMartin Walch "o The 'Location:' lines tells where in the menu structure this symbol\n" 2651da177e4SLinus Torvalds " is located\n" 2665e609addSBenjamin Poirier " A location followed by a [=y] indicates that this is a\n" 2675e609addSBenjamin Poirier " selectable menu item - and the current value is displayed inside\n" 2685e609addSBenjamin Poirier " brackets.\n" 2695e609addSBenjamin Poirier " Press the key in the (#) prefix to jump directly to that\n" 2705e609addSBenjamin Poirier " location. You will be returned to the current search results\n" 2715e609addSBenjamin Poirier " after exiting this new menu.\n" 2728d9dfe82SMartin Walch "o The 'Selects:' line tells what symbols will be automatically\n" 2731da177e4SLinus Torvalds " selected if this symbol is selected (y or m)\n" 2748d9dfe82SMartin Walch "o The 'Selected by' line tells what symbol has selected this symbol\n" 2751da177e4SLinus Torvalds "\n" 2761da177e4SLinus Torvalds "Only relevant lines are shown.\n" 2771da177e4SLinus Torvalds "\n\n" 2781da177e4SLinus Torvalds "Search examples:\n" 27959dfa24dSArnaud Lacombe "Examples: USB => find all symbols containing USB\n" 28059dfa24dSArnaud Lacombe " ^USB => find all symbols starting with USB\n" 28159dfa24dSArnaud Lacombe " USB$ => find all symbols ending with USB\n" 282694c49a7SSam Ravnborg "\n"; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds static int indent; 2851da177e4SLinus Torvalds static struct menu *current_menu; 2861da177e4SLinus Torvalds static int child_count; 2871da177e4SLinus Torvalds static int single_menu_mode; 28822c7eca6SLi Zefan static int show_all_options; 2896364fd0cSWang YanQing static int save_and_exit; 2900a1f00a1SMichal Marek static int silent; 291*e14f1242SMasahiro Yamada static int jump_key_char; 2921da177e4SLinus Torvalds 2935e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_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 30068876c38SMasahiro Yamada snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s", 30168876c38SMasahiro Yamada config_filename, rootmenu.prompt->text); 30295e30f95SSam Ravnborg set_dialog_backtitle(menu_backtitle); 30395e30f95SSam Ravnborg 30468876c38SMasahiro Yamada snprintf(filename, sizeof(filename), "%s", config_filename); 30595e30f95SSam Ravnborg } 30695e30f95SSam Ravnborg 3079a69abf8SBenjamin Poirier struct subtitle_part { 3089a69abf8SBenjamin Poirier struct list_head entries; 3099a69abf8SBenjamin Poirier const char *text; 3109a69abf8SBenjamin Poirier }; 3119a69abf8SBenjamin Poirier static LIST_HEAD(trail); 3129a69abf8SBenjamin Poirier 3139a69abf8SBenjamin Poirier static struct subtitle_list *subtitles; 3149a69abf8SBenjamin Poirier static void set_subtitle(void) 3159a69abf8SBenjamin Poirier { 3169a69abf8SBenjamin Poirier struct subtitle_part *sp; 3179a69abf8SBenjamin Poirier struct subtitle_list *pos, *tmp; 3189a69abf8SBenjamin Poirier 3199a69abf8SBenjamin Poirier for (pos = subtitles; pos != NULL; pos = tmp) { 3209a69abf8SBenjamin Poirier tmp = pos->next; 3219a69abf8SBenjamin Poirier free(pos); 3229a69abf8SBenjamin Poirier } 3239a69abf8SBenjamin Poirier 3249a69abf8SBenjamin Poirier subtitles = NULL; 3259a69abf8SBenjamin Poirier list_for_each_entry(sp, &trail, entries) { 3269a69abf8SBenjamin Poirier if (sp->text) { 3279a69abf8SBenjamin Poirier if (pos) { 328e4e458b4SArjun Sreedharan pos->next = xcalloc(1, sizeof(*pos)); 3299a69abf8SBenjamin Poirier pos = pos->next; 3309a69abf8SBenjamin Poirier } else { 331e4e458b4SArjun Sreedharan subtitles = pos = xcalloc(1, sizeof(*pos)); 3329a69abf8SBenjamin Poirier } 3339a69abf8SBenjamin Poirier pos->text = sp->text; 3349a69abf8SBenjamin Poirier } 3359a69abf8SBenjamin Poirier } 3369a69abf8SBenjamin Poirier 3379a69abf8SBenjamin Poirier set_dialog_subtitles(subtitles); 3389a69abf8SBenjamin Poirier } 3399a69abf8SBenjamin Poirier 3409a69abf8SBenjamin Poirier static void reset_subtitle(void) 3419a69abf8SBenjamin Poirier { 3429a69abf8SBenjamin Poirier struct subtitle_list *pos, *tmp; 3439a69abf8SBenjamin Poirier 3449a69abf8SBenjamin Poirier for (pos = subtitles; pos != NULL; pos = tmp) { 3459a69abf8SBenjamin Poirier tmp = pos->next; 3469a69abf8SBenjamin Poirier free(pos); 3479a69abf8SBenjamin Poirier } 3489a69abf8SBenjamin Poirier subtitles = NULL; 3499a69abf8SBenjamin Poirier set_dialog_subtitles(subtitles); 3509a69abf8SBenjamin Poirier } 35195e30f95SSam Ravnborg 352*e14f1242SMasahiro Yamada static int show_textbox_ext(const char *title, const char *text, int r, int c, 353*e14f1242SMasahiro Yamada int *vscroll, int *hscroll, 354*e14f1242SMasahiro Yamada int (*extra_key_cb)(int, size_t, size_t, void *), 355*e14f1242SMasahiro Yamada void *data) 356fb318e54SMasahiro Yamada { 357fb318e54SMasahiro Yamada dialog_clear(); 358*e14f1242SMasahiro Yamada return dialog_textbox(title, text, r, c, vscroll, hscroll, 359*e14f1242SMasahiro Yamada extra_key_cb, data); 360fb318e54SMasahiro Yamada } 361fb318e54SMasahiro Yamada 362fb318e54SMasahiro Yamada static void show_textbox(const char *title, const char *text, int r, int c) 363fb318e54SMasahiro Yamada { 364*e14f1242SMasahiro Yamada show_textbox_ext(title, text, r, c, NULL, NULL, NULL, NULL); 365fb318e54SMasahiro Yamada } 366fb318e54SMasahiro Yamada 367fb318e54SMasahiro Yamada static void show_helptext(const char *title, const char *text) 368fb318e54SMasahiro Yamada { 369fb318e54SMasahiro Yamada show_textbox(title, text, 0, 0); 370fb318e54SMasahiro Yamada } 371fb318e54SMasahiro Yamada 372fb318e54SMasahiro Yamada static void show_help(struct menu *menu) 373fb318e54SMasahiro Yamada { 374fb318e54SMasahiro Yamada struct gstr help = str_new(); 375fb318e54SMasahiro Yamada 376fb318e54SMasahiro Yamada help.max_width = getmaxx(stdscr) - 10; 377fb318e54SMasahiro Yamada menu_get_ext_help(menu, &help); 378fb318e54SMasahiro Yamada 379fb318e54SMasahiro Yamada show_helptext(menu_get_prompt(menu), str_get(&help)); 380fb318e54SMasahiro Yamada str_free(&help); 381fb318e54SMasahiro Yamada } 382fb318e54SMasahiro Yamada 38395ac9b3bSBenjamin Poirier struct search_data { 384bad9955dSBenjamin Poirier struct list_head *head; 385*e14f1242SMasahiro Yamada struct menu *target; 38695ac9b3bSBenjamin Poirier }; 38795ac9b3bSBenjamin Poirier 388*e14f1242SMasahiro Yamada static int next_jump_key(int key) 389*e14f1242SMasahiro Yamada { 390*e14f1242SMasahiro Yamada if (key < '1' || key > '9') 391*e14f1242SMasahiro Yamada return '1'; 392*e14f1242SMasahiro Yamada 393*e14f1242SMasahiro Yamada key++; 394*e14f1242SMasahiro Yamada 395*e14f1242SMasahiro Yamada if (key > '9') 396*e14f1242SMasahiro Yamada key = '1'; 397*e14f1242SMasahiro Yamada 398*e14f1242SMasahiro Yamada return key; 399*e14f1242SMasahiro Yamada } 400*e14f1242SMasahiro Yamada 401*e14f1242SMasahiro Yamada static int handle_search_keys(int key, size_t start, size_t end, void *_data) 40295ac9b3bSBenjamin Poirier { 40395ac9b3bSBenjamin Poirier struct search_data *data = _data; 40495ac9b3bSBenjamin Poirier struct jump_key *pos; 405*e14f1242SMasahiro Yamada 406*e14f1242SMasahiro Yamada if (key < '1' || key > '9') 407*e14f1242SMasahiro Yamada return 0; 40895ac9b3bSBenjamin Poirier 409bad9955dSBenjamin Poirier list_for_each_entry(pos, data->head, entries) { 410*e14f1242SMasahiro Yamada if (pos->offset < start) 411*e14f1242SMasahiro Yamada continue; 41295ac9b3bSBenjamin Poirier 413*e14f1242SMasahiro Yamada if (pos->offset >= end) 414*e14f1242SMasahiro Yamada break; 41595ac9b3bSBenjamin Poirier 416*e14f1242SMasahiro Yamada if (key == '1' + (pos->index % JUMP_NB)) { 417*e14f1242SMasahiro Yamada data->target = pos->target; 418*e14f1242SMasahiro Yamada return 1; 41995ac9b3bSBenjamin Poirier } 42095ac9b3bSBenjamin Poirier } 421*e14f1242SMasahiro Yamada 422*e14f1242SMasahiro Yamada return 0; 423*e14f1242SMasahiro Yamada } 424*e14f1242SMasahiro Yamada 425*e14f1242SMasahiro Yamada int get_jump_key_char(void) 426*e14f1242SMasahiro Yamada { 427*e14f1242SMasahiro Yamada jump_key_char = next_jump_key(jump_key_char); 428*e14f1242SMasahiro Yamada 429*e14f1242SMasahiro Yamada return jump_key_char; 43095ac9b3bSBenjamin Poirier } 43195ac9b3bSBenjamin Poirier 4321da177e4SLinus Torvalds static void search_conf(void) 4331da177e4SLinus Torvalds { 4341da177e4SLinus Torvalds struct symbol **sym_arr; 4351da177e4SLinus Torvalds struct gstr res; 436337a275dSYann E. MORIN struct gstr title; 4370584f9f9SBernhard Walle char *dialog_input; 4385e609addSBenjamin Poirier int dres, vscroll = 0, hscroll = 0; 4395e609addSBenjamin Poirier bool again; 4409a69abf8SBenjamin Poirier struct gstr sttext; 4419a69abf8SBenjamin Poirier struct subtitle_part stpart; 4425e609addSBenjamin Poirier 443337a275dSYann E. MORIN title = str_new(); 444694c49a7SSam Ravnborg str_printf( &title, "Enter (sub)string or regexp to search for " 445694c49a7SSam Ravnborg "(with or without \"%s\")", CONFIG_); 446337a275dSYann E. MORIN 4471da177e4SLinus Torvalds again: 448e94c5bdeSSam Ravnborg dialog_clear(); 449694c49a7SSam Ravnborg dres = dialog_inputbox("Search Configuration Parameter", 450337a275dSYann E. MORIN str_get(&title), 4512982de69SSam Ravnborg 10, 75, ""); 4522982de69SSam Ravnborg switch (dres) { 4531da177e4SLinus Torvalds case 0: 4541da177e4SLinus Torvalds break; 4551da177e4SLinus Torvalds case 1: 456694c49a7SSam Ravnborg show_helptext("Search Configuration", search_help); 4571da177e4SLinus Torvalds goto again; 4581da177e4SLinus Torvalds default: 459337a275dSYann E. MORIN str_free(&title); 4601da177e4SLinus Torvalds return; 4611da177e4SLinus Torvalds } 4621da177e4SLinus Torvalds 463ffb5957bSArnaud Lacombe /* strip the prefix if necessary */ 4640584f9f9SBernhard Walle dialog_input = dialog_input_result; 465ffb5957bSArnaud Lacombe if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0) 466ffb5957bSArnaud Lacombe dialog_input += strlen(CONFIG_); 4670584f9f9SBernhard Walle 4689a69abf8SBenjamin Poirier sttext = str_new(); 4699a69abf8SBenjamin Poirier str_printf(&sttext, "Search (%s)", dialog_input_result); 4709a69abf8SBenjamin Poirier stpart.text = str_get(&sttext); 4719a69abf8SBenjamin Poirier list_add_tail(&stpart.entries, &trail); 4729a69abf8SBenjamin Poirier 4730584f9f9SBernhard Walle sym_arr = sym_re_search(dialog_input); 4745e609addSBenjamin Poirier do { 475bad9955dSBenjamin Poirier LIST_HEAD(head); 47695ac9b3bSBenjamin Poirier struct search_data data = { 47795ac9b3bSBenjamin Poirier .head = &head, 47895ac9b3bSBenjamin Poirier }; 479edb749f4SBenjamin Poirier struct jump_key *pos, *tmp; 4805e609addSBenjamin Poirier 481*e14f1242SMasahiro Yamada jump_key_char = 0; 48295ac9b3bSBenjamin Poirier res = get_relations_str(sym_arr, &head); 4839a69abf8SBenjamin Poirier set_subtitle(); 4844d980fd1SMasahiro Yamada dres = show_textbox_ext("Search Results", str_get(&res), 0, 0, 485*e14f1242SMasahiro Yamada &vscroll, &hscroll, 486*e14f1242SMasahiro Yamada handle_search_keys, &data); 4875e609addSBenjamin Poirier again = false; 488*e14f1242SMasahiro Yamada if (dres >= '1' && dres <= '9') { 489*e14f1242SMasahiro Yamada assert(data.target != NULL); 490*e14f1242SMasahiro Yamada conf(data.target->parent, data.target); 4915e609addSBenjamin Poirier again = true; 4925e609addSBenjamin Poirier } 4931da177e4SLinus Torvalds str_free(&res); 494edb749f4SBenjamin Poirier list_for_each_entry_safe(pos, tmp, &head, entries) 495edb749f4SBenjamin Poirier free(pos); 4965e609addSBenjamin Poirier } while (again); 4975e609addSBenjamin Poirier free(sym_arr); 498337a275dSYann E. MORIN str_free(&title); 4999a69abf8SBenjamin Poirier list_del(trail.prev); 5009a69abf8SBenjamin Poirier str_free(&sttext); 5011da177e4SLinus Torvalds } 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds static void build_conf(struct menu *menu) 5041da177e4SLinus Torvalds { 5051da177e4SLinus Torvalds struct symbol *sym; 5061da177e4SLinus Torvalds struct property *prop; 5071da177e4SLinus Torvalds struct menu *child; 5081da177e4SLinus Torvalds int type, tmp, doint = 2; 5091da177e4SLinus Torvalds tristate val; 5101da177e4SLinus Torvalds char ch; 51122c7eca6SLi Zefan bool visible; 5121da177e4SLinus Torvalds 51322c7eca6SLi Zefan /* 51422c7eca6SLi Zefan * note: menu_is_visible() has side effect that it will 51522c7eca6SLi Zefan * recalc the value of the symbol. 51622c7eca6SLi Zefan */ 51722c7eca6SLi Zefan visible = menu_is_visible(menu); 51822c7eca6SLi Zefan if (show_all_options && !menu_has_prompt(menu)) 51922c7eca6SLi Zefan return; 52022c7eca6SLi Zefan else if (!show_all_options && !visible) 5211da177e4SLinus Torvalds return; 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds sym = menu->sym; 5241da177e4SLinus Torvalds prop = menu->prompt; 5251da177e4SLinus Torvalds if (!sym) { 5261da177e4SLinus Torvalds if (prop && menu != current_menu) { 5271da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 5281da177e4SLinus Torvalds switch (prop->type) { 5291da177e4SLinus Torvalds case P_MENU: 5301da177e4SLinus Torvalds child_count++; 5311da177e4SLinus Torvalds if (single_menu_mode) { 5322982de69SSam Ravnborg item_make("%s%*c%s", 5331da177e4SLinus Torvalds menu->data ? "-->" : "++>", 5341da177e4SLinus Torvalds indent + 1, ' ', prompt); 5351da177e4SLinus Torvalds } else 5361278ebdbSDirk Gouders item_make(" %*c%s %s", 5371278ebdbSDirk Gouders indent + 1, ' ', prompt, 5381278ebdbSDirk Gouders menu_is_empty(menu) ? "----" : "--->"); 5392982de69SSam Ravnborg item_set_tag('m'); 5402982de69SSam Ravnborg item_set_data(menu); 5411da177e4SLinus Torvalds if (single_menu_mode && menu->data) 5421da177e4SLinus Torvalds goto conf_childs; 5431da177e4SLinus Torvalds return; 54448874077SSam Ravnborg case P_COMMENT: 54548874077SSam Ravnborg if (prompt) { 54648874077SSam Ravnborg child_count++; 547694c49a7SSam Ravnborg item_make(" %*c*** %s ***", indent + 1, ' ', prompt); 54848874077SSam Ravnborg item_set_tag(':'); 54948874077SSam Ravnborg item_set_data(menu); 55048874077SSam Ravnborg } 55148874077SSam Ravnborg break; 5521da177e4SLinus Torvalds default: 5531da177e4SLinus Torvalds if (prompt) { 5541da177e4SLinus Torvalds child_count++; 555694c49a7SSam Ravnborg item_make("---%*c%s", indent + 1, ' ', prompt); 5562982de69SSam Ravnborg item_set_tag(':'); 5572982de69SSam Ravnborg item_set_data(menu); 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds } 5601da177e4SLinus Torvalds } else 5611da177e4SLinus Torvalds doint = 0; 5621da177e4SLinus Torvalds goto conf_childs; 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds type = sym_get_type(sym); 5661da177e4SLinus Torvalds if (sym_is_choice(sym)) { 5671da177e4SLinus Torvalds struct symbol *def_sym = sym_get_choice_value(sym); 5681da177e4SLinus Torvalds struct menu *def_menu = NULL; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds child_count++; 5711da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 5721da177e4SLinus Torvalds if (menu_is_visible(child) && child->sym == def_sym) 5731da177e4SLinus Torvalds def_menu = child; 5741da177e4SLinus Torvalds } 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds val = sym_get_tristate_value(sym); 577baa23ec8SMarco Ammon if (sym_is_changeable(sym)) { 5781da177e4SLinus Torvalds switch (type) { 5791da177e4SLinus Torvalds case S_BOOLEAN: 5802982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*'); 5811da177e4SLinus Torvalds break; 5821da177e4SLinus Torvalds case S_TRISTATE: 5831da177e4SLinus Torvalds switch (val) { 5841da177e4SLinus Torvalds case yes: ch = '*'; break; 5851da177e4SLinus Torvalds case mod: ch = 'M'; break; 5861da177e4SLinus Torvalds default: ch = ' '; break; 5871da177e4SLinus Torvalds } 5882982de69SSam Ravnborg item_make("<%c>", ch); 5891da177e4SLinus Torvalds break; 5901da177e4SLinus Torvalds } 5912982de69SSam Ravnborg item_set_tag('t'); 5922982de69SSam Ravnborg item_set_data(menu); 5931da177e4SLinus Torvalds } else { 5942982de69SSam Ravnborg item_make(" "); 5952982de69SSam Ravnborg item_set_tag(def_menu ? 't' : ':'); 5962982de69SSam Ravnborg item_set_data(menu); 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds 599694c49a7SSam Ravnborg item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu)); 6001da177e4SLinus Torvalds if (val == yes) { 6011da177e4SLinus Torvalds if (def_menu) { 602694c49a7SSam Ravnborg item_add_str(" (%s)", menu_get_prompt(def_menu)); 6032982de69SSam Ravnborg item_add_str(" --->"); 6041da177e4SLinus Torvalds if (def_menu->list) { 6051da177e4SLinus Torvalds indent += 2; 6061da177e4SLinus Torvalds build_conf(def_menu); 6071da177e4SLinus Torvalds indent -= 2; 6081da177e4SLinus Torvalds } 6092982de69SSam Ravnborg } 6101da177e4SLinus Torvalds return; 6111da177e4SLinus Torvalds } 6121da177e4SLinus Torvalds } else { 6131da177e4SLinus Torvalds if (menu == current_menu) { 614694c49a7SSam Ravnborg item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); 6152982de69SSam Ravnborg item_set_tag(':'); 6162982de69SSam Ravnborg item_set_data(menu); 6171da177e4SLinus Torvalds goto conf_childs; 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds child_count++; 6201da177e4SLinus Torvalds val = sym_get_tristate_value(sym); 6211da177e4SLinus Torvalds if (sym_is_choice_value(sym) && val == yes) { 6222982de69SSam Ravnborg item_make(" "); 6232982de69SSam Ravnborg item_set_tag(':'); 6242982de69SSam Ravnborg item_set_data(menu); 6251da177e4SLinus Torvalds } else { 6261da177e4SLinus Torvalds switch (type) { 6271da177e4SLinus Torvalds case S_BOOLEAN: 628baa23ec8SMarco Ammon if (sym_is_changeable(sym)) 6292982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*'); 6301da177e4SLinus Torvalds else 631b5d609dbSMatej Laitl item_make("-%c-", val == no ? ' ' : '*'); 6322982de69SSam Ravnborg item_set_tag('t'); 6332982de69SSam Ravnborg item_set_data(menu); 6341da177e4SLinus Torvalds break; 6351da177e4SLinus Torvalds case S_TRISTATE: 6361da177e4SLinus Torvalds switch (val) { 6371da177e4SLinus Torvalds case yes: ch = '*'; break; 6381da177e4SLinus Torvalds case mod: ch = 'M'; break; 6391da177e4SLinus Torvalds default: ch = ' '; break; 6401da177e4SLinus Torvalds } 641baa23ec8SMarco Ammon if (sym_is_changeable(sym)) { 642b5d609dbSMatej Laitl if (sym->rev_dep.tri == mod) 643b5d609dbSMatej Laitl item_make("{%c}", ch); 6441da177e4SLinus Torvalds else 645b5d609dbSMatej Laitl item_make("<%c>", ch); 646b5d609dbSMatej Laitl } else 647b5d609dbSMatej Laitl item_make("-%c-", ch); 6482982de69SSam Ravnborg item_set_tag('t'); 6492982de69SSam Ravnborg item_set_data(menu); 6501da177e4SLinus Torvalds break; 6511da177e4SLinus Torvalds default: 6522982de69SSam Ravnborg tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */ 6532982de69SSam Ravnborg item_make("(%s)", sym_get_string_value(sym)); 6541da177e4SLinus Torvalds tmp = indent - tmp + 4; 6551da177e4SLinus Torvalds if (tmp < 0) 6561da177e4SLinus Torvalds tmp = 0; 657694c49a7SSam Ravnborg item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu), 658baa23ec8SMarco Ammon (sym_has_value(sym) || !sym_is_changeable(sym)) ? 659694c49a7SSam Ravnborg "" : " (NEW)"); 6602982de69SSam Ravnborg item_set_tag('s'); 6612982de69SSam Ravnborg item_set_data(menu); 6621da177e4SLinus Torvalds goto conf_childs; 6631da177e4SLinus Torvalds } 6641da177e4SLinus Torvalds } 665694c49a7SSam Ravnborg item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), 666baa23ec8SMarco Ammon (sym_has_value(sym) || !sym_is_changeable(sym)) ? 667694c49a7SSam Ravnborg "" : " (NEW)"); 6681da177e4SLinus Torvalds if (menu->prompt->type == P_MENU) { 6691278ebdbSDirk Gouders item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->"); 6701da177e4SLinus Torvalds return; 6711da177e4SLinus Torvalds } 6721da177e4SLinus Torvalds } 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds conf_childs: 6751da177e4SLinus Torvalds indent += doint; 6761da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) 6771da177e4SLinus Torvalds build_conf(child); 6781da177e4SLinus Torvalds indent -= doint; 6791da177e4SLinus Torvalds } 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds static void conf_choice(struct menu *menu) 6821da177e4SLinus Torvalds { 683694c49a7SSam Ravnborg const char *prompt = menu_get_prompt(menu); 6841da177e4SLinus Torvalds struct menu *child; 6851da177e4SLinus Torvalds struct symbol *active; 6861da177e4SLinus Torvalds 6871da177e4SLinus Torvalds active = sym_get_choice_value(menu->sym); 6881da177e4SLinus Torvalds while (1) { 6892982de69SSam Ravnborg int res; 6902982de69SSam Ravnborg int selected; 6912982de69SSam Ravnborg item_reset(); 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds current_menu = menu; 6941da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 6951da177e4SLinus Torvalds if (!menu_is_visible(child)) 6961da177e4SLinus Torvalds continue; 697af6c1598SPeter Korsgaard if (child->sym) 698694c49a7SSam Ravnborg item_make("%s", menu_get_prompt(child)); 699af6c1598SPeter Korsgaard else { 700694c49a7SSam Ravnborg item_make("*** %s ***", menu_get_prompt(child)); 701af6c1598SPeter Korsgaard item_set_tag(':'); 702af6c1598SPeter Korsgaard } 7032982de69SSam Ravnborg item_set_data(child); 7042982de69SSam Ravnborg if (child->sym == active) 7052982de69SSam Ravnborg item_set_selected(1); 7061da177e4SLinus Torvalds if (child->sym == sym_get_choice_value(menu->sym)) 7072982de69SSam Ravnborg item_set_tag('X'); 7081da177e4SLinus Torvalds } 709e94c5bdeSSam Ravnborg dialog_clear(); 710694c49a7SSam Ravnborg res = dialog_checklist(prompt ? prompt : "Main Menu", 711694c49a7SSam Ravnborg radiolist_instructions, 712ff7b0c2cSSedat Dilek MENUBOX_HEIGTH_MIN, 713ff7b0c2cSSedat Dilek MENUBOX_WIDTH_MIN, 714ff7b0c2cSSedat Dilek CHECKLIST_HEIGTH_MIN); 7152982de69SSam Ravnborg selected = item_activate_selected(); 7162982de69SSam Ravnborg switch (res) { 7171da177e4SLinus Torvalds case 0: 7182982de69SSam Ravnborg if (selected) { 7192982de69SSam Ravnborg child = item_data(); 720af6c1598SPeter Korsgaard if (!child->sym) 721af6c1598SPeter Korsgaard break; 722af6c1598SPeter Korsgaard 7231da177e4SLinus Torvalds sym_set_tristate_value(child->sym, yes); 7242982de69SSam Ravnborg } 7251da177e4SLinus Torvalds return; 7261da177e4SLinus Torvalds case 1: 7272982de69SSam Ravnborg if (selected) { 7282982de69SSam Ravnborg child = item_data(); 7291da177e4SLinus Torvalds show_help(child); 7301da177e4SLinus Torvalds active = child->sym; 7311da177e4SLinus Torvalds } else 7321da177e4SLinus Torvalds show_help(menu); 7331da177e4SLinus Torvalds break; 734f3cbcdc9SSam Ravnborg case KEY_ESC: 7351da177e4SLinus Torvalds return; 736c8dc68adSSam Ravnborg case -ERRDISPLAYTOOSMALL: 737c8dc68adSSam Ravnborg return; 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds } 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds static void conf_string(struct menu *menu) 7431da177e4SLinus Torvalds { 7441da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds while (1) { 7472982de69SSam Ravnborg int res; 748c4143a83SSam Ravnborg const char *heading; 7492982de69SSam Ravnborg 7501da177e4SLinus Torvalds switch (sym_get_type(menu->sym)) { 7511da177e4SLinus Torvalds case S_INT: 752694c49a7SSam Ravnborg heading = inputbox_instructions_int; 7531da177e4SLinus Torvalds break; 7541da177e4SLinus Torvalds case S_HEX: 755694c49a7SSam Ravnborg heading = inputbox_instructions_hex; 7561da177e4SLinus Torvalds break; 7571da177e4SLinus Torvalds case S_STRING: 758694c49a7SSam Ravnborg heading = inputbox_instructions_string; 7591da177e4SLinus Torvalds break; 7601da177e4SLinus Torvalds default: 761694c49a7SSam Ravnborg heading = "Internal mconf error!"; 7621da177e4SLinus Torvalds } 763e94c5bdeSSam Ravnborg dialog_clear(); 764694c49a7SSam Ravnborg res = dialog_inputbox(prompt ? prompt : "Main Menu", 7652982de69SSam Ravnborg heading, 10, 75, 7662982de69SSam Ravnborg sym_get_string_value(menu->sym)); 7672982de69SSam Ravnborg switch (res) { 7681da177e4SLinus Torvalds case 0: 7692982de69SSam Ravnborg if (sym_set_string_value(menu->sym, dialog_input_result)) 7701da177e4SLinus Torvalds return; 771694c49a7SSam Ravnborg show_textbox(NULL, "You have made an invalid entry.", 5, 43); 7721da177e4SLinus Torvalds break; 7731da177e4SLinus Torvalds case 1: 7741da177e4SLinus Torvalds show_help(menu); 7751da177e4SLinus Torvalds break; 776f3cbcdc9SSam Ravnborg case KEY_ESC: 7771da177e4SLinus Torvalds return; 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds } 7801da177e4SLinus Torvalds } 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds static void conf_load(void) 7831da177e4SLinus Torvalds { 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds while (1) { 7862982de69SSam Ravnborg int res; 787e94c5bdeSSam Ravnborg dialog_clear(); 7882982de69SSam Ravnborg res = dialog_inputbox(NULL, load_config_text, 7892982de69SSam Ravnborg 11, 55, filename); 7902982de69SSam Ravnborg switch(res) { 7911da177e4SLinus Torvalds case 0: 7922982de69SSam Ravnborg if (!dialog_input_result[0]) 7931da177e4SLinus Torvalds return; 79495e30f95SSam Ravnborg if (!conf_read(dialog_input_result)) { 79595e30f95SSam Ravnborg set_config_filename(dialog_input_result); 7965ee54659SMasahiro Yamada conf_set_changed(true); 7971da177e4SLinus Torvalds return; 79895e30f95SSam Ravnborg } 799694c49a7SSam Ravnborg show_textbox(NULL, "File does not exist!", 5, 38); 8001da177e4SLinus Torvalds break; 8011da177e4SLinus Torvalds case 1: 802694c49a7SSam Ravnborg show_helptext("Load Alternate Configuration", load_config_help); 8031da177e4SLinus Torvalds break; 804f3cbcdc9SSam Ravnborg case KEY_ESC: 8051da177e4SLinus Torvalds return; 8061da177e4SLinus Torvalds } 8071da177e4SLinus Torvalds } 8081da177e4SLinus Torvalds } 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds static void conf_save(void) 8111da177e4SLinus Torvalds { 8121da177e4SLinus Torvalds while (1) { 8132982de69SSam Ravnborg int res; 814e94c5bdeSSam Ravnborg dialog_clear(); 8152982de69SSam Ravnborg res = dialog_inputbox(NULL, save_config_text, 8162982de69SSam Ravnborg 11, 55, filename); 8172982de69SSam Ravnborg switch(res) { 8181da177e4SLinus Torvalds case 0: 8192982de69SSam Ravnborg if (!dialog_input_result[0]) 8201da177e4SLinus Torvalds return; 82195e30f95SSam Ravnborg if (!conf_write(dialog_input_result)) { 82295e30f95SSam Ravnborg set_config_filename(dialog_input_result); 8231da177e4SLinus Torvalds return; 82495e30f95SSam Ravnborg } 825580c5b3eSMasahiro Yamada show_textbox(NULL, "Can't create file!", 5, 60); 8261da177e4SLinus Torvalds break; 8271da177e4SLinus Torvalds case 1: 828694c49a7SSam Ravnborg show_helptext("Save Alternate Configuration", save_config_help); 8291da177e4SLinus Torvalds break; 830f3cbcdc9SSam Ravnborg case KEY_ESC: 8311da177e4SLinus Torvalds return; 8321da177e4SLinus Torvalds } 8331da177e4SLinus Torvalds } 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds 836fb318e54SMasahiro Yamada static void conf(struct menu *menu, struct menu *active_menu) 837fb318e54SMasahiro Yamada { 838fb318e54SMasahiro Yamada struct menu *submenu; 839fb318e54SMasahiro Yamada const char *prompt = menu_get_prompt(menu); 840fb318e54SMasahiro Yamada struct subtitle_part stpart; 841fb318e54SMasahiro Yamada struct symbol *sym; 842fb318e54SMasahiro Yamada int res; 843fb318e54SMasahiro Yamada int s_scroll = 0; 844fb318e54SMasahiro Yamada 845fb318e54SMasahiro Yamada if (menu != &rootmenu) 846fb318e54SMasahiro Yamada stpart.text = menu_get_prompt(menu); 847fb318e54SMasahiro Yamada else 848fb318e54SMasahiro Yamada stpart.text = NULL; 849fb318e54SMasahiro Yamada list_add_tail(&stpart.entries, &trail); 850fb318e54SMasahiro Yamada 851fb318e54SMasahiro Yamada while (1) { 852fb318e54SMasahiro Yamada item_reset(); 853fb318e54SMasahiro Yamada current_menu = menu; 854fb318e54SMasahiro Yamada build_conf(menu); 855fb318e54SMasahiro Yamada if (!child_count) 856fb318e54SMasahiro Yamada break; 857fb318e54SMasahiro Yamada set_subtitle(); 858fb318e54SMasahiro Yamada dialog_clear(); 859fb318e54SMasahiro Yamada res = dialog_menu(prompt ? prompt : "Main Menu", 860fb318e54SMasahiro Yamada menu_instructions, 861fb318e54SMasahiro Yamada active_menu, &s_scroll); 862fb318e54SMasahiro Yamada if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL) 863fb318e54SMasahiro Yamada break; 864fb318e54SMasahiro Yamada if (item_count() != 0) { 865fb318e54SMasahiro Yamada if (!item_activate_selected()) 866fb318e54SMasahiro Yamada continue; 867fb318e54SMasahiro Yamada if (!item_tag()) 868fb318e54SMasahiro Yamada continue; 869fb318e54SMasahiro Yamada } 870fb318e54SMasahiro Yamada submenu = item_data(); 871fb318e54SMasahiro Yamada active_menu = item_data(); 872fb318e54SMasahiro Yamada if (submenu) 873fb318e54SMasahiro Yamada sym = submenu->sym; 874fb318e54SMasahiro Yamada else 875fb318e54SMasahiro Yamada sym = NULL; 876fb318e54SMasahiro Yamada 877fb318e54SMasahiro Yamada switch (res) { 878fb318e54SMasahiro Yamada case 0: 879fb318e54SMasahiro Yamada switch (item_tag()) { 880fb318e54SMasahiro Yamada case 'm': 881fb318e54SMasahiro Yamada if (single_menu_mode) 882fb318e54SMasahiro Yamada submenu->data = (void *) (long) !submenu->data; 883fb318e54SMasahiro Yamada else 884fb318e54SMasahiro Yamada conf(submenu, NULL); 885fb318e54SMasahiro Yamada break; 886fb318e54SMasahiro Yamada case 't': 887fb318e54SMasahiro Yamada if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes) 888fb318e54SMasahiro Yamada conf_choice(submenu); 889fb318e54SMasahiro Yamada else if (submenu->prompt->type == P_MENU) 890fb318e54SMasahiro Yamada conf(submenu, NULL); 891fb318e54SMasahiro Yamada break; 892fb318e54SMasahiro Yamada case 's': 893fb318e54SMasahiro Yamada conf_string(submenu); 894fb318e54SMasahiro Yamada break; 895fb318e54SMasahiro Yamada } 896fb318e54SMasahiro Yamada break; 897fb318e54SMasahiro Yamada case 2: 898fb318e54SMasahiro Yamada if (sym) 899fb318e54SMasahiro Yamada show_help(submenu); 900fb318e54SMasahiro Yamada else { 901fb318e54SMasahiro Yamada reset_subtitle(); 902fb318e54SMasahiro Yamada show_helptext("README", mconf_readme); 903fb318e54SMasahiro Yamada } 904fb318e54SMasahiro Yamada break; 905fb318e54SMasahiro Yamada case 3: 906fb318e54SMasahiro Yamada reset_subtitle(); 907fb318e54SMasahiro Yamada conf_save(); 908fb318e54SMasahiro Yamada break; 909fb318e54SMasahiro Yamada case 4: 910fb318e54SMasahiro Yamada reset_subtitle(); 911fb318e54SMasahiro Yamada conf_load(); 912fb318e54SMasahiro Yamada break; 913fb318e54SMasahiro Yamada case 5: 914fb318e54SMasahiro Yamada if (item_is_tag('t')) { 915fb318e54SMasahiro Yamada if (sym_set_tristate_value(sym, yes)) 916fb318e54SMasahiro Yamada break; 917fb318e54SMasahiro Yamada if (sym_set_tristate_value(sym, mod)) 918fb318e54SMasahiro Yamada show_textbox(NULL, setmod_text, 6, 74); 919fb318e54SMasahiro Yamada } 920fb318e54SMasahiro Yamada break; 921fb318e54SMasahiro Yamada case 6: 922fb318e54SMasahiro Yamada if (item_is_tag('t')) 923fb318e54SMasahiro Yamada sym_set_tristate_value(sym, no); 924fb318e54SMasahiro Yamada break; 925fb318e54SMasahiro Yamada case 7: 926fb318e54SMasahiro Yamada if (item_is_tag('t')) 927fb318e54SMasahiro Yamada sym_set_tristate_value(sym, mod); 928fb318e54SMasahiro Yamada break; 929fb318e54SMasahiro Yamada case 8: 930fb318e54SMasahiro Yamada if (item_is_tag('t')) 931fb318e54SMasahiro Yamada sym_toggle_tristate_value(sym); 932fb318e54SMasahiro Yamada else if (item_is_tag('m')) 933fb318e54SMasahiro Yamada conf(submenu, NULL); 934fb318e54SMasahiro Yamada break; 935fb318e54SMasahiro Yamada case 9: 936fb318e54SMasahiro Yamada search_conf(); 937fb318e54SMasahiro Yamada break; 938fb318e54SMasahiro Yamada case 10: 939fb318e54SMasahiro Yamada show_all_options = !show_all_options; 940fb318e54SMasahiro Yamada break; 941fb318e54SMasahiro Yamada } 942fb318e54SMasahiro Yamada } 943fb318e54SMasahiro Yamada 944fb318e54SMasahiro Yamada list_del(trail.prev); 945fb318e54SMasahiro Yamada } 946fb318e54SMasahiro Yamada 947fb318e54SMasahiro Yamada static void conf_message_callback(const char *s) 948fb318e54SMasahiro Yamada { 949fb318e54SMasahiro Yamada if (save_and_exit) { 950fb318e54SMasahiro Yamada if (!silent) 951fb318e54SMasahiro Yamada printf("%s", s); 952fb318e54SMasahiro Yamada } else { 953fb318e54SMasahiro Yamada show_textbox(NULL, s, 6, 60); 954fb318e54SMasahiro Yamada } 955fb318e54SMasahiro Yamada } 956fb318e54SMasahiro Yamada 957564899f9SDavidlohr Bueso static int handle_exit(void) 958564899f9SDavidlohr Bueso { 959564899f9SDavidlohr Bueso int res; 960564899f9SDavidlohr Bueso 9616364fd0cSWang YanQing save_and_exit = 1; 9629a69abf8SBenjamin Poirier reset_subtitle(); 963564899f9SDavidlohr Bueso dialog_clear(); 964564899f9SDavidlohr Bueso if (conf_get_changed()) 965564899f9SDavidlohr Bueso res = dialog_yesno(NULL, 966694c49a7SSam Ravnborg "Do you wish to save your new configuration?\n" 967694c49a7SSam Ravnborg "(Press <ESC><ESC> to continue kernel configuration.)", 968564899f9SDavidlohr Bueso 6, 60); 969564899f9SDavidlohr Bueso else 970564899f9SDavidlohr Bueso res = -1; 971564899f9SDavidlohr Bueso 972564899f9SDavidlohr Bueso end_dialog(saved_x, saved_y); 973564899f9SDavidlohr Bueso 974564899f9SDavidlohr Bueso switch (res) { 975564899f9SDavidlohr Bueso case 0: 976564899f9SDavidlohr Bueso if (conf_write(filename)) { 977694c49a7SSam Ravnborg fprintf(stderr, "\n\n" 978564899f9SDavidlohr Bueso "Error while writing of the configuration.\n" 979564899f9SDavidlohr Bueso "Your configuration changes were NOT saved." 980694c49a7SSam Ravnborg "\n\n"); 981564899f9SDavidlohr Bueso return 1; 982564899f9SDavidlohr Bueso } 98300c864f8SMasahiro Yamada conf_write_autoconf(0); 984564899f9SDavidlohr Bueso /* fall through */ 985564899f9SDavidlohr Bueso case -1: 9860a1f00a1SMichal Marek if (!silent) 987694c49a7SSam Ravnborg printf("\n\n" 988564899f9SDavidlohr Bueso "*** End of the configuration.\n" 989564899f9SDavidlohr Bueso "*** Execute 'make' to start the build or try 'make help'." 990694c49a7SSam Ravnborg "\n\n"); 991564899f9SDavidlohr Bueso res = 0; 992564899f9SDavidlohr Bueso break; 993564899f9SDavidlohr Bueso default: 9940a1f00a1SMichal Marek if (!silent) 995694c49a7SSam Ravnborg fprintf(stderr, "\n\n" 996564899f9SDavidlohr Bueso "Your configuration changes were NOT saved." 997694c49a7SSam Ravnborg "\n\n"); 99830c4eaafSLi Zefan if (res != KEY_ESC) 999c55ac154SWang YanQing res = 0; 1000564899f9SDavidlohr Bueso } 1001564899f9SDavidlohr Bueso 1002564899f9SDavidlohr Bueso return res; 1003564899f9SDavidlohr Bueso } 1004564899f9SDavidlohr Bueso 1005564899f9SDavidlohr Bueso static void sig_handler(int signo) 1006564899f9SDavidlohr Bueso { 1007564899f9SDavidlohr Bueso exit(handle_exit()); 1008564899f9SDavidlohr Bueso } 1009564899f9SDavidlohr Bueso 10101da177e4SLinus Torvalds int main(int ac, char **av) 10111da177e4SLinus Torvalds { 10121da177e4SLinus Torvalds char *mode; 10132982de69SSam Ravnborg int res; 10141da177e4SLinus Torvalds 1015564899f9SDavidlohr Bueso signal(SIGINT, sig_handler); 1016564899f9SDavidlohr Bueso 10170a1f00a1SMichal Marek if (ac > 1 && strcmp(av[1], "-s") == 0) { 10180a1f00a1SMichal Marek silent = 1; 10190a1f00a1SMichal Marek /* Silence conf_read() until the real callback is set up */ 10200a1f00a1SMichal Marek conf_set_message_callback(NULL); 10210a1f00a1SMichal Marek av++; 10220a1f00a1SMichal Marek } 10231da177e4SLinus Torvalds conf_parse(av[1]); 10241da177e4SLinus Torvalds conf_read(NULL); 10251da177e4SLinus Torvalds 10261da177e4SLinus Torvalds mode = getenv("MENUCONFIG_MODE"); 10271da177e4SLinus Torvalds if (mode) { 10281da177e4SLinus Torvalds if (!strcasecmp(mode, "single_menu")) 10291da177e4SLinus Torvalds single_menu_mode = 1; 10301da177e4SLinus Torvalds } 10311da177e4SLinus Torvalds 103209af091fSLadislav Michl if (init_dialog(NULL)) { 1033694c49a7SSam Ravnborg fprintf(stderr, "Your display is too small to run Menuconfig!\n"); 1034694c49a7SSam Ravnborg fprintf(stderr, "It must be at least 19 lines by 80 columns.\n"); 103509af091fSLadislav Michl return 1; 103609af091fSLadislav Michl } 103709af091fSLadislav Michl 1038d802b50fSSam Ravnborg set_config_filename(conf_get_configname()); 10396364fd0cSWang YanQing conf_set_message_callback(conf_message_callback); 1040f3cbcdc9SSam Ravnborg do { 10415e609addSBenjamin Poirier conf(&rootmenu, NULL); 1042564899f9SDavidlohr Bueso res = handle_exit(); 1043f3cbcdc9SSam Ravnborg } while (res == KEY_ESC); 1044b3214293SKarsten Wiese 1045564899f9SDavidlohr Bueso return res; 10461da177e4SLinus Torvalds } 1047