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 AA47E429E48
\r
6 for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 15:07:12 -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 wZBEyzfzjRMx for <notmuch@notmuchmail.org>;
\r
16 Fri, 13 Jan 2012 15:07:12 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id CE0D4429E25
\r
20 for <notmuch@notmuchmail.org>; Fri, 13 Jan 2012 15:07:11 -0800 (PST)
\r
21 X-AuditID: 12074423-b7f9c6d0000008c3-4f-4f10b91fa8a8
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 87.0A.02243.F19B01F4; Fri, 13 Jan 2012 18:07:11 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0DN7ADO030620;
\r
27 Fri, 13 Jan 2012 18:07:10 -0500
\r
28 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0DN79cl028769
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Fri, 13 Jan 2012 18:07:09 -0500 (EST)
\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amthrax@drake.mit.edu>)
\r
36 id 1RlqDF-0003lq-0g; Fri, 13 Jan 2012 18:07:09 -0500
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v2 1/3] count: Convert to new-style argument parsing
\r
40 Date: Fri, 13 Jan 2012 18:07:02 -0500
\r
41 Message-Id: <1326496024-14403-2-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.7.7.3
\r
43 In-Reply-To: <1326496024-14403-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1326258173-21163-1-git-send-email-amdragon@mit.edu>
\r
45 <1326496024-14403-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFjrEIsWRmVeSWpSXmKPExsUixG6nriu/U8Df4NcPAYum6c4We/Z5WVy/
\r
48 OZPZgdnj7mkuj1v3X7N7PFt1izmAOYrLJiU1J7MstUjfLoErY/d9wYKPIhWPjv9ha2A8zd/F
\r
49 yMkhIWAisfrHRnYIW0ziwr31bF2MXBxCAvsYJS4fPwzlbGCUeLb/ByOEc5xJYtm6aVDOfEaJ
\r
50 5ys+soH0swloSGzbv5wRxBYRkJbYeXc2K4jNLOAo8fPeQyCbg0NYwEXi2v4CEJNFQFXi2dpo
\r
51 kApeAQeJrs/n2SCuUJA4t/oc2EWcQJ1/X3WCTRQSKJdYfGQN4wRG/gWMDKsYZVNyq3RzEzNz
\r
52 ilOTdYuTE/PyUot0zfRyM0v0UlNKNzGCg8pFeQfjn4NKhxgFOBiVeHglswT8hVgTy4orcw8x
\r
53 SnIwKYnyPtgGFOJLyk+pzEgszogvKs1JLT7EKMHBrCTCK2UKlONNSaysSi3Kh0lJc7AoifNq
\r
54 aL3zExJITyxJzU5NLUgtgsnKcHAoSfDy7wBqFCxKTU+tSMvMKUFIM3FwggznARrOBVLDW1yQ
\r
55 mFucmQ6RP8WoKCXOqwiSEABJZJTmwfXCov4VozjQK8K8vCBVPMCEAdf9CmgwE9DgshQ+kMEl
\r
56 iQgpqQZGtfp4jpnvC3hslPf9b4nosgw35M/yOe7C+z93p0XP3oanN/gCltt27GaM7p+1Iu8h
\r
57 34JDAsnrDartjO+Hxv4IlSgP119bGHPt/8y1l8PtK8/2RZyees5nvl6TgfQSr4Vm6UdKTZU/
\r
58 X5D5GPeu/Vf1R3+t4KMb45jCT+tFNK229F5607mi2V6JpTgj0VCLuag4EQD0ftmp1QIAAA==
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Fri, 13 Jan 2012 23:07:12 -0000
\r
74 notmuch-count.c | 53 +++++++++++++++++++++++++----------------------------
\r
75 1 files changed, 25 insertions(+), 28 deletions(-)
\r
77 diff --git a/notmuch-count.c b/notmuch-count.c
\r
78 index 20ce334..0982f99 100644
\r
79 --- a/notmuch-count.c
\r
80 +++ b/notmuch-count.c
\r
83 #include "notmuch-client.h"
\r
91 notmuch_count_command (void *ctx, int argc, char *argv[])
\r
93 @@ -28,35 +33,23 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
94 notmuch_database_t *notmuch;
\r
95 notmuch_query_t *query;
\r
98 - notmuch_bool_t output_messages = TRUE;
\r
100 + int output = OUTPUT_MESSAGES;
\r
102 - argc--; argv++; /* skip subcommand argument */
\r
103 + notmuch_opt_desc_t options[] = {
\r
104 + { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
\r
105 + (notmuch_keyword_t []){ { "threads", OUTPUT_THREADS },
\r
106 + { "messages", OUTPUT_MESSAGES },
\r
108 + { 0, 0, 0, 0, 0 }
\r
111 - for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
112 - if (strcmp (argv[i], "--") == 0) {
\r
116 - if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
\r
117 - const char *opt = argv[i] + sizeof ("--output=") - 1;
\r
118 - if (strcmp (opt, "threads") == 0) {
\r
119 - output_messages = FALSE;
\r
120 - } else if (strcmp (opt, "messages") == 0) {
\r
121 - output_messages = TRUE;
\r
123 - fprintf (stderr, "Invalid value for --output: %s\n", opt);
\r
127 - fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
130 + opt_index = parse_arguments (argc, argv, options, 1);
\r
132 + if (opt_index < 0) {
\r
139 config = notmuch_config_open (ctx, NULL, NULL);
\r
140 if (config == NULL)
\r
142 @@ -66,7 +59,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
143 if (notmuch == NULL)
\r
146 - query_str = query_string_from_args (ctx, argc, argv);
\r
147 + query_str = query_string_from_args (ctx, argc-opt_index, argv+opt_index);
\r
148 if (query_str == NULL) {
\r
149 fprintf (stderr, "Out of memory.\n");
\r
151 @@ -82,10 +75,14 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
\r
155 - if (output_messages)
\r
156 + switch (output) {
\r
157 + case OUTPUT_MESSAGES:
\r
158 printf ("%u\n", notmuch_query_count_messages (query));
\r
161 + case OUTPUT_THREADS:
\r
162 printf ("%u\n", notmuch_query_count_threads (query));
\r
166 notmuch_query_destroy (query);
\r
167 notmuch_database_close (notmuch);
\r