degesch: simplify the configuration dumper

This commit is contained in:
Přemysl Eric Janouch 2018-01-08 21:38:13 +01:00
parent 277af83100
commit 682f90e989
Signed by: p
GPG Key ID: B715679E3A361BE6

View File

@ -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);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -