1 Return-Path: <bremner@pivot.cs.unb.ca>
\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 1B474429E2F
\r
6 for <notmuch@notmuchmail.org>; Wed, 7 Dec 2011 11:26:58 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 5efvo8hB1NOM for <notmuch@notmuchmail.org>;
\r
16 Wed, 7 Dec 2011 11:26:56 -0800 (PST)
\r
17 Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21])
\r
18 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 19286429E3D
\r
21 for <notmuch@notmuchmail.org>; Wed, 7 Dec 2011 11:26:49 -0800 (PST)
\r
22 Received: from convex-new.cs.unb.ca ([131.202.13.154])
\r
23 by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id pB7JQiPB021342;
\r
24 Wed, 7 Dec 2011 15:26:46 -0400
\r
25 Received: from bremner by convex-new.cs.unb.ca with local (Exim 4.72)
\r
26 (envelope-from <bremner@pivot.cs.unb.ca>)
\r
27 id 1RYN8d-0004Ps-Vb; Wed, 07 Dec 2011 15:26:43 -0400
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [PATCH v4 5/5] notmuch-search: convert to command-line-arguments
\r
31 Date: Wed, 7 Dec 2011 15:26:39 -0400
\r
32 Message-Id: <1323285999-16870-6-git-send-email-david@tethera.net>
\r
33 X-Mailer: git-send-email 1.7.5.4
\r
34 In-Reply-To: <1323285999-16870-1-git-send-email-david@tethera.net>
\r
35 References: <87iplso9c9.fsf@zancas.localnet>
\r
36 <1323285999-16870-1-git-send-email-david@tethera.net>
\r
37 Cc: David Bremner <bremner@debian.org>
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Wed, 07 Dec 2011 19:26:58 -0000
\r
52 From: David Bremner <bremner@debian.org>
\r
54 The switch on format_sel is slightly clunky, but it doesn't seem worth
\r
55 special casing argument processing for function pointers, when I think
\r
56 the function pointer approach will be modified/abandoned.
\r
58 notmuch-search.c | 106 +++++++++++++++++++----------------------------------
\r
59 1 files changed, 38 insertions(+), 68 deletions(-)
\r
61 diff --git a/notmuch-search.c b/notmuch-search.c
\r
62 index 36686d1..861c888 100644
\r
63 --- a/notmuch-search.c
\r
64 +++ b/notmuch-search.c
\r
65 @@ -415,81 +415,51 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
66 notmuch_database_t *notmuch;
\r
67 notmuch_query_t *query;
\r
70 notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
71 const search_format_t *format = &format_text;
\r
73 + int opt_index, ret;
\r
74 output_t output = OUTPUT_SUMMARY;
\r
76 int limit = -1; /* unlimited */
\r
78 - argc--; argv++; /* skip subcommand argument */
\r
80 - for (i = 0; i < argc && argv[i][0] == '-'; i++) {
\r
81 - if (strcmp (argv[i], "--") == 0) {
\r
85 - if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {
\r
86 - opt = argv[i] + sizeof ("--sort=") - 1;
\r
87 - if (strcmp (opt, "oldest-first") == 0) {
\r
88 - sort = NOTMUCH_SORT_OLDEST_FIRST;
\r
89 - } else if (strcmp (opt, "newest-first") == 0) {
\r
90 - sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
92 - fprintf (stderr, "Invalid value for --sort: %s\n", opt);
\r
95 - } else if (STRNCMP_LITERAL (argv[i], "--offset=") == 0) {
\r
97 - opt = argv[i] + sizeof ("--offset=") - 1;
\r
98 - offset = strtol (opt, &p, 10);
\r
99 - if (*opt == '\0' || p == opt || *p != '\0') {
\r
100 - fprintf (stderr, "Invalid value for --offset: %s\n", opt);
\r
103 - } else if (STRNCMP_LITERAL (argv[i], "--limit=") == 0) {
\r
105 - opt = argv[i] + sizeof ("--limit=") - 1;
\r
106 - limit = strtoul (opt, &p, 10);
\r
107 - if (*opt == '\0' || p == opt || *p != '\0') {
\r
108 - fprintf (stderr, "Invalid value for --limit: %s\n", opt);
\r
111 - } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
\r
112 - opt = argv[i] + sizeof ("--format=") - 1;
\r
113 - if (strcmp (opt, "text") == 0) {
\r
114 - format = &format_text;
\r
115 - } else if (strcmp (opt, "json") == 0) {
\r
116 - format = &format_json;
\r
118 - fprintf (stderr, "Invalid value for --format: %s\n", opt);
\r
121 - } else if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
\r
122 - opt = argv[i] + sizeof ("--output=") - 1;
\r
123 - if (strcmp (opt, "summary") == 0) {
\r
124 - output = OUTPUT_SUMMARY;
\r
125 - } else if (strcmp (opt, "threads") == 0) {
\r
126 - output = OUTPUT_THREADS;
\r
127 - } else if (strcmp (opt, "messages") == 0) {
\r
128 - output = OUTPUT_MESSAGES;
\r
129 - } else if (strcmp (opt, "files") == 0) {
\r
130 - output = OUTPUT_FILES;
\r
131 - } else if (strcmp (opt, "tags") == 0) {
\r
132 - output = OUTPUT_TAGS;
\r
134 - fprintf (stderr, "Invalid value for --output: %s\n", opt);
\r
138 - fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
141 + enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
\r
142 + format_sel = NOTMUCH_FORMAT_TEXT;
\r
144 + notmuch_opt_desc_t options[] = {
\r
145 + { NOTMUCH_OPT_KEYWORD, &sort, "sort", 's',
\r
146 + (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
147 + { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
149 + { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
\r
150 + (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
\r
151 + { "text", NOTMUCH_FORMAT_TEXT },
\r
153 + { NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
\r
154 + (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
\r
155 + { "threads", OUTPUT_THREADS },
\r
156 + { "messages", OUTPUT_MESSAGES },
\r
157 + { "files", OUTPUT_FILES },
\r
158 + { "tags", OUTPUT_TAGS },
\r
160 + { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },
\r
161 + { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0 },
\r
162 + { 0, 0, 0, 0, 0 }
\r
165 + opt_index = parse_arguments (argc, argv, options, 1);
\r
167 + if (opt_index < 0) {
\r
173 + switch (format_sel) {
\r
174 + case NOTMUCH_FORMAT_TEXT:
\r
175 + format = &format_text;
\r
177 + case NOTMUCH_FORMAT_JSON:
\r
178 + format = &format_json;
\r
182 config = notmuch_config_open (ctx, NULL, NULL);
\r
183 if (config == NULL)
\r
184 @@ -500,7 +470,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
185 if (notmuch == NULL)
\r
188 - query_str = query_string_from_args (notmuch, argc, argv);
\r
189 + query_str = query_string_from_args (notmuch, argc-opt_index, argv+opt_index);
\r
190 if (query_str == NULL) {
\r
191 fprintf (stderr, "Out of memory.\n");
\r