1 Return-Path: <tomi.ollila@iki.fi>
\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 9FD68431FBC
\r
6 for <notmuch@notmuchmail.org>; Fri, 20 Jul 2012 02:08:59 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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 6OhAR-PXdlpA for <notmuch@notmuchmail.org>;
\r
16 Fri, 20 Jul 2012 02:08:58 -0700 (PDT)
\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 39A80431FAE
\r
19 for <notmuch@notmuchmail.org>; Fri, 20 Jul 2012 02:08:58 -0700 (PDT)
\r
20 Received: by guru.guru-group.fi (Postfix, from userid 501)
\r
21 id 96BF710014D; Fri, 20 Jul 2012 12:09:07 +0300 (EEST)
\r
22 From: Tomi Ollila <tomi.ollila@iki.fi>
\r
23 To: craven@gmx.net, notmuch@notmuchmail.org
\r
24 Subject: Re: [PATCH v7 1/3] Add support for structured output formatters.
\r
25 In-Reply-To: <1342766173-1344-2-git-send-email-craven@gmx.net>
\r
26 References: <20120718194819.GP31670@mit.edu>
\r
27 <1342766173-1344-1-git-send-email-craven@gmx.net>
\r
28 <1342766173-1344-2-git-send-email-craven@gmx.net>
\r
29 User-Agent: Notmuch/0.13.2+93~ge4fdd97 (http://notmuchmail.org) Emacs/23.1.1
\r
30 (x86_64-redhat-linux-gnu)
\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL
\r
32 $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F
\r
33 !)g;OY^,BjTbr)Np:%c_o'jj,Z
\r
34 Date: Fri, 20 Jul 2012 12:09:07 +0300
\r
35 Message-ID: <m2txx294uk.fsf@guru.guru-group.fi>
\r
37 Content-Type: text/plain; charset=us-ascii
\r
38 X-BeenThere: notmuch@notmuchmail.org
\r
39 X-Mailman-Version: 2.1.13
\r
41 List-Id: "Use and development of the notmuch mail system."
\r
42 <notmuch.notmuchmail.org>
\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
46 List-Post: <mailto:notmuch@notmuchmail.org>
\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
50 X-List-Received-Date: Fri, 20 Jul 2012 09:08:59 -0000
\r
52 On Fri, Jul 20 2012, craven@gmx.net wrote:
\r
54 > From: <craven@gmx.net>
\r
56 > This patch adds a new struct type sprinter_t, which is used for
\r
57 > structured formatting, e.g. JSON or S-Expressions. The structure printer
\r
58 > is heavily based on code from Austin Clements
\r
59 > (id:87d34hsdx8.fsf@awakening.csail.mit.edu).
\r
61 > It includes the following functions:
\r
63 > /* Start a new map/dictionary structure. This should be followed by
\r
64 > * a sequence of alternating calls to map_key and one of the
\r
65 > * value-printing functions until the map is ended by end.
\r
67 > void (*begin_map) (struct sprinter *);
\r
69 > /* Start a new list/array structure.
\r
71 > void (*begin_list) (struct sprinter *);
\r
73 > /* End the last opened list or map structure.
\r
75 > void (*end) (struct sprinter *);
\r
77 > /* Print one string/integer/boolean/null element (possibly inside a
\r
78 > * list or map, followed or preceded by separators).
\r
79 > * For string, the char * must be UTF-8 encoded.
\r
81 > void (*string) (struct sprinter *, const char *);
\r
82 > void (*integer) (struct sprinter *, int);
\r
83 > void (*boolean) (struct sprinter *, notmuch_bool_t);
\r
84 > void (*null) (struct sprinter *);
\r
86 > /* Print the key of a map's key/value pair. The char * must be UTF-8
\r
89 > void (*map_key) (struct sprinter *, const char *);
\r
91 > /* Insert a separator (usually extra whitespace) for improved
\r
92 > * readability without affecting the abstract syntax of the
\r
93 > * structure being printed.
\r
94 > * For JSON, this could simply be a line break.
\r
96 > void (*separator) (struct sprinter *);
\r
98 > /* Set the current string prefix. This only affects the text
\r
99 > * printer, which will print this string, followed by a colon,
\r
100 > * before any string. For other printers, this does nothing.
\r
102 > void (*set_prefix) (struct sprinter *, const char *);
\r
104 The above block duplicated below. Otherwise this LGTM.
\r
106 I presume the patch 3/3 emails
\r
108 id:"1342766173-1344-4-git-send-email-craven@gmx.net"
\r
109 id:"1342772624-23329-1-git-send-email-craven@gmx.net"
\r
111 have identical content ?
\r
113 > To support the plain text format properly, the following additional
\r
114 > function must also be implemented:
\r
116 > /* Set the current string prefix. This only affects the text
\r
117 > * printer, which will print this string, followed by a colon,
\r
118 > * before any string. For other printers, this does nothing.
\r
120 > void (*set_prefix) (struct sprinter *, const char *);
\r
122 > The structure also contains a flag that should be set to FALSE in all
\r
123 > custom printers and to TRUE in the plain text formatter.
\r
125 > /* True if this is the special-cased plain text printer.
\r
127 > notmuch_bool_t is_text_printer;
\r
129 > The printer can (and should) use internal state to insert delimiters
\r
130 > and syntax at the correct places.
\r
134 > format->begin_map(format);
\r
135 > format->map_key(format, "foo");
\r
136 > format->begin_list(format);
\r
137 > format->integer(format, 1);
\r
138 > format->integer(format, 2);
\r
139 > format->integer(format, 3);
\r
140 > format->end(format);
\r
141 > format->map_key(format, "bar");
\r
142 > format->begin_map(format);
\r
143 > format->map_key(format, "baaz");
\r
144 > format->string(format, "hello world");
\r
145 > format->end(format);
\r
146 > format->end(format);
\r
148 > would output JSON as follows:
\r
150 > {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}
\r
152 > sprinter.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
153 > 1 file changed, 58 insertions(+)
\r
154 > create mode 100644 sprinter.h
\r
156 > diff --git a/sprinter.h b/sprinter.h
\r
157 > new file mode 100644
\r
158 > index 0000000..77dc26f
\r
162 > +#ifndef NOTMUCH_SPRINTER_H
\r
163 > +#define NOTMUCH_SPRINTER_H
\r
165 > +/* Necessary for notmuch_bool_t */
\r
166 > +#include "notmuch-client.h"
\r
168 > +/* Structure printer interface. This is used to create output
\r
169 > + * structured as maps (with key/value pairs), lists and primitives
\r
170 > + * (strings, integers and booleans).
\r
172 > +typedef struct sprinter {
\r
173 > + /* Start a new map/dictionary structure. This should be followed by
\r
174 > + * a sequence of alternating calls to map_key and one of the
\r
175 > + * value-printing functions until the map is ended by end.
\r
177 > + void (*begin_map) (struct sprinter *);
\r
179 > + /* Start a new list/array structure.
\r
181 > + void (*begin_list) (struct sprinter *);
\r
183 > + /* End the last opened list or map structure.
\r
185 > + void (*end) (struct sprinter *);
\r
187 > + /* Print one string/integer/boolean/null element (possibly inside a
\r
188 > + * list or map, followed or preceded by separators).
\r
189 > + * For string, the char * must be UTF-8 encoded.
\r
191 > + void (*string) (struct sprinter *, const char *);
\r
192 > + void (*integer) (struct sprinter *, int);
\r
193 > + void (*boolean) (struct sprinter *, notmuch_bool_t);
\r
194 > + void (*null) (struct sprinter *);
\r
196 > + /* Print the key of a map's key/value pair. The char * must be UTF-8
\r
199 > + void (*map_key) (struct sprinter *, const char *);
\r
201 > + /* Insert a separator (usually extra whitespace) for improved
\r
202 > + * readability without affecting the abstract syntax of the
\r
203 > + * structure being printed.
\r
204 > + * For JSON, this could simply be a line break.
\r
206 > + void (*separator) (struct sprinter *);
\r
208 > + /* Set the current string prefix. This only affects the text
\r
209 > + * printer, which will print this string, followed by a colon,
\r
210 > + * before any string. For other printers, this does nothing.
\r
212 > + void (*set_prefix) (struct sprinter *, const char *);
\r
214 > + /* True if this is the special-cased plain text printer.
\r
216 > + notmuch_bool_t is_text_printer;
\r
219 > +#endif // NOTMUCH_SPRINTER_H
\r
223 > _______________________________________________
\r
224 > notmuch mailing list
\r
225 > notmuch@notmuchmail.org
\r
226 > http://notmuchmail.org/mailman/listinfo/notmuch
\r