[PATCH 2/3] man: partial conversion to pod.
[notmuch-archives.git] / 1a / 92f279e0a07445e6dd5ffc47ebfbba0cb2629e
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 B0B7D431FC4\r
6         for <notmuch@notmuchmail.org>; Wed, 12 Sep 2012 14:27:52 -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 DLk4SSzXCWvf for <notmuch@notmuchmail.org>;\r
17         Wed, 12 Sep 2012 14:27:50 -0700 (PDT)\r
18 Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
19         [209.85.217.181]) (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 94C22431FBF\r
22         for <notmuch@notmuchmail.org>; Wed, 12 Sep 2012 14:27:43 -0700 (PDT)\r
23 Received: by mail-lb0-f181.google.com with SMTP id gk1so1587473lbb.26\r
24         for <notmuch@notmuchmail.org>; Wed, 12 Sep 2012 14:27:43 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
28         :in-reply-to:references:mime-version:content-type\r
29         :content-transfer-encoding:x-gm-message-state;\r
30         bh=LYU0qbNmIrV2qbjDj72xbhvjtMSldh8P1re9D4XWQrc=;\r
31         b=nEnRHuf38ltBl4fcyahUgVAC44LkcJtv1FRfvtUZ4ptCmTBWdgCSekWFCKye65h8XT\r
32         y1gWoZDYUUpWJij3RLh0JCi8kPurc6ifH9H59sPWXTfw7iRYMe/XVJP49VdGfXgffdaw\r
33         FbDkVe8Nnl8LDZZCESUMCHW6k7N5+rP6o6aAJca4WC+dTZjdi+ZGtsn+4vM8dRYvBE4j\r
34         oZgBeV23CE1ykLzzQC5iLlt35VqNR6OPi4Ofk5nT0hMMLPWL0zBeLuKMuNpnT+siPVcF\r
35         PL5+l9QMaO4f39653cGvkYQwcXQ/igol2yZRYroyo39M8eUOa01MTfJ5q+ALUBHUCkf0\r
36         N5SA==\r
37 Received: by 10.112.83.129 with SMTP id q1mr131010lby.89.1347485263162;\r
38         Wed, 12 Sep 2012 14:27:43 -0700 (PDT)\r
39 Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
40         [80.223.81.27])\r
41         by mx.google.com with ESMTPS id y4sm5532727lbg.5.2012.09.12.14.27.40\r
42         (version=SSLv3 cipher=OTHER); Wed, 12 Sep 2012 14:27:42 -0700 (PDT)\r
43 From: Jani Nikula <jani@nikula.org>\r
44 To: notmuch@notmuchmail.org,\r
45         David Bremner <david@tethera.net>\r
46 Subject:\r
47  [PATCH v3 3/9] test: add new test tool parse-time for date/time parser\r
48 Date: Thu, 13 Sep 2012 00:27:20 +0300\r
49 Message-Id:\r
50  <a5998ce294d32f66f4ce9572d50710d117f6bd8b.1347484177.git.jani@nikula.org>\r
51 X-Mailer: git-send-email 1.7.9.5\r
52 In-Reply-To: <cover.1347484177.git.jani@nikula.org>\r
53 References: <cover.1347484177.git.jani@nikula.org>\r
54 In-Reply-To: <cover.1347484177.git.jani@nikula.org>\r
55 References: <cover.1347484177.git.jani@nikula.org>\r
56 MIME-Version: 1.0\r
57 Content-Type: text/plain; charset=UTF-8\r
58 Content-Transfer-Encoding: 8bit\r
59 X-Gm-Message-State:\r
60  ALoCoQkb2UJWgQw2f4wWzZspsdG+IfjuxG0qUuILiwInLtjgL/Mvm7b7gfL51ogaPwrUu6wQmVtD\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Wed, 12 Sep 2012 21:27:53 -0000\r
74 \r
75 Add a smoke testing tool to support testing the date/time parser\r
76 module directly and independent of the rest of notmuch.\r
77 ---\r
78  test/Makefile.local |    7 ++-\r
79  test/basic          |    2 +-\r
80  test/parse-time.c   |  145 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
81  3 files changed, 152 insertions(+), 2 deletions(-)\r
82  create mode 100644 test/parse-time.c\r
83 \r
84 diff --git a/test/Makefile.local b/test/Makefile.local\r
85 index 45df4c7..9ae130a 100644\r
86 --- a/test/Makefile.local\r
87 +++ b/test/Makefile.local\r
88 @@ -19,9 +19,13 @@ $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
89  $(dir)/symbol-test: $(dir)/symbol-test.o\r
90         $(call quiet,CXX) $^ -o $@ -Llib -lnotmuch $(XAPIAN_LDFLAGS)\r
91  \r
92 +$(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o\r
93 +       $(call quiet,CC) $^ -o $@\r
94 +\r
95  .PHONY: test check\r
96  \r
97 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test\r
98 +test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \\r
99 +       $(dir)/parse-time\r
100  \r
101  test:  all test-binaries\r
102         @${dir}/notmuch-test $(OPTIONS)\r
103 @@ -32,4 +36,5 @@ SRCS := $(SRCS) $(smtp_dummy_srcs)\r
104  CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
105          $(dir)/symbol-test $(dir)/symbol-test.o \\r
106          $(dir)/arg-test $(dir)/arg-test.o \\r
107 +        $(dir)/parse-time $(dir)/parse-time.o \\r
108          $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
109 diff --git a/test/basic b/test/basic\r
110 index 3b635c8..c47197c 100755\r
111 --- a/test/basic\r
112 +++ b/test/basic\r
113 @@ -54,7 +54,7 @@ test_begin_subtest 'Ensure that all available tests will be run by notmuch-test'\r
114  eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/notmuch-test)\r
115  tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
116  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111 | \\r
117 -    sed -r -e "s,.*/,," -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test)$/d" | \\r
118 +    sed -r -e "s,.*/,," -e "/^(aggregate-results.sh|notmuch-test|smtp-dummy|test-verbose|symbol-test|arg-test|parse-time)$/d" | \\r
119      sort)\r
120  test_expect_equal "$tests_in_suite" "$available"\r
121  \r
122 diff --git a/test/parse-time.c b/test/parse-time.c\r
123 new file mode 100644\r
124 index 0000000..b4de76b\r
125 --- /dev/null\r
126 +++ b/test/parse-time.c\r
127 @@ -0,0 +1,145 @@\r
128 +/*\r
129 + * parse time string - user friendly date and time parser\r
130 + * Copyright © 2012 Jani Nikula\r
131 + *\r
132 + * This program is free software: you can redistribute it and/or modify\r
133 + * it under the terms of the GNU General Public License as published by\r
134 + * the Free Software Foundation, either version 2 of the License, or\r
135 + * (at your option) any later version.\r
136 + *\r
137 + * This program is distributed in the hope that it will be useful,\r
138 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
139 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
140 + * GNU General Public License for more details.\r
141 + *\r
142 + * You should have received a copy of the GNU General Public License\r
143 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
144 + *\r
145 + * Author: Jani Nikula <jani@nikula.org>\r
146 + */\r
147 +\r
148 +#include <getopt.h>\r
149 +#include <stdio.h>\r
150 +#include <stdlib.h>\r
151 +#include <string.h>\r
152 +\r
153 +#include "parse-time-string.h"\r
154 +\r
155 +/*\r
156 + * concat argv[start]...argv[end - 1], separating them by a single\r
157 + * space, to a malloced string\r
158 + */\r
159 +static char *\r
160 +concat_args (int start, int end, char *argv[])\r
161 +{\r
162 +    int i;\r
163 +    size_t len = 1;\r
164 +    char *p;\r
165 +\r
166 +    for (i = start; i < end; i++)\r
167 +       len += strlen (argv[i]) + 1;\r
168 +\r
169 +    p = malloc (len);\r
170 +    if (!p)\r
171 +       return NULL;\r
172 +\r
173 +    *p = 0;\r
174 +\r
175 +    for (i = start; i < end; i++) {\r
176 +       if (i != start)\r
177 +           strcat (p, " ");\r
178 +       strcat (p, argv[i]);\r
179 +    }\r
180 +\r
181 +    return p;\r
182 +}\r
183 +\r
184 +#define DEFAULT_FORMAT "%a %b %d %T %z %Y"\r
185 +\r
186 +static void\r
187 +usage (const char *name)\r
188 +{\r
189 +    printf ("Usage: %s [options ...] <date/time>\n\n", name);\r
190 +    printf (\r
191 +       "Parse <date/time> and display it in given format.\n\n"\r
192 +       "  -f, --format=FMT output format, FMT according to strftime(3)\n"\r
193 +       "                   (default: \"%s\")\n"\r
194 +       "  -n, --now=N      use N seconds since epoch as now (default: now)\n"\r
195 +       "  -u, --up         round result up (default: no rounding)\n"\r
196 +       "  -d, --down       round result down (default: no rounding)\n"\r
197 +       "  -h, --help       print this help\n",\r
198 +       DEFAULT_FORMAT);\r
199 +}\r
200 +\r
201 +int\r
202 +main (int argc, char *argv[])\r
203 +{\r
204 +    int r;\r
205 +    struct tm tm;\r
206 +    time_t result;\r
207 +    time_t now;\r
208 +    time_t *nowp = NULL;\r
209 +    char *argstr;\r
210 +    int round = PARSE_TIME_NO_ROUND;\r
211 +    char buf[1024];\r
212 +    const char *format = DEFAULT_FORMAT;\r
213 +    struct option options[] = {\r
214 +       { "help",       no_argument,            NULL,   'h' },\r
215 +       { "up",         no_argument,            NULL,   'u' },\r
216 +       { "down",       no_argument,            NULL,   'd' },\r
217 +       { "format",     required_argument,      NULL,   'f' },\r
218 +       { "now",        required_argument,      NULL,   'n' },\r
219 +       { NULL, 0, NULL, 0 },\r
220 +    };\r
221 +\r
222 +    for (;;) {\r
223 +       int c;\r
224 +\r
225 +       c = getopt_long (argc, argv, "hudf:n:", options, NULL);\r
226 +       if (c == -1)\r
227 +           break;\r
228 +\r
229 +       switch (c) {\r
230 +       case 'f':\r
231 +           /* output format */\r
232 +           format = optarg;\r
233 +           break;\r
234 +       case 'u':\r
235 +           round = PARSE_TIME_ROUND_UP;\r
236 +           break;\r
237 +       case 'd':\r
238 +           round = PARSE_TIME_ROUND_DOWN;\r
239 +           break;\r
240 +       case 'n':\r
241 +           /* specify now in seconds since epoch */\r
242 +           now = (time_t) strtol (optarg, NULL, 10);\r
243 +           if (now >= (time_t) 0)\r
244 +               nowp = &now;\r
245 +           break;\r
246 +       case 'h':\r
247 +       case '?':\r
248 +       default:\r
249 +           usage (argv[0]);\r
250 +           return 1;\r
251 +       }\r
252 +    }\r
253 +\r
254 +    argstr = concat_args (optind, argc, argv);\r
255 +    if (!argstr)\r
256 +       return 1;\r
257 +\r
258 +    r = parse_time_string (argstr, &result, nowp, round);\r
259 +\r
260 +    free (argstr);\r
261 +\r
262 +    if (r)\r
263 +       return 1;\r
264 +\r
265 +    if (!localtime_r (&result, &tm))\r
266 +       return 1;\r
267 +\r
268 +    strftime (buf, sizeof (buf), format, &tm);\r
269 +    printf ("%s\n", buf);\r
270 +\r
271 +    return 0;\r
272 +}\r
273 -- \r
274 1.7.9.5\r
275 \r