diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2009-10-18 19:14:19 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2009-10-18 19:14:19 +0200 |
commit | 0415b1ec23934e833b5d859aed0f12565c65b526 (patch) | |
tree | 26d0dabd7e0de3c1e64ffdbb1136ce7ae0773b15 /conf.c | |
parent | fca50d0be2ee6393edb111372305efaeb09ecf36 (diff) |
new custom columns WIP
Diffstat (limited to 'conf.c')
-rw-r--r-- | conf.c | 51 |
1 files changed, 46 insertions, 5 deletions
@@ -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; + } + } +} |