From 682f90e98979f25d1825d9311f596341e9a541e7 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Mon, 8 Jan 2018 21:38:13 +0100 Subject: degesch: simplify the configuration dumper --- degesch.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/degesch.c b/degesch.c index 1906123..74ce5e1 100644 --- a/degesch.c +++ b/degesch.c @@ -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); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-70-g09d2