Re: [PATCH v7 1/3] Add support for structured output formatters.
authorTomi Ollila <tomi.ollila@iki.fi>
Fri, 20 Jul 2012 09:09:07 +0000 (12:09 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:25 +0000 (09:48 -0800)
da/4247ceb5f878aa6c3cc4f4d6db9ac02c96773d [new file with mode: 0644]

diff --git a/da/4247ceb5f878aa6c3cc4f4d6db9ac02c96773d b/da/4247ceb5f878aa6c3cc4f4d6db9ac02c96773d
new file mode 100644 (file)
index 0000000..ab467a7
--- /dev/null
@@ -0,0 +1,226 @@
+Return-Path: <tomi.ollila@iki.fi>\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 9FD68431FBC\r
+       for <notmuch@notmuchmail.org>; Fri, 20 Jul 2012 02:08:59 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\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 6OhAR-PXdlpA for <notmuch@notmuchmail.org>;\r
+       Fri, 20 Jul 2012 02:08:58 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 39A80431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 20 Jul 2012 02:08:58 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+       id 96BF710014D; Fri, 20 Jul 2012 12:09:07 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: craven@gmx.net, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v7 1/3] Add support for structured output formatters.\r
+In-Reply-To: <1342766173-1344-2-git-send-email-craven@gmx.net>\r
+References: <20120718194819.GP31670@mit.edu>\r
+       <1342766173-1344-1-git-send-email-craven@gmx.net>\r
+       <1342766173-1344-2-git-send-email-craven@gmx.net>\r
+User-Agent: Notmuch/0.13.2+93~ge4fdd97 (http://notmuchmail.org) Emacs/23.1.1\r
+       (x86_64-redhat-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+       $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+       !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Fri, 20 Jul 2012 12:09:07 +0300\r
+Message-ID: <m2txx294uk.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\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, 20 Jul 2012 09:08:59 -0000\r
+\r
+On Fri, Jul 20 2012, craven@gmx.net wrote:\r
+\r
+> From: <craven@gmx.net>\r
+>\r
+> This patch adds a new struct type sprinter_t, which is used for\r
+> structured formatting, e.g. JSON or S-Expressions. The structure printer\r
+> is heavily based on code from Austin Clements\r
+> (id:87d34hsdx8.fsf@awakening.csail.mit.edu).\r
+>\r
+> It includes the following functions:\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
+>     /* 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
+>     /* Set the current string prefix. This only affects the text\r
+>      * printer, which will print this string, followed by a colon,\r
+>      * before any string. For other printers, this does nothing.\r
+>      */\r
+>     void (*set_prefix) (struct sprinter *, const char *);\r
+\r
+The above block duplicated below. Otherwise this LGTM.\r
+\r
+I presume the patch 3/3 emails\r
+\r
+id:"1342766173-1344-4-git-send-email-craven@gmx.net"\r
+id:"1342772624-23329-1-git-send-email-craven@gmx.net"\r
+\r
+have identical content ?\r
+\r
+> To support the plain text format properly, the following additional\r
+> function must also be implemented:\r
+>\r
+>     /* Set the current string prefix. This only affects the text\r
+>      * printer, which will print this string, followed by a colon,\r
+>      * before any string. For other printers, this does nothing.\r
+>      */\r
+>     void (*set_prefix) (struct sprinter *, const char *);\r
+>\r
+> The structure also contains a flag that should be set to FALSE in all\r
+> custom printers and to TRUE in the plain text formatter.\r
+>\r
+>     /* True if this is the special-cased plain text printer.\r
+>      */\r
+>     notmuch_bool_t is_text_printer;\r
+>\r
+> The printer can (and should) use internal state to insert delimiters\r
+> and 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 | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+>  1 file changed, 58 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..77dc26f\r
+> --- /dev/null\r
+> +++ b/sprinter.h\r
+> @@ -0,0 +1,58 @@\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. This is used to create output\r
+> + * structured as maps (with key/value pairs), lists and primitives\r
+> + * (strings, integers and booleans).\r
+> + */\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
+> +    /* 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
+> +    /* Set the current string prefix. This only affects the text\r
+> +     * printer, which will print this string, followed by a colon,\r
+> +     * before any string. For other printers, this does nothing.\r
+> +     */\r
+> +    void (*set_prefix) (struct sprinter *, const char *);\r
+> +\r
+> +    /* True if this is the special-cased plain text printer.\r
+> +     */\r
+> +    notmuch_bool_t is_text_printer;\r
+> +} sprinter_t;\r
+> +\r
+> +#endif // NOTMUCH_SPRINTER_H\r
+> -- \r
+> 1.7.11.2\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r