[PATCH WIP v2 0/5] emacs: show: redesign unread/read logic
[notmuch-archives.git] / c1 / 86c56157ee572d5dd32cee81ae5156fd5ee2bf
1 Return-Path: <bremner@tethera.net>\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 9176E431FBF\r
6         for <notmuch@notmuchmail.org>; Sun,  2 Dec 2012 05:34:04 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 0rXGhEqA8F58 for <notmuch@notmuchmail.org>;\r
16         Sun,  2 Dec 2012 05:34:00 -0800 (PST)\r
17 Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238])\r
18         (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 9E35E431FCB\r
21         for <notmuch@notmuchmail.org>; Sun,  2 Dec 2012 05:33:50 -0800 (PST)\r
22 Received: from fctnnbsc30w-142167090129.dhcp-dynamic.fibreop.nb.bellaliant.net\r
23         ([142.167.90.129] helo=zancas.localnet)\r
24         by tesseract.cs.unb.ca with esmtpsa\r
25         (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72)\r
26         (envelope-from <bremner@tethera.net>)\r
27         id 1Tf9g0-0005w1-GM; Sun, 02 Dec 2012 09:33:50 -0400\r
28 Received: from bremner by zancas.localnet with local (Exim 4.80)\r
29         (envelope-from <bremner@tethera.net>)\r
30         id 1Tf9fv-0001rO-0v; Sun, 02 Dec 2012 09:33:39 -0400\r
31 From: david@tethera.net\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [patch v3 2/6] test/hex-xcode: new test binary\r
34 Date: Sun,  2 Dec 2012 09:33:20 -0400\r
35 Message-Id: <1354455204-6908-3-git-send-email-david@tethera.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1354455204-6908-1-git-send-email-david@tethera.net>\r
38 References: <1354455204-6908-1-git-send-email-david@tethera.net>\r
39 X-Spam_bar: -\r
40 Cc: David Bremner <bremner@debian.org>\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sun, 02 Dec 2012 13:34:05 -0000\r
54 \r
55 From: David Bremner <bremner@debian.org>\r
56 \r
57 This program is used both as a test-bed/unit-tester for\r
58 ../util/hex-escape.c, and also as a utility in future tests of dump\r
59 and restore.\r
60 ---\r
61  test/.gitignore     |    1 +\r
62  test/Makefile.local |   13 +++++-\r
63  test/basic          |    1 +\r
64  test/hex-xcode.c    |  109 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
65  4 files changed, 122 insertions(+), 2 deletions(-)\r
66  create mode 100644 test/hex-xcode.c\r
67 \r
68 diff --git a/test/.gitignore b/test/.gitignore\r
69 index e63c689..be7ab5e 100644\r
70 --- a/test/.gitignore\r
71 +++ b/test/.gitignore\r
72 @@ -3,4 +3,5 @@ corpus.mail\r
73  smtp-dummy\r
74  symbol-test\r
75  arg-test\r
76 +hex-xcode\r
77  tmp.*\r
78 diff --git a/test/Makefile.local b/test/Makefile.local\r
79 index 9ae130a..8da4c56 100644\r
80 --- a/test/Makefile.local\r
81 +++ b/test/Makefile.local\r
82 @@ -13,6 +13,9 @@ smtp_dummy_modules = $(smtp_dummy_srcs:.c=.o)\r
83  $(dir)/arg-test: $(dir)/arg-test.o command-line-arguments.o util/libutil.a\r
84         $(call quiet,CC) -I. $^ -o $@\r
85  \r
86 +$(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a\r
87 +       $(call quiet,CC) -I. $^ -o $@ -ltalloc\r
88 +\r
89  $(dir)/smtp-dummy: $(smtp_dummy_modules)\r
90         $(call quiet,CC) $^ -o $@\r
91  \r
92 @@ -24,8 +27,13 @@ $(dir)/parse-time: $(dir)/parse-time.o parse-time-string/parse-time-string.o\r
93  \r
94  .PHONY: test check\r
95  \r
96 -test-binaries: $(dir)/arg-test $(dir)/smtp-dummy $(dir)/symbol-test \\r
97 -       $(dir)/parse-time\r
98 +TEST_BINARIES=$(dir)/arg-test \\r
99 +             $(dir)/hex-xcode \\r
100 +             $(dir)/parse-time \\r
101 +             $(dir)/smtp-dummy \\r
102 +             $(dir)/symbol-test\r
103 +\r
104 +test-binaries: $(TEST_BINARIES)\r
105  \r
106  test:  all test-binaries\r
107         @${dir}/notmuch-test $(OPTIONS)\r
108 @@ -36,5 +44,6 @@ SRCS := $(SRCS) $(smtp_dummy_srcs)\r
109  CLEAN := $(CLEAN) $(dir)/smtp-dummy $(dir)/smtp-dummy.o \\r
110          $(dir)/symbol-test $(dir)/symbol-test.o \\r
111          $(dir)/arg-test $(dir)/arg-test.o \\r
112 +        $(dir)/hex-xcode $(dir)/hex-xcode.o \\r
113          $(dir)/parse-time $(dir)/parse-time.o \\r
114          $(dir)/corpus.mail $(dir)/test-results $(dir)/tmp.*\r
115 diff --git a/test/basic b/test/basic\r
116 index b7feb07..c448ef8 100755\r
117 --- a/test/basic\r
118 +++ b/test/basic\r
119 @@ -56,6 +56,7 @@ tests_in_suite=$(for i in $TESTS; do echo $i; done | sort)\r
120  available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm +111  \\r
121      ! -name aggregate-results.sh       \\r
122      ! -name arg-test                   \\r
123 +    ! -name hex-xcode                  \\r
124      ! -name notmuch-test               \\r
125      ! -name parse-time                 \\r
126      ! -name smtp-dummy                 \\r
127 diff --git a/test/hex-xcode.c b/test/hex-xcode.c\r
128 new file mode 100644\r
129 index 0000000..65d4956\r
130 --- /dev/null\r
131 +++ b/test/hex-xcode.c\r
132 @@ -0,0 +1,109 @@\r
133 +/* No, nothing to to with IDE from Apple Inc.\r
134 + * testbed for ../util/hex-escape.c.\r
135 + *\r
136 + * usage:\r
137 + * hex-xcode [--direction=(encode|decode)] [--omit-newline] < file\r
138 + * hex-xcode [--direction=(encode|decode)] [--omit-newline] [--in-place] arg1 arg2 arg3 ...\r
139 + *\r
140 + */\r
141 +\r
142 +#include "notmuch-client.h"\r
143 +#include "hex-escape.h"\r
144 +#include <assert.h>\r
145 +\r
146 +enum direction {\r
147 +    ENCODE,\r
148 +    DECODE\r
149 +};\r
150 +\r
151 +static int inplace = FALSE;\r
152 +\r
153 +static int\r
154 +xcode (void *ctx, enum direction dir, char *in, char **buf_p, size_t *size_p)\r
155 +{\r
156 +    hex_status_t status;\r
157 +\r
158 +    if (dir == ENCODE)\r
159 +       status = hex_encode (ctx, in, buf_p, size_p);\r
160 +    else\r
161 +       if (inplace) {\r
162 +           status = hex_decode_inplace (in);\r
163 +           *buf_p = in;\r
164 +           *size_p = strlen(in);\r
165 +       } else {\r
166 +           status = hex_decode (ctx, in, buf_p, size_p);\r
167 +       }\r
168 +\r
169 +    if (status == HEX_SUCCESS)\r
170 +       fputs (*buf_p, stdout);\r
171 +\r
172 +    return status;\r
173 +}\r
174 +\r
175 +int\r
176 +main (int argc, char **argv)\r
177 +{\r
178 +\r
179 +    enum direction dir = DECODE;\r
180 +    int omit_newline = FALSE;\r
181 +\r
182 +    notmuch_opt_desc_t options[] = {\r
183 +       { NOTMUCH_OPT_KEYWORD, &dir, "direction", 'd',\r
184 +         (notmuch_keyword_t []){ { "encode", ENCODE },\r
185 +                                 { "decode", DECODE },\r
186 +                                 { 0, 0 } } },\r
187 +       { NOTMUCH_OPT_BOOLEAN, &omit_newline, "omit-newline", 'n', 0 },\r
188 +       { NOTMUCH_OPT_BOOLEAN, &inplace, "in-place", 'i', 0 },\r
189 +       { 0, 0, 0, 0, 0 }\r
190 +    };\r
191 +\r
192 +    int opt_index = parse_arguments (argc, argv, options, 1);\r
193 +\r
194 +    if (opt_index < 0)\r
195 +       exit (1);\r
196 +\r
197 +    void *ctx = talloc_new (NULL);\r
198 +\r
199 +    char *line = NULL;\r
200 +    size_t line_size;\r
201 +    ssize_t line_len;\r
202 +\r
203 +    char *buffer = NULL;\r
204 +    size_t buf_size = 0;\r
205 +\r
206 +    notmuch_bool_t read_stdin = TRUE;\r
207 +\r
208 +    for (; opt_index < argc; opt_index++) {\r
209 +\r
210 +       if (xcode (ctx, dir, argv[opt_index],\r
211 +                  &buffer, &buf_size) != HEX_SUCCESS)\r
212 +           return 1;\r
213 +\r
214 +       if (! omit_newline)\r
215 +           putchar ('\n');\r
216 +\r
217 +       read_stdin = FALSE;\r
218 +    }\r
219 +\r
220 +    if (! read_stdin)\r
221 +       return 0;\r
222 +\r
223 +    while ((line_len = getline (&line, &line_size, stdin)) != -1) {\r
224 +\r
225 +       chomp_newline (line);\r
226 +\r
227 +       if (xcode (ctx, dir, line, &buffer, &buf_size) != HEX_SUCCESS)\r
228 +           return 1;\r
229 +\r
230 +       if (! omit_newline)\r
231 +           putchar ('\n');\r
232 +\r
233 +    }\r
234 +\r
235 +    if (line)\r
236 +       free (line);\r
237 +\r
238 +    talloc_free (ctx);\r
239 +\r
240 +    return 0;\r
241 +}\r
242 -- \r
243 1.7.10.4\r
244 \r