From: Daniel Carl Date: Sun, 7 Apr 2013 18:10:14 +0000 (+0200) Subject: Removed command hash map from global scope. X-Git-Url: https://git.owens.tech/projects.html/projects.html/git?a=commitdiff_plain;h=d2f8ce130fc58cf952d1a412753ab04a21421bae;p=vimb.git Removed command hash map from global scope. --- diff --git a/src/command.c b/src/command.c index e6f65e9..b666157 100644 --- a/src/command.c +++ b/src/command.c @@ -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); diff --git a/src/command.h b/src/command.h index 6f0bd60..f75d99d 100644 --- a/src/command.h +++ b/src/command.h @@ -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); diff --git a/src/completion.c b/src/completion.c index 3acfdf3..1ef88c4 100644 --- a/src/completion.c +++ b/src/completion.c @@ -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]), diff --git a/src/main.h b/src/main.h index 195acff..1bb33af 100644 --- a/src/main.h +++ b/src/main.h @@ -252,7 +252,6 @@ typedef struct { /* behaviour */ typedef struct { - GHashTable *commands; GSList *keys; GString *modkeys; GSList *searchengines;