0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <ctype.h>
0012 #include <errno.h>
0013 #include <fcntl.h>
0014 #include <limits.h>
0015 #include <stdarg.h>
0016 #include <stdlib.h>
0017 #include <string.h>
0018 #include <strings.h>
0019 #include <signal.h>
0020 #include <unistd.h>
0021
0022 #include "lkc.h"
0023 #include "lxdialog/dialog.h"
0024
0025 #define JUMP_NB 9
0026
0027 static const char mconf_readme[] =
0028 "Overview\n"
0029 "--------\n"
0030 "This interface lets you select features and parameters for the build.\n"
0031 "Features can either be built-in, modularized, or ignored. Parameters\n"
0032 "must be entered in as decimal or hexadecimal numbers or text.\n"
0033 "\n"
0034 "Menu items beginning with following braces represent features that\n"
0035 " [ ] can be built in or removed\n"
0036 " < > can be built in, modularized or removed\n"
0037 " { } can be built in or modularized (selected by other feature)\n"
0038 " - - are selected by other feature,\n"
0039 "while *, M or whitespace inside braces means to build in, build as\n"
0040 "a module or to exclude the feature respectively.\n"
0041 "\n"
0042 "To change any of these features, highlight it with the cursor\n"
0043 "keys and press <Y> to build it in, <M> to make it a module or\n"
0044 "<N> to remove it. You may also press the <Space Bar> to cycle\n"
0045 "through the available options (i.e. Y->N->M->Y).\n"
0046 "\n"
0047 "Some additional keyboard hints:\n"
0048 "\n"
0049 "Menus\n"
0050 "----------\n"
0051 "o Use the Up/Down arrow keys (cursor keys) to highlight the item you\n"
0052 " wish to change or the submenu you wish to select and press <Enter>.\n"
0053 " Submenus are designated by \"--->\", empty ones by \"----\".\n"
0054 "\n"
0055 " Shortcut: Press the option's highlighted letter (hotkey).\n"
0056 " Pressing a hotkey more than once will sequence\n"
0057 " through all visible items which use that hotkey.\n"
0058 "\n"
0059 " You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n"
0060 " unseen options into view.\n"
0061 "\n"
0062 "o To exit a menu use the cursor keys to highlight the <Exit> button\n"
0063 " and press <ENTER>.\n"
0064 "\n"
0065 " Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n"
0066 " using those letters. You may press a single <ESC>, but\n"
0067 " there is a delayed response which you may find annoying.\n"
0068 "\n"
0069 " Also, the <TAB> and cursor keys will cycle between <Select>,\n"
0070 " <Exit>, <Help>, <Save>, and <Load>.\n"
0071 "\n"
0072 "o To get help with an item, use the cursor keys to highlight <Help>\n"
0073 " and press <ENTER>.\n"
0074 "\n"
0075 " Shortcut: Press <H> or <?>.\n"
0076 "\n"
0077 "o To toggle the display of hidden options, press <Z>.\n"
0078 "\n"
0079 "\n"
0080 "Radiolists (Choice lists)\n"
0081 "-----------\n"
0082 "o Use the cursor keys to select the option you wish to set and press\n"
0083 " <S> or the <SPACE BAR>.\n"
0084 "\n"
0085 " Shortcut: Press the first letter of the option you wish to set then\n"
0086 " press <S> or <SPACE BAR>.\n"
0087 "\n"
0088 "o To see available help for the item, use the cursor keys to highlight\n"
0089 " <Help> and Press <ENTER>.\n"
0090 "\n"
0091 " Shortcut: Press <H> or <?>.\n"
0092 "\n"
0093 " Also, the <TAB> and cursor keys will cycle between <Select> and\n"
0094 " <Help>\n"
0095 "\n"
0096 "\n"
0097 "Data Entry\n"
0098 "-----------\n"
0099 "o Enter the requested information and press <ENTER>\n"
0100 " If you are entering hexadecimal values, it is not necessary to\n"
0101 " add the '0x' prefix to the entry.\n"
0102 "\n"
0103 "o For help, use the <TAB> or cursor keys to highlight the help option\n"
0104 " and press <ENTER>. You can try <TAB><H> as well.\n"
0105 "\n"
0106 "\n"
0107 "Text Box (Help Window)\n"
0108 "--------\n"
0109 "o Use the cursor keys to scroll up/down/left/right. The VI editor\n"
0110 " keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for\n"
0111 " those who are familiar with less and lynx.\n"
0112 "\n"
0113 "o Press <E>, <X>, <q>, <Enter> or <Esc><Esc> to exit.\n"
0114 "\n"
0115 "\n"
0116 "Alternate Configuration Files\n"
0117 "-----------------------------\n"
0118 "Menuconfig supports the use of alternate configuration files for\n"
0119 "those who, for various reasons, find it necessary to switch\n"
0120 "between different configurations.\n"
0121 "\n"
0122 "The <Save> button will let you save the current configuration to\n"
0123 "a file of your choosing. Use the <Load> button to load a previously\n"
0124 "saved alternate configuration.\n"
0125 "\n"
0126 "Even if you don't use alternate configuration files, but you find\n"
0127 "during a Menuconfig session that you have completely messed up your\n"
0128 "settings, you may use the <Load> button to restore your previously\n"
0129 "saved settings from \".config\" without restarting Menuconfig.\n"
0130 "\n"
0131 "Other information\n"
0132 "-----------------\n"
0133 "If you use Menuconfig in an XTERM window, make sure you have your\n"
0134 "$TERM variable set to point to an xterm definition which supports\n"
0135 "color. Otherwise, Menuconfig will look rather bad. Menuconfig will\n"
0136 "not display correctly in an RXVT window because rxvt displays only one\n"
0137 "intensity of color, bright.\n"
0138 "\n"
0139 "Menuconfig will display larger menus on screens or xterms which are\n"
0140 "set to display more than the standard 25 row by 80 column geometry.\n"
0141 "In order for this to work, the \"stty size\" command must be able to\n"
0142 "display the screen's current row and column geometry. I STRONGLY\n"
0143 "RECOMMEND that you make sure you do NOT have the shell variables\n"
0144 "LINES and COLUMNS exported into your environment. Some distributions\n"
0145 "export those variables via /etc/profile. Some ncurses programs can\n"
0146 "become confused when those variables (LINES & COLUMNS) don't reflect\n"
0147 "the true screen size.\n"
0148 "\n"
0149 "Optional personality available\n"
0150 "------------------------------\n"
0151 "If you prefer to have all of the options listed in a single menu,\n"
0152 "rather than the default multimenu hierarchy, run the menuconfig with\n"
0153 "MENUCONFIG_MODE environment variable set to single_menu. Example:\n"
0154 "\n"
0155 "make MENUCONFIG_MODE=single_menu menuconfig\n"
0156 "\n"
0157 "<Enter> will then unroll the appropriate category, or enfold it if it\n"
0158 "is already unrolled.\n"
0159 "\n"
0160 "Note that this mode can eventually be a little more CPU expensive\n"
0161 "(especially with a larger number of unrolled categories) than the\n"
0162 "default mode.\n"
0163 "\n"
0164 "Different color themes available\n"
0165 "--------------------------------\n"
0166 "It is possible to select different color themes using the variable\n"
0167 "MENUCONFIG_COLOR. To select a theme use:\n"
0168 "\n"
0169 "make MENUCONFIG_COLOR=<theme> menuconfig\n"
0170 "\n"
0171 "Available themes are\n"
0172 " mono => selects colors suitable for monochrome displays\n"
0173 " blackbg => selects a color scheme with black background\n"
0174 " classic => theme with blue background. The classic look\n"
0175 " bluetitle => an LCD friendly version of classic. (default)\n"
0176 "\n",
0177 menu_instructions[] =
0178 "Arrow keys navigate the menu. "
0179 "<Enter> selects submenus ---> (or empty submenus ----). "
0180 "Highlighted letters are hotkeys. "
0181 "Pressing <Y> includes, <N> excludes, <M> modularizes features. "
0182 "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
0183 "Legend: [*] built-in [ ] excluded <M> module < > module capable",
0184 radiolist_instructions[] =
0185 "Use the arrow keys to navigate this window or "
0186 "press the hotkey of the item you wish to select "
0187 "followed by the <SPACE BAR>. "
0188 "Press <?> for additional information about this option.",
0189 inputbox_instructions_int[] =
0190 "Please enter a decimal value. "
0191 "Fractions will not be accepted. "
0192 "Use the <TAB> key to move from the input field to the buttons below it.",
0193 inputbox_instructions_hex[] =
0194 "Please enter a hexadecimal value. "
0195 "Use the <TAB> key to move from the input field to the buttons below it.",
0196 inputbox_instructions_string[] =
0197 "Please enter a string value. "
0198 "Use the <TAB> key to move from the input field to the buttons below it.",
0199 setmod_text[] =
0200 "This feature depends on another which has been configured as a module.\n"
0201 "As a result, this feature will be built as a module.",
0202 load_config_text[] =
0203 "Enter the name of the configuration file you wish to load. "
0204 "Accept the name shown to restore the configuration you "
0205 "last retrieved. Leave blank to abort.",
0206 load_config_help[] =
0207 "\n"
0208 "For various reasons, one may wish to keep several different\n"
0209 "configurations available on a single machine.\n"
0210 "\n"
0211 "If you have saved a previous configuration in a file other than the\n"
0212 "default one, entering its name here will allow you to modify that\n"
0213 "configuration.\n"
0214 "\n"
0215 "If you are uncertain, then you have probably never used alternate\n"
0216 "configuration files. You should therefore leave this blank to abort.\n",
0217 save_config_text[] =
0218 "Enter a filename to which this configuration should be saved "
0219 "as an alternate. Leave blank to abort.",
0220 save_config_help[] =
0221 "\n"
0222 "For various reasons, one may wish to keep different configurations\n"
0223 "available on a single machine.\n"
0224 "\n"
0225 "Entering a file name here will allow you to later retrieve, modify\n"
0226 "and use the current configuration as an alternate to whatever\n"
0227 "configuration options you have selected at that time.\n"
0228 "\n"
0229 "If you are uncertain what all this means then you should probably\n"
0230 "leave this blank.\n",
0231 search_help[] =
0232 "\n"
0233 "Search for symbols and display their relations.\n"
0234 "Regular expressions are allowed.\n"
0235 "Example: search for \"^FOO\"\n"
0236 "Result:\n"
0237 "-----------------------------------------------------------------\n"
0238 "Symbol: FOO [=m]\n"
0239 "Type : tristate\n"
0240 "Prompt: Foo bus is used to drive the bar HW\n"
0241 " Location:\n"
0242 " -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
0243 " -> PCI support (PCI [=y])\n"
0244 "(1) -> PCI access mode (<choice> [=y])\n"
0245 " Defined at drivers/pci/Kconfig:47\n"
0246 " Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
0247 " Selects: LIBCRC32\n"
0248 " Selected by: BAR [=n]\n"
0249 "-----------------------------------------------------------------\n"
0250 "o The line 'Type:' shows the type of the configuration option for\n"
0251 " this symbol (bool, tristate, string, ...)\n"
0252 "o The line 'Prompt:' shows the text used in the menu structure for\n"
0253 " this symbol\n"
0254 "o The 'Defined at' line tells at what file / line number the symbol\n"
0255 " is defined\n"
0256 "o The 'Depends on:' line tells what symbols need to be defined for\n"
0257 " this symbol to be visible in the menu (selectable)\n"
0258 "o The 'Location:' lines tells where in the menu structure this symbol\n"
0259 " is located\n"
0260 " A location followed by a [=y] indicates that this is a\n"
0261 " selectable menu item - and the current value is displayed inside\n"
0262 " brackets.\n"
0263 " Press the key in the (#) prefix to jump directly to that\n"
0264 " location. You will be returned to the current search results\n"
0265 " after exiting this new menu.\n"
0266 "o The 'Selects:' line tells what symbols will be automatically\n"
0267 " selected if this symbol is selected (y or m)\n"
0268 "o The 'Selected by' line tells what symbol has selected this symbol\n"
0269 "\n"
0270 "Only relevant lines are shown.\n"
0271 "\n\n"
0272 "Search examples:\n"
0273 "Examples: USB => find all symbols containing USB\n"
0274 " ^USB => find all symbols starting with USB\n"
0275 " USB$ => find all symbols ending with USB\n"
0276 "\n";
0277
0278 static int indent;
0279 static struct menu *current_menu;
0280 static int child_count;
0281 static int single_menu_mode;
0282 static int show_all_options;
0283 static int save_and_exit;
0284 static int silent;
0285
0286 static void conf(struct menu *menu, struct menu *active_menu);
0287 static void conf_choice(struct menu *menu);
0288 static void conf_string(struct menu *menu);
0289 static void conf_load(void);
0290 static void conf_save(void);
0291 static int show_textbox_ext(const char *title, char *text, int r, int c,
0292 int *keys, int *vscroll, int *hscroll,
0293 update_text_fn update_text, void *data);
0294 static void show_textbox(const char *title, const char *text, int r, int c);
0295 static void show_helptext(const char *title, const char *text);
0296 static void show_help(struct menu *menu);
0297
0298 static char filename[PATH_MAX+1];
0299 static void set_config_filename(const char *config_filename)
0300 {
0301 static char menu_backtitle[PATH_MAX+128];
0302
0303 snprintf(menu_backtitle, sizeof(menu_backtitle), "%s - %s",
0304 config_filename, rootmenu.prompt->text);
0305 set_dialog_backtitle(menu_backtitle);
0306
0307 snprintf(filename, sizeof(filename), "%s", config_filename);
0308 }
0309
0310 struct subtitle_part {
0311 struct list_head entries;
0312 const char *text;
0313 };
0314 static LIST_HEAD(trail);
0315
0316 static struct subtitle_list *subtitles;
0317 static void set_subtitle(void)
0318 {
0319 struct subtitle_part *sp;
0320 struct subtitle_list *pos, *tmp;
0321
0322 for (pos = subtitles; pos != NULL; pos = tmp) {
0323 tmp = pos->next;
0324 free(pos);
0325 }
0326
0327 subtitles = NULL;
0328 list_for_each_entry(sp, &trail, entries) {
0329 if (sp->text) {
0330 if (pos) {
0331 pos->next = xcalloc(1, sizeof(*pos));
0332 pos = pos->next;
0333 } else {
0334 subtitles = pos = xcalloc(1, sizeof(*pos));
0335 }
0336 pos->text = sp->text;
0337 }
0338 }
0339
0340 set_dialog_subtitles(subtitles);
0341 }
0342
0343 static void reset_subtitle(void)
0344 {
0345 struct subtitle_list *pos, *tmp;
0346
0347 for (pos = subtitles; pos != NULL; pos = tmp) {
0348 tmp = pos->next;
0349 free(pos);
0350 }
0351 subtitles = NULL;
0352 set_dialog_subtitles(subtitles);
0353 }
0354
0355 struct search_data {
0356 struct list_head *head;
0357 struct menu **targets;
0358 int *keys;
0359 };
0360
0361 static void update_text(char *buf, size_t start, size_t end, void *_data)
0362 {
0363 struct search_data *data = _data;
0364 struct jump_key *pos;
0365 int k = 0;
0366
0367 list_for_each_entry(pos, data->head, entries) {
0368 if (pos->offset >= start && pos->offset < end) {
0369 char header[4];
0370
0371 if (k < JUMP_NB) {
0372 int key = '0' + (pos->index % JUMP_NB) + 1;
0373
0374 sprintf(header, "(%c)", key);
0375 data->keys[k] = key;
0376 data->targets[k] = pos->target;
0377 k++;
0378 } else {
0379 sprintf(header, " ");
0380 }
0381
0382 memcpy(buf + pos->offset, header, sizeof(header) - 1);
0383 }
0384 }
0385 data->keys[k] = 0;
0386 }
0387
0388 static void search_conf(void)
0389 {
0390 struct symbol **sym_arr;
0391 struct gstr res;
0392 struct gstr title;
0393 char *dialog_input;
0394 int dres, vscroll = 0, hscroll = 0;
0395 bool again;
0396 struct gstr sttext;
0397 struct subtitle_part stpart;
0398
0399 title = str_new();
0400 str_printf( &title, "Enter (sub)string or regexp to search for "
0401 "(with or without \"%s\")", CONFIG_);
0402
0403 again:
0404 dialog_clear();
0405 dres = dialog_inputbox("Search Configuration Parameter",
0406 str_get(&title),
0407 10, 75, "");
0408 switch (dres) {
0409 case 0:
0410 break;
0411 case 1:
0412 show_helptext("Search Configuration", search_help);
0413 goto again;
0414 default:
0415 str_free(&title);
0416 return;
0417 }
0418
0419
0420 dialog_input = dialog_input_result;
0421 if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
0422 dialog_input += strlen(CONFIG_);
0423
0424 sttext = str_new();
0425 str_printf(&sttext, "Search (%s)", dialog_input_result);
0426 stpart.text = str_get(&sttext);
0427 list_add_tail(&stpart.entries, &trail);
0428
0429 sym_arr = sym_re_search(dialog_input);
0430 do {
0431 LIST_HEAD(head);
0432 struct menu *targets[JUMP_NB];
0433 int keys[JUMP_NB + 1], i;
0434 struct search_data data = {
0435 .head = &head,
0436 .targets = targets,
0437 .keys = keys,
0438 };
0439 struct jump_key *pos, *tmp;
0440
0441 res = get_relations_str(sym_arr, &head);
0442 set_subtitle();
0443 dres = show_textbox_ext("Search Results", (char *)
0444 str_get(&res), 0, 0, keys, &vscroll,
0445 &hscroll, &update_text, (void *)
0446 &data);
0447 again = false;
0448 for (i = 0; i < JUMP_NB && keys[i]; i++)
0449 if (dres == keys[i]) {
0450 conf(targets[i]->parent, targets[i]);
0451 again = true;
0452 }
0453 str_free(&res);
0454 list_for_each_entry_safe(pos, tmp, &head, entries)
0455 free(pos);
0456 } while (again);
0457 free(sym_arr);
0458 str_free(&title);
0459 list_del(trail.prev);
0460 str_free(&sttext);
0461 }
0462
0463 static void build_conf(struct menu *menu)
0464 {
0465 struct symbol *sym;
0466 struct property *prop;
0467 struct menu *child;
0468 int type, tmp, doint = 2;
0469 tristate val;
0470 char ch;
0471 bool visible;
0472
0473
0474
0475
0476
0477 visible = menu_is_visible(menu);
0478 if (show_all_options && !menu_has_prompt(menu))
0479 return;
0480 else if (!show_all_options && !visible)
0481 return;
0482
0483 sym = menu->sym;
0484 prop = menu->prompt;
0485 if (!sym) {
0486 if (prop && menu != current_menu) {
0487 const char *prompt = menu_get_prompt(menu);
0488 switch (prop->type) {
0489 case P_MENU:
0490 child_count++;
0491 if (single_menu_mode) {
0492 item_make("%s%*c%s",
0493 menu->data ? "-->" : "++>",
0494 indent + 1, ' ', prompt);
0495 } else
0496 item_make(" %*c%s %s",
0497 indent + 1, ' ', prompt,
0498 menu_is_empty(menu) ? "----" : "--->");
0499 item_set_tag('m');
0500 item_set_data(menu);
0501 if (single_menu_mode && menu->data)
0502 goto conf_childs;
0503 return;
0504 case P_COMMENT:
0505 if (prompt) {
0506 child_count++;
0507 item_make(" %*c*** %s ***", indent + 1, ' ', prompt);
0508 item_set_tag(':');
0509 item_set_data(menu);
0510 }
0511 break;
0512 default:
0513 if (prompt) {
0514 child_count++;
0515 item_make("---%*c%s", indent + 1, ' ', prompt);
0516 item_set_tag(':');
0517 item_set_data(menu);
0518 }
0519 }
0520 } else
0521 doint = 0;
0522 goto conf_childs;
0523 }
0524
0525 type = sym_get_type(sym);
0526 if (sym_is_choice(sym)) {
0527 struct symbol *def_sym = sym_get_choice_value(sym);
0528 struct menu *def_menu = NULL;
0529
0530 child_count++;
0531 for (child = menu->list; child; child = child->next) {
0532 if (menu_is_visible(child) && child->sym == def_sym)
0533 def_menu = child;
0534 }
0535
0536 val = sym_get_tristate_value(sym);
0537 if (sym_is_changeable(sym)) {
0538 switch (type) {
0539 case S_BOOLEAN:
0540 item_make("[%c]", val == no ? ' ' : '*');
0541 break;
0542 case S_TRISTATE:
0543 switch (val) {
0544 case yes: ch = '*'; break;
0545 case mod: ch = 'M'; break;
0546 default: ch = ' '; break;
0547 }
0548 item_make("<%c>", ch);
0549 break;
0550 }
0551 item_set_tag('t');
0552 item_set_data(menu);
0553 } else {
0554 item_make(" ");
0555 item_set_tag(def_menu ? 't' : ':');
0556 item_set_data(menu);
0557 }
0558
0559 item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
0560 if (val == yes) {
0561 if (def_menu) {
0562 item_add_str(" (%s)", menu_get_prompt(def_menu));
0563 item_add_str(" --->");
0564 if (def_menu->list) {
0565 indent += 2;
0566 build_conf(def_menu);
0567 indent -= 2;
0568 }
0569 }
0570 return;
0571 }
0572 } else {
0573 if (menu == current_menu) {
0574 item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
0575 item_set_tag(':');
0576 item_set_data(menu);
0577 goto conf_childs;
0578 }
0579 child_count++;
0580 val = sym_get_tristate_value(sym);
0581 if (sym_is_choice_value(sym) && val == yes) {
0582 item_make(" ");
0583 item_set_tag(':');
0584 item_set_data(menu);
0585 } else {
0586 switch (type) {
0587 case S_BOOLEAN:
0588 if (sym_is_changeable(sym))
0589 item_make("[%c]", val == no ? ' ' : '*');
0590 else
0591 item_make("-%c-", val == no ? ' ' : '*');
0592 item_set_tag('t');
0593 item_set_data(menu);
0594 break;
0595 case S_TRISTATE:
0596 switch (val) {
0597 case yes: ch = '*'; break;
0598 case mod: ch = 'M'; break;
0599 default: ch = ' '; break;
0600 }
0601 if (sym_is_changeable(sym)) {
0602 if (sym->rev_dep.tri == mod)
0603 item_make("{%c}", ch);
0604 else
0605 item_make("<%c>", ch);
0606 } else
0607 item_make("-%c-", ch);
0608 item_set_tag('t');
0609 item_set_data(menu);
0610 break;
0611 default:
0612 tmp = 2 + strlen(sym_get_string_value(sym));
0613 item_make("(%s)", sym_get_string_value(sym));
0614 tmp = indent - tmp + 4;
0615 if (tmp < 0)
0616 tmp = 0;
0617 item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
0618 (sym_has_value(sym) || !sym_is_changeable(sym)) ?
0619 "" : " (NEW)");
0620 item_set_tag('s');
0621 item_set_data(menu);
0622 goto conf_childs;
0623 }
0624 }
0625 item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
0626 (sym_has_value(sym) || !sym_is_changeable(sym)) ?
0627 "" : " (NEW)");
0628 if (menu->prompt->type == P_MENU) {
0629 item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
0630 return;
0631 }
0632 }
0633
0634 conf_childs:
0635 indent += doint;
0636 for (child = menu->list; child; child = child->next)
0637 build_conf(child);
0638 indent -= doint;
0639 }
0640
0641 static void conf(struct menu *menu, struct menu *active_menu)
0642 {
0643 struct menu *submenu;
0644 const char *prompt = menu_get_prompt(menu);
0645 struct subtitle_part stpart;
0646 struct symbol *sym;
0647 int res;
0648 int s_scroll = 0;
0649
0650 if (menu != &rootmenu)
0651 stpart.text = menu_get_prompt(menu);
0652 else
0653 stpart.text = NULL;
0654 list_add_tail(&stpart.entries, &trail);
0655
0656 while (1) {
0657 item_reset();
0658 current_menu = menu;
0659 build_conf(menu);
0660 if (!child_count)
0661 break;
0662 set_subtitle();
0663 dialog_clear();
0664 res = dialog_menu(prompt ? prompt : "Main Menu",
0665 menu_instructions,
0666 active_menu, &s_scroll);
0667 if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
0668 break;
0669 if (item_count() != 0) {
0670 if (!item_activate_selected())
0671 continue;
0672 if (!item_tag())
0673 continue;
0674 }
0675 submenu = item_data();
0676 active_menu = item_data();
0677 if (submenu)
0678 sym = submenu->sym;
0679 else
0680 sym = NULL;
0681
0682 switch (res) {
0683 case 0:
0684 switch (item_tag()) {
0685 case 'm':
0686 if (single_menu_mode)
0687 submenu->data = (void *) (long) !submenu->data;
0688 else
0689 conf(submenu, NULL);
0690 break;
0691 case 't':
0692 if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
0693 conf_choice(submenu);
0694 else if (submenu->prompt->type == P_MENU)
0695 conf(submenu, NULL);
0696 break;
0697 case 's':
0698 conf_string(submenu);
0699 break;
0700 }
0701 break;
0702 case 2:
0703 if (sym)
0704 show_help(submenu);
0705 else {
0706 reset_subtitle();
0707 show_helptext("README", mconf_readme);
0708 }
0709 break;
0710 case 3:
0711 reset_subtitle();
0712 conf_save();
0713 break;
0714 case 4:
0715 reset_subtitle();
0716 conf_load();
0717 break;
0718 case 5:
0719 if (item_is_tag('t')) {
0720 if (sym_set_tristate_value(sym, yes))
0721 break;
0722 if (sym_set_tristate_value(sym, mod))
0723 show_textbox(NULL, setmod_text, 6, 74);
0724 }
0725 break;
0726 case 6:
0727 if (item_is_tag('t'))
0728 sym_set_tristate_value(sym, no);
0729 break;
0730 case 7:
0731 if (item_is_tag('t'))
0732 sym_set_tristate_value(sym, mod);
0733 break;
0734 case 8:
0735 if (item_is_tag('t'))
0736 sym_toggle_tristate_value(sym);
0737 else if (item_is_tag('m'))
0738 conf(submenu, NULL);
0739 break;
0740 case 9:
0741 search_conf();
0742 break;
0743 case 10:
0744 show_all_options = !show_all_options;
0745 break;
0746 }
0747 }
0748
0749 list_del(trail.prev);
0750 }
0751
0752 static int show_textbox_ext(const char *title, char *text, int r, int c, int
0753 *keys, int *vscroll, int *hscroll, update_text_fn
0754 update_text, void *data)
0755 {
0756 dialog_clear();
0757 return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
0758 update_text, data);
0759 }
0760
0761 static void show_textbox(const char *title, const char *text, int r, int c)
0762 {
0763 show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
0764 NULL, NULL);
0765 }
0766
0767 static void show_helptext(const char *title, const char *text)
0768 {
0769 show_textbox(title, text, 0, 0);
0770 }
0771
0772 static void conf_message_callback(const char *s)
0773 {
0774 if (save_and_exit) {
0775 if (!silent)
0776 printf("%s", s);
0777 } else {
0778 show_textbox(NULL, s, 6, 60);
0779 }
0780 }
0781
0782 static void show_help(struct menu *menu)
0783 {
0784 struct gstr help = str_new();
0785
0786 help.max_width = getmaxx(stdscr) - 10;
0787 menu_get_ext_help(menu, &help);
0788
0789 show_helptext(menu_get_prompt(menu), str_get(&help));
0790 str_free(&help);
0791 }
0792
0793 static void conf_choice(struct menu *menu)
0794 {
0795 const char *prompt = menu_get_prompt(menu);
0796 struct menu *child;
0797 struct symbol *active;
0798
0799 active = sym_get_choice_value(menu->sym);
0800 while (1) {
0801 int res;
0802 int selected;
0803 item_reset();
0804
0805 current_menu = menu;
0806 for (child = menu->list; child; child = child->next) {
0807 if (!menu_is_visible(child))
0808 continue;
0809 if (child->sym)
0810 item_make("%s", menu_get_prompt(child));
0811 else {
0812 item_make("*** %s ***", menu_get_prompt(child));
0813 item_set_tag(':');
0814 }
0815 item_set_data(child);
0816 if (child->sym == active)
0817 item_set_selected(1);
0818 if (child->sym == sym_get_choice_value(menu->sym))
0819 item_set_tag('X');
0820 }
0821 dialog_clear();
0822 res = dialog_checklist(prompt ? prompt : "Main Menu",
0823 radiolist_instructions,
0824 MENUBOX_HEIGTH_MIN,
0825 MENUBOX_WIDTH_MIN,
0826 CHECKLIST_HEIGTH_MIN);
0827 selected = item_activate_selected();
0828 switch (res) {
0829 case 0:
0830 if (selected) {
0831 child = item_data();
0832 if (!child->sym)
0833 break;
0834
0835 sym_set_tristate_value(child->sym, yes);
0836 }
0837 return;
0838 case 1:
0839 if (selected) {
0840 child = item_data();
0841 show_help(child);
0842 active = child->sym;
0843 } else
0844 show_help(menu);
0845 break;
0846 case KEY_ESC:
0847 return;
0848 case -ERRDISPLAYTOOSMALL:
0849 return;
0850 }
0851 }
0852 }
0853
0854 static void conf_string(struct menu *menu)
0855 {
0856 const char *prompt = menu_get_prompt(menu);
0857
0858 while (1) {
0859 int res;
0860 const char *heading;
0861
0862 switch (sym_get_type(menu->sym)) {
0863 case S_INT:
0864 heading = inputbox_instructions_int;
0865 break;
0866 case S_HEX:
0867 heading = inputbox_instructions_hex;
0868 break;
0869 case S_STRING:
0870 heading = inputbox_instructions_string;
0871 break;
0872 default:
0873 heading = "Internal mconf error!";
0874 }
0875 dialog_clear();
0876 res = dialog_inputbox(prompt ? prompt : "Main Menu",
0877 heading, 10, 75,
0878 sym_get_string_value(menu->sym));
0879 switch (res) {
0880 case 0:
0881 if (sym_set_string_value(menu->sym, dialog_input_result))
0882 return;
0883 show_textbox(NULL, "You have made an invalid entry.", 5, 43);
0884 break;
0885 case 1:
0886 show_help(menu);
0887 break;
0888 case KEY_ESC:
0889 return;
0890 }
0891 }
0892 }
0893
0894 static void conf_load(void)
0895 {
0896
0897 while (1) {
0898 int res;
0899 dialog_clear();
0900 res = dialog_inputbox(NULL, load_config_text,
0901 11, 55, filename);
0902 switch(res) {
0903 case 0:
0904 if (!dialog_input_result[0])
0905 return;
0906 if (!conf_read(dialog_input_result)) {
0907 set_config_filename(dialog_input_result);
0908 conf_set_changed(true);
0909 return;
0910 }
0911 show_textbox(NULL, "File does not exist!", 5, 38);
0912 break;
0913 case 1:
0914 show_helptext("Load Alternate Configuration", load_config_help);
0915 break;
0916 case KEY_ESC:
0917 return;
0918 }
0919 }
0920 }
0921
0922 static void conf_save(void)
0923 {
0924 while (1) {
0925 int res;
0926 dialog_clear();
0927 res = dialog_inputbox(NULL, save_config_text,
0928 11, 55, filename);
0929 switch(res) {
0930 case 0:
0931 if (!dialog_input_result[0])
0932 return;
0933 if (!conf_write(dialog_input_result)) {
0934 set_config_filename(dialog_input_result);
0935 return;
0936 }
0937 show_textbox(NULL, "Can't create file!", 5, 60);
0938 break;
0939 case 1:
0940 show_helptext("Save Alternate Configuration", save_config_help);
0941 break;
0942 case KEY_ESC:
0943 return;
0944 }
0945 }
0946 }
0947
0948 static int handle_exit(void)
0949 {
0950 int res;
0951
0952 save_and_exit = 1;
0953 reset_subtitle();
0954 dialog_clear();
0955 if (conf_get_changed())
0956 res = dialog_yesno(NULL,
0957 "Do you wish to save your new configuration?\n"
0958 "(Press <ESC><ESC> to continue kernel configuration.)",
0959 6, 60);
0960 else
0961 res = -1;
0962
0963 end_dialog(saved_x, saved_y);
0964
0965 switch (res) {
0966 case 0:
0967 if (conf_write(filename)) {
0968 fprintf(stderr, "\n\n"
0969 "Error while writing of the configuration.\n"
0970 "Your configuration changes were NOT saved."
0971 "\n\n");
0972 return 1;
0973 }
0974 conf_write_autoconf(0);
0975
0976 case -1:
0977 if (!silent)
0978 printf("\n\n"
0979 "*** End of the configuration.\n"
0980 "*** Execute 'make' to start the build or try 'make help'."
0981 "\n\n");
0982 res = 0;
0983 break;
0984 default:
0985 if (!silent)
0986 fprintf(stderr, "\n\n"
0987 "Your configuration changes were NOT saved."
0988 "\n\n");
0989 if (res != KEY_ESC)
0990 res = 0;
0991 }
0992
0993 return res;
0994 }
0995
0996 static void sig_handler(int signo)
0997 {
0998 exit(handle_exit());
0999 }
1000
1001 int main(int ac, char **av)
1002 {
1003 char *mode;
1004 int res;
1005
1006 signal(SIGINT, sig_handler);
1007
1008 if (ac > 1 && strcmp(av[1], "-s") == 0) {
1009 silent = 1;
1010
1011 conf_set_message_callback(NULL);
1012 av++;
1013 }
1014 conf_parse(av[1]);
1015 conf_read(NULL);
1016
1017 mode = getenv("MENUCONFIG_MODE");
1018 if (mode) {
1019 if (!strcasecmp(mode, "single_menu"))
1020 single_menu_mode = 1;
1021 }
1022
1023 if (init_dialog(NULL)) {
1024 fprintf(stderr, "Your display is too small to run Menuconfig!\n");
1025 fprintf(stderr, "It must be at least 19 lines by 80 columns.\n");
1026 return 1;
1027 }
1028
1029 set_config_filename(conf_get_configname());
1030 conf_set_message_callback(conf_message_callback);
1031 do {
1032 conf(&rootmenu, NULL);
1033 res = handle_exit();
1034 } while (res == KEY_ESC);
1035
1036 return res;
1037 }