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_len (struct sprinter *sp, const char *val, size_t len)
30 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
32 if (sptxt->current_prefix != NULL)
33 fprintf (sptxt->stream, "%s:", sptxt->current_prefix);
35 fwrite (val, len, 1, sptxt->stream);
39 text_string (struct sprinter *sp, const char *val)
41 text_string_len (sp, val, strlen (val));
45 text_integer (struct sprinter *sp, int val)
47 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
49 fprintf (sptxt->stream, "%d", val);
53 text_boolean (struct sprinter *sp, notmuch_bool_t val)
55 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
57 fputs (val ? "true" : "false", sptxt->stream);
61 text_separator (struct sprinter *sp)
63 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
65 fputc ('\n', sptxt->stream);
69 text_set_prefix (struct sprinter *sp, const char *prefix)
71 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
73 sptxt->current_prefix = prefix;
76 /* The structure functions begin_map, begin_list, end and map_key
77 * don't do anything in the text formatter.
81 text_begin_map (unused (struct sprinter *sp))
86 text_begin_list (unused (struct sprinter *sp))
91 text_end (unused (struct sprinter *sp))
96 text_null (unused (struct sprinter *sp))
101 text_map_key (unused (struct sprinter *sp), unused (const char *key))
106 sprinter_text_create (const void *ctx, FILE *stream)
108 static const struct sprinter_text template = {
110 .begin_map = text_begin_map,
111 .begin_list = text_begin_list,
113 .string = text_string,
114 .string_len = text_string_len,
115 .integer = text_integer,
116 .boolean = text_boolean,
118 .map_key = text_map_key,
119 .separator = text_separator,
120 .set_prefix = text_set_prefix,
121 .is_text_printer = TRUE,
124 struct sprinter_text *res;
126 res = talloc (ctx, struct sprinter_text);
131 res->stream = stream;