From: Austin Clements Date: Sat, 14 Jul 2012 01:46:29 +0000 (+2000) Subject: Re: [PATCH v5 1/3] Add support for structured output formatters. X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=8589d1d1bd13daa7e7f2b941794c9ea03802b36a;p=notmuch-archives.git Re: [PATCH v5 1/3] Add support for structured output formatters. --- diff --git a/c8/c22242c18f7e1d274a7b24fa7e3b53fd06f6be b/c8/c22242c18f7e1d274a7b24fa7e3b53fd06f6be new file mode 100644 index 000000000..d241affa5 --- /dev/null +++ b/c8/c22242c18f7e1d274a7b24fa7e3b53fd06f6be @@ -0,0 +1,228 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id D2F0F431FB6 + for ; Fri, 13 Jul 2012 18:46:33 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id MxJB49XwDqnA for ; + Fri, 13 Jul 2012 18:46:33 -0700 (PDT) +Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU + [18.9.25.13]) + by olra.theworths.org (Postfix) with ESMTP id D4B58431FAE + for ; Fri, 13 Jul 2012 18:46:32 -0700 (PDT) +X-AuditID: 1209190d-b7fd56d000000933-f4-5000cf77a7e0 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP + id 4C.B7.02355.77FC0005; Fri, 13 Jul 2012 21:46:31 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q6E1kUSS006235; + Fri, 13 Jul 2012 21:46:31 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6E1kTIw007839 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Fri, 13 Jul 2012 21:46:30 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SprRF-0000cE-DJ; Fri, 13 Jul 2012 21:46:29 -0400 +Date: Fri, 13 Jul 2012 21:46:29 -0400 +From: Austin Clements +To: Peter Feigl +Subject: Re: [PATCH v5 1/3] Add support for structured output formatters. +Message-ID: <20120714014629.GB31670@mit.edu> +References: <20120710191331.GE7332@mit.edu> + <1342167097-25012-1-git-send-email-craven@gmx.net> + <1342167097-25012-2-git-send-email-craven@gmx.net> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <1342167097-25012-2-git-send-email-craven@gmx.net> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT0S0/zxBg8PKlgsXehnZGi+s3ZzI7 + MHks3rSfzePZqlvMAUxRXDYpqTmZZalF+nYJXBk7D69lLniqUbFgzmG2BsYH8l2MnBwSAiYS + m280skPYYhIX7q1n62Lk4hAS2McocXjNS7CEkMAGRomJ74shEieZJObefcEM4SxhlHh29jZY + FYuAqkRXYwsriM0moCGxbf9yRhBbREBB4tm6JjCbWUBa4tvvZiYQW1jAU2Lv3e1sIDavgI5E + y5XprBBDpzJKzH97khUiIShxcuYTFohmLYkb/14CNXOADVr+jwMkzClgL/H82zFmEFtUQEVi + ysltbBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFukZ6uZkleqkppZsY + QYHNKcm7g/HdQaVDjAIcjEo8vKn+DAFCrIllxZW5hxglOZiURHlrjwOF+JLyUyozEosz4otK + c1KLDzFKcDArifCatwHleFMSK6tSi/JhUtIcLErivFdSbvoLCaQnlqRmp6YWpBbBZGU4OJQk + eE+fA2oULEpNT61Iy8wpQUgzcXCCDOcBGv4QpIa3uCAxtzgzHSJ/ilFRSpz3LUhCACSRUZoH + 1wtLPK8YxYFeEeb9BVLFA0xacN2vgAYzAQ2e9fOfP9DgkkSElFQD4/ZFzH9eP5t19mR9dLyR + 97T9FzyZbm3JP71eYf+BiD3nj8ZErnis6mw3VW02V+HcZTEMX24Vr+b76WN0YM2Smf/vT7g/ + 42hiwlGn0Bk7dnPLRdqJ3FHs32OdzKzscVhMYuuThmKdiww9/M4W+n7ZdndTozjDO456Jb2a + u3zr9zcp+j0TAn/wPlZiKc5INNRiLipOBACWAzoyFwMAAA== +Cc: notmuch@notmuchmail.org +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 14 Jul 2012 01:46:34 -0000 + +Quoth Peter Feigl on Jul 13 at 10:11 am: +> From: +> +> This patch adds a new type sprinter_t, which is used for structured +> formatting, e.g. JSON or S-Expressions. The structure printer is the +> code from Austin Clements (id:87d34hsdx8.fsf@awakening.csail.mit.edu) +> with minor modifications. +> +> The structure printer contains the following function pointers: +> +> /* Start a new map/dictionary structure. This should be followed by +> * a sequence of alternating calls to map_key and one of the +> * value-printing functions until the map is ended by end. +> */ +> void (*begin_map)(struct sprinter *); +> +> /* Start a new list/array structure. +> */ +> void (*begin_list)(struct sprinter *); +> +> /* End the last opened list or map structure. +> */ +> void (*end)(struct sprinter *); +> +> /* Set the prefix of the next component. This is purely for +> * debugging purposes and for the unstructured text formatter. +> */ +> void (*set_prefix)(struct sprinter *, const char *); +> +> /* Print one string/integer/boolean/null element (possibly inside a +> * list or map, followed or preceded by separators). +> * For string, the char * must be UTF-8 encoded. +> */ +> void (*string)(struct sprinter *, const char *); +> void (*integer)(struct sprinter *, int); +> void (*boolean)(struct sprinter *, notmuch_bool_t); +> void (*null)(struct sprinter *); +> +> /* Print the key of a map's key/value pair. The char * must be UTF-8 +> * encoded. +> */ +> void (*map_key)(struct sprinter *, const char *); +> +> /* Insert a separator (usually extra whitespace) for improved +> * readability without affecting the abstract syntax of the +> * structure being printed. +> * For JSON, this could simply be a line break. +> */ +> void (*separator)(struct sprinter *); +> +> The printer can (and should) use internal state to insert delimiters and +> syntax at the correct places. +> +> Example: +> +> format->begin_map(format); +> format->map_key(format, "foo"); +> format->begin_list(format); +> format->integer(format, 1); +> format->integer(format, 2); +> format->integer(format, 3); +> format->end(format); +> format->map_key(format, "bar"); +> format->begin_map(format); +> format->map_key(format, "baaz"); +> format->string(format, "hello world"); +> format->end(format); +> format->end(format); +> +> would output JSON as follows: +> +> {"foo": [1, 2, 3], "bar": { "baaz": "hello world"}} +> --- +> sprinter.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ +> 1 file changed, 50 insertions(+) +> create mode 100644 sprinter.h +> +> diff --git a/sprinter.h b/sprinter.h +> new file mode 100644 +> index 0000000..c9cd6a6 +> --- /dev/null +> +++ b/sprinter.h +> @@ -0,0 +1,50 @@ +> +#ifndef NOTMUCH_SPRINTER_H +> +#define NOTMUCH_SPRINTER_H +> + +> +/* Necessary for notmuch_bool_t */ +> +#include "notmuch-client.h" +> + +> +/* Structure printer interface */ +> +typedef struct sprinter { +> + /* Start a new map/dictionary structure. This should be followed by +> + * a sequence of alternating calls to map_key and one of the +> + * value-printing functions until the map is ended by end. +> + */ +> + void (*begin_map)(struct sprinter *); + +It looks like you lost the spaces before the argument lists, which +your previous version had. Was this from uncrustify? The few other +places that notmuch had function pointers do put a space here. + +> + +> + /* Start a new list/array structure. +> + */ +> + void (*begin_list)(struct sprinter *); +> + +> + /* End the last opened list or map structure. +> + */ +> + void (*end)(struct sprinter *); +> + +> + /* Set the prefix of the next component. This is purely for +> + * debugging purposes and for the unstructured text formatter. + +This should probably be more specific about what this operation does +and under what circumstances. It also makes it sound like it only +applies to the next component, which I think is not the case. Maybe + +/* Set the current string prefix. This only affects the text + * printer, which will print this string, followed by a colon, before + * any string. For other printers, this does nothing. + */ + +? + +> + */ +> + void (*set_prefix)(struct sprinter *, const char *); +> + +> + /* Print one string/integer/boolean/null element (possibly inside a +> + * list or map, followed or preceded by separators). +> + * For string, the char * must be UTF-8 encoded. +> + */ +> + void (*string)(struct sprinter *, const char *); +> + void (*integer)(struct sprinter *, int); +> + void (*boolean)(struct sprinter *, notmuch_bool_t); +> + void (*null)(struct sprinter *); +> + +> + /* Print the key of a map's key/value pair. The char * must be UTF-8 +> + * encoded. +> + */ +> + void (*map_key)(struct sprinter *, const char *); +> + +> + /* Insert a separator (usually extra whitespace) for improved +> + * readability without affecting the abstract syntax of the +> + * structure being printed. +> + * For JSON, this could simply be a line break. +> + */ +> + void (*separator)(struct sprinter *); +> +} sprinter_t; +> + +> +#endif // NOTMUCH_SPRINTER_H