From 1e5554a20312775a8773328fc81552c8e1eb0064 Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Tue, 5 Jun 2007 11:27:58 +0000 Subject: [PATCH] Remove code duplication. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4539 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/completion.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/fe-common/core/completion.c b/src/fe-common/core/completion.c index d4e69798..88e9b029 100644 --- a/src/fe-common/core/completion.c +++ b/src/fe-common/core/completion.c @@ -344,7 +344,7 @@ GList *filename_complete(const char *path, const char *default_path) return list; } -static GList *completion_get_settings(const char *key) +static GList *completion_get_settings(const char *key, SettingType type) { GList *complist; GSList *tmp, *sets; @@ -359,29 +359,7 @@ static GList *completion_get_settings(const char *key) for (tmp = sets; tmp != NULL; tmp = tmp->next) { SETTINGS_REC *rec = tmp->data; - if (g_strncasecmp(rec->key, key, len) == 0) - complist = g_list_insert_sorted(complist, g_strdup(rec->key), (GCompareFunc) g_istr_cmp); - } - g_slist_free(sets); - return complist; -} - -static GList *completion_get_bool_settings(const char *key) -{ - GList *complist; - GSList *tmp, *sets; - int len; - - g_return_val_if_fail(key != NULL, NULL); - - sets = settings_get_sorted(); - - len = strlen(key); - complist = NULL; - for (tmp = sets; tmp != NULL; tmp = tmp->next) { - SETTINGS_REC *rec = tmp->data; - - if (rec->type == SETTING_TYPE_BOOLEAN && + if ((type == -1 || rec->type == type) && g_strncasecmp(rec->key, key, len) == 0) complist = g_list_insert_sorted(complist, g_strdup(rec->key), (GCompareFunc) g_istr_cmp); } @@ -701,7 +679,7 @@ static void sig_complete_set(GList **list, WINDOW_REC *window, if (*line != '\0') return; - *list = completion_get_settings(word); + *list = completion_get_settings(word, -1); if (*list != NULL) signal_stop(); } @@ -714,7 +692,7 @@ static void sig_complete_toggle(GList **list, WINDOW_REC *window, if (*line != '\0') return; - *list = completion_get_bool_settings(word); + *list = completion_get_settings(word, SETTING_TYPE_BOOLEAN); if (*list != NULL) signal_stop(); }