1 #ifndef NOTMUCH_SPRINTER_H
2 #define NOTMUCH_SPRINTER_H
4 /* Necessary for notmuch_bool_t */
5 #include "notmuch-client.h"
7 /* Structure printer interface. This is used to create output
8 * structured as maps (with key/value pairs), lists and primitives
9 * (strings, integers and booleans).
11 typedef struct sprinter {
12 /* Start a new map/dictionary structure. This should be followed by
13 * a sequence of alternating calls to map_key and one of the
14 * value-printing functions until the map is ended by end.
16 void (*begin_map) (struct sprinter *);
18 /* Start a new list/array structure.
20 void (*begin_list) (struct sprinter *);
22 /* End the last opened list or map structure.
24 void (*end) (struct sprinter *);
26 /* Print one string/integer/boolean/null element (possibly inside
27 * a list or map, followed or preceded by separators). For string
28 * and string_len, the char * must be UTF-8 encoded. string_len
29 * allows non-terminated strings and strings with embedded NULs
30 * (though the handling of the latter is format-dependent).
32 void (*string) (struct sprinter *, const char *);
33 void (*string_len) (struct sprinter *, const char *, size_t);
34 void (*integer) (struct sprinter *, int);
35 void (*boolean) (struct sprinter *, notmuch_bool_t);
36 void (*null) (struct sprinter *);
38 /* Print the key of a map's key/value pair. The char * must be UTF-8
41 void (*map_key) (struct sprinter *, const char *);
43 /* Insert a separator (usually extra whitespace) for improved
44 * readability without affecting the abstract syntax of the
45 * structure being printed.
46 * For JSON, this could simply be a line break.
48 void (*separator) (struct sprinter *);
50 /* Set the current string prefix. This only affects the text
51 * printer, which will print this string, followed by a colon,
52 * before any string. For other printers, this does nothing.
54 void (*set_prefix) (struct sprinter *, const char *);
56 /* True if this is the special-cased plain text printer.
58 notmuch_bool_t is_text_printer;
62 /* Create a new unstructured printer that emits the default text format
63 * for "notmuch search". */
65 sprinter_text_create (const void *ctx, FILE *stream);
67 /* Create a new structure printer that emits JSON. */
69 sprinter_json_create (const void *ctx, FILE *stream);
71 #endif // NOTMUCH_SPRINTER_H