11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 31da177e4SLinus Torvalds * Released under the terms of the GNU GPL v2.0. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Introduced single menu mode (show all sub-menus in one large tree). 61da177e4SLinus Torvalds * 2002-11-06 Petr Baudis <pasky@ucw.cz> 73b9fa093SArnaldo Carvalho de Melo * 83b9fa093SArnaldo Carvalho de Melo * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br> 91da177e4SLinus Torvalds */ 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds #include <ctype.h> 121da177e4SLinus Torvalds #include <errno.h> 131da177e4SLinus Torvalds #include <fcntl.h> 141da177e4SLinus Torvalds #include <limits.h> 151da177e4SLinus Torvalds #include <stdarg.h> 161da177e4SLinus Torvalds #include <stdlib.h> 171da177e4SLinus Torvalds #include <string.h> 18564899f9SDavidlohr Bueso #include <signal.h> 191da177e4SLinus Torvalds #include <unistd.h> 20442ff702SJean-Christophe Dubois #include <locale.h> 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include "lkc.h" 232982de69SSam Ravnborg #include "lxdialog/dialog.h" 241da177e4SLinus Torvalds 253b9fa093SArnaldo Carvalho de Melo static const char mconf_readme[] = N_( 261da177e4SLinus Torvalds "Overview\n" 271da177e4SLinus Torvalds "--------\n" 28652cf982SArnaud Lacombe "This interface let 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" 421da177e4SLinus Torvalds "<N> to removed it. You may also press the <Space Bar> to cycle\n" 431da177e4SLinus Torvalds "through the available options (ie. 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" 491da177e4SLinus Torvalds "o Use the Up/Down arrow keys (cursor keys) to highlight the item\n" 501da177e4SLinus Torvalds " you wish to change or submenu 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" 6822c7eca6SLi Zefan " <Exit> and <Help>.\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" 1201da177e4SLinus Torvalds "At the end of the main menu you will find two options. One is\n" 1211da177e4SLinus Torvalds "for saving the current configuration to a file of your choosing.\n" 1221da177e4SLinus Torvalds "The other option is for loading a previously saved alternate\n" 1231da177e4SLinus Torvalds "configuration.\n" 1241da177e4SLinus Torvalds "\n" 1251da177e4SLinus Torvalds "Even if you don't use alternate configuration files, but you\n" 1261da177e4SLinus Torvalds "find during a Menuconfig session that you have completely messed\n" 1271da177e4SLinus Torvalds "up your settings, you may use the \"Load Alternate...\" option to\n" 1281da177e4SLinus Torvalds "restore your previously saved settings from \".config\" without\n" 1291da177e4SLinus Torvalds "restarting Menuconfig.\n" 1301da177e4SLinus Torvalds "\n" 1311da177e4SLinus Torvalds "Other information\n" 1321da177e4SLinus Torvalds "-----------------\n" 1331da177e4SLinus Torvalds "If you use Menuconfig in an XTERM window make sure you have your\n" 1341da177e4SLinus Torvalds "$TERM variable set to point to a xterm definition which supports color.\n" 1351da177e4SLinus Torvalds "Otherwise, Menuconfig will look rather bad. Menuconfig will not\n" 1361da177e4SLinus Torvalds "display correctly in a 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" 151652cf982SArnaud Lacombe "If you prefer to have all of the options listed in a single menu, rather\n" 152652cf982SArnaud Lacombe "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" 16445897213SSam Ravnborg "Different color themes available\n" 16545897213SSam Ravnborg "--------------------------------\n" 16645897213SSam Ravnborg "It is possible to select different color themes using the variable\n" 16745897213SSam Ravnborg "MENUCONFIG_COLOR. To select a theme use:\n" 16845897213SSam Ravnborg "\n" 16945897213SSam Ravnborg "make MENUCONFIG_COLOR=<theme> menuconfig\n" 17045897213SSam Ravnborg "\n" 17145897213SSam Ravnborg "Available themes are\n" 17245897213SSam Ravnborg " mono => selects colors suitable for monochrome displays\n" 17345897213SSam Ravnborg " blackbg => selects a color scheme with black background\n" 174350b5b76SSam Ravnborg " classic => theme with blue background. The classic look\n" 175350b5b76SSam Ravnborg " bluetitle => a LCD friendly version of classic. (default)\n" 17645897213SSam Ravnborg "\n"), 1773b9fa093SArnaldo Carvalho de Melo menu_instructions[] = N_( 1781da177e4SLinus Torvalds "Arrow keys navigate the menu. " 1791278ebdbSDirk Gouders "<Enter> selects submenus ---> (or empty submenus ----). " 1801da177e4SLinus Torvalds "Highlighted letters are hotkeys. " 1811da177e4SLinus Torvalds "Pressing <Y> includes, <N> excludes, <M> modularizes features. " 1821da177e4SLinus Torvalds "Press <Esc><Esc> to exit, <?> for Help, </> for Search. " 1833b9fa093SArnaldo Carvalho de Melo "Legend: [*] built-in [ ] excluded <M> module < > module capable"), 1843b9fa093SArnaldo Carvalho de Melo radiolist_instructions[] = N_( 1851da177e4SLinus Torvalds "Use the arrow keys to navigate this window or " 1861da177e4SLinus Torvalds "press the hotkey of the item you wish to select " 1871da177e4SLinus Torvalds "followed by the <SPACE BAR>. " 1883b9fa093SArnaldo Carvalho de Melo "Press <?> for additional information about this option."), 1893b9fa093SArnaldo Carvalho de Melo inputbox_instructions_int[] = N_( 1901da177e4SLinus Torvalds "Please enter a decimal value. " 1911da177e4SLinus Torvalds "Fractions will not be accepted. " 1923b9fa093SArnaldo Carvalho de Melo "Use the <TAB> key to move from the input field to the buttons below it."), 1933b9fa093SArnaldo Carvalho de Melo inputbox_instructions_hex[] = N_( 1941da177e4SLinus Torvalds "Please enter a hexadecimal value. " 1953b9fa093SArnaldo Carvalho de Melo "Use the <TAB> key to move from the input field to the buttons below it."), 1963b9fa093SArnaldo Carvalho de Melo inputbox_instructions_string[] = N_( 1971da177e4SLinus Torvalds "Please enter a string value. " 1983b9fa093SArnaldo Carvalho de Melo "Use the <TAB> key to move from the input field to the buttons below it."), 1993b9fa093SArnaldo Carvalho de Melo setmod_text[] = N_( 2001da177e4SLinus Torvalds "This feature depends on another which has been configured as a module.\n" 2013b9fa093SArnaldo Carvalho de Melo "As a result, this feature will be built as a module."), 2023b9fa093SArnaldo Carvalho de Melo load_config_text[] = N_( 2031da177e4SLinus Torvalds "Enter the name of the configuration file you wish to load. " 2041da177e4SLinus Torvalds "Accept the name shown to restore the configuration you " 2053b9fa093SArnaldo Carvalho de Melo "last retrieved. Leave blank to abort."), 2063b9fa093SArnaldo Carvalho de Melo load_config_help[] = N_( 2071da177e4SLinus Torvalds "\n" 208652cf982SArnaud Lacombe "For various reasons, one may wish to keep several different\n" 2091da177e4SLinus Torvalds "configurations available on a single machine.\n" 2101da177e4SLinus Torvalds "\n" 2111da177e4SLinus Torvalds "If you have saved a previous configuration in a file other than the\n" 212652cf982SArnaud Lacombe "default one, entering its name here will allow you to modify that\n" 213652cf982SArnaud Lacombe "configuration.\n" 2141da177e4SLinus Torvalds "\n" 2151da177e4SLinus Torvalds "If you are uncertain, then you have probably never used alternate\n" 216af901ca1SAndré Goddard Rosa "configuration files. You should therefore leave this blank to abort.\n"), 2173b9fa093SArnaldo Carvalho de Melo save_config_text[] = N_( 2181da177e4SLinus Torvalds "Enter a filename to which this configuration should be saved " 2193b9fa093SArnaldo Carvalho de Melo "as an alternate. Leave blank to abort."), 2203b9fa093SArnaldo Carvalho de Melo save_config_help[] = N_( 2211da177e4SLinus Torvalds "\n" 222652cf982SArnaud Lacombe "For various reasons, one may wish to keep different configurations\n" 223652cf982SArnaud Lacombe "available on a single machine.\n" 2241da177e4SLinus Torvalds "\n" 2251da177e4SLinus Torvalds "Entering a file name here will allow you to later retrieve, modify\n" 2261da177e4SLinus Torvalds "and use the current configuration as an alternate to whatever\n" 2271da177e4SLinus Torvalds "configuration options you have selected at that time.\n" 2281da177e4SLinus Torvalds "\n" 2291da177e4SLinus Torvalds "If you are uncertain what all this means then you should probably\n" 2303b9fa093SArnaldo Carvalho de Melo "leave this blank.\n"), 2313b9fa093SArnaldo Carvalho de Melo search_help[] = N_( 2321da177e4SLinus Torvalds "\n" 23359dfa24dSArnaud Lacombe "Search for symbols and display their relations.\n" 234503af334SRandy Dunlap "Regular expressions are allowed.\n" 2351da177e4SLinus Torvalds "Example: search for \"^FOO\"\n" 2361da177e4SLinus Torvalds "Result:\n" 2371da177e4SLinus Torvalds "-----------------------------------------------------------------\n" 2381da177e4SLinus Torvalds "Symbol: FOO [=m]\n" 2395e609addSBenjamin Poirier "Type : tristate\n" 2401da177e4SLinus Torvalds "Prompt: Foo bus is used to drive the bar HW\n" 2411da177e4SLinus Torvalds " Defined at drivers/pci/Kconfig:47\n" 2421da177e4SLinus Torvalds " Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n" 2431da177e4SLinus Torvalds " Location:\n" 244bb8187d3SPaul Gortmaker " -> Bus options (PCI, PCMCIA, EISA, ISA)\n" 2451da177e4SLinus Torvalds " -> PCI support (PCI [=y])\n" 2465e609addSBenjamin Poirier "(1) -> PCI access mode (<choice> [=y])\n" 2471da177e4SLinus Torvalds " Selects: LIBCRC32\n" 2481da177e4SLinus Torvalds " Selected by: BAR\n" 2491da177e4SLinus Torvalds "-----------------------------------------------------------------\n" 2505e609addSBenjamin Poirier "o The line 'Type:' shows the type of the configuration option for\n" 2515e609addSBenjamin Poirier " this symbol (boolean, tristate, string, ...)\n" 2521da177e4SLinus Torvalds "o The line 'Prompt:' shows the text used in the menu structure for\n" 25359dfa24dSArnaud Lacombe " this symbol\n" 2541da177e4SLinus Torvalds "o The 'Defined at' line tell at what file / line number the symbol\n" 2551da177e4SLinus Torvalds " is defined\n" 2561da177e4SLinus Torvalds "o The 'Depends on:' line tell what symbols needs to be defined for\n" 2571da177e4SLinus Torvalds " this symbol to be visible in the menu (selectable)\n" 2581da177e4SLinus Torvalds "o The 'Location:' lines tell where in the menu structure this symbol\n" 2591da177e4SLinus Torvalds " is located\n" 2605e609addSBenjamin Poirier " A location followed by a [=y] indicates that this is a\n" 2615e609addSBenjamin Poirier " selectable menu item - and the current value is displayed inside\n" 2625e609addSBenjamin Poirier " brackets.\n" 2635e609addSBenjamin Poirier " Press the key in the (#) prefix to jump directly to that\n" 2645e609addSBenjamin Poirier " location. You will be returned to the current search results\n" 2655e609addSBenjamin Poirier " after exiting this new menu.\n" 2661da177e4SLinus Torvalds "o The 'Selects:' line tell what symbol will be automatically\n" 2671da177e4SLinus Torvalds " selected if this symbol is selected (y or m)\n" 2681da177e4SLinus Torvalds "o The 'Selected by' line tell what symbol has selected this symbol\n" 2691da177e4SLinus Torvalds "\n" 2701da177e4SLinus Torvalds "Only relevant lines are shown.\n" 2711da177e4SLinus Torvalds "\n\n" 2721da177e4SLinus Torvalds "Search examples:\n" 27359dfa24dSArnaud Lacombe "Examples: USB => find all symbols containing USB\n" 27459dfa24dSArnaud Lacombe " ^USB => find all symbols starting with USB\n" 27559dfa24dSArnaud Lacombe " USB$ => find all symbols ending with USB\n" 2763b9fa093SArnaldo Carvalho de Melo "\n"); 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds static int indent; 2791da177e4SLinus Torvalds static struct menu *current_menu; 2801da177e4SLinus Torvalds static int child_count; 2811da177e4SLinus Torvalds static int single_menu_mode; 28222c7eca6SLi Zefan static int show_all_options; 2836364fd0cSWang YanQing static int save_and_exit; 2841da177e4SLinus Torvalds 2855e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_menu); 2861da177e4SLinus Torvalds static void conf_choice(struct menu *menu); 2871da177e4SLinus Torvalds static void conf_string(struct menu *menu); 2881da177e4SLinus Torvalds static void conf_load(void); 2891da177e4SLinus Torvalds static void conf_save(void); 29095ac9b3bSBenjamin Poirier static int show_textbox_ext(const char *title, char *text, int r, int c, 29195ac9b3bSBenjamin Poirier int *keys, int *vscroll, int *hscroll, 29295ac9b3bSBenjamin Poirier update_text_fn update_text, void *data); 2931da177e4SLinus Torvalds static void show_textbox(const char *title, const char *text, int r, int c); 2941da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text); 2951da177e4SLinus Torvalds static void show_help(struct menu *menu); 2961da177e4SLinus Torvalds 29795e30f95SSam Ravnborg static char filename[PATH_MAX+1]; 29895e30f95SSam Ravnborg static void set_config_filename(const char *config_filename) 29995e30f95SSam Ravnborg { 30095e30f95SSam Ravnborg static char menu_backtitle[PATH_MAX+128]; 30195e30f95SSam Ravnborg int size; 30295e30f95SSam Ravnborg 30395e30f95SSam Ravnborg size = snprintf(menu_backtitle, sizeof(menu_backtitle), 3040954828fSArnaud Lacombe "%s - %s", config_filename, rootmenu.prompt->text); 30595e30f95SSam Ravnborg if (size >= sizeof(menu_backtitle)) 30695e30f95SSam Ravnborg menu_backtitle[sizeof(menu_backtitle)-1] = '\0'; 30795e30f95SSam Ravnborg set_dialog_backtitle(menu_backtitle); 30895e30f95SSam Ravnborg 30995e30f95SSam Ravnborg size = snprintf(filename, sizeof(filename), "%s", config_filename); 31095e30f95SSam Ravnborg if (size >= sizeof(filename)) 31195e30f95SSam Ravnborg filename[sizeof(filename)-1] = '\0'; 31295e30f95SSam Ravnborg } 31395e30f95SSam Ravnborg 3149a69abf8SBenjamin Poirier struct subtitle_part { 3159a69abf8SBenjamin Poirier struct list_head entries; 3169a69abf8SBenjamin Poirier const char *text; 3179a69abf8SBenjamin Poirier }; 3189a69abf8SBenjamin Poirier static LIST_HEAD(trail); 3199a69abf8SBenjamin Poirier 3209a69abf8SBenjamin Poirier static struct subtitle_list *subtitles; 3219a69abf8SBenjamin Poirier static void set_subtitle(void) 3229a69abf8SBenjamin Poirier { 3239a69abf8SBenjamin Poirier struct subtitle_part *sp; 3249a69abf8SBenjamin Poirier struct subtitle_list *pos, *tmp; 3259a69abf8SBenjamin Poirier 3269a69abf8SBenjamin Poirier for (pos = subtitles; pos != NULL; pos = tmp) { 3279a69abf8SBenjamin Poirier tmp = pos->next; 3289a69abf8SBenjamin Poirier free(pos); 3299a69abf8SBenjamin Poirier } 3309a69abf8SBenjamin Poirier 3319a69abf8SBenjamin Poirier subtitles = NULL; 3329a69abf8SBenjamin Poirier list_for_each_entry(sp, &trail, entries) { 3339a69abf8SBenjamin Poirier if (sp->text) { 3349a69abf8SBenjamin Poirier if (pos) { 3359a69abf8SBenjamin Poirier pos->next = xcalloc(sizeof(*pos), 1); 3369a69abf8SBenjamin Poirier pos = pos->next; 3379a69abf8SBenjamin Poirier } else { 3389a69abf8SBenjamin Poirier subtitles = pos = xcalloc(sizeof(*pos), 1); 3399a69abf8SBenjamin Poirier } 3409a69abf8SBenjamin Poirier pos->text = sp->text; 3419a69abf8SBenjamin Poirier } 3429a69abf8SBenjamin Poirier } 3439a69abf8SBenjamin Poirier 3449a69abf8SBenjamin Poirier set_dialog_subtitles(subtitles); 3459a69abf8SBenjamin Poirier } 3469a69abf8SBenjamin Poirier 3479a69abf8SBenjamin Poirier static void reset_subtitle(void) 3489a69abf8SBenjamin Poirier { 3499a69abf8SBenjamin Poirier struct subtitle_list *pos, *tmp; 3509a69abf8SBenjamin Poirier 3519a69abf8SBenjamin Poirier for (pos = subtitles; pos != NULL; pos = tmp) { 3529a69abf8SBenjamin Poirier tmp = pos->next; 3539a69abf8SBenjamin Poirier free(pos); 3549a69abf8SBenjamin Poirier } 3559a69abf8SBenjamin Poirier subtitles = NULL; 3569a69abf8SBenjamin Poirier set_dialog_subtitles(subtitles); 3579a69abf8SBenjamin Poirier } 35895e30f95SSam Ravnborg 35995ac9b3bSBenjamin Poirier struct search_data { 360bad9955dSBenjamin Poirier struct list_head *head; 36195ac9b3bSBenjamin Poirier struct menu **targets; 36295ac9b3bSBenjamin Poirier int *keys; 36395ac9b3bSBenjamin Poirier }; 36495ac9b3bSBenjamin Poirier 36595ac9b3bSBenjamin Poirier static void update_text(char *buf, size_t start, size_t end, void *_data) 36695ac9b3bSBenjamin Poirier { 36795ac9b3bSBenjamin Poirier struct search_data *data = _data; 36895ac9b3bSBenjamin Poirier struct jump_key *pos; 36995ac9b3bSBenjamin Poirier int k = 0; 37095ac9b3bSBenjamin Poirier 371bad9955dSBenjamin Poirier list_for_each_entry(pos, data->head, entries) { 37295ac9b3bSBenjamin Poirier if (pos->offset >= start && pos->offset < end) { 37395ac9b3bSBenjamin Poirier char header[4]; 37495ac9b3bSBenjamin Poirier 37595ac9b3bSBenjamin Poirier if (k < JUMP_NB) { 37695ac9b3bSBenjamin Poirier int key = '0' + (pos->index % JUMP_NB) + 1; 37795ac9b3bSBenjamin Poirier 37895ac9b3bSBenjamin Poirier sprintf(header, "(%c)", key); 37995ac9b3bSBenjamin Poirier data->keys[k] = key; 38095ac9b3bSBenjamin Poirier data->targets[k] = pos->target; 38195ac9b3bSBenjamin Poirier k++; 38295ac9b3bSBenjamin Poirier } else { 38395ac9b3bSBenjamin Poirier sprintf(header, " "); 38495ac9b3bSBenjamin Poirier } 38595ac9b3bSBenjamin Poirier 38695ac9b3bSBenjamin Poirier memcpy(buf + pos->offset, header, sizeof(header) - 1); 38795ac9b3bSBenjamin Poirier } 38895ac9b3bSBenjamin Poirier } 38995ac9b3bSBenjamin Poirier data->keys[k] = 0; 39095ac9b3bSBenjamin Poirier } 39195ac9b3bSBenjamin Poirier 3921da177e4SLinus Torvalds static void search_conf(void) 3931da177e4SLinus Torvalds { 3941da177e4SLinus Torvalds struct symbol **sym_arr; 3951da177e4SLinus Torvalds struct gstr res; 396337a275dSYann E. MORIN struct gstr title; 3970584f9f9SBernhard Walle char *dialog_input; 3985e609addSBenjamin Poirier int dres, vscroll = 0, hscroll = 0; 3995e609addSBenjamin Poirier bool again; 4009a69abf8SBenjamin Poirier struct gstr sttext; 4019a69abf8SBenjamin Poirier struct subtitle_part stpart; 4025e609addSBenjamin Poirier 403337a275dSYann E. MORIN title = str_new(); 404337a275dSYann E. MORIN str_printf( &title, _("Enter %s (sub)string to search for " 405337a275dSYann E. MORIN "(with or without \"%s\")"), CONFIG_, CONFIG_); 406337a275dSYann E. MORIN 4071da177e4SLinus Torvalds again: 408e94c5bdeSSam Ravnborg dialog_clear(); 4092982de69SSam Ravnborg dres = dialog_inputbox(_("Search Configuration Parameter"), 410337a275dSYann E. MORIN str_get(&title), 4112982de69SSam Ravnborg 10, 75, ""); 4122982de69SSam Ravnborg switch (dres) { 4131da177e4SLinus Torvalds case 0: 4141da177e4SLinus Torvalds break; 4151da177e4SLinus Torvalds case 1: 4163b9fa093SArnaldo Carvalho de Melo show_helptext(_("Search Configuration"), search_help); 4171da177e4SLinus Torvalds goto again; 4181da177e4SLinus Torvalds default: 419337a275dSYann E. MORIN str_free(&title); 4201da177e4SLinus Torvalds return; 4211da177e4SLinus Torvalds } 4221da177e4SLinus Torvalds 423ffb5957bSArnaud Lacombe /* strip the prefix if necessary */ 4240584f9f9SBernhard Walle dialog_input = dialog_input_result; 425ffb5957bSArnaud Lacombe if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0) 426ffb5957bSArnaud Lacombe dialog_input += strlen(CONFIG_); 4270584f9f9SBernhard Walle 4289a69abf8SBenjamin Poirier sttext = str_new(); 4299a69abf8SBenjamin Poirier str_printf(&sttext, "Search (%s)", dialog_input_result); 4309a69abf8SBenjamin Poirier stpart.text = str_get(&sttext); 4319a69abf8SBenjamin Poirier list_add_tail(&stpart.entries, &trail); 4329a69abf8SBenjamin Poirier 4330584f9f9SBernhard Walle sym_arr = sym_re_search(dialog_input); 4345e609addSBenjamin Poirier do { 435bad9955dSBenjamin Poirier LIST_HEAD(head); 43695ac9b3bSBenjamin Poirier struct menu *targets[JUMP_NB]; 43795ac9b3bSBenjamin Poirier int keys[JUMP_NB + 1], i; 43895ac9b3bSBenjamin Poirier struct search_data data = { 43995ac9b3bSBenjamin Poirier .head = &head, 44095ac9b3bSBenjamin Poirier .targets = targets, 44195ac9b3bSBenjamin Poirier .keys = keys, 44295ac9b3bSBenjamin Poirier }; 443edb749f4SBenjamin Poirier struct jump_key *pos, *tmp; 4445e609addSBenjamin Poirier 44595ac9b3bSBenjamin Poirier res = get_relations_str(sym_arr, &head); 4469a69abf8SBenjamin Poirier set_subtitle(); 44795ac9b3bSBenjamin Poirier dres = show_textbox_ext(_("Search Results"), (char *) 44895ac9b3bSBenjamin Poirier str_get(&res), 0, 0, keys, &vscroll, 44995ac9b3bSBenjamin Poirier &hscroll, &update_text, (void *) 45095ac9b3bSBenjamin Poirier &data); 4515e609addSBenjamin Poirier again = false; 45295ac9b3bSBenjamin Poirier for (i = 0; i < JUMP_NB && keys[i]; i++) 4535e609addSBenjamin Poirier if (dres == keys[i]) { 45495ac9b3bSBenjamin Poirier conf(targets[i]->parent, targets[i]); 4555e609addSBenjamin Poirier again = true; 4565e609addSBenjamin Poirier } 4571da177e4SLinus Torvalds str_free(&res); 458edb749f4SBenjamin Poirier list_for_each_entry_safe(pos, tmp, &head, entries) 459edb749f4SBenjamin Poirier free(pos); 4605e609addSBenjamin Poirier } while (again); 4615e609addSBenjamin Poirier free(sym_arr); 462337a275dSYann E. MORIN str_free(&title); 4639a69abf8SBenjamin Poirier list_del(trail.prev); 4649a69abf8SBenjamin Poirier str_free(&sttext); 4651da177e4SLinus Torvalds } 4661da177e4SLinus Torvalds 4671da177e4SLinus Torvalds static void build_conf(struct menu *menu) 4681da177e4SLinus Torvalds { 4691da177e4SLinus Torvalds struct symbol *sym; 4701da177e4SLinus Torvalds struct property *prop; 4711da177e4SLinus Torvalds struct menu *child; 4721da177e4SLinus Torvalds int type, tmp, doint = 2; 4731da177e4SLinus Torvalds tristate val; 4741da177e4SLinus Torvalds char ch; 47522c7eca6SLi Zefan bool visible; 4761da177e4SLinus Torvalds 47722c7eca6SLi Zefan /* 47822c7eca6SLi Zefan * note: menu_is_visible() has side effect that it will 47922c7eca6SLi Zefan * recalc the value of the symbol. 48022c7eca6SLi Zefan */ 48122c7eca6SLi Zefan visible = menu_is_visible(menu); 48222c7eca6SLi Zefan if (show_all_options && !menu_has_prompt(menu)) 48322c7eca6SLi Zefan return; 48422c7eca6SLi Zefan else if (!show_all_options && !visible) 4851da177e4SLinus Torvalds return; 4861da177e4SLinus Torvalds 4871da177e4SLinus Torvalds sym = menu->sym; 4881da177e4SLinus Torvalds prop = menu->prompt; 4891da177e4SLinus Torvalds if (!sym) { 4901da177e4SLinus Torvalds if (prop && menu != current_menu) { 4911da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 4921da177e4SLinus Torvalds switch (prop->type) { 4931da177e4SLinus Torvalds case P_MENU: 4941da177e4SLinus Torvalds child_count++; 495413f006bSEGRY Gabor prompt = _(prompt); 4961da177e4SLinus Torvalds if (single_menu_mode) { 4972982de69SSam Ravnborg item_make("%s%*c%s", 4981da177e4SLinus Torvalds menu->data ? "-->" : "++>", 4991da177e4SLinus Torvalds indent + 1, ' ', prompt); 5001da177e4SLinus Torvalds } else 5011278ebdbSDirk Gouders item_make(" %*c%s %s", 5021278ebdbSDirk Gouders indent + 1, ' ', prompt, 5031278ebdbSDirk Gouders menu_is_empty(menu) ? "----" : "--->"); 5042982de69SSam Ravnborg item_set_tag('m'); 5052982de69SSam Ravnborg item_set_data(menu); 5061da177e4SLinus Torvalds if (single_menu_mode && menu->data) 5071da177e4SLinus Torvalds goto conf_childs; 5081da177e4SLinus Torvalds return; 50948874077SSam Ravnborg case P_COMMENT: 51048874077SSam Ravnborg if (prompt) { 51148874077SSam Ravnborg child_count++; 512413f006bSEGRY Gabor item_make(" %*c*** %s ***", indent + 1, ' ', _(prompt)); 51348874077SSam Ravnborg item_set_tag(':'); 51448874077SSam Ravnborg item_set_data(menu); 51548874077SSam Ravnborg } 51648874077SSam Ravnborg break; 5171da177e4SLinus Torvalds default: 5181da177e4SLinus Torvalds if (prompt) { 5191da177e4SLinus Torvalds child_count++; 520413f006bSEGRY Gabor item_make("---%*c%s", indent + 1, ' ', _(prompt)); 5212982de69SSam Ravnborg item_set_tag(':'); 5222982de69SSam Ravnborg item_set_data(menu); 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds } 5251da177e4SLinus Torvalds } else 5261da177e4SLinus Torvalds doint = 0; 5271da177e4SLinus Torvalds goto conf_childs; 5281da177e4SLinus Torvalds } 5291da177e4SLinus Torvalds 5301da177e4SLinus Torvalds type = sym_get_type(sym); 5311da177e4SLinus Torvalds if (sym_is_choice(sym)) { 5321da177e4SLinus Torvalds struct symbol *def_sym = sym_get_choice_value(sym); 5331da177e4SLinus Torvalds struct menu *def_menu = NULL; 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds child_count++; 5361da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 5371da177e4SLinus Torvalds if (menu_is_visible(child) && child->sym == def_sym) 5381da177e4SLinus Torvalds def_menu = child; 5391da177e4SLinus Torvalds } 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds val = sym_get_tristate_value(sym); 5421da177e4SLinus Torvalds if (sym_is_changable(sym)) { 5431da177e4SLinus Torvalds switch (type) { 5441da177e4SLinus Torvalds case S_BOOLEAN: 5452982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*'); 5461da177e4SLinus Torvalds break; 5471da177e4SLinus Torvalds case S_TRISTATE: 5481da177e4SLinus Torvalds switch (val) { 5491da177e4SLinus Torvalds case yes: ch = '*'; break; 5501da177e4SLinus Torvalds case mod: ch = 'M'; break; 5511da177e4SLinus Torvalds default: ch = ' '; break; 5521da177e4SLinus Torvalds } 5532982de69SSam Ravnborg item_make("<%c>", ch); 5541da177e4SLinus Torvalds break; 5551da177e4SLinus Torvalds } 5562982de69SSam Ravnborg item_set_tag('t'); 5572982de69SSam Ravnborg item_set_data(menu); 5581da177e4SLinus Torvalds } else { 5592982de69SSam Ravnborg item_make(" "); 5602982de69SSam Ravnborg item_set_tag(def_menu ? 't' : ':'); 5612982de69SSam Ravnborg item_set_data(menu); 5621da177e4SLinus Torvalds } 5631da177e4SLinus Torvalds 564413f006bSEGRY Gabor item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu))); 5651da177e4SLinus Torvalds if (val == yes) { 5661da177e4SLinus Torvalds if (def_menu) { 567413f006bSEGRY Gabor item_add_str(" (%s)", _(menu_get_prompt(def_menu))); 5682982de69SSam Ravnborg item_add_str(" --->"); 5691da177e4SLinus Torvalds if (def_menu->list) { 5701da177e4SLinus Torvalds indent += 2; 5711da177e4SLinus Torvalds build_conf(def_menu); 5721da177e4SLinus Torvalds indent -= 2; 5731da177e4SLinus Torvalds } 5742982de69SSam Ravnborg } 5751da177e4SLinus Torvalds return; 5761da177e4SLinus Torvalds } 5771da177e4SLinus Torvalds } else { 5781da177e4SLinus Torvalds if (menu == current_menu) { 579413f006bSEGRY Gabor item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu))); 5802982de69SSam Ravnborg item_set_tag(':'); 5812982de69SSam Ravnborg item_set_data(menu); 5821da177e4SLinus Torvalds goto conf_childs; 5831da177e4SLinus Torvalds } 5841da177e4SLinus Torvalds child_count++; 5851da177e4SLinus Torvalds val = sym_get_tristate_value(sym); 5861da177e4SLinus Torvalds if (sym_is_choice_value(sym) && val == yes) { 5872982de69SSam Ravnborg item_make(" "); 5882982de69SSam Ravnborg item_set_tag(':'); 5892982de69SSam Ravnborg item_set_data(menu); 5901da177e4SLinus Torvalds } else { 5911da177e4SLinus Torvalds switch (type) { 5921da177e4SLinus Torvalds case S_BOOLEAN: 5931da177e4SLinus Torvalds if (sym_is_changable(sym)) 5942982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*'); 5951da177e4SLinus Torvalds else 596b5d609dbSMatej Laitl item_make("-%c-", val == no ? ' ' : '*'); 5972982de69SSam Ravnborg item_set_tag('t'); 5982982de69SSam Ravnborg item_set_data(menu); 5991da177e4SLinus Torvalds break; 6001da177e4SLinus Torvalds case S_TRISTATE: 6011da177e4SLinus Torvalds switch (val) { 6021da177e4SLinus Torvalds case yes: ch = '*'; break; 6031da177e4SLinus Torvalds case mod: ch = 'M'; break; 6041da177e4SLinus Torvalds default: ch = ' '; break; 6051da177e4SLinus Torvalds } 606b5d609dbSMatej Laitl if (sym_is_changable(sym)) { 607b5d609dbSMatej Laitl if (sym->rev_dep.tri == mod) 608b5d609dbSMatej Laitl item_make("{%c}", ch); 6091da177e4SLinus Torvalds else 610b5d609dbSMatej Laitl item_make("<%c>", ch); 611b5d609dbSMatej Laitl } else 612b5d609dbSMatej Laitl item_make("-%c-", ch); 6132982de69SSam Ravnborg item_set_tag('t'); 6142982de69SSam Ravnborg item_set_data(menu); 6151da177e4SLinus Torvalds break; 6161da177e4SLinus Torvalds default: 6172982de69SSam Ravnborg tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */ 6182982de69SSam Ravnborg item_make("(%s)", sym_get_string_value(sym)); 6191da177e4SLinus Torvalds tmp = indent - tmp + 4; 6201da177e4SLinus Torvalds if (tmp < 0) 6211da177e4SLinus Torvalds tmp = 0; 622413f006bSEGRY Gabor item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)), 6231da177e4SLinus Torvalds (sym_has_value(sym) || !sym_is_changable(sym)) ? 624413f006bSEGRY Gabor "" : _(" (NEW)")); 6252982de69SSam Ravnborg item_set_tag('s'); 6262982de69SSam Ravnborg item_set_data(menu); 6271da177e4SLinus Torvalds goto conf_childs; 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds } 630413f006bSEGRY Gabor item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)), 6311da177e4SLinus Torvalds (sym_has_value(sym) || !sym_is_changable(sym)) ? 632413f006bSEGRY Gabor "" : _(" (NEW)")); 6331da177e4SLinus Torvalds if (menu->prompt->type == P_MENU) { 6341278ebdbSDirk Gouders item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->"); 6351da177e4SLinus Torvalds return; 6361da177e4SLinus Torvalds } 6371da177e4SLinus Torvalds } 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds conf_childs: 6401da177e4SLinus Torvalds indent += doint; 6411da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) 6421da177e4SLinus Torvalds build_conf(child); 6431da177e4SLinus Torvalds indent -= doint; 6441da177e4SLinus Torvalds } 6451da177e4SLinus Torvalds 6465e609addSBenjamin Poirier static void conf(struct menu *menu, struct menu *active_menu) 6471da177e4SLinus Torvalds { 6481da177e4SLinus Torvalds struct menu *submenu; 6491da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 6509a69abf8SBenjamin Poirier struct subtitle_part stpart; 6511da177e4SLinus Torvalds struct symbol *sym; 6522982de69SSam Ravnborg int res; 6532982de69SSam Ravnborg int s_scroll = 0; 6541da177e4SLinus Torvalds 6559a69abf8SBenjamin Poirier if (menu != &rootmenu) 6569a69abf8SBenjamin Poirier stpart.text = menu_get_prompt(menu); 6579a69abf8SBenjamin Poirier else 6589a69abf8SBenjamin Poirier stpart.text = NULL; 6599a69abf8SBenjamin Poirier list_add_tail(&stpart.entries, &trail); 6609a69abf8SBenjamin Poirier 6611da177e4SLinus Torvalds while (1) { 6622982de69SSam Ravnborg item_reset(); 6631da177e4SLinus Torvalds current_menu = menu; 6641da177e4SLinus Torvalds build_conf(menu); 6651da177e4SLinus Torvalds if (!child_count) 6661da177e4SLinus Torvalds break; 6679a69abf8SBenjamin Poirier set_subtitle(); 668e94c5bdeSSam Ravnborg dialog_clear(); 669413f006bSEGRY Gabor res = dialog_menu(prompt ? _(prompt) : _("Main Menu"), 6702982de69SSam Ravnborg _(menu_instructions), 6712982de69SSam Ravnborg active_menu, &s_scroll); 672c8dc68adSSam Ravnborg if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL) 6731da177e4SLinus Torvalds break; 6742982de69SSam Ravnborg if (!item_activate_selected()) 6752982de69SSam Ravnborg continue; 6762982de69SSam Ravnborg if (!item_tag()) 6771da177e4SLinus Torvalds continue; 6781da177e4SLinus Torvalds 6792982de69SSam Ravnborg submenu = item_data(); 6802982de69SSam Ravnborg active_menu = item_data(); 681c8dc68adSSam Ravnborg if (submenu) 6821da177e4SLinus Torvalds sym = submenu->sym; 683c8dc68adSSam Ravnborg else 684c8dc68adSSam Ravnborg sym = NULL; 6851da177e4SLinus Torvalds 6862982de69SSam Ravnborg switch (res) { 6871da177e4SLinus Torvalds case 0: 6882982de69SSam Ravnborg switch (item_tag()) { 6891da177e4SLinus Torvalds case 'm': 6901da177e4SLinus Torvalds if (single_menu_mode) 6911da177e4SLinus Torvalds submenu->data = (void *) (long) !submenu->data; 6921da177e4SLinus Torvalds else 6935e609addSBenjamin Poirier conf(submenu, NULL); 6941da177e4SLinus Torvalds break; 6951da177e4SLinus Torvalds case 't': 6961da177e4SLinus Torvalds if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes) 6971da177e4SLinus Torvalds conf_choice(submenu); 6981da177e4SLinus Torvalds else if (submenu->prompt->type == P_MENU) 6995e609addSBenjamin Poirier conf(submenu, NULL); 7001da177e4SLinus Torvalds break; 7011da177e4SLinus Torvalds case 's': 7021da177e4SLinus Torvalds conf_string(submenu); 7031da177e4SLinus Torvalds break; 7041da177e4SLinus Torvalds } 7051da177e4SLinus Torvalds break; 7061da177e4SLinus Torvalds case 2: 7071da177e4SLinus Torvalds if (sym) 7081da177e4SLinus Torvalds show_help(submenu); 7099a69abf8SBenjamin Poirier else { 7109a69abf8SBenjamin Poirier reset_subtitle(); 711413f006bSEGRY Gabor show_helptext(_("README"), _(mconf_readme)); 7129a69abf8SBenjamin Poirier } 7131da177e4SLinus Torvalds break; 7141da177e4SLinus Torvalds case 3: 7159a69abf8SBenjamin Poirier reset_subtitle(); 7166364fd0cSWang YanQing conf_save(); 7176364fd0cSWang YanQing break; 7186364fd0cSWang YanQing case 4: 7199a69abf8SBenjamin Poirier reset_subtitle(); 7206364fd0cSWang YanQing conf_load(); 7216364fd0cSWang YanQing break; 7226364fd0cSWang YanQing case 5: 7232982de69SSam Ravnborg if (item_is_tag('t')) { 7241da177e4SLinus Torvalds if (sym_set_tristate_value(sym, yes)) 7251da177e4SLinus Torvalds break; 7261da177e4SLinus Torvalds if (sym_set_tristate_value(sym, mod)) 7271da177e4SLinus Torvalds show_textbox(NULL, setmod_text, 6, 74); 7281da177e4SLinus Torvalds } 7291da177e4SLinus Torvalds break; 7306364fd0cSWang YanQing case 6: 7312982de69SSam Ravnborg if (item_is_tag('t')) 7321da177e4SLinus Torvalds sym_set_tristate_value(sym, no); 7331da177e4SLinus Torvalds break; 7346364fd0cSWang YanQing case 7: 7352982de69SSam Ravnborg if (item_is_tag('t')) 7361da177e4SLinus Torvalds sym_set_tristate_value(sym, mod); 7371da177e4SLinus Torvalds break; 7386364fd0cSWang YanQing case 8: 7392982de69SSam Ravnborg if (item_is_tag('t')) 7401da177e4SLinus Torvalds sym_toggle_tristate_value(sym); 7412982de69SSam Ravnborg else if (item_is_tag('m')) 7425e609addSBenjamin Poirier conf(submenu, NULL); 7431da177e4SLinus Torvalds break; 7446364fd0cSWang YanQing case 9: 7451da177e4SLinus Torvalds search_conf(); 7461da177e4SLinus Torvalds break; 7476364fd0cSWang YanQing case 10: 74822c7eca6SLi Zefan show_all_options = !show_all_options; 74922c7eca6SLi Zefan break; 7501da177e4SLinus Torvalds } 7511da177e4SLinus Torvalds } 7529a69abf8SBenjamin Poirier 7539a69abf8SBenjamin Poirier list_del(trail.prev); 7541da177e4SLinus Torvalds } 7551da177e4SLinus Torvalds 75695ac9b3bSBenjamin Poirier static int show_textbox_ext(const char *title, char *text, int r, int c, int 75795ac9b3bSBenjamin Poirier *keys, int *vscroll, int *hscroll, update_text_fn 75895ac9b3bSBenjamin Poirier update_text, void *data) 7591da177e4SLinus Torvalds { 760e94c5bdeSSam Ravnborg dialog_clear(); 76195ac9b3bSBenjamin Poirier return dialog_textbox(title, text, r, c, keys, vscroll, hscroll, 76295ac9b3bSBenjamin Poirier update_text, data); 763537ddae7SBenjamin Poirier } 764537ddae7SBenjamin Poirier 765537ddae7SBenjamin Poirier static void show_textbox(const char *title, const char *text, int r, int c) 766537ddae7SBenjamin Poirier { 76795ac9b3bSBenjamin Poirier show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL, 76895ac9b3bSBenjamin Poirier NULL, NULL); 7691da177e4SLinus Torvalds } 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text) 7721da177e4SLinus Torvalds { 7731da177e4SLinus Torvalds show_textbox(title, text, 0, 0); 7741da177e4SLinus Torvalds } 7751da177e4SLinus Torvalds 7766364fd0cSWang YanQing static void conf_message_callback(const char *fmt, va_list ap) 7776364fd0cSWang YanQing { 7786364fd0cSWang YanQing char buf[PATH_MAX+1]; 7796364fd0cSWang YanQing 7806364fd0cSWang YanQing vsnprintf(buf, sizeof(buf), fmt, ap); 7816364fd0cSWang YanQing if (save_and_exit) 7826364fd0cSWang YanQing printf("%s", buf); 7836364fd0cSWang YanQing else 7846364fd0cSWang YanQing show_textbox(NULL, buf, 6, 60); 7856364fd0cSWang YanQing } 7866364fd0cSWang YanQing 7871da177e4SLinus Torvalds static void show_help(struct menu *menu) 7881da177e4SLinus Torvalds { 7891da177e4SLinus Torvalds struct gstr help = str_new(); 7901da177e4SLinus Torvalds 791da60fbbcSVadim Bendebury (вб) help.max_width = getmaxx(stdscr) - 10; 7921d525e7cSCheng Renquan menu_get_ext_help(menu, &help); 7931d525e7cSCheng Renquan 794413f006bSEGRY Gabor show_helptext(_(menu_get_prompt(menu)), str_get(&help)); 7951da177e4SLinus Torvalds str_free(&help); 7961da177e4SLinus Torvalds } 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds static void conf_choice(struct menu *menu) 7991da177e4SLinus Torvalds { 800413f006bSEGRY Gabor const char *prompt = _(menu_get_prompt(menu)); 8011da177e4SLinus Torvalds struct menu *child; 8021da177e4SLinus Torvalds struct symbol *active; 8031da177e4SLinus Torvalds 8041da177e4SLinus Torvalds active = sym_get_choice_value(menu->sym); 8051da177e4SLinus Torvalds while (1) { 8062982de69SSam Ravnborg int res; 8072982de69SSam Ravnborg int selected; 8082982de69SSam Ravnborg item_reset(); 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds current_menu = menu; 8111da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 8121da177e4SLinus Torvalds if (!menu_is_visible(child)) 8131da177e4SLinus Torvalds continue; 814af6c1598SPeter Korsgaard if (child->sym) 815413f006bSEGRY Gabor item_make("%s", _(menu_get_prompt(child))); 816af6c1598SPeter Korsgaard else { 817af6c1598SPeter Korsgaard item_make("*** %s ***", _(menu_get_prompt(child))); 818af6c1598SPeter Korsgaard item_set_tag(':'); 819af6c1598SPeter Korsgaard } 8202982de69SSam Ravnborg item_set_data(child); 8212982de69SSam Ravnborg if (child->sym == active) 8222982de69SSam Ravnborg item_set_selected(1); 8231da177e4SLinus Torvalds if (child->sym == sym_get_choice_value(menu->sym)) 8242982de69SSam Ravnborg item_set_tag('X'); 8251da177e4SLinus Torvalds } 826e94c5bdeSSam Ravnborg dialog_clear(); 827413f006bSEGRY Gabor res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"), 8282982de69SSam Ravnborg _(radiolist_instructions), 829ff7b0c2cSSedat Dilek MENUBOX_HEIGTH_MIN, 830ff7b0c2cSSedat Dilek MENUBOX_WIDTH_MIN, 831ff7b0c2cSSedat Dilek CHECKLIST_HEIGTH_MIN); 8322982de69SSam Ravnborg selected = item_activate_selected(); 8332982de69SSam Ravnborg switch (res) { 8341da177e4SLinus Torvalds case 0: 8352982de69SSam Ravnborg if (selected) { 8362982de69SSam Ravnborg child = item_data(); 837af6c1598SPeter Korsgaard if (!child->sym) 838af6c1598SPeter Korsgaard break; 839af6c1598SPeter Korsgaard 8401da177e4SLinus Torvalds sym_set_tristate_value(child->sym, yes); 8412982de69SSam Ravnborg } 8421da177e4SLinus Torvalds return; 8431da177e4SLinus Torvalds case 1: 8442982de69SSam Ravnborg if (selected) { 8452982de69SSam Ravnborg child = item_data(); 8461da177e4SLinus Torvalds show_help(child); 8471da177e4SLinus Torvalds active = child->sym; 8481da177e4SLinus Torvalds } else 8491da177e4SLinus Torvalds show_help(menu); 8501da177e4SLinus Torvalds break; 851f3cbcdc9SSam Ravnborg case KEY_ESC: 8521da177e4SLinus Torvalds return; 853c8dc68adSSam Ravnborg case -ERRDISPLAYTOOSMALL: 854c8dc68adSSam Ravnborg return; 8551da177e4SLinus Torvalds } 8561da177e4SLinus Torvalds } 8571da177e4SLinus Torvalds } 8581da177e4SLinus Torvalds 8591da177e4SLinus Torvalds static void conf_string(struct menu *menu) 8601da177e4SLinus Torvalds { 8611da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 8621da177e4SLinus Torvalds 8631da177e4SLinus Torvalds while (1) { 8642982de69SSam Ravnborg int res; 865c4143a83SSam Ravnborg const char *heading; 8662982de69SSam Ravnborg 8671da177e4SLinus Torvalds switch (sym_get_type(menu->sym)) { 8681da177e4SLinus Torvalds case S_INT: 8692982de69SSam Ravnborg heading = _(inputbox_instructions_int); 8701da177e4SLinus Torvalds break; 8711da177e4SLinus Torvalds case S_HEX: 8722982de69SSam Ravnborg heading = _(inputbox_instructions_hex); 8731da177e4SLinus Torvalds break; 8741da177e4SLinus Torvalds case S_STRING: 8752982de69SSam Ravnborg heading = _(inputbox_instructions_string); 8761da177e4SLinus Torvalds break; 8771da177e4SLinus Torvalds default: 878413f006bSEGRY Gabor heading = _("Internal mconf error!"); 8791da177e4SLinus Torvalds } 880e94c5bdeSSam Ravnborg dialog_clear(); 881413f006bSEGRY Gabor res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"), 8822982de69SSam Ravnborg heading, 10, 75, 8832982de69SSam Ravnborg sym_get_string_value(menu->sym)); 8842982de69SSam Ravnborg switch (res) { 8851da177e4SLinus Torvalds case 0: 8862982de69SSam Ravnborg if (sym_set_string_value(menu->sym, dialog_input_result)) 8871da177e4SLinus Torvalds return; 8883b9fa093SArnaldo Carvalho de Melo show_textbox(NULL, _("You have made an invalid entry."), 5, 43); 8891da177e4SLinus Torvalds break; 8901da177e4SLinus Torvalds case 1: 8911da177e4SLinus Torvalds show_help(menu); 8921da177e4SLinus Torvalds break; 893f3cbcdc9SSam Ravnborg case KEY_ESC: 8941da177e4SLinus Torvalds return; 8951da177e4SLinus Torvalds } 8961da177e4SLinus Torvalds } 8971da177e4SLinus Torvalds } 8981da177e4SLinus Torvalds 8991da177e4SLinus Torvalds static void conf_load(void) 9001da177e4SLinus Torvalds { 9011da177e4SLinus Torvalds 9021da177e4SLinus Torvalds while (1) { 9032982de69SSam Ravnborg int res; 904e94c5bdeSSam Ravnborg dialog_clear(); 9052982de69SSam Ravnborg res = dialog_inputbox(NULL, load_config_text, 9062982de69SSam Ravnborg 11, 55, filename); 9072982de69SSam Ravnborg switch(res) { 9081da177e4SLinus Torvalds case 0: 9092982de69SSam Ravnborg if (!dialog_input_result[0]) 9101da177e4SLinus Torvalds return; 91195e30f95SSam Ravnborg if (!conf_read(dialog_input_result)) { 91295e30f95SSam Ravnborg set_config_filename(dialog_input_result); 91336ef805bSSam Ravnborg sym_set_change_count(1); 9141da177e4SLinus Torvalds return; 91595e30f95SSam Ravnborg } 9163b9fa093SArnaldo Carvalho de Melo show_textbox(NULL, _("File does not exist!"), 5, 38); 9171da177e4SLinus Torvalds break; 9181da177e4SLinus Torvalds case 1: 9193b9fa093SArnaldo Carvalho de Melo show_helptext(_("Load Alternate Configuration"), load_config_help); 9201da177e4SLinus Torvalds break; 921f3cbcdc9SSam Ravnborg case KEY_ESC: 9221da177e4SLinus Torvalds return; 9231da177e4SLinus Torvalds } 9241da177e4SLinus Torvalds } 9251da177e4SLinus Torvalds } 9261da177e4SLinus Torvalds 9271da177e4SLinus Torvalds static void conf_save(void) 9281da177e4SLinus Torvalds { 9291da177e4SLinus Torvalds while (1) { 9302982de69SSam Ravnborg int res; 931e94c5bdeSSam Ravnborg dialog_clear(); 9322982de69SSam Ravnborg res = dialog_inputbox(NULL, save_config_text, 9332982de69SSam Ravnborg 11, 55, filename); 9342982de69SSam Ravnborg switch(res) { 9351da177e4SLinus Torvalds case 0: 9362982de69SSam Ravnborg if (!dialog_input_result[0]) 9371da177e4SLinus Torvalds return; 93895e30f95SSam Ravnborg if (!conf_write(dialog_input_result)) { 93995e30f95SSam Ravnborg set_config_filename(dialog_input_result); 9401da177e4SLinus Torvalds return; 94195e30f95SSam Ravnborg } 9423b9fa093SArnaldo Carvalho de Melo show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60); 9431da177e4SLinus Torvalds break; 9441da177e4SLinus Torvalds case 1: 9453b9fa093SArnaldo Carvalho de Melo show_helptext(_("Save Alternate Configuration"), save_config_help); 9461da177e4SLinus Torvalds break; 947f3cbcdc9SSam Ravnborg case KEY_ESC: 9481da177e4SLinus Torvalds return; 9491da177e4SLinus Torvalds } 9501da177e4SLinus Torvalds } 9511da177e4SLinus Torvalds } 9521da177e4SLinus Torvalds 953564899f9SDavidlohr Bueso static int handle_exit(void) 954564899f9SDavidlohr Bueso { 955564899f9SDavidlohr Bueso int res; 956564899f9SDavidlohr Bueso 9576364fd0cSWang YanQing save_and_exit = 1; 9589a69abf8SBenjamin Poirier reset_subtitle(); 959564899f9SDavidlohr Bueso dialog_clear(); 960564899f9SDavidlohr Bueso if (conf_get_changed()) 961564899f9SDavidlohr Bueso res = dialog_yesno(NULL, 962564899f9SDavidlohr Bueso _("Do you wish to save your new configuration?\n" 96313763916SDirk Gouders "(Press <ESC><ESC> to continue kernel configuration.)"), 964564899f9SDavidlohr Bueso 6, 60); 965564899f9SDavidlohr Bueso else 966564899f9SDavidlohr Bueso res = -1; 967564899f9SDavidlohr Bueso 968564899f9SDavidlohr Bueso end_dialog(saved_x, saved_y); 969564899f9SDavidlohr Bueso 970564899f9SDavidlohr Bueso switch (res) { 971564899f9SDavidlohr Bueso case 0: 972564899f9SDavidlohr Bueso if (conf_write(filename)) { 973564899f9SDavidlohr Bueso fprintf(stderr, _("\n\n" 974564899f9SDavidlohr Bueso "Error while writing of the configuration.\n" 975564899f9SDavidlohr Bueso "Your configuration changes were NOT saved." 976564899f9SDavidlohr Bueso "\n\n")); 977564899f9SDavidlohr Bueso return 1; 978564899f9SDavidlohr Bueso } 979564899f9SDavidlohr Bueso /* fall through */ 980564899f9SDavidlohr Bueso case -1: 981564899f9SDavidlohr Bueso printf(_("\n\n" 982564899f9SDavidlohr Bueso "*** End of the configuration.\n" 983564899f9SDavidlohr Bueso "*** Execute 'make' to start the build or try 'make help'." 984564899f9SDavidlohr Bueso "\n\n")); 985564899f9SDavidlohr Bueso res = 0; 986564899f9SDavidlohr Bueso break; 987564899f9SDavidlohr Bueso default: 988564899f9SDavidlohr Bueso fprintf(stderr, _("\n\n" 989564899f9SDavidlohr Bueso "Your configuration changes were NOT saved." 990564899f9SDavidlohr Bueso "\n\n")); 99130c4eaafSLi Zefan if (res != KEY_ESC) 992c55ac154SWang YanQing res = 0; 993564899f9SDavidlohr Bueso } 994564899f9SDavidlohr Bueso 995564899f9SDavidlohr Bueso return res; 996564899f9SDavidlohr Bueso } 997564899f9SDavidlohr Bueso 998564899f9SDavidlohr Bueso static void sig_handler(int signo) 999564899f9SDavidlohr Bueso { 1000564899f9SDavidlohr Bueso exit(handle_exit()); 1001564899f9SDavidlohr Bueso } 1002564899f9SDavidlohr Bueso 10031da177e4SLinus Torvalds int main(int ac, char **av) 10041da177e4SLinus Torvalds { 10051da177e4SLinus Torvalds char *mode; 10062982de69SSam Ravnborg int res; 10071da177e4SLinus Torvalds 10083b9fa093SArnaldo Carvalho de Melo setlocale(LC_ALL, ""); 10093b9fa093SArnaldo Carvalho de Melo bindtextdomain(PACKAGE, LOCALEDIR); 10103b9fa093SArnaldo Carvalho de Melo textdomain(PACKAGE); 10113b9fa093SArnaldo Carvalho de Melo 1012564899f9SDavidlohr Bueso signal(SIGINT, sig_handler); 1013564899f9SDavidlohr Bueso 10141da177e4SLinus Torvalds conf_parse(av[1]); 10151da177e4SLinus Torvalds conf_read(NULL); 10161da177e4SLinus Torvalds 10171da177e4SLinus Torvalds mode = getenv("MENUCONFIG_MODE"); 10181da177e4SLinus Torvalds if (mode) { 10191da177e4SLinus Torvalds if (!strcasecmp(mode, "single_menu")) 10201da177e4SLinus Torvalds single_menu_mode = 1; 10211da177e4SLinus Torvalds } 10221da177e4SLinus Torvalds 102309af091fSLadislav Michl if (init_dialog(NULL)) { 102409af091fSLadislav Michl fprintf(stderr, N_("Your display is too small to run Menuconfig!\n")); 102509af091fSLadislav Michl fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n")); 102609af091fSLadislav Michl return 1; 102709af091fSLadislav Michl } 102809af091fSLadislav Michl 1029d802b50fSSam Ravnborg set_config_filename(conf_get_configname()); 10306364fd0cSWang YanQing conf_set_message_callback(conf_message_callback); 1031f3cbcdc9SSam Ravnborg do { 10325e609addSBenjamin Poirier conf(&rootmenu, NULL); 1033564899f9SDavidlohr Bueso res = handle_exit(); 1034f3cbcdc9SSam Ravnborg } while (res == KEY_ESC); 1035b3214293SKarsten Wiese 1036564899f9SDavidlohr Bueso return res; 10371da177e4SLinus Torvalds } 1038c4143a83SSam Ravnborg 1039