diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-23 23:38:44 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-23 23:38:44 (EDT) |
commit | 4fb37b1ef103fd9470a991cd334f2d3c99b52baf (patch) | |
tree | 719d97ce9b6dca2e69f35bfb3492ddbd03dfc213 /src | |
parent | 43e56dfed6deda657150c33cbaea700c60543cd0 (diff) | |
download | marquee-4fb37b1ef103fd9470a991cd334f2d3c99b52baf.zip marquee-4fb37b1ef103fd9470a991cd334f2d3c99b52baf.tar.gz marquee-4fb37b1ef103fd9470a991cd334f2d3c99b52baf.tar.bz2 |
mq_tree_foreach_from(): Fix tree traversal
Diffstat (limited to 'src')
-rw-r--r-- | src/tree.c | 33 |
1 files changed, 14 insertions, 19 deletions
@@ -214,7 +214,7 @@ mq_tree_seek(MqTree *node, gint offset) } static gboolean -foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), +foreach_down(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { for (; node; node = node->next) { @@ -225,7 +225,7 @@ foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), } if (node->first_child) { - if (foreach(node->first_child, cb, user_data) == + if (foreach_down(node->first_child, cb, user_data) == MQ_TREE_STOP) { return MQ_TREE_STOP; } @@ -241,29 +241,22 @@ mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), { print_head("foreach", node); - foreach(node->root->first_child, cb, user_data); + foreach_down(node->root->first_child, cb, user_data); } static gboolean -foreach_from(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), +foreach_up(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { - for (; node; node = node->next) { - print_node(node); - if (cb(node, user_data) == MQ_TREE_STOP) { + if (node->next) { + if (foreach_down(node->next, cb, user_data) == MQ_TREE_STOP) { return MQ_TREE_STOP; } - if (node->first_child) { - if (foreach_from(node->first_child, cb, user_data) == - MQ_TREE_STOP) { - return MQ_TREE_STOP; - } - } - if (node->parent && node->parent->next) { - if (foreach_from(node->parent->next, cb, user_data) == - MQ_TREE_STOP) { - return MQ_TREE_STOP; - } + } + + if (node->parent) { + if (foreach_up(node->parent, cb, user_data) == MQ_TREE_STOP) { + return MQ_TREE_STOP; } } @@ -276,5 +269,7 @@ mq_tree_foreach_from(MqTree *node, { print_head("foreach from", node); - foreach_from(node, cb, user_data); + if (foreach_down(node, cb, user_data) == MQ_TREE_CONTINUE) { + foreach_up(node, cb, user_data); + } } |