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 B62EA429E54 for ; Sun, 22 Jan 2012 21:08:07 -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 66RznvDQNUI8 for ; Sun, 22 Jan 2012 21:08:07 -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 268E3429E40 for ; Sun, 22 Jan 2012 21:08:07 -0800 (PST) X-AuditID: 12074425-b7f4a6d0000008e0-93-4f1ceb36bfd1 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 4E.4A.02272.63BEC1F4; Mon, 23 Jan 2012 00:08:06 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0N585G7023710; Mon, 23 Jan 2012 00:08:06 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0N584kS001140 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 23 Jan 2012 00:08:05 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RpC81-0002NU-Dj; Mon, 23 Jan 2012 00:07:37 -0500 Date: Mon, 23 Jan 2012 00:07:37 -0500 From: Austin Clements To: Pieter Praet Subject: Re: [PATCH v2 4/6] setup: move tag printing and parsing into separate functions Message-ID: <20120123050737.GT16740@mit.edu> References: <87obtvaw8h.fsf@praet.org> <1327292557-7701-4-git-send-email-pieter@praet.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1327292557-7701-4-git-send-email-pieter@praet.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT1zV7LeNvMPGpjsX1mzOZLX6/vsHs wOTxbNUtZo+OfZdZA5iiuGxSUnMyy1KL9O0SuDL2/P/DUvBLrOLxi5AGxrmCXYycHBICJhJH Dk5kgrDFJC7cW8/WxcjFISSwj1Fi2r3NrBDOBkaJjwsPs0M4J5kkDn+6wAThLGGUOLN3MgtI P4uAqsTGVd/AZrEJaEhs27+cEcQWEVCWOP3kJzuIzSygJbF14wewuLBAlMTbRa+AVnBw8Aro SLy97wQSFhKIkbix8wUziM0rIChxcuYTFpjWG/9eMoGUMwtISyz/xwES5hRwkPg15zhYuaiA isSUk9vYJjAKzULSPQtJ9yyE7gWMzKsYZVNyq3RzEzNzilOTdYuTE/PyUot0LfRyM0v0UlNK NzGCg9pFdQfjhENKhxgFOBiVeHgjlsr4C7EmlhVX5h5ilORgUhLl3foCKMSXlJ9SmZFYnBFf VJqTWnyIUYKDWUmE1+gxUI43JbGyKrUoHyYlzcGiJM6rqfXOT0ggPbEkNTs1tSC1CCYrw8Gh JMF7/RVQo2BRanpqRVpmTglCmomDE2Q4D9DwJpAa3uKCxNzizHSI/ClGRSlx3mUgCQGQREZp HlwvLOm8YhQHekWYtxmkigeYsOC6XwENZgIazJEnBTK4JBEhJdXAuK93osnjXflOC/Mf6L/8 maTYqnbsjtdzA7nIbfzrrcpjayNXHcwT3rtupkgHb6CgKptlulL7o6N2298snGsnwM9nOP3a XU2zvIeaPnvTHN9+7Y45tf7q4iWWyakxeUs5kp7uPLbIbXdx9I2N5U88Dx3f+fxQ8d5zzjkH b3g9Xxs2hUtcrGmDsBJLcUaioRZzUXEiABwQh48VAwAA Cc: Notmuch Mail 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: Mon, 23 Jan 2012 05:08:07 -0000 Quoth Pieter Praet on Jan 23 at 5:22 am: > From: Austin Clements > > * notmuch-setup.c (notmuch_setup_command): > Break tag printing and response parsing out into separate functions > called `print_tag_list' respectively `parse_tag_list', for reuse > with the 'search.exclude_tags' option. Since I'm revising this patch a little bit anyway, how about setup: Create functions for tag list printing and parsing This refactors the tag list printing and parsing currently used for new.tags so that both can be reused for the new search.exclude_tags option. > > --- > notmuch-setup.c | 55 ++++++++++++++++++++++++++++++++++--------------------- > 1 files changed, 34 insertions(+), 21 deletions(-) > > diff --git a/notmuch-setup.c b/notmuch-setup.c > index c3ea937..dcfa607 100644 > --- a/notmuch-setup.c > +++ b/notmuch-setup.c > @@ -87,6 +87,38 @@ welcome_message_post_setup (void) > "have sufficient storage space available now.\n\n"); > } > > +static void > +print_tag_list (const char **tags, size_t tags_len) > +{ > + unsigned int i; > + for (i = 0; i < tags_len; i++) { > + if (i != 0) > + printf (" "); > + printf ("%s", tags[i]); > + } > +} > + > +static GPtrArray * > +parse_tag_list (void *ctx, char *response) > +{ > + GPtrArray *tags = g_ptr_array_new (); > + char *tag = response; > + char *space; > + > + while (tag && *tag) { > + space = strchr (tag, ' '); > + if (space) > + g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag)); > + else > + g_ptr_array_add (tags, talloc_strdup (ctx, tag)); > + tag = space; > + while (tag && *tag == ' ') > + tag++; > + } > + > + return tags; > +} > + > int > notmuch_setup_command (unused (void *ctx), > unused (int argc), unused (char *argv[])) > @@ -164,30 +196,11 @@ notmuch_setup_command (unused (void *ctx), > new_tags = notmuch_config_get_new_tags (config, &new_tags_len); > > printf ("Tags to apply to all new messages (separated by spaces) ["); > - > - for (i = 0; i < new_tags_len; i++) { > - if (i != 0) > - printf (" "); > - printf ("%s", new_tags[i]); > - } > - > + print_tag_list(new_tags, new_tags_len); Missing space before paren. (Sorry, my fault.) > prompt ("]: "); > > if (strlen (response)) { > - GPtrArray *tags = g_ptr_array_new (); > - char *tag = response; > - char *space; > - > - while (tag && *tag) { > - space = strchr (tag, ' '); > - if (space) > - g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag)); > - else > - g_ptr_array_add (tags, talloc_strdup (ctx, tag)); > - tag = space; > - while (tag && *tag == ' ') > - tag++; > - } > + GPtrArray *tags = parse_tag_list (ctx, response); > > notmuch_config_set_new_tags (config, (const char **) tags->pdata, > tags->len);