Re: [PATCH v5 2/3] Add structured output formatter for JSON and text.
authorAustin Clements <amdragon@MIT.EDU>
Sat, 14 Jul 2012 02:02:11 +0000 (22:02 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:17 +0000 (09:48 -0800)
40/235554518d43339946f6fe93530aedc6978587 [new file with mode: 0644]

diff --git a/40/235554518d43339946f6fe93530aedc6978587 b/40/235554518d43339946f6fe93530aedc6978587
new file mode 100644 (file)
index 0000000..616d7bd
--- /dev/null
@@ -0,0 +1,552 @@
+Return-Path: <amdragon@mit.edu>\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 BD3FF431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 19:02:15 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 WeD2gnFmBSmI for <notmuch@notmuchmail.org>;\r
+       Fri, 13 Jul 2012 19:02:13 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
+       [18.9.25.13])\r
+       by olra.theworths.org (Postfix) with ESMTP id 3D3DC431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 19:02:13 -0700 (PDT)\r
+X-AuditID: 1209190d-b7fd56d000000933-cd-5000d32426b7\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 25.F7.02355.423D0005; Fri, 13 Jul 2012 22:02:12 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q6E22CSA007243; \r
+       Fri, 13 Jul 2012 22:02:12 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6E22Bcu009180\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Fri, 13 Jul 2012 22:02:12 -0400 (EDT)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SprgR-0000e7-CG; Fri, 13 Jul 2012 22:02:11 -0400\r
+Date: Fri, 13 Jul 2012 22:02:11 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Peter Feigl <craven@gmx.net>\r
+Subject: Re: [PATCH v5 2/3] Add structured output formatter for JSON and text.\r
+Message-ID: <20120714020211.GC31670@mit.edu>\r
+References: <20120710191331.GE7332@mit.edu>\r
+       <1342167097-25012-1-git-send-email-craven@gmx.net>\r
+       <1342167097-25012-3-git-send-email-craven@gmx.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1342167097-25012-3-git-send-email-craven@gmx.net>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT0VW5zBBg0N5hYLG3oZ3R4vrNmcwO\r
+       TB6LN+1n83i26hZzAFMUl01Kak5mWWqRvl0CV8aa+T+YCjbmVbz6u4K9gXFuSBcjJ4eEgInE\r
+       xDmn2SFsMYkL99azdTFycQgJ7GOUuLlwKiuEs4FR4u70zSwQzkkmiWWzL0A5SxglTjVtBirj\r
+       4GARUJV4d7oMZBSbgIbEtv3LGUFsEQEFiWfrmsBsZgFpiW+/m5lAbGEBP4nVRw+wgti8AjoS\r
+       J3fMhlo9lVFiycZzUAlBiZMzn7BANGtJ3Pj3kglkF8ig5f84QMKcAvYS7Ve6wWaKCqhITDm5\r
+       jW0Co9AsJN2zkHTPQuhewMi8ilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdILzezRC81pXQTIyiw\r
+       OSV5dzC+O6h0iFGAg1GJhzfVnyFAiDWxrLgy9xCjJAeTkijvrItAIb6k/JTKjMTijPii0pzU\r
+       4kOMEhzMSiK85m1AOd6UxMqq1KJ8mJQ0B4uSOO+VlJv+QgLpiSWp2ampBalFMFkZDg4lCd6w\r
+       S0CNgkWp6akVaZk5JQhpJg5OkOE8QMP1QWp4iwsSc4sz0yHypxgVpcR5i0ESAiCJjNI8uF5Y\r
+       4nnFKA70ijCvM0gVDzBpwXW/AhrMBDR41s9//kCDSxIRUlINjNLnBN5Mfnp499K57OViUm2m\r
+       CRa+h2wKPyh9temqti7aVnp+n5b6iouxZ8sCF/bMbJpSKbREW/GC3p1LkpV7lGYKuWT4z7F/\r
+       sjX82Gux5pZHa3QjpPcqMnkcfO/Zlry48L1+59TFpw9tOiumtvLKTNEzMx6qbzI1im9b45Of\r
+       N/PWcv4VCddMmJRYijMSDbWYi4oTAdGJc5oXAwAA\r
+Cc: notmuch@notmuchmail.org\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: Sat, 14 Jul 2012 02:02:15 -0000\r
+\r
+Quoth Peter Feigl on Jul 13 at 10:11 am:\r
+> From: <craven@gmx.net>\r
+> \r
+> Using the new structured printer support in sprinter.h, implement\r
+> sprinter_json_create, which returns a new JSON structured output\r
+> formatter. The formatter prints output similar to the existing JSON, but\r
+> with differences in whitespace (mostly newlines, --output=summary prints\r
+> the entire message summary on one line, not split across multiple lines).\r
+> \r
+> Also implement a "structured" formatter that prints the current plain\r
+> text format. This passes all tests, but the exact formatting is probably\r
+> specific to notmuch-search and cannot easily (if at all) be adapted to\r
+> be used across all of notmuch-{search,reply,show,...}.\r
+> ---\r
+>  Makefile.local         |   2 +\r
+>  sprinter-json.c        | 184 +++++++++++++++++++++++++++++++++++++++++++++++\r
+>  sprinter-text-search.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+>  sprinter.h             |   8 +++\r
+>  4 files changed, 384 insertions(+)\r
+>  create mode 100644 sprinter-json.c\r
+>  create mode 100644 sprinter-text-search.c\r
+> \r
+> diff --git a/Makefile.local b/Makefile.local\r
+> index a890df2..b6c7e0c 100644\r
+> --- a/Makefile.local\r
+> +++ b/Makefile.local\r
+> @@ -290,6 +290,8 @@ notmuch_client_srcs =            \\r
+>      notmuch-show.c          \\r
+>      notmuch-tag.c           \\r
+>      notmuch-time.c          \\r
+> +    sprinter-json.c         \\r
+> +    sprinter-text-search.c  \\r
+>      query-string.c          \\r
+>      mime-node.c             \\r
+>      crypto.c                \\r
+> diff --git a/sprinter-json.c b/sprinter-json.c\r
+> new file mode 100644\r
+> index 0000000..215151d\r
+> --- /dev/null\r
+> +++ b/sprinter-json.c\r
+> @@ -0,0 +1,184 @@\r
+> +#include <stdbool.h>\r
+> +#include <stdio.h>\r
+> +#include <talloc.h>\r
+> +#include "sprinter.h"\r
+> +\r
+> +struct sprinter_json {\r
+> +    struct sprinter vtable;\r
+> +    FILE *stream;\r
+> +    /* Top of the state stack, or NULL if the printer is not currently\r
+> +     * inside any aggregate types. */\r
+> +    struct json_state *state;\r
+> +\r
+> +    /* A flag to signify that a separator should be inserted in the\r
+> +     * output as soon as possible.\r
+> +     */\r
+> +    notmuch_bool_t insert_separator;\r
+> +};\r
+> +\r
+> +struct json_state {\r
+> +    struct json_state *parent;\r
+> +    /* True if nothing has been printed in this aggregate yet.\r
+> +     * Suppresses the comma before a value. */\r
+> +    notmuch_bool_t first;\r
+> +    /* The character that closes the current aggregate. */\r
+> +    char close;\r
+> +};\r
+> +\r
+> +/* Helper function to set up the stream to print a value.  If this\r
+> + * value follows another value, prints a comma. */\r
+> +static struct sprinter_json *\r
+> +json_begin_value (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_json *spj = (struct sprinter_json *) sp;\r
+> +\r
+> +    if (spj->state) {\r
+> +    if (! spj->state->first) {\r
+> +        fputc (',', spj->stream);\r
+> +        if (spj->insert_separator) {\r
+> +            fputc ('\n', spj->stream);\r
+> +            spj->insert_separator = FALSE;\r
+> +        } else\r
+> +            fputc (' ', spj->stream);\r
+> +    } else\r
+> +        spj->state->first = FALSE;\r
+> +    }\r
+> +    return spj;\r
+> +}\r
+> +\r
+> +/* Helper function to begin an aggregate type.  Prints the open\r
+> + * character and pushes a new state frame. */\r
+> +static void\r
+> +json_begin_aggregate (struct sprinter *sp, char open, char close)\r
+> +{\r
+> +    struct sprinter_json *spj = json_begin_value (sp);\r
+> +    struct json_state *state = talloc (spj, struct json_state);\r
+> +\r
+> +    fputc (open, spj->stream);\r
+> +    state->parent = spj->state;\r
+> +    state->first = TRUE;\r
+> +    state->close = close;\r
+> +    spj->state = state;\r
+> +}\r
+> +\r
+> +static void\r
+> +json_begin_map (struct sprinter *sp)\r
+> +{\r
+> +    json_begin_aggregate (sp, '{', '}');\r
+> +}\r
+> +\r
+> +static void\r
+> +json_begin_list (struct sprinter *sp)\r
+> +{\r
+> +    json_begin_aggregate (sp, '[', ']');\r
+> +}\r
+> +\r
+> +static void\r
+> +json_end (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_json *spj = (struct sprinter_json *) sp;\r
+> +    struct json_state *state = spj->state;\r
+> +\r
+> +    fputc (spj->state->close, spj->stream);\r
+> +    spj->state = state->parent;\r
+> +    talloc_free (state);\r
+> +    if (spj->state == NULL)\r
+> +    fputc ('\n', spj->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +json_string (struct sprinter *sp, const char *val)\r
+> +{\r
+> +    static const char *const escapes[] = {\r
+> +    ['\"'] = "\\\"", ['\\'] = "\\\\", ['\b'] = "\\b",\r
+> +    ['\f'] = "\\f",  ['\n'] = "\\n",  ['\t'] = "\\t"\r
+> +    };\r
+> +    struct sprinter_json *spj = json_begin_value (sp);\r
+> +\r
+> +    fputc ('"', spj->stream);\r
+> +    for (; *val; ++val) {\r
+> +    unsigned char ch = *val;\r
+> +    if (ch < ARRAY_SIZE (escapes) && escapes[ch])\r
+> +        fputs (escapes[ch], spj->stream);\r
+> +    else if (ch >= 32)\r
+> +        fputc (ch, spj->stream);\r
+> +    else\r
+> +        fprintf (spj->stream, "\\u%04x", ch);\r
+> +    }\r
+> +    fputc ('"', spj->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +json_integer (struct sprinter *sp, int val)\r
+> +{\r
+> +    struct sprinter_json *spj = json_begin_value (sp);\r
+> +\r
+> +    fprintf (spj->stream, "%d", val);\r
+> +}\r
+> +\r
+> +static void\r
+> +json_boolean (struct sprinter *sp, notmuch_bool_t val)\r
+> +{\r
+> +    struct sprinter_json *spj = json_begin_value (sp);\r
+> +\r
+> +    fputs (val ? "true" : "false", spj->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +json_null (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_json *spj = json_begin_value (sp);\r
+> +\r
+> +    fputs ("null", spj->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +json_map_key (struct sprinter *sp, const char *key)\r
+> +{\r
+> +    struct sprinter_json *spj = (struct sprinter_json *) sp;\r
+> +\r
+> +    json_string (sp, key);\r
+> +    fputs (": ", spj->stream);\r
+> +    spj->state->first = TRUE;\r
+> +}\r
+> +\r
+> +static void\r
+> +json_set_prefix (unused (struct sprinter *sp), unused (const char *name))\r
+> +{\r
+> +}\r
+> +\r
+> +static void\r
+> +json_separator (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_json *spj = (struct sprinter_json *) sp;\r
+> +\r
+> +    spj->insert_separator = TRUE;\r
+> +}\r
+> +\r
+> +struct sprinter *\r
+> +sprinter_json_create (const void *ctx, FILE *stream)\r
+> +{\r
+> +    static const struct sprinter_json template = {\r
+> +    .vtable = {\r
+> +        .begin_map = json_begin_map,\r
+> +        .begin_list = json_begin_list,\r
+> +        .end = json_end,\r
+> +        .string = json_string,\r
+> +        .integer = json_integer,\r
+> +        .boolean = json_boolean,\r
+> +        .null = json_null,\r
+> +        .map_key = json_map_key,\r
+> +        .separator = json_separator,\r
+> +        .set_prefix = json_set_prefix,\r
+> +    }\r
+> +    };\r
+> +    struct sprinter_json *res;\r
+> +\r
+> +    res = talloc (ctx, struct sprinter_json);\r
+> +    if (! res)\r
+> +    return NULL;\r
+> +\r
+> +    *res = template;\r
+> +    res->stream = stream;\r
+> +    return &res->vtable;\r
+> +}\r
+> diff --git a/sprinter-text-search.c b/sprinter-text-search.c\r
+> new file mode 100644\r
+> index 0000000..95ed9cb\r
+> --- /dev/null\r
+> +++ b/sprinter-text-search.c\r
+> @@ -0,0 +1,190 @@\r
+> +#include <stdbool.h>\r
+> +#include <stdio.h>\r
+> +#include <talloc.h>\r
+> +#include "sprinter.h"\r
+> +\r
+> +/* "Structured printer" interface for unstructured text printing.\r
+> + * This is at best a misuse of the interface, but it simplifies the code\r
+> + * in notmuch-search.c considerably.\r
+> + */\r
+> +\r
+> +struct sprinter_text_search {\r
+> +    struct sprinter vtable;\r
+> +    FILE *stream;\r
+> +\r
+> +    /* The current name or prefix to be printed with string/integer/boolean\r
+> +     * data.\r
+> +     */\r
+> +    const char *current_name;\r
+\r
+"current_prefix"?  Or maybe just "prefix"?  This is the only place\r
+where you use the term "name" for this.\r
+\r
+> +\r
+> +    /* A flag to indicate if this is the first tag. Used in list of tags\r
+> +     * for summary.\r
+> +     */\r
+> +    notmuch_bool_t first_tag;\r
+> +};\r
+> +\r
+> +/* struct text_search_state { */\r
+> +/*     struct text_search_state *parent; */\r
+> +/* }; */\r
+\r
+Left over scratch code?\r
+\r
+> +\r
+> +static notmuch_bool_t\r
+> +current_context (struct sprinter_text_search *sptxt, const char *marker)\r
+> +{\r
+> +    return (sptxt->current_name != NULL\r
+> +        && ! strncmp (marker, sptxt->current_name, strlen (marker)));\r
+> +}\r
+\r
+All of this context stuff seems way more complicated than having a few\r
+special cases in notmuch-search.c.  This is, in effect, just moving\r
+this special casing from there to here, but since the text format is\r
+highly irregular, attempting to generalize it is only going to\r
+obfuscate it.\r
+\r
+I think the simplest and most readable thing to do is to make all of\r
+these functions no-ops (literally empty function bodies) except\r
+text_search_separator and text_search_set_prefix, which should be like\r
+you have them, and text_search_string:\r
+\r
+static void\r
+text_search_string (struct sprinter *sp, const char *val)\r
+{\r
+    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+\r
+    if (sptxt->current_name)\r
+       fprintf (sptxt->stream, "%s:", sptxt->current_name);\r
+    print_sanitized_string (sptxt->stream, val);\r
+}\r
+\r
+For the summary output, you'll have to format the summary line in\r
+notmuch-search.c, much like you did in v4, which was a much simpler\r
+and more readable way to put together the text format lines.\r
+\r
+> +\r
+> +static void\r
+> +print_sanitized_string (FILE *stream, const char *str)\r
+> +{\r
+> +    if (NULL == str)\r
+> +    return;\r
+> +\r
+> +    for (; *str; str++) {\r
+> +    if ((unsigned char) (*str) < 32)\r
+> +        fputc ('?', stream);\r
+> +    else\r
+> +        fputc (*str, stream);\r
+> +    }\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_begin_map (unused (struct sprinter *sp))\r
+> +{\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_begin_list (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    if (current_context (sptxt, "tags")) {\r
+> +    fputs (" (", sptxt->stream);\r
+> +    sptxt->first_tag = TRUE;\r
+> +    }\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_end (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    if (current_context (sptxt, "tags")) {\r
+> +    fputc (')', sptxt->stream);\r
+> +    sptxt->current_name = NULL;\r
+> +    }\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_string (struct sprinter *sp, const char *val)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    if (sptxt->current_name != NULL) {\r
+> +    if (current_context (sptxt, "thread"))\r
+> +        fprintf ( sptxt->stream, "thread:%s ", val);\r
+> +    else if (current_context (sptxt, "date_relative"))\r
+> +        fprintf ( sptxt->stream, "%12s ", val);\r
+> +    else if (current_context (sptxt, "authors")) {\r
+> +        print_sanitized_string (sptxt->stream, val);\r
+> +        fputs ("; ", sptxt->stream);\r
+> +    } else if (current_context (sptxt, "subject"))\r
+> +        print_sanitized_string (sptxt->stream, val);\r
+> +    else if (current_context (sptxt, "tags")) {\r
+> +        if (! sptxt->first_tag)\r
+> +            fputc (' ', sptxt->stream);\r
+> +        else\r
+> +            sptxt->first_tag = FALSE;\r
+> +\r
+> +        fputs (val, sptxt->stream);\r
+> +    } else {\r
+> +        fputs (sptxt->current_name, sptxt->stream);\r
+> +        fputc (':', sptxt->stream);\r
+> +        fputs (val, sptxt->stream);\r
+> +    }\r
+> +    } else {\r
+> +    fputs (val, sptxt->stream);\r
+> +    }\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_integer (struct sprinter *sp, int val)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    if (sptxt->current_name != NULL) {\r
+> +    if (current_context (sptxt, "matched"))\r
+> +        fprintf ( sptxt->stream, "[%d/", val);\r
+> +    else if (current_context (sptxt, "total"))\r
+> +        fprintf ( sptxt->stream, "%d] ", val);\r
+> +    } else\r
+> +    fprintf (sptxt->stream, "%d", val);\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_boolean (struct sprinter *sp, notmuch_bool_t val)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    fputs (val ? "true" : "false", sptxt->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_null (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    fputs ("null", sptxt->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_map_key (struct sprinter *sp, const char *key)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    sptxt->current_name = key;\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_separator (struct sprinter *sp)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    fputc ('\n', sptxt->stream);\r
+> +}\r
+> +\r
+> +static void\r
+> +text_search_set_prefix (struct sprinter *sp, const char *name)\r
+> +{\r
+> +    struct sprinter_text_search *sptxt = (struct sprinter_text_search *) sp;\r
+> +\r
+> +    sptxt->current_name = name;\r
+> +}\r
+> +\r
+> +struct sprinter *\r
+> +sprinter_text_search_create (const void *ctx, FILE *stream)\r
+> +{\r
+> +    static const struct sprinter_text_search template = {\r
+> +    .vtable = {\r
+> +        .begin_map = text_search_begin_map,\r
+> +        .begin_list = text_search_begin_list,\r
+> +        .end = text_search_end,\r
+> +        .string = text_search_string,\r
+> +        .integer = text_search_integer,\r
+> +        .boolean = text_search_boolean,\r
+> +        .null = text_search_null,\r
+> +        .map_key = text_search_map_key,\r
+> +        .separator = text_search_separator,\r
+> +        .set_prefix = text_search_set_prefix,\r
+> +    }\r
+> +    };\r
+> +    struct sprinter_text_search *res;\r
+> +\r
+> +    res = talloc (ctx, struct sprinter_text_search);\r
+> +    if (! res)\r
+> +    return NULL;\r
+> +\r
+> +    *res = template;\r
+> +    res->stream = stream;\r
+> +    return &res->vtable;\r
+> +}\r
+> diff --git a/sprinter.h b/sprinter.h\r
+> index c9cd6a6..4241d65 100644\r
+> --- a/sprinter.h\r
+> +++ b/sprinter.h\r
+> @@ -47,4 +47,12 @@ typedef struct sprinter {\r
+>      void (*separator)(struct sprinter *);\r
+>  } sprinter_t;\r
+>  \r
+> +/* Create a new unstructured printer that emits the default Text format for search. */\r
+\r
+Wrap at 70 columns.\r
+\r
+> +struct sprinter *\r
+> +sprinter_text_search_create (const void *ctx, FILE *stream);\r
+> +\r
+> +/* Create a new structure printer that emits JSON. */\r
+> +struct sprinter *\r
+> +sprinter_json_create (const void *ctx, FILE *stream);\r
+> +\r
+>  #endif // NOTMUCH_SPRINTER_H\r