2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0.
5 * Introduced single menu mode (show all sub-menus in one large tree).
6 * 2002-11-06 Petr Baudis <pasky@ucw.cz>
8 * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
23 #include "lxdialog/dialog.h"
25 static const char mconf_readme[] = N_(
28 "Some OpenWrt features may be built directly into the image.\n"
29 "Some may be made into installable ipkg packages. Some features\n"
30 "may be completely removed altogether.\n"
32 "Menu items beginning with [*], <M> or [ ] represent features\n"
33 "configured to be included, built as package or removed respectively.\n"
34 "Pointed brackets <> represent packaging capable features.\n"
36 "To change any of these features, highlight it with the cursor\n"
37 "keys and press <Y> to build it in, <M> to make it a module or\n"
38 "<N> to remove it. You may also press the <Space Bar> to cycle\n"
39 "through the available options (i.e. Y->N->M->Y).\n"
41 "Some additional keyboard hints:\n"
45 "o Use the Up/Down arrow keys (cursor keys) to highlight the item you\n"
46 " wish to change or the submenu you wish to select and press <Enter>.\n"
47 " Submenus are designated by \"--->\", empty ones by \"----\".\n"
49 " Shortcut: Press the option's highlighted letter (hotkey).\n"
50 " Pressing a hotkey more than once will sequence\n"
51 " through all visible items which use that hotkey.\n"
53 " You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n"
54 " unseen options into view.\n"
56 "o To exit a menu use the cursor keys to highlight the <Exit> button\n"
57 " and press <ENTER>.\n"
59 " Shortcut: Press <ESC><ESC> or <E> or <X> if there is no hotkey\n"
60 " using those letters. You may press a single <ESC>, but\n"
61 " there is a delayed response which you may find annoying.\n"
63 " Also, the <TAB> and cursor keys will cycle between <Select>,\n"
64 " <Exit>, <Help>, <Save>, and <Load>.\n"
66 "o To get help with an item, use the cursor keys to highlight <Help>\n"
67 " and press <ENTER>.\n"
69 " Shortcut: Press <H> or <?>.\n"
71 "o To toggle the display of hidden options, press <Z>.\n"
74 "Radiolists (Choice lists)\n"
76 "o Use the cursor keys to select the option you wish to set and press\n"
77 " <S> or the <SPACE BAR>.\n"
79 " Shortcut: Press the first letter of the option you wish to set then\n"
80 " press <S> or <SPACE BAR>.\n"
82 "o To see available help for the item, use the cursor keys to highlight\n"
83 " <Help> and Press <ENTER>.\n"
85 " Shortcut: Press <H> or <?>.\n"
87 " Also, the <TAB> and cursor keys will cycle between <Select> and\n"
93 "o Enter the requested information and press <ENTER>\n"
94 " If you are entering hexadecimal values, it is not necessary to\n"
95 " add the '0x' prefix to the entry.\n"
97 "o For help, use the <TAB> or cursor keys to highlight the help option\n"
98 " and press <ENTER>. You can try <TAB><H> as well.\n"
101 "Text Box (Help Window)\n"
103 "o Use the cursor keys to scroll up/down/left/right. The VI editor\n"
104 " keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for\n"
105 " those who are familiar with less and lynx.\n"
107 "o Press <E>, <X>, <q>, <Enter> or <Esc><Esc> to exit.\n"
110 "Alternate Configuration Files\n"
111 "-----------------------------\n"
112 "Menuconfig supports the use of alternate configuration files for\n"
113 "those who, for various reasons, find it necessary to switch\n"
114 "between different configurations.\n"
116 "The <Save> button will let you save the current configuration to\n"
117 "a file of your choosing. Use the <Load> button to load a previously\n"
118 "saved alternate configuration.\n"
120 "Even if you don't use alternate configuration files, but you find\n"
121 "during a Menuconfig session that you have completely messed up your\n"
122 "settings, you may use the <Load> button to restore your previously\n"
123 "saved settings from \".config\" without restarting Menuconfig.\n"
125 "Other information\n"
126 "-----------------\n"
127 "If you use Menuconfig in an XTERM window, make sure you have your\n"
128 "$TERM variable set to point to an xterm definition which supports\n"
129 "color. Otherwise, Menuconfig will look rather bad. Menuconfig will\n"
130 "not display correctly in an RXVT window because rxvt displays only one\n"
131 "intensity of color, bright.\n"
133 "Menuconfig will display larger menus on screens or xterms which are\n"
134 "set to display more than the standard 25 row by 80 column geometry.\n"
135 "In order for this to work, the \"stty size\" command must be able to\n"
136 "display the screen's current row and column geometry. I STRONGLY\n"
137 "RECOMMEND that you make sure you do NOT have the shell variables\n"
138 "LINES and COLUMNS exported into your environment. Some distributions\n"
139 "export those variables via /etc/profile. Some ncurses programs can\n"
140 "become confused when those variables (LINES & COLUMNS) don't reflect\n"
141 "the true screen size.\n"
143 "Optional personality available\n"
144 "------------------------------\n"
145 "If you prefer to have all of the options listed in a single menu,\n"
146 "rather than the default multimenu hierarchy, run the menuconfig with\n"
147 "MENUCONFIG_MODE environment variable set to single_menu. Example:\n"
149 "make MENUCONFIG_MODE=single_menu menuconfig\n"
151 "<Enter> will then unroll the appropriate category, or enfold it if it\n"
152 "is already unrolled.\n"
154 "Note that this mode can eventually be a little more CPU expensive\n"
155 "(especially with a larger number of unrolled categories) than the\n"
158 "Different color themes available\n"
159 "--------------------------------\n"
160 "It is possible to select different color themes using the variable\n"
161 "MENUCONFIG_COLOR. To select a theme use:\n"
163 "make MENUCONFIG_COLOR=<theme> menuconfig\n"
165 "Available themes are\n"
166 " mono => selects colors suitable for monochrome displays\n"
167 " blackbg => selects a color scheme with black background\n"
168 " classic => theme with blue background. The classic look\n"
169 " bluetitle => an LCD friendly version of classic. (default)\n"
171 menu_instructions[] = N_(
172 "Arrow keys navigate the menu. "
173 "<Enter> selects submenus ---> (or empty submenus ----). "
174 "Highlighted letters are hotkeys. "
175 "Pressing <Y> includes, <N> excludes, <M> modularizes features. "
176 "Press <Esc><Esc> to exit, <?> for Help, </> for Search. "
177 "Legend: [*] built-in [ ] excluded <M> module < > module capable"),
178 radiolist_instructions[] = N_(
179 "Use the arrow keys to navigate this window or "
180 "press the hotkey of the item you wish to select "
181 "followed by the <SPACE BAR>. "
182 "Press <?> for additional information about this option."),
183 inputbox_instructions_int[] = N_(
184 "Please enter a decimal value. "
185 "Fractions will not be accepted. "
186 "Use the <TAB> key to move from the input field to the buttons below it."),
187 inputbox_instructions_hex[] = N_(
188 "Please enter a hexadecimal value. "
189 "Use the <TAB> key to move from the input field to the buttons below it."),
190 inputbox_instructions_string[] = N_(
191 "Please enter a string value. "
192 "Use the <TAB> key to move from the input field to the buttons below it."),
194 "This feature depends on another which has been configured as a module.\n"
195 "As a result, this feature will be built as a module."),
196 load_config_text[] = N_(
197 "Enter the name of the configuration file you wish to load. "
198 "Accept the name shown to restore the configuration you "
199 "last retrieved. Leave blank to abort."),
200 load_config_help[] = N_(
202 "For various reasons, one may wish to keep several different\n"
203 "configurations available on a single machine.\n"
205 "If you have saved a previous configuration in a file other than the\n"
206 "default one, entering its name here will allow you to modify that\n"
209 "If you are uncertain, then you have probably never used alternate\n"
210 "configuration files. You should therefore leave this blank to abort.\n"),
211 save_config_text[] = N_(
212 "Enter a filename to which this configuration should be saved "
213 "as an alternate. Leave blank to abort."),
214 save_config_help[] = N_(
216 "For various reasons, one may wish to keep different configurations\n"
217 "available on a single machine.\n"
219 "Entering a file name here will allow you to later retrieve, modify\n"
220 "and use the current configuration as an alternate to whatever\n"
221 "configuration options you have selected at that time.\n"
223 "If you are uncertain what all this means then you should probably\n"
224 "leave this blank.\n"),
227 "Search for symbols and display their relations.\n"
228 "Regular expressions are allowed.\n"
229 "Example: search for \"^FOO\"\n"
231 "-----------------------------------------------------------------\n"
234 "Prompt: Foo bus is used to drive the bar HW\n"
236 " -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
237 " -> PCI support (PCI [=y])\n"
238 "(1) -> PCI access mode (<choice> [=y])\n"
239 " Defined at drivers/pci/Kconfig:47\n"
240 " Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
241 " Selects: LIBCRC32\n"
242 " Selected by: BAR [=n]\n"
243 "-----------------------------------------------------------------\n"
244 "o The line 'Type:' shows the type of the configuration option for\n"
245 " this symbol (boolean, tristate, string, ...)\n"
246 "o The line 'Prompt:' shows the text used in the menu structure for\n"
248 "o The 'Defined at' line tells at what file / line number the symbol\n"
250 "o The 'Depends on:' line tells what symbols need to be defined for\n"
251 " this symbol to be visible in the menu (selectable)\n"
252 "o The 'Location:' lines tells where in the menu structure this symbol\n"
254 " A location followed by a [=y] indicates that this is a\n"
255 " selectable menu item - and the current value is displayed inside\n"
257 " Press the key in the (#) prefix to jump directly to that\n"
258 " location. You will be returned to the current search results\n"
259 " after exiting this new menu.\n"
260 "o The 'Selects:' line tells what symbols will be automatically\n"
261 " selected if this symbol is selected (y or m)\n"
262 "o The 'Selected by' line tells what symbol has selected this symbol\n"
264 "Only relevant lines are shown.\n"
267 "Examples: USB => find all symbols containing USB\n"
268 " ^USB => find all symbols starting with USB\n"
269 " USB$ => find all symbols ending with USB\n"
273 static struct menu *current_menu;
274 static int child_count;
275 static int single_menu_mode;
276 static int show_all_options;
277 static int save_and_exit;
280 static void conf(struct menu *menu, struct menu *active_menu);
281 static void conf_choice(struct menu *menu);
282 static void conf_string(struct menu *menu);
283 static void conf_load(void);
284 static void conf_save(void);
285 static int show_textbox_ext(const char *title, char *text, int r, int c,
286 int *keys, int *vscroll, int *hscroll,
287 update_text_fn update_text, void *data);
288 static void show_textbox(const char *title, const char *text, int r, int c);
289 static void show_helptext(const char *title, const char *text);
290 static void show_help(struct menu *menu);
292 static char filename[PATH_MAX+1];
293 static void set_config_filename(const char *config_filename)
295 static char menu_backtitle[PATH_MAX+128];
298 size = snprintf(menu_backtitle, sizeof(menu_backtitle),
299 "%s - %s", config_filename, rootmenu.prompt->text);
300 if (size >= sizeof(menu_backtitle))
301 menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
302 set_dialog_backtitle(menu_backtitle);
304 size = snprintf(filename, sizeof(filename), "%s", config_filename);
305 if (size >= sizeof(filename))
306 filename[sizeof(filename)-1] = '\0';
309 struct subtitle_part {
310 struct list_head entries;
313 static LIST_HEAD(trail);
315 static struct subtitle_list *subtitles;
316 static void set_subtitle(void)
318 struct subtitle_part *sp;
319 struct subtitle_list *pos, *tmp;
321 for (pos = subtitles; pos != NULL; pos = tmp) {
327 list_for_each_entry(sp, &trail, entries) {
330 pos->next = xcalloc(1, sizeof(*pos));
333 subtitles = pos = xcalloc(1, sizeof(*pos));
335 pos->text = sp->text;
339 set_dialog_subtitles(subtitles);
342 static void reset_subtitle(void)
344 struct subtitle_list *pos, *tmp;
346 for (pos = subtitles; pos != NULL; pos = tmp) {
351 set_dialog_subtitles(subtitles);
355 struct list_head *head;
356 struct menu **targets;
360 static void update_text(char *buf, size_t start, size_t end, void *_data)
362 struct search_data *data = _data;
363 struct jump_key *pos;
366 list_for_each_entry(pos, data->head, entries) {
367 if (pos->offset >= start && pos->offset < end) {
371 int key = '0' + (pos->index % JUMP_NB) + 1;
373 sprintf(header, "(%c)", key);
375 data->targets[k] = pos->target;
378 sprintf(header, " ");
381 memcpy(buf + pos->offset, header, sizeof(header) - 1);
387 static void search_conf(void)
389 struct symbol **sym_arr;
393 int dres, vscroll = 0, hscroll = 0;
396 struct subtitle_part stpart;
399 str_printf( &title, _("Enter (sub)string or regexp to search for "
400 "(with or without \"%s\")"), CONFIG_);
404 dres = dialog_inputbox(_("Search Configuration Parameter"),
411 show_helptext(_("Search Configuration"), search_help);
418 /* strip the prefix if necessary */
419 dialog_input = dialog_input_result;
420 if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
421 dialog_input += strlen(CONFIG_);
424 str_printf(&sttext, "Search (%s)", dialog_input_result);
425 stpart.text = str_get(&sttext);
426 list_add_tail(&stpart.entries, &trail);
428 sym_arr = sym_re_search(dialog_input);
431 struct menu *targets[JUMP_NB];
432 int keys[JUMP_NB + 1], i;
433 struct search_data data = {
438 struct jump_key *pos, *tmp;
440 res = get_relations_str(sym_arr, &head);
442 dres = show_textbox_ext(_("Search Results"), (char *)
443 str_get(&res), 0, 0, keys, &vscroll,
444 &hscroll, &update_text, (void *)
447 for (i = 0; i < JUMP_NB && keys[i]; i++)
448 if (dres == keys[i]) {
449 conf(targets[i]->parent, targets[i]);
453 list_for_each_entry_safe(pos, tmp, &head, entries)
458 list_del(trail.prev);
462 static void build_conf(struct menu *menu)
465 struct property *prop;
467 int type, tmp, doint = 2;
473 * note: menu_is_visible() has side effect that it will
474 * recalc the value of the symbol.
476 visible = menu_is_visible(menu);
477 if (show_all_options && !menu_has_prompt(menu))
479 else if (!show_all_options && !visible)
485 if (prop && menu != current_menu) {
486 const char *prompt = menu_get_prompt(menu);
487 switch (prop->type) {
491 if (single_menu_mode) {
493 menu->data ? "-->" : "++>",
494 indent + 1, ' ', prompt);
496 item_make(" %*c%s %s",
497 indent + 1, ' ', prompt,
498 menu_is_empty(menu) ? "----" : "--->");
501 if (single_menu_mode && menu->data)
507 item_make(" %*c*** %s ***", indent + 1, ' ', _(prompt));
515 item_make("---%*c%s", indent + 1, ' ', _(prompt));
525 type = sym_get_type(sym);
526 if (sym_is_choice(sym)) {
527 struct symbol *def_sym = sym_get_choice_value(sym);
528 struct menu *def_menu = NULL;
531 for (child = menu->list; child; child = child->next) {
532 if (menu_is_visible(child) && child->sym == def_sym)
536 val = sym_get_tristate_value(sym);
537 if (sym_is_changable(sym)) {
540 item_make("[%c]", val == no ? ' ' : '*');
544 case yes: ch = '*'; break;
545 case mod: ch = 'M'; break;
546 default: ch = ' '; break;
548 item_make("<%c>", ch);
555 item_set_tag(def_menu ? 't' : ':');
559 item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
562 item_add_str(" (%s)", _(menu_get_prompt(def_menu)));
563 item_add_str(" --->");
564 if (def_menu->list) {
566 build_conf(def_menu);
573 if (menu == current_menu) {
574 item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
580 val = sym_get_tristate_value(sym);
581 if (sym_is_choice_value(sym) && val == yes) {
588 if (sym_is_changable(sym))
589 item_make("[%c]", val == no ? ' ' : '*');
591 item_make("-%c-", val == no ? ' ' : '*');
597 case yes: ch = '*'; break;
598 case mod: ch = 'M'; break;
599 default: ch = ' '; break;
601 if (sym_is_changable(sym)) {
602 if (sym->rev_dep.tri == mod)
603 item_make("{%c}", ch);
605 item_make("<%c>", ch);
607 item_make("-%c-", ch);
612 tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
613 item_make("(%s)", sym_get_string_value(sym));
614 tmp = indent - tmp + 4;
617 item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)),
618 (sym_has_value(sym) || !sym_is_changable(sym)) ?
625 item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)),
626 (sym_has_value(sym) || !sym_is_changable(sym)) ?
628 if (menu->prompt->type == P_MENU) {
629 item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
636 for (child = menu->list; child; child = child->next)
641 static void conf(struct menu *menu, struct menu *active_menu)
643 struct menu *submenu;
644 const char *prompt = menu_get_prompt(menu);
645 struct subtitle_part stpart;
650 if (menu != &rootmenu)
651 stpart.text = menu_get_prompt(menu);
654 list_add_tail(&stpart.entries, &trail);
664 res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
665 _(menu_instructions),
666 active_menu, &s_scroll);
667 if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
669 if (item_count() != 0) {
670 if (!item_activate_selected())
675 submenu = item_data();
676 active_menu = item_data();
684 switch (item_tag()) {
686 if (single_menu_mode)
687 submenu->data = (void *) (long) !submenu->data;
692 if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
693 conf_choice(submenu);
694 else if (submenu->prompt->type == P_MENU)
698 conf_string(submenu);
707 show_helptext(_("README"), _(mconf_readme));
719 if (item_is_tag('t')) {
720 if (sym_set_tristate_value(sym, yes))
722 if (sym_set_tristate_value(sym, mod))
723 show_textbox(NULL, setmod_text, 6, 74);
727 if (item_is_tag('t'))
728 sym_set_tristate_value(sym, no);
731 if (item_is_tag('t'))
732 sym_set_tristate_value(sym, mod);
735 if (item_is_tag('t'))
736 sym_toggle_tristate_value(sym);
737 else if (item_is_tag('m'))
744 show_all_options = !show_all_options;
749 list_del(trail.prev);
752 static int show_textbox_ext(const char *title, char *text, int r, int c, int
753 *keys, int *vscroll, int *hscroll, update_text_fn
754 update_text, void *data)
757 return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
761 static void show_textbox(const char *title, const char *text, int r, int c)
763 show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
767 static void show_helptext(const char *title, const char *text)
769 show_textbox(title, text, 0, 0);
772 static void conf_message_callback(const char *fmt, va_list ap)
774 char buf[PATH_MAX+1];
776 vsnprintf(buf, sizeof(buf), fmt, ap);
781 show_textbox(NULL, buf, 6, 60);
785 static void show_help(struct menu *menu)
787 struct gstr help = str_new();
789 help.max_width = getmaxx(stdscr) - 10;
790 menu_get_ext_help(menu, &help);
792 show_helptext(_(menu_get_prompt(menu)), str_get(&help));
796 static void conf_choice(struct menu *menu)
798 const char *prompt = _(menu_get_prompt(menu));
800 struct symbol *active;
801 struct property *prop;
803 active = sym_get_choice_value(menu->sym);
810 for (child = menu->list; child; child = child->next) {
811 if (!menu_is_visible(child))
814 item_make("%s", _(menu_get_prompt(child)));
816 item_make("*** %s ***", _(menu_get_prompt(child)));
819 item_set_data(child);
820 if (child->sym == active)
821 item_set_selected(1);
822 if (child->sym == sym_get_choice_value(menu->sym))
826 res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
827 _(radiolist_instructions),
830 CHECKLIST_HEIGTH_MIN);
831 selected = item_activate_selected();
839 if (sym_get_tristate_value(child->sym) != yes) {
840 for_all_properties(menu->sym, prop, P_RESET) {
841 if (expr_calc_value(prop->visible.expr) == no)
844 conf_reset(S_DEF_USER);
848 sym_set_tristate_value(child->sym, yes);
861 case -ERRDISPLAYTOOSMALL:
867 static void conf_string(struct menu *menu)
869 const char *prompt = menu_get_prompt(menu);
875 switch (sym_get_type(menu->sym)) {
877 heading = _(inputbox_instructions_int);
880 heading = _(inputbox_instructions_hex);
883 heading = _(inputbox_instructions_string);
886 heading = _("Internal mconf error!");
889 res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
891 sym_get_string_value(menu->sym));
894 if (sym_set_string_value(menu->sym, dialog_input_result))
896 show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
907 static void conf_load(void)
913 res = dialog_inputbox(NULL, load_config_text,
917 if (!dialog_input_result[0])
919 if (!conf_read(dialog_input_result)) {
920 set_config_filename(dialog_input_result);
921 sym_set_change_count(1);
924 show_textbox(NULL, _("File does not exist!"), 5, 38);
927 show_helptext(_("Load Alternate Configuration"), load_config_help);
935 static void conf_save(void)
940 res = dialog_inputbox(NULL, save_config_text,
944 if (!dialog_input_result[0])
946 if (!conf_write(dialog_input_result)) {
947 set_config_filename(dialog_input_result);
950 show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60);
953 show_helptext(_("Save Alternate Configuration"), save_config_help);
961 static int handle_exit(void)
968 if (conf_get_changed())
969 res = dialog_yesno(NULL,
970 _("Do you wish to save your new configuration?\n"
971 "(Press <ESC><ESC> to continue kernel configuration.)"),
976 end_dialog(saved_x, saved_y);
980 if (conf_write(filename)) {
981 fprintf(stderr, _("\n\n"
982 "Error while writing of the configuration.\n"
983 "Your configuration changes were NOT saved."
991 "*** End of the configuration.\n"
992 "*** Execute 'make' to start the build or try 'make help'."
998 fprintf(stderr, _("\n\n"
999 "Your configuration changes were NOT saved."
1008 static void sig_handler(int signo)
1010 exit(handle_exit());
1013 int main(int ac, char **av)
1018 setlocale(LC_ALL, "");
1019 bindtextdomain(PACKAGE, LOCALEDIR);
1020 textdomain(PACKAGE);
1022 signal(SIGINT, sig_handler);
1024 if (ac > 1 && strcmp(av[1], "-s") == 0) {
1026 /* Silence conf_read() until the real callback is set up */
1027 conf_set_message_callback(NULL);
1033 mode = getenv("MENUCONFIG_MODE");
1035 if (!strcasecmp(mode, "single_menu"))
1036 single_menu_mode = 1;
1039 if (init_dialog(NULL)) {
1040 fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
1041 fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
1045 set_config_filename(conf_get_configname());
1046 conf_set_message_callback(conf_message_callback);
1048 conf(&rootmenu, NULL);
1049 res = handle_exit();
1050 } while (res == KEY_ESC);