summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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 */