--- /dev/null
+Return-Path: <craven@gmx.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 6F71D42119C\r
+ for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 01:13:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.001\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.001 tagged_above=-999 required=5\r
+ tests=[FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 6rWCsySVhxs0 for <notmuch@notmuchmail.org>;\r
+ Fri, 13 Jul 2012 01:13:38 -0700 (PDT)\r
+Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23])\r
+ by olra.theworths.org (Postfix) with SMTP id 5182D431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 01:13:38 -0700 (PDT)\r
+Received: (qmail invoked by alias); 13 Jul 2012 08:13:37 -0000\r
+Received: from cm56-137-203.liwest.at (EHLO nexork.localdomain)\r
+ [86.56.137.203] by mail.gmx.net (mp035) with SMTP; 13 Jul 2012 10:13:37 +0200\r
+X-Authenticated: #201305\r
+X-Provags-ID: V01U2FsdGVkX193oLhdBFl3aBKpTndLiBGE+TLr/5HmDGbu4KAsHe\r
+ eh9Ap1g+Hv+kSZ\r
+Received: by nexork.localdomain (Postfix, from userid 1000)\r
+ id 9BC3D4527802; Fri, 13 Jul 2012 10:11:42 +0200 (CEST)\r
+From: Peter Feigl <craven@gmx.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 1/3] Add support for structured output formatters.\r
+Date: Fri, 13 Jul 2012 10:11:35 +0200\r
+Message-Id: <1342167097-25012-2-git-send-email-craven@gmx.net>\r
+X-Mailer: git-send-email 1.7.11.1\r
+In-Reply-To: <1342167097-25012-1-git-send-email-craven@gmx.net>\r
+References: <20120710191331.GE7332@mit.edu>\r
+ <1342167097-25012-1-git-send-email-craven@gmx.net>\r
+X-Y-GMX-Trusted: 0\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 13 Jul 2012 08:13:42 -0000\r
+\r
+From: <craven@gmx.net>\r
+\r
+This patch adds a new type sprinter_t, which is used for structured\r
+formatting, e.g. JSON or S-Expressions. The structure printer is the\r
+code from Austin Clements (id:87d34hsdx8.fsf@awakening.csail.mit.edu)\r
+with minor modifications.\r
+\r
+The structure printer contains the following function pointers:\r
+\r
+/* Start a new map/dictionary structure. This should be followed by\r
+ * a sequence of alternating calls to map_key and one of the\r
+ * value-printing functions until the map is ended by end.\r
+ */\r
+void (*begin_map)(struct sprinter *);\r
+\r
+/* Start a new list/array structure.\r
+ */\r
+void (*begin_list)(struct sprinter *);\r
+\r
+/* End the last opened list or map structure.\r
+ */\r
+void (*end)(struct sprinter *);\r
+\r
+/* Set the prefix of the next component. This is purely for\r
+ * debugging purposes and for the unstructured text formatter.\r
+ */\r
+void (*set_prefix)(struct sprinter *, const char *);\r
+\r
+/* Print one string/integer/boolean/null element (possibly inside a\r
+ * list or map, followed or preceded by separators).\r
+ * For string, the char * must be UTF-8 encoded.\r
+ */\r
+void (*string)(struct sprinter *, const char *);\r
+void (*integer)(struct sprinter *, int);\r
+void (*boolean)(struct sprinter *, notmuch_bool_t);\r
+void (*null)(struct sprinter *);\r
+\r
+/* Print the key of a map's key/value pair. The char * must be UTF-8\r
+ * encoded.\r
+ */\r
+void (*map_key)(struct sprinter *, const char *);\r
+\r
+/* Insert a separator (usually extra whitespace) for improved\r
+ * readability without affecting the abstract syntax of the\r
+ * structure being printed.\r
+ * For JSON, this could simply be a line break.\r
+ */\r
+void (*separator)(struct sprinter *);\r
+\r
+The printer can (and should) use internal state to insert delimiters and\r
+syntax at the correct places.\r
+\r
+Example:\r
+\r
+format->begin_map(format);\r
+format->map_key(format, "foo");\r
+format->begin_list(format);\r
+format->integer(format, 1);\r
+format->integer(format, 2);\r
+format->integer(format, 3);\r
+format->end(format);\r
+format->map_key(format, "bar");\r
+format->begin_map(format);\r
+format->map_key(format, "baaz");\r
+format->string(format, "hello world");\r
+format->end(format);\r
+format->end(format);\r
+\r
+would output JSON as follows:\r
+\r
+{"foo": [1, 2, 3], "bar": { "baaz": "hello world"}}\r
+---\r
+ sprinter.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 50 insertions(+)\r
+ create mode 100644 sprinter.h\r
+\r
+diff --git a/sprinter.h b/sprinter.h\r
+new file mode 100644\r
+index 0000000..c9cd6a6\r
+--- /dev/null\r
++++ b/sprinter.h\r
+@@ -0,0 +1,50 @@\r
++#ifndef NOTMUCH_SPRINTER_H\r
++#define NOTMUCH_SPRINTER_H\r
++\r
++/* Necessary for notmuch_bool_t */\r
++#include "notmuch-client.h"\r
++\r
++/* Structure printer interface */\r
++typedef struct sprinter {\r
++ /* Start a new map/dictionary structure. This should be followed by\r
++ * a sequence of alternating calls to map_key and one of the\r
++ * value-printing functions until the map is ended by end.\r
++ */\r
++ void (*begin_map)(struct sprinter *);\r
++\r
++ /* Start a new list/array structure.\r
++ */\r
++ void (*begin_list)(struct sprinter *);\r
++\r
++ /* End the last opened list or map structure.\r
++ */\r
++ void (*end)(struct sprinter *);\r
++\r
++ /* Set the prefix of the next component. This is purely for\r
++ * debugging purposes and for the unstructured text formatter.\r
++ */\r
++ void (*set_prefix)(struct sprinter *, const char *);\r
++\r
++ /* Print one string/integer/boolean/null element (possibly inside a\r
++ * list or map, followed or preceded by separators).\r
++ * For string, the char * must be UTF-8 encoded.\r
++ */\r
++ void (*string)(struct sprinter *, const char *);\r
++ void (*integer)(struct sprinter *, int);\r
++ void (*boolean)(struct sprinter *, notmuch_bool_t);\r
++ void (*null)(struct sprinter *);\r
++\r
++ /* Print the key of a map's key/value pair. The char * must be UTF-8\r
++ * encoded.\r
++ */\r
++ void (*map_key)(struct sprinter *, const char *);\r
++\r
++ /* Insert a separator (usually extra whitespace) for improved\r
++ * readability without affecting the abstract syntax of the\r
++ * structure being printed.\r
++ * For JSON, this could simply be a line break.\r
++ */\r
++ void (*separator)(struct sprinter *);\r
++} sprinter_t;\r
++\r
++#endif // NOTMUCH_SPRINTER_H\r
+-- \r
+1.7.11.1\r
+\r