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 29153431FC9
\r
6 for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 00:42:21 -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 kH1GQ0bvk8eU for <notmuch@notmuchmail.org>;
\r
17 Thu, 12 Jul 2012 00:42:19 -0700 (PDT)
\r
18 Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22])
\r
19 by olra.theworths.org (Postfix) with SMTP id E8F5B429E4B
\r
20 for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 00:42:15 -0700 (PDT)
\r
21 Received: (qmail invoked by alias); 12 Jul 2012 07:42:03 -0000
\r
22 Received: from gw.arelion.cust.net.lagis.at (EHLO dodekanex.arelion.at)
\r
24 by mail.gmx.net (mp030) with SMTP; 12 Jul 2012 09:42:03 +0200
\r
25 X-Authenticated: #201305
\r
26 X-Provags-ID: V01U2FsdGVkX1/sUeJEZpbsAZ2RhLXfCrmVKmhokI92GbzUxdJC3b
\r
28 Received: by dodekanex.arelion.at (Postfix, from userid 1000)
\r
29 id 1F6593011A8; Thu, 12 Jul 2012 09:43:30 +0200 (CEST)
\r
30 From: <craven@gmx.net>
\r
31 To: notmuch@notmuchmail.org
\r
32 Subject: [PATCH v4 1/3] Add support for structured output formatters.
\r
33 Date: Thu, 12 Jul 2012 09:43:22 +0200
\r
34 Message-Id: <1342079004-5300-2-git-send-email-craven@gmx.net>
\r
35 X-Mailer: git-send-email 1.7.11.1
\r
36 In-Reply-To: <1342079004-5300-1-git-send-email-craven@gmx.net>
\r
37 References: <87d34hsdx8.fsf@awakening.csail.mit.edu>
\r
38 <1342079004-5300-1-git-send-email-craven@gmx.net>
\r
40 X-BeenThere: notmuch@notmuchmail.org
\r
41 X-Mailman-Version: 2.1.13
\r
43 List-Id: "Use and development of the notmuch mail system."
\r
44 <notmuch.notmuchmail.org>
\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
48 List-Post: <mailto:notmuch@notmuchmail.org>
\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
51 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
52 X-List-Received-Date: Thu, 12 Jul 2012 07:42:21 -0000
\r
54 This patch adds a new type sprinter_t, which is used for structured
\r
55 formatting, e.g. JSON or S-Expressions. The structure printer is the
\r
56 code from Austin Clements (id:87d34hsdx8.fsf@awakening.csail.mit.edu).
\r
58 The structure printer contains the following function pointers:
\r
60 /* start a new map/dictionary structure.
\r
62 void (*begin_map) (struct sprinter *);
\r
64 /* start a new list/array structure
\r
66 void (*begin_list) (struct sprinter *);
\r
68 /* end the last opened list or map structure
\r
70 void (*end) (struct sprinter *);
\r
72 /* print one string/integer/boolean/null element (possibly inside a
\r
75 void (*string) (struct sprinter *, const char *);
\r
76 void (*integer) (struct sprinter *, int);
\r
77 void (*boolean) (struct sprinter *, notmuch_bool_t);
\r
78 void (*null) (struct sprinter *);
\r
80 /* print the key of a map's key/value pair.
\r
82 void (*map_key) (struct sprinter *, const char *);
\r
84 /* print a frame delimiter (such as a newline or extra whitespace)
\r
86 void (*frame) (struct sprinter *);
\r
88 The printer can (and should) use internal state to insert delimiters and
\r
89 syntax at the correct places.
\r
93 format->begin_map(format);
\r
94 format->map_key(format, "foo");
\r
95 format->begin_list(format);
\r
96 format->integer(format, 1);
\r
97 format->integer(format, 2);
\r
98 format->integer(format, 3);
\r
99 format->end(format);
\r
100 format->map_key(format, "bar");
\r
101 format->begin_map(format);
\r
102 format->map_key(format, "baaz");
\r
103 format->string(format, "hello world");
\r
104 format->end(format);
\r
105 format->end(format);
\r
107 would output JSON as follows:
\r
109 {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}
\r
111 sprinter.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
112 1 file changed, 49 insertions(+)
\r
113 create mode 100644 sprinter.h
\r
115 diff --git a/sprinter.h b/sprinter.h
\r
116 new file mode 100644
\r
117 index 0000000..1dad9a0
\r
121 +#ifndef NOTMUCH_SPRINTER_H
\r
122 +#define NOTMUCH_SPRINTER_H
\r
124 +/* for notmuch_bool_t */
\r
125 +#include "notmuch-client.h"
\r
127 +/* Structure printer interface */
\r
128 +typedef struct sprinter
\r
130 + /* start a new map/dictionary structure.
\r
132 + void (*begin_map) (struct sprinter *);
\r
134 + /* start a new list/array structure
\r
136 + void (*begin_list) (struct sprinter *);
\r
138 + /* end the last opened list or map structure
\r
140 + void (*end) (struct sprinter *);
\r
142 + /* print one string/integer/boolean/null element (possibly inside a
\r
145 + void (*string) (struct sprinter *, const char *);
\r
146 + void (*integer) (struct sprinter *, int);
\r
147 + void (*boolean) (struct sprinter *, notmuch_bool_t);
\r
148 + void (*null) (struct sprinter *);
\r
150 + /* print the key of a map's key/value pair.
\r
152 + void (*map_key) (struct sprinter *, const char *);
\r
154 + /* print a frame delimiter (such as a newline or extra whitespace)
\r
156 + void (*frame) (struct sprinter *);
\r
159 +/* Create a new structure printer that emits JSON */
\r
161 +sprinter_json_new(const void *ctx, FILE *stream);
\r
163 +/* A dummy structure printer that signifies that standard text output is
\r
164 + * to be used instead of any structured format.
\r
169 +#endif // NOTMUCH_SPRINTER_H
\r