1 Return-Path: <amthrax@drake.mit.edu>
\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 270D1431FB6
\r
6 for <notmuch@notmuchmail.org>; Tue, 10 Jan 2012 21:03:40 -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 6bb05VpFR-iX for <notmuch@notmuchmail.org>;
\r
16 Tue, 10 Jan 2012 21:03:39 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 9C7A5429E29
\r
20 for <notmuch@notmuchmail.org>; Tue, 10 Jan 2012 21:03:37 -0800 (PST)
\r
21 X-AuditID: 12074424-b7fae6d000000906-79-4f0d1829aff2
\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id CD.50.02310.9281D0F4; Wed, 11 Jan 2012 00:03:37 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0B53aao012429;
\r
27 Wed, 11 Jan 2012 00:03:36 -0500
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0B53ZZp017222
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Wed, 11 Jan 2012 00:03:36 -0500 (EST)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1RkqLX-0005dc-Cy; Wed, 11 Jan 2012 00:03:35 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 1/3] count: Convert to new-style argument parsing
\r
41 Date: Wed, 11 Jan 2012 00:02:51 -0500
\r
42 Message-Id: <1326258173-21163-2-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.7.3
\r
44 In-Reply-To: <1326258173-21163-1-git-send-email-amdragon@mit.edu>
\r
45 References: <20120109043101.GH20796@mit.edu>
\r
46 <1326258173-21163-1-git-send-email-amdragon@mit.edu>
\r
47 X-Brightmail-Tracker:
\r
48 H4sIAAAAAAAAA+NgFtrEIsWRmVeSWpSXmKPExsUixCmqraspwetv0HqX0+L6zZnMDowez1bd
\r
49 Yg5gjOKySUnNySxLLdK3S+DK+D73IntBu2jF58nX2BsY7/N3MXJySAiYSMzvn8gCYYtJXLi3
\r
50 nq2LkYtDSGAfo8S1v/tZIZwNjBJdn3uhMveZJH62v4Fy5jNKfOrZwgrSzyagIbFt/3JGEFtE
\r
51 QFpi593ZQHEODmYBEYl3M5lATGEBR4nvz0pAKlgEVCXW7PrGDGLzCjhI9KyYwQ5xhYLEudXn
\r
52 wGxOoPI7uzYzgdhCAskS7f0rmCcw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka66Xm1mi
\r
53 l5pSuokRFDTsLio7GJsPKR1iFOBgVOLhNUjl8RdiTSwrrsw9xCjJwaQkytsnxusvxJeUn1KZ
\r
54 kVicEV9UmpNafIhRgoNZSYRXMQuonDclsbIqtSgfJiXNwaIkzquh9c5PSCA9sSQ1OzW1ILUI
\r
55 JivDwaEkwbtXHGioYFFqempFWmZOCUKaiYMTZDgP0PBdIDW8xQWJucWZ6RD5U4yKUuK8vSAJ
\r
56 AZBERmkeXC8sql8xigO9Isx7AKSKB5gQ4LpfAQ1mAhq8ZR3I1cUliQgpqQbGWlb72Lnby8x2
\r
57 pyldFEzZsidm3t4Vm3U/SnvPn7v/l47ys5SkQ7OjL67qfvae2/jdq+i1ZqEvZ33c/+HWpZdx
\r
58 0q5ruA9Mfn+MqzIlv6Di7YMs0+enficnvDiSnyRvVbBxiUVW87HK/Gauxa+fmPVe0f2Wt2j9
\r
59 o+T7p7Jz7kyffXGW3W7vpEkc35RYijMSDbWYi4oTATWtCgDFAgAA
\r
60 X-BeenThere: notmuch@notmuchmail.org
\r
61 X-Mailman-Version: 2.1.13
\r
63 List-Id: "Use and development of the notmuch mail system."
\r
64 <notmuch.notmuchmail.org>
\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
68 List-Post: <mailto:notmuch@notmuchmail.org>
\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
72 X-List-Received-Date: Wed, 11 Jan 2012 05:03:40 -0000
\r
75 notmuch-count.c | 53 +++++++++++++++++++++++++----------------------------
\r
76 1 files changed, 25 insertions(+), 28 deletions(-)
\r
78 diff --git a/notmuch-count.c b/notmuch-count.c
\r
79 index 20ce334..fb7401b 100644
\r
80 --- a/notmuch-count.c
\r
81 +++ b/notmuch-count.c
\r
84 #include "notmuch-client.h"
\r
92 notmuch_count_command (void *ctx, int argc, char *argv[])
\r
94 @@ -28,35 +33,23 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
95 notmuch_database_t *notmuch;
\r
96 notmuch_query_t *query;
\r
99 - notmuch_bool_t output_messages = TRUE;
\r
101 + output_t output = OUTPUT_MESSAGES;
\r
103 - argc--; argv++; /* skip subcommand argument */
\r
104 + notmuch_opt_desc_t options[] = {
\r
105 + { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
\r
106 + (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
\r
107 + { "messages", OUTPUT_MESSAGES },
\r
109 + { 0, 0, 0, 0, 0 }
\r
112 - for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
113 - if (strcmp (argv[i], "--") == 0) {
\r
117 - if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
\r
118 - const char *opt = argv[i] + sizeof ("--output=") - 1;
\r
119 - if (strcmp (opt, "threads") == 0) {
\r
120 - output_messages = FALSE;
\r
121 - } else if (strcmp (opt, "messages") == 0) {
\r
122 - output_messages = TRUE;
\r
124 - fprintf (stderr, "Invalid value for --output: %s\n", opt);
\r
128 - fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
131 + opt_index = parse_arguments (argc, argv, options, 1);
\r
133 + if (opt_index < 0) {
\r
140 config = notmuch_config_open (ctx, NULL, NULL);
\r
141 if (config == NULL)
\r
143 @@ -66,7 +59,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
144 if (notmuch == NULL)
\r
147 - query_str = query_string_from_args (ctx, argc, argv);
\r
148 + query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
\r
149 if (query_str == NULL) {
\r
150 fprintf (stderr, "Out of memory.\n");
\r
152 @@ -82,10 +75,14 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
156 - if (output_messages)
\r
157 + switch (output) {
\r
158 + case OUTPUT_MESSAGES:
\r
159 printf ("%u\n", notmuch_query_count_messages (query));
\r
162 + case OUTPUT_THREADS:
\r
163 printf ("%u\n", notmuch_query_count_threads (query));
\r
167 notmuch_query_destroy (query);
\r
168 notmuch_database_close (notmuch);
\r