1 Return-Path: <sojkam1@fel.cvut.cz>
\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 1A0E6431FC3
\r
6 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 16:26:56 -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 lxhH0e21xcbj for <notmuch@notmuchmail.org>;
\r
16 Tue, 4 Nov 2014 16:26:52 -0800 (PST)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 0D01C431FC4
\r
19 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 16:26:23 -0800 (PST)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 756FC5CD1AB
\r
22 for <notmuch@notmuchmail.org>; Wed, 5 Nov 2014 01:26:22 +0100 (CET)
\r
23 X-Virus-Scanned: IMAP STYX AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,
\r
26 port 10044) with ESMTP id MdIJl_qV3mMX for <notmuch@notmuchmail.org>;
\r
27 Wed, 5 Nov 2014 01:26:17 +0100 (CET)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id 4C6CE5CD1AE
\r
30 for <notmuch@notmuchmail.org>; Wed, 5 Nov 2014 01:26:14 +0100 (CET)
\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)
\r
32 (envelope-from <sojkam1@fel.cvut.cz>)
\r
33 id 1XloQI-0005Cg-O9; Wed, 05 Nov 2014 01:26:06 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v3 01/10] cli: search: Rename options to context
\r
37 Date: Wed, 5 Nov 2014 01:25:50 +0100
\r
38 Message-Id: <1415147159-19946-2-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 2.1.1
\r
40 In-Reply-To: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 References: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>
\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, 05 Nov 2014 00:26:56 -0000
\r
56 In the next commit the options structure will be extended by
\r
57 non-option variables. Therefore we need a more generic name.
\r
59 Just text replacement, no other changes.
\r
61 notmuch-search.c | 142 +++++++++++++++++++++++++++----------------------------
\r
62 1 file changed, 71 insertions(+), 71 deletions(-)
\r
64 diff --git a/notmuch-search.c b/notmuch-search.c
\r
65 index 6345fb6..2c47b80 100644
\r
66 --- a/notmuch-search.c
\r
67 +++ b/notmuch-search.c
\r
68 @@ -42,7 +42,7 @@ typedef struct {
\r
72 -} search_options_t;
\r
73 +} search_context_t;
\r
77 @@ -89,39 +89,39 @@ get_thread_query (notmuch_thread_t *thread,
\r
81 -do_search_threads (search_options_t *opt)
\r
82 +do_search_threads (search_context_t *ctx)
\r
84 notmuch_thread_t *thread;
\r
85 notmuch_threads_t *threads;
\r
86 notmuch_tags_t *tags;
\r
87 - sprinter_t *format = opt->format;
\r
88 + sprinter_t *format = ctx->format;
\r
92 - if (opt->offset < 0) {
\r
93 - opt->offset += notmuch_query_count_threads (opt->query);
\r
94 - if (opt->offset < 0)
\r
96 + if (ctx->offset < 0) {
\r
97 + ctx->offset += notmuch_query_count_threads (ctx->query);
\r
98 + if (ctx->offset < 0)
\r
102 - threads = notmuch_query_search_threads (opt->query);
\r
103 + threads = notmuch_query_search_threads (ctx->query);
\r
104 if (threads == NULL)
\r
107 format->begin_list (format);
\r
110 - notmuch_threads_valid (threads) && (opt->limit < 0 || i < opt->offset + opt->limit);
\r
111 + notmuch_threads_valid (threads) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);
\r
112 notmuch_threads_move_to_next (threads), i++)
\r
114 thread = notmuch_threads_get (threads);
\r
116 - if (i < opt->offset) {
\r
117 + if (i < ctx->offset) {
\r
118 notmuch_thread_destroy (thread);
\r
122 - if (opt->output == OUTPUT_THREADS) {
\r
123 + if (ctx->output == OUTPUT_THREADS) {
\r
124 format->set_prefix (format, "thread");
\r
125 format->string (format,
\r
126 notmuch_thread_get_thread_id (thread));
\r
127 @@ -138,7 +138,7 @@ do_search_threads (search_options_t *opt)
\r
129 format->begin_map (format);
\r
131 - if (opt->sort == NOTMUCH_SORT_OLDEST_FIRST)
\r
132 + if (ctx->sort == NOTMUCH_SORT_OLDEST_FIRST)
\r
133 date = notmuch_thread_get_oldest_date (thread);
\r
135 date = notmuch_thread_get_newest_date (thread);
\r
136 @@ -230,11 +230,11 @@ do_search_threads (search_options_t *opt)
\r
140 -print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
\r
141 +print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox)
\r
143 const char *name = mailbox->name;
\r
144 const char *addr = mailbox->addr;
\r
145 - sprinter_t *format = opt->format;
\r
146 + sprinter_t *format = ctx->format;
\r
147 InternetAddress *ia = internet_address_mailbox_new (name, addr);
\r
150 @@ -263,7 +263,7 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
\r
152 /* Print addresses from InternetAddressList. */
\r
154 -process_address_list (const search_options_t *opt, InternetAddressList *list)
\r
155 +process_address_list (const search_context_t *ctx, InternetAddressList *list)
\r
157 InternetAddress *address;
\r
159 @@ -279,7 +279,7 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)
\r
160 if (group_list == NULL)
\r
163 - process_address_list (opt, group_list);
\r
164 + process_address_list (ctx, group_list);
\r
166 InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
\r
168 @@ -287,14 +287,14 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)
\r
169 .addr = internet_address_mailbox_get_addr (mailbox),
\r
172 - print_mailbox (opt, &mbx);
\r
173 + print_mailbox (ctx, &mbx);
\r
178 /* Print addresses from a message header. */
\r
180 -process_address_header (const search_options_t *opt, const char *value)
\r
181 +process_address_header (const search_context_t *ctx, const char *value)
\r
183 InternetAddressList *list;
\r
185 @@ -305,7 +305,7 @@ process_address_header (const search_options_t *opt, const char *value)
\r
189 - process_address_list (opt, list);
\r
190 + process_address_list (ctx, list);
\r
192 g_object_unref (list);
\r
194 @@ -329,36 +329,36 @@ _count_filenames (notmuch_message_t *message)
\r
198 -do_search_messages (search_options_t *opt)
\r
199 +do_search_messages (search_context_t *ctx)
\r
201 notmuch_message_t *message;
\r
202 notmuch_messages_t *messages;
\r
203 notmuch_filenames_t *filenames;
\r
204 - sprinter_t *format = opt->format;
\r
205 + sprinter_t *format = ctx->format;
\r
208 - if (opt->offset < 0) {
\r
209 - opt->offset += notmuch_query_count_messages (opt->query);
\r
210 - if (opt->offset < 0)
\r
212 + if (ctx->offset < 0) {
\r
213 + ctx->offset += notmuch_query_count_messages (ctx->query);
\r
214 + if (ctx->offset < 0)
\r
218 - messages = notmuch_query_search_messages (opt->query);
\r
219 + messages = notmuch_query_search_messages (ctx->query);
\r
220 if (messages == NULL)
\r
223 format->begin_list (format);
\r
226 - notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);
\r
227 + notmuch_messages_valid (messages) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);
\r
228 notmuch_messages_move_to_next (messages), i++)
\r
230 - if (i < opt->offset)
\r
231 + if (i < ctx->offset)
\r
234 message = notmuch_messages_get (messages);
\r
236 - if (opt->output == OUTPUT_FILES) {
\r
237 + if (ctx->output == OUTPUT_FILES) {
\r
239 filenames = notmuch_message_get_filenames (message);
\r
241 @@ -366,7 +366,7 @@ do_search_messages (search_options_t *opt)
\r
242 notmuch_filenames_valid (filenames);
\r
243 notmuch_filenames_move_to_next (filenames), j++)
\r
245 - if (opt->dupe < 0 || opt->dupe == j) {
\r
246 + if (ctx->dupe < 0 || ctx->dupe == j) {
\r
247 format->string (format, notmuch_filenames_get (filenames));
\r
248 format->separator (format);
\r
250 @@ -374,30 +374,30 @@ do_search_messages (search_options_t *opt)
\r
252 notmuch_filenames_destroy( filenames );
\r
254 - } else if (opt->output == OUTPUT_MESSAGES) {
\r
255 + } else if (ctx->output == OUTPUT_MESSAGES) {
\r
256 /* special case 1 for speed */
\r
257 - if (opt->dupe <= 1 || opt->dupe <= _count_filenames (message)) {
\r
258 + if (ctx->dupe <= 1 || ctx->dupe <= _count_filenames (message)) {
\r
259 format->set_prefix (format, "id");
\r
260 format->string (format,
\r
261 notmuch_message_get_message_id (message));
\r
262 format->separator (format);
\r
265 - if (opt->output & OUTPUT_SENDER) {
\r
266 + if (ctx->output & OUTPUT_SENDER) {
\r
269 addrs = notmuch_message_get_header (message, "from");
\r
270 - process_address_header (opt, addrs);
\r
271 + process_address_header (ctx, addrs);
\r
274 - if (opt->output & OUTPUT_RECIPIENTS) {
\r
275 + if (ctx->output & OUTPUT_RECIPIENTS) {
\r
276 const char *hdrs[] = { "to", "cc", "bcc" };
\r
280 for (j = 0; j < ARRAY_SIZE (hdrs); j++) {
\r
281 addrs = notmuch_message_get_header (message, hdrs[j]);
\r
282 - process_address_header (opt, addrs);
\r
283 + process_address_header (ctx, addrs);
\r
287 @@ -414,13 +414,13 @@ do_search_messages (search_options_t *opt)
\r
290 do_search_tags (notmuch_database_t *notmuch,
\r
291 - const search_options_t *opt)
\r
292 + const search_context_t *ctx)
\r
294 notmuch_messages_t *messages = NULL;
\r
295 notmuch_tags_t *tags;
\r
297 - sprinter_t *format = opt->format;
\r
298 - notmuch_query_t *query = opt->query;
\r
299 + sprinter_t *format = ctx->format;
\r
300 + notmuch_query_t *query = ctx->query;
\r
302 /* should the following only special case if no excluded terms
\r
304 @@ -465,7 +465,7 @@ int
\r
305 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
307 notmuch_database_t *notmuch;
\r
308 - search_options_t opt = {
\r
309 + search_context_t ctx = {
\r
310 .sort = NOTMUCH_SORT_NEWEST_FIRST,
\r
313 @@ -485,7 +485,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
314 } format_sel = NOTMUCH_FORMAT_TEXT;
\r
316 notmuch_opt_desc_t options[] = {
\r
317 - { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's',
\r
318 + { NOTMUCH_OPT_KEYWORD, &ctx.sort, "sort", 's',
\r
319 (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
320 { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
322 @@ -496,7 +496,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
323 { "text0", NOTMUCH_FORMAT_TEXT0 },
\r
325 { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
\r
326 - { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',
\r
327 + { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx.output, "output", 'o',
\r
328 (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
\r
329 { "threads", OUTPUT_THREADS },
\r
330 { "messages", OUTPUT_MESSAGES },
\r
331 @@ -511,9 +511,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
332 { "flag", NOTMUCH_EXCLUDE_FLAG },
\r
333 { "all", NOTMUCH_EXCLUDE_ALL },
\r
335 - { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 },
\r
336 - { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0 },
\r
337 - { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0 },
\r
338 + { NOTMUCH_OPT_INT, &ctx.offset, "offset", 'O', 0 },
\r
339 + { NOTMUCH_OPT_INT, &ctx.limit, "limit", 'L', 0 },
\r
340 + { NOTMUCH_OPT_INT, &ctx.dupe, "duplicate", 'D', 0 },
\r
344 @@ -521,31 +521,31 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
346 return EXIT_FAILURE;
\r
348 - if (! opt.output)
\r
349 - opt.output = OUTPUT_SUMMARY;
\r
350 + if (! ctx.output)
\r
351 + ctx.output = OUTPUT_SUMMARY;
\r
353 - if (opt.output != OUTPUT_FILES && opt.output != OUTPUT_MESSAGES &&
\r
354 - opt.dupe != -1) {
\r
355 + if (ctx.output != OUTPUT_FILES && ctx.output != OUTPUT_MESSAGES &&
\r
356 + ctx.dupe != -1) {
\r
357 fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");
\r
358 return EXIT_FAILURE;
\r
361 switch (format_sel) {
\r
362 case NOTMUCH_FORMAT_TEXT:
\r
363 - opt.format = sprinter_text_create (config, stdout);
\r
364 + ctx.format = sprinter_text_create (config, stdout);
\r
366 case NOTMUCH_FORMAT_TEXT0:
\r
367 - if (opt.output == OUTPUT_SUMMARY) {
\r
368 + if (ctx.output == OUTPUT_SUMMARY) {
\r
369 fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
\r
370 return EXIT_FAILURE;
\r
372 - opt.format = sprinter_text0_create (config, stdout);
\r
373 + ctx.format = sprinter_text0_create (config, stdout);
\r
375 case NOTMUCH_FORMAT_JSON:
\r
376 - opt.format = sprinter_json_create (config, stdout);
\r
377 + ctx.format = sprinter_json_create (config, stdout);
\r
379 case NOTMUCH_FORMAT_SEXP:
\r
380 - opt.format = sprinter_sexp_create (config, stdout);
\r
381 + ctx.format = sprinter_sexp_create (config, stdout);
\r
384 /* this should never happen */
\r
385 @@ -568,15 +568,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
386 return EXIT_FAILURE;
\r
389 - opt.query = notmuch_query_create (notmuch, query_str);
\r
390 - if (opt.query == NULL) {
\r
391 + ctx.query = notmuch_query_create (notmuch, query_str);
\r
392 + if (ctx.query == NULL) {
\r
393 fprintf (stderr, "Out of memory\n");
\r
394 return EXIT_FAILURE;
\r
397 - notmuch_query_set_sort (opt.query, opt.sort);
\r
398 + notmuch_query_set_sort (ctx.query, ctx.sort);
\r
400 - if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {
\r
401 + if (exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {
\r
402 /* If we are not doing summary output there is nowhere to
\r
403 * print the excluded flag so fall back on including the
\r
404 * excluded messages. */
\r
405 @@ -591,28 +591,28 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
406 search_exclude_tags = notmuch_config_get_search_exclude_tags
\r
407 (config, &search_exclude_tags_length);
\r
408 for (i = 0; i < search_exclude_tags_length; i++)
\r
409 - notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]);
\r
410 - notmuch_query_set_omit_excluded (opt.query, exclude);
\r
411 + notmuch_query_add_tag_exclude (ctx.query, search_exclude_tags[i]);
\r
412 + notmuch_query_set_omit_excluded (ctx.query, exclude);
\r
415 - if (opt.output == OUTPUT_SUMMARY ||
\r
416 - opt.output == OUTPUT_THREADS)
\r
417 - ret = do_search_threads (&opt);
\r
418 - else if (opt.output == OUTPUT_MESSAGES ||
\r
419 - opt.output == OUTPUT_FILES ||
\r
420 - (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))
\r
421 - ret = do_search_messages (&opt);
\r
422 - else if (opt.output == OUTPUT_TAGS)
\r
423 - ret = do_search_tags (notmuch, &opt);
\r
424 + if (ctx.output == OUTPUT_SUMMARY ||
\r
425 + ctx.output == OUTPUT_THREADS)
\r
426 + ret = do_search_threads (&ctx);
\r
427 + else if (ctx.output == OUTPUT_MESSAGES ||
\r
428 + ctx.output == OUTPUT_FILES ||
\r
429 + (ctx.output & OUTPUT_ADDRESS_FLAGS && !(ctx.output & ~OUTPUT_ADDRESS_FLAGS)))
\r
430 + ret = do_search_messages (&ctx);
\r
431 + else if (ctx.output == OUTPUT_TAGS)
\r
432 + ret = do_search_tags (notmuch, &ctx);
\r
434 fprintf (stderr, "Error: the combination of outputs is not supported.\n");
\r
438 - notmuch_query_destroy (opt.query);
\r
439 + notmuch_query_destroy (ctx.query);
\r
440 notmuch_database_destroy (notmuch);
\r
442 - talloc_free (opt.format);
\r
443 + talloc_free (ctx.format);
\r
445 return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r