[PATCH 5/5] contrib: pick: remove unused function
[notmuch-archives.git] / ba / 1ac0348c9ab962b750cba19044de03982edff8
1 Return-Path: <jani@nikula.org>\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 CADE3429E34\r
6         for <notmuch@notmuchmail.org>; Fri,  4 Nov 2011 13:25:29 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 3JNwgFqfgDLa for <notmuch@notmuchmail.org>;\r
17         Fri,  4 Nov 2011 13:25:26 -0700 (PDT)\r
18 Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
19         [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 11AE1429E31\r
22         for <notmuch@notmuchmail.org>; Fri,  4 Nov 2011 13:25:22 -0700 (PDT)\r
23 Received: by mail-fx0-f53.google.com with SMTP id n15so52582faa.26\r
24         for <notmuch@notmuchmail.org>; Fri, 04 Nov 2011 13:25:22 -0700 (PDT)\r
25 Received: by 10.223.91.143 with SMTP id n15mr26503211fam.23.1320438322629;\r
26         Fri, 04 Nov 2011 13:25:22 -0700 (PDT)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id l18sm18312680fab.9.2011.11.04.13.25.21\r
30         (version=SSLv3 cipher=OTHER); Fri, 04 Nov 2011 13:25:22 -0700 (PDT)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH v3 2/7] cli: add options --first and --maxitems to notmuch\r
34         search\r
35 Date: Fri,  4 Nov 2011 22:25:10 +0200\r
36 Message-Id:\r
37  <e8eb7e3462fa813abb05788167e6ed912ef67e1c.1320349030.git.jani@nikula.org>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <cover.1320349030.git.jani@nikula.org>\r
40 References: <cover.1320349030.git.jani@nikula.org>\r
41 In-Reply-To: <cover.1320349030.git.jani@nikula.org>\r
42 References: <cover.1320349030.git.jani@nikula.org>\r
43 Cc: amdragon@mit.edu\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Fri, 04 Nov 2011 20:25:30 -0000\r
57 \r
58 Add options --first=[-]N and --maxitems=M to notmuch search to determine\r
59 the first result and maximum number of results to display.\r
60 \r
61 Option --maxitems=M limits the maximum number of results to display to M.\r
62 \r
63 Option --first=[-]N skips the first N results; with the leading '-' skip\r
64 until the Nth result from the end (showing a total of N results if within\r
65 bounds of the total number of results and not limited with --maxitems).\r
66 \r
67 Note that --first with a negative N for thread or summary output requires\r
68 counting the number of matching threads in advance.\r
69 \r
70 Signed-off-by: Jani Nikula <jani@nikula.org>\r
71 ---\r
72  notmuch-search.c |   70 ++++++++++++++++++++++++++++++++++++++++++++---------\r
73  1 files changed, 58 insertions(+), 12 deletions(-)\r
74 \r
75 diff --git a/notmuch-search.c b/notmuch-search.c\r
76 index 6f04d9a..e1168f9 100644\r
77 --- a/notmuch-search.c\r
78 +++ b/notmuch-search.c\r
79 @@ -194,13 +194,22 @@ static int\r
80  do_search_threads (const search_format_t *format,\r
81                    notmuch_query_t *query,\r
82                    notmuch_sort_t sort,\r
83 -                  output_t output)\r
84 +                  output_t output,\r
85 +                  int first,\r
86 +                  int maxitems)\r
87  {\r
88      notmuch_thread_t *thread;\r
89      notmuch_threads_t *threads;\r
90      notmuch_tags_t *tags;\r
91      time_t date;\r
92      int first_thread = 1;\r
93 +    int i;\r
94 +\r
95 +    if (first < 0) {\r
96 +       first += notmuch_query_count_threads (query);\r
97 +       if (first < 0)\r
98 +           first = 0;\r
99 +    }\r
100  \r
101      threads = notmuch_query_search_threads (query);\r
102      if (threads == NULL)\r
103 @@ -208,17 +217,23 @@ do_search_threads (const search_format_t *format,\r
104  \r
105      fputs (format->results_start, stdout);\r
106  \r
107 -    for (;\r
108 -        notmuch_threads_valid (threads);\r
109 -        notmuch_threads_move_to_next (threads))\r
110 +    for (i = 0;\r
111 +        notmuch_threads_valid (threads) &&\r
112 +            (maxitems < 0 || i < first + maxitems);\r
113 +        notmuch_threads_move_to_next (threads), i++)\r
114      {\r
115         int first_tag = 1;\r
116  \r
117 +       thread = notmuch_threads_get (threads);\r
118 +\r
119 +       if (i < first) {\r
120 +           notmuch_thread_destroy (thread);\r
121 +           continue;\r
122 +       }\r
123 +\r
124         if (! first_thread)\r
125             fputs (format->item_sep, stdout);\r
126  \r
127 -       thread = notmuch_threads_get (threads);\r
128 -\r
129         if (output == OUTPUT_THREADS) {\r
130             format->item_id (thread, "thread:",\r
131                              notmuch_thread_get_thread_id (thread));\r
132 @@ -271,12 +286,21 @@ do_search_threads (const search_format_t *format,\r
133  static int\r
134  do_search_messages (const search_format_t *format,\r
135                     notmuch_query_t *query,\r
136 -                   output_t output)\r
137 +                   output_t output,\r
138 +                   int first,\r
139 +                   int maxitems)\r
140  {\r
141      notmuch_message_t *message;\r
142      notmuch_messages_t *messages;\r
143      notmuch_filenames_t *filenames;\r
144      int first_message = 1;\r
145 +    int i;\r
146 +\r
147 +    if (first < 0) {\r
148 +       first += notmuch_query_count_messages (query);\r
149 +       if (first < 0)\r
150 +           first = 0;\r
151 +    }\r
152  \r
153      messages = notmuch_query_search_messages (query);\r
154      if (messages == NULL)\r
155 @@ -284,10 +308,14 @@ do_search_messages (const search_format_t *format,\r
156  \r
157      fputs (format->results_start, stdout);\r
158  \r
159 -    for (;\r
160 -        notmuch_messages_valid (messages);\r
161 -        notmuch_messages_move_to_next (messages))\r
162 +    for (i = 0;\r
163 +        notmuch_messages_valid (messages) &&\r
164 +            (maxitems < 0 || i < first + maxitems);\r
165 +        notmuch_messages_move_to_next (messages), i++)\r
166      {\r
167 +       if (i < first)\r
168 +           continue;\r
169 +\r
170         message = notmuch_messages_get (messages);\r
171  \r
172         if (output == OUTPUT_FILES) {\r
173 @@ -394,6 +422,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
174      const search_format_t *format = &format_text;\r
175      int i, ret;\r
176      output_t output = OUTPUT_SUMMARY;\r
177 +    int maxitems = -1; /* unlimited */\r
178 +    int first = 0;\r
179  \r
180      argc--; argv++; /* skip subcommand argument */\r
181  \r
182 @@ -412,6 +442,22 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
183                 fprintf (stderr, "Invalid value for --sort: %s\n", opt);\r
184                 return 1;\r
185             }\r
186 +       } else if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {\r
187 +           char *p;\r
188 +           opt = argv[i] + sizeof ("--first=") - 1;\r
189 +           first = strtol(opt, &p, 10);\r
190 +           if (*opt == '\0' || p == opt || *p != '\0') {\r
191 +               fprintf (stderr, "Invalid value for --first: %s\n", opt);\r
192 +               return 1;\r
193 +           }\r
194 +       } else if (STRNCMP_LITERAL (argv[i], "--maxitems=") == 0) {\r
195 +           char *p;\r
196 +           opt = argv[i] + sizeof ("--maxitems=") - 1;\r
197 +           maxitems = strtoul(opt, &p, 10);\r
198 +           if (*opt == '\0' || p == opt || *p != '\0') {\r
199 +               fprintf (stderr, "Invalid value for --maxitems: %s\n", opt);\r
200 +               return 1;\r
201 +           }\r
202         } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
203             opt = argv[i] + sizeof ("--format=") - 1;\r
204             if (strcmp (opt, "text") == 0) {\r
205 @@ -478,11 +524,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
206      default:\r
207      case OUTPUT_SUMMARY:\r
208      case OUTPUT_THREADS:\r
209 -       ret = do_search_threads (format, query, sort, output);\r
210 +       ret = do_search_threads (format, query, sort, output, first, maxitems);\r
211         break;\r
212      case OUTPUT_MESSAGES:\r
213      case OUTPUT_FILES:\r
214 -       ret = do_search_messages (format, query, output);\r
215 +       ret = do_search_messages (format, query, output, first, maxitems);\r
216         break;\r
217      case OUTPUT_TAGS:\r
218         ret = do_search_tags (notmuch, format, query);\r
219 -- \r
220 1.7.5.4\r
221 \r