diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-23 07:31:31 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-23 07:31:31 (EDT) |
commit | 4d5e5657bc1894dae524045be3097eb42c43bc12 (patch) | |
tree | 395b03c681b080f50422c92eb414e149f9209e6e /src | |
parent | 4d61838c33028595652f5ff54f76c10058b35e91 (diff) | |
download | marquee-4d5e5657bc1894dae524045be3097eb42c43bc12.zip marquee-4d5e5657bc1894dae524045be3097eb42c43bc12.tar.gz marquee-4d5e5657bc1894dae524045be3097eb42c43bc12.tar.bz2 |
mq_tree_foreach_from(): New function
Diffstat (limited to 'src')
-rw-r--r-- | src/tree.c | 32 | ||||
-rw-r--r-- | src/tree.h | 4 |
2 files changed, 36 insertions, 0 deletions
@@ -201,3 +201,35 @@ mq_tree_foreach_child(MqTree *node, { foreach_child(node->root->first_child, cb, user_data); } + +static gboolean +foreach_from(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) +{ + for (; node; node = node->next) { + if (cb(node, 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; + } + } + } + + return MQ_TREE_CONTINUE; +} + +void +mq_tree_foreach_from(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) +{ + foreach_from(node, cb, user_data); +} @@ -81,6 +81,10 @@ void mq_tree_foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data); +void +mq_tree_foreach_from(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data); + G_END_DECLS #endif /* MQ_TREE_H */ |