summaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-02 15:07:14 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-02 15:07:14 +0200
commit7cffbc1b2e8361093f0b0311857df0545680611e (patch)
tree0c8518f8e1a10bc3c477e40e279901427682dcb3 /common.c
parent409a13ac7f6b0d810affc9a07ac80d55d85d21d7 (diff)
downloadxK-7cffbc1b2e8361093f0b0311857df0545680611e.tar.gz
xK-7cffbc1b2e8361093f0b0311857df0545680611e.tar.xz
xK-7cffbc1b2e8361093f0b0311857df0545680611e.zip
config: implement config_load()
Diffstat (limited to 'common.c')
-rw-r--r--common.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/common.c b/common.c
index 03c6356..57518d9 100644
--- a/common.c
+++ b/common.c
@@ -1421,7 +1421,7 @@ end:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-// TODO: this doesn't necessarily have to be well designed at all
+// XXX: this doesn't necessarily have to be well designed at all
typedef void (*config_module_load_fn)
(struct config_item_ *subtree, void *user_data);
@@ -1481,8 +1481,25 @@ config_register_module (struct config *self,
str_map_set (&self->modules, name, module);
}
-static bool
-config_load (struct config *self, struct config_item_ *root, struct error **e)
+static void
+config_load (struct config *self, struct config_item_ *root)
{
- // TODO
+ hard_assert (root->type == CONFIG_ITEM_OBJECT);
+
+ struct str_map_iter iter;
+ str_map_iter_init (&iter, &self->modules);
+
+ struct config_module *module;
+ while ((module = str_map_iter_next (&iter)))
+ {
+ struct config_item_ *subtree = str_map_find
+ (&root->value.object, module->name);
+ // Silently fix inputs that only a lunatic user could create
+ if (!subtree || subtree->type != CONFIG_ITEM_OBJECT)
+ {
+ subtree = config_item_object ();
+ str_map_set (&root->value.object, module->name, subtree);
+ }
+ module->loader (subtree, module->user_data);
+ }
}