Replaces GArray param from commands with Arg.
authorDaniel Carl <danielcarl@gmx.de>
Mon, 1 Oct 2012 18:39:15 +0000 (20:39 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Mon, 1 Oct 2012 18:39:15 +0000 (20:39 +0200)
Also renamed the c -> s in Arg struct.

src/command.c
src/command.h
src/keybind.c
src/main.c
src/main.h

index 55e0255..50970c9 100644 (file)
@@ -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);
index 36acfc7..7081de6 100644 (file)
@@ -4,7 +4,7 @@
 #include "main.h"
 #include <webkit/webkit.h>
 
-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 */
index c31e446..b7a36e1 100644 (file)
@@ -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;
index 9ca09c5..78ca87e 100644 (file)
@@ -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();
index 67cc893..2dde5a3 100644 (file)
@@ -42,7 +42,7 @@ enum {
 /* structs */
 typedef struct {
     gint  i;
-    char* c;
+    char* s;
 } Arg;
 
 /* statusbar */