Skip to content

Commit

Permalink
kconfig: handle format string before calling conf_message_callback()
Browse files Browse the repository at this point in the history
As you see in mconf.c and nconf.c, conf_message_callback() hooks are
likely to end up with the boilerplate of vsnprintf().  Process the
string format before calling conf_message_callback() so that it
receives a simple string.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Dirk Gouders <dirk@gouders.net>
  • Loading branch information
masahir0y committed Jul 25, 2018
1 parent 693359f commit 5accd7f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
17 changes: 11 additions & 6 deletions scripts/kconfig/confdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,32 @@ static void conf_warning(const char *fmt, ...)
conf_warnings++;
}

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

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

static void conf_message(const char *fmt, ...)
{
va_list ap;
char buf[4096];

if (!conf_message_callback)
return;

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

vsnprintf(buf, sizeof(buf), fmt, ap);
conf_message_callback(buf);
va_end(ap);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/kconfig/lkc_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int conf_write(const char *name);
int conf_write_autoconf(void);
bool conf_get_changed(void);
void conf_set_changed_callback(void (*fn)(void));
void conf_set_message_callback(void (*fn)(const char *fmt, va_list ap));
void conf_set_message_callback(void (*fn)(const char *s));

/* menu.c */
extern struct menu rootmenu;
Expand Down
9 changes: 3 additions & 6 deletions scripts/kconfig/mconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,16 +772,13 @@ static void show_helptext(const char *title, const char *text)
show_textbox(title, text, 0, 0);
}

static void conf_message_callback(const char *fmt, va_list ap)
static void conf_message_callback(const char *s)
{
char buf[PATH_MAX+1];

vsnprintf(buf, sizeof(buf), fmt, ap);
if (save_and_exit) {
if (!silent)
printf("%s", buf);
printf("%s", s);
} else {
show_textbox(NULL, buf, 6, 60);
show_textbox(NULL, s, 6, 60);
}
}

Expand Down
7 changes: 2 additions & 5 deletions scripts/kconfig/nconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,12 +1210,9 @@ static void conf(struct menu *menu)
}
}

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

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

static void show_help(struct menu *menu)
Expand Down

0 comments on commit 5accd7f

Please sign in to comment.