From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 164AF431FBD for ; Wed, 9 Dec 2009 05:08:11 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 IjlRJ3L9iplM for ; Wed, 9 Dec 2009 05:08:10 -0800 (PST) Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26]) by olra.theworths.org (Postfix) with ESMTP id 5258D431FAE for ; Wed, 9 Dec 2009 05:08:09 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by flatline.sindominio.net (Postfix) with ESMTP id C40E42623EE for ; Wed, 9 Dec 2009 14:08:07 +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 LT45ACUAghL7 for ; Wed, 9 Dec 2009 14:08:02 +0100 (CET) Received: from blackspot (rpollan-laptop.cern.ch [137.138.192.228]) by flatline.sindominio.net (Postfix) with ESMTPA id 024602624E3 for ; Wed, 9 Dec 2009 14:08:02 +0100 (CET) Received: by blackspot (Postfix, from userid 1000) id 061868BBF1; Wed, 9 Dec 2009 14:10:07 +0100 (CET) From: Ruben Pollan To: notmuch@notmuchmail.org Date: Wed, 9 Dec 2009 14:10:06 +0100 Message-Id: <1260364206-344-1-git-send-email-meskio@sindominio.net> X-Mailer: git-send-email 1.6.5.4 In-Reply-To: <20091126202347.GA16654@blackspot> References: <20091126202347.GA16654@blackspot> Subject: [PATCH] Added regress option to tags iterator X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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: Wed, 09 Dec 2009 13:08:11 -0000 Added the functions notmuch_tags_regress and notmuch_tags_is_first to notmuch library. With them is possible to iterate backwards on tags. * notmuch_tags_regress do the opposite than notmuch_tags_advance, getting the tags iterator one position backwards. * notmuch_tags_is_first return TRUE if the iterator is in the first tag. --- lib/notmuch.h | 8 ++++++++ lib/tags.c | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index e28ce46..db051c8 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -917,6 +917,10 @@ notmuch_message_destroy (notmuch_message_t *message); notmuch_bool_t notmuch_tags_has_more (notmuch_tags_t *tags); +/* Is the given notmuch_tags_t object on the first tags */ +notmuch_bool_t +notmuch_tags_is_first (notmuch_tags_t *tags); + /* Get the current tag from 'tags' as a string. * * Note: The returned string belongs to 'tags' and has a lifetime @@ -936,6 +940,10 @@ notmuch_tags_get (notmuch_tags_t *tags); void notmuch_tags_advance (notmuch_tags_t *tags); +/* Regress the 'tags' iterator to the previous result. */ +void +notmuch_tags_regress (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 85507e9..cf9e030 100644 --- a/lib/tags.c +++ b/lib/tags.c @@ -25,6 +25,7 @@ struct _notmuch_tags { int sorted; GList *tags; + GList *previous_node; GList *iterator; }; @@ -55,6 +56,7 @@ _notmuch_tags_create (void *ctx) tags->sorted = 1; tags->tags = NULL; + tags->previous_node = NULL; tags->iterator = NULL; return tags; @@ -94,6 +96,12 @@ notmuch_tags_has_more (notmuch_tags_t *tags) return tags->iterator != NULL; } +notmuch_bool_t +notmuch_tags_is_first (notmuch_tags_t *tags) +{ + return tags->previous_node == NULL; +} + const char * notmuch_tags_get (notmuch_tags_t *tags) { @@ -109,10 +117,21 @@ notmuch_tags_advance (notmuch_tags_t *tags) if (tags->iterator == NULL) return; + tags->previous_node = tags->iterator; tags->iterator = tags->iterator->next; } void +notmuch_tags_regress (notmuch_tags_t *tags) +{ + if (tags->previous_node == NULL) + return; + + tags->iterator = tags->previous_node; + tags->previous_node = tags->iterator->prev; +} + +void notmuch_tags_destroy (notmuch_tags_t *tags) { talloc_free (tags); -- 1.6.5.4