Skip to content

Commit

Permalink
kconfig: Allow frontends to display messages themselves
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Marek <mmarek@suse.cz>
  • Loading branch information
Michal Marek committed Aug 17, 2010
1 parent 94bedec commit 42368c3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 48 deletions.
35 changes: 29 additions & 6 deletions scripts/kconfig/confdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
static void conf_warning(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));

static void conf_message(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));

static const char *conf_filename;
static int conf_lineno, conf_warnings, conf_unsaved;

Expand All @@ -35,6 +38,29 @@ static void conf_warning(const char *fmt, ...)
conf_warnings++;
}

static void conf_default_message_callback(const char *fmt, va_list ap)
{
printf("#\n# ");
vprintf(fmt, ap);
printf("\n#\n");
}

static void (*conf_message_callback) (const char *fmt, va_list ap) =
conf_default_message_callback;
void conf_set_message_callback(void (*fn) (const char *fmt, va_list ap))
{
conf_message_callback = fn;
}

static void conf_message(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
if (conf_message_callback)
conf_message_callback(fmt, ap);
}

const char *conf_get_configname(void)
{
char *name = getenv("KCONFIG_CONFIG");
Expand Down Expand Up @@ -184,9 +210,8 @@ int conf_read_simple(const char *name, int def)
name = conf_expand_value(prop->expr->left.sym->name);
in = zconf_fopen(name);
if (in) {
printf(_("#\n"
"# using defaults found in %s\n"
"#\n"), name);
conf_message(_("using defaults found in %s"),
name);
goto load;
}
}
Expand Down Expand Up @@ -651,9 +676,7 @@ int conf_write(const char *name)
return 1;
}

printf(_("#\n"
"# configuration written to %s\n"
"#\n"), newname);
conf_message(_("configuration written to %s"), newname);

sym_set_change_count(0);

Expand Down
2 changes: 2 additions & 0 deletions scripts/kconfig/lkc_proto.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdarg.h>

/* confdata.c */
P(conf_parse,void,(const char *name));
Expand All @@ -8,6 +9,7 @@ P(conf_write,int,(const char *name));
P(conf_write_autoconf,int,(void));
P(conf_get_changed,bool,(void));
P(conf_set_changed_callback, void,(void (*fn)(void)));
P(conf_set_message_callback, void,(void (*fn)(const char *fmt, va_list ap)));

/* menu.c */
P(rootmenu,struct menu,);
Expand Down
51 changes: 9 additions & 42 deletions scripts/kconfig/nconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,25 +651,6 @@ static const char *set_config_filename(const char *config_filename)
return menu_backtitle;
}

/* command = 0 is supress, 1 is restore */
static void supress_stdout(int command)
{
static FILE *org_stdout;
static FILE *org_stderr;

if (command == 0) {
org_stdout = stdout;
org_stderr = stderr;
stdout = fopen("/dev/null", "a");
stderr = fopen("/dev/null", "a");
} else {
fclose(stdout);
fclose(stderr);
stdout = org_stdout;
stderr = org_stderr;
}
}

/* return = 0 means we are successful.
* -1 means go on doing what you were doing
*/
Expand All @@ -695,9 +676,7 @@ static int do_exit(void)
/* if we got here, the user really wants to exit */
switch (res) {
case 0:
supress_stdout(0);
res = conf_write(filename);
supress_stdout(1);
if (res)
btn_dialog(
main_window,
Expand All @@ -707,19 +686,6 @@ static int do_exit(void)
"changes were NOT saved."),
1,
"<OK>");
else {
char buf[1024];
snprintf(buf, 1024,
_("Configuration written to %s\n"
"End of Linux kernel configuration.\n"
"Execute 'make' to build the kernel or try"
" 'make help'."), filename);
btn_dialog(
main_window,
buf,
1,
"<OK>");
}
break;
default:
btn_dialog(
Expand Down Expand Up @@ -1255,6 +1221,14 @@ static void conf(struct menu *menu)
}
}

static void conf_message_callback(const char *fmt, va_list ap)
{
char buf[1024];

vsnprintf(buf, sizeof(buf), fmt, ap);
btn_dialog(main_window, buf, 1, "<OK>");
}

static void show_help(struct menu *menu)
{
struct gstr help = str_new();
Expand Down Expand Up @@ -1477,16 +1451,8 @@ static void conf_save(void)
case 0:
if (!dialog_input_result[0])
return;
supress_stdout(0);
res = conf_write(dialog_input_result);
supress_stdout(1);
if (!res) {
char buf[1024];
sprintf(buf, "%s %s",
_("configuration file saved to: "),
dialog_input_result);
btn_dialog(main_window,
buf, 1, "<OK>");
set_config_filename(dialog_input_result);
return;
}
Expand Down Expand Up @@ -1579,6 +1545,7 @@ int main(int ac, char **av)
_(menu_no_f_instructions));
}

conf_set_message_callback(conf_message_callback);
/* do the work */
while (!global_exit) {
conf(&rootmenu);
Expand Down

0 comments on commit 42368c3

Please sign in to comment.