summaryrefslogtreecommitdiff
path: root/scripts/kconfig/mconf.c
Unidiff
Diffstat (limited to 'scripts/kconfig/mconf.c') (more/less context) (show whitespace changes)
-rw-r--r--scripts/kconfig/mconf.c91
1 files changed, 80 insertions, 11 deletions
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index dec8603..eba5ff7 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -1,26 +1,31 @@
1/* 1/*
2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> 2 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
3 * Released under the terms of the GNU GPL v2.0. 3 * Released under the terms of the GNU GPL v2.0.
4 *
5 * Introduced single menu mode (show all sub-menus in one large tree).
6 * 2002-11-06 Petr Baudis <pasky@ucw.cz>
4 */ 7 */
5 8
6#include <sys/ioctl.h> 9#include <sys/ioctl.h>
7#include <sys/wait.h> 10#include <sys/wait.h>
8#include <ctype.h> 11#include <ctype.h>
9#include <errno.h> 12#include <errno.h>
10#include <fcntl.h> 13#include <fcntl.h>
14#include <limits.h>
11#include <signal.h> 15#include <signal.h>
12#include <stdarg.h> 16#include <stdarg.h>
13#include <stdlib.h> 17#include <stdlib.h>
14#include <string.h> 18#include <string.h>
19#include <termios.h>
15#include <unistd.h> 20#include <unistd.h>
16 21
17#define LKC_DIRECT_LINK 22#define LKC_DIRECT_LINK
18#include "lkc.h" 23#include "lkc.h"
19 24
20static char menu_backtitle[128]; 25static char menu_backtitle[128];
21static const char menu_instructions[] = 26static const char menu_instructions[] =
22 "Arrow keys navigate the menu. " 27 "Arrow keys navigate the menu. "
23 "<Enter> selects submenus --->. " 28 "<Enter> selects submenus --->. "
24 "Highlighted letters are hotkeys. " 29 "Highlighted letters are hotkeys. "
25 "Pressing <Y> includes, <N> excludes, <M> modularizes features. " 30 "Pressing <Y> includes, <N> excludes, <M> modularizes features. "
26 "Press <Esc><Esc> to exit, <?> for Help. " 31 "Press <Esc><Esc> to exit, <?> for Help. "
@@ -35,90 +40,108 @@ inputbox_instructions_int[] =
35 "Fractions will not be accepted. " 40 "Fractions will not be accepted. "
36 "Use the <TAB> key to move from the input field to the buttons below it.", 41 "Use the <TAB> key to move from the input field to the buttons below it.",
37inputbox_instructions_hex[] = 42inputbox_instructions_hex[] =
38 "Please enter a hexadecimal value. " 43 "Please enter a hexadecimal value. "
39 "Use the <TAB> key to move from the input field to the buttons below it.", 44 "Use the <TAB> key to move from the input field to the buttons below it.",
40inputbox_instructions_string[] = 45inputbox_instructions_string[] =
41 "Please enter a string value. " 46 "Please enter a string value. "
42 "Use the <TAB> key to move from the input field to the buttons below it.", 47 "Use the <TAB> key to move from the input field to the buttons below it.",
43setmod_text[] = 48setmod_text[] =
44 "This feature depends on another which has been configured as a module.\n" 49 "This feature depends on another which has been configured as a module.\n"
45 "As a result, this feature will be built as a module.", 50 "As a result, this feature will be built as a module.",
46nohelp_text[] = 51nohelp_text[] =
47 "There is no help available for this option.\n", 52 "There is no help available for this kernel option.\n",
48load_config_text[] = 53load_config_text[] =
49 "Enter the name of the configuration file you wish to load. " 54 "Enter the name of the configuration file you wish to load. "
50 "Accept the name shown to restore the configuration you " 55 "Accept the name shown to restore the configuration you "
51 "last retrieved. Leave blank to abort.", 56 "last retrieved. Leave blank to abort.",
52load_config_help[] = 57load_config_help[] =
53 "\n" 58 "\n"
54 "For various reasons, one may wish to keep several different\n" 59 "For various reasons, one may wish to keep several different kernel\n"
55 "configurations available on a single machine.\n" 60 "configurations available on a single machine.\n"
56 "\n" 61 "\n"
57 "If you have saved a previous configuration in a file other than the\n" 62 "If you have saved a previous configuration in a file other than the\n"
58 "default, entering the name of the file here will allow you\n" 63 "kernel's default, entering the name of the file here will allow you\n"
59 "to modify that configuration.\n" 64 "to modify that configuration.\n"
60 "\n" 65 "\n"
61 "If you are uncertain, then you have probably never used alternate\n" 66 "If you are uncertain, then you have probably never used alternate\n"
62 "configuration files. You should therefor leave this blank to abort.\n", 67 "configuration files. You should therefor leave this blank to abort.\n",
63save_config_text[] = 68save_config_text[] =
64 "Enter a filename to which this configuration should be saved " 69 "Enter a filename to which this configuration should be saved "
65 "as an alternate. Leave blank to abort.", 70 "as an alternate. Leave blank to abort.",
66save_config_help[] = 71save_config_help[] =
67 "\n" 72 "\n"
68 "For various reasons, one may wish to keep different\n" 73 "For various reasons, one may wish to keep different kernel\n"
69 "configurations available on a single machine.\n" 74 "configurations available on a single machine.\n"
70 "\n" 75 "\n"
71 "Entering a file name here will allow you to later retrieve, modify\n" 76 "Entering a file name here will allow you to later retrieve, modify\n"
72 "and use the current configuration as an alternate to whatever\n" 77 "and use the current configuration as an alternate to whatever\n"
73 "configuration options you have selected at that time.\n" 78 "configuration options you have selected at that time.\n"
74 "\n" 79 "\n"
75 "If you are uncertain what all this means then you should probably\n" 80 "If you are uncertain what all this means then you should probably\n"
76 "leave this blank.\n" 81 "leave this blank.\n"
77; 82;
78 83
79static char buf[4096], *bufptr = buf; 84static char buf[4096], *bufptr = buf;
80static char input_buf[4096]; 85static char input_buf[4096];
86static char filename[PATH_MAX+1] = ".config";
81static char *args[1024], **argptr = args; 87static char *args[1024], **argptr = args;
82static int indent = 0; 88static int indent = 0;
89static struct termios ios_org;
83static int rows, cols; 90static int rows, cols;
84static struct menu *current_menu; 91static struct menu *current_menu;
85static int child_count; 92static int child_count;
86static int do_resize; 93static int do_resize;
94static int single_menu_mode;
87 95
88static void conf(struct menu *menu); 96static void conf(struct menu *menu);
89static void conf_choice(struct menu *menu); 97static void conf_choice(struct menu *menu);
90static void conf_string(struct menu *menu); 98static void conf_string(struct menu *menu);
91static void conf_load(void); 99static void conf_load(void);
92static void conf_save(void); 100static void conf_save(void);
93static void show_textbox(const char *title, const char *text, int r, int c); 101static void show_textbox(const char *title, const char *text, int r, int c);
94static void show_helptext(const char *title, const char *text); 102static void show_helptext(const char *title, const char *text);
95static void show_help(struct menu *menu); 103static void show_help(struct menu *menu);
96static void show_readme(void); 104static void show_readme(void);
97 105
98static void cprint_init(void); 106static void cprint_init(void);
99static int cprint1(const char *fmt, ...); 107static int cprint1(const char *fmt, ...);
100static void cprint_done(void); 108static void cprint_done(void);
101static int cprint(const char *fmt, ...); 109static int cprint(const char *fmt, ...);
102 110
103static void init_wsize(void) 111static void init_wsize(void)
104{ 112{
105 struct winsize ws; 113 struct winsize ws;
114 char *env;
106 115
107 if (ioctl(1, TIOCGWINSZ, &ws) == -1) { 116 if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
108 rows = 24; 117 rows = 24;
109 cols = 80; 118 cols = 80;
110 } else { 119 } else {
111 rows = ws.ws_row; 120 rows = ws.ws_row;
112 cols = ws.ws_col; 121 cols = ws.ws_col;
122 if (!rows) {
123 env = getenv("LINES");
124 if (env)
125 rows = atoi(env);
126 if (!rows)
127 rows = 24;
128 }
129 if (!cols) {
130 env = getenv("COLUMNS");
131 if (env)
132 cols = atoi(env);
133 if (!cols)
134 cols = 80;
135 }
113 } 136 }
114 137
115 if (rows < 19 || cols < 80) { 138 if (rows < 19 || cols < 80) {
116 fprintf(stderr, "Your display is too small to run Menuconfig!\n"); 139 fprintf(stderr, "Your display is too small to run Menuconfig!\n");
117 fprintf(stderr, "It must be at least 19 lines by 80 columns.\n"); 140 fprintf(stderr, "It must be at least 19 lines by 80 columns.\n");
118 exit(1); 141 exit(1);
119 } 142 }
120 143
121 rows -= 4; 144 rows -= 4;
122 cols -= 5; 145 cols -= 5;
123} 146}
124 147
@@ -265,28 +288,38 @@ static void build_conf(struct menu *menu)
265 if (!menu_is_visible(menu)) 288 if (!menu_is_visible(menu))
266 return; 289 return;
267 290
268 sym = menu->sym; 291 sym = menu->sym;
269 prop = menu->prompt; 292 prop = menu->prompt;
270 if (!sym) { 293 if (!sym) {
271 if (prop && menu != current_menu) { 294 if (prop && menu != current_menu) {
272 const char *prompt = menu_get_prompt(menu); 295 const char *prompt = menu_get_prompt(menu);
273 switch (prop->type) { 296 switch (prop->type) {
274 case P_MENU: 297 case P_MENU:
275 child_count++; 298 child_count++;
276 cprint("m%p", menu); 299 cprint("m%p", menu);
300
301 if (single_menu_mode) {
302 cprint1("%s%*c%s",
303 menu->data ? "-->" : "++>",
304 indent + 1, ' ', prompt);
305 } else {
277 if (menu->parent != &rootmenu) 306 if (menu->parent != &rootmenu)
278 cprint1(" %*c", indent + 1, ' '); 307 cprint1(" %*c", indent + 1, ' ');
279 cprint1("%s --->", prompt); 308 cprint1("%s --->", prompt);
309 }
310
280 cprint_done(); 311 cprint_done();
312 if (single_menu_mode && menu->data)
313 goto conf_childs;
281 return; 314 return;
282 default: 315 default:
283 if (prompt) { 316 if (prompt) {
284 child_count++; 317 child_count++;
285 cprint(":%p", menu); 318 cprint(":%p", menu);
286 cprint("---%*c%s", indent + 1, ' ', prompt); 319 cprint("---%*c%s", indent + 1, ' ', prompt);
287 } 320 }
288 } 321 }
289 } else 322 } else
290 doint = 0; 323 doint = 0;
291 goto conf_childs; 324 goto conf_childs;
292 } 325 }
@@ -383,24 +416,25 @@ conf_childs:
383 build_conf(child); 416 build_conf(child);
384 indent -= doint; 417 indent -= doint;
385} 418}
386 419
387static void conf(struct menu *menu) 420static void conf(struct menu *menu)
388{ 421{
389 struct menu *submenu; 422 struct menu *submenu;
390 const char *prompt = menu_get_prompt(menu); 423 const char *prompt = menu_get_prompt(menu);
391 struct symbol *sym; 424 struct symbol *sym;
392 char active_entry[40]; 425 char active_entry[40];
393 int stat, type, i; 426 int stat, type, i;
394 427
428 unlink("lxdialog.scrltmp");
395 active_entry[0] = 0; 429 active_entry[0] = 0;
396 while (1) { 430 while (1) {
397 cprint_init(); 431 cprint_init();
398 cprint("--title"); 432 cprint("--title");
399 cprint("%s", prompt ? prompt : "Main Menu"); 433 cprint("%s", prompt ? prompt : "Main Menu");
400 cprint("--menu"); 434 cprint("--menu");
401 cprint(menu_instructions); 435 cprint(menu_instructions);
402 cprint("%d", rows); 436 cprint("%d", rows);
403 cprint("%d", cols); 437 cprint("%d", cols);
404 cprint("%d", rows - 10); 438 cprint("%d", rows - 10);
405 cprint("%s", active_entry); 439 cprint("%s", active_entry);
406 current_menu = menu; 440 current_menu = menu;
@@ -433,24 +467,27 @@ static void conf(struct menu *menu)
433 input_buf[i] = 0; 467 input_buf[i] = 0;
434 strcpy(active_entry, input_buf); 468 strcpy(active_entry, input_buf);
435 469
436 sym = NULL; 470 sym = NULL;
437 submenu = NULL; 471 submenu = NULL;
438 if (sscanf(input_buf + 1, "%p", &submenu) == 1) 472 if (sscanf(input_buf + 1, "%p", &submenu) == 1)
439 sym = submenu->sym; 473 sym = submenu->sym;
440 474
441 switch (stat) { 475 switch (stat) {
442 case 0: 476 case 0:
443 switch (type) { 477 switch (type) {
444 case 'm': 478 case 'm':
479 if (single_menu_mode)
480 submenu->data = (void *) !submenu->data;
481 else
445 conf(submenu); 482 conf(submenu);
446 break; 483 break;
447 case 't': 484 case 't':
448 if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes) 485 if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
449 conf_choice(submenu); 486 conf_choice(submenu);
450 break; 487 break;
451 case 's': 488 case 's':
452 conf_string(submenu); 489 conf_string(submenu);
453 break; 490 break;
454 case 'L': 491 case 'L':
455 conf_load(); 492 conf_load();
456 break; 493 break;
@@ -475,24 +512,26 @@ static void conf(struct menu *menu)
475 break; 512 break;
476 case 4: 513 case 4:
477 if (type == 't') 514 if (type == 't')
478 sym_set_tristate_value(sym, no); 515 sym_set_tristate_value(sym, no);
479 break; 516 break;
480 case 5: 517 case 5:
481 if (type == 't') 518 if (type == 't')
482 sym_set_tristate_value(sym, mod); 519 sym_set_tristate_value(sym, mod);
483 break; 520 break;
484 case 6: 521 case 6:
485 if (type == 't') 522 if (type == 't')
486 sym_toggle_tristate_value(sym); 523 sym_toggle_tristate_value(sym);
524 else if (type == 'm')
525 conf(submenu);
487 break; 526 break;
488 } 527 }
489 } 528 }
490} 529}
491 530
492static void show_textbox(const char *title, const char *text, int r, int c) 531static void show_textbox(const char *title, const char *text, int r, int c)
493{ 532{
494 int fd; 533 int fd;
495 534
496 fd = creat(".help.tmp", 0777); 535 fd = creat(".help.tmp", 0777);
497 write(fd, text, strlen(text)); 536 write(fd, text, strlen(text));
498 close(fd); 537 close(fd);
@@ -509,28 +548,36 @@ static void show_textbox(const char *title, const char *text, int r, int c)
509 } while (exec_conf() < 0); 548 } while (exec_conf() < 0);
510 unlink(".help.tmp"); 549 unlink(".help.tmp");
511} 550}
512 551
513static void show_helptext(const char *title, const char *text) 552static void show_helptext(const char *title, const char *text)
514{ 553{
515 show_textbox(title, text, rows, cols); 554 show_textbox(title, text, rows, cols);
516} 555}
517 556
518static void show_help(struct menu *menu) 557static void show_help(struct menu *menu)
519{ 558{
520 const char *help; 559 const char *help;
560 char *helptext;
561 struct symbol *sym = menu->sym;
521 562
522 help = menu->sym->help; 563 help = sym->help;
523 if (!help) 564 if (!help)
524 help = nohelp_text; 565 help = nohelp_text;
566 if (sym->name) {
567 helptext = malloc(strlen(sym->name) + strlen(help) + 16);
568 sprintf(helptext, "CONFIG_%s:\n\n%s", sym->name, help);
569 show_helptext(menu_get_prompt(menu), helptext);
570 free(helptext);
571 } else
525 show_helptext(menu_get_prompt(menu), help); 572 show_helptext(menu_get_prompt(menu), help);
526} 573}
527 574
528static void show_readme(void) 575static void show_readme(void)
529{ 576{
530 do { 577 do {
531 cprint_init(); 578 cprint_init();
532 cprint("--textbox"); 579 cprint("--textbox");
533 cprint("scripts/README.Menuconfig"); 580 cprint("scripts/README.Menuconfig");
534 cprint("%d", rows); 581 cprint("%d", rows);
535 cprint("%d", cols); 582 cprint("%d", cols);
536 } while (exec_conf() == -1); 583 } while (exec_conf() == -1);
@@ -622,25 +669,25 @@ static void conf_string(struct menu *menu)
622} 669}
623 670
624static void conf_load(void) 671static void conf_load(void)
625{ 672{
626 int stat; 673 int stat;
627 674
628 while (1) { 675 while (1) {
629 cprint_init(); 676 cprint_init();
630 cprint("--inputbox"); 677 cprint("--inputbox");
631 cprint(load_config_text); 678 cprint(load_config_text);
632 cprint("11"); 679 cprint("11");
633 cprint("55"); 680 cprint("55");
634 cprint("%s", conf_filename); 681 cprint("%s", filename);
635 stat = exec_conf(); 682 stat = exec_conf();
636 switch(stat) { 683 switch(stat) {
637 case 0: 684 case 0:
638 if (!input_buf[0]) 685 if (!input_buf[0])
639 return; 686 return;
640 if (!conf_read(input_buf)) 687 if (!conf_read(input_buf))
641 return; 688 return;
642 show_textbox(NULL, "File does not exist!", 5, 38); 689 show_textbox(NULL, "File does not exist!", 5, 38);
643 break; 690 break;
644 case 1: 691 case 1:
645 show_helptext("Load Alternate Configuration", load_config_help); 692 show_helptext("Load Alternate Configuration", load_config_help);
646 break; 693 break;
@@ -651,61 +698,83 @@ static void conf_load(void)
651} 698}
652 699
653static void conf_save(void) 700static void conf_save(void)
654{ 701{
655 int stat; 702 int stat;
656 703
657 while (1) { 704 while (1) {
658 cprint_init(); 705 cprint_init();
659 cprint("--inputbox"); 706 cprint("--inputbox");
660 cprint(save_config_text); 707 cprint(save_config_text);
661 cprint("11"); 708 cprint("11");
662 cprint("55"); 709 cprint("55");
663 cprint("%s", conf_filename); 710 cprint("%s", filename);
664 stat = exec_conf(); 711 stat = exec_conf();
665 switch(stat) { 712 switch(stat) {
666 case 0: 713 case 0:
667 if (!input_buf[0]) 714 if (!input_buf[0])
668 return; 715 return;
669 if (!conf_write(input_buf)) 716 if (!conf_write(input_buf))
670 return; 717 return;
671 show_textbox(NULL, "Can't create file! Probably a nonexistent directory.", 5, 60); 718 show_textbox(NULL, "Can't create file! Probably a nonexistent directory.", 5, 60);
672 break; 719 break;
673 case 1: 720 case 1:
674 show_helptext("Save Alternate Configuration", save_config_help); 721 show_helptext("Save Alternate Configuration", save_config_help);
675 break; 722 break;
676 case 255: 723 case 255:
677 return; 724 return;
678 } 725 }
679 } 726 }
680} 727}
681 728
729static void conf_cleanup(void)
730{
731 tcsetattr(1, TCSAFLUSH, &ios_org);
732 unlink(".help.tmp");
733 unlink("lxdialog.scrltmp");
734}
735
682int main(int ac, char **av) 736int main(int ac, char **av)
683{ 737{
738 struct symbol *sym;
739 char *mode;
684 int stat; 740 int stat;
741
685 conf_parse(av[1]); 742 conf_parse(av[1]);
686 conf_read(NULL); 743 conf_read(NULL);
687 744
688 sprintf(menu_backtitle, "Configuration"); 745 sym = sym_lookup("KERNELRELEASE", 0);
746 sym_calc_value(sym);
747 sprintf(menu_backtitle, "Linux Kernel v%s Configuration",
748 sym_get_string_value(sym));
749
750 mode = getenv("MENUCONFIG_MODE");
751 if (mode) {
752 if (!strcasecmp(mode, "single_menu"))
753 single_menu_mode = 1;
754 }
689 755
756 tcgetattr(1, &ios_org);
757 atexit(conf_cleanup);
690 init_wsize(); 758 init_wsize();
691 conf(&rootmenu); 759 conf(&rootmenu);
692 760
693 do { 761 do {
694 cprint_init(); 762 cprint_init();
695 cprint("--yesno"); 763 cprint("--yesno");
696 cprint("Do you wish to save your new configuration?"); 764 cprint("Do you wish to save your new configuration?");
697 cprint("5"); 765 cprint("5");
698 cprint("60"); 766 cprint("60");
699 stat = exec_conf(); 767 stat = exec_conf();
700 } while (stat < 0); 768 } while (stat < 0);
701 769
702 if (stat == 0) { 770 if (stat == 0) {
703 conf_write(NULL); 771 conf_write(NULL);
704 printf("\n\n" 772 printf("\n\n"
705 "*** End of configuration.\n" 773 "*** End of Linux kernel configuration.\n"
706 "*** Check the top-level Makefile for additional configuration.\n"); 774 "*** Check the top-level Makefile for additional configuration.\n"
775 "*** Next, you may run 'make bzImage', 'make bzdisk', or 'make install'.\n\n");
707 } else 776 } else
708 printf("\n\nYour configuration changes were NOT saved.\n\n"); 777 printf("\n\nYour kernel configuration changes were NOT saved.\n\n");
709 778
710 return 0; 779 return 0;
711} 780}