summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-23 07:31:31 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-23 07:31:31 (EDT)
commit4d5e5657bc1894dae524045be3097eb42c43bc12 (patch)
tree395b03c681b080f50422c92eb414e149f9209e6e /src
parent4d61838c33028595652f5ff54f76c10058b35e91 (diff)
downloadmarquee-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.c32
-rw-r--r--src/tree.h4
2 files changed, 36 insertions, 0 deletions
diff --git a/src/tree.c b/src/tree.c
index 90a7af7..b64bc5e 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -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);
+}
diff --git a/src/tree.h b/src/tree.h
index 70e24d5..4d06a65 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -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 */