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
1 changed files with 11 additions and 29 deletions

View File

@ -7934,16 +7934,9 @@ send_autosplit_message (struct server *s,
// --- Configuration dumper ---------------------------------------------------- // --- 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_data
{ {
struct config_dump_level *head; ///< The first level struct strv path; ///< Levels
struct config_dump_level **tail; ///< Where to place further levels
struct strv *output; ///< Where to place new entries struct strv *output; ///< Where to place new entries
}; };
@ -7956,23 +7949,14 @@ config_dump_children
{ {
hard_assert (object->type == CONFIG_ITEM_OBJECT); 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 str_map_iter iter = str_map_iter_make (&object->value.object);
struct config_item *child; struct config_item *child;
while ((child = str_map_iter_next (&iter))) 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); config_dump_item (child, data);
strv_steal (&data->path, data->path.len - 1);
} }
data->tail = prev_tail;
*data->tail = NULL;
} }
static void static void
@ -7992,14 +7976,10 @@ config_dump_item (struct config_item *item, struct config_dump_data *data)
return; return;
struct str line = str_make (); struct str line = str_make ();
struct config_dump_level *iter = data->head; if (data->path.len)
if (iter) str_append (&line, data->path.vector[0]);
{ for (size_t i = 1; i < data->path.len; i++)
str_append (&line, iter->name); str_append_printf (&line, ".%s", data->path.vector[i]);
iter = iter->next;
}
for (; iter; iter = iter->next)
str_append_printf (&line, ".%s", iter->name);
struct str value = str_make (); struct str value = str_make ();
config_item_write (item, false, &value); config_item_write (item, false, &value);
@ -8027,11 +8007,13 @@ static void
config_dump (struct config_item *root, struct strv *output) config_dump (struct config_item *root, struct strv *output)
{ {
struct config_dump_data data; struct config_dump_data data;
data.head = NULL; data.path = strv_make ();
data.tail = &data.head;
data.output = output; data.output = output;
config_dump_item (root, &data); config_dump_item (root, &data);
hard_assert (!data.path.len);
strv_free (&data.path);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -