diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2018-01-08 21:38:13 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2018-01-08 22:16:52 +0100 |
commit | 682f90e98979f25d1825d9311f596341e9a541e7 (patch) | |
tree | e1b056cbf7e6e5ae0132a75f4f732cd3a595b067 /degesch.c | |
parent | 277af83100c96ac6de137be16f970c1612b46cff (diff) | |
download | xK-682f90e98979f25d1825d9311f596341e9a541e7.tar.gz xK-682f90e98979f25d1825d9311f596341e9a541e7.tar.xz xK-682f90e98979f25d1825d9311f596341e9a541e7.zip |
degesch: simplify the configuration dumper
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 40 |
1 files changed, 11 insertions, 29 deletions
@@ -7934,16 +7934,9 @@ send_autosplit_message (struct server *s, // --- Configuration dumper ---------------------------------------------------- -struct config_dump_level -{ - struct config_dump_level *next; ///< Next print level - const char *name; ///< Name of the object -}; - struct config_dump_data { - struct config_dump_level *head; ///< The first level - struct config_dump_level **tail; ///< Where to place further levels + struct strv path; ///< Levels struct strv *output; ///< Where to place new entries }; @@ -7956,23 +7949,14 @@ config_dump_children { hard_assert (object->type == CONFIG_ITEM_OBJECT); - struct config_dump_level level; - level.next = NULL; - - struct config_dump_level **prev_tail = data->tail; - *data->tail = &level; - data->tail = &level.next; - struct str_map_iter iter = str_map_iter_make (&object->value.object); struct config_item *child; while ((child = str_map_iter_next (&iter))) { - level.name = iter.link->key; + strv_append_owned (&data->path, iter.link->key); config_dump_item (child, data); + strv_steal (&data->path, data->path.len - 1); } - - data->tail = prev_tail; - *data->tail = NULL; } static void @@ -7992,14 +7976,10 @@ config_dump_item (struct config_item *item, struct config_dump_data *data) return; struct str line = str_make (); - struct config_dump_level *iter = data->head; - if (iter) - { - str_append (&line, iter->name); - iter = iter->next; - } - for (; iter; iter = iter->next) - str_append_printf (&line, ".%s", iter->name); + if (data->path.len) + str_append (&line, data->path.vector[0]); + for (size_t i = 1; i < data->path.len; i++) + str_append_printf (&line, ".%s", data->path.vector[i]); struct str value = str_make (); config_item_write (item, false, &value); @@ -8027,11 +8007,13 @@ static void config_dump (struct config_item *root, struct strv *output) { struct config_dump_data data; - data.head = NULL; - data.tail = &data.head; + data.path = strv_make (); data.output = output; config_dump_item (root, &data); + + hard_assert (!data.path.len); + strv_free (&data.path); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |