aboutsummaryrefslogtreecommitdiffhomepage
path: root/mime-node.c
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@MIT.EDU>2011-12-24 13:52:45 -0500
committerGravatar David Bremner <bremner@debian.org>2011-12-25 22:21:04 -0400
commit5d1ac7d1d351c6f122ddaa44d3c82ec68d45178c (patch)
tree132ffcd30cdc57ba076afb2881d03d5ae78b50dc /mime-node.c
parentbb189220a323e3140198161234ed54bf98175469 (diff)
Utility function to seek in MIME trees in depth-first order.
This function matches how we number parts for the --part argument to show. It will allow us to jump directly to the desired part, rather than traversing the entire tree and carefully tracking whether or not we're "in the zone".
Diffstat (limited to 'mime-node.c')
-rw-r--r--mime-node.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/mime-node.c b/mime-node.c
index 760c55f6..d26bb445 100644
--- a/mime-node.c
+++ b/mime-node.c
@@ -236,3 +236,30 @@ mime_node_child (const mime_node_t *parent, int child)
}
return _mime_node_create (parent, sub);
}
+
+static mime_node_t *
+_mime_node_seek_dfs_walk (mime_node_t *node, int *n)
+{
+ mime_node_t *ret = NULL;
+ int i;
+
+ if (*n == 0)
+ return node;
+
+ *n -= 1;
+ for (i = 0; i < node->nchildren && !ret; i++) {
+ mime_node_t *child = mime_node_child (node, i);
+ ret = _mime_node_seek_dfs_walk (child, n);
+ if (!ret)
+ talloc_free (child);
+ }
+ return ret;
+}
+
+mime_node_t *
+mime_node_seek_dfs (mime_node_t *node, int n)
+{
+ if (n < 0)
+ return NULL;
+ return _mime_node_seek_dfs_walk (node, &n);
+}