From 754ff9123ec9e2dd317351cd7c631ffa9f76b343 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 10 Oct 2009 17:14:17 +0200 Subject: ported all custom configs to common config --- conf.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'conf.c') diff --git a/conf.c b/conf.c index 087d8183..3af8f68e 100644 --- a/conf.c +++ b/conf.c @@ -21,13 +21,7 @@ #include #include "conf.h" -struct conf_item_t { - char *key; - char *value; - struct conf_item_t *next; -}; - -static struct conf_item_t *conf_items; +static DB_conf_item_t *conf_items; int conf_load (void) { @@ -86,7 +80,7 @@ conf_free (void) { const char * conf_get_str (const char *key, const char *def) { - for (struct conf_item_t *it = conf_items; it; it = it->next) { + for (DB_conf_item_t *it = conf_items; it; it = it->next) { if (!strcasecmp (key, it->key)) { return it->value; } @@ -106,17 +100,28 @@ conf_get_int (const char *key, int def) { return v ? atoi (v) : def; } +DB_conf_item_t * +conf_find (const char *group, DB_conf_item_t *prev) { + int l = strlen (group); + for (DB_conf_item_t *it = prev ? prev->next : conf_items; it; it = it->next) { + if (!strncasecmp (group, it->key, l)) { + return it; + } + } + return NULL; +} + void conf_set_str (const char *key, const char *val) { - for (struct conf_item_t *it = conf_items; it; it = it->next) { + for (DB_conf_item_t *it = conf_items; it; it = it->next) { if (!strcasecmp (key, it->key)) { free (it->value); it->value = strdup (val); return; } } - struct conf_item_t *it = malloc (sizeof (struct conf_item_t)); - memset (it, 0, sizeof (struct conf_item_t)); + DB_conf_item_t *it = malloc (sizeof (DB_conf_item_t)); + memset (it, 0, sizeof (DB_conf_item_t)); it->next = conf_items; it->key = strdup (key); it->value = strdup (val); -- cgit v1.2.3