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 0AA9E429E29
\r
6 for <notmuch@notmuchmail.org>; Mon, 3 Nov 2014 15:51:00 -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 G8cIEpsFHp2J for <notmuch@notmuchmail.org>;
\r
16 Mon, 3 Nov 2014 15:50:55 -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 C05E1431FD9
\r
19 for <notmuch@notmuchmail.org>; Mon, 3 Nov 2014 15:50:47 -0800 (PST)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 3F23F5CD013
\r
22 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 00:50:47 +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 xi8OgttPjLlZ for <notmuch@notmuchmail.org>;
\r
27 Tue, 4 Nov 2014 00:50:40 +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 C67FA5CD008
\r
30 for <notmuch@notmuchmail.org>; Tue, 4 Nov 2014 00:50:40 +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 1XlROM-0005WM-1e; Tue, 04 Nov 2014 00:50:34 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v2 01/10] cli: search: Rename options to context
\r
37 Date: Tue, 4 Nov 2014 00:50:13 +0100
\r
38 Message-Id: <1415058622-21162-2-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 2.1.1
\r
40 In-Reply-To: <1415058622-21162-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 References: <1415058622-21162-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: Mon, 03 Nov 2014 23:51:00 -0000
\r
56 Just text replacement, no other changes.
\r
58 notmuch-search.c | 142 +++++++++++++++++++++++++++----------------------------
\r
59 1 file changed, 71 insertions(+), 71 deletions(-)
\r
61 diff --git a/notmuch-search.c b/notmuch-search.c
\r
62 index 6345fb6..2c47b80 100644
\r
63 --- a/notmuch-search.c
\r
64 +++ b/notmuch-search.c
\r
65 @@ -42,7 +42,7 @@ typedef struct {
\r
69 -} search_options_t;
\r
70 +} search_context_t;
\r
74 @@ -89,39 +89,39 @@ get_thread_query (notmuch_thread_t *thread,
\r
78 -do_search_threads (search_options_t *opt)
\r
79 +do_search_threads (search_context_t *ctx)
\r
81 notmuch_thread_t *thread;
\r
82 notmuch_threads_t *threads;
\r
83 notmuch_tags_t *tags;
\r
84 - sprinter_t *format = opt->format;
\r
85 + sprinter_t *format = ctx->format;
\r
89 - if (opt->offset < 0) {
\r
90 - opt->offset += notmuch_query_count_threads (opt->query);
\r
91 - if (opt->offset < 0)
\r
93 + if (ctx->offset < 0) {
\r
94 + ctx->offset += notmuch_query_count_threads (ctx->query);
\r
95 + if (ctx->offset < 0)
\r
99 - threads = notmuch_query_search_threads (opt->query);
\r
100 + threads = notmuch_query_search_threads (ctx->query);
\r
101 if (threads == NULL)
\r
104 format->begin_list (format);
\r
107 - notmuch_threads_valid (threads) && (opt->limit < 0 || i < opt->offset + opt->limit);
\r
108 + notmuch_threads_valid (threads) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);
\r
109 notmuch_threads_move_to_next (threads), i++)
\r
111 thread = notmuch_threads_get (threads);
\r
113 - if (i < opt->offset) {
\r
114 + if (i < ctx->offset) {
\r
115 notmuch_thread_destroy (thread);
\r
119 - if (opt->output == OUTPUT_THREADS) {
\r
120 + if (ctx->output == OUTPUT_THREADS) {
\r
121 format->set_prefix (format, "thread");
\r
122 format->string (format,
\r
123 notmuch_thread_get_thread_id (thread));
\r
124 @@ -138,7 +138,7 @@ do_search_threads (search_options_t *opt)
\r
126 format->begin_map (format);
\r
128 - if (opt->sort == NOTMUCH_SORT_OLDEST_FIRST)
\r
129 + if (ctx->sort == NOTMUCH_SORT_OLDEST_FIRST)
\r
130 date = notmuch_thread_get_oldest_date (thread);
\r
132 date = notmuch_thread_get_newest_date (thread);
\r
133 @@ -230,11 +230,11 @@ do_search_threads (search_options_t *opt)
\r
137 -print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
\r
138 +print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox)
\r
140 const char *name = mailbox->name;
\r
141 const char *addr = mailbox->addr;
\r
142 - sprinter_t *format = opt->format;
\r
143 + sprinter_t *format = ctx->format;
\r
144 InternetAddress *ia = internet_address_mailbox_new (name, addr);
\r
147 @@ -263,7 +263,7 @@ print_mailbox (const search_options_t *opt, const mailbox_t *mailbox)
\r
149 /* Print addresses from InternetAddressList. */
\r
151 -process_address_list (const search_options_t *opt, InternetAddressList *list)
\r
152 +process_address_list (const search_context_t *ctx, InternetAddressList *list)
\r
154 InternetAddress *address;
\r
156 @@ -279,7 +279,7 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)
\r
157 if (group_list == NULL)
\r
160 - process_address_list (opt, group_list);
\r
161 + process_address_list (ctx, group_list);
\r
163 InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
\r
165 @@ -287,14 +287,14 @@ process_address_list (const search_options_t *opt, InternetAddressList *list)
\r
166 .addr = internet_address_mailbox_get_addr (mailbox),
\r
169 - print_mailbox (opt, &mbx);
\r
170 + print_mailbox (ctx, &mbx);
\r
175 /* Print addresses from a message header. */
\r
177 -process_address_header (const search_options_t *opt, const char *value)
\r
178 +process_address_header (const search_context_t *ctx, const char *value)
\r
180 InternetAddressList *list;
\r
182 @@ -305,7 +305,7 @@ process_address_header (const search_options_t *opt, const char *value)
\r
186 - process_address_list (opt, list);
\r
187 + process_address_list (ctx, list);
\r
189 g_object_unref (list);
\r
191 @@ -329,36 +329,36 @@ _count_filenames (notmuch_message_t *message)
\r
195 -do_search_messages (search_options_t *opt)
\r
196 +do_search_messages (search_context_t *ctx)
\r
198 notmuch_message_t *message;
\r
199 notmuch_messages_t *messages;
\r
200 notmuch_filenames_t *filenames;
\r
201 - sprinter_t *format = opt->format;
\r
202 + sprinter_t *format = ctx->format;
\r
205 - if (opt->offset < 0) {
\r
206 - opt->offset += notmuch_query_count_messages (opt->query);
\r
207 - if (opt->offset < 0)
\r
209 + if (ctx->offset < 0) {
\r
210 + ctx->offset += notmuch_query_count_messages (ctx->query);
\r
211 + if (ctx->offset < 0)
\r
215 - messages = notmuch_query_search_messages (opt->query);
\r
216 + messages = notmuch_query_search_messages (ctx->query);
\r
217 if (messages == NULL)
\r
220 format->begin_list (format);
\r
223 - notmuch_messages_valid (messages) && (opt->limit < 0 || i < opt->offset + opt->limit);
\r
224 + notmuch_messages_valid (messages) && (ctx->limit < 0 || i < ctx->offset + ctx->limit);
\r
225 notmuch_messages_move_to_next (messages), i++)
\r
227 - if (i < opt->offset)
\r
228 + if (i < ctx->offset)
\r
231 message = notmuch_messages_get (messages);
\r
233 - if (opt->output == OUTPUT_FILES) {
\r
234 + if (ctx->output == OUTPUT_FILES) {
\r
236 filenames = notmuch_message_get_filenames (message);
\r
238 @@ -366,7 +366,7 @@ do_search_messages (search_options_t *opt)
\r
239 notmuch_filenames_valid (filenames);
\r
240 notmuch_filenames_move_to_next (filenames), j++)
\r
242 - if (opt->dupe < 0 || opt->dupe == j) {
\r
243 + if (ctx->dupe < 0 || ctx->dupe == j) {
\r
244 format->string (format, notmuch_filenames_get (filenames));
\r
245 format->separator (format);
\r
247 @@ -374,30 +374,30 @@ do_search_messages (search_options_t *opt)
\r
249 notmuch_filenames_destroy( filenames );
\r
251 - } else if (opt->output == OUTPUT_MESSAGES) {
\r
252 + } else if (ctx->output == OUTPUT_MESSAGES) {
\r
253 /* special case 1 for speed */
\r
254 - if (opt->dupe <= 1 || opt->dupe <= _count_filenames (message)) {
\r
255 + if (ctx->dupe <= 1 || ctx->dupe <= _count_filenames (message)) {
\r
256 format->set_prefix (format, "id");
\r
257 format->string (format,
\r
258 notmuch_message_get_message_id (message));
\r
259 format->separator (format);
\r
262 - if (opt->output & OUTPUT_SENDER) {
\r
263 + if (ctx->output & OUTPUT_SENDER) {
\r
266 addrs = notmuch_message_get_header (message, "from");
\r
267 - process_address_header (opt, addrs);
\r
268 + process_address_header (ctx, addrs);
\r
271 - if (opt->output & OUTPUT_RECIPIENTS) {
\r
272 + if (ctx->output & OUTPUT_RECIPIENTS) {
\r
273 const char *hdrs[] = { "to", "cc", "bcc" };
\r
277 for (j = 0; j < ARRAY_SIZE (hdrs); j++) {
\r
278 addrs = notmuch_message_get_header (message, hdrs[j]);
\r
279 - process_address_header (opt, addrs);
\r
280 + process_address_header (ctx, addrs);
\r
284 @@ -414,13 +414,13 @@ do_search_messages (search_options_t *opt)
\r
287 do_search_tags (notmuch_database_t *notmuch,
\r
288 - const search_options_t *opt)
\r
289 + const search_context_t *ctx)
\r
291 notmuch_messages_t *messages = NULL;
\r
292 notmuch_tags_t *tags;
\r
294 - sprinter_t *format = opt->format;
\r
295 - notmuch_query_t *query = opt->query;
\r
296 + sprinter_t *format = ctx->format;
\r
297 + notmuch_query_t *query = ctx->query;
\r
299 /* should the following only special case if no excluded terms
\r
301 @@ -465,7 +465,7 @@ int
\r
302 notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
304 notmuch_database_t *notmuch;
\r
305 - search_options_t opt = {
\r
306 + search_context_t ctx = {
\r
307 .sort = NOTMUCH_SORT_NEWEST_FIRST,
\r
310 @@ -485,7 +485,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
311 } format_sel = NOTMUCH_FORMAT_TEXT;
\r
313 notmuch_opt_desc_t options[] = {
\r
314 - { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's',
\r
315 + { NOTMUCH_OPT_KEYWORD, &ctx.sort, "sort", 's',
\r
316 (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
\r
317 { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
\r
319 @@ -496,7 +496,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
320 { "text0", NOTMUCH_FORMAT_TEXT0 },
\r
322 { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 },
\r
323 - { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',
\r
324 + { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx.output, "output", 'o',
\r
325 (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },
\r
326 { "threads", OUTPUT_THREADS },
\r
327 { "messages", OUTPUT_MESSAGES },
\r
328 @@ -511,9 +511,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
329 { "flag", NOTMUCH_EXCLUDE_FLAG },
\r
330 { "all", NOTMUCH_EXCLUDE_ALL },
\r
332 - { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 },
\r
333 - { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0 },
\r
334 - { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0 },
\r
335 + { NOTMUCH_OPT_INT, &ctx.offset, "offset", 'O', 0 },
\r
336 + { NOTMUCH_OPT_INT, &ctx.limit, "limit", 'L', 0 },
\r
337 + { NOTMUCH_OPT_INT, &ctx.dupe, "duplicate", 'D', 0 },
\r
341 @@ -521,31 +521,31 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
343 return EXIT_FAILURE;
\r
345 - if (! opt.output)
\r
346 - opt.output = OUTPUT_SUMMARY;
\r
347 + if (! ctx.output)
\r
348 + ctx.output = OUTPUT_SUMMARY;
\r
350 - if (opt.output != OUTPUT_FILES && opt.output != OUTPUT_MESSAGES &&
\r
351 - opt.dupe != -1) {
\r
352 + if (ctx.output != OUTPUT_FILES && ctx.output != OUTPUT_MESSAGES &&
\r
353 + ctx.dupe != -1) {
\r
354 fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");
\r
355 return EXIT_FAILURE;
\r
358 switch (format_sel) {
\r
359 case NOTMUCH_FORMAT_TEXT:
\r
360 - opt.format = sprinter_text_create (config, stdout);
\r
361 + ctx.format = sprinter_text_create (config, stdout);
\r
363 case NOTMUCH_FORMAT_TEXT0:
\r
364 - if (opt.output == OUTPUT_SUMMARY) {
\r
365 + if (ctx.output == OUTPUT_SUMMARY) {
\r
366 fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n");
\r
367 return EXIT_FAILURE;
\r
369 - opt.format = sprinter_text0_create (config, stdout);
\r
370 + ctx.format = sprinter_text0_create (config, stdout);
\r
372 case NOTMUCH_FORMAT_JSON:
\r
373 - opt.format = sprinter_json_create (config, stdout);
\r
374 + ctx.format = sprinter_json_create (config, stdout);
\r
376 case NOTMUCH_FORMAT_SEXP:
\r
377 - opt.format = sprinter_sexp_create (config, stdout);
\r
378 + ctx.format = sprinter_sexp_create (config, stdout);
\r
381 /* this should never happen */
\r
382 @@ -568,15 +568,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
383 return EXIT_FAILURE;
\r
386 - opt.query = notmuch_query_create (notmuch, query_str);
\r
387 - if (opt.query == NULL) {
\r
388 + ctx.query = notmuch_query_create (notmuch, query_str);
\r
389 + if (ctx.query == NULL) {
\r
390 fprintf (stderr, "Out of memory\n");
\r
391 return EXIT_FAILURE;
\r
394 - notmuch_query_set_sort (opt.query, opt.sort);
\r
395 + notmuch_query_set_sort (ctx.query, ctx.sort);
\r
397 - if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) {
\r
398 + if (exclude == NOTMUCH_EXCLUDE_FLAG && ctx.output != OUTPUT_SUMMARY) {
\r
399 /* If we are not doing summary output there is nowhere to
\r
400 * print the excluded flag so fall back on including the
\r
401 * excluded messages. */
\r
402 @@ -591,28 +591,28 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
403 search_exclude_tags = notmuch_config_get_search_exclude_tags
\r
404 (config, &search_exclude_tags_length);
\r
405 for (i = 0; i < search_exclude_tags_length; i++)
\r
406 - notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]);
\r
407 - notmuch_query_set_omit_excluded (opt.query, exclude);
\r
408 + notmuch_query_add_tag_exclude (ctx.query, search_exclude_tags[i]);
\r
409 + notmuch_query_set_omit_excluded (ctx.query, exclude);
\r
412 - if (opt.output == OUTPUT_SUMMARY ||
\r
413 - opt.output == OUTPUT_THREADS)
\r
414 - ret = do_search_threads (&opt);
\r
415 - else if (opt.output == OUTPUT_MESSAGES ||
\r
416 - opt.output == OUTPUT_FILES ||
\r
417 - (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS)))
\r
418 - ret = do_search_messages (&opt);
\r
419 - else if (opt.output == OUTPUT_TAGS)
\r
420 - ret = do_search_tags (notmuch, &opt);
\r
421 + if (ctx.output == OUTPUT_SUMMARY ||
\r
422 + ctx.output == OUTPUT_THREADS)
\r
423 + ret = do_search_threads (&ctx);
\r
424 + else if (ctx.output == OUTPUT_MESSAGES ||
\r
425 + ctx.output == OUTPUT_FILES ||
\r
426 + (ctx.output & OUTPUT_ADDRESS_FLAGS && !(ctx.output & ~OUTPUT_ADDRESS_FLAGS)))
\r
427 + ret = do_search_messages (&ctx);
\r
428 + else if (ctx.output == OUTPUT_TAGS)
\r
429 + ret = do_search_tags (notmuch, &ctx);
\r
431 fprintf (stderr, "Error: the combination of outputs is not supported.\n");
\r
435 - notmuch_query_destroy (opt.query);
\r
436 + notmuch_query_destroy (ctx.query);
\r
437 notmuch_database_destroy (notmuch);
\r
439 - talloc_free (opt.format);
\r
440 + talloc_free (ctx.format);
\r
442 return ret ? EXIT_FAILURE : EXIT_SUCCESS;
\r