From 0415b1ec23934e833b5d859aed0f12565c65b526 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sun, 18 Oct 2009 19:14:19 +0200 Subject: new custom columns WIP --- conf.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'conf.c') diff --git a/conf.c b/conf.c index f45eabd5..912db783 100644 --- a/conf.c +++ b/conf.c @@ -66,6 +66,8 @@ conf_load (void) { } *p = 0; // new items are appended, to preserve order + conf_set_str (str, value); +#if 0 DB_conf_item_t *it = malloc (sizeof (DB_conf_item_t)); memset (it, 0, sizeof (DB_conf_item_t)); it->key = strdup (str); @@ -77,6 +79,7 @@ conf_load (void) { tail->next = it; } tail = it; +#endif } fclose (fp); changed = 0; @@ -105,8 +108,19 @@ conf_free (void) { DB_conf_item_t *next = NULL; for (DB_conf_item_t *it = conf_items; it; it = next) { next = it->next; - free (it->key); - free (it->value); + conf_item_free (it); + } +} + +void +conf_item_free (DB_conf_item_t *it) { + if (it) { + if (it->key) { + free (it->key); + } + if (it->value) { + free (it->value); + } free (it); } } @@ -147,19 +161,32 @@ conf_find (const char *group, DB_conf_item_t *prev) { void conf_set_str (const char *key, const char *val) { changed = 1; + DB_conf_item_t *prev = NULL; for (DB_conf_item_t *it = conf_items; it; it = it->next) { - if (!strcasecmp (key, it->key)) { + int cmp = strcasecmp (key, it->key); + if (!cmp) { free (it->value); it->value = strdup (val); return; } + else if (cmp < 0) { + break; + } + prev = it; } 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); - conf_items = it; + if (prev) { + DB_conf_item_t *next = prev->next; + prev->next = it; + it->next = next; + } + else { + it->next = conf_items; + conf_items = it; + } } void @@ -185,3 +212,17 @@ void conf_setchanged (int c) { changed = c; } + +void +conf_remove_items (const char *key) { + int l = strlen (key); + DB_conf_item_t *it = conf_find (key, NULL); + while (it) { + DB_conf_item_t *next = it->next; + conf_item_free (it); + it = next; + if (strncasecmp (key, it->key, l)) { + break; + } + } +} -- cgit v1.2.3