1 Return-Path: <peter.feigl@gmx.at>
\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 8EC86431FC0
\r
6 for <notmuch@notmuchmail.org>; Tue, 10 Jul 2012 11:56:14 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5
\r
12 tests=[FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001]
\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 Rdh+vVmivbtq for <notmuch@notmuchmail.org>;
\r
17 Tue, 10 Jul 2012 11:56:13 -0700 (PDT)
\r
18 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23])
\r
19 by olra.theworths.org (Postfix) with SMTP id 4C6AA431FBF
\r
20 for <notmuch@notmuchmail.org>; Tue, 10 Jul 2012 11:56:13 -0700 (PDT)
\r
21 Received: (qmail invoked by alias); 10 Jul 2012 18:56:10 -0000
\r
22 Received: from www.nexoid.at (EHLO mail.nexoid.at) [178.79.130.240]
\r
23 by mail.gmx.net (mp031) with SMTP; 10 Jul 2012 20:56:10 +0200
\r
24 X-Authenticated: #4563876
\r
25 X-Provags-ID: V01U2FsdGVkX19Vb2BisVBVkwwxE2kmexZLYEysiJVDAUaGlOF67S
\r
27 Received: from nexoid (localhost [127.0.0.1])
\r
28 by mail.nexoid.at (Postfix) with ESMTP id 4C6AAE00C
\r
29 for <notmuch@notmuchmail.org>; Tue, 10 Jul 2012 20:56:09 +0200 (CEST)
\r
30 From: <craven@gmx.net>
\r
31 To: notmuch@notmuchmail.org
\r
32 Subject: [PATCH v3 1/3] Add support for structured output formatters.
\r
33 User-Agent: Notmuch/0.11+77~gad6d0d5 (http://notmuchmail.org) Emacs/24.1.50.2
\r
35 Date: Tue, 10 Jul 2012 20:56:09 +0200
\r
36 Message-ID: <87394zv41i.fsf@nexoid.at>
\r
38 Content-Type: text/plain; charset=utf-8
\r
39 Content-Transfer-Encoding: quoted-printable
\r
41 X-BeenThere: notmuch@notmuchmail.org
\r
42 X-Mailman-Version: 2.1.13
\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: Tue, 10 Jul 2012 18:56:14 -0000
\r
55 This patch adds a new type structure_printer, which is used for structured =
\r
56 formatting, e.g. JSON or S-Expressions.
\r
58 The structure contains the following function pointers:
\r
60 - initial_state: is called to create a state object, that is passed to all =
\r
61 invocations. This should be used to keep track of the output file and every=
\r
62 thing else necessary to correctly format output.
\r
63 - map: is called when a new map (associative array, dictionary) is started.=
\r
64 map_key and the primitives (string, number, bool) are used alternatingly t=
\r
65 o add key/value pairs. pop is used to close the map (see there). This funct=
\r
66 ion must return a nesting level identifier that can be used to close all ne=
\r
67 sted structures (maps and lists), backing out to the returned nesting level.
\r
68 - list: is called when a new list (array, vector) is started. the primitive=
\r
69 s (string, number, bool) are used consecutively to add values to the list. =
\r
70 pop is used to close the list. This function must return a nesting level id=
\r
71 entifier that can be used to close all nested structures (maps and lists), =
\r
72 backing out to the returned nesting level.
\r
73 - pop: is called to return to a given nesting level. All lists and maps wit=
\r
74 h a deeper nesting level must be closed.
\r
75 - number, string, bool: output one element of the specific type.
\r
77 All functions should use state to insert delimiters etc. automatically when=
\r
83 map_key(state, "foo");
\r
84 one =3D list(state);
\r
89 map_key(state, "bar");
\r
91 map_key(state, "baaz");
\r
92 string(state, "hello world");
\r
95 would output JSON as follows:
\r
97 {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}
\r
99 Makefile.local | 1 +
\r
100 structured-output.h | 64 +++++++++++++++++++++++++++++++++++++++++++++++=
\r
102 2 files changed, 65 insertions(+)
\r
103 create mode 100644 structured-output.h
\r
105 diff --git a/Makefile.local b/Makefile.local
\r
106 index a890df2..9b3db5e 100644
\r
107 --- a/Makefile.local
\r
108 +++ b/Makefile.local
\r
109 @@ -286,6 +286,7 @@ notmuch_client_srcs =3D \
\r
111 notmuch-restore.c \
\r
113 + structured-output.c \
\r
117 diff --git a/structured-output.h b/structured-output.h
\r
118 new file mode 100644
\r
119 index 0000000..b43afe0
\r
121 +++ b/structured-output.h
\r
123 +/* notmuch - Not much of an email program, (just index and search)
\r
125 + * Copyright =C2=A9 2009 Carl Worth
\r
127 + * This program is free software: you can redistribute it and/or modify
\r
128 + * it under the terms of the GNU General Public License as published by
\r
129 + * the Free Software Foundation, either version 3 of the License, or
\r
130 + * (at your option) any later version.
\r
132 + * This program is distributed in the hope that it will be useful,
\r
133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
135 + * GNU General Public License for more details.
\r
137 + * You should have received a copy of the GNU General Public License
\r
138 + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
140 + * Author: Carl Worth <cworth@cworth.org>
\r
143 +#include "notmuch-client.h"
\r
145 +/* structured formatting, useful for JSON, S-Expressions, ...
\r
147 +- initial_state: is called to create a state object, that is passed to all=
\r
148 invocations. This should be used to keep track of the output file and ever=
\r
149 ything else necessary to correctly format output.
\r
150 +- map: is called when a new map (associative array, dictionary) is started=
\r
151 . map_key and the primitives (string, number, bool) are used alternatingly =
\r
152 to add key/value pairs. pop is used to close the map (see there). This func=
\r
153 tion must return a nesting level identifier that can be used to close all n=
\r
154 ested structures (maps and lists), backing out to the returned nesting leve=
\r
156 +- list: is called when a new list (array, vector) is started. the primitiv=
\r
157 es (string, number, bool) are used consecutively to add values to the list.=
\r
158 pop is used to close the list. This function must return a nesting level i=
\r
159 dentifier that can be used to close all nested structures (maps and lists),=
\r
160 backing out to the returned nesting level.
\r
161 +- pop: is called to return to a given nesting level. All lists and maps wi=
\r
162 th a deeper nesting level must be closed.
\r
163 +- number, string, bool: output one element of the specific type.
\r
165 +All functions should use state to insert delimiters etc. automatically whe=
\r
170 +top =3D map(state);
\r
171 +map_key(state, "foo");
\r
172 +one =3D list(state);
\r
177 +map_key(state, "bar");
\r
179 +map_key(state, "baaz");
\r
180 +string(state, "hello world");
\r
183 +would output JSON as follows:
\r
185 +{"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}
\r
188 +typedef struct structure_printer {
\r
189 + int (*map)(void *state);
\r
190 + int (*list)(void *state);
\r
191 + void (*pop)(void *state, int level);
\r
192 + void (*map_key)(void *state, const char *key);
\r
193 + void (*number)(void *state, int val);
\r
194 + void (*string)(void *state, const char *val);
\r
195 + void (*bool)(void *state, notmuch_bool_t val);
\r
196 + void *(*initial_state)(const struct structure_printer *sp, FILE *outpu=
\r
198 +} structure_printer_t;
\r