summaryrefslogtreecommitdiff
path: root/src/core/misc.c
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2016-06-05 17:24:27 +0200
committerLemonBoy <thatlemon@gmail.com>2016-06-05 17:24:27 +0200
commit0060f682c213dc25901f4c0ab01a01176e14da9e (patch)
treeb23ef3ec549ae6d0c935549a94578934fad0379f /src/core/misc.c
parent2e8744319d5e5e47799ec20b2f737c437e8c6398 (diff)
downloadirssi-0060f682c213dc25901f4c0ab01a01176e14da9e.zip
Factor out some redundant code and remove hashtable_get_keys
Diffstat (limited to 'src/core/misc.c')
-rw-r--r--src/core/misc.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/core/misc.c b/src/core/misc.c
index 9081abe1..bc9f504e 100644
--- a/src/core/misc.c
+++ b/src/core/misc.c
@@ -20,6 +20,7 @@
#include "module.h"
#include "misc.h"
+#include "commands.h"
#ifdef HAVE_REGEX_H
# include <regex.h>
@@ -265,14 +266,23 @@ void hash_save_key(char *key, void *value, GSList **list)
*list = g_slist_append(*list, key);
}
-/* save all keys in hash table to linked list - you shouldn't remove any
- items while using this list, use g_slist_free() after you're done with it */
-GSList *hashtable_get_keys(GHashTable *hash)
+/* remove all the options from the optlist hash table that are valid for the
+ * command cmd */
+GList *optlist_remove_known(const char *cmd, GHashTable *optlist)
{
- GSList *list;
+ GList *list, *tmp, *next;
+
+ list = g_hash_table_get_keys(optlist);
+ if (cmd != NULL && list != NULL) {
+ for (tmp = list; tmp != NULL; tmp = next) {
+ char *option = tmp->data;
+ next = tmp->next;
+
+ if (command_have_option(cmd, option))
+ list = g_list_remove(list, option);
+ }
+ }
- list = NULL;
- g_hash_table_foreach(hash, (GHFunc) hash_save_key, &list);
return list;
}