1 Return-Path: <craven@gmx.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 6F71D42119C
\r
6 for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 01:13:42 -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 6rWCsySVhxs0 for <notmuch@notmuchmail.org>;
\r
17 Fri, 13 Jul 2012 01:13:38 -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 5182D431FAE
\r
20 for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 01:13:38 -0700 (PDT)
\r
21 Received: (qmail invoked by alias); 13 Jul 2012 08:13:37 -0000
\r
22 Received: from cm56-137-203.liwest.at (EHLO nexork.localdomain)
\r
23 [86.56.137.203] by mail.gmx.net (mp035) with SMTP; 13 Jul 2012 10:13:37 +0200
\r
24 X-Authenticated: #201305
\r
25 X-Provags-ID: V01U2FsdGVkX193oLhdBFl3aBKpTndLiBGE+TLr/5HmDGbu4KAsHe
\r
27 Received: by nexork.localdomain (Postfix, from userid 1000)
\r
28 id 9BC3D4527802; Fri, 13 Jul 2012 10:11:42 +0200 (CEST)
\r
29 From: Peter Feigl <craven@gmx.net>
\r
30 To: notmuch@notmuchmail.org
\r
31 Subject: [PATCH v5 1/3] Add support for structured output formatters.
\r
32 Date: Fri, 13 Jul 2012 10:11:35 +0200
\r
33 Message-Id: <1342167097-25012-2-git-send-email-craven@gmx.net>
\r
34 X-Mailer: git-send-email 1.7.11.1
\r
35 In-Reply-To: <1342167097-25012-1-git-send-email-craven@gmx.net>
\r
36 References: <20120710191331.GE7332@mit.edu>
\r
37 <1342167097-25012-1-git-send-email-craven@gmx.net>
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Fri, 13 Jul 2012 08:13:42 -0000
\r
53 From: <craven@gmx.net>
\r
55 This patch adds a new type sprinter_t, which is used for structured
\r
56 formatting, e.g. JSON or S-Expressions. The structure printer is the
\r
57 code from Austin Clements (id:87d34hsdx8.fsf@awakening.csail.mit.edu)
\r
58 with minor modifications.
\r
60 The structure printer contains the following function pointers:
\r
62 /* Start a new map/dictionary structure. This should be followed by
\r
63 * a sequence of alternating calls to map_key and one of the
\r
64 * value-printing functions until the map is ended by end.
\r
66 void (*begin_map)(struct sprinter *);
\r
68 /* Start a new list/array structure.
\r
70 void (*begin_list)(struct sprinter *);
\r
72 /* End the last opened list or map structure.
\r
74 void (*end)(struct sprinter *);
\r
76 /* Set the prefix of the next component. This is purely for
\r
77 * debugging purposes and for the unstructured text formatter.
\r
79 void (*set_prefix)(struct sprinter *, const char *);
\r
81 /* Print one string/integer/boolean/null element (possibly inside a
\r
82 * list or map, followed or preceded by separators).
\r
83 * For string, the char * must be UTF-8 encoded.
\r
85 void (*string)(struct sprinter *, const char *);
\r
86 void (*integer)(struct sprinter *, int);
\r
87 void (*boolean)(struct sprinter *, notmuch_bool_t);
\r
88 void (*null)(struct sprinter *);
\r
90 /* Print the key of a map's key/value pair. The char * must be UTF-8
\r
93 void (*map_key)(struct sprinter *, const char *);
\r
95 /* Insert a separator (usually extra whitespace) for improved
\r
96 * readability without affecting the abstract syntax of the
\r
97 * structure being printed.
\r
98 * For JSON, this could simply be a line break.
\r
100 void (*separator)(struct sprinter *);
\r
102 The printer can (and should) use internal state to insert delimiters and
\r
103 syntax at the correct places.
\r
107 format->begin_map(format);
\r
108 format->map_key(format, "foo");
\r
109 format->begin_list(format);
\r
110 format->integer(format, 1);
\r
111 format->integer(format, 2);
\r
112 format->integer(format, 3);
\r
113 format->end(format);
\r
114 format->map_key(format, "bar");
\r
115 format->begin_map(format);
\r
116 format->map_key(format, "baaz");
\r
117 format->string(format, "hello world");
\r
118 format->end(format);
\r
119 format->end(format);
\r
121 would output JSON as follows:
\r
123 {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}
\r
125 sprinter.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
126 1 file changed, 50 insertions(+)
\r
127 create mode 100644 sprinter.h
\r
129 diff --git a/sprinter.h b/sprinter.h
\r
130 new file mode 100644
\r
131 index 0000000..c9cd6a6
\r
135 +#ifndef NOTMUCH_SPRINTER_H
\r
136 +#define NOTMUCH_SPRINTER_H
\r
138 +/* Necessary for notmuch_bool_t */
\r
139 +#include "notmuch-client.h"
\r
141 +/* Structure printer interface */
\r
142 +typedef struct sprinter {
\r
143 + /* Start a new map/dictionary structure. This should be followed by
\r
144 + * a sequence of alternating calls to map_key and one of the
\r
145 + * value-printing functions until the map is ended by end.
\r
147 + void (*begin_map)(struct sprinter *);
\r
149 + /* Start a new list/array structure.
\r
151 + void (*begin_list)(struct sprinter *);
\r
153 + /* End the last opened list or map structure.
\r
155 + void (*end)(struct sprinter *);
\r
157 + /* Set the prefix of the next component. This is purely for
\r
158 + * debugging purposes and for the unstructured text formatter.
\r
160 + void (*set_prefix)(struct sprinter *, const char *);
\r
162 + /* Print one string/integer/boolean/null element (possibly inside a
\r
163 + * list or map, followed or preceded by separators).
\r
164 + * For string, the char * must be UTF-8 encoded.
\r
166 + void (*string)(struct sprinter *, const char *);
\r
167 + void (*integer)(struct sprinter *, int);
\r
168 + void (*boolean)(struct sprinter *, notmuch_bool_t);
\r
169 + void (*null)(struct sprinter *);
\r
171 + /* Print the key of a map's key/value pair. The char * must be UTF-8
\r
174 + void (*map_key)(struct sprinter *, const char *);
\r
176 + /* Insert a separator (usually extra whitespace) for improved
\r
177 + * readability without affecting the abstract syntax of the
\r
178 + * structure being printed.
\r
179 + * For JSON, this could simply be a line break.
\r
181 + void (*separator)(struct sprinter *);
\r
184 +#endif // NOTMUCH_SPRINTER_H
\r