]> git.notmuchmail.org Git - notmuch/commitdiff
show: Associate an sprinter with each format
authorAustin Clements <amdragon@MIT.EDU>
Fri, 3 Aug 2012 01:14:50 +0000 (21:14 -0400)
committerDavid Bremner <bremner@debian.org>
Fri, 3 Aug 2012 23:21:50 +0000 (20:21 -0300)
This associates an sprinter constructor with each show format and uses
this to construct the appropriate sprinter.  Currently nothing is done
with this sprinter, but the following patches will weave it through
the layers of notmuch show.

notmuch-client.h
notmuch-show.c

index f9307989878b4724de489f6862bea2763e4595d2..bbc0a11499b539bf4c84db7e479637e7c3d6f13c 100644 (file)
@@ -69,6 +69,7 @@ typedef struct mime_node mime_node_t;
 struct notmuch_show_params;
 
 typedef struct notmuch_show_format {
+    struct sprinter *(*new_sprinter) (const void *ctx, FILE *stream);
     const char *message_set_start;
     notmuch_status_t (*part) (const void *ctx,
                              struct mime_node *node, int indent,
index d3419e4e84741cd3b6faaaef0057b1c5618996e9..d04943f7d337fbb688c5790185d2da5627e1b25e 100644 (file)
 
 #include "notmuch-client.h"
 #include "gmime-filter-reply.h"
+#include "sprinter.h"
 
 static notmuch_status_t
 format_part_text (const void *ctx, mime_node_t *node,
                  int indent, const notmuch_show_params_t *params);
 
 static const notmuch_show_format_t format_text = {
+    .new_sprinter = sprinter_text_create,
     .part = format_part_text,
 };
 
@@ -34,6 +36,7 @@ format_part_json_entry (const void *ctx, mime_node_t *node,
                        int indent, const notmuch_show_params_t *params);
 
 static const notmuch_show_format_t format_json = {
+    .new_sprinter = sprinter_json_create,
     .message_set_start = "[",
     .part = format_part_json_entry,
     .message_set_sep = ", ",
@@ -46,6 +49,7 @@ format_part_mbox (const void *ctx, mime_node_t *node,
                  int indent, const notmuch_show_params_t *params);
 
 static const notmuch_show_format_t format_mbox = {
+    .new_sprinter = sprinter_text_create,
     .part = format_part_mbox,
 };
 
@@ -55,6 +59,7 @@ format_part_raw (unused (const void *ctx), mime_node_t *node,
                 unused (const notmuch_show_params_t *params));
 
 static const notmuch_show_format_t format_raw = {
+    .new_sprinter = sprinter_text_create,
     .part = format_part_raw,
 };
 
@@ -1003,6 +1008,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
     char *query_string;
     int opt_index, ret;
     const notmuch_show_format_t *format = &format_text;
+    sprinter_t *sprinter;
     notmuch_show_params_t params = {
        .part = -1,
        .omit_excluded = TRUE,
@@ -1130,6 +1136,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
        return 1;
     }
 
+    /* Create structure printer. */
+    sprinter = format->new_sprinter(ctx, stdout);
+
     /* If a single message is requested we do not use search_excludes. */
     if (params.part >= 0)
        ret = do_show_single (ctx, query, format, &params);