From a4e87d63a620a5da2956848d55f4098ae55c31d7 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 1 Nov 2012 01:54:46 +0100 Subject: [PATCH] Use variable args for vp_echo function. --- src/main.c | 13 +++++++++---- src/main.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 1725492..142a396 100644 --- a/src/main.c +++ b/src/main.c @@ -110,9 +110,7 @@ static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data) success = vp_process_input((text + 1)); if (!success) { /* print error message */ - gchar* message = g_strdup_printf("Command '%s' not found", (text + 1)); - vp_echo(VP_MSG_ERROR, message); - g_free(message); + vp_echo(VP_MSG_ERROR, "Command '%s' not found", (text + 1)); /* switch to normal mode after running command */ Arg a = {VP_MODE_NORMAL}; @@ -468,8 +466,15 @@ void vp_update_statusbar(void) g_free(markup); } -void vp_echo(const MessageType type, const gchar *message) +void vp_echo(const MessageType type, const char *error, ...) { + va_list arg_list; + + va_start(arg_list, error); + char message[255]; + vsnprintf(message, 255, error, arg_list); + va_end(arg_list); + /* don't print message if the input is focussed */ if (gtk_widget_is_focus(GTK_WIDGET(vp.gui.inputbox))) { return; diff --git a/src/main.h b/src/main.h index 54e0d4e..a20125c 100644 --- a/src/main.h +++ b/src/main.h @@ -179,7 +179,7 @@ extern VpCore vp; /* functions */ void vp_update_statusbar(void); void vp_update_urlbar(const gchar* uri); -void vp_echo(const MessageType type, const gchar *message); +void vp_echo(const MessageType type, const char *error, ...); gboolean vp_navigate(const Arg* arg); gboolean vp_scroll(const Arg* arg); gboolean vp_close_browser(const Arg* arg); -- 2.20.1