[WIP2 04/12] cli: add type introspection to sprinter type

David Bremner david at tethera.net
Sun Apr 5 15:59:06 PDT 2015


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



More information about the notmuch mailing list