7 /* "Structured printer" interface for unstructured text printing.
8 * Note that --output=summary is dispatched and formatted in
9 * notmuch-search.c, the code in this file is only used for all other
13 struct sprinter_text {
14 struct sprinter vtable;
17 /* The current prefix to be printed with string/integer/boolean
20 const char *current_prefix;
22 /* A flag to indicate if this is the first tag. Used in list of tags
29 text_string_len (struct sprinter *sp, const char *val, size_t len)
31 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
33 if (sptxt->current_prefix != NULL)
34 fprintf (sptxt->stream, "%s:", sptxt->current_prefix);
36 fwrite (val, len, 1, sptxt->stream);
40 text_string (struct sprinter *sp, const char *val)
44 text_string_len (sp, val, strlen (val));
48 text_integer (struct sprinter *sp, int64_t val)
50 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
52 fprintf (sptxt->stream, "%" PRId64, val);
56 text_boolean (struct sprinter *sp, bool val)
58 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
60 fputs (val ? "true" : "false", sptxt->stream);
64 text_separator (struct sprinter *sp)
66 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
68 fputc ('\n', sptxt->stream);
72 text0_separator (struct sprinter *sp)
74 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
76 fputc ('\0', sptxt->stream);
80 text_set_prefix (struct sprinter *sp, const char *prefix)
82 struct sprinter_text *sptxt = (struct sprinter_text *) sp;
84 sptxt->current_prefix = prefix;
87 /* The structure functions begin_map, begin_list, end and map_key
88 * don't do anything in the text formatter.
92 text_begin_map (unused (struct sprinter *sp))
97 text_begin_list (unused (struct sprinter *sp))
102 text_end (unused (struct sprinter *sp))
107 text_null (unused (struct sprinter *sp))
112 text_map_key (unused (struct sprinter *sp), unused (const char *key))
117 sprinter_text_create (notmuch_database_t *db, FILE *stream)
119 static const struct sprinter_text template = {
121 .begin_map = text_begin_map,
122 .begin_list = text_begin_list,
124 .string = text_string,
125 .string_len = text_string_len,
126 .integer = text_integer,
127 .boolean = text_boolean,
129 .map_key = text_map_key,
130 .separator = text_separator,
131 .set_prefix = text_set_prefix,
132 .is_text_printer = true,
135 struct sprinter_text *res;
137 res = talloc (db, struct sprinter_text);
142 res->vtable.notmuch = db;
143 res->stream = stream;
148 sprinter_text0_create (notmuch_database_t *db, FILE *stream)
152 sp = sprinter_text_create (db, stream);
156 sp->separator = text0_separator;