From: Daniel Carl Date: Wed, 3 Oct 2012 14:05:21 +0000 (+0200) Subject: Removed unneeded function to parse commands from strings. X-Git-Url: https://git.owens.tech/assets/static/git-favicon.png/assets/static/git-favicon.png/git?a=commitdiff_plain;h=3a9d88dab2c02bdcdb68477c0cb6a6a9cd8840be;p=vimb.git Removed unneeded function to parse commands from strings. --- diff --git a/src/command.c b/src/command.c index 50970c9..f5f5706 100644 --- a/src/command.c +++ b/src/command.c @@ -1,9 +1,9 @@ #include "command.h" static CommandInfo cmd_list[] = { - /* command function */ - {"quit", quit}, - {"source", view_source}, + /* command function arg */ + {"quit", quit, {0}}, + {"source", view_source, {0}}, }; void command_init() @@ -16,57 +16,23 @@ void command_init() } } -void command_parse_line(const gchar* line) -{ - gchar* string = g_strdup(line); - - /* strip trailing newline, and any other whitespace from left */ - g_strstrip(string); - - if (strcmp(string, "")) { - /* ignore comment lines */ - if ((string[0] != '#')) { - Arg* a = NULL; - const CommandInfo* c = command_parse_parts(string, a); - if (c) { - command_run_command(c, a); - } - g_free(a->s); - } - } - - g_free(string); -} - -/* static? */ -const CommandInfo* command_parse_parts(const gchar* line, Arg* arg) +void command_run(const gchar* name) { CommandInfo* c = NULL; - - /* split the line into the command and its parameters */ - gchar **tokens = g_strsplit(line, " ", 2); - - /* look up the command */ - c = g_hash_table_lookup(vp.behave.commands, tokens[0]); + Arg a; + c = g_hash_table_lookup(vp.behave.commands, name); if (!c) { - g_strfreev(tokens); - return NULL; + return; } - - arg->s = g_strdup(tokens[2]); - g_strfreev(tokens); - - return c; -} - -void command_run_command(const CommandInfo* c, Arg* arg) -{ - c->function(arg); + a.i = c->arg.i; + a.s = g_strdup(c->arg.s); + c->function(&a); + g_free(a.s); } void quit(Arg* arg) { - vp_close_browser(); + vp_close_browser(); } void view_source(Arg* arg) diff --git a/src/command.h b/src/command.h index 7081de6..8992289 100644 --- a/src/command.h +++ b/src/command.h @@ -9,13 +9,12 @@ typedef void (*Command)(Arg* arg); typedef struct { const gchar* name; Command function; + const Arg arg; } CommandInfo; void command_init(void); -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 command_run(const gchar* name); void quit(Arg* arg); void view_source(Arg* arg); diff --git a/src/keybind.c b/src/keybind.c index b7a36e1..4ed31a9 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -82,12 +82,7 @@ static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* e && keybind->modkey == vp.state.modkey && keybind->command ) { - Arg* a = NULL; - const CommandInfo* c = command_parse_parts(keybind->command, a); - if (c) { - command_run_command(c, a); - } - g_free(a->s); + command_run(keybind->command); /* if key binding used, remove the modkey */ vp.state.modkey = 0; diff --git a/src/main.c b/src/main.c index 78ca87e..cd7cb03 100644 --- a/src/main.c +++ b/src/main.c @@ -135,8 +135,7 @@ static void vp_init(void) /* initialize the keybindings */ keybind_init(); - /*command_parse_line("quit", NULL);*/ - keybind_add(VP_MODE_NORMAL, GDK_g, 0, GDK_s, "source"); + keybind_add(VP_MODE_NORMAL, GDK_g, 0, GDK_f, "source"); keybind_add(VP_MODE_NORMAL, 0, 0, GDK_d, "quit"); }