]> git.notmuchmail.org Git - notmuch/blob - sprinter.h
debian: changelog stanza for 0.23.3-3
[notmuch] / sprinter.h
1 #ifndef NOTMUCH_SPRINTER_H
2 #define NOTMUCH_SPRINTER_H
3
4 /* Necessary for notmuch_bool_t */
5 #include "notmuch-client.h"
6
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).
10  */
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.
15      */
16     void (*begin_map) (struct sprinter *);
17
18     /* Start a new list/array structure.
19      */
20     void (*begin_list) (struct sprinter *);
21
22     /* End the last opened list or map structure.
23      */
24     void (*end) (struct sprinter *);
25
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). For
31      * string (but not string_len) the string pointer passed may be
32      * NULL.
33      */
34     void (*string) (struct sprinter *, const char *);
35     void (*string_len) (struct sprinter *, const char *, size_t);
36     void (*integer) (struct sprinter *, int);
37     void (*boolean) (struct sprinter *, notmuch_bool_t);
38     void (*null) (struct sprinter *);
39
40     /* Print the key of a map's key/value pair. The char * must be UTF-8
41      * encoded.
42      */
43     void (*map_key) (struct sprinter *, const char *);
44
45     /* Insert a separator (usually extra whitespace). For the text
46      * printers, this is a syntactic separator. For the structured
47      * printers, this is for improved readability without affecting
48      * the abstract syntax of the structure being printed. For JSON,
49      * this could simply be a line break.
50      */
51     void (*separator) (struct sprinter *);
52
53     /* Set the current string prefix. This only affects the text
54      * printer, which will print this string, followed by a colon,
55      * before any string. For other printers, this does nothing.
56      */
57     void (*set_prefix) (struct sprinter *, const char *);
58
59     /* True if this is the special-cased plain text printer.
60      */
61     notmuch_bool_t is_text_printer;
62 } sprinter_t;
63
64
65 /* Create a new unstructured printer that emits the default text format
66  * for "notmuch search". */
67 struct sprinter *
68 sprinter_text_create (const void *ctx, FILE *stream);
69
70 /* Create a new unstructured printer that emits the text format for
71  * "notmuch search", with each field separated by a null character
72  * instead of the newline character. */
73 struct sprinter *
74 sprinter_text0_create (const void *ctx, FILE *stream);
75
76 /* Create a new structure printer that emits JSON. */
77 struct sprinter *
78 sprinter_json_create (const void *ctx, FILE *stream);
79
80 /* Create a new structure printer that emits S-Expressions. */
81 struct sprinter *
82 sprinter_sexp_create (const void *ctx, FILE *stream);
83
84 #endif // NOTMUCH_SPRINTER_H