diff options
author | Michal Marek <mmarek@suse.cz> | 2010-08-17 04:21:19 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2010-08-17 04:21:19 -0400 |
commit | 42368c37fbd51f7b478d041ae55c5df000897158 (patch) | |
tree | 6e7ba38ab4fc8c07408c0c9276372c4e904c7607 | |
parent | 94bedeca77bf79a81952ed4c3abb8c1cce4c85dd (diff) |
kconfig: Allow frontends to display messages themselves
Signed-off-by: Michal Marek <mmarek@suse.cz>
-rw-r--r-- | scripts/kconfig/confdata.c | 35 | ||||
-rw-r--r-- | scripts/kconfig/lkc_proto.h | 2 | ||||
-rw-r--r-- | scripts/kconfig/nconf.c | 51 |
3 files changed, 40 insertions, 48 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index dc11d51bd8b3..c07060ab7820 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -19,6 +19,9 @@ | |||
19 | static void conf_warning(const char *fmt, ...) | 19 | static void conf_warning(const char *fmt, ...) |
20 | __attribute__ ((format (printf, 1, 2))); | 20 | __attribute__ ((format (printf, 1, 2))); |
21 | 21 | ||
22 | static void conf_message(const char *fmt, ...) | ||
23 | __attribute__ ((format (printf, 1, 2))); | ||
24 | |||
22 | static const char *conf_filename; | 25 | static const char *conf_filename; |
23 | static int conf_lineno, conf_warnings, conf_unsaved; | 26 | static int conf_lineno, conf_warnings, conf_unsaved; |
24 | 27 | ||
@@ -35,6 +38,29 @@ static void conf_warning(const char *fmt, ...) | |||
35 | conf_warnings++; | 38 | conf_warnings++; |
36 | } | 39 | } |
37 | 40 | ||
41 | static void conf_default_message_callback(const char *fmt, va_list ap) | ||
42 | { | ||
43 | printf("#\n# "); | ||
44 | vprintf(fmt, ap); | ||
45 | printf("\n#\n"); | ||
46 | } | ||
47 | |||
48 | static void (*conf_message_callback) (const char *fmt, va_list ap) = | ||
49 | conf_default_message_callback; | ||
50 | void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap)) | ||
51 | { | ||
52 | conf_message_callback = fn; | ||
53 | } | ||
54 | |||
55 | static void conf_message(const char *fmt, ...) | ||
56 | { | ||
57 | va_list ap; | ||
58 | |||
59 | va_start(ap, fmt); | ||
60 | if (conf_message_callback) | ||
61 | conf_message_callback(fmt, ap); | ||
62 | } | ||
63 | |||
38 | const char *conf_get_configname(void) | 64 | const char *conf_get_configname(void) |
39 | { | 65 | { |
40 | char *name = getenv("KCONFIG_CONFIG"); | 66 | char *name = getenv("KCONFIG_CONFIG"); |
@@ -184,9 +210,8 @@ int conf_read_simple(const char *name, int def) | |||
184 | name = conf_expand_value(prop->expr->left.sym->name); | 210 | name = conf_expand_value(prop->expr->left.sym->name); |
185 | in = zconf_fopen(name); | 211 | in = zconf_fopen(name); |
186 | if (in) { | 212 | if (in) { |
187 | printf(_("#\n" | 213 | conf_message(_("using defaults found in %s"), |
188 | "# using defaults found in %s\n" | 214 | name); |
189 | "#\n"), name); | ||
190 | goto load; | 215 | goto load; |
191 | } | 216 | } |
192 | } | 217 | } |
@@ -651,9 +676,7 @@ next: | |||
651 | return 1; | 676 | return 1; |
652 | } | 677 | } |
653 | 678 | ||
654 | printf(_("#\n" | 679 | conf_message(_("configuration written to %s"), newname); |
655 | "# configuration written to %s\n" | ||
656 | "#\n"), newname); | ||
657 | 680 | ||
658 | sym_set_change_count(0); | 681 | sym_set_change_count(0); |
659 | 682 | ||
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 9a948c9ce44e..481d4849d0f0 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <stdarg.h> | ||
1 | 2 | ||
2 | /* confdata.c */ | 3 | /* confdata.c */ |
3 | P(conf_parse,void,(const char *name)); | 4 | P(conf_parse,void,(const char *name)); |
@@ -8,6 +9,7 @@ P(conf_write,int,(const char *name)); | |||
8 | P(conf_write_autoconf,int,(void)); | 9 | P(conf_write_autoconf,int,(void)); |
9 | P(conf_get_changed,bool,(void)); | 10 | P(conf_get_changed,bool,(void)); |
10 | P(conf_set_changed_callback, void,(void (*fn)(void))); | 11 | P(conf_set_changed_callback, void,(void (*fn)(void))); |
12 | P(conf_set_message_callback, void,(void (*fn)(const char *fmt, va_list ap))); | ||
11 | 13 | ||
12 | /* menu.c */ | 14 | /* menu.c */ |
13 | P(rootmenu,struct menu,); | 15 | P(rootmenu,struct menu,); |
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 18a215de9f36..16233a9382c8 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c | |||
@@ -651,25 +651,6 @@ static const char *set_config_filename(const char *config_filename) | |||
651 | return menu_backtitle; | 651 | return menu_backtitle; |
652 | } | 652 | } |
653 | 653 | ||
654 | /* command = 0 is supress, 1 is restore */ | ||
655 | static void supress_stdout(int command) | ||
656 | { | ||
657 | static FILE *org_stdout; | ||
658 | static FILE *org_stderr; | ||
659 | |||
660 | if (command == 0) { | ||
661 | org_stdout = stdout; | ||
662 | org_stderr = stderr; | ||
663 | stdout = fopen("/dev/null", "a"); | ||
664 | stderr = fopen("/dev/null", "a"); | ||
665 | } else { | ||
666 | fclose(stdout); | ||
667 | fclose(stderr); | ||
668 | stdout = org_stdout; | ||
669 | stderr = org_stderr; | ||
670 | } | ||
671 | } | ||
672 | |||
673 | /* return = 0 means we are successful. | 654 | /* return = 0 means we are successful. |
674 | * -1 means go on doing what you were doing | 655 | * -1 means go on doing what you were doing |
675 | */ | 656 | */ |
@@ -695,9 +676,7 @@ static int do_exit(void) | |||
695 | /* if we got here, the user really wants to exit */ | 676 | /* if we got here, the user really wants to exit */ |
696 | switch (res) { | 677 | switch (res) { |
697 | case 0: | 678 | case 0: |
698 | supress_stdout(0); | ||
699 | res = conf_write(filename); | 679 | res = conf_write(filename); |
700 | supress_stdout(1); | ||
701 | if (res) | 680 | if (res) |
702 | btn_dialog( | 681 | btn_dialog( |
703 | main_window, | 682 | main_window, |
@@ -707,19 +686,6 @@ static int do_exit(void) | |||
707 | "changes were NOT saved."), | 686 | "changes were NOT saved."), |
708 | 1, | 687 | 1, |
709 | "<OK>"); | 688 | "<OK>"); |
710 | else { | ||
711 | char buf[1024]; | ||
712 | snprintf(buf, 1024, | ||
713 | _("Configuration written to %s\n" | ||
714 | "End of Linux kernel configuration.\n" | ||
715 | "Execute 'make' to build the kernel or try" | ||
716 | " 'make help'."), filename); | ||
717 | btn_dialog( | ||
718 | main_window, | ||
719 | buf, | ||
720 | 1, | ||
721 | "<OK>"); | ||
722 | } | ||
723 | break; | 689 | break; |
724 | default: | 690 | default: |
725 | btn_dialog( | 691 | btn_dialog( |
@@ -1255,6 +1221,14 @@ static void conf(struct menu *menu) | |||
1255 | } | 1221 | } |
1256 | } | 1222 | } |
1257 | 1223 | ||
1224 | static void conf_message_callback(const char *fmt, va_list ap) | ||
1225 | { | ||
1226 | char buf[1024]; | ||
1227 | |||
1228 | vsnprintf(buf, sizeof(buf), fmt, ap); | ||
1229 | btn_dialog(main_window, buf, 1, "<OK>"); | ||
1230 | } | ||
1231 | |||
1258 | static void show_help(struct menu *menu) | 1232 | static void show_help(struct menu *menu) |
1259 | { | 1233 | { |
1260 | struct gstr help = str_new(); | 1234 | struct gstr help = str_new(); |
@@ -1477,16 +1451,8 @@ static void conf_save(void) | |||
1477 | case 0: | 1451 | case 0: |
1478 | if (!dialog_input_result[0]) | 1452 | if (!dialog_input_result[0]) |
1479 | return; | 1453 | return; |
1480 | supress_stdout(0); | ||
1481 | res = conf_write(dialog_input_result); | 1454 | res = conf_write(dialog_input_result); |
1482 | supress_stdout(1); | ||
1483 | if (!res) { | 1455 | if (!res) { |
1484 | char buf[1024]; | ||
1485 | sprintf(buf, "%s %s", | ||
1486 | _("configuration file saved to: "), | ||
1487 | dialog_input_result); | ||
1488 | btn_dialog(main_window, | ||
1489 | buf, 1, "<OK>"); | ||
1490 | set_config_filename(dialog_input_result); | 1456 | set_config_filename(dialog_input_result); |
1491 | return; | 1457 | return; |
1492 | } | 1458 | } |
@@ -1579,6 +1545,7 @@ int main(int ac, char **av) | |||
1579 | _(menu_no_f_instructions)); | 1545 | _(menu_no_f_instructions)); |
1580 | } | 1546 | } |
1581 | 1547 | ||
1548 | conf_set_message_callback(conf_message_callback); | ||
1582 | /* do the work */ | 1549 | /* do the work */ |
1583 | while (!global_exit) { | 1550 | while (!global_exit) { |
1584 | conf(&rootmenu); | 1551 | conf(&rootmenu); |