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 E93D6417341 for ; Sat, 20 Mar 2010 03:22:14 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5 tests=[BAYES_20=-0.001] autolearn=ham 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 LOtAKEXQMmDW for ; Sat, 20 Mar 2010 03:22:14 -0700 (PDT) Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26]) by olra.theworths.org (Postfix) with ESMTP id 12C4941733B for ; Sat, 20 Mar 2010 03:22:14 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by flatline.sindominio.net (Postfix) with ESMTP id 5910A26282B; Sat, 20 Mar 2010 11:22:13 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at sindominio.net Received: from flatline.sindominio.net ([127.0.0.1]) by localhost (flatline.sindominio.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Bs3P71CXzcgQ; Sat, 20 Mar 2010 11:22:10 +0100 (CET) Received: from blackspot (heal.cauterized.net [89.140.131.167]) by flatline.sindominio.net (Postfix) with ESMTPA id 926F1262E3D; Sat, 20 Mar 2010 11:21:52 +0100 (CET) Received: by blackspot (Postfix, from userid 1000) id 8BB608BE00; Sat, 20 Mar 2010 11:24:55 +0100 (CET) From: Ruben Pollan To: notmuch@notmuchmail.org Date: Sat, 20 Mar 2010 11:23:25 +0100 Message-Id: <1269080605-5617-6-git-send-email-meskio@sindominio.net> X-Mailer: git-send-email 1.7.0 In-Reply-To: <873a09jt2t.fsf@yoom.home.cworth.org> References: <873a09jt2t.fsf@yoom.home.cworth.org> Subject: [notmuch] [PATCH 5/5] Added backwards iterator to tags 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: Sat, 20 Mar 2010 10:22:15 -0000 Added the functions notmuch_tags_move_to_prevoius, notmuch_tags_move_to_last and notmuch_tags_move_to_first to notmuch library. With them is possible to iterate backwards on tags. * notmuch_tags_move_to_prevoius do the opposite than notmuch_tags_move_to_next, getting the tags iterator one position backwards. * notmuch_tags_move_to_last move the iterator to the first last tag. * notmuch_tags_move_to_first move the iterator to the first valid tag. --- lib/notmuch.h | 28 ++++++++++++++++++++++++++++ lib/tags.c | 21 +++++++++++++++++++++ 2 files changed, 49 insertions(+), 0 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index b96b624..dc668dc 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1022,6 +1022,15 @@ notmuch_tags_valid (notmuch_tags_t *tags); const char * notmuch_tags_get (notmuch_tags_t *tags); +/* Move the 'tags' iterator to the first tag. + * + * After that the 'tags' iterator will be set to the first valid + * tag, so it can be use to iterate with + * notmuch_tags_move_to_next. + */ +void +notmuch_tags_move_to_first (notmuch_tags_t *tags); + /* Move the 'tags' iterator to the next tag. * * If 'tags' is already pointing at the last tag then the iterator @@ -1035,6 +1044,25 @@ notmuch_tags_get (notmuch_tags_t *tags); void notmuch_tags_move_to_next (notmuch_tags_t *tags); +/* Move the 'tags' iterator to the last tag. + * + * After that the 'tags' iterator will be set to the last valid + * tag, so it can be use to iterate with + * notmuch_tags_move_to_previous. + */ +void +notmuch_tags_move_to_last (notmuch_tags_t *tags); + +/* Move the 'tags' iterator to the previous tag. + * + * If 'tags' is already pointing at the first tag then the + * iterator will be moved to a point just beyond that first tag, + * (where notmuch_tags_valid will return FALSE and + * notmuch_tags_get will return NULL). + */ +void +notmuch_tags_move_to_previous (notmuch_tags_t *tags); + /* Destroy a notmuch_tags_t object. * * It's not strictly necessary to call this function. All memory from diff --git a/lib/tags.c b/lib/tags.c index 8fe4a3f..9c9a897 100644 --- a/lib/tags.c +++ b/lib/tags.c @@ -105,6 +105,12 @@ notmuch_tags_get (notmuch_tags_t *tags) } void +notmuch_tags_move_to_first (notmuch_tags_t *tags) +{ + tags->iterator = g_list_first (tags->tags); +} + +void notmuch_tags_move_to_next (notmuch_tags_t *tags) { if (tags->iterator == NULL) @@ -114,6 +120,21 @@ notmuch_tags_move_to_next (notmuch_tags_t *tags) } void +notmuch_tags_move_to_last (notmuch_tags_t *tags) +{ + tags->iterator = g_list_last (tags->tags); +} + +void +notmuch_tags_move_to_previous (notmuch_tags_t *tags) +{ + if (tags->iterator == NULL) + return; + + tags->iterator = tags->iterator->prev; +} + +void notmuch_tags_destroy (notmuch_tags_t *tags) { talloc_free (tags); -- 1.7.0