From b68a606c827eb01d43b5590faaf9f2c1059578fa Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 13 Jul 2012 18:08:14 +2000 Subject: [PATCH] Re: [PATCH v4 1/3] Add support for structured output formatters. --- 0b/eb6d656e22c0cd5722213c5899cfbe330f60de | 199 ++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 0b/eb6d656e22c0cd5722213c5899cfbe330f60de diff --git a/0b/eb6d656e22c0cd5722213c5899cfbe330f60de b/0b/eb6d656e22c0cd5722213c5899cfbe330f60de new file mode 100644 index 000000000..eba4fea32 --- /dev/null +++ b/0b/eb6d656e22c0cd5722213c5899cfbe330f60de @@ -0,0 +1,199 @@ +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 CA81B431FC4 + for ; Thu, 12 Jul 2012 15:08:17 -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 1UbJDQi0ahld for ; + Thu, 12 Jul 2012 15:08:16 -0700 (PDT) +Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU + [18.7.68.34]) + by olra.theworths.org (Postfix) with ESMTP id 61701431FAE + for ; Thu, 12 Jul 2012 15:08:16 -0700 (PDT) +X-AuditID: 12074422-b7f1f6d00000090b-97-4fff4acfa785 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP + id 3B.A7.02315.FCA4FFF4; Thu, 12 Jul 2012 18:08:15 -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 q6CM8FcE024815; + Thu, 12 Jul 2012 18:08:15 -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 q6CM8Ee2029131 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 12 Jul 2012 18:08:14 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SpRYU-0004sR-1R; Thu, 12 Jul 2012 18:08:14 -0400 +Date: Thu, 12 Jul 2012 18:08:14 -0400 +From: Austin Clements +To: craven@gmx.net +Subject: Re: [PATCH v4 1/3] Add support for structured output formatters. +Message-ID: <20120712220814.GJ7332@mit.edu> +References: <87d34hsdx8.fsf@awakening.csail.mit.edu> + <1342079004-5300-1-git-send-email-craven@gmx.net> + <1342079004-5300-2-git-send-email-craven@gmx.net> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <1342079004-5300-2-git-send-email-craven@gmx.net> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmplleLIzCtJLcpLzFFi42IRYrdT0T3v9d/fYPk6C4u9De2MFtdvzmR2 + YPJYvGk/m8ezVbeYA5iiuGxSUnMyy1KL9O0SuDIebrjLVHBXpqLpwRzWBsZtYl2MnBwSAiYS + j491sEDYYhIX7q1n62Lk4hAS2McoceXcGlYIZwOjxLmvexghnJNMEk/bjzFDOEsYJZY3T2cE + 6WcRUJVY8X4DG4jNJqAhsW3/crC4iICQxKQvr8B2MAtIS3z73cwEYgsLeEqcOt0KFucV0JbY + vXgJC8TQOYwSEzsfsUIkBCVOznwC1awlcePfS6BmDrBBy/9xgIQ5BewkTk3/D7ZLVEBFYsrJ + bWwTGIVmIemehaR7FkL3AkbmVYyyKblVurmJmTnFqcm6xcmJeXmpRbqmermZJXqpKaWbGMGh + 7aK0g/HnQaVDjAIcjEo8vDvX/fUXYk0sK67MPcQoycGkJMpr7frfX4gvKT+lMiOxOCO+qDQn + tfgQowQHs5II7zp7oBxvSmJlVWpRPkxKmoNFSZz3WspNfyGB9MSS1OzU1ILUIpisDAeHkgTv + Fk+gRsGi1PTUirTMnBKENBMHJ8hwHqDhs0BqeIsLEnOLM9Mh8qcYFaXEeW+CJARAEhmleXC9 + sNTzilEc6BVh3jsgVTzAtAXX/QpoMBPI4J//QAaXJCKkpBoYUw7cWa4gn3aZI7Ex6syqaVsU + php4lZYde5kuGenatdz0sYyQpVmQzqy22TM+ZbZFnjeI3r94Ddu9tef+f2C2n3Dr5+sf9RdN + bxS969q5/9qOWp8oGy3pFUzlsR+/hJ+4wrcyp0TjzPZL/NMEP0ce3xt4UOH+I5fQloIy3tRJ + 1rZrGmfoudfVKLEUZyQaajEXFScCAItFvqMYAwAA +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: Thu, 12 Jul 2012 22:08:17 -0000 + +Quoth craven@gmx.net on Jul 12 at 9:43 am: +> 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). +> +> The structure printer contains the following function pointers: +> +> /* start a new map/dictionary structure. +> */ +> 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 *); +> +> /* print one string/integer/boolean/null element (possibly inside a +> * list or map +> */ +> 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. +> */ +> void (*map_key) (struct sprinter *, const char *); +> +> /* print a frame delimiter (such as a newline or extra whitespace) +> */ +> void (*frame) (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 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ +> 1 file changed, 49 insertions(+) +> create mode 100644 sprinter.h +> +> diff --git a/sprinter.h b/sprinter.h +> new file mode 100644 +> index 0000000..1dad9a0 +> --- /dev/null +> +++ b/sprinter.h +> @@ -0,0 +1,49 @@ +> +#ifndef NOTMUCH_SPRINTER_H +> +#define NOTMUCH_SPRINTER_H +> + +> +/* for notmuch_bool_t */ +> +#include "notmuch-client.h" +> + +> +/* Structure printer interface */ +> +typedef struct sprinter +> +{ +> + /* start a new map/dictionary structure. +> + */ +> + 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 *); +> + +> + /* print one string/integer/boolean/null element (possibly inside a +> + * list or map +> + */ +> + void (*string) (struct sprinter *, const char *); + +Oh, also, the documentation for string should mention the string +argument should be UTF-8 encoded. + +> + 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. +> + */ +> + void (*map_key) (struct sprinter *, const char *); +> + +> + /* print a frame delimiter (such as a newline or extra whitespace) +> + */ +> + void (*frame) (struct sprinter *); +> +} sprinter_t; +> + +> +/* Create a new structure printer that emits JSON */ +> +struct sprinter * +> +sprinter_json_new(const void *ctx, FILE *stream); +> + +> +/* A dummy structure printer that signifies that standard text output is +> + * to be used instead of any structured format. +> + */ +> +struct sprinter * +> +sprinter_text; +> + +> +#endif // NOTMUCH_SPRINTER_H -- 2.26.2