summaryrefslogtreecommitdiff
path: root/src/config/conftree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/conftree.c')
-rw-r--r--src/config/conftree.c70
1 files changed, 24 insertions, 46 deletions
diff --git a/src/config/conftree.c b/src/config/conftree.c
index 47bf4fb..d4b01ef 100644
--- a/src/config/conftree.c
+++ b/src/config/conftree.c
@@ -1,78 +1,56 @@
/* ISC license. */
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-
-#include <skalibs/gensetdyn.h>
+#include <skalibs/genalloc.h>
#include <skalibs/avltree.h>
#include <skalibs/cdbmake.h>
-#include <skalibs/strerr.h>
#include "tipidee-config-internal.h"
-static void *confnode_dtok (uint32_t d, void *data)
-{
- return g.storage.s + GENSETDYN_P(confnode, (gensetdyn *)data, d)->key ;
-}
+static repo conftree = \
+{ \
+ .ga = GENALLOC_ZERO, \
+ .tree = AVLTREE_INIT(8, 3, 8, &node_dtok, &node_cmp, &conftree.ga), \
+ .storage = &g.storage \
+} ;
-static int confnode_cmp (void const *a, void const *b, void *data)
+void confnode_start (node *node, char const *key, size_t filepos, uint32_t line)
{
- (void)data ;
- return strcmp((char const *)a, (char const *)b) ;
+ return node_start(&g.storage, node, key, filepos, line) ;
}
-struct nodestore_s
+void confnode_add (node *node, char const *s, size_t len)
{
- gensetdyn set ;
- avltree tree ;
-} ;
-
-static struct nodestore_s nodestore = \
-{ \
- .set = GENSETDYN_INIT(confnode, 8, 3, 8), \
- .tree = AVLTREE_INIT(8, 3, 8, &confnode_dtok, &confnode_cmp, &nodestore.set) \
-} ;
+ return node_add(&g.storage, node, s, len) ;
+}
-confnode const *conftree_search (char const *key)
+node const *conftree_search (char const *key)
{
- uint32_t i ;
- return avltree_search(&nodestore.tree, key, &i) ? GENSETDYN_P(confnode const, &nodestore.set, i) : 0 ;
+ return repo_search(&conftree, key) ;
}
-void conftree_add (confnode const *node)
+void conftree_add (node const *node)
{
- uint32_t i ;
- if (!gensetdyn_new(&nodestore.set, &i)) dienomem() ;
- *GENSETDYN_P(confnode, &nodestore.set, i) = *node ;
- if (!avltree_insert(&nodestore.tree, i)) dienomem() ;
+ return repo_add(&conftree, node) ;
}
-void conftree_update (confnode const *node)
+void conftree_update (node const *node)
{
- uint32_t i ;
- if (avltree_search(&nodestore.tree, g.storage.s + node->key, &i))
- {
- if (!avltree_delete(&nodestore.tree, g.storage.s + node->key)) dienomem() ;
- *GENSETDYN_P(confnode, &nodestore.set, i) = *node ;
- if (!avltree_insert(&nodestore.tree, i)) dienomem() ;
- }
- else return conftree_add(node) ;
+ return repo_update(&conftree, node) ;
}
static int confnode_write (uint32_t d, unsigned int h, void *data)
{
- confnode *node = GENSETDYN_P(confnode, &nodestore.set, d) ;
+ node *nod = genalloc_s(node, &conftree.ga) + d ;
(void)h ;
- if ((g.storage.s[node->key] & ~0x20) == 'A')
+ if ((conftree.storage->s[nod->key] & ~0x20) == 'A')
{
- g.storage.s[++node->data] |= '@' ;
- node->datalen-- ;
+ conftree.storage->s[++nod->data] |= '@' ;
+ nod->datalen-- ;
}
- return cdbmake_add((cdbmaker *)data, g.storage.s + node->key, node->keylen, g.storage.s + node->data, node->datalen) ;
+ return cdbmake_add((cdbmaker *)data, conftree.storage->s + nod->key, nod->keylen, conftree.storage->s + nod->data, nod->datalen) ;
}
int conftree_write (cdbmaker *cm)
{
- return avltree_iter(&nodestore.tree, &confnode_write, cm) ;
+ return avltree_iter(&conftree.tree, &confnode_write, cm) ;
}