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)
43 text_string_len (sp, val, strlen (val));
47 text_integer (struct sprinter *sp, int val)
49 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
51 fprintf (sptxt->stream, "%d", val);
55 text_boolean (struct sprinter *sp, notmuch_bool_t val)
57 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
59 fputs (val ? "true" : "false", sptxt->stream);
63 text_separator (struct sprinter *sp)
65 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
67 fputc ('\n', sptxt->stream);
71 text_set_prefix (struct sprinter *sp, const char *prefix)
73 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
75 sptxt->current_prefix = prefix;
78 /* The structure functions begin_map, begin_list, end and map_key
79 * don't do anything in the text formatter.
83 text_begin_map (unused (struct sprinter *sp))
88 text_begin_list (unused (struct sprinter *sp))
93 text_end (unused (struct sprinter *sp))
98 text_null (unused (struct sprinter *sp))
103 text_map_key (unused (struct sprinter *sp), unused (const char *key))
108 sprinter_text_create (const void *ctx, FILE *stream)
110 static const struct sprinter_text template = {
112 .begin_map = text_begin_map,
113 .begin_list = text_begin_list,
115 .string = text_string,
116 .string_len = text_string_len,
117 .integer = text_integer,
118 .boolean = text_boolean,
120 .map_key = text_map_key,
121 .separator = text_separator,
122 .set_prefix = text_set_prefix,
123 .is_text_printer = TRUE,
126 struct sprinter_text *res;
128 res = talloc (ctx, struct sprinter_text);
133 res->stream = stream;