mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Factor out some redundant code and remove hashtable_get_keys
This commit is contained in:
parent
2e8744319d
commit
0060f682c2
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "commands.h"
|
||||||
|
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
# include <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);
|
*list = g_slist_append(*list, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* save all keys in hash table to linked list - you shouldn't remove any
|
/* remove all the options from the optlist hash table that are valid for the
|
||||||
items while using this list, use g_slist_free() after you're done with it */
|
* command cmd */
|
||||||
GSList *hashtable_get_keys(GHashTable *hash)
|
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;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,9 +32,7 @@ char *gslistptr_to_string(GSList *list, int offset, const char *delimiter);
|
|||||||
/* `list' contains char* */
|
/* `list' contains char* */
|
||||||
char *gslist_to_string(GSList *list, const char *delimiter);
|
char *gslist_to_string(GSList *list, const char *delimiter);
|
||||||
|
|
||||||
/* save all keys in hash table to linked list - you shouldn't remove any
|
GList *optlist_remove_known(const char *cmd, GHashTable *optlist);
|
||||||
items while using this list, use g_slist_free() after you're done with it */
|
|
||||||
GSList *hashtable_get_keys(GHashTable *hash);
|
|
||||||
|
|
||||||
/* convert ~/ to $HOME */
|
/* convert ~/ to $HOME */
|
||||||
char *convert_home(const char *path);
|
char *convert_home(const char *path);
|
||||||
|
@ -684,21 +684,11 @@ SERVER_REC *cmd_options_get_server(const char *cmd,
|
|||||||
SERVER_REC *defserver)
|
SERVER_REC *defserver)
|
||||||
{
|
{
|
||||||
SERVER_REC *server;
|
SERVER_REC *server;
|
||||||
GSList *list, *tmp, *next;
|
GList *list;
|
||||||
|
|
||||||
/* get all the options, then remove the known ones. there should
|
/* get all the options, then remove the known ones. there should
|
||||||
be only one left - the server tag. */
|
be only one left - the server tag. */
|
||||||
list = hashtable_get_keys(optlist);
|
list = optlist_remove_known(cmd, optlist);
|
||||||
if (cmd != NULL) {
|
|
||||||
for (tmp = list; tmp != NULL; tmp = next) {
|
|
||||||
char *option = tmp->data;
|
|
||||||
next = tmp->next;
|
|
||||||
|
|
||||||
if (command_have_option(cmd, option))
|
|
||||||
list = g_slist_remove(list, option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
return defserver;
|
return defserver;
|
||||||
|
|
||||||
@ -713,7 +703,7 @@ SERVER_REC *cmd_options_get_server(const char *cmd,
|
|||||||
server = NULL;
|
server = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free(list);
|
g_list_free(list);
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,22 +237,13 @@ static int signal_name_to_id(const char *name)
|
|||||||
static int cmd_options_get_signal(const char *cmd,
|
static int cmd_options_get_signal(const char *cmd,
|
||||||
GHashTable *optlist)
|
GHashTable *optlist)
|
||||||
{
|
{
|
||||||
GSList *list, *tmp, *next;
|
GList *list;
|
||||||
char *signame;
|
char *signame;
|
||||||
int signum;
|
int signum;
|
||||||
|
|
||||||
/* get all the options, then remove the known ones. there should
|
/* get all the options, then remove the known ones. there should
|
||||||
be only one left - the signal */
|
be only one left - the signal */
|
||||||
list = hashtable_get_keys(optlist);
|
list = optlist_remove_known(cmd, optlist);
|
||||||
if (cmd != NULL) {
|
|
||||||
for (tmp = list; tmp != NULL; tmp = next) {
|
|
||||||
char *option = tmp->data;
|
|
||||||
next = tmp->next;
|
|
||||||
|
|
||||||
if (command_have_option(cmd, option))
|
|
||||||
list = g_slist_remove(list, option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -272,7 +263,7 @@ static int cmd_options_get_signal(const char *cmd,
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free(list);
|
g_list_free(list);
|
||||||
return signum;
|
return signum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,21 +39,10 @@
|
|||||||
Returns -1 if unknown option was given. */
|
Returns -1 if unknown option was given. */
|
||||||
int cmd_options_get_level(const char *cmd, GHashTable *optlist)
|
int cmd_options_get_level(const char *cmd, GHashTable *optlist)
|
||||||
{
|
{
|
||||||
GSList *list, *tmp, *next;
|
GList *list;
|
||||||
int level, retlevel;
|
int level, retlevel;
|
||||||
|
|
||||||
/* get all the options, then remove the known ones. there should
|
list = optlist_remove_known(cmd, optlist);
|
||||||
be only one left - the server tag. */
|
|
||||||
list = hashtable_get_keys(optlist);
|
|
||||||
if (cmd != NULL) {
|
|
||||||
for (tmp = list; tmp != NULL; tmp = next) {
|
|
||||||
char *option = tmp->data;
|
|
||||||
next = tmp->next;
|
|
||||||
|
|
||||||
if (command_have_option(cmd, option))
|
|
||||||
list = g_slist_remove(list, option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
retlevel = 0;
|
retlevel = 0;
|
||||||
while (list != NULL) {
|
while (list != NULL) {
|
||||||
@ -68,7 +57,7 @@ int cmd_options_get_level(const char *cmd, GHashTable *optlist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
retlevel |= level;
|
retlevel |= level;
|
||||||
list = g_slist_remove(list, list->data);
|
list = g_list_remove(list, list->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retlevel;
|
return retlevel;
|
||||||
|
Loading…
Reference in New Issue
Block a user