[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / d8 / cf3f7b4320fdf0aab2a36e1d6f9bcd5254d313
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 090D7431FD0\r
6         for <notmuch@notmuchmail.org>; Sat, 14 Apr 2012 05:15:46 -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 agiprwdvByI6 for <notmuch@notmuchmail.org>;\r
17         Sat, 14 Apr 2012 05:15:43 -0700 (PDT)\r
18 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
19         [209.85.215.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 A481D431FAF\r
22         for <notmuch@notmuchmail.org>; Sat, 14 Apr 2012 05:15:41 -0700 (PDT)\r
23 Received: by lahc1 with SMTP id c1so3043779lah.26\r
24         for <notmuch@notmuchmail.org>; Sat, 14 Apr 2012 05:15:40 -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:x-gm-message-state;\r
29         bh=xzBJ3u3Hut25+Jh3QsGfiqLOJrn/ACcxy3Y1cvJo4hc=;\r
30         b=ULLhSmVZUmdMKKu68kSyJIGCB5HHUSIXCsiTKEm4uZeLp9NJx+ZTY/F9SPlwmk+Fga\r
31         ghP33I42a1LchMqY55FBJg4ZS34Lq/Y/4Ri+ptr7nmw00+AzBfwKl3v1arADfkOJA229\r
32         zHo+heqPZmwD3OqxN7hBXFJ1g3Lqiy2wUCaVLLxUF8LLM8a0tTUzvFFY2QjV/xPk6By1\r
33         hRlkghjAoxtkd5DYEJMRY5r3/SzwasnWbKVZNlmM8oqaD1ft2YERgSEiEdb7aPwufcnW\r
34         4ppzBZl3uqbfoferVlCZzGhA9uZTNMS4kEfYHy4BG0DHfGIM2nSdHLH8h6uVUObAhjTU\r
35         kuuw==\r
36 Received: by 10.112.44.42 with SMTP id b10mr2322788lbm.31.1334405740093;\r
37         Sat, 14 Apr 2012 05:15:40 -0700 (PDT)\r
38 Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi.\r
39         [80.220.80.68])\r
40         by mx.google.com with ESMTPS id n6sm16004259lbn.11.2012.04.14.05.15.37\r
41         (version=SSLv3 cipher=OTHER); Sat, 14 Apr 2012 05:15:38 -0700 (PDT)\r
42 From: Jani Nikula <jani@nikula.org>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v2 1/6] hex-escape: (en|de)code strings to/from restricted\r
45         character set\r
46 Date: Sat, 14 Apr 2012 15:15:26 +0300\r
47 Message-Id:\r
48  <921e481740d8c546c5f40a4f455a9f245cae005f.1334404979.git.jani@nikula.org>\r
49 X-Mailer: git-send-email 1.7.5.4\r
50 In-Reply-To: <cover.1334404979.git.jani@nikula.org>\r
51 References: <cover.1334404979.git.jani@nikula.org>\r
52 In-Reply-To: <cover.1334404979.git.jani@nikula.org>\r
53 References: <cover.1334404979.git.jani@nikula.org>\r
54 X-Gm-Message-State:\r
55  ALoCoQkX02IEqzJVDbGnLG4oNiU/vFZAEep5L5sOWTfw2GyQGhQz49j+V4w6ANEICne+/ddJx/eV\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Sat, 14 Apr 2012 12:15:46 -0000\r
69 \r
70 From: David Bremner <bremner@debian.org>\r
71 \r
72 The character set is chosen to be suitable for pathnames, and the same\r
73 as that used by contrib/nmbug\r
74 \r
75 [With additions by Jani Nikula]\r
76 ---\r
77  util/Makefile.local |    2 +-\r
78  util/hex-escape.c   |  168 +++++++++++++++++++++++++++++++++++++++++++++++++++\r
79  util/hex-escape.h   |   41 ++++++++++++\r
80  3 files changed, 210 insertions(+), 1 deletions(-)\r
81  create mode 100644 util/hex-escape.c\r
82  create mode 100644 util/hex-escape.h\r
83 \r
84 diff --git a/util/Makefile.local b/util/Makefile.local\r
85 index c7cae61..3ca623e 100644\r
86 --- a/util/Makefile.local\r
87 +++ b/util/Makefile.local\r
88 @@ -3,7 +3,7 @@\r
89  dir := util\r
90  extra_cflags += -I$(srcdir)/$(dir)\r
91  \r
92 -libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c\r
93 +libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c\r
94  \r
95  libutil_modules := $(libutil_c_srcs:.c=.o)\r
96  \r
97 diff --git a/util/hex-escape.c b/util/hex-escape.c\r
98 new file mode 100644\r
99 index 0000000..d8905d0\r
100 --- /dev/null\r
101 +++ b/util/hex-escape.c\r
102 @@ -0,0 +1,168 @@\r
103 +/* hex-escape.c -  Manage encoding and decoding of byte strings into path names\r
104 + *\r
105 + * Copyright (c) 2011 David Bremner\r
106 + *\r
107 + * This program is free software: you can redistribute it and/or modify\r
108 + * it under the terms of the GNU General Public License as published by\r
109 + * the Free Software Foundation, either version 3 of the License, or\r
110 + * (at your option) any later version.\r
111 + *\r
112 + * This program is distributed in the hope that it will be useful,\r
113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
115 + * GNU General Public License for more details.\r
116 + *\r
117 + * You should have received a copy of the GNU General Public License\r
118 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
119 + *\r
120 + * Author: David Bremner <david@tethera.net>\r
121 + */\r
122 +\r
123 +#include <assert.h>\r
124 +#include <string.h>\r
125 +#include <talloc.h>\r
126 +#include <ctype.h>\r
127 +#include "error_util.h"\r
128 +#include "hex-escape.h"\r
129 +\r
130 +static const size_t default_buf_size = 1024;\r
131 +\r
132 +static const char *output_charset =\r
133 +    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-_@=.:,";\r
134 +\r
135 +static const char escape_char = '%';\r
136 +\r
137 +static int\r
138 +is_output (char c)\r
139 +{\r
140 +    return (strchr (output_charset, c) != NULL);\r
141 +}\r
142 +\r
143 +static int\r
144 +maybe_realloc (void *ctx, size_t needed, char **out, size_t *out_size)\r
145 +{\r
146 +    if (*out_size < needed) {\r
147 +\r
148 +       if (*out == NULL)\r
149 +           *out = talloc_size (ctx, needed);\r
150 +       else\r
151 +           *out = talloc_realloc (ctx, *out, char, needed);\r
152 +\r
153 +       if (*out == NULL)\r
154 +           return 0;\r
155 +\r
156 +       *out_size = needed;\r
157 +    }\r
158 +    return 1;\r
159 +}\r
160 +\r
161 +hex_status_t\r
162 +hex_encode (void *ctx, const char *in, char **out, size_t *out_size)\r
163 +{\r
164 +\r
165 +    const unsigned char *p;\r
166 +    char *q;\r
167 +\r
168 +    size_t escape_count = 0;\r
169 +    size_t len = 0;\r
170 +    size_t needed;\r
171 +\r
172 +    assert (ctx); assert (in); assert (out); assert (out_size);\r
173 +\r
174 +    for (p = (unsigned char *) in; *p; p++) {\r
175 +       escape_count += (!is_output (*p));\r
176 +       len++;\r
177 +    }\r
178 +\r
179 +    needed = len + escape_count * 2 + 1;\r
180 +\r
181 +    if (*out == NULL)\r
182 +       *out_size = 0;\r
183 +\r
184 +    if (!maybe_realloc (ctx, needed, out, out_size))\r
185 +       return HEX_OUT_OF_MEMORY;\r
186 +\r
187 +    q = *out;\r
188 +    p = (unsigned char *) in;\r
189 +\r
190 +    while (*p) {\r
191 +       if (is_output (*p)) {\r
192 +           *q++ = *p++;\r
193 +       } else {\r
194 +           sprintf (q, "%%%02x", *p++);\r
195 +           q += 3;\r
196 +       }\r
197 +    }\r
198 +\r
199 +    *q = '\0';\r
200 +    return HEX_SUCCESS;\r
201 +}\r
202 +\r
203 +/* Hex decode 'in' to 'out'.\r
204 + *\r
205 + * This must succeed for in == out to support hex_decode_inplace().\r
206 + */\r
207 +static hex_status_t\r
208 +hex_decode_internal (const char *in, unsigned char *out)\r
209 +{\r
210 +    char buf[3];\r
211 +\r
212 +    while (*in) {\r
213 +       if (*in == escape_char) {\r
214 +           char *endp;\r
215 +\r
216 +           /* This also handles unexpected end-of-string. */\r
217 +           if (!isxdigit ((unsigned char) in[1]) ||\r
218 +               !isxdigit ((unsigned char) in[2]))\r
219 +               return HEX_SYNTAX_ERROR;\r
220 +\r
221 +           buf[0] = in[1];\r
222 +           buf[1] = in[2];\r
223 +           buf[2] = '\0';\r
224 +\r
225 +           *out = strtoul (buf, &endp, 16);\r
226 +\r
227 +           if (endp != buf + 2)\r
228 +               return HEX_SYNTAX_ERROR;\r
229 +\r
230 +           in += 3;\r
231 +           out++;\r
232 +       } else {\r
233 +           *out++ = *in++;\r
234 +       }\r
235 +    }\r
236 +\r
237 +    *out = '\0';\r
238 +\r
239 +    return HEX_SUCCESS;\r
240 +}\r
241 +\r
242 +hex_status_t\r
243 +hex_decode_inplace (char *s)\r
244 +{\r
245 +    /* A decoded string is never longer than the encoded one, so it is\r
246 +     * safe to decode a string onto itself. */\r
247 +    return hex_decode_internal (s, (unsigned char *) s);\r
248 +}\r
249 +\r
250 +hex_status_t\r
251 +hex_decode (void *ctx, const char *in, char **out, size_t * out_size)\r
252 +{\r
253 +    const char *p;\r
254 +    size_t escape_count = 0;\r
255 +    size_t needed = 0;\r
256 +\r
257 +    assert (ctx); assert (in); assert (out); assert (out_size);\r
258 +\r
259 +    size_t len = strlen (in);\r
260 +\r
261 +    for (p = in; *p; p++)\r
262 +       escape_count += (*p == escape_char);\r
263 +\r
264 +    needed = len - escape_count * 2 + 1;\r
265 +\r
266 +    if (!maybe_realloc (ctx, needed, out, out_size))\r
267 +       return HEX_OUT_OF_MEMORY;\r
268 +\r
269 +    return hex_decode_internal (in, (unsigned char *) *out);\r
270 +}\r
271 diff --git a/util/hex-escape.h b/util/hex-escape.h\r
272 new file mode 100644\r
273 index 0000000..5182042\r
274 --- /dev/null\r
275 +++ b/util/hex-escape.h\r
276 @@ -0,0 +1,41 @@\r
277 +#ifndef _HEX_ESCAPE_H\r
278 +#define _HEX_ESCAPE_H\r
279 +\r
280 +typedef enum hex_status {\r
281 +    HEX_SUCCESS = 0,\r
282 +    HEX_SYNTAX_ERROR,\r
283 +    HEX_OUT_OF_MEMORY\r
284 +} hex_status_t;\r
285 +\r
286 +/*\r
287 + * The API for hex_encode() and hex_decode() is modelled on that for\r
288 + * getline.\r
289 + *\r
290 + * If 'out' points to a NULL pointer a char array of the appropriate\r
291 + * size is allocated using talloc, and out_size is updated.\r
292 + *\r
293 + * If 'out' points to a non-NULL pointer, it assumed to describe an\r
294 + * existing char array, with the size given in *out_size.  This array\r
295 + * may be resized by talloc_realloc if needed; in this case *out_size\r
296 + * will also be updated.\r
297 + *\r
298 + * Note that it is an error to pass a NULL pointer for any parameter\r
299 + * of these routines.\r
300 + */\r
301 +\r
302 +hex_status_t\r
303 +hex_encode (void *talloc_ctx, const char *in, char **out,\r
304 +            size_t *out_size);\r
305 +\r
306 +hex_status_t\r
307 +hex_decode (void *talloc_ctx, const char *in, char **out,\r
308 +            size_t *out_size);\r
309 +\r
310 +/*\r
311 + * Non-allocating hex decode to decode 's' in-place. The length of the\r
312 + * result is always equal to or shorter than the length of the\r
313 + * original.\r
314 + */\r
315 +hex_status_t\r
316 +hex_decode_inplace (char *s);\r
317 +#endif\r
318 -- \r
319 1.7.5.4\r
320 \r