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 <sys/ioctl.h> 121da177e4SLinus Torvalds #include <sys/wait.h> 131da177e4SLinus Torvalds #include <ctype.h> 141da177e4SLinus Torvalds #include <errno.h> 151da177e4SLinus Torvalds #include <fcntl.h> 161da177e4SLinus Torvalds #include <limits.h> 171da177e4SLinus Torvalds #include <signal.h> 181da177e4SLinus Torvalds #include <stdarg.h> 191da177e4SLinus Torvalds #include <stdlib.h> 201da177e4SLinus Torvalds #include <string.h> 211da177e4SLinus Torvalds #include <termios.h> 221da177e4SLinus Torvalds #include <unistd.h> 23442ff702SJean-Christophe Dubois #include <locale.h> 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #define LKC_DIRECT_LINK 261da177e4SLinus Torvalds #include "lkc.h" 272982de69SSam Ravnborg #include "lxdialog/dialog.h" 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds static char menu_backtitle[128]; 303b9fa093SArnaldo Carvalho de Melo static const char mconf_readme[] = N_( 311da177e4SLinus Torvalds "Overview\n" 321da177e4SLinus Torvalds "--------\n" 331da177e4SLinus Torvalds "Some kernel features may be built directly into the kernel.\n" 341da177e4SLinus Torvalds "Some may be made into loadable runtime modules. Some features\n" 351da177e4SLinus Torvalds "may be completely removed altogether. There are also certain\n" 361da177e4SLinus Torvalds "kernel parameters which are not really features, but must be\n" 371da177e4SLinus Torvalds "entered in as decimal or hexadecimal numbers or possibly text.\n" 381da177e4SLinus Torvalds "\n" 391da177e4SLinus Torvalds "Menu items beginning with [*], <M> or [ ] represent features\n" 401da177e4SLinus Torvalds "configured to be built in, modularized or removed respectively.\n" 411da177e4SLinus Torvalds "Pointed brackets <> represent module capable features.\n" 421da177e4SLinus Torvalds "\n" 431da177e4SLinus Torvalds "To change any of these features, highlight it with the cursor\n" 441da177e4SLinus Torvalds "keys and press <Y> to build it in, <M> to make it a module or\n" 451da177e4SLinus Torvalds "<N> to removed it. You may also press the <Space Bar> to cycle\n" 461da177e4SLinus Torvalds "through the available options (ie. Y->N->M->Y).\n" 471da177e4SLinus Torvalds "\n" 481da177e4SLinus Torvalds "Some additional keyboard hints:\n" 491da177e4SLinus Torvalds "\n" 501da177e4SLinus Torvalds "Menus\n" 511da177e4SLinus Torvalds "----------\n" 521da177e4SLinus Torvalds "o Use the Up/Down arrow keys (cursor keys) to highlight the item\n" 531da177e4SLinus Torvalds " you wish to change or submenu wish to select and press <Enter>.\n" 541da177e4SLinus Torvalds " Submenus are designated by \"--->\".\n" 551da177e4SLinus Torvalds "\n" 561da177e4SLinus Torvalds " Shortcut: Press the option's highlighted letter (hotkey).\n" 571da177e4SLinus Torvalds " Pressing a hotkey more than once will sequence\n" 581da177e4SLinus Torvalds " through all visible items which use that hotkey.\n" 591da177e4SLinus Torvalds "\n" 601da177e4SLinus Torvalds " You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n" 611da177e4SLinus Torvalds " unseen options into view.\n" 621da177e4SLinus Torvalds "\n" 631da177e4SLinus Torvalds "o To exit a menu use the cursor keys to highlight the <Exit> button\n" 641da177e4SLinus Torvalds " and press <ENTER>.\n" 651da177e4SLinus Torvalds "\n" 661da177e4SLinus Torvalds " Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n" 671da177e4SLinus Torvalds " using those letters. You may press a single <ESC>, but\n" 681da177e4SLinus Torvalds " there is a delayed response which you may find annoying.\n" 691da177e4SLinus Torvalds "\n" 701da177e4SLinus Torvalds " Also, the <TAB> and cursor keys will cycle between <Select>,\n" 711da177e4SLinus Torvalds " <Exit> and <Help>\n" 721da177e4SLinus Torvalds "\n" 731da177e4SLinus Torvalds "o To get help with an item, use the cursor keys to highlight <Help>\n" 741da177e4SLinus Torvalds " and Press <ENTER>.\n" 751da177e4SLinus Torvalds "\n" 761da177e4SLinus Torvalds " Shortcut: Press <H> or <?>.\n" 771da177e4SLinus Torvalds "\n" 781da177e4SLinus Torvalds "\n" 791da177e4SLinus Torvalds "Radiolists (Choice lists)\n" 801da177e4SLinus Torvalds "-----------\n" 811da177e4SLinus Torvalds "o Use the cursor keys to select the option you wish to set and press\n" 821da177e4SLinus Torvalds " <S> or the <SPACE BAR>.\n" 831da177e4SLinus Torvalds "\n" 841da177e4SLinus Torvalds " Shortcut: Press the first letter of the option you wish to set then\n" 851da177e4SLinus Torvalds " press <S> or <SPACE BAR>.\n" 861da177e4SLinus Torvalds "\n" 871da177e4SLinus Torvalds "o To see available help for the item, use the cursor keys to highlight\n" 881da177e4SLinus Torvalds " <Help> and Press <ENTER>.\n" 891da177e4SLinus Torvalds "\n" 901da177e4SLinus Torvalds " Shortcut: Press <H> or <?>.\n" 911da177e4SLinus Torvalds "\n" 921da177e4SLinus Torvalds " Also, the <TAB> and cursor keys will cycle between <Select> and\n" 931da177e4SLinus Torvalds " <Help>\n" 941da177e4SLinus Torvalds "\n" 951da177e4SLinus Torvalds "\n" 961da177e4SLinus Torvalds "Data Entry\n" 971da177e4SLinus Torvalds "-----------\n" 981da177e4SLinus Torvalds "o Enter the requested information and press <ENTER>\n" 991da177e4SLinus Torvalds " If you are entering hexadecimal values, it is not necessary to\n" 1001da177e4SLinus Torvalds " add the '0x' prefix to the entry.\n" 1011da177e4SLinus Torvalds "\n" 1021da177e4SLinus Torvalds "o For help, use the <TAB> or cursor keys to highlight the help option\n" 1031da177e4SLinus Torvalds " and press <ENTER>. You can try <TAB><H> as well.\n" 1041da177e4SLinus Torvalds "\n" 1051da177e4SLinus Torvalds "\n" 1061da177e4SLinus Torvalds "Text Box (Help Window)\n" 1071da177e4SLinus Torvalds "--------\n" 1081da177e4SLinus Torvalds "o Use the cursor keys to scroll up/down/left/right. The VI editor\n" 1091da177e4SLinus Torvalds " keys h,j,k,l function here as do <SPACE BAR> and <B> for those\n" 1101da177e4SLinus Torvalds " who are familiar with less and lynx.\n" 1111da177e4SLinus Torvalds "\n" 1121da177e4SLinus Torvalds "o Press <E>, <X>, <Enter> or <Esc><Esc> to exit.\n" 1131da177e4SLinus Torvalds "\n" 1141da177e4SLinus Torvalds "\n" 1151da177e4SLinus Torvalds "Alternate Configuration Files\n" 1161da177e4SLinus Torvalds "-----------------------------\n" 1171da177e4SLinus Torvalds "Menuconfig supports the use of alternate configuration files for\n" 1181da177e4SLinus Torvalds "those who, for various reasons, find it necessary to switch\n" 1191da177e4SLinus Torvalds "between different kernel configurations.\n" 1201da177e4SLinus Torvalds "\n" 1211da177e4SLinus Torvalds "At the end of the main menu you will find two options. One is\n" 1221da177e4SLinus Torvalds "for saving the current configuration to a file of your choosing.\n" 1231da177e4SLinus Torvalds "The other option is for loading a previously saved alternate\n" 1241da177e4SLinus Torvalds "configuration.\n" 1251da177e4SLinus Torvalds "\n" 1261da177e4SLinus Torvalds "Even if you don't use alternate configuration files, but you\n" 1271da177e4SLinus Torvalds "find during a Menuconfig session that you have completely messed\n" 1281da177e4SLinus Torvalds "up your settings, you may use the \"Load Alternate...\" option to\n" 1291da177e4SLinus Torvalds "restore your previously saved settings from \".config\" without\n" 1301da177e4SLinus Torvalds "restarting Menuconfig.\n" 1311da177e4SLinus Torvalds "\n" 1321da177e4SLinus Torvalds "Other information\n" 1331da177e4SLinus Torvalds "-----------------\n" 1341da177e4SLinus Torvalds "If you use Menuconfig in an XTERM window make sure you have your\n" 1351da177e4SLinus Torvalds "$TERM variable set to point to a xterm definition which supports color.\n" 1361da177e4SLinus Torvalds "Otherwise, Menuconfig will look rather bad. Menuconfig will not\n" 1371da177e4SLinus Torvalds "display correctly in a RXVT window because rxvt displays only one\n" 1381da177e4SLinus Torvalds "intensity of color, bright.\n" 1391da177e4SLinus Torvalds "\n" 1401da177e4SLinus Torvalds "Menuconfig will display larger menus on screens or xterms which are\n" 1411da177e4SLinus Torvalds "set to display more than the standard 25 row by 80 column geometry.\n" 1421da177e4SLinus Torvalds "In order for this to work, the \"stty size\" command must be able to\n" 1431da177e4SLinus Torvalds "display the screen's current row and column geometry. I STRONGLY\n" 1441da177e4SLinus Torvalds "RECOMMEND that you make sure you do NOT have the shell variables\n" 1451da177e4SLinus Torvalds "LINES and COLUMNS exported into your environment. Some distributions\n" 1461da177e4SLinus Torvalds "export those variables via /etc/profile. Some ncurses programs can\n" 1471da177e4SLinus Torvalds "become confused when those variables (LINES & COLUMNS) don't reflect\n" 1481da177e4SLinus Torvalds "the true screen size.\n" 1491da177e4SLinus Torvalds "\n" 1501da177e4SLinus Torvalds "Optional personality available\n" 1511da177e4SLinus Torvalds "------------------------------\n" 1521da177e4SLinus Torvalds "If you prefer to have all of the kernel options listed in a single\n" 1531da177e4SLinus Torvalds "menu, rather than the default multimenu hierarchy, run the menuconfig\n" 1541da177e4SLinus Torvalds "with MENUCONFIG_MODE environment variable set to single_menu. Example:\n" 1551da177e4SLinus Torvalds "\n" 1561da177e4SLinus Torvalds "make MENUCONFIG_MODE=single_menu menuconfig\n" 1571da177e4SLinus Torvalds "\n" 1581da177e4SLinus Torvalds "<Enter> will then unroll the appropriate category, or enfold it if it\n" 1591da177e4SLinus Torvalds "is already unrolled.\n" 1601da177e4SLinus Torvalds "\n" 1611da177e4SLinus Torvalds "Note that this mode can eventually be a little more CPU expensive\n" 1621da177e4SLinus Torvalds "(especially with a larger number of unrolled categories) than the\n" 16345897213SSam Ravnborg "default mode.\n" 16445897213SSam Ravnborg "\n" 16545897213SSam Ravnborg "Different color themes available\n" 16645897213SSam Ravnborg "--------------------------------\n" 16745897213SSam Ravnborg "It is possible to select different color themes using the variable\n" 16845897213SSam Ravnborg "MENUCONFIG_COLOR. To select a theme use:\n" 16945897213SSam Ravnborg "\n" 17045897213SSam Ravnborg "make MENUCONFIG_COLOR=<theme> menuconfig\n" 17145897213SSam Ravnborg "\n" 17245897213SSam Ravnborg "Available themes are\n" 17345897213SSam Ravnborg " mono => selects colors suitable for monochrome displays\n" 17445897213SSam Ravnborg " blackbg => selects a color scheme with black background\n" 175350b5b76SSam Ravnborg " classic => theme with blue background. The classic look\n" 176350b5b76SSam Ravnborg " bluetitle => a LCD friendly version of classic. (default)\n" 17745897213SSam Ravnborg "\n"), 1783b9fa093SArnaldo Carvalho de Melo menu_instructions[] = N_( 1791da177e4SLinus Torvalds "Arrow keys navigate the menu. " 1801da177e4SLinus Torvalds "<Enter> selects submenus --->. " 1811da177e4SLinus Torvalds "Highlighted letters are hotkeys. " 1821da177e4SLinus Torvalds "Pressing <Y> includes, <N> excludes, <M> modularizes features. " 1831da177e4SLinus Torvalds "Press <Esc><Esc> to exit, <?> for Help, </> for Search. " 1843b9fa093SArnaldo Carvalho de Melo "Legend: [*] built-in [ ] excluded <M> module < > module capable"), 1853b9fa093SArnaldo Carvalho de Melo radiolist_instructions[] = N_( 1861da177e4SLinus Torvalds "Use the arrow keys to navigate this window or " 1871da177e4SLinus Torvalds "press the hotkey of the item you wish to select " 1881da177e4SLinus Torvalds "followed by the <SPACE BAR>. " 1893b9fa093SArnaldo Carvalho de Melo "Press <?> for additional information about this option."), 1903b9fa093SArnaldo Carvalho de Melo inputbox_instructions_int[] = N_( 1911da177e4SLinus Torvalds "Please enter a decimal value. " 1921da177e4SLinus Torvalds "Fractions will not be accepted. " 1933b9fa093SArnaldo Carvalho de Melo "Use the <TAB> key to move from the input field to the buttons below it."), 1943b9fa093SArnaldo Carvalho de Melo inputbox_instructions_hex[] = N_( 1951da177e4SLinus Torvalds "Please enter a hexadecimal value. " 1963b9fa093SArnaldo Carvalho de Melo "Use the <TAB> key to move from the input field to the buttons below it."), 1973b9fa093SArnaldo Carvalho de Melo inputbox_instructions_string[] = N_( 1981da177e4SLinus Torvalds "Please enter a string value. " 1993b9fa093SArnaldo Carvalho de Melo "Use the <TAB> key to move from the input field to the buttons below it."), 2003b9fa093SArnaldo Carvalho de Melo setmod_text[] = N_( 2011da177e4SLinus Torvalds "This feature depends on another which has been configured as a module.\n" 2023b9fa093SArnaldo Carvalho de Melo "As a result, this feature will be built as a module."), 2033b9fa093SArnaldo Carvalho de Melo nohelp_text[] = N_( 2043b9fa093SArnaldo Carvalho de Melo "There is no help available for this kernel option.\n"), 2053b9fa093SArnaldo Carvalho de Melo load_config_text[] = N_( 2061da177e4SLinus Torvalds "Enter the name of the configuration file you wish to load. " 2071da177e4SLinus Torvalds "Accept the name shown to restore the configuration you " 2083b9fa093SArnaldo Carvalho de Melo "last retrieved. Leave blank to abort."), 2093b9fa093SArnaldo Carvalho de Melo load_config_help[] = N_( 2101da177e4SLinus Torvalds "\n" 2111da177e4SLinus Torvalds "For various reasons, one may wish to keep several different kernel\n" 2121da177e4SLinus Torvalds "configurations available on a single machine.\n" 2131da177e4SLinus Torvalds "\n" 2141da177e4SLinus Torvalds "If you have saved a previous configuration in a file other than the\n" 2151da177e4SLinus Torvalds "kernel's default, entering the name of the file here will allow you\n" 2161da177e4SLinus Torvalds "to modify that configuration.\n" 2171da177e4SLinus Torvalds "\n" 2181da177e4SLinus Torvalds "If you are uncertain, then you have probably never used alternate\n" 2193b9fa093SArnaldo Carvalho de Melo "configuration files. You should therefor leave this blank to abort.\n"), 2203b9fa093SArnaldo Carvalho de Melo save_config_text[] = N_( 2211da177e4SLinus Torvalds "Enter a filename to which this configuration should be saved " 2223b9fa093SArnaldo Carvalho de Melo "as an alternate. Leave blank to abort."), 2233b9fa093SArnaldo Carvalho de Melo save_config_help[] = N_( 2241da177e4SLinus Torvalds "\n" 2251da177e4SLinus Torvalds "For various reasons, one may wish to keep different kernel\n" 2261da177e4SLinus Torvalds "configurations available on a single machine.\n" 2271da177e4SLinus Torvalds "\n" 2281da177e4SLinus Torvalds "Entering a file name here will allow you to later retrieve, modify\n" 2291da177e4SLinus Torvalds "and use the current configuration as an alternate to whatever\n" 2301da177e4SLinus Torvalds "configuration options you have selected at that time.\n" 2311da177e4SLinus Torvalds "\n" 2321da177e4SLinus Torvalds "If you are uncertain what all this means then you should probably\n" 2333b9fa093SArnaldo Carvalho de Melo "leave this blank.\n"), 2343b9fa093SArnaldo Carvalho de Melo search_help[] = N_( 2351da177e4SLinus Torvalds "\n" 2361da177e4SLinus Torvalds "Search for CONFIG_ symbols and display their relations.\n" 237503af334SRandy Dunlap "Regular expressions are allowed.\n" 2381da177e4SLinus Torvalds "Example: search for \"^FOO\"\n" 2391da177e4SLinus Torvalds "Result:\n" 2401da177e4SLinus Torvalds "-----------------------------------------------------------------\n" 2411da177e4SLinus Torvalds "Symbol: FOO [=m]\n" 2421da177e4SLinus Torvalds "Prompt: Foo bus is used to drive the bar HW\n" 2431da177e4SLinus Torvalds "Defined at drivers/pci/Kconfig:47\n" 2441da177e4SLinus Torvalds "Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n" 2451da177e4SLinus Torvalds "Location:\n" 2461da177e4SLinus Torvalds " -> Bus options (PCI, PCMCIA, EISA, MCA, ISA)\n" 2471da177e4SLinus Torvalds " -> PCI support (PCI [=y])\n" 2481da177e4SLinus Torvalds " -> PCI access mode (<choice> [=y])\n" 2491da177e4SLinus Torvalds "Selects: LIBCRC32\n" 2501da177e4SLinus Torvalds "Selected by: BAR\n" 2511da177e4SLinus Torvalds "-----------------------------------------------------------------\n" 2521da177e4SLinus Torvalds "o The line 'Prompt:' shows the text used in the menu structure for\n" 2531da177e4SLinus Torvalds " this CONFIG_ 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" 2601da177e4SLinus Torvalds " A location followed by a [=y] indicate that this is a selectable\n" 2611da177e4SLinus Torvalds " menu item - and current value is displayed inside brackets.\n" 2621da177e4SLinus Torvalds "o The 'Selects:' line tell what symbol will be automatically\n" 2631da177e4SLinus Torvalds " selected if this symbol is selected (y or m)\n" 2641da177e4SLinus Torvalds "o The 'Selected by' line tell what symbol has selected this symbol\n" 2651da177e4SLinus Torvalds "\n" 2661da177e4SLinus Torvalds "Only relevant lines are shown.\n" 2671da177e4SLinus Torvalds "\n\n" 2681da177e4SLinus Torvalds "Search examples:\n" 2691da177e4SLinus Torvalds "Examples: USB => find all CONFIG_ symbols containing USB\n" 2701da177e4SLinus Torvalds " ^USB => find all CONFIG_ symbols starting with USB\n" 2711da177e4SLinus Torvalds " USB$ => find all CONFIG_ symbols ending with USB\n" 2723b9fa093SArnaldo Carvalho de Melo "\n"); 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds static char filename[PATH_MAX+1] = ".config"; 2751da177e4SLinus Torvalds static int indent; 2761da177e4SLinus Torvalds static struct termios ios_org; 2771da177e4SLinus Torvalds static int rows = 0, cols = 0; 2781da177e4SLinus Torvalds static struct menu *current_menu; 2791da177e4SLinus Torvalds static int child_count; 2801da177e4SLinus Torvalds static int single_menu_mode; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds static void conf(struct menu *menu); 2831da177e4SLinus Torvalds static void conf_choice(struct menu *menu); 2841da177e4SLinus Torvalds static void conf_string(struct menu *menu); 2851da177e4SLinus Torvalds static void conf_load(void); 2861da177e4SLinus Torvalds static void conf_save(void); 2871da177e4SLinus Torvalds static void show_textbox(const char *title, const char *text, int r, int c); 2881da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text); 2891da177e4SLinus Torvalds static void show_help(struct menu *menu); 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds static void init_wsize(void) 2921da177e4SLinus Torvalds { 2931da177e4SLinus Torvalds struct winsize ws; 2941da177e4SLinus Torvalds char *env; 2951da177e4SLinus Torvalds 2961da177e4SLinus Torvalds if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) { 2971da177e4SLinus Torvalds rows = ws.ws_row; 2981da177e4SLinus Torvalds cols = ws.ws_col; 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds if (!rows) { 3021da177e4SLinus Torvalds env = getenv("LINES"); 3031da177e4SLinus Torvalds if (env) 3041da177e4SLinus Torvalds rows = atoi(env); 3051da177e4SLinus Torvalds if (!rows) 3061da177e4SLinus Torvalds rows = 24; 3071da177e4SLinus Torvalds } 3081da177e4SLinus Torvalds if (!cols) { 3091da177e4SLinus Torvalds env = getenv("COLUMNS"); 3101da177e4SLinus Torvalds if (env) 3111da177e4SLinus Torvalds cols = atoi(env); 3121da177e4SLinus Torvalds if (!cols) 3131da177e4SLinus Torvalds cols = 80; 3141da177e4SLinus Torvalds } 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds if (rows < 19 || cols < 80) { 3173b9fa093SArnaldo Carvalho de Melo fprintf(stderr, N_("Your display is too small to run Menuconfig!\n")); 3183b9fa093SArnaldo Carvalho de Melo fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n")); 3191da177e4SLinus Torvalds exit(1); 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds 3221da177e4SLinus Torvalds rows -= 4; 3231da177e4SLinus Torvalds cols -= 5; 3241da177e4SLinus Torvalds } 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds static void get_prompt_str(struct gstr *r, struct property *prop) 3271da177e4SLinus Torvalds { 3281da177e4SLinus Torvalds int i, j; 3291da177e4SLinus Torvalds struct menu *submenu[8], *menu; 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds str_printf(r, "Prompt: %s\n", prop->text); 3321da177e4SLinus Torvalds str_printf(r, " Defined at %s:%d\n", prop->menu->file->name, 3331da177e4SLinus Torvalds prop->menu->lineno); 3341da177e4SLinus Torvalds if (!expr_is_yes(prop->visible.expr)) { 3351da177e4SLinus Torvalds str_append(r, " Depends on: "); 3361da177e4SLinus Torvalds expr_gstr_print(prop->visible.expr, r); 3371da177e4SLinus Torvalds str_append(r, "\n"); 3381da177e4SLinus Torvalds } 3391da177e4SLinus Torvalds menu = prop->menu->parent; 3401da177e4SLinus Torvalds for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) 3411da177e4SLinus Torvalds submenu[i++] = menu; 3421da177e4SLinus Torvalds if (i > 0) { 3431da177e4SLinus Torvalds str_printf(r, " Location:\n"); 3441da177e4SLinus Torvalds for (j = 4; --i >= 0; j += 2) { 3451da177e4SLinus Torvalds menu = submenu[i]; 3461da177e4SLinus Torvalds str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu)); 3471da177e4SLinus Torvalds if (menu->sym) { 3481da177e4SLinus Torvalds str_printf(r, " (%s [=%s])", menu->sym->name ? 3491da177e4SLinus Torvalds menu->sym->name : "<choice>", 3501da177e4SLinus Torvalds sym_get_string_value(menu->sym)); 3511da177e4SLinus Torvalds } 3521da177e4SLinus Torvalds str_append(r, "\n"); 3531da177e4SLinus Torvalds } 3541da177e4SLinus Torvalds } 3551da177e4SLinus Torvalds } 3561da177e4SLinus Torvalds 3571da177e4SLinus Torvalds static void get_symbol_str(struct gstr *r, struct symbol *sym) 3581da177e4SLinus Torvalds { 3591da177e4SLinus Torvalds bool hit; 3601da177e4SLinus Torvalds struct property *prop; 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds str_printf(r, "Symbol: %s [=%s]\n", sym->name, 3631da177e4SLinus Torvalds sym_get_string_value(sym)); 3641da177e4SLinus Torvalds for_all_prompts(sym, prop) 3651da177e4SLinus Torvalds get_prompt_str(r, prop); 3661da177e4SLinus Torvalds hit = false; 3671da177e4SLinus Torvalds for_all_properties(sym, prop, P_SELECT) { 3681da177e4SLinus Torvalds if (!hit) { 3691da177e4SLinus Torvalds str_append(r, " Selects: "); 3701da177e4SLinus Torvalds hit = true; 3711da177e4SLinus Torvalds } else 3721da177e4SLinus Torvalds str_printf(r, " && "); 3731da177e4SLinus Torvalds expr_gstr_print(prop->expr, r); 3741da177e4SLinus Torvalds } 3751da177e4SLinus Torvalds if (hit) 3761da177e4SLinus Torvalds str_append(r, "\n"); 3771da177e4SLinus Torvalds if (sym->rev_dep.expr) { 3781da177e4SLinus Torvalds str_append(r, " Selected by: "); 3791da177e4SLinus Torvalds expr_gstr_print(sym->rev_dep.expr, r); 3801da177e4SLinus Torvalds str_append(r, "\n"); 3811da177e4SLinus Torvalds } 3821da177e4SLinus Torvalds str_append(r, "\n\n"); 3831da177e4SLinus Torvalds } 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds static struct gstr get_relations_str(struct symbol **sym_arr) 3861da177e4SLinus Torvalds { 3871da177e4SLinus Torvalds struct symbol *sym; 3881da177e4SLinus Torvalds struct gstr res = str_new(); 3891da177e4SLinus Torvalds int i; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds for (i = 0; sym_arr && (sym = sym_arr[i]); i++) 3921da177e4SLinus Torvalds get_symbol_str(&res, sym); 3931da177e4SLinus Torvalds if (!i) 3941da177e4SLinus Torvalds str_append(&res, "No matches found.\n"); 3951da177e4SLinus Torvalds return res; 3961da177e4SLinus Torvalds } 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds static void search_conf(void) 3991da177e4SLinus Torvalds { 4001da177e4SLinus Torvalds struct symbol **sym_arr; 4011da177e4SLinus Torvalds struct gstr res; 4022982de69SSam Ravnborg int dres; 4031da177e4SLinus Torvalds again: 404e94c5bdeSSam Ravnborg dialog_clear(); 4052982de69SSam Ravnborg dres = dialog_inputbox(_("Search Configuration Parameter"), 4062982de69SSam Ravnborg _("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"), 4072982de69SSam Ravnborg 10, 75, ""); 4082982de69SSam Ravnborg switch (dres) { 4091da177e4SLinus Torvalds case 0: 4101da177e4SLinus Torvalds break; 4111da177e4SLinus Torvalds case 1: 4123b9fa093SArnaldo Carvalho de Melo show_helptext(_("Search Configuration"), search_help); 4131da177e4SLinus Torvalds goto again; 4141da177e4SLinus Torvalds default: 4151da177e4SLinus Torvalds return; 4161da177e4SLinus Torvalds } 4171da177e4SLinus Torvalds 4182982de69SSam Ravnborg sym_arr = sym_re_search(dialog_input_result); 4191da177e4SLinus Torvalds res = get_relations_str(sym_arr); 4201da177e4SLinus Torvalds free(sym_arr); 4213b9fa093SArnaldo Carvalho de Melo show_textbox(_("Search Results"), str_get(&res), 0, 0); 4221da177e4SLinus Torvalds str_free(&res); 4231da177e4SLinus Torvalds } 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvalds static void build_conf(struct menu *menu) 4261da177e4SLinus Torvalds { 4271da177e4SLinus Torvalds struct symbol *sym; 4281da177e4SLinus Torvalds struct property *prop; 4291da177e4SLinus Torvalds struct menu *child; 4301da177e4SLinus Torvalds int type, tmp, doint = 2; 4311da177e4SLinus Torvalds tristate val; 4321da177e4SLinus Torvalds char ch; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds if (!menu_is_visible(menu)) 4351da177e4SLinus Torvalds return; 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds sym = menu->sym; 4381da177e4SLinus Torvalds prop = menu->prompt; 4391da177e4SLinus Torvalds if (!sym) { 4401da177e4SLinus Torvalds if (prop && menu != current_menu) { 4411da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 4421da177e4SLinus Torvalds switch (prop->type) { 4431da177e4SLinus Torvalds case P_MENU: 4441da177e4SLinus Torvalds child_count++; 4451da177e4SLinus Torvalds if (single_menu_mode) { 4462982de69SSam Ravnborg item_make("%s%*c%s", 4471da177e4SLinus Torvalds menu->data ? "-->" : "++>", 4481da177e4SLinus Torvalds indent + 1, ' ', prompt); 4491da177e4SLinus Torvalds } else 4502982de69SSam Ravnborg item_make(" %*c%s --->", indent + 1, ' ', prompt); 4511da177e4SLinus Torvalds 4522982de69SSam Ravnborg item_set_tag('m'); 4532982de69SSam Ravnborg item_set_data(menu); 4541da177e4SLinus Torvalds if (single_menu_mode && menu->data) 4551da177e4SLinus Torvalds goto conf_childs; 4561da177e4SLinus Torvalds return; 4571da177e4SLinus Torvalds default: 4581da177e4SLinus Torvalds if (prompt) { 4591da177e4SLinus Torvalds child_count++; 4602982de69SSam Ravnborg item_make("---%*c%s", indent + 1, ' ', prompt); 4612982de69SSam Ravnborg item_set_tag(':'); 4622982de69SSam Ravnborg item_set_data(menu); 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds } else 4661da177e4SLinus Torvalds doint = 0; 4671da177e4SLinus Torvalds goto conf_childs; 4681da177e4SLinus Torvalds } 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds type = sym_get_type(sym); 4711da177e4SLinus Torvalds if (sym_is_choice(sym)) { 4721da177e4SLinus Torvalds struct symbol *def_sym = sym_get_choice_value(sym); 4731da177e4SLinus Torvalds struct menu *def_menu = NULL; 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds child_count++; 4761da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 4771da177e4SLinus Torvalds if (menu_is_visible(child) && child->sym == def_sym) 4781da177e4SLinus Torvalds def_menu = child; 4791da177e4SLinus Torvalds } 4801da177e4SLinus Torvalds 4811da177e4SLinus Torvalds val = sym_get_tristate_value(sym); 4821da177e4SLinus Torvalds if (sym_is_changable(sym)) { 4831da177e4SLinus Torvalds switch (type) { 4841da177e4SLinus Torvalds case S_BOOLEAN: 4852982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*'); 4861da177e4SLinus Torvalds break; 4871da177e4SLinus Torvalds case S_TRISTATE: 4881da177e4SLinus Torvalds switch (val) { 4891da177e4SLinus Torvalds case yes: ch = '*'; break; 4901da177e4SLinus Torvalds case mod: ch = 'M'; break; 4911da177e4SLinus Torvalds default: ch = ' '; break; 4921da177e4SLinus Torvalds } 4932982de69SSam Ravnborg item_make("<%c>", ch); 4941da177e4SLinus Torvalds break; 4951da177e4SLinus Torvalds } 4962982de69SSam Ravnborg item_set_tag('t'); 4972982de69SSam Ravnborg item_set_data(menu); 4981da177e4SLinus Torvalds } else { 4992982de69SSam Ravnborg item_make(" "); 5002982de69SSam Ravnborg item_set_tag(def_menu ? 't' : ':'); 5012982de69SSam Ravnborg item_set_data(menu); 5021da177e4SLinus Torvalds } 5031da177e4SLinus Torvalds 5042982de69SSam Ravnborg item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu)); 5051da177e4SLinus Torvalds if (val == yes) { 5061da177e4SLinus Torvalds if (def_menu) { 5072982de69SSam Ravnborg item_add_str(" (%s)", menu_get_prompt(def_menu)); 5082982de69SSam Ravnborg item_add_str(" --->"); 5091da177e4SLinus Torvalds if (def_menu->list) { 5101da177e4SLinus Torvalds indent += 2; 5111da177e4SLinus Torvalds build_conf(def_menu); 5121da177e4SLinus Torvalds indent -= 2; 5131da177e4SLinus Torvalds } 5142982de69SSam Ravnborg } 5151da177e4SLinus Torvalds return; 5161da177e4SLinus Torvalds } 5171da177e4SLinus Torvalds } else { 5181da177e4SLinus Torvalds if (menu == current_menu) { 5192982de69SSam Ravnborg item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); 5202982de69SSam Ravnborg item_set_tag(':'); 5212982de69SSam Ravnborg item_set_data(menu); 5221da177e4SLinus Torvalds goto conf_childs; 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds child_count++; 5251da177e4SLinus Torvalds val = sym_get_tristate_value(sym); 5261da177e4SLinus Torvalds if (sym_is_choice_value(sym) && val == yes) { 5272982de69SSam Ravnborg item_make(" "); 5282982de69SSam Ravnborg item_set_tag(':'); 5292982de69SSam Ravnborg item_set_data(menu); 5301da177e4SLinus Torvalds } else { 5311da177e4SLinus Torvalds switch (type) { 5321da177e4SLinus Torvalds case S_BOOLEAN: 5331da177e4SLinus Torvalds if (sym_is_changable(sym)) 5342982de69SSam Ravnborg item_make("[%c]", val == no ? ' ' : '*'); 5351da177e4SLinus Torvalds else 5362982de69SSam Ravnborg item_make("---"); 5372982de69SSam Ravnborg item_set_tag('t'); 5382982de69SSam Ravnborg item_set_data(menu); 5391da177e4SLinus Torvalds break; 5401da177e4SLinus Torvalds case S_TRISTATE: 5411da177e4SLinus Torvalds switch (val) { 5421da177e4SLinus Torvalds case yes: ch = '*'; break; 5431da177e4SLinus Torvalds case mod: ch = 'M'; break; 5441da177e4SLinus Torvalds default: ch = ' '; break; 5451da177e4SLinus Torvalds } 5461da177e4SLinus Torvalds if (sym_is_changable(sym)) 5472982de69SSam Ravnborg item_make("<%c>", ch); 5481da177e4SLinus Torvalds else 5492982de69SSam Ravnborg item_make("---"); 5502982de69SSam Ravnborg item_set_tag('t'); 5512982de69SSam Ravnborg item_set_data(menu); 5521da177e4SLinus Torvalds break; 5531da177e4SLinus Torvalds default: 5542982de69SSam Ravnborg tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */ 5552982de69SSam Ravnborg item_make("(%s)", sym_get_string_value(sym)); 5561da177e4SLinus Torvalds tmp = indent - tmp + 4; 5571da177e4SLinus Torvalds if (tmp < 0) 5581da177e4SLinus Torvalds tmp = 0; 5592982de69SSam Ravnborg item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu), 5601da177e4SLinus Torvalds (sym_has_value(sym) || !sym_is_changable(sym)) ? 5611da177e4SLinus Torvalds "" : " (NEW)"); 5622982de69SSam Ravnborg item_set_tag('s'); 5632982de69SSam Ravnborg item_set_data(menu); 5641da177e4SLinus Torvalds goto conf_childs; 5651da177e4SLinus Torvalds } 5661da177e4SLinus Torvalds } 5672982de69SSam Ravnborg item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), 5681da177e4SLinus Torvalds (sym_has_value(sym) || !sym_is_changable(sym)) ? 5691da177e4SLinus Torvalds "" : " (NEW)"); 5701da177e4SLinus Torvalds if (menu->prompt->type == P_MENU) { 5712982de69SSam Ravnborg item_add_str(" --->"); 5721da177e4SLinus Torvalds return; 5731da177e4SLinus Torvalds } 5741da177e4SLinus Torvalds } 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds conf_childs: 5771da177e4SLinus Torvalds indent += doint; 5781da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) 5791da177e4SLinus Torvalds build_conf(child); 5801da177e4SLinus Torvalds indent -= doint; 5811da177e4SLinus Torvalds } 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds static void conf(struct menu *menu) 5841da177e4SLinus Torvalds { 5851da177e4SLinus Torvalds struct menu *submenu; 5861da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 5871da177e4SLinus Torvalds struct symbol *sym; 5882982de69SSam Ravnborg struct menu *active_menu = NULL; 5892982de69SSam Ravnborg int res; 5902982de69SSam Ravnborg int s_scroll = 0; 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds while (1) { 5932982de69SSam Ravnborg item_reset(); 5941da177e4SLinus Torvalds current_menu = menu; 5951da177e4SLinus Torvalds build_conf(menu); 5961da177e4SLinus Torvalds if (!child_count) 5971da177e4SLinus Torvalds break; 5981da177e4SLinus Torvalds if (menu == &rootmenu) { 5992982de69SSam Ravnborg item_make("--- "); 6002982de69SSam Ravnborg item_set_tag(':'); 6012982de69SSam Ravnborg item_make(_(" Load an Alternate Configuration File")); 6022982de69SSam Ravnborg item_set_tag('L'); 6032982de69SSam Ravnborg item_make(_(" Save an Alternate Configuration File")); 6042982de69SSam Ravnborg item_set_tag('S'); 6051da177e4SLinus Torvalds } 606e94c5bdeSSam Ravnborg dialog_clear(); 6072982de69SSam Ravnborg res = dialog_menu(prompt ? prompt : _("Main Menu"), 6082982de69SSam Ravnborg _(menu_instructions), 6092982de69SSam Ravnborg active_menu, &s_scroll); 610c8dc68adSSam Ravnborg if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL) 6111da177e4SLinus Torvalds break; 6122982de69SSam Ravnborg if (!item_activate_selected()) 6132982de69SSam Ravnborg continue; 6142982de69SSam Ravnborg if (!item_tag()) 6151da177e4SLinus Torvalds continue; 6161da177e4SLinus Torvalds 6172982de69SSam Ravnborg submenu = item_data(); 6182982de69SSam Ravnborg active_menu = item_data(); 619c8dc68adSSam Ravnborg if (submenu) 6201da177e4SLinus Torvalds sym = submenu->sym; 621c8dc68adSSam Ravnborg else 622c8dc68adSSam Ravnborg sym = NULL; 6231da177e4SLinus Torvalds 6242982de69SSam Ravnborg switch (res) { 6251da177e4SLinus Torvalds case 0: 6262982de69SSam Ravnborg switch (item_tag()) { 6271da177e4SLinus Torvalds case 'm': 6281da177e4SLinus Torvalds if (single_menu_mode) 6291da177e4SLinus Torvalds submenu->data = (void *) (long) !submenu->data; 6301da177e4SLinus Torvalds else 6311da177e4SLinus Torvalds conf(submenu); 6321da177e4SLinus Torvalds break; 6331da177e4SLinus Torvalds case 't': 6341da177e4SLinus Torvalds if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes) 6351da177e4SLinus Torvalds conf_choice(submenu); 6361da177e4SLinus Torvalds else if (submenu->prompt->type == P_MENU) 6371da177e4SLinus Torvalds conf(submenu); 6381da177e4SLinus Torvalds break; 6391da177e4SLinus Torvalds case 's': 6401da177e4SLinus Torvalds conf_string(submenu); 6411da177e4SLinus Torvalds break; 6421da177e4SLinus Torvalds case 'L': 6431da177e4SLinus Torvalds conf_load(); 6441da177e4SLinus Torvalds break; 6451da177e4SLinus Torvalds case 'S': 6461da177e4SLinus Torvalds conf_save(); 6471da177e4SLinus Torvalds break; 6481da177e4SLinus Torvalds } 6491da177e4SLinus Torvalds break; 6501da177e4SLinus Torvalds case 2: 6511da177e4SLinus Torvalds if (sym) 6521da177e4SLinus Torvalds show_help(submenu); 6531da177e4SLinus Torvalds else 6543b9fa093SArnaldo Carvalho de Melo show_helptext("README", _(mconf_readme)); 6551da177e4SLinus Torvalds break; 6561da177e4SLinus Torvalds case 3: 6572982de69SSam Ravnborg if (item_is_tag('t')) { 6581da177e4SLinus Torvalds if (sym_set_tristate_value(sym, yes)) 6591da177e4SLinus Torvalds break; 6601da177e4SLinus Torvalds if (sym_set_tristate_value(sym, mod)) 6611da177e4SLinus Torvalds show_textbox(NULL, setmod_text, 6, 74); 6621da177e4SLinus Torvalds } 6631da177e4SLinus Torvalds break; 6641da177e4SLinus Torvalds case 4: 6652982de69SSam Ravnborg if (item_is_tag('t')) 6661da177e4SLinus Torvalds sym_set_tristate_value(sym, no); 6671da177e4SLinus Torvalds break; 6681da177e4SLinus Torvalds case 5: 6692982de69SSam Ravnborg if (item_is_tag('t')) 6701da177e4SLinus Torvalds sym_set_tristate_value(sym, mod); 6711da177e4SLinus Torvalds break; 6721da177e4SLinus Torvalds case 6: 6732982de69SSam Ravnborg if (item_is_tag('t')) 6741da177e4SLinus Torvalds sym_toggle_tristate_value(sym); 6752982de69SSam Ravnborg else if (item_is_tag('m')) 6761da177e4SLinus Torvalds conf(submenu); 6771da177e4SLinus Torvalds break; 6781da177e4SLinus Torvalds case 7: 6791da177e4SLinus Torvalds search_conf(); 6801da177e4SLinus Torvalds break; 6811da177e4SLinus Torvalds } 6821da177e4SLinus Torvalds } 6831da177e4SLinus Torvalds } 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds static void show_textbox(const char *title, const char *text, int r, int c) 6861da177e4SLinus Torvalds { 687e94c5bdeSSam Ravnborg dialog_clear(); 688c8dc68adSSam Ravnborg dialog_textbox(title, text, r, c); 6891da177e4SLinus Torvalds } 6901da177e4SLinus Torvalds 6911da177e4SLinus Torvalds static void show_helptext(const char *title, const char *text) 6921da177e4SLinus Torvalds { 6931da177e4SLinus Torvalds show_textbox(title, text, 0, 0); 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds static void show_help(struct menu *menu) 6971da177e4SLinus Torvalds { 6981da177e4SLinus Torvalds struct gstr help = str_new(); 6991da177e4SLinus Torvalds struct symbol *sym = menu->sym; 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds if (sym->help) 7021da177e4SLinus Torvalds { 7031da177e4SLinus Torvalds if (sym->name) { 7041da177e4SLinus Torvalds str_printf(&help, "CONFIG_%s:\n\n", sym->name); 7053b9fa093SArnaldo Carvalho de Melo str_append(&help, _(sym->help)); 7061da177e4SLinus Torvalds str_append(&help, "\n"); 7071da177e4SLinus Torvalds } 7081da177e4SLinus Torvalds } else { 7091da177e4SLinus Torvalds str_append(&help, nohelp_text); 7101da177e4SLinus Torvalds } 7111da177e4SLinus Torvalds get_symbol_str(&help, sym); 7121da177e4SLinus Torvalds show_helptext(menu_get_prompt(menu), str_get(&help)); 7131da177e4SLinus Torvalds str_free(&help); 7141da177e4SLinus Torvalds } 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds static void conf_choice(struct menu *menu) 7171da177e4SLinus Torvalds { 7181da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 7191da177e4SLinus Torvalds struct menu *child; 7201da177e4SLinus Torvalds struct symbol *active; 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds active = sym_get_choice_value(menu->sym); 7231da177e4SLinus Torvalds while (1) { 7242982de69SSam Ravnborg int res; 7252982de69SSam Ravnborg int selected; 7262982de69SSam Ravnborg item_reset(); 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds current_menu = menu; 7291da177e4SLinus Torvalds for (child = menu->list; child; child = child->next) { 7301da177e4SLinus Torvalds if (!menu_is_visible(child)) 7311da177e4SLinus Torvalds continue; 7322982de69SSam Ravnborg item_make("%s", menu_get_prompt(child)); 7332982de69SSam Ravnborg item_set_data(child); 7342982de69SSam Ravnborg if (child->sym == active) 7352982de69SSam Ravnborg item_set_selected(1); 7361da177e4SLinus Torvalds if (child->sym == sym_get_choice_value(menu->sym)) 7372982de69SSam Ravnborg item_set_tag('X'); 7381da177e4SLinus Torvalds } 739e94c5bdeSSam Ravnborg dialog_clear(); 7402982de69SSam Ravnborg res = dialog_checklist(prompt ? prompt : _("Main Menu"), 7412982de69SSam Ravnborg _(radiolist_instructions), 7422982de69SSam Ravnborg 15, 70, 6); 7432982de69SSam Ravnborg selected = item_activate_selected(); 7442982de69SSam Ravnborg switch (res) { 7451da177e4SLinus Torvalds case 0: 7462982de69SSam Ravnborg if (selected) { 7472982de69SSam Ravnborg child = item_data(); 7481da177e4SLinus Torvalds sym_set_tristate_value(child->sym, yes); 7492982de69SSam Ravnborg } 7501da177e4SLinus Torvalds return; 7511da177e4SLinus Torvalds case 1: 7522982de69SSam Ravnborg if (selected) { 7532982de69SSam Ravnborg child = item_data(); 7541da177e4SLinus Torvalds show_help(child); 7551da177e4SLinus Torvalds active = child->sym; 7561da177e4SLinus Torvalds } else 7571da177e4SLinus Torvalds show_help(menu); 7581da177e4SLinus Torvalds break; 759f3cbcdc9SSam Ravnborg case KEY_ESC: 7601da177e4SLinus Torvalds return; 761c8dc68adSSam Ravnborg case -ERRDISPLAYTOOSMALL: 762c8dc68adSSam Ravnborg return; 7631da177e4SLinus Torvalds } 7641da177e4SLinus Torvalds } 7651da177e4SLinus Torvalds } 7661da177e4SLinus Torvalds 7671da177e4SLinus Torvalds static void conf_string(struct menu *menu) 7681da177e4SLinus Torvalds { 7691da177e4SLinus Torvalds const char *prompt = menu_get_prompt(menu); 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds while (1) { 7722982de69SSam Ravnborg int res; 7732982de69SSam Ravnborg char *heading; 7742982de69SSam Ravnborg 7751da177e4SLinus Torvalds switch (sym_get_type(menu->sym)) { 7761da177e4SLinus Torvalds case S_INT: 7772982de69SSam Ravnborg heading = _(inputbox_instructions_int); 7781da177e4SLinus Torvalds break; 7791da177e4SLinus Torvalds case S_HEX: 7802982de69SSam Ravnborg heading = _(inputbox_instructions_hex); 7811da177e4SLinus Torvalds break; 7821da177e4SLinus Torvalds case S_STRING: 7832982de69SSam Ravnborg heading = _(inputbox_instructions_string); 7841da177e4SLinus Torvalds break; 7851da177e4SLinus Torvalds default: 7862982de69SSam Ravnborg heading = "Internal mconf error!"; 7871da177e4SLinus Torvalds } 788e94c5bdeSSam Ravnborg dialog_clear(); 7892982de69SSam Ravnborg res = dialog_inputbox(prompt ? prompt : _("Main Menu"), 7902982de69SSam Ravnborg heading, 10, 75, 7912982de69SSam Ravnborg sym_get_string_value(menu->sym)); 7922982de69SSam Ravnborg switch (res) { 7931da177e4SLinus Torvalds case 0: 7942982de69SSam Ravnborg if (sym_set_string_value(menu->sym, dialog_input_result)) 7951da177e4SLinus Torvalds return; 7963b9fa093SArnaldo Carvalho de Melo show_textbox(NULL, _("You have made an invalid entry."), 5, 43); 7971da177e4SLinus Torvalds break; 7981da177e4SLinus Torvalds case 1: 7991da177e4SLinus Torvalds show_help(menu); 8001da177e4SLinus Torvalds break; 801f3cbcdc9SSam Ravnborg case KEY_ESC: 8021da177e4SLinus Torvalds return; 8031da177e4SLinus Torvalds } 8041da177e4SLinus Torvalds } 8051da177e4SLinus Torvalds } 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds static void conf_load(void) 8081da177e4SLinus Torvalds { 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds while (1) { 8112982de69SSam Ravnborg int res; 812e94c5bdeSSam Ravnborg dialog_clear(); 8132982de69SSam Ravnborg res = dialog_inputbox(NULL, load_config_text, 8142982de69SSam Ravnborg 11, 55, filename); 8152982de69SSam Ravnborg switch(res) { 8161da177e4SLinus Torvalds case 0: 8172982de69SSam Ravnborg if (!dialog_input_result[0]) 8181da177e4SLinus Torvalds return; 8192982de69SSam Ravnborg if (!conf_read(dialog_input_result)) 8201da177e4SLinus Torvalds return; 8213b9fa093SArnaldo Carvalho de Melo show_textbox(NULL, _("File does not exist!"), 5, 38); 8221da177e4SLinus Torvalds break; 8231da177e4SLinus Torvalds case 1: 8243b9fa093SArnaldo Carvalho de Melo show_helptext(_("Load Alternate Configuration"), load_config_help); 8251da177e4SLinus Torvalds break; 826f3cbcdc9SSam Ravnborg case KEY_ESC: 8271da177e4SLinus Torvalds return; 8281da177e4SLinus Torvalds } 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds } 8311da177e4SLinus Torvalds 8321da177e4SLinus Torvalds static void conf_save(void) 8331da177e4SLinus Torvalds { 8341da177e4SLinus Torvalds while (1) { 8352982de69SSam Ravnborg int res; 836e94c5bdeSSam Ravnborg dialog_clear(); 8372982de69SSam Ravnborg res = dialog_inputbox(NULL, save_config_text, 8382982de69SSam Ravnborg 11, 55, filename); 8392982de69SSam Ravnborg switch(res) { 8401da177e4SLinus Torvalds case 0: 8412982de69SSam Ravnborg if (!dialog_input_result[0]) 8421da177e4SLinus Torvalds return; 8432982de69SSam Ravnborg if (!conf_write(dialog_input_result)) 8441da177e4SLinus Torvalds return; 8453b9fa093SArnaldo Carvalho de Melo show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60); 8461da177e4SLinus Torvalds break; 8471da177e4SLinus Torvalds case 1: 8483b9fa093SArnaldo Carvalho de Melo show_helptext(_("Save Alternate Configuration"), save_config_help); 8491da177e4SLinus Torvalds break; 850f3cbcdc9SSam Ravnborg case KEY_ESC: 8511da177e4SLinus Torvalds return; 8521da177e4SLinus Torvalds } 8531da177e4SLinus Torvalds } 8541da177e4SLinus Torvalds } 8551da177e4SLinus Torvalds 8561da177e4SLinus Torvalds static void conf_cleanup(void) 8571da177e4SLinus Torvalds { 8581da177e4SLinus Torvalds tcsetattr(1, TCSAFLUSH, &ios_org); 8591da177e4SLinus Torvalds } 8601da177e4SLinus Torvalds 8611da177e4SLinus Torvalds int main(int ac, char **av) 8621da177e4SLinus Torvalds { 8631da177e4SLinus Torvalds struct symbol *sym; 8641da177e4SLinus Torvalds char *mode; 8652982de69SSam Ravnborg int res; 8661da177e4SLinus Torvalds 8673b9fa093SArnaldo Carvalho de Melo setlocale(LC_ALL, ""); 8683b9fa093SArnaldo Carvalho de Melo bindtextdomain(PACKAGE, LOCALEDIR); 8693b9fa093SArnaldo Carvalho de Melo textdomain(PACKAGE); 8703b9fa093SArnaldo Carvalho de Melo 8711da177e4SLinus Torvalds conf_parse(av[1]); 8721da177e4SLinus Torvalds conf_read(NULL); 8731da177e4SLinus Torvalds 8742244cbd8SSam Ravnborg sym = sym_lookup("KERNELVERSION", 0); 8751da177e4SLinus Torvalds sym_calc_value(sym); 8763b9fa093SArnaldo Carvalho de Melo sprintf(menu_backtitle, _("Linux Kernel v%s Configuration"), 8771da177e4SLinus Torvalds sym_get_string_value(sym)); 8781da177e4SLinus Torvalds 8791da177e4SLinus Torvalds mode = getenv("MENUCONFIG_MODE"); 8801da177e4SLinus Torvalds if (mode) { 8811da177e4SLinus Torvalds if (!strcasecmp(mode, "single_menu")) 8821da177e4SLinus Torvalds single_menu_mode = 1; 8831da177e4SLinus Torvalds } 8841da177e4SLinus Torvalds 8851da177e4SLinus Torvalds tcgetattr(1, &ios_org); 8861da177e4SLinus Torvalds atexit(conf_cleanup); 8871da177e4SLinus Torvalds init_wsize(); 8882982de69SSam Ravnborg reset_dialog(); 8892982de69SSam Ravnborg init_dialog(menu_backtitle); 890f3cbcdc9SSam Ravnborg do { 8911da177e4SLinus Torvalds conf(&rootmenu); 892e94c5bdeSSam Ravnborg dialog_clear(); 893b3214293SKarsten Wiese if (conf_get_changed()) 8942982de69SSam Ravnborg res = dialog_yesno(NULL, 8952982de69SSam Ravnborg _("Do you wish to save your " 896f3cbcdc9SSam Ravnborg "new kernel configuration?\n" 897f3cbcdc9SSam Ravnborg "<ESC><ESC> to continue."), 898f3cbcdc9SSam Ravnborg 6, 60); 899b3214293SKarsten Wiese else 900b3214293SKarsten Wiese res = -1; 901f3cbcdc9SSam Ravnborg } while (res == KEY_ESC); 9022982de69SSam Ravnborg end_dialog(); 903b3214293SKarsten Wiese 904b3214293SKarsten Wiese switch (res) { 905b3214293SKarsten Wiese case 0: 9061da177e4SLinus Torvalds if (conf_write(NULL)) { 9073b9fa093SArnaldo Carvalho de Melo fprintf(stderr, _("\n\n" 9081da177e4SLinus Torvalds "Error during writing of the kernel configuration.\n" 9091da177e4SLinus Torvalds "Your kernel configuration changes were NOT saved." 9103b9fa093SArnaldo Carvalho de Melo "\n\n")); 9111da177e4SLinus Torvalds return 1; 9121da177e4SLinus Torvalds } 913b3214293SKarsten Wiese case -1: 9143b9fa093SArnaldo Carvalho de Melo printf(_("\n\n" 9151da177e4SLinus Torvalds "*** End of Linux kernel configuration.\n" 9161da177e4SLinus Torvalds "*** Execute 'make' to build the kernel or try 'make help'." 9173b9fa093SArnaldo Carvalho de Melo "\n\n")); 918b3214293SKarsten Wiese break; 919b3214293SKarsten Wiese default: 9203b9fa093SArnaldo Carvalho de Melo fprintf(stderr, _("\n\n" 9211da177e4SLinus Torvalds "Your kernel configuration changes were NOT saved." 9223b9fa093SArnaldo Carvalho de Melo "\n\n")); 9231da177e4SLinus Torvalds } 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds return 0; 9261da177e4SLinus Torvalds } 927