From 4b718209bc1a27c647db1b05c9686d84c10cc742 Mon Sep 17 00:00:00 2001 From: Andrew Sidwell Date: Thu, 10 Jul 2008 10:44:04 +0000 Subject: Fix the test harness' implementation of reparent_children(). svn path=/trunk/hubbub/; revision=4559 --- test/tree2.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/test/tree2.c b/test/tree2.c index 4cc9322..71bd3d7 100644 --- a/test/tree2.c +++ b/test/tree2.c @@ -531,15 +531,36 @@ int clone_node(void *ctx, void *node, bool deep, void **result) return 0; } -/* Reparent "node" to "new_parent" */ +/* Take all of the child nodes of "node" and append them to "new_parent" */ int reparent_children(void *ctx, void *node, void *new_parent) { - node_t *tparent = new_parent; - node_t *tchild = node; - void *nnode; + node_t *parent = new_parent; + node_t *old_parent = node; - remove_child(ctx, tchild->parent, tchild, &nnode); - append_child(ctx, tparent, tchild, &nnode); + node_t *insert; + node_t *kids; + + kids = old_parent->child; + if (!kids) return 0; + + old_parent->child = NULL; + + insert = parent->child; + if (!insert) { + parent->child = kids; + } else { + while (insert->next != NULL) { + insert = insert->next; + } + + insert->next = kids; + kids->prev = insert; + } + + while (kids) { + kids->parent = parent; + kids = kids->next; + } return 0; } -- cgit v1.2.3