Removed command hash map from global scope.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 7 Apr 2013 18:10:14 +0000 (20:10 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 7 Apr 2013 18:10:14 +0000 (20:10 +0200)
src/command.c
src/command.h
src/completion.c
src/main.h

index e6f65e9..b666157 100644 (file)
@@ -31,6 +31,7 @@
 extern VbCore vb;
 extern const unsigned int INPUT_LENGTH;
 
+static GHashTable *commands;
 static CommandInfo cmd_list[] = {
     /* command               function                      mode */
     {"open",                 command_open,                 {VB_TARGET_CURRENT, ""}},
@@ -105,23 +106,28 @@ static CommandInfo cmd_list[] = {
 void command_init(void)
 {
     guint i;
-    vb.behave.commands = g_hash_table_new(g_str_hash, g_str_equal);
+    commands = g_hash_table_new(g_str_hash, g_str_equal);
 
     for (i = 0; i < LENGTH(cmd_list); i++) {
-        g_hash_table_insert(vb.behave.commands, (gpointer)cmd_list[i].name, &cmd_list[i]);
+        g_hash_table_insert(commands, (gpointer)cmd_list[i].name, &cmd_list[i]);
     }
 }
 
+GList *command_get_all(void)
+{
+    return g_hash_table_get_keys(commands);
+}
+
 void command_cleanup(void)
 {
-    if (vb.behave.commands) {
-        g_hash_table_destroy(vb.behave.commands);
+    if (commands) {
+        g_hash_table_destroy(commands);
     }
 }
 
 gboolean command_exists(const char *name)
 {
-    return g_hash_table_contains(vb.behave.commands, name);
+    return g_hash_table_contains(commands, name);
 }
 
 gboolean command_run(const char *name, const char *param)
@@ -129,7 +135,7 @@ gboolean command_run(const char *name, const char *param)
     CommandInfo *command = NULL;
     gboolean result;
     Arg a;
-    command = g_hash_table_lookup(vb.behave.commands, name);
+    command = g_hash_table_lookup(commands, name);
     if (!command) {
         vb_echo(VB_MSG_ERROR, true, "Command '%s' not found", name);
         vb_set_mode(VB_MODE_NORMAL, false);
index 6f0bd60..f75d99d 100644 (file)
@@ -44,6 +44,7 @@ typedef struct {
 
 
 void command_init(void);
+GList *command_get_all(void);
 void command_cleanup(void);
 gboolean command_exists(const char *name);
 gboolean command_run(const char *name, const char *param);
index 3acfdf3..1ef88c4 100644 (file)
@@ -21,6 +21,7 @@
 #include "util.h"
 #include "history.h"
 #include "bookmark.h"
+#include "command.h"
 
 extern VbCore vb;
 
@@ -112,8 +113,7 @@ gboolean completion_complete(gboolean back)
 
         history_list_free(&source);
     } else {
-        source = g_hash_table_get_keys(vb.behave.commands);
-        source = g_list_sort(source, (GCompareFunc)g_strcmp0);
+        source = g_list_sort(command_get_all(), (GCompareFunc)g_strcmp0);
         comps.completions = init_completion(
             comps.completions,
             filter_list(tmp, source, (Comp_Func)g_str_has_prefix, &input[1]),
index 195acff..1bb33af 100644 (file)
@@ -252,7 +252,6 @@ typedef struct {
 
 /* behaviour */
 typedef struct {
-    GHashTable *commands;
     GSList     *keys;
     GString    *modkeys;
     GSList     *searchengines;