Re: [PATCH v4 1/3] Add support for structured output formatters.
authorMark Walters <markwalters1009@gmail.com>
Thu, 12 Jul 2012 09:21:51 +0000 (10:21 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:12 +0000 (09:48 -0800)
f4/763c2bb8f7b6e41c83bd14e23e957ae7a064fc [new file with mode: 0644]

diff --git a/f4/763c2bb8f7b6e41c83bd14e23e957ae7a064fc b/f4/763c2bb8f7b6e41c83bd14e23e957ae7a064fc
new file mode 100644 (file)
index 0000000..3db31b7
--- /dev/null
@@ -0,0 +1,219 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 B57D0431FC7\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 02:21:56 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 jFHSvwIOdpCj for <notmuch@notmuchmail.org>;\r
+       Thu, 12 Jul 2012 02:21:56 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C60C9431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 02:21:55 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1SpFar-0003s2-SS; Thu, 12 Jul 2012 10:21:54 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1SpFar-0001iA-F5; Thu, 12 Jul 2012 10:21:53 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: craven@gmx.net, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v4 1/3] Add support for structured output formatters.\r
+In-Reply-To: <1342079004-5300-2-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
+       <1342079004-5300-2-git-send-email-craven@gmx.net>\r
+User-Agent: Notmuch/0.13.2+61~gf708609 (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Thu, 12 Jul 2012 10:21:51 +0100\r
+Message-ID: <87pq81tjv4.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: 3f501e9c07fc91483d22fb48a286358c (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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 09:21:56 -0000\r
+\r
+\r
+A couple more things:\r
+\r
+On Thu, 12 Jul 2012, craven@gmx.net wrote:\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
+what is the advantage of having this as one function rather than end_map\r
+and end_list? Indeed, my choice (but I think most other people would\r
+disagree) would be to have both functions but still keep state as this\r
+currently does and then throw an error if the code closes the wrong\r
+thing.\r
+\r
+A second question: do you have an implementation in this style for\r
+s-expressions. I find it hard to tell whether the interface is right\r
+with just a single example. Even a completely hacky not ready for review\r
+example would be helpful.\r
+\r
+Best wishes\r
+\r
+Mark\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
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r