[PATCH v4 1/3] Add support for structured output formatters.
authorcraven <craven@gmx.net>
Thu, 12 Jul 2012 07:43:22 +0000 (09:43 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:11 +0000 (09:48 -0800)
f1/5570a49071ba698c6ab2d9c914d2749082d965 [new file with mode: 0644]

diff --git a/f1/5570a49071ba698c6ab2d9c914d2749082d965 b/f1/5570a49071ba698c6ab2d9c914d2749082d965
new file mode 100644 (file)
index 0000000..91c731e
--- /dev/null
@@ -0,0 +1,172 @@
+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 29153431FC9\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 00:42:21 -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 kH1GQ0bvk8eU for <notmuch@notmuchmail.org>;\r
+       Thu, 12 Jul 2012 00:42:19 -0700 (PDT)\r
+Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.22])\r
+       by olra.theworths.org (Postfix) with SMTP id E8F5B429E4B\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 00:42:15 -0700 (PDT)\r
+Received: (qmail invoked by alias); 12 Jul 2012 07:42:03 -0000\r
+Received: from gw.arelion.cust.net.lagis.at (EHLO dodekanex.arelion.at)\r
+       [83.164.197.182]\r
+       by mail.gmx.net (mp030) with SMTP; 12 Jul 2012 09:42:03 +0200\r
+X-Authenticated: #201305\r
+X-Provags-ID: V01U2FsdGVkX1/sUeJEZpbsAZ2RhLXfCrmVKmhokI92GbzUxdJC3b\r
+       1C2Le4WrIjDPca\r
+Received: by dodekanex.arelion.at (Postfix, from userid 1000)\r
+       id 1F6593011A8; Thu, 12 Jul 2012 09:43:30 +0200 (CEST)\r
+From: <craven@gmx.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 1/3] Add support for structured output formatters.\r
+Date: Thu, 12 Jul 2012 09:43:22 +0200\r
+Message-Id: <1342079004-5300-2-git-send-email-craven@gmx.net>\r
+X-Mailer: git-send-email 1.7.11.1\r
+In-Reply-To: <1342079004-5300-1-git-send-email-craven@gmx.net>\r
+References: <87d34hsdx8.fsf@awakening.csail.mit.edu>\r
+       <1342079004-5300-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: Thu, 12 Jul 2012 07:42:21 -0000\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
+\r
+The structure printer contains the following function pointers:\r
+\r
+/* start a new map/dictionary structure.\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
+/* print one string/integer/boolean/null element (possibly inside a\r
+ * list or map\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.\r
+ */\r
+void (*map_key) (struct sprinter *, const char *);\r
+\r
+/* print a frame delimiter (such as a newline or extra whitespace)\r
+ */\r
+void (*frame) (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 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 file changed, 49 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..1dad9a0\r
+--- /dev/null\r
++++ b/sprinter.h\r
+@@ -0,0 +1,49 @@\r
++#ifndef NOTMUCH_SPRINTER_H\r
++#define NOTMUCH_SPRINTER_H\r
++\r
++/* for notmuch_bool_t */\r
++#include "notmuch-client.h"\r
++\r
++/* Structure printer interface */\r
++typedef struct sprinter\r
++{\r
++    /* start a new map/dictionary structure.\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
++    /* print one string/integer/boolean/null element (possibly inside a\r
++     * list or map\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.\r
++     */\r
++    void (*map_key) (struct sprinter *, const char *);\r
++\r
++    /* print a frame delimiter (such as a newline or extra whitespace)\r
++     */\r
++    void (*frame) (struct sprinter *);\r
++} sprinter_t;\r
++\r
++/* Create a new structure printer that emits JSON */\r
++struct sprinter *\r
++sprinter_json_new(const void *ctx, FILE *stream);\r
++\r
++/* A dummy structure printer that signifies that standard text output is\r
++ * to be used instead of any structured format.\r
++ */\r
++struct sprinter *\r
++sprinter_text;\r
++\r
++#endif // NOTMUCH_SPRINTER_H\r
+-- \r
+1.7.11.1\r
+\r