From fed79c87b7f9e8447c63dc4ca2c5593ed28e622c Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Mon, 1 Oct 2012 20:39:15 +0200 Subject: [PATCH] Replaces GArray param from commands with Arg. Also renamed the c -> s in Arg struct. --- src/command.c | 32 ++++++++++---------------------- src/command.h | 12 ++++++------ src/keybind.c | 6 +++--- src/main.c | 8 ++++---- src/main.h | 2 +- 5 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/command.c b/src/command.c index 55e0255..50970c9 100644 --- a/src/command.c +++ b/src/command.c @@ -6,9 +6,6 @@ static CommandInfo cmd_list[] = { {"source", view_source}, }; -static void command_sharg_append(GArray* a, const gchar* str); - - void command_init() { guint i; @@ -19,7 +16,7 @@ void command_init() } } -void command_parse_line(const gchar* line, GString* result) +void command_parse_line(const gchar* line) { gchar* string = g_strdup(line); @@ -29,12 +26,12 @@ void command_parse_line(const gchar* line, GString* result) if (strcmp(string, "")) { /* ignore comment lines */ if ((string[0] != '#')) { - GArray* a = g_array_new(TRUE, FALSE, sizeof(gchar*)); + Arg* a = NULL; const CommandInfo* c = command_parse_parts(string, a); if (c) { - command_run_command(c, a, result); + command_run_command(c, a); } - g_array_free(a, TRUE); + g_free(a->s); } } @@ -42,7 +39,7 @@ void command_parse_line(const gchar* line, GString* result) } /* static? */ -const CommandInfo* command_parse_parts(const gchar* line, GArray* a) +const CommandInfo* command_parse_parts(const gchar* line, Arg* arg) { CommandInfo* c = NULL; @@ -56,32 +53,23 @@ const CommandInfo* command_parse_parts(const gchar* line, GArray* a) return NULL; } - gchar* p = g_strdup(tokens[1]); - command_sharg_append(a, p); - + arg->s = g_strdup(tokens[2]); g_strfreev(tokens); - g_free(p); return c; } -void command_run_command(const CommandInfo* c, GArray* a, GString* result) -{ - c->function(a, result); -} - -static void command_sharg_append(GArray* a, const gchar* str) +void command_run_command(const CommandInfo* c, Arg* arg) { - const gchar* s = (str ? str : ""); - g_array_append_val(a, s); + c->function(arg); } -void quit(GArray* argv, GString* result) +void quit(Arg* arg) { vp_close_browser(); } -void view_source(GArray* argv, GString* result) +void view_source(Arg* arg) { gboolean mode = webkit_web_view_get_view_source_mode(vp.gui.webview); webkit_web_view_set_view_source_mode(vp.gui.webview, !mode); diff --git a/src/command.h b/src/command.h index 36acfc7..7081de6 100644 --- a/src/command.h +++ b/src/command.h @@ -4,7 +4,7 @@ #include "main.h" #include -typedef void (*Command)(GArray *argv, GString *result); +typedef void (*Command)(Arg* arg); typedef struct { const gchar* name; @@ -13,11 +13,11 @@ typedef struct { void command_init(void); -void command_parse_line(const gchar* line, GString* result); -const CommandInfo* command_parse_parts(const gchar* line, GArray* a); -void command_run_command(const CommandInfo* c, GArray* a, GString* result); +void command_parse_line(const gchar* line); +const CommandInfo* command_parse_parts(const gchar* line, Arg* arg); +void command_run_command(const CommandInfo* c, Arg* arg); -void quit(GArray* argv, GString* result); -void view_source(GArray* argv, GString* result); +void quit(Arg* arg); +void view_source(Arg* arg); #endif /* end of include guard: COMMAND_H */ diff --git a/src/keybind.c b/src/keybind.c index c31e446..b7a36e1 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -82,12 +82,12 @@ static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* e && keybind->modkey == vp.state.modkey && keybind->command ) { - GArray* a = g_array_new(TRUE, FALSE, sizeof(gchar*)); + Arg* a = NULL; const CommandInfo* c = command_parse_parts(keybind->command, a); if (c) { - command_run_command(c, a, NULL); + command_run_command(c, a); } - g_array_free(a, TRUE); + g_free(a->s); /* if key binding used, remove the modkey */ vp.state.modkey = 0; diff --git a/src/main.c b/src/main.c index 9ca09c5..78ca87e 100644 --- a/src/main.c +++ b/src/main.c @@ -49,7 +49,7 @@ gboolean vp_frame_scrollbar_policy_changed_cb(void) gboolean vp_load_uri(const Arg* arg) { char* u; - const char* uri = arg->c; + const char* uri = arg->s; if (strcmp(uri, "") == 0) { return FALSE; @@ -250,12 +250,12 @@ int main(int argc, char* argv[]) /* command line argument: URL */ Arg arg; if (argc > 1) { - arg.c = g_strdup(argv[argc - 1]); + arg.s = g_strdup(argv[argc - 1]); } else { - arg.c = g_strdup(START_PAGE); + arg.s = g_strdup(START_PAGE); } vp_load_uri(&arg); - g_free(arg.c); + g_free(arg.s); /* Run the main GTK+ event loop */ gtk_main(); diff --git a/src/main.h b/src/main.h index 67cc893..2dde5a3 100644 --- a/src/main.h +++ b/src/main.h @@ -42,7 +42,7 @@ enum { /* structs */ typedef struct { gint i; - char* c; + char* s; } Arg; /* statusbar */ -- 2.20.1