From 956c19284195f3200a1370166bd8847e5d159588 Mon Sep 17 00:00:00 2001 From: Petr Rockai Date: Tue, 18 Nov 2014 23:39:11 +0100 Subject: [PATCH] libdm-config: Re-link config trees to reflect file order of keys/sections. --- libdm/libdm-config.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c index 4965e3229..c02638513 100644 --- a/libdm/libdm-config.c +++ b/libdm/libdm-config.c @@ -154,6 +154,24 @@ struct dm_config_tree *dm_config_insert_cascaded_tree(struct dm_config_tree *fir return first_cft; } +static struct dm_config_node *_config_reverse(struct dm_config_node *head) +{ + if (!head) + return NULL; + + struct dm_config_node *left = head, *middle = NULL, *right = NULL; + + do { + right = middle; + middle = left; + left = left->sib; + middle->sib = right; + middle->child = _config_reverse(middle->child); + } while (left); + + return middle; +}; + int dm_config_parse(struct dm_config_tree *cft, const char *start, const char *end) { /* TODO? if (start == end) return 1; */ @@ -172,6 +190,8 @@ int dm_config_parse(struct dm_config_tree *cft, const char *start, const char *e if (!(cft->root = _file(p))) return_0; + cft->root = _config_reverse(cft->root); + return 1; }