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;
279 static void conf(struct menu *menu, struct menu *active_menu);
280 static void conf_choice(struct menu *menu);
281 static void conf_string(struct menu *menu);
282 static void conf_load(void);
283 static void conf_save(void);
284 static int show_textbox_ext(const char *title, char *text, int r, int c,
285 int *keys, int *vscroll, int *hscroll,
286 update_text_fn update_text, void *data);
287 static void show_textbox(const char *title, const char *text, int r, int c);
288 static void show_helptext(const char *title, const char *text);
289 static void show_help(struct menu *menu);
291 static char filename[PATH_MAX+1];
292 static void set_config_filename(const char *config_filename)
294 static char menu_backtitle[PATH_MAX+128];
297 size = snprintf(menu_backtitle, sizeof(menu_backtitle),
298 "%s - %s", config_filename, rootmenu.prompt->text);
299 if (size >= sizeof(menu_backtitle))
300 menu_backtitle[sizeof(menu_backtitle)-1] = '\0';
301 set_dialog_backtitle(menu_backtitle);
303 size = snprintf(filename, sizeof(filename), "%s", config_filename);
304 if (size >= sizeof(filename))
305 filename[sizeof(filename)-1] = '\0';
308 struct subtitle_part {
309 struct list_head entries;
312 static LIST_HEAD(trail);
314 static struct subtitle_list *subtitles;
315 static void set_subtitle(void)
317 struct subtitle_part *sp;
318 struct subtitle_list *pos, *tmp;
320 for (pos = subtitles; pos != NULL; pos = tmp) {
326 list_for_each_entry(sp, &trail, entries) {
329 pos->next = xcalloc(1, sizeof(*pos));
332 subtitles = pos = xcalloc(1, sizeof(*pos));
334 pos->text = sp->text;
338 set_dialog_subtitles(subtitles);
341 static void reset_subtitle(void)
343 struct subtitle_list *pos, *tmp;
345 for (pos = subtitles; pos != NULL; pos = tmp) {
350 set_dialog_subtitles(subtitles);
354 struct list_head *head;
355 struct menu **targets;
359 static void update_text(char *buf, size_t start, size_t end, void *_data)
361 struct search_data *data = _data;
362 struct jump_key *pos;
365 list_for_each_entry(pos, data->head, entries) {
366 if (pos->offset >= start && pos->offset < end) {
370 int key = '0' + (pos->index % JUMP_NB) + 1;
372 sprintf(header, "(%c)", key);
374 data->targets[k] = pos->target;
377 sprintf(header, " ");
380 memcpy(buf + pos->offset, header, sizeof(header) - 1);
386 static void search_conf(void)
388 struct symbol **sym_arr;
392 int dres, vscroll = 0, hscroll = 0;
395 struct subtitle_part stpart;
398 str_printf( &title, _("Enter (sub)string or regexp to search for "
399 "(with or without \"%s\")"), CONFIG_);
403 dres = dialog_inputbox(_("Search Configuration Parameter"),
410 show_helptext(_("Search Configuration"), search_help);
417 /* strip the prefix if necessary */
418 dialog_input = dialog_input_result;
419 if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
420 dialog_input += strlen(CONFIG_);
423 str_printf(&sttext, "Search (%s)", dialog_input_result);
424 stpart.text = str_get(&sttext);
425 list_add_tail(&stpart.entries, &trail);
427 sym_arr = sym_re_search(dialog_input);
430 struct menu *targets[JUMP_NB];
431 int keys[JUMP_NB + 1], i;
432 struct search_data data = {
437 struct jump_key *pos, *tmp;
439 res = get_relations_str(sym_arr, &head);
441 dres = show_textbox_ext(_("Search Results"), (char *)
442 str_get(&res), 0, 0, keys, &vscroll,
443 &hscroll, &update_text, (void *)
446 for (i = 0; i < JUMP_NB && keys[i]; i++)
447 if (dres == keys[i]) {
448 conf(targets[i]->parent, targets[i]);
452 list_for_each_entry_safe(pos, tmp, &head, entries)
457 list_del(trail.prev);
461 static void build_conf(struct menu *menu)
464 struct property *prop;
466 int type, tmp, doint = 2;
472 * note: menu_is_visible() has side effect that it will
473 * recalc the value of the symbol.
475 visible = menu_is_visible(menu);
476 if (show_all_options && !menu_has_prompt(menu))
478 else if (!show_all_options && !visible)
484 if (prop && menu != current_menu) {
485 const char *prompt = menu_get_prompt(menu);
486 switch (prop->type) {
490 if (single_menu_mode) {
492 menu->data ? "-->" : "++>",
493 indent + 1, ' ', prompt);
495 item_make(" %*c%s %s",
496 indent + 1, ' ', prompt,
497 menu_is_empty(menu) ? "----" : "--->");
500 if (single_menu_mode && menu->data)
506 item_make(" %*c*** %s ***", indent + 1, ' ', _(prompt));
514 item_make("---%*c%s", indent + 1, ' ', _(prompt));
524 type = sym_get_type(sym);
525 if (sym_is_choice(sym)) {
526 struct symbol *def_sym = sym_get_choice_value(sym);
527 struct menu *def_menu = NULL;
530 for (child = menu->list; child; child = child->next) {
531 if (menu_is_visible(child) && child->sym == def_sym)
535 val = sym_get_tristate_value(sym);
536 if (sym_is_changable(sym)) {
539 item_make("[%c]", val == no ? ' ' : '*');
543 case yes: ch = '*'; break;
544 case mod: ch = 'M'; break;
545 default: ch = ' '; break;
547 item_make("<%c>", ch);
554 item_set_tag(def_menu ? 't' : ':');
558 item_add_str("%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
561 item_add_str(" (%s)", _(menu_get_prompt(def_menu)));
562 item_add_str(" --->");
563 if (def_menu->list) {
565 build_conf(def_menu);
572 if (menu == current_menu) {
573 item_make("---%*c%s", indent + 1, ' ', _(menu_get_prompt(menu)));
579 val = sym_get_tristate_value(sym);
580 if (sym_is_choice_value(sym) && val == yes) {
587 if (sym_is_changable(sym))
588 item_make("[%c]", val == no ? ' ' : '*');
590 item_make("-%c-", val == no ? ' ' : '*');
596 case yes: ch = '*'; break;
597 case mod: ch = 'M'; break;
598 default: ch = ' '; break;
600 if (sym_is_changable(sym)) {
601 if (sym->rev_dep.tri == mod)
602 item_make("{%c}", ch);
604 item_make("<%c>", ch);
606 item_make("-%c-", ch);
611 tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
612 item_make("(%s)", sym_get_string_value(sym));
613 tmp = indent - tmp + 4;
616 item_add_str("%*c%s%s", tmp, ' ', _(menu_get_prompt(menu)),
617 (sym_has_value(sym) || !sym_is_changable(sym)) ?
624 item_add_str("%*c%s%s", indent + 1, ' ', _(menu_get_prompt(menu)),
625 (sym_has_value(sym) || !sym_is_changable(sym)) ?
627 if (menu->prompt->type == P_MENU) {
628 item_add_str(" %s", menu_is_empty(menu) ? "----" : "--->");
635 for (child = menu->list; child; child = child->next)
640 static void conf(struct menu *menu, struct menu *active_menu)
642 struct menu *submenu;
643 const char *prompt = menu_get_prompt(menu);
644 struct subtitle_part stpart;
649 if (menu != &rootmenu)
650 stpart.text = menu_get_prompt(menu);
653 list_add_tail(&stpart.entries, &trail);
663 res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
664 _(menu_instructions),
665 active_menu, &s_scroll);
666 if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
668 if (item_count() != 0) {
669 if (!item_activate_selected())
674 submenu = item_data();
675 active_menu = item_data();
683 switch (item_tag()) {
685 if (single_menu_mode)
686 submenu->data = (void *) (long) !submenu->data;
691 if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
692 conf_choice(submenu);
693 else if (submenu->prompt->type == P_MENU)
697 conf_string(submenu);
706 show_helptext(_("README"), _(mconf_readme));
718 if (item_is_tag('t')) {
719 if (sym_set_tristate_value(sym, yes))
721 if (sym_set_tristate_value(sym, mod))
722 show_textbox(NULL, setmod_text, 6, 74);
726 if (item_is_tag('t'))
727 sym_set_tristate_value(sym, no);
730 if (item_is_tag('t'))
731 sym_set_tristate_value(sym, mod);
734 if (item_is_tag('t'))
735 sym_toggle_tristate_value(sym);
736 else if (item_is_tag('m'))
743 show_all_options = !show_all_options;
748 list_del(trail.prev);
751 static int show_textbox_ext(const char *title, char *text, int r, int c, int
752 *keys, int *vscroll, int *hscroll, update_text_fn
753 update_text, void *data)
756 return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
760 static void show_textbox(const char *title, const char *text, int r, int c)
762 show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
766 static void show_helptext(const char *title, const char *text)
768 show_textbox(title, text, 0, 0);
771 static void conf_message_callback(const char *fmt, va_list ap)
773 char buf[PATH_MAX+1];
775 vsnprintf(buf, sizeof(buf), fmt, ap);
779 show_textbox(NULL, buf, 6, 60);
782 static void show_help(struct menu *menu)
784 struct gstr help = str_new();
786 help.max_width = getmaxx(stdscr) - 10;
787 menu_get_ext_help(menu, &help);
789 show_helptext(_(menu_get_prompt(menu)), str_get(&help));
793 static void conf_choice(struct menu *menu)
795 const char *prompt = _(menu_get_prompt(menu));
797 struct symbol *active;
798 struct property *prop;
800 active = sym_get_choice_value(menu->sym);
807 for (child = menu->list; child; child = child->next) {
808 if (!menu_is_visible(child))
811 item_make("%s", _(menu_get_prompt(child)));
813 item_make("*** %s ***", _(menu_get_prompt(child)));
816 item_set_data(child);
817 if (child->sym == active)
818 item_set_selected(1);
819 if (child->sym == sym_get_choice_value(menu->sym))
823 res = dialog_checklist(prompt ? _(prompt) : _("Main Menu"),
824 _(radiolist_instructions),
827 CHECKLIST_HEIGTH_MIN);
828 selected = item_activate_selected();
836 if (sym_get_tristate_value(child->sym) != yes) {
837 for_all_properties(menu->sym, prop, P_RESET) {
838 if (expr_calc_value(prop->visible.expr) == no)
841 conf_reset(S_DEF_USER);
845 sym_set_tristate_value(child->sym, yes);
858 case -ERRDISPLAYTOOSMALL:
864 static void conf_string(struct menu *menu)
866 const char *prompt = menu_get_prompt(menu);
872 switch (sym_get_type(menu->sym)) {
874 heading = _(inputbox_instructions_int);
877 heading = _(inputbox_instructions_hex);
880 heading = _(inputbox_instructions_string);
883 heading = _("Internal mconf error!");
886 res = dialog_inputbox(prompt ? _(prompt) : _("Main Menu"),
888 sym_get_string_value(menu->sym));
891 if (sym_set_string_value(menu->sym, dialog_input_result))
893 show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
904 static void conf_load(void)
910 res = dialog_inputbox(NULL, load_config_text,
914 if (!dialog_input_result[0])
916 if (!conf_read(dialog_input_result)) {
917 set_config_filename(dialog_input_result);
918 sym_set_change_count(1);
921 show_textbox(NULL, _("File does not exist!"), 5, 38);
924 show_helptext(_("Load Alternate Configuration"), load_config_help);
932 static void conf_save(void)
937 res = dialog_inputbox(NULL, save_config_text,
941 if (!dialog_input_result[0])
943 if (!conf_write(dialog_input_result)) {
944 set_config_filename(dialog_input_result);
947 show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60);
950 show_helptext(_("Save Alternate Configuration"), save_config_help);
958 static int handle_exit(void)
965 if (conf_get_changed())
966 res = dialog_yesno(NULL,
967 _("Do you wish to save your new configuration?\n"
968 "(Press <ESC><ESC> to continue kernel configuration.)"),
973 end_dialog(saved_x, saved_y);
977 if (conf_write(filename)) {
978 fprintf(stderr, _("\n\n"
979 "Error while writing of the configuration.\n"
980 "Your configuration changes were NOT saved."
987 "*** End of the configuration.\n"
988 "*** Execute 'make' to start the build or try 'make help'."
993 fprintf(stderr, _("\n\n"
994 "Your configuration changes were NOT saved."
1003 static void sig_handler(int signo)
1005 exit(handle_exit());
1008 int main(int ac, char **av)
1013 setlocale(LC_ALL, "");
1014 bindtextdomain(PACKAGE, LOCALEDIR);
1015 textdomain(PACKAGE);
1017 signal(SIGINT, sig_handler);
1022 mode = getenv("MENUCONFIG_MODE");
1024 if (!strcasecmp(mode, "single_menu"))
1025 single_menu_mode = 1;
1028 if (init_dialog(NULL)) {
1029 fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
1030 fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
1034 set_config_filename(conf_get_configname());
1035 conf_set_message_callback(conf_message_callback);
1037 conf(&rootmenu, NULL);
1038 res = handle_exit();
1039 } while (res == KEY_ESC);