From fd818a2f7d1ea235c5cdf22a32456fffe6cf02ce Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sun, 7 Apr 2013 20:37:23 +0200 Subject: [PATCH] Remove settings hashmap from global scope. --- src/completion.c | 4 ++-- src/main.h | 1 - src/setting.c | 17 ++++++++++++----- src/setting.h | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/completion.c b/src/completion.c index 1ef88c4..ddd1111 100644 --- a/src/completion.c +++ b/src/completion.c @@ -22,6 +22,7 @@ #include "history.h" #include "bookmark.h" #include "command.h" +#include "setting.h" extern VbCore vb; @@ -80,8 +81,7 @@ gboolean completion_complete(gboolean back) /* TODO move these decision to a more generic place */ if (!strncmp(input, ":set ", 5)) { - source = g_hash_table_get_keys(vb.settings); - source = g_list_sort(source, (GCompareFunc)g_strcmp0); + source = g_list_sort(setting_get_all(), (GCompareFunc)g_strcmp0); comps.completions = init_completion( comps.completions, filter_list(tmp, source, (Comp_Func)g_str_has_prefix, &input[5]), diff --git a/src/main.h b/src/main.h index 0f95554..97f400e 100644 --- a/src/main.h +++ b/src/main.h @@ -285,7 +285,6 @@ typedef struct { char *files[FILES_LAST]; Config config; Style style; - GHashTable *settings; SoupSession *session; #ifdef HAS_GTK3 Window embed; diff --git a/src/setting.c b/src/setting.c index bfcf0e4..8ed1886 100644 --- a/src/setting.c +++ b/src/setting.c @@ -20,6 +20,8 @@ #include "setting.h" #include "util.h" +static GHashTable *settings; + extern VbCore vb; static Arg *char_to_arg(const char *str, const Type type); @@ -107,19 +109,24 @@ void setting_init(void) { Setting *s; unsigned int i; - vb.settings = g_hash_table_new(g_str_hash, g_str_equal); + settings = g_hash_table_new(g_str_hash, g_str_equal); for (i = 0; i < LENGTH(default_settings); i++) { s = &default_settings[i]; /* use alias as key if available */ - g_hash_table_insert(vb.settings, (gpointer)s->alias != NULL ? s->alias : s->name, s); + g_hash_table_insert(settings, (gpointer)s->alias != NULL ? s->alias : s->name, s); } } +GList* setting_get_all(void) +{ + return g_hash_table_get_keys(settings); +} + void setting_cleanup(void) { - if (vb.settings) { - g_hash_table_destroy(vb.settings); + if (settings) { + g_hash_table_destroy(settings); } } @@ -141,7 +148,7 @@ gboolean setting_run(char *name, const char *param) type = SETTING_GET; } - Setting *s = g_hash_table_lookup(vb.settings, name); + Setting *s = g_hash_table_lookup(settings, name); if (!s) { vb_echo(VB_MSG_ERROR, true, "Config '%s' not found", name); return false; diff --git a/src/setting.h b/src/setting.h index b259860..e670d2a 100644 --- a/src/setting.h +++ b/src/setting.h @@ -40,6 +40,7 @@ struct _Setting { }; void setting_init(void); +GList* setting_get_all(void); void setting_cleanup(void); gboolean setting_run(char* name, const char* param); -- 2.20.1