15257cf54a5810105bc4a75703a06740d756d8e8landley/*
25257cf54a5810105bc4a75703a06740d756d8e8landley * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
35257cf54a5810105bc4a75703a06740d756d8e8landley * Released under the terms of the GNU GPL v2.0.
45257cf54a5810105bc4a75703a06740d756d8e8landley *
55257cf54a5810105bc4a75703a06740d756d8e8landley * Introduced single menu mode (show all sub-menus in one large tree).
65257cf54a5810105bc4a75703a06740d756d8e8landley * 2002-11-06 Petr Baudis <pasky@ucw.cz>
75257cf54a5810105bc4a75703a06740d756d8e8landley *
85257cf54a5810105bc4a75703a06740d756d8e8landley * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
95257cf54a5810105bc4a75703a06740d756d8e8landley */
105257cf54a5810105bc4a75703a06740d756d8e8landley
115257cf54a5810105bc4a75703a06740d756d8e8landley#include <sys/ioctl.h>
125257cf54a5810105bc4a75703a06740d756d8e8landley#include <sys/wait.h>
135257cf54a5810105bc4a75703a06740d756d8e8landley#include <ctype.h>
145257cf54a5810105bc4a75703a06740d756d8e8landley#include <errno.h>
155257cf54a5810105bc4a75703a06740d756d8e8landley#include <fcntl.h>
165257cf54a5810105bc4a75703a06740d756d8e8landley#include <limits.h>
175257cf54a5810105bc4a75703a06740d756d8e8landley#include <signal.h>
185257cf54a5810105bc4a75703a06740d756d8e8landley#include <stdarg.h>
195257cf54a5810105bc4a75703a06740d756d8e8landley#include <stdlib.h>
205257cf54a5810105bc4a75703a06740d756d8e8landley#include <string.h>
215257cf54a5810105bc4a75703a06740d756d8e8landley#include <termios.h>
225257cf54a5810105bc4a75703a06740d756d8e8landley#include <unistd.h>
235257cf54a5810105bc4a75703a06740d756d8e8landley#include <locale.h>
245257cf54a5810105bc4a75703a06740d756d8e8landley
255257cf54a5810105bc4a75703a06740d756d8e8landley#define LKC_DIRECT_LINK
265257cf54a5810105bc4a75703a06740d756d8e8landley#include "lkc.h"
275257cf54a5810105bc4a75703a06740d756d8e8landley#include "lxdialog/dialog.h"
285257cf54a5810105bc4a75703a06740d756d8e8landley
295257cf54a5810105bc4a75703a06740d756d8e8landleystatic char menu_backtitle[128];
305257cf54a5810105bc4a75703a06740d756d8e8landleystatic const char mconf_readme[] = N_(
315257cf54a5810105bc4a75703a06740d756d8e8landley"Overview\n"
325257cf54a5810105bc4a75703a06740d756d8e8landley"--------\n"
33d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley"Some features may be built directly into the project.\n"
345257cf54a5810105bc4a75703a06740d756d8e8landley"Some may be made into loadable runtime modules.  Some features\n"
355257cf54a5810105bc4a75703a06740d756d8e8landley"may be completely removed altogether.  There are also certain\n"
36d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley"parameters which are not really features, but must be\n"
375257cf54a5810105bc4a75703a06740d756d8e8landley"entered in as decimal or hexadecimal numbers or possibly text.\n"
385257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
395257cf54a5810105bc4a75703a06740d756d8e8landley"Menu items beginning with [*], <M> or [ ] represent features\n"
405257cf54a5810105bc4a75703a06740d756d8e8landley"configured to be built in, modularized or removed respectively.\n"
415257cf54a5810105bc4a75703a06740d756d8e8landley"Pointed brackets <> represent module capable features.\n"
425257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
435257cf54a5810105bc4a75703a06740d756d8e8landley"To change any of these features, highlight it with the cursor\n"
445257cf54a5810105bc4a75703a06740d756d8e8landley"keys and press <Y> to build it in, <M> to make it a module or\n"
455257cf54a5810105bc4a75703a06740d756d8e8landley"<N> to removed it.  You may also press the <Space Bar> to cycle\n"
465257cf54a5810105bc4a75703a06740d756d8e8landley"through the available options (ie. Y->N->M->Y).\n"
475257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
485257cf54a5810105bc4a75703a06740d756d8e8landley"Some additional keyboard hints:\n"
495257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
505257cf54a5810105bc4a75703a06740d756d8e8landley"Menus\n"
515257cf54a5810105bc4a75703a06740d756d8e8landley"----------\n"
525257cf54a5810105bc4a75703a06740d756d8e8landley"o  Use the Up/Down arrow keys (cursor keys) to highlight the item\n"
535257cf54a5810105bc4a75703a06740d756d8e8landley"   you wish to change or submenu wish to select and press <Enter>.\n"
545257cf54a5810105bc4a75703a06740d756d8e8landley"   Submenus are designated by \"--->\".\n"
555257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
565257cf54a5810105bc4a75703a06740d756d8e8landley"   Shortcut: Press the option's highlighted letter (hotkey).\n"
575257cf54a5810105bc4a75703a06740d756d8e8landley"             Pressing a hotkey more than once will sequence\n"
585257cf54a5810105bc4a75703a06740d756d8e8landley"             through all visible items which use that hotkey.\n"
595257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
605257cf54a5810105bc4a75703a06740d756d8e8landley"   You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n"
615257cf54a5810105bc4a75703a06740d756d8e8landley"   unseen options into view.\n"
625257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
635257cf54a5810105bc4a75703a06740d756d8e8landley"o  To exit a menu use the cursor keys to highlight the <Exit> button\n"
645257cf54a5810105bc4a75703a06740d756d8e8landley"   and press <ENTER>.\n"
655257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
665257cf54a5810105bc4a75703a06740d756d8e8landley"   Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n"
675257cf54a5810105bc4a75703a06740d756d8e8landley"             using those letters.  You may press a single <ESC>, but\n"
685257cf54a5810105bc4a75703a06740d756d8e8landley"             there is a delayed response which you may find annoying.\n"
695257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
705257cf54a5810105bc4a75703a06740d756d8e8landley"   Also, the <TAB> and cursor keys will cycle between <Select>,\n"
715257cf54a5810105bc4a75703a06740d756d8e8landley"   <Exit> and <Help>\n"
725257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
735257cf54a5810105bc4a75703a06740d756d8e8landley"o  To get help with an item, use the cursor keys to highlight <Help>\n"
745257cf54a5810105bc4a75703a06740d756d8e8landley"   and Press <ENTER>.\n"
755257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
765257cf54a5810105bc4a75703a06740d756d8e8landley"   Shortcut: Press <H> or <?>.\n"
775257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
785257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
795257cf54a5810105bc4a75703a06740d756d8e8landley"Radiolists  (Choice lists)\n"
805257cf54a5810105bc4a75703a06740d756d8e8landley"-----------\n"
815257cf54a5810105bc4a75703a06740d756d8e8landley"o  Use the cursor keys to select the option you wish to set and press\n"
825257cf54a5810105bc4a75703a06740d756d8e8landley"   <S> or the <SPACE BAR>.\n"
835257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
845257cf54a5810105bc4a75703a06740d756d8e8landley"   Shortcut: Press the first letter of the option you wish to set then\n"
855257cf54a5810105bc4a75703a06740d756d8e8landley"             press <S> or <SPACE BAR>.\n"
865257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
875257cf54a5810105bc4a75703a06740d756d8e8landley"o  To see available help for the item, use the cursor keys to highlight\n"
885257cf54a5810105bc4a75703a06740d756d8e8landley"   <Help> and Press <ENTER>.\n"
895257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
905257cf54a5810105bc4a75703a06740d756d8e8landley"   Shortcut: Press <H> or <?>.\n"
915257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
925257cf54a5810105bc4a75703a06740d756d8e8landley"   Also, the <TAB> and cursor keys will cycle between <Select> and\n"
935257cf54a5810105bc4a75703a06740d756d8e8landley"   <Help>\n"
945257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
955257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
965257cf54a5810105bc4a75703a06740d756d8e8landley"Data Entry\n"
975257cf54a5810105bc4a75703a06740d756d8e8landley"-----------\n"
985257cf54a5810105bc4a75703a06740d756d8e8landley"o  Enter the requested information and press <ENTER>\n"
995257cf54a5810105bc4a75703a06740d756d8e8landley"   If you are entering hexadecimal values, it is not necessary to\n"
1005257cf54a5810105bc4a75703a06740d756d8e8landley"   add the '0x' prefix to the entry.\n"
1015257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1025257cf54a5810105bc4a75703a06740d756d8e8landley"o  For help, use the <TAB> or cursor keys to highlight the help option\n"
1035257cf54a5810105bc4a75703a06740d756d8e8landley"   and press <ENTER>.  You can try <TAB><H> as well.\n"
1045257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1055257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1065257cf54a5810105bc4a75703a06740d756d8e8landley"Text Box    (Help Window)\n"
1075257cf54a5810105bc4a75703a06740d756d8e8landley"--------\n"
1085257cf54a5810105bc4a75703a06740d756d8e8landley"o  Use the cursor keys to scroll up/down/left/right.  The VI editor\n"
1095257cf54a5810105bc4a75703a06740d756d8e8landley"   keys h,j,k,l function here as do <SPACE BAR> and <B> for those\n"
1105257cf54a5810105bc4a75703a06740d756d8e8landley"   who are familiar with less and lynx.\n"
1115257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1125257cf54a5810105bc4a75703a06740d756d8e8landley"o  Press <E>, <X>, <Enter> or <Esc><Esc> to exit.\n"
1135257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1145257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1155257cf54a5810105bc4a75703a06740d756d8e8landley"Alternate Configuration Files\n"
1165257cf54a5810105bc4a75703a06740d756d8e8landley"-----------------------------\n"
1175257cf54a5810105bc4a75703a06740d756d8e8landley"Menuconfig supports the use of alternate configuration files for\n"
1185257cf54a5810105bc4a75703a06740d756d8e8landley"those who, for various reasons, find it necessary to switch\n"
119d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley"between different configurations.\n"
1205257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1215257cf54a5810105bc4a75703a06740d756d8e8landley"At the end of the main menu you will find two options.  One is\n"
1225257cf54a5810105bc4a75703a06740d756d8e8landley"for saving the current configuration to a file of your choosing.\n"
1235257cf54a5810105bc4a75703a06740d756d8e8landley"The other option is for loading a previously saved alternate\n"
1245257cf54a5810105bc4a75703a06740d756d8e8landley"configuration.\n"
1255257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1265257cf54a5810105bc4a75703a06740d756d8e8landley"Even if you don't use alternate configuration files, but you\n"
1275257cf54a5810105bc4a75703a06740d756d8e8landley"find during a Menuconfig session that you have completely messed\n"
1285257cf54a5810105bc4a75703a06740d756d8e8landley"up your settings, you may use the \"Load Alternate...\" option to\n"
1295257cf54a5810105bc4a75703a06740d756d8e8landley"restore your previously saved settings from \".config\" without\n"
1305257cf54a5810105bc4a75703a06740d756d8e8landley"restarting Menuconfig.\n"
1315257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1325257cf54a5810105bc4a75703a06740d756d8e8landley"Other information\n"
1335257cf54a5810105bc4a75703a06740d756d8e8landley"-----------------\n"
1345257cf54a5810105bc4a75703a06740d756d8e8landley"If you use Menuconfig in an XTERM window make sure you have your\n"
1355257cf54a5810105bc4a75703a06740d756d8e8landley"$TERM variable set to point to a xterm definition which supports color.\n"
1365257cf54a5810105bc4a75703a06740d756d8e8landley"Otherwise, Menuconfig will look rather bad.  Menuconfig will not\n"
1375257cf54a5810105bc4a75703a06740d756d8e8landley"display correctly in a RXVT window because rxvt displays only one\n"
1385257cf54a5810105bc4a75703a06740d756d8e8landley"intensity of color, bright.\n"
1395257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1405257cf54a5810105bc4a75703a06740d756d8e8landley"Menuconfig will display larger menus on screens or xterms which are\n"
1415257cf54a5810105bc4a75703a06740d756d8e8landley"set to display more than the standard 25 row by 80 column geometry.\n"
1425257cf54a5810105bc4a75703a06740d756d8e8landley"In order for this to work, the \"stty size\" command must be able to\n"
1435257cf54a5810105bc4a75703a06740d756d8e8landley"display the screen's current row and column geometry.  I STRONGLY\n"
1445257cf54a5810105bc4a75703a06740d756d8e8landley"RECOMMEND that you make sure you do NOT have the shell variables\n"
1455257cf54a5810105bc4a75703a06740d756d8e8landley"LINES and COLUMNS exported into your environment.  Some distributions\n"
1465257cf54a5810105bc4a75703a06740d756d8e8landley"export those variables via /etc/profile.  Some ncurses programs can\n"
1475257cf54a5810105bc4a75703a06740d756d8e8landley"become confused when those variables (LINES & COLUMNS) don't reflect\n"
1485257cf54a5810105bc4a75703a06740d756d8e8landley"the true screen size.\n"
1495257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1505257cf54a5810105bc4a75703a06740d756d8e8landley"Optional personality available\n"
1515257cf54a5810105bc4a75703a06740d756d8e8landley"------------------------------\n"
152d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley"If you prefer to have all of the options listed in a single\n"
1535257cf54a5810105bc4a75703a06740d756d8e8landley"menu, rather than the default multimenu hierarchy, run the menuconfig\n"
1545257cf54a5810105bc4a75703a06740d756d8e8landley"with MENUCONFIG_MODE environment variable set to single_menu. Example:\n"
1555257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1565257cf54a5810105bc4a75703a06740d756d8e8landley"make MENUCONFIG_MODE=single_menu menuconfig\n"
1575257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1585257cf54a5810105bc4a75703a06740d756d8e8landley"<Enter> will then unroll the appropriate category, or enfold it if it\n"
1595257cf54a5810105bc4a75703a06740d756d8e8landley"is already unrolled.\n"
1605257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1615257cf54a5810105bc4a75703a06740d756d8e8landley"Note that this mode can eventually be a little more CPU expensive\n"
1625257cf54a5810105bc4a75703a06740d756d8e8landley"(especially with a larger number of unrolled categories) than the\n"
1635257cf54a5810105bc4a75703a06740d756d8e8landley"default mode.\n"
1645257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1655257cf54a5810105bc4a75703a06740d756d8e8landley"Different color themes available\n"
1665257cf54a5810105bc4a75703a06740d756d8e8landley"--------------------------------\n"
1675257cf54a5810105bc4a75703a06740d756d8e8landley"It is possible to select different color themes using the variable\n"
1685257cf54a5810105bc4a75703a06740d756d8e8landley"MENUCONFIG_COLOR. To select a theme use:\n"
1695257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1705257cf54a5810105bc4a75703a06740d756d8e8landley"make MENUCONFIG_COLOR=<theme> menuconfig\n"
1715257cf54a5810105bc4a75703a06740d756d8e8landley"\n"
1725257cf54a5810105bc4a75703a06740d756d8e8landley"Available themes are\n"
1735257cf54a5810105bc4a75703a06740d756d8e8landley" mono       => selects colors suitable for monochrome displays\n"
1745257cf54a5810105bc4a75703a06740d756d8e8landley" blackbg    => selects a color scheme with black background\n"
1755257cf54a5810105bc4a75703a06740d756d8e8landley" classic    => theme with blue background. The classic look\n"
1765257cf54a5810105bc4a75703a06740d756d8e8landley" bluetitle  => a LCD friendly version of classic. (default)\n"
1775257cf54a5810105bc4a75703a06740d756d8e8landley"\n"),
1785257cf54a5810105bc4a75703a06740d756d8e8landleymenu_instructions[] = N_(
1795257cf54a5810105bc4a75703a06740d756d8e8landley	"Arrow keys navigate the menu.  "
1805257cf54a5810105bc4a75703a06740d756d8e8landley	"<Enter> selects submenus --->.  "
1815257cf54a5810105bc4a75703a06740d756d8e8landley	"Highlighted letters are hotkeys.  "
1825257cf54a5810105bc4a75703a06740d756d8e8landley	"Pressing <Y> includes, <N> excludes, <M> modularizes features.  "
1835257cf54a5810105bc4a75703a06740d756d8e8landley	"Press <Esc><Esc> to exit, <?> for Help, </> for Search.  "
1845257cf54a5810105bc4a75703a06740d756d8e8landley	"Legend: [*] built-in  [ ] excluded  <M> module  < > module capable"),
1855257cf54a5810105bc4a75703a06740d756d8e8landleyradiolist_instructions[] = N_(
1865257cf54a5810105bc4a75703a06740d756d8e8landley	"Use the arrow keys to navigate this window or "
1875257cf54a5810105bc4a75703a06740d756d8e8landley	"press the hotkey of the item you wish to select "
1885257cf54a5810105bc4a75703a06740d756d8e8landley	"followed by the <SPACE BAR>. "
1895257cf54a5810105bc4a75703a06740d756d8e8landley	"Press <?> for additional information about this option."),
1905257cf54a5810105bc4a75703a06740d756d8e8landleyinputbox_instructions_int[] = N_(
1915257cf54a5810105bc4a75703a06740d756d8e8landley	"Please enter a decimal value. "
1925257cf54a5810105bc4a75703a06740d756d8e8landley	"Fractions will not be accepted.  "
1935257cf54a5810105bc4a75703a06740d756d8e8landley	"Use the <TAB> key to move from the input field to the buttons below it."),
1945257cf54a5810105bc4a75703a06740d756d8e8landleyinputbox_instructions_hex[] = N_(
1955257cf54a5810105bc4a75703a06740d756d8e8landley	"Please enter a hexadecimal value. "
1965257cf54a5810105bc4a75703a06740d756d8e8landley	"Use the <TAB> key to move from the input field to the buttons below it."),
1975257cf54a5810105bc4a75703a06740d756d8e8landleyinputbox_instructions_string[] = N_(
1985257cf54a5810105bc4a75703a06740d756d8e8landley	"Please enter a string value. "
1995257cf54a5810105bc4a75703a06740d756d8e8landley	"Use the <TAB> key to move from the input field to the buttons below it."),
2005257cf54a5810105bc4a75703a06740d756d8e8landleysetmod_text[] = N_(
2015257cf54a5810105bc4a75703a06740d756d8e8landley	"This feature depends on another which has been configured as a module.\n"
2025257cf54a5810105bc4a75703a06740d756d8e8landley	"As a result, this feature will be built as a module."),
2035257cf54a5810105bc4a75703a06740d756d8e8landleynohelp_text[] = N_(
204d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley	"There is no help available for this option.\n"),
2055257cf54a5810105bc4a75703a06740d756d8e8landleyload_config_text[] = N_(
2065257cf54a5810105bc4a75703a06740d756d8e8landley	"Enter the name of the configuration file you wish to load.  "
2075257cf54a5810105bc4a75703a06740d756d8e8landley	"Accept the name shown to restore the configuration you "
2085257cf54a5810105bc4a75703a06740d756d8e8landley	"last retrieved.  Leave blank to abort."),
2095257cf54a5810105bc4a75703a06740d756d8e8landleyload_config_help[] = N_(
2105257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
211d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley	"For various reasons, one may wish to keep several different\n"
2125257cf54a5810105bc4a75703a06740d756d8e8landley	"configurations available on a single machine.\n"
2135257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
2145257cf54a5810105bc4a75703a06740d756d8e8landley	"If you have saved a previous configuration in a file other than the\n"
215d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley	"default, entering the name of the file here will allow you\n"
2165257cf54a5810105bc4a75703a06740d756d8e8landley	"to modify that configuration.\n"
2175257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
2185257cf54a5810105bc4a75703a06740d756d8e8landley	"If you are uncertain, then you have probably never used alternate\n"
2195257cf54a5810105bc4a75703a06740d756d8e8landley	"configuration files.  You should therefor leave this blank to abort.\n"),
2205257cf54a5810105bc4a75703a06740d756d8e8landleysave_config_text[] = N_(
2215257cf54a5810105bc4a75703a06740d756d8e8landley	"Enter a filename to which this configuration should be saved "
2225257cf54a5810105bc4a75703a06740d756d8e8landley	"as an alternate.  Leave blank to abort."),
2235257cf54a5810105bc4a75703a06740d756d8e8landleysave_config_help[] = N_(
2245257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
225d1ed4c625df616b845077ca1670a44e2ec66161fRob Landley	"For various reasons, one may wish to keep different\n"
2265257cf54a5810105bc4a75703a06740d756d8e8landley	"configurations available on a single machine.\n"
2275257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
2285257cf54a5810105bc4a75703a06740d756d8e8landley	"Entering a file name here will allow you to later retrieve, modify\n"
2295257cf54a5810105bc4a75703a06740d756d8e8landley	"and use the current configuration as an alternate to whatever\n"
2305257cf54a5810105bc4a75703a06740d756d8e8landley	"configuration options you have selected at that time.\n"
2315257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
2325257cf54a5810105bc4a75703a06740d756d8e8landley	"If you are uncertain what all this means then you should probably\n"
2335257cf54a5810105bc4a75703a06740d756d8e8landley	"leave this blank.\n"),
2345257cf54a5810105bc4a75703a06740d756d8e8landleysearch_help[] = N_(
2355257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
2365257cf54a5810105bc4a75703a06740d756d8e8landley	"Search for CONFIG_ symbols and display their relations.\n"
2375257cf54a5810105bc4a75703a06740d756d8e8landley	"Regular expressions are allowed.\n"
2385257cf54a5810105bc4a75703a06740d756d8e8landley	"Example: search for \"^FOO\"\n"
2395257cf54a5810105bc4a75703a06740d756d8e8landley	"Result:\n"
2405257cf54a5810105bc4a75703a06740d756d8e8landley	"-----------------------------------------------------------------\n"
2415257cf54a5810105bc4a75703a06740d756d8e8landley	"Symbol: FOO [=m]\n"
2425257cf54a5810105bc4a75703a06740d756d8e8landley	"Prompt: Foo bus is used to drive the bar HW\n"
2435257cf54a5810105bc4a75703a06740d756d8e8landley	"Defined at drivers/pci/Kconfig:47\n"
2445257cf54a5810105bc4a75703a06740d756d8e8landley	"Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
2455257cf54a5810105bc4a75703a06740d756d8e8landley	"Location:\n"
2465257cf54a5810105bc4a75703a06740d756d8e8landley	"  -> Bus options (PCI, PCMCIA, EISA, MCA, ISA)\n"
2475257cf54a5810105bc4a75703a06740d756d8e8landley	"    -> PCI support (PCI [=y])\n"
2485257cf54a5810105bc4a75703a06740d756d8e8landley	"      -> PCI access mode (<choice> [=y])\n"
2495257cf54a5810105bc4a75703a06740d756d8e8landley	"Selects: LIBCRC32\n"
2505257cf54a5810105bc4a75703a06740d756d8e8landley	"Selected by: BAR\n"
2515257cf54a5810105bc4a75703a06740d756d8e8landley	"-----------------------------------------------------------------\n"
2525257cf54a5810105bc4a75703a06740d756d8e8landley	"o The line 'Prompt:' shows the text used in the menu structure for\n"
2535257cf54a5810105bc4a75703a06740d756d8e8landley	"  this CONFIG_ symbol\n"
2545257cf54a5810105bc4a75703a06740d756d8e8landley	"o The 'Defined at' line tell at what file / line number the symbol\n"
2555257cf54a5810105bc4a75703a06740d756d8e8landley	"  is defined\n"
2565257cf54a5810105bc4a75703a06740d756d8e8landley	"o The 'Depends on:' line tell what symbols needs to be defined for\n"
2575257cf54a5810105bc4a75703a06740d756d8e8landley	"  this symbol to be visible in the menu (selectable)\n"
2585257cf54a5810105bc4a75703a06740d756d8e8landley	"o The 'Location:' lines tell where in the menu structure this symbol\n"
2595257cf54a5810105bc4a75703a06740d756d8e8landley	"  is located\n"
2605257cf54a5810105bc4a75703a06740d756d8e8landley	"    A location followed by a [=y] indicate that this is a selectable\n"
2615257cf54a5810105bc4a75703a06740d756d8e8landley	"    menu item - and current value is displayed inside brackets.\n"
2625257cf54a5810105bc4a75703a06740d756d8e8landley	"o The 'Selects:' line tell what symbol will be automatically\n"
2635257cf54a5810105bc4a75703a06740d756d8e8landley	"  selected if this symbol is selected (y or m)\n"
2645257cf54a5810105bc4a75703a06740d756d8e8landley	"o The 'Selected by' line tell what symbol has selected this symbol\n"
2655257cf54a5810105bc4a75703a06740d756d8e8landley	"\n"
2665257cf54a5810105bc4a75703a06740d756d8e8landley	"Only relevant lines are shown.\n"
2675257cf54a5810105bc4a75703a06740d756d8e8landley	"\n\n"
2685257cf54a5810105bc4a75703a06740d756d8e8landley	"Search examples:\n"
2695257cf54a5810105bc4a75703a06740d756d8e8landley	"Examples: USB	=> find all CONFIG_ symbols containing USB\n"
2705257cf54a5810105bc4a75703a06740d756d8e8landley	"          ^USB => find all CONFIG_ symbols starting with USB\n"
2715257cf54a5810105bc4a75703a06740d756d8e8landley	"          USB$ => find all CONFIG_ symbols ending with USB\n"
2725257cf54a5810105bc4a75703a06740d756d8e8landley	"\n");
2735257cf54a5810105bc4a75703a06740d756d8e8landley
2745257cf54a5810105bc4a75703a06740d756d8e8landleystatic char filename[PATH_MAX+1] = ".config";
2755257cf54a5810105bc4a75703a06740d756d8e8landleystatic int indent;
2765257cf54a5810105bc4a75703a06740d756d8e8landleystatic struct termios ios_org;
2775257cf54a5810105bc4a75703a06740d756d8e8landleystatic int rows = 0, cols = 0;
2785257cf54a5810105bc4a75703a06740d756d8e8landleystatic struct menu *current_menu;
2795257cf54a5810105bc4a75703a06740d756d8e8landleystatic int child_count;
2805257cf54a5810105bc4a75703a06740d756d8e8landleystatic int single_menu_mode;
2815257cf54a5810105bc4a75703a06740d756d8e8landley
2825257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf(struct menu *menu);
2835257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_choice(struct menu *menu);
2845257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_string(struct menu *menu);
2855257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_load(void);
2865257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_save(void);
2875257cf54a5810105bc4a75703a06740d756d8e8landleystatic void show_textbox(const char *title, const char *text, int r, int c);
2885257cf54a5810105bc4a75703a06740d756d8e8landleystatic void show_helptext(const char *title, const char *text);
2895257cf54a5810105bc4a75703a06740d756d8e8landleystatic void show_help(struct menu *menu);
2905257cf54a5810105bc4a75703a06740d756d8e8landley
2915257cf54a5810105bc4a75703a06740d756d8e8landleystatic void init_wsize(void)
2925257cf54a5810105bc4a75703a06740d756d8e8landley{
2935257cf54a5810105bc4a75703a06740d756d8e8landley	struct winsize ws;
2945257cf54a5810105bc4a75703a06740d756d8e8landley	char *env;
2955257cf54a5810105bc4a75703a06740d756d8e8landley
2965257cf54a5810105bc4a75703a06740d756d8e8landley	if (!ioctl(STDIN_FILENO, TIOCGWINSZ, &ws)) {
2975257cf54a5810105bc4a75703a06740d756d8e8landley		rows = ws.ws_row;
2985257cf54a5810105bc4a75703a06740d756d8e8landley		cols = ws.ws_col;
2995257cf54a5810105bc4a75703a06740d756d8e8landley	}
3005257cf54a5810105bc4a75703a06740d756d8e8landley
3015257cf54a5810105bc4a75703a06740d756d8e8landley	if (!rows) {
3025257cf54a5810105bc4a75703a06740d756d8e8landley		env = getenv("LINES");
3035257cf54a5810105bc4a75703a06740d756d8e8landley		if (env)
3045257cf54a5810105bc4a75703a06740d756d8e8landley			rows = atoi(env);
3055257cf54a5810105bc4a75703a06740d756d8e8landley		if (!rows)
3065257cf54a5810105bc4a75703a06740d756d8e8landley			rows = 24;
3075257cf54a5810105bc4a75703a06740d756d8e8landley	}
3085257cf54a5810105bc4a75703a06740d756d8e8landley	if (!cols) {
3095257cf54a5810105bc4a75703a06740d756d8e8landley		env = getenv("COLUMNS");
3105257cf54a5810105bc4a75703a06740d756d8e8landley		if (env)
3115257cf54a5810105bc4a75703a06740d756d8e8landley			cols = atoi(env);
3125257cf54a5810105bc4a75703a06740d756d8e8landley		if (!cols)
3135257cf54a5810105bc4a75703a06740d756d8e8landley			cols = 80;
3145257cf54a5810105bc4a75703a06740d756d8e8landley	}
3155257cf54a5810105bc4a75703a06740d756d8e8landley
3165257cf54a5810105bc4a75703a06740d756d8e8landley	if (rows < 19 || cols < 80) {
3175257cf54a5810105bc4a75703a06740d756d8e8landley		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
3185257cf54a5810105bc4a75703a06740d756d8e8landley		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
3195257cf54a5810105bc4a75703a06740d756d8e8landley		exit(1);
3205257cf54a5810105bc4a75703a06740d756d8e8landley	}
3215257cf54a5810105bc4a75703a06740d756d8e8landley
3225257cf54a5810105bc4a75703a06740d756d8e8landley	rows -= 4;
3235257cf54a5810105bc4a75703a06740d756d8e8landley	cols -= 5;
3245257cf54a5810105bc4a75703a06740d756d8e8landley}
3255257cf54a5810105bc4a75703a06740d756d8e8landley
3265257cf54a5810105bc4a75703a06740d756d8e8landleystatic void get_prompt_str(struct gstr *r, struct property *prop)
3275257cf54a5810105bc4a75703a06740d756d8e8landley{
3285257cf54a5810105bc4a75703a06740d756d8e8landley	int i, j;
3295257cf54a5810105bc4a75703a06740d756d8e8landley	struct menu *submenu[8], *menu;
3305257cf54a5810105bc4a75703a06740d756d8e8landley
3315257cf54a5810105bc4a75703a06740d756d8e8landley	str_printf(r, "Prompt: %s\n", prop->text);
3325257cf54a5810105bc4a75703a06740d756d8e8landley	str_printf(r, "  Defined at %s:%d\n", prop->menu->file->name,
3335257cf54a5810105bc4a75703a06740d756d8e8landley		prop->menu->lineno);
3345257cf54a5810105bc4a75703a06740d756d8e8landley	if (!expr_is_yes(prop->visible.expr)) {
3355257cf54a5810105bc4a75703a06740d756d8e8landley		str_append(r, "  Depends on: ");
3365257cf54a5810105bc4a75703a06740d756d8e8landley		expr_gstr_print(prop->visible.expr, r);
3375257cf54a5810105bc4a75703a06740d756d8e8landley		str_append(r, "\n");
3385257cf54a5810105bc4a75703a06740d756d8e8landley	}
3395257cf54a5810105bc4a75703a06740d756d8e8landley	menu = prop->menu->parent;
3405257cf54a5810105bc4a75703a06740d756d8e8landley	for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent)
3415257cf54a5810105bc4a75703a06740d756d8e8landley		submenu[i++] = menu;
3425257cf54a5810105bc4a75703a06740d756d8e8landley	if (i > 0) {
3435257cf54a5810105bc4a75703a06740d756d8e8landley		str_printf(r, "  Location:\n");
3445257cf54a5810105bc4a75703a06740d756d8e8landley		for (j = 4; --i >= 0; j += 2) {
3455257cf54a5810105bc4a75703a06740d756d8e8landley			menu = submenu[i];
3465257cf54a5810105bc4a75703a06740d756d8e8landley			str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu));
3475257cf54a5810105bc4a75703a06740d756d8e8landley			if (menu->sym) {
3485257cf54a5810105bc4a75703a06740d756d8e8landley				str_printf(r, " (%s [=%s])", menu->sym->name ?
3495257cf54a5810105bc4a75703a06740d756d8e8landley					menu->sym->name : "<choice>",
3505257cf54a5810105bc4a75703a06740d756d8e8landley					sym_get_string_value(menu->sym));
3515257cf54a5810105bc4a75703a06740d756d8e8landley			}
3525257cf54a5810105bc4a75703a06740d756d8e8landley			str_append(r, "\n");
3535257cf54a5810105bc4a75703a06740d756d8e8landley		}
3545257cf54a5810105bc4a75703a06740d756d8e8landley	}
3555257cf54a5810105bc4a75703a06740d756d8e8landley}
3565257cf54a5810105bc4a75703a06740d756d8e8landley
3575257cf54a5810105bc4a75703a06740d756d8e8landleystatic void get_symbol_str(struct gstr *r, struct symbol *sym)
3585257cf54a5810105bc4a75703a06740d756d8e8landley{
3595257cf54a5810105bc4a75703a06740d756d8e8landley	bool hit;
3605257cf54a5810105bc4a75703a06740d756d8e8landley	struct property *prop;
3615257cf54a5810105bc4a75703a06740d756d8e8landley
3625257cf54a5810105bc4a75703a06740d756d8e8landley	str_printf(r, "Symbol: %s [=%s]\n", sym->name,
3635257cf54a5810105bc4a75703a06740d756d8e8landley	                               sym_get_string_value(sym));
3645257cf54a5810105bc4a75703a06740d756d8e8landley	for_all_prompts(sym, prop)
3655257cf54a5810105bc4a75703a06740d756d8e8landley		get_prompt_str(r, prop);
3665257cf54a5810105bc4a75703a06740d756d8e8landley	hit = false;
3675257cf54a5810105bc4a75703a06740d756d8e8landley	for_all_properties(sym, prop, P_SELECT) {
3685257cf54a5810105bc4a75703a06740d756d8e8landley		if (!hit) {
3695257cf54a5810105bc4a75703a06740d756d8e8landley			str_append(r, "  Selects: ");
3705257cf54a5810105bc4a75703a06740d756d8e8landley			hit = true;
3715257cf54a5810105bc4a75703a06740d756d8e8landley		} else
3725257cf54a5810105bc4a75703a06740d756d8e8landley			str_printf(r, " && ");
3735257cf54a5810105bc4a75703a06740d756d8e8landley		expr_gstr_print(prop->expr, r);
3745257cf54a5810105bc4a75703a06740d756d8e8landley	}
3755257cf54a5810105bc4a75703a06740d756d8e8landley	if (hit)
3765257cf54a5810105bc4a75703a06740d756d8e8landley		str_append(r, "\n");
3775257cf54a5810105bc4a75703a06740d756d8e8landley	if (sym->rev_dep.expr) {
3785257cf54a5810105bc4a75703a06740d756d8e8landley		str_append(r, "  Selected by: ");
3795257cf54a5810105bc4a75703a06740d756d8e8landley		expr_gstr_print(sym->rev_dep.expr, r);
3805257cf54a5810105bc4a75703a06740d756d8e8landley		str_append(r, "\n");
3815257cf54a5810105bc4a75703a06740d756d8e8landley	}
3825257cf54a5810105bc4a75703a06740d756d8e8landley	str_append(r, "\n\n");
3835257cf54a5810105bc4a75703a06740d756d8e8landley}
3845257cf54a5810105bc4a75703a06740d756d8e8landley
3855257cf54a5810105bc4a75703a06740d756d8e8landleystatic struct gstr get_relations_str(struct symbol **sym_arr)
3865257cf54a5810105bc4a75703a06740d756d8e8landley{
3875257cf54a5810105bc4a75703a06740d756d8e8landley	struct symbol *sym;
3885257cf54a5810105bc4a75703a06740d756d8e8landley	struct gstr res = str_new();
3895257cf54a5810105bc4a75703a06740d756d8e8landley	int i;
3905257cf54a5810105bc4a75703a06740d756d8e8landley
3915257cf54a5810105bc4a75703a06740d756d8e8landley	for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
3925257cf54a5810105bc4a75703a06740d756d8e8landley		get_symbol_str(&res, sym);
3935257cf54a5810105bc4a75703a06740d756d8e8landley	if (!i)
3945257cf54a5810105bc4a75703a06740d756d8e8landley		str_append(&res, "No matches found.\n");
3955257cf54a5810105bc4a75703a06740d756d8e8landley	return res;
3965257cf54a5810105bc4a75703a06740d756d8e8landley}
3975257cf54a5810105bc4a75703a06740d756d8e8landley
3985257cf54a5810105bc4a75703a06740d756d8e8landleystatic void search_conf(void)
3995257cf54a5810105bc4a75703a06740d756d8e8landley{
4005257cf54a5810105bc4a75703a06740d756d8e8landley	struct symbol **sym_arr;
4015257cf54a5810105bc4a75703a06740d756d8e8landley	struct gstr res;
4025257cf54a5810105bc4a75703a06740d756d8e8landley	int dres;
4035257cf54a5810105bc4a75703a06740d756d8e8landleyagain:
4045257cf54a5810105bc4a75703a06740d756d8e8landley	dialog_clear();
4055257cf54a5810105bc4a75703a06740d756d8e8landley	dres = dialog_inputbox(_("Search Configuration Parameter"),
4065257cf54a5810105bc4a75703a06740d756d8e8landley			      _("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"),
4075257cf54a5810105bc4a75703a06740d756d8e8landley			      10, 75, "");
4085257cf54a5810105bc4a75703a06740d756d8e8landley	switch (dres) {
4095257cf54a5810105bc4a75703a06740d756d8e8landley	case 0:
4105257cf54a5810105bc4a75703a06740d756d8e8landley		break;
4115257cf54a5810105bc4a75703a06740d756d8e8landley	case 1:
4125257cf54a5810105bc4a75703a06740d756d8e8landley		show_helptext(_("Search Configuration"), search_help);
4135257cf54a5810105bc4a75703a06740d756d8e8landley		goto again;
4145257cf54a5810105bc4a75703a06740d756d8e8landley	default:
4155257cf54a5810105bc4a75703a06740d756d8e8landley		return;
4165257cf54a5810105bc4a75703a06740d756d8e8landley	}
4175257cf54a5810105bc4a75703a06740d756d8e8landley
4185257cf54a5810105bc4a75703a06740d756d8e8landley	sym_arr = sym_re_search(dialog_input_result);
4195257cf54a5810105bc4a75703a06740d756d8e8landley	res = get_relations_str(sym_arr);
4205257cf54a5810105bc4a75703a06740d756d8e8landley	free(sym_arr);
4215257cf54a5810105bc4a75703a06740d756d8e8landley	show_textbox(_("Search Results"), str_get(&res), 0, 0);
4225257cf54a5810105bc4a75703a06740d756d8e8landley	str_free(&res);
4235257cf54a5810105bc4a75703a06740d756d8e8landley}
4245257cf54a5810105bc4a75703a06740d756d8e8landley
4255257cf54a5810105bc4a75703a06740d756d8e8landleystatic void build_conf(struct menu *menu)
4265257cf54a5810105bc4a75703a06740d756d8e8landley{
4275257cf54a5810105bc4a75703a06740d756d8e8landley	struct symbol *sym;
4285257cf54a5810105bc4a75703a06740d756d8e8landley	struct property *prop;
4295257cf54a5810105bc4a75703a06740d756d8e8landley	struct menu *child;
4305257cf54a5810105bc4a75703a06740d756d8e8landley	int type, tmp, doint = 2;
4315257cf54a5810105bc4a75703a06740d756d8e8landley	tristate val;
4325257cf54a5810105bc4a75703a06740d756d8e8landley	char ch;
4335257cf54a5810105bc4a75703a06740d756d8e8landley
4345257cf54a5810105bc4a75703a06740d756d8e8landley	if (!menu_is_visible(menu))
4355257cf54a5810105bc4a75703a06740d756d8e8landley		return;
4365257cf54a5810105bc4a75703a06740d756d8e8landley
4375257cf54a5810105bc4a75703a06740d756d8e8landley	sym = menu->sym;
4385257cf54a5810105bc4a75703a06740d756d8e8landley	prop = menu->prompt;
4395257cf54a5810105bc4a75703a06740d756d8e8landley	if (!sym) {
4405257cf54a5810105bc4a75703a06740d756d8e8landley		if (prop && menu != current_menu) {
4415257cf54a5810105bc4a75703a06740d756d8e8landley			const char *prompt = menu_get_prompt(menu);
4425257cf54a5810105bc4a75703a06740d756d8e8landley			switch (prop->type) {
4435257cf54a5810105bc4a75703a06740d756d8e8landley			case P_MENU:
4445257cf54a5810105bc4a75703a06740d756d8e8landley				child_count++;
4455257cf54a5810105bc4a75703a06740d756d8e8landley				if (single_menu_mode) {
4465257cf54a5810105bc4a75703a06740d756d8e8landley					item_make("%s%*c%s",
4475257cf54a5810105bc4a75703a06740d756d8e8landley						  menu->data ? "-->" : "++>",
4485257cf54a5810105bc4a75703a06740d756d8e8landley						  indent + 1, ' ', prompt);
4495257cf54a5810105bc4a75703a06740d756d8e8landley				} else
4505257cf54a5810105bc4a75703a06740d756d8e8landley					item_make("   %*c%s  --->", indent + 1, ' ', prompt);
4515257cf54a5810105bc4a75703a06740d756d8e8landley
4525257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_tag('m');
4535257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_data(menu);
4545257cf54a5810105bc4a75703a06740d756d8e8landley				if (single_menu_mode && menu->data)
4555257cf54a5810105bc4a75703a06740d756d8e8landley					goto conf_childs;
4565257cf54a5810105bc4a75703a06740d756d8e8landley				return;
4575257cf54a5810105bc4a75703a06740d756d8e8landley			default:
4585257cf54a5810105bc4a75703a06740d756d8e8landley				if (prompt) {
4595257cf54a5810105bc4a75703a06740d756d8e8landley					child_count++;
4605257cf54a5810105bc4a75703a06740d756d8e8landley					item_make("---%*c%s", indent + 1, ' ', prompt);
4615257cf54a5810105bc4a75703a06740d756d8e8landley					item_set_tag(':');
4625257cf54a5810105bc4a75703a06740d756d8e8landley					item_set_data(menu);
4635257cf54a5810105bc4a75703a06740d756d8e8landley				}
4645257cf54a5810105bc4a75703a06740d756d8e8landley			}
4655257cf54a5810105bc4a75703a06740d756d8e8landley		} else
4665257cf54a5810105bc4a75703a06740d756d8e8landley			doint = 0;
4675257cf54a5810105bc4a75703a06740d756d8e8landley		goto conf_childs;
4685257cf54a5810105bc4a75703a06740d756d8e8landley	}
4695257cf54a5810105bc4a75703a06740d756d8e8landley
4705257cf54a5810105bc4a75703a06740d756d8e8landley	type = sym_get_type(sym);
4715257cf54a5810105bc4a75703a06740d756d8e8landley	if (sym_is_choice(sym)) {
4725257cf54a5810105bc4a75703a06740d756d8e8landley		struct symbol *def_sym = sym_get_choice_value(sym);
4735257cf54a5810105bc4a75703a06740d756d8e8landley		struct menu *def_menu = NULL;
4745257cf54a5810105bc4a75703a06740d756d8e8landley
4755257cf54a5810105bc4a75703a06740d756d8e8landley		child_count++;
4765257cf54a5810105bc4a75703a06740d756d8e8landley		for (child = menu->list; child; child = child->next) {
4775257cf54a5810105bc4a75703a06740d756d8e8landley			if (menu_is_visible(child) && child->sym == def_sym)
4785257cf54a5810105bc4a75703a06740d756d8e8landley				def_menu = child;
4795257cf54a5810105bc4a75703a06740d756d8e8landley		}
4805257cf54a5810105bc4a75703a06740d756d8e8landley
4815257cf54a5810105bc4a75703a06740d756d8e8landley		val = sym_get_tristate_value(sym);
4825257cf54a5810105bc4a75703a06740d756d8e8landley		if (sym_is_changable(sym)) {
4835257cf54a5810105bc4a75703a06740d756d8e8landley			switch (type) {
4845257cf54a5810105bc4a75703a06740d756d8e8landley			case S_BOOLEAN:
4855257cf54a5810105bc4a75703a06740d756d8e8landley				item_make("[%c]", val == no ? ' ' : '*');
4865257cf54a5810105bc4a75703a06740d756d8e8landley				break;
4875257cf54a5810105bc4a75703a06740d756d8e8landley			case S_TRISTATE:
4885257cf54a5810105bc4a75703a06740d756d8e8landley				switch (val) {
4895257cf54a5810105bc4a75703a06740d756d8e8landley				case yes: ch = '*'; break;
4905257cf54a5810105bc4a75703a06740d756d8e8landley				case mod: ch = 'M'; break;
4915257cf54a5810105bc4a75703a06740d756d8e8landley				default:  ch = ' '; break;
4925257cf54a5810105bc4a75703a06740d756d8e8landley				}
4935257cf54a5810105bc4a75703a06740d756d8e8landley				item_make("<%c>", ch);
4945257cf54a5810105bc4a75703a06740d756d8e8landley				break;
4955257cf54a5810105bc4a75703a06740d756d8e8landley			}
4965257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_tag('t');
4975257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_data(menu);
4985257cf54a5810105bc4a75703a06740d756d8e8landley		} else {
4995257cf54a5810105bc4a75703a06740d756d8e8landley			item_make("   ");
5005257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_tag(def_menu ? 't' : ':');
5015257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_data(menu);
5025257cf54a5810105bc4a75703a06740d756d8e8landley		}
5035257cf54a5810105bc4a75703a06740d756d8e8landley
5045257cf54a5810105bc4a75703a06740d756d8e8landley		item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
5055257cf54a5810105bc4a75703a06740d756d8e8landley		if (val == yes) {
5065257cf54a5810105bc4a75703a06740d756d8e8landley			if (def_menu) {
5075257cf54a5810105bc4a75703a06740d756d8e8landley				item_add_str(" (%s)", menu_get_prompt(def_menu));
5085257cf54a5810105bc4a75703a06740d756d8e8landley				item_add_str("  --->");
5095257cf54a5810105bc4a75703a06740d756d8e8landley				if (def_menu->list) {
5105257cf54a5810105bc4a75703a06740d756d8e8landley					indent += 2;
5115257cf54a5810105bc4a75703a06740d756d8e8landley					build_conf(def_menu);
5125257cf54a5810105bc4a75703a06740d756d8e8landley					indent -= 2;
5135257cf54a5810105bc4a75703a06740d756d8e8landley				}
5145257cf54a5810105bc4a75703a06740d756d8e8landley			}
5155257cf54a5810105bc4a75703a06740d756d8e8landley			return;
5165257cf54a5810105bc4a75703a06740d756d8e8landley		}
5175257cf54a5810105bc4a75703a06740d756d8e8landley	} else {
5185257cf54a5810105bc4a75703a06740d756d8e8landley		if (menu == current_menu) {
5195257cf54a5810105bc4a75703a06740d756d8e8landley			item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
5205257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_tag(':');
5215257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_data(menu);
5225257cf54a5810105bc4a75703a06740d756d8e8landley			goto conf_childs;
5235257cf54a5810105bc4a75703a06740d756d8e8landley		}
5245257cf54a5810105bc4a75703a06740d756d8e8landley		child_count++;
5255257cf54a5810105bc4a75703a06740d756d8e8landley		val = sym_get_tristate_value(sym);
5265257cf54a5810105bc4a75703a06740d756d8e8landley		if (sym_is_choice_value(sym) && val == yes) {
5275257cf54a5810105bc4a75703a06740d756d8e8landley			item_make("   ");
5285257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_tag(':');
5295257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_data(menu);
5305257cf54a5810105bc4a75703a06740d756d8e8landley		} else {
5315257cf54a5810105bc4a75703a06740d756d8e8landley			switch (type) {
5325257cf54a5810105bc4a75703a06740d756d8e8landley			case S_BOOLEAN:
5335257cf54a5810105bc4a75703a06740d756d8e8landley				if (sym_is_changable(sym))
5345257cf54a5810105bc4a75703a06740d756d8e8landley					item_make("[%c]", val == no ? ' ' : '*');
5355257cf54a5810105bc4a75703a06740d756d8e8landley				else
5365257cf54a5810105bc4a75703a06740d756d8e8landley					item_make("---");
5375257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_tag('t');
5385257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_data(menu);
5395257cf54a5810105bc4a75703a06740d756d8e8landley				break;
5405257cf54a5810105bc4a75703a06740d756d8e8landley			case S_TRISTATE:
5415257cf54a5810105bc4a75703a06740d756d8e8landley				switch (val) {
5425257cf54a5810105bc4a75703a06740d756d8e8landley				case yes: ch = '*'; break;
5435257cf54a5810105bc4a75703a06740d756d8e8landley				case mod: ch = 'M'; break;
5445257cf54a5810105bc4a75703a06740d756d8e8landley				default:  ch = ' '; break;
5455257cf54a5810105bc4a75703a06740d756d8e8landley				}
5465257cf54a5810105bc4a75703a06740d756d8e8landley				if (sym_is_changable(sym))
5475257cf54a5810105bc4a75703a06740d756d8e8landley					item_make("<%c>", ch);
5485257cf54a5810105bc4a75703a06740d756d8e8landley				else
5495257cf54a5810105bc4a75703a06740d756d8e8landley					item_make("---");
5505257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_tag('t');
5515257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_data(menu);
5525257cf54a5810105bc4a75703a06740d756d8e8landley				break;
5535257cf54a5810105bc4a75703a06740d756d8e8landley			default:
5545257cf54a5810105bc4a75703a06740d756d8e8landley				tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
5555257cf54a5810105bc4a75703a06740d756d8e8landley				item_make("(%s)", sym_get_string_value(sym));
5565257cf54a5810105bc4a75703a06740d756d8e8landley				tmp = indent - tmp + 4;
5575257cf54a5810105bc4a75703a06740d756d8e8landley				if (tmp < 0)
5585257cf54a5810105bc4a75703a06740d756d8e8landley					tmp = 0;
5595257cf54a5810105bc4a75703a06740d756d8e8landley				item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
5605257cf54a5810105bc4a75703a06740d756d8e8landley					     (sym_has_value(sym) || !sym_is_changable(sym)) ?
5615257cf54a5810105bc4a75703a06740d756d8e8landley					     "" : " (NEW)");
5625257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_tag('s');
5635257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_data(menu);
5645257cf54a5810105bc4a75703a06740d756d8e8landley				goto conf_childs;
5655257cf54a5810105bc4a75703a06740d756d8e8landley			}
5665257cf54a5810105bc4a75703a06740d756d8e8landley		}
5675257cf54a5810105bc4a75703a06740d756d8e8landley		item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
5685257cf54a5810105bc4a75703a06740d756d8e8landley			  (sym_has_value(sym) || !sym_is_changable(sym)) ?
5695257cf54a5810105bc4a75703a06740d756d8e8landley			  "" : " (NEW)");
5705257cf54a5810105bc4a75703a06740d756d8e8landley		if (menu->prompt->type == P_MENU) {
5715257cf54a5810105bc4a75703a06740d756d8e8landley			item_add_str("  --->");
5725257cf54a5810105bc4a75703a06740d756d8e8landley			return;
5735257cf54a5810105bc4a75703a06740d756d8e8landley		}
5745257cf54a5810105bc4a75703a06740d756d8e8landley	}
5755257cf54a5810105bc4a75703a06740d756d8e8landley
5765257cf54a5810105bc4a75703a06740d756d8e8landleyconf_childs:
5775257cf54a5810105bc4a75703a06740d756d8e8landley	indent += doint;
5785257cf54a5810105bc4a75703a06740d756d8e8landley	for (child = menu->list; child; child = child->next)
5795257cf54a5810105bc4a75703a06740d756d8e8landley		build_conf(child);
5805257cf54a5810105bc4a75703a06740d756d8e8landley	indent -= doint;
5815257cf54a5810105bc4a75703a06740d756d8e8landley}
5825257cf54a5810105bc4a75703a06740d756d8e8landley
5835257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf(struct menu *menu)
5845257cf54a5810105bc4a75703a06740d756d8e8landley{
5855257cf54a5810105bc4a75703a06740d756d8e8landley	struct menu *submenu;
5865257cf54a5810105bc4a75703a06740d756d8e8landley	const char *prompt = menu_get_prompt(menu);
5875257cf54a5810105bc4a75703a06740d756d8e8landley	struct symbol *sym;
5885257cf54a5810105bc4a75703a06740d756d8e8landley	struct menu *active_menu = NULL;
5895257cf54a5810105bc4a75703a06740d756d8e8landley	int res;
5905257cf54a5810105bc4a75703a06740d756d8e8landley	int s_scroll = 0;
5915257cf54a5810105bc4a75703a06740d756d8e8landley
5925257cf54a5810105bc4a75703a06740d756d8e8landley	while (1) {
5935257cf54a5810105bc4a75703a06740d756d8e8landley		item_reset();
5945257cf54a5810105bc4a75703a06740d756d8e8landley		current_menu = menu;
5955257cf54a5810105bc4a75703a06740d756d8e8landley		build_conf(menu);
5965257cf54a5810105bc4a75703a06740d756d8e8landley		if (!child_count)
5975257cf54a5810105bc4a75703a06740d756d8e8landley			break;
5985257cf54a5810105bc4a75703a06740d756d8e8landley		if (menu == &rootmenu) {
5995257cf54a5810105bc4a75703a06740d756d8e8landley			item_make("--- ");
6005257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_tag(':');
6015257cf54a5810105bc4a75703a06740d756d8e8landley			item_make(_("    Load an Alternate Configuration File"));
6025257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_tag('L');
6035257cf54a5810105bc4a75703a06740d756d8e8landley			item_make(_("    Save an Alternate Configuration File"));
6045257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_tag('S');
6055257cf54a5810105bc4a75703a06740d756d8e8landley		}
6065257cf54a5810105bc4a75703a06740d756d8e8landley		dialog_clear();
6075257cf54a5810105bc4a75703a06740d756d8e8landley		res = dialog_menu(prompt ? prompt : _("Main Menu"),
6085257cf54a5810105bc4a75703a06740d756d8e8landley				  _(menu_instructions),
6095257cf54a5810105bc4a75703a06740d756d8e8landley				  active_menu, &s_scroll);
6105257cf54a5810105bc4a75703a06740d756d8e8landley		if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
6115257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6125257cf54a5810105bc4a75703a06740d756d8e8landley		if (!item_activate_selected())
6135257cf54a5810105bc4a75703a06740d756d8e8landley			continue;
6145257cf54a5810105bc4a75703a06740d756d8e8landley		if (!item_tag())
6155257cf54a5810105bc4a75703a06740d756d8e8landley			continue;
6165257cf54a5810105bc4a75703a06740d756d8e8landley
6175257cf54a5810105bc4a75703a06740d756d8e8landley		submenu = item_data();
6185257cf54a5810105bc4a75703a06740d756d8e8landley		active_menu = item_data();
6195257cf54a5810105bc4a75703a06740d756d8e8landley		if (submenu)
6205257cf54a5810105bc4a75703a06740d756d8e8landley			sym = submenu->sym;
6215257cf54a5810105bc4a75703a06740d756d8e8landley		else
6225257cf54a5810105bc4a75703a06740d756d8e8landley			sym = NULL;
6235257cf54a5810105bc4a75703a06740d756d8e8landley
6245257cf54a5810105bc4a75703a06740d756d8e8landley		switch (res) {
6255257cf54a5810105bc4a75703a06740d756d8e8landley		case 0:
6265257cf54a5810105bc4a75703a06740d756d8e8landley			switch (item_tag()) {
6275257cf54a5810105bc4a75703a06740d756d8e8landley			case 'm':
6285257cf54a5810105bc4a75703a06740d756d8e8landley				if (single_menu_mode)
6295257cf54a5810105bc4a75703a06740d756d8e8landley					submenu->data = (void *) (long) !submenu->data;
6305257cf54a5810105bc4a75703a06740d756d8e8landley				else
6315257cf54a5810105bc4a75703a06740d756d8e8landley					conf(submenu);
6325257cf54a5810105bc4a75703a06740d756d8e8landley				break;
6335257cf54a5810105bc4a75703a06740d756d8e8landley			case 't':
6345257cf54a5810105bc4a75703a06740d756d8e8landley				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
6355257cf54a5810105bc4a75703a06740d756d8e8landley					conf_choice(submenu);
6365257cf54a5810105bc4a75703a06740d756d8e8landley				else if (submenu->prompt->type == P_MENU)
6375257cf54a5810105bc4a75703a06740d756d8e8landley					conf(submenu);
6385257cf54a5810105bc4a75703a06740d756d8e8landley				break;
6395257cf54a5810105bc4a75703a06740d756d8e8landley			case 's':
6405257cf54a5810105bc4a75703a06740d756d8e8landley				conf_string(submenu);
6415257cf54a5810105bc4a75703a06740d756d8e8landley				break;
6425257cf54a5810105bc4a75703a06740d756d8e8landley			case 'L':
6435257cf54a5810105bc4a75703a06740d756d8e8landley				conf_load();
6445257cf54a5810105bc4a75703a06740d756d8e8landley				break;
6455257cf54a5810105bc4a75703a06740d756d8e8landley			case 'S':
6465257cf54a5810105bc4a75703a06740d756d8e8landley				conf_save();
6475257cf54a5810105bc4a75703a06740d756d8e8landley				break;
6485257cf54a5810105bc4a75703a06740d756d8e8landley			}
6495257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6505257cf54a5810105bc4a75703a06740d756d8e8landley		case 2:
6515257cf54a5810105bc4a75703a06740d756d8e8landley			if (sym)
6525257cf54a5810105bc4a75703a06740d756d8e8landley				show_help(submenu);
6535257cf54a5810105bc4a75703a06740d756d8e8landley			else
6545257cf54a5810105bc4a75703a06740d756d8e8landley				show_helptext("README", _(mconf_readme));
6555257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6565257cf54a5810105bc4a75703a06740d756d8e8landley		case 3:
6575257cf54a5810105bc4a75703a06740d756d8e8landley			if (item_is_tag('t')) {
6585257cf54a5810105bc4a75703a06740d756d8e8landley				if (sym_set_tristate_value(sym, yes))
6595257cf54a5810105bc4a75703a06740d756d8e8landley					break;
6605257cf54a5810105bc4a75703a06740d756d8e8landley				if (sym_set_tristate_value(sym, mod))
6615257cf54a5810105bc4a75703a06740d756d8e8landley					show_textbox(NULL, setmod_text, 6, 74);
6625257cf54a5810105bc4a75703a06740d756d8e8landley			}
6635257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6645257cf54a5810105bc4a75703a06740d756d8e8landley		case 4:
6655257cf54a5810105bc4a75703a06740d756d8e8landley			if (item_is_tag('t'))
6665257cf54a5810105bc4a75703a06740d756d8e8landley				sym_set_tristate_value(sym, no);
6675257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6685257cf54a5810105bc4a75703a06740d756d8e8landley		case 5:
6695257cf54a5810105bc4a75703a06740d756d8e8landley			if (item_is_tag('t'))
6705257cf54a5810105bc4a75703a06740d756d8e8landley				sym_set_tristate_value(sym, mod);
6715257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6725257cf54a5810105bc4a75703a06740d756d8e8landley		case 6:
6735257cf54a5810105bc4a75703a06740d756d8e8landley			if (item_is_tag('t'))
6745257cf54a5810105bc4a75703a06740d756d8e8landley				sym_toggle_tristate_value(sym);
6755257cf54a5810105bc4a75703a06740d756d8e8landley			else if (item_is_tag('m'))
6765257cf54a5810105bc4a75703a06740d756d8e8landley				conf(submenu);
6775257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6785257cf54a5810105bc4a75703a06740d756d8e8landley		case 7:
6795257cf54a5810105bc4a75703a06740d756d8e8landley			search_conf();
6805257cf54a5810105bc4a75703a06740d756d8e8landley			break;
6815257cf54a5810105bc4a75703a06740d756d8e8landley		}
6825257cf54a5810105bc4a75703a06740d756d8e8landley	}
6835257cf54a5810105bc4a75703a06740d756d8e8landley}
6845257cf54a5810105bc4a75703a06740d756d8e8landley
6855257cf54a5810105bc4a75703a06740d756d8e8landleystatic void show_textbox(const char *title, const char *text, int r, int c)
6865257cf54a5810105bc4a75703a06740d756d8e8landley{
6875257cf54a5810105bc4a75703a06740d756d8e8landley	dialog_clear();
6885257cf54a5810105bc4a75703a06740d756d8e8landley	dialog_textbox(title, text, r, c);
6895257cf54a5810105bc4a75703a06740d756d8e8landley}
6905257cf54a5810105bc4a75703a06740d756d8e8landley
6915257cf54a5810105bc4a75703a06740d756d8e8landleystatic void show_helptext(const char *title, const char *text)
6925257cf54a5810105bc4a75703a06740d756d8e8landley{
6935257cf54a5810105bc4a75703a06740d756d8e8landley	show_textbox(title, text, 0, 0);
6945257cf54a5810105bc4a75703a06740d756d8e8landley}
6955257cf54a5810105bc4a75703a06740d756d8e8landley
6965257cf54a5810105bc4a75703a06740d756d8e8landleystatic void show_help(struct menu *menu)
6975257cf54a5810105bc4a75703a06740d756d8e8landley{
6985257cf54a5810105bc4a75703a06740d756d8e8landley	struct gstr help = str_new();
6995257cf54a5810105bc4a75703a06740d756d8e8landley	struct symbol *sym = menu->sym;
7005257cf54a5810105bc4a75703a06740d756d8e8landley
7015257cf54a5810105bc4a75703a06740d756d8e8landley	if (sym->help)
7025257cf54a5810105bc4a75703a06740d756d8e8landley	{
7035257cf54a5810105bc4a75703a06740d756d8e8landley		if (sym->name) {
7045257cf54a5810105bc4a75703a06740d756d8e8landley			str_printf(&help, "CONFIG_%s:\n\n", sym->name);
7055257cf54a5810105bc4a75703a06740d756d8e8landley			str_append(&help, _(sym->help));
7065257cf54a5810105bc4a75703a06740d756d8e8landley			str_append(&help, "\n");
7075257cf54a5810105bc4a75703a06740d756d8e8landley		}
7085257cf54a5810105bc4a75703a06740d756d8e8landley	} else {
7095257cf54a5810105bc4a75703a06740d756d8e8landley		str_append(&help, nohelp_text);
7105257cf54a5810105bc4a75703a06740d756d8e8landley	}
7115257cf54a5810105bc4a75703a06740d756d8e8landley	get_symbol_str(&help, sym);
7125257cf54a5810105bc4a75703a06740d756d8e8landley	show_helptext(menu_get_prompt(menu), str_get(&help));
7135257cf54a5810105bc4a75703a06740d756d8e8landley	str_free(&help);
7145257cf54a5810105bc4a75703a06740d756d8e8landley}
7155257cf54a5810105bc4a75703a06740d756d8e8landley
7165257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_choice(struct menu *menu)
7175257cf54a5810105bc4a75703a06740d756d8e8landley{
7185257cf54a5810105bc4a75703a06740d756d8e8landley	const char *prompt = menu_get_prompt(menu);
7195257cf54a5810105bc4a75703a06740d756d8e8landley	struct menu *child;
7205257cf54a5810105bc4a75703a06740d756d8e8landley	struct symbol *active;
7215257cf54a5810105bc4a75703a06740d756d8e8landley
7225257cf54a5810105bc4a75703a06740d756d8e8landley	active = sym_get_choice_value(menu->sym);
7235257cf54a5810105bc4a75703a06740d756d8e8landley	while (1) {
7245257cf54a5810105bc4a75703a06740d756d8e8landley		int res;
7255257cf54a5810105bc4a75703a06740d756d8e8landley		int selected;
7265257cf54a5810105bc4a75703a06740d756d8e8landley		item_reset();
7275257cf54a5810105bc4a75703a06740d756d8e8landley
7285257cf54a5810105bc4a75703a06740d756d8e8landley		current_menu = menu;
7295257cf54a5810105bc4a75703a06740d756d8e8landley		for (child = menu->list; child; child = child->next) {
7305257cf54a5810105bc4a75703a06740d756d8e8landley			if (!menu_is_visible(child))
7315257cf54a5810105bc4a75703a06740d756d8e8landley				continue;
7325257cf54a5810105bc4a75703a06740d756d8e8landley			item_make("%s", menu_get_prompt(child));
7335257cf54a5810105bc4a75703a06740d756d8e8landley			item_set_data(child);
7345257cf54a5810105bc4a75703a06740d756d8e8landley			if (child->sym == active)
7355257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_selected(1);
7365257cf54a5810105bc4a75703a06740d756d8e8landley			if (child->sym == sym_get_choice_value(menu->sym))
7375257cf54a5810105bc4a75703a06740d756d8e8landley				item_set_tag('X');
7385257cf54a5810105bc4a75703a06740d756d8e8landley		}
7395257cf54a5810105bc4a75703a06740d756d8e8landley		dialog_clear();
7405257cf54a5810105bc4a75703a06740d756d8e8landley		res = dialog_checklist(prompt ? prompt : _("Main Menu"),
7415257cf54a5810105bc4a75703a06740d756d8e8landley					_(radiolist_instructions),
7425257cf54a5810105bc4a75703a06740d756d8e8landley					 15, 70, 6);
7435257cf54a5810105bc4a75703a06740d756d8e8landley		selected = item_activate_selected();
7445257cf54a5810105bc4a75703a06740d756d8e8landley		switch (res) {
7455257cf54a5810105bc4a75703a06740d756d8e8landley		case 0:
7465257cf54a5810105bc4a75703a06740d756d8e8landley			if (selected) {
7475257cf54a5810105bc4a75703a06740d756d8e8landley				child = item_data();
7485257cf54a5810105bc4a75703a06740d756d8e8landley				sym_set_tristate_value(child->sym, yes);
7495257cf54a5810105bc4a75703a06740d756d8e8landley			}
7505257cf54a5810105bc4a75703a06740d756d8e8landley			return;
7515257cf54a5810105bc4a75703a06740d756d8e8landley		case 1:
7525257cf54a5810105bc4a75703a06740d756d8e8landley			if (selected) {
7535257cf54a5810105bc4a75703a06740d756d8e8landley				child = item_data();
7545257cf54a5810105bc4a75703a06740d756d8e8landley				show_help(child);
7555257cf54a5810105bc4a75703a06740d756d8e8landley				active = child->sym;
7565257cf54a5810105bc4a75703a06740d756d8e8landley			} else
7575257cf54a5810105bc4a75703a06740d756d8e8landley				show_help(menu);
7585257cf54a5810105bc4a75703a06740d756d8e8landley			break;
7595257cf54a5810105bc4a75703a06740d756d8e8landley		case KEY_ESC:
7605257cf54a5810105bc4a75703a06740d756d8e8landley			return;
7615257cf54a5810105bc4a75703a06740d756d8e8landley		case -ERRDISPLAYTOOSMALL:
7625257cf54a5810105bc4a75703a06740d756d8e8landley			return;
7635257cf54a5810105bc4a75703a06740d756d8e8landley		}
7645257cf54a5810105bc4a75703a06740d756d8e8landley	}
7655257cf54a5810105bc4a75703a06740d756d8e8landley}
7665257cf54a5810105bc4a75703a06740d756d8e8landley
7675257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_string(struct menu *menu)
7685257cf54a5810105bc4a75703a06740d756d8e8landley{
7695257cf54a5810105bc4a75703a06740d756d8e8landley	const char *prompt = menu_get_prompt(menu);
7705257cf54a5810105bc4a75703a06740d756d8e8landley
7715257cf54a5810105bc4a75703a06740d756d8e8landley	while (1) {
7725257cf54a5810105bc4a75703a06740d756d8e8landley		int res;
7735257cf54a5810105bc4a75703a06740d756d8e8landley		char *heading;
7745257cf54a5810105bc4a75703a06740d756d8e8landley
7755257cf54a5810105bc4a75703a06740d756d8e8landley		switch (sym_get_type(menu->sym)) {
7765257cf54a5810105bc4a75703a06740d756d8e8landley		case S_INT:
777bdcb80e9d316863a77ff922e18d32e9024c77c82Rob Landley			heading = (char *)_(inputbox_instructions_int);
7785257cf54a5810105bc4a75703a06740d756d8e8landley			break;
7795257cf54a5810105bc4a75703a06740d756d8e8landley		case S_HEX:
780bdcb80e9d316863a77ff922e18d32e9024c77c82Rob Landley			heading = (char *)_(inputbox_instructions_hex);
7815257cf54a5810105bc4a75703a06740d756d8e8landley			break;
7825257cf54a5810105bc4a75703a06740d756d8e8landley		case S_STRING:
783bdcb80e9d316863a77ff922e18d32e9024c77c82Rob Landley			heading = (char *)_(inputbox_instructions_string);
7845257cf54a5810105bc4a75703a06740d756d8e8landley			break;
7855257cf54a5810105bc4a75703a06740d756d8e8landley		default:
7865257cf54a5810105bc4a75703a06740d756d8e8landley			heading = "Internal mconf error!";
7875257cf54a5810105bc4a75703a06740d756d8e8landley		}
7885257cf54a5810105bc4a75703a06740d756d8e8landley		dialog_clear();
7895257cf54a5810105bc4a75703a06740d756d8e8landley		res = dialog_inputbox(prompt ? prompt : _("Main Menu"),
7905257cf54a5810105bc4a75703a06740d756d8e8landley				      heading, 10, 75,
7915257cf54a5810105bc4a75703a06740d756d8e8landley				      sym_get_string_value(menu->sym));
7925257cf54a5810105bc4a75703a06740d756d8e8landley		switch (res) {
7935257cf54a5810105bc4a75703a06740d756d8e8landley		case 0:
7945257cf54a5810105bc4a75703a06740d756d8e8landley			if (sym_set_string_value(menu->sym, dialog_input_result))
7955257cf54a5810105bc4a75703a06740d756d8e8landley				return;
7965257cf54a5810105bc4a75703a06740d756d8e8landley			show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
7975257cf54a5810105bc4a75703a06740d756d8e8landley			break;
7985257cf54a5810105bc4a75703a06740d756d8e8landley		case 1:
7995257cf54a5810105bc4a75703a06740d756d8e8landley			show_help(menu);
8005257cf54a5810105bc4a75703a06740d756d8e8landley			break;
8015257cf54a5810105bc4a75703a06740d756d8e8landley		case KEY_ESC:
8025257cf54a5810105bc4a75703a06740d756d8e8landley			return;
8035257cf54a5810105bc4a75703a06740d756d8e8landley		}
8045257cf54a5810105bc4a75703a06740d756d8e8landley	}
8055257cf54a5810105bc4a75703a06740d756d8e8landley}
8065257cf54a5810105bc4a75703a06740d756d8e8landley
8075257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_load(void)
8085257cf54a5810105bc4a75703a06740d756d8e8landley{
8095257cf54a5810105bc4a75703a06740d756d8e8landley
8105257cf54a5810105bc4a75703a06740d756d8e8landley	while (1) {
8115257cf54a5810105bc4a75703a06740d756d8e8landley		int res;
8125257cf54a5810105bc4a75703a06740d756d8e8landley		dialog_clear();
8135257cf54a5810105bc4a75703a06740d756d8e8landley		res = dialog_inputbox(NULL, load_config_text,
8145257cf54a5810105bc4a75703a06740d756d8e8landley				      11, 55, filename);
8155257cf54a5810105bc4a75703a06740d756d8e8landley		switch(res) {
8165257cf54a5810105bc4a75703a06740d756d8e8landley		case 0:
8175257cf54a5810105bc4a75703a06740d756d8e8landley			if (!dialog_input_result[0])
8185257cf54a5810105bc4a75703a06740d756d8e8landley				return;
8195257cf54a5810105bc4a75703a06740d756d8e8landley			if (!conf_read(dialog_input_result))
8205257cf54a5810105bc4a75703a06740d756d8e8landley				return;
8215257cf54a5810105bc4a75703a06740d756d8e8landley			show_textbox(NULL, _("File does not exist!"), 5, 38);
8225257cf54a5810105bc4a75703a06740d756d8e8landley			break;
8235257cf54a5810105bc4a75703a06740d756d8e8landley		case 1:
8245257cf54a5810105bc4a75703a06740d756d8e8landley			show_helptext(_("Load Alternate Configuration"), load_config_help);
8255257cf54a5810105bc4a75703a06740d756d8e8landley			break;
8265257cf54a5810105bc4a75703a06740d756d8e8landley		case KEY_ESC:
8275257cf54a5810105bc4a75703a06740d756d8e8landley			return;
8285257cf54a5810105bc4a75703a06740d756d8e8landley		}
8295257cf54a5810105bc4a75703a06740d756d8e8landley	}
8305257cf54a5810105bc4a75703a06740d756d8e8landley}
8315257cf54a5810105bc4a75703a06740d756d8e8landley
8325257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_save(void)
8335257cf54a5810105bc4a75703a06740d756d8e8landley{
8345257cf54a5810105bc4a75703a06740d756d8e8landley	while (1) {
8355257cf54a5810105bc4a75703a06740d756d8e8landley		int res;
8365257cf54a5810105bc4a75703a06740d756d8e8landley		dialog_clear();
8375257cf54a5810105bc4a75703a06740d756d8e8landley		res = dialog_inputbox(NULL, save_config_text,
8385257cf54a5810105bc4a75703a06740d756d8e8landley				      11, 55, filename);
8395257cf54a5810105bc4a75703a06740d756d8e8landley		switch(res) {
8405257cf54a5810105bc4a75703a06740d756d8e8landley		case 0:
8415257cf54a5810105bc4a75703a06740d756d8e8landley			if (!dialog_input_result[0])
8425257cf54a5810105bc4a75703a06740d756d8e8landley				return;
8435257cf54a5810105bc4a75703a06740d756d8e8landley			if (!conf_write(dialog_input_result))
8445257cf54a5810105bc4a75703a06740d756d8e8landley				return;
8455257cf54a5810105bc4a75703a06740d756d8e8landley			show_textbox(NULL, _("Can't create file!  Probably a nonexistent directory."), 5, 60);
8465257cf54a5810105bc4a75703a06740d756d8e8landley			break;
8475257cf54a5810105bc4a75703a06740d756d8e8landley		case 1:
8485257cf54a5810105bc4a75703a06740d756d8e8landley			show_helptext(_("Save Alternate Configuration"), save_config_help);
8495257cf54a5810105bc4a75703a06740d756d8e8landley			break;
8505257cf54a5810105bc4a75703a06740d756d8e8landley		case KEY_ESC:
8515257cf54a5810105bc4a75703a06740d756d8e8landley			return;
8525257cf54a5810105bc4a75703a06740d756d8e8landley		}
8535257cf54a5810105bc4a75703a06740d756d8e8landley	}
8545257cf54a5810105bc4a75703a06740d756d8e8landley}
8555257cf54a5810105bc4a75703a06740d756d8e8landley
8565257cf54a5810105bc4a75703a06740d756d8e8landleystatic void conf_cleanup(void)
8575257cf54a5810105bc4a75703a06740d756d8e8landley{
8585257cf54a5810105bc4a75703a06740d756d8e8landley	tcsetattr(1, TCSAFLUSH, &ios_org);
8595257cf54a5810105bc4a75703a06740d756d8e8landley}
8605257cf54a5810105bc4a75703a06740d756d8e8landley
8615257cf54a5810105bc4a75703a06740d756d8e8landleyint main(int ac, char **av)
8625257cf54a5810105bc4a75703a06740d756d8e8landley{
8635257cf54a5810105bc4a75703a06740d756d8e8landley	struct symbol *sym;
8645257cf54a5810105bc4a75703a06740d756d8e8landley	char *mode;
8655257cf54a5810105bc4a75703a06740d756d8e8landley	int res;
8665257cf54a5810105bc4a75703a06740d756d8e8landley
8675257cf54a5810105bc4a75703a06740d756d8e8landley	setlocale(LC_ALL, "");
8685257cf54a5810105bc4a75703a06740d756d8e8landley	bindtextdomain(PACKAGE, LOCALEDIR);
8695257cf54a5810105bc4a75703a06740d756d8e8landley	textdomain(PACKAGE);
8705257cf54a5810105bc4a75703a06740d756d8e8landley
8715257cf54a5810105bc4a75703a06740d756d8e8landley	conf_parse(av[1] ? av[1] : "");
8725257cf54a5810105bc4a75703a06740d756d8e8landley	conf_read(NULL);
8735257cf54a5810105bc4a75703a06740d756d8e8landley
8745257cf54a5810105bc4a75703a06740d756d8e8landley	sym = sym_lookup("KERNELVERSION", 0);
8755257cf54a5810105bc4a75703a06740d756d8e8landley	sym_calc_value(sym);
8765257cf54a5810105bc4a75703a06740d756d8e8landley	sprintf(menu_backtitle, _(PROJECT_NAME" v%s Configuration"),
8775257cf54a5810105bc4a75703a06740d756d8e8landley		sym_get_string_value(sym));
8785257cf54a5810105bc4a75703a06740d756d8e8landley
8795257cf54a5810105bc4a75703a06740d756d8e8landley	mode = getenv("MENUCONFIG_MODE");
8805257cf54a5810105bc4a75703a06740d756d8e8landley	if (mode) {
8815257cf54a5810105bc4a75703a06740d756d8e8landley		if (!strcasecmp(mode, "single_menu"))
8825257cf54a5810105bc4a75703a06740d756d8e8landley			single_menu_mode = 1;
8835257cf54a5810105bc4a75703a06740d756d8e8landley	}
8845257cf54a5810105bc4a75703a06740d756d8e8landley
8855257cf54a5810105bc4a75703a06740d756d8e8landley	tcgetattr(1, &ios_org);
8865257cf54a5810105bc4a75703a06740d756d8e8landley	atexit(conf_cleanup);
8875257cf54a5810105bc4a75703a06740d756d8e8landley	init_wsize();
8885257cf54a5810105bc4a75703a06740d756d8e8landley	reset_dialog();
8895257cf54a5810105bc4a75703a06740d756d8e8landley	init_dialog(menu_backtitle);
8905257cf54a5810105bc4a75703a06740d756d8e8landley	do {
8915257cf54a5810105bc4a75703a06740d756d8e8landley		conf(&rootmenu);
8925257cf54a5810105bc4a75703a06740d756d8e8landley		dialog_clear();
8935257cf54a5810105bc4a75703a06740d756d8e8landley		res = dialog_yesno(NULL,
8945257cf54a5810105bc4a75703a06740d756d8e8landley				   _("Do you wish to save your "
8955257cf54a5810105bc4a75703a06740d756d8e8landley				     "new "PROJECT_NAME" configuration?\n"
8965257cf54a5810105bc4a75703a06740d756d8e8landley				     "<ESC><ESC> to continue."),
8975257cf54a5810105bc4a75703a06740d756d8e8landley				   6, 60);
8985257cf54a5810105bc4a75703a06740d756d8e8landley	} while (res == KEY_ESC);
8995257cf54a5810105bc4a75703a06740d756d8e8landley	end_dialog();
9005257cf54a5810105bc4a75703a06740d756d8e8landley	if (res == 0) {
9015257cf54a5810105bc4a75703a06740d756d8e8landley		if (conf_write(NULL)) {
9025257cf54a5810105bc4a75703a06740d756d8e8landley			fprintf(stderr, _("\n\n"
9035257cf54a5810105bc4a75703a06740d756d8e8landley				"Error writing "PROJECT_NAME" configuration.\n"
9045257cf54a5810105bc4a75703a06740d756d8e8landley				"Your configuration changes were NOT saved."
9055257cf54a5810105bc4a75703a06740d756d8e8landley				"\n\n"));
9065257cf54a5810105bc4a75703a06740d756d8e8landley			return 1;
9075257cf54a5810105bc4a75703a06740d756d8e8landley		}
9085257cf54a5810105bc4a75703a06740d756d8e8landley		printf(_("\n\n"
9095257cf54a5810105bc4a75703a06740d756d8e8landley			"*** End of "PROJECT_NAME" configuration.\n"
9105257cf54a5810105bc4a75703a06740d756d8e8landley			"*** Execute 'make' to build, or try 'make help'."
9115257cf54a5810105bc4a75703a06740d756d8e8landley			"\n\n"));
9125257cf54a5810105bc4a75703a06740d756d8e8landley	} else {
9135257cf54a5810105bc4a75703a06740d756d8e8landley		fprintf(stderr, _("\n\n"
9145257cf54a5810105bc4a75703a06740d756d8e8landley			"Your configuration changes were NOT saved."
9155257cf54a5810105bc4a75703a06740d756d8e8landley			"\n\n"));
9165257cf54a5810105bc4a75703a06740d756d8e8landley	}
9175257cf54a5810105bc4a75703a06740d756d8e8landley
9185257cf54a5810105bc4a75703a06740d756d8e8landley	return 0;
9195257cf54a5810105bc4a75703a06740d756d8e8landley}
920