From abdf9036ec3763daf0425d9a629ebf908a9bc053 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 6 Apr 2015 07:59:06 +0900 Subject: [PATCH] [WIP2 04/12] cli: add type introspection to sprinter type --- 42/3dc9e809601759aab67a9697a86a63e3710382 | 121 ++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 42/3dc9e809601759aab67a9697a86a63e3710382 diff --git a/42/3dc9e809601759aab67a9697a86a63e3710382 b/42/3dc9e809601759aab67a9697a86a63e3710382 new file mode 100644 index 000000000..6213da14f --- /dev/null +++ b/42/3dc9e809601759aab67a9697a86a63e3710382 @@ -0,0 +1,121 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 79E566DE1B83 + for ; Sun, 5 Apr 2015 16:01:36 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.564 +X-Spam-Level: +X-Spam-Status: No, score=0.564 tagged_above=-999 required=5 tests=[AWL=0.554, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id bfzld1fAu9Lw for ; + Sun, 5 Apr 2015 16:01:34 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id B0A006DE1B72 + for ; Sun, 5 Apr 2015 16:01:34 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1YetXA-0002om-S7; Sun, 05 Apr 2015 23:00:52 +0000 +Received: (nullmailer pid 2243 invoked by uid 1000); Sun, 05 Apr 2015 + 22:59:25 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [WIP2 04/12] cli: add type introspection to sprinter type +Date: Mon, 6 Apr 2015 07:59:06 +0900 +Message-Id: <1428274754-1698-5-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net> +References: <1428274754-1698-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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: Sun, 05 Apr 2015 23:01:36 -0000 + +This will make it easier to skip generating certain output for the +text format. +--- + sprinter-json.c | 1 + + sprinter-sexp.c | 1 + + sprinter-text.c | 1 + + sprinter.h | 10 ++++++++++ + 4 files changed, 13 insertions(+) + +diff --git a/sprinter-json.c b/sprinter-json.c +index 0a07790..8e5ffbe 100644 +--- a/sprinter-json.c ++++ b/sprinter-json.c +@@ -175,6 +175,7 @@ sprinter_json_create (const void *ctx, FILE *stream) + { + static const struct sprinter_json template = { + .vtable = { ++ .type = NOTMUCH_SPRINTER_JSON, + .begin_map = json_begin_map, + .begin_list = json_begin_list, + .end = json_end, +diff --git a/sprinter-sexp.c b/sprinter-sexp.c +index 0aa51e8..e187c05 100644 +--- a/sprinter-sexp.c ++++ b/sprinter-sexp.c +@@ -210,6 +210,7 @@ sprinter_sexp_create (const void *ctx, FILE *stream) + { + static const struct sprinter_sexp template = { + .vtable = { ++ .type = NOTMUCH_SPRINTER_SEXP, + .begin_map = sexp_begin_map, + .begin_list = sexp_begin_list, + .end = sexp_end, +diff --git a/sprinter-text.c b/sprinter-text.c +index 7779488..cd6cd56 100644 +--- a/sprinter-text.c ++++ b/sprinter-text.c +@@ -117,6 +117,7 @@ sprinter_text_create (const void *ctx, FILE *stream) + { + static const struct sprinter_text template = { + .vtable = { ++ .type = NOTMUCH_SPRINTER_TEXT, + .begin_map = text_begin_map, + .begin_list = text_begin_list, + .end = text_end, +diff --git a/sprinter.h b/sprinter.h +index f859672..7e58f69 100644 +--- a/sprinter.h ++++ b/sprinter.h +@@ -4,11 +4,21 @@ + /* Necessary for notmuch_bool_t */ + #include "notmuch-client.h" + ++enum notmuch_sprinter_type { ++ NOTMUCH_SPRINTER_JSON, ++ NOTMUCH_SPRINTER_SEXP, ++ NOTMUCH_SPRINTER_TEXT ++}; ++ + /* Structure printer interface. This is used to create output + * structured as maps (with key/value pairs), lists and primitives + * (strings, integers and booleans). + */ + typedef struct sprinter { ++ /* Identify the type of sprinter ++ */ ++ enum notmuch_sprinter_type type; ++ + /* 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. +-- +2.1.4 + -- 2.26.2