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 text0_separator (struct sprinter *sp)
73 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
75 fputc ('\0', sptxt->stream);
79 text_set_prefix (struct sprinter *sp, const char *prefix)
81 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
83 sptxt->current_prefix = prefix;
86 /* The structure functions begin_map, begin_list, end and map_key
87 * don't do anything in the text formatter.
91 text_begin_map (unused (struct sprinter *sp))
96 text_begin_list (unused (struct sprinter *sp))
101 text_end (unused (struct sprinter *sp))
106 text_null (unused (struct sprinter *sp))
111 text_map_key (unused (struct sprinter *sp), unused (const char *key))
116 sprinter_text_create (const void *ctx, FILE *stream)
118 static const struct sprinter_text template = {
120 .begin_map = text_begin_map,
121 .begin_list = text_begin_list,
123 .string = text_string,
124 .string_len = text_string_len,
125 .integer = text_integer,
126 .boolean = text_boolean,
128 .map_key = text_map_key,
129 .separator = text_separator,
130 .set_prefix = text_set_prefix,
131 .is_text_printer = TRUE,
134 struct sprinter_text *res;
136 res = talloc (ctx, struct sprinter_text);
141 res->stream = stream;
146 sprinter_text0_create (const void *ctx, FILE *stream)
150 sp = sprinter_text_create (ctx, stream);
154 sp->separator = text0_separator;