summaryrefslogtreecommitdiff
path: root/src/lib-config
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-08-26 15:39:44 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-08-26 15:39:44 +0000
commite395e87dedd9aa85f05e5c74330a76f1ef700371 (patch)
tree1184487b13038499f1771e4c553222f85b8524d2 /src/lib-config
parent3d124da13b8da5c0b535abfe6265fc471d9d2ebd (diff)
downloadirssi-e395e87dedd9aa85f05e5c74330a76f1ef700371.zip
Lots of moving stuff around - hopefully I didn't break too much :)
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@632 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/lib-config')
-rw-r--r--src/lib-config/Makefile.am4
-rw-r--r--src/lib-config/get.c16
-rw-r--r--src/lib-config/iconfig.h4
-rw-r--r--src/lib-config/parse.c7
-rw-r--r--src/lib-config/set.c20
5 files changed, 39 insertions, 12 deletions
diff --git a/src/lib-config/Makefile.am b/src/lib-config/Makefile.am
index 00969218..3907ac3d 100644
--- a/src/lib-config/Makefile.am
+++ b/src/lib-config/Makefile.am
@@ -1,10 +1,10 @@
-noinst_LTLIBRARIES = libirssi_config.la
+noinst_LIBRARIES = libirssi_config.a
INCLUDES = \
$(GLIB_CFLAGS) \
-I$(top_srcdir)/src
-libirssi_config_la_SOURCES = \
+libirssi_config_a_SOURCES = \
get.c \
set.c \
parse.c \
diff --git a/src/lib-config/get.c b/src/lib-config/get.c
index c4cde5b8..4db6b4b7 100644
--- a/src/lib-config/get.c
+++ b/src/lib-config/get.c
@@ -291,3 +291,19 @@ char **config_node_get_list(CONFIG_NODE *node)
g_string_free(values, TRUE);
return ret;
}
+
+/* Returns n'th node from list. */
+CONFIG_NODE *config_node_index(CONFIG_NODE *node, int index)
+{
+ GSList *tmp;
+
+ g_return_val_if_fail(node != NULL, NULL);
+ g_return_val_if_fail(is_node_list(node), NULL);
+
+ for (tmp = node->value; tmp != NULL; tmp = tmp->next, index--) {
+ if (index == 0)
+ return tmp->data;
+ }
+
+ return NULL;
+}
diff --git a/src/lib-config/iconfig.h b/src/lib-config/iconfig.h
index 86659a13..f6910642 100644
--- a/src/lib-config/iconfig.h
+++ b/src/lib-config/iconfig.h
@@ -98,6 +98,8 @@ int config_get_bool(CONFIG_REC *rec, const char *section, const char *key, int d
const char *config_list_find(CONFIG_REC *rec, const char *section, const char *key, const char *value, const char *value_key);
/* Like config_list_find(), but return node instead of it's value */
CONFIG_NODE *config_list_find_node(CONFIG_REC *rec, const char *section, const char *key, const char *value, const char *value_key);
+/* Returns n'th node from list. */
+CONFIG_NODE *config_node_index(CONFIG_NODE *node, int index);
/* Setting values */
int config_set_str(CONFIG_REC *rec, const char *section, const char *key, const char *value);
@@ -135,6 +137,8 @@ void config_node_remove(CONFIG_REC *rec, CONFIG_NODE *parent, CONFIG_NODE *node)
/* Remove n'th node from a list */
void config_node_list_remove(CONFIG_REC *rec, CONFIG_NODE *node, int index);
+/* Clear all data inside node, but leave the node */
+void config_node_clear(CONFIG_REC *rec, CONFIG_NODE *node);
/* Clear the entire configuration */
void config_nodes_remove_all(CONFIG_REC *rec);
diff --git a/src/lib-config/parse.c b/src/lib-config/parse.c
index ba5d9b34..05b76975 100644
--- a/src/lib-config/parse.c
+++ b/src/lib-config/parse.c
@@ -116,7 +116,8 @@ static void config_parse_peek_token(GScanner *scanner, CONFIG_NODE *node)
}
/* get optional token, optionally warn if it's missing */
-static void config_parse_warn_missing(CONFIG_REC *rec, CONFIG_NODE *node, int expected_token, int print_warning)
+static void config_parse_warn_missing(CONFIG_REC *rec, CONFIG_NODE *node,
+ GTokenType expected_token, int print_warning)
{
config_parse_peek_token(rec->scanner, node);
if (rec->scanner->next_token == expected_token) {
@@ -128,7 +129,7 @@ static void config_parse_warn_missing(CONFIG_REC *rec, CONFIG_NODE *node, int ex
g_scanner_warn(rec->scanner, "Warning: missing '%c'", expected_token);
}
-static void config_parse_loop(CONFIG_REC *rec, CONFIG_NODE *node, int expect);
+static void config_parse_loop(CONFIG_REC *rec, CONFIG_NODE *node, GTokenType expect);
static int config_parse_symbol(CONFIG_REC *rec, CONFIG_NODE *node)
{
@@ -215,7 +216,7 @@ static int config_parse_symbol(CONFIG_REC *rec, CONFIG_NODE *node)
return G_TOKEN_NONE;
}
-static void config_parse_loop(CONFIG_REC *rec, CONFIG_NODE *node, int expect)
+static void config_parse_loop(CONFIG_REC *rec, CONFIG_NODE *node, GTokenType expect)
{
int expected_token;
diff --git a/src/lib-config/set.c b/src/lib-config/set.c
index 4b887558..f750c40a 100644
--- a/src/lib-config/set.c
+++ b/src/lib-config/set.c
@@ -59,17 +59,23 @@ void config_node_remove(CONFIG_REC *rec, CONFIG_NODE *parent, CONFIG_NODE *node)
/* Remove n'th node from a list */
void config_node_list_remove(CONFIG_REC *rec, CONFIG_NODE *node, int index)
{
- GSList *tmp;
+ CONFIG_NODE *child;
g_return_if_fail(node != NULL);
g_return_if_fail(is_node_list(node));
- for (tmp = node->value; tmp != NULL; tmp = tmp->next, index--) {
- if (index == 0) {
- config_node_remove(rec, node, tmp->data);
- break;
- }
- }
+ child = config_node_index(node, index);
+ if (child != NULL) config_node_remove(rec, node, child);
+}
+
+/* Clear all data inside node, but leave the node */
+void config_node_clear(CONFIG_REC *rec, CONFIG_NODE *node)
+{
+ g_return_if_fail(node != NULL);
+ g_return_if_fail(is_node_list(node));
+
+ while (node->value != NULL)
+ config_node_remove(rec, node, node->value);
}
void config_nodes_remove_all(CONFIG_REC *rec)