Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id ECBBC429E36 for ; Sun, 4 Dec 2011 11:31:59 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L3k4rJXmWMrz for ; Sun, 4 Dec 2011 11:31:57 -0800 (PST) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id 05E27429E28 for ; Sun, 4 Dec 2011 11:31:56 -0800 (PST) X-AuditID: 12074425-b7f116d0000008fe-ed-4edbcaac2d78 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 84.36.02302.CAACBDE4; Sun, 4 Dec 2011 14:31:56 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id pB4JVuBO006826; Sun, 4 Dec 2011 14:31:56 -0500 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pB4JVs9c029484 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 4 Dec 2011 14:31:55 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.76) (envelope-from ) id 1RXHn0-0002j5-TW; Sun, 04 Dec 2011 14:31:54 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 3/4] Utility function to seek in MIME trees in depth-first order. Date: Sun, 4 Dec 2011 14:31:39 -0500 Message-Id: <1323027100-10307-4-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1323027100-10307-1-git-send-email-amdragon@mit.edu> References: <1322446871-14986-1-git-send-email-amdragon@mit.edu> <1323027100-10307-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFIsWRmVeSWpSXmKPExsUixCmqrLvm1G0/g4bZ2hat3Z+ZLK5u7We3 2LPPy+L6zZnMDiweZ7vbWT3unuby2DnrLrvHs1W3mANYorhsUlJzMstSi/TtErgyOqdNYC2Y zFuxb9Z0lgbGtVxdjBwcEgImEl/2B3QxcgKZYhIX7q1n62Lk4hAS2McosfdKMwuEs55R4mbn JFYI5x6TxKzbx6Gc+YwS859tYgXpZxPQkNi2fzkjiC0iIC2x8+5ssDizQJ1E58Yz7CC2sECg xPc5r5hAbBYBVYmWxq1sIDavgIPEzqs3GCHuUJD4dWQVK8h5nAKOEjdvWYKEhQTKJe627Web wMi/gJFhFaNsSm6Vbm5iZk5xarJucXJiXl5qka6FXm5miV5qSukmRlCwsbuo7mCccEjpEKMA B6MSD2/miVt+QqyJZcWVuYcYJTmYlER5n5y87SfEl5SfUpmRWJwRX1Sak1p8iFGCg1lJhDdj MVCONyWxsiq1KB8mJc3BoiTO+3qHg5+QQHpiSWp2ampBahFMVoaDQ0mC9ynIUMGi1PTUirTM nBKENBMHJ8hwHqDhCqdAhhcXJOYWZ6ZD5E8x6nKcvNt/hlGIJS8/L1VKnJcDpEgApCijNA9u DixJvGIUB3pLmPcVyDoeYIKBm/QKaAkT0BLFxhsgS0oSEVJSDYzbntjpP6q+PDf9g+6n5eUb 2GbGephd0fZ/5xG/PGrnwuO/18tdz5svKvRx74k2QRUtyyjlU5N+ccRxL076L9p1Woep2GnT PjP7An9P/WS5xXZPtjQ+lk1yavrvYj29gLH9mwLjinPqCjuVsvj28btYnFgcKnDv2mcX2b8u T+QeC0xUXHhwwnolluKMREMt5qLiRABU1Wrv7QIAAA== Cc: dkg@fifthhorseman.net X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Dec 2011 19:32:00 -0000 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". --- mime-node.c | 25 +++++++++++++++++++++++++ notmuch-client.h | 5 +++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/mime-node.c b/mime-node.c index a8e4a59..207818e 100644 --- a/mime-node.c +++ b/mime-node.c @@ -232,3 +232,28 @@ mime_node_child (const mime_node_t *parent, int child) g_type_name (G_OBJECT_TYPE (parent->part))); } } + +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 = *n - 1; + for (i = 0; i < node->children && !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) +{ + return _mime_node_seek_dfs_walk (node, &n); +} diff --git a/notmuch-client.h b/notmuch-client.h index 752c234..5482969 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -318,4 +318,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message, mime_node_t * mime_node_child (const mime_node_t *parent, int child); +/* Return the nth child of node in a depth-first traversal. If n is + * 0, returns node itself. Returns NULL if there is no such part. */ +mime_node_t * +mime_node_seek_dfs (mime_node_t *node, int n); + #endif -- 1.7.5.4