1 Return-Path: <amdragon@mit.edu>
\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 CA81B431FC4
\r
6 for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 15:08:17 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 1UbJDQi0ahld for <notmuch@notmuchmail.org>;
\r
16 Thu, 12 Jul 2012 15:08:16 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 61701431FAE
\r
20 for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 15:08:16 -0700 (PDT)
\r
21 X-AuditID: 12074422-b7f1f6d00000090b-97-4fff4acfa785
\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])
\r
23 by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 3B.A7.02315.FCA4FFF4; Thu, 12 Jul 2012 18:08:15 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q6CM8FcE024815;
\r
27 Thu, 12 Jul 2012 18:08:15 -0400
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6CM8Ee2029131
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Thu, 12 Jul 2012 18:08:14 -0400 (EDT)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1SpRYU-0004sR-1R; Thu, 12 Jul 2012 18:08:14 -0400
\r
37 Date: Thu, 12 Jul 2012 18:08:14 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
40 Subject: Re: [PATCH v4 1/3] Add support for structured output formatters.
\r
41 Message-ID: <20120712220814.GJ7332@mit.edu>
\r
42 References: <87d34hsdx8.fsf@awakening.csail.mit.edu>
\r
43 <1342079004-5300-1-git-send-email-craven@gmx.net>
\r
44 <1342079004-5300-2-git-send-email-craven@gmx.net>
\r
46 Content-Type: text/plain; charset=us-ascii
\r
47 Content-Disposition: inline
\r
48 In-Reply-To: <1342079004-5300-2-git-send-email-craven@gmx.net>
\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
50 X-Brightmail-Tracker:
\r
51 H4sIAAAAAAAAA+NgFmplleLIzCtJLcpLzFFi42IRYrdT0T3v9d/fYPk6C4u9De2MFtdvzmR2
\r
52 YPJYvGk/m8ezVbeYA5iiuGxSUnMyy1KL9O0SuDIebrjLVHBXpqLpwRzWBsZtYl2MnBwSAiYS
\r
53 j491sEDYYhIX7q1n62Lk4hAS2McoceXcGlYIZwOjxLmvexghnJNMEk/bjzFDOEsYJZY3T2cE
\r
54 6WcRUJVY8X4DG4jNJqAhsW3/crC4iICQxKQvr8B2MAtIS3z73cwEYgsLeEqcOt0KFucV0JbY
\r
55 vXgJC8TQOYwSEzsfsUIkBCVOznwC1awlcePfS6BmDrBBy/9xgIQ5BewkTk3/D7ZLVEBFYsrJ
\r
56 bWwTGIVmIemehaR7FkL3AkbmVYyyKblVurmJmTnFqcm6xcmJeXmpRbqmermZJXqpKaWbGMGh
\r
57 7aK0g/HnQaVDjAIcjEo8vDvX/fUXYk0sK67MPcQoycGkJMpr7frfX4gvKT+lMiOxOCO+qDQn
\r
58 tfgQowQHs5II7zp7oBxvSmJlVWpRPkxKmoNFSZz3WspNfyGB9MSS1OzU1ILUIpisDAeHkgTv
\r
59 Fk+gRsGi1PTUirTMnBKENBMHJ8hwHqDhs0BqeIsLEnOLM9Mh8qcYFaXEeW+CJARAEhmleXC9
\r
60 sNTzilEc6BVh3jsgVTzAtAXX/QpoMBPI4J//QAaXJCKkpBoYUw7cWa4gn3aZI7Ex6syqaVsU
\r
61 php4lZYde5kuGenatdz0sYyQpVmQzqy22TM+ZbZFnjeI3r94Ddu9tef+f2C2n3Dr5+sf9RdN
\r
62 bxS969q5/9qOWp8oGy3pFUzlsR+/hJ+4wrcyp0TjzPZL/NMEP0ce3xt4UOH+I5fQloIy3tRJ
\r
63 1rZrGmfoudfVKLEUZyQaajEXFScCAItFvqMYAwAA
\r
64 Cc: notmuch@notmuchmail.org
\r
65 X-BeenThere: notmuch@notmuchmail.org
\r
66 X-Mailman-Version: 2.1.13
\r
68 List-Id: "Use and development of the notmuch mail system."
\r
69 <notmuch.notmuchmail.org>
\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
71 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
73 List-Post: <mailto:notmuch@notmuchmail.org>
\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
76 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
77 X-List-Received-Date: Thu, 12 Jul 2012 22:08:17 -0000
\r
79 Quoth craven@gmx.net on Jul 12 at 9:43 am:
\r
80 > This patch adds a new type sprinter_t, which is used for structured
\r
81 > formatting, e.g. JSON or S-Expressions. The structure printer is the
\r
82 > code from Austin Clements (id:87d34hsdx8.fsf@awakening.csail.mit.edu).
\r
84 > The structure printer contains the following function pointers:
\r
86 > /* start a new map/dictionary structure.
\r
88 > void (*begin_map) (struct sprinter *);
\r
90 > /* start a new list/array structure
\r
92 > void (*begin_list) (struct sprinter *);
\r
94 > /* end the last opened list or map structure
\r
96 > void (*end) (struct sprinter *);
\r
98 > /* print one string/integer/boolean/null element (possibly inside a
\r
101 > void (*string) (struct sprinter *, const char *);
\r
102 > void (*integer) (struct sprinter *, int);
\r
103 > void (*boolean) (struct sprinter *, notmuch_bool_t);
\r
104 > void (*null) (struct sprinter *);
\r
106 > /* print the key of a map's key/value pair.
\r
108 > void (*map_key) (struct sprinter *, const char *);
\r
110 > /* print a frame delimiter (such as a newline or extra whitespace)
\r
112 > void (*frame) (struct sprinter *);
\r
114 > The printer can (and should) use internal state to insert delimiters and
\r
115 > syntax at the correct places.
\r
119 > format->begin_map(format);
\r
120 > format->map_key(format, "foo");
\r
121 > format->begin_list(format);
\r
122 > format->integer(format, 1);
\r
123 > format->integer(format, 2);
\r
124 > format->integer(format, 3);
\r
125 > format->end(format);
\r
126 > format->map_key(format, "bar");
\r
127 > format->begin_map(format);
\r
128 > format->map_key(format, "baaz");
\r
129 > format->string(format, "hello world");
\r
130 > format->end(format);
\r
131 > format->end(format);
\r
133 > would output JSON as follows:
\r
135 > {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}
\r
137 > sprinter.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
138 > 1 file changed, 49 insertions(+)
\r
139 > create mode 100644 sprinter.h
\r
141 > diff --git a/sprinter.h b/sprinter.h
\r
142 > new file mode 100644
\r
143 > index 0000000..1dad9a0
\r
147 > +#ifndef NOTMUCH_SPRINTER_H
\r
148 > +#define NOTMUCH_SPRINTER_H
\r
150 > +/* for notmuch_bool_t */
\r
151 > +#include "notmuch-client.h"
\r
153 > +/* Structure printer interface */
\r
154 > +typedef struct sprinter
\r
156 > + /* start a new map/dictionary structure.
\r
158 > + void (*begin_map) (struct sprinter *);
\r
160 > + /* start a new list/array structure
\r
162 > + void (*begin_list) (struct sprinter *);
\r
164 > + /* end the last opened list or map structure
\r
166 > + void (*end) (struct sprinter *);
\r
168 > + /* print one string/integer/boolean/null element (possibly inside a
\r
171 > + void (*string) (struct sprinter *, const char *);
\r
173 Oh, also, the documentation for string should mention the string
\r
174 argument should be UTF-8 encoded.
\r
176 > + void (*integer) (struct sprinter *, int);
\r
177 > + void (*boolean) (struct sprinter *, notmuch_bool_t);
\r
178 > + void (*null) (struct sprinter *);
\r
180 > + /* print the key of a map's key/value pair.
\r
182 > + void (*map_key) (struct sprinter *, const char *);
\r
184 > + /* print a frame delimiter (such as a newline or extra whitespace)
\r
186 > + void (*frame) (struct sprinter *);
\r
189 > +/* Create a new structure printer that emits JSON */
\r
190 > +struct sprinter *
\r
191 > +sprinter_json_new(const void *ctx, FILE *stream);
\r
193 > +/* A dummy structure printer that signifies that standard text output is
\r
194 > + * to be used instead of any structured format.
\r
196 > +struct sprinter *
\r
199 > +#endif // NOTMUCH_SPRINTER_H
\r