1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 58894431FD0
\r
6 for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 00:17:14 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id Tjj4mk9yjBqh for <notmuch@notmuchmail.org>;
\r
16 Wed, 11 Jan 2012 00:17:13 -0800 (PST)
\r
17 Received: from mail-qw0-f46.google.com (mail-qw0-f46.google.com
\r
18 [209.85.216.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 9702A431FB6
\r
21 for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 00:17:13 -0800 (PST)
\r
22 Received: by qats34 with SMTP id s34so2564896qat.5
\r
23 for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 00:17:12 -0800 (PST)
\r
24 Received: by 10.224.116.16 with SMTP id k16mr26394533qaq.28.1326269829950;
\r
25 Wed, 11 Jan 2012 00:17:09 -0800 (PST)
\r
26 Received: from localhost (nikula.org. [92.243.24.172])
\r
27 by mx.google.com with ESMTPS id o8sm2215121qaj.0.2012.01.11.00.17.07
\r
28 (version=SSLv3 cipher=OTHER); Wed, 11 Jan 2012 00:17:08 -0800 (PST)
\r
29 From: Jani Nikula <jani@nikula.org>
\r
30 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
\r
31 Subject: Re: [PATCH 1/3] count: Convert to new-style argument parsing
\r
32 In-Reply-To: <1326258173-21163-2-git-send-email-amdragon@mit.edu>
\r
33 References: <20120109043101.GH20796@mit.edu>
\r
34 <1326258173-21163-1-git-send-email-amdragon@mit.edu>
\r
35 <1326258173-21163-2-git-send-email-amdragon@mit.edu>
\r
36 User-Agent: Notmuch/0.10.2+129~g8a76c81 (http://notmuchmail.org) Emacs/23.1.1
\r
38 Date: Wed, 11 Jan 2012 08:17:05 +0000
\r
39 Message-ID: <87zkdulkla.fsf@nikula.org>
\r
41 Content-Type: text/plain; charset=us-ascii
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Wed, 11 Jan 2012 08:17:14 -0000
\r
56 On Wed, 11 Jan 2012 00:02:51 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
\r
58 > notmuch-count.c | 53 +++++++++++++++++++++++++----------------------------
\r
59 > 1 files changed, 25 insertions(+), 28 deletions(-)
\r
61 > diff --git a/notmuch-count.c b/notmuch-count.c
\r
62 > index 20ce334..fb7401b 100644
\r
63 > --- a/notmuch-count.c
\r
64 > +++ b/notmuch-count.c
\r
65 > @@ -21,6 +21,11 @@
\r
67 > #include "notmuch-client.h"
\r
71 > + OUTPUT_MESSAGES,
\r
75 > notmuch_count_command (void *ctx, int argc, char *argv[])
\r
77 > @@ -28,35 +33,23 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
78 > notmuch_database_t *notmuch;
\r
79 > notmuch_query_t *query;
\r
82 > - notmuch_bool_t output_messages = TRUE;
\r
84 > + output_t output = OUTPUT_MESSAGES;
\r
86 > - argc--; argv++; /* skip subcommand argument */
\r
87 > + notmuch_opt_desc_t options[] = {
\r
88 > + { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
\r
89 > + (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
\r
90 > + { "messages", OUTPUT_MESSAGES },
\r
93 To be pedantic, parse_arguments() expects 'output_var' to be a pointer
\r
94 to int for NOTMUCH_OPT_KEYWORD. sizeof(enum) is implementation
\r
95 dependent. I would forget about output_t typedef, use plain enum, and
\r
96 int type for 'output'.
\r
98 In fact, this is exactly what I did in commits
\r
99 e6d89ad723f775952d89d4f81b6072617c5caf18 and
\r
100 be5619cca32452f1a398add85908d78d6e72f469. In the latter I could have
\r
101 used notmuch_bool_t because it's a typedeffed int, but then I would've
\r
102 depended on some external typedef not changing (it probably won't, but
\r
103 this is defensive programming).
\r
105 Otherwise, looks good.
\r
111 > + { 0, 0, 0, 0, 0 }
\r
114 > - for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
115 > - if (strcmp (argv[i], "--") == 0) {
\r
119 > - if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
\r
120 > - const char *opt = argv[i] + sizeof ("--output=") - 1;
\r
121 > - if (strcmp (opt, "threads") == 0) {
\r
122 > - output_messages = FALSE;
\r
123 > - } else if (strcmp (opt, "messages") == 0) {
\r
124 > - output_messages = TRUE;
\r
126 > - fprintf (stderr, "Invalid value for --output: %s\n", opt);
\r
130 > - fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
133 > + opt_index = parse_arguments (argc, argv, options, 1);
\r
135 > + if (opt_index < 0) {
\r
142 > config = notmuch_config_open (ctx, NULL, NULL);
\r
143 > if (config == NULL)
\r
145 > @@ -66,7 +59,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
146 > if (notmuch == NULL)
\r
149 > - query_str = query_string_from_args (ctx, argc, argv);
\r
150 > + query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
\r
151 > if (query_str == NULL) {
\r
152 > fprintf (stderr, "Out of memory.\n");
\r
154 > @@ -82,10 +75,14 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
158 > - if (output_messages)
\r
159 > + switch (output) {
\r
160 > + case OUTPUT_MESSAGES:
\r
161 > printf ("%u\n", notmuch_query_count_messages (query));
\r
164 > + case OUTPUT_THREADS:
\r
165 > printf ("%u\n", notmuch_query_count_threads (query));
\r
169 > notmuch_query_destroy (query);
\r
170 > notmuch_database_close (notmuch);
\r
174 > _______________________________________________
\r
175 > notmuch mailing list
\r
176 > notmuch@notmuchmail.org
\r
177 > http://notmuchmail.org/mailman/listinfo/notmuch
\r