6 /* "Structured printer" interface for unstructured text printing.
7 * Note that --output=summary is dispatched and formatted in
8 * notmuch-search.c, the code in this file is only used for all other
12 struct sprinter_text {
13 struct sprinter vtable;
16 /* The current prefix to be printed with string/integer/boolean
19 const char *current_prefix;
21 /* A flag to indicate if this is the first tag. Used in list of tags
24 notmuch_bool_t first_tag;
28 text_string (struct sprinter *sp, const char *val)
30 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
32 if (sptxt->current_prefix != NULL)
33 fprintf (sptxt->stream, "%s:", sptxt->current_prefix);
35 fputs(val, sptxt->stream);
39 text_integer (struct sprinter *sp, int val)
41 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
43 fprintf (sptxt->stream, "%d", val);
47 text_boolean (struct sprinter *sp, notmuch_bool_t val)
49 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
51 fputs (val ? "true" : "false", sptxt->stream);
55 text_separator (struct sprinter *sp)
57 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
59 fputc ('\n', sptxt->stream);
63 text_set_prefix (struct sprinter *sp, const char *prefix)
65 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
67 sptxt->current_prefix = prefix;
70 /* The structure functions begin_map, begin_list, end and map_key
71 * don't do anything in the text formatter.
75 text_begin_map (unused (struct sprinter *sp))
80 text_begin_list (unused (struct sprinter *sp))
85 text_end (unused (struct sprinter *sp))
90 text_null (unused (struct sprinter *sp))
95 text_map_key (unused (struct sprinter *sp), unused (const char *key))
100 sprinter_text_create (const void *ctx, FILE *stream)
102 static const struct sprinter_text template = {
104 .begin_map = text_begin_map,
105 .begin_list = text_begin_list,
107 .string = text_string,
108 .integer = text_integer,
109 .boolean = text_boolean,
111 .map_key = text_map_key,
112 .separator = text_separator,
113 .set_prefix = text_set_prefix,
114 .is_text_printer = TRUE,
117 struct sprinter_text *res;
119 res = talloc (ctx, struct sprinter_text);
124 res->stream = stream;