]>
Commit | Line | Data |
---|---|---|
faeb1b64 KZ |
1 | /* |
2 | * No copyright is claimed. This code is in the public domain; do with | |
3 | * it what you wish. | |
4 | */ | |
37bcd056 KZ |
5 | #ifndef UTIL_LINUX_JSONWRT_H |
6 | #define UTIL_LINUX_JSONWRT_H | |
7 | ||
8 | enum { | |
9 | UL_JSON_OBJECT, | |
10 | UL_JSON_ARRAY, | |
11 | UL_JSON_VALUE | |
12 | }; | |
13 | ||
14 | struct ul_jsonwrt { | |
15 | FILE *out; | |
16 | int indent; | |
17 | ||
d124a780 | 18 | unsigned int after_close :1; |
37bcd056 KZ |
19 | }; |
20 | ||
21 | void ul_jsonwrt_init(struct ul_jsonwrt *fmt, FILE *out, int indent); | |
195993d5 | 22 | int ul_jsonwrt_is_ready(struct ul_jsonwrt *fmt); |
37bcd056 KZ |
23 | void ul_jsonwrt_indent(struct ul_jsonwrt *fmt); |
24 | void ul_jsonwrt_open(struct ul_jsonwrt *fmt, const char *name, int type); | |
d124a780 | 25 | void ul_jsonwrt_close(struct ul_jsonwrt *fmt, int type); |
37bcd056 KZ |
26 | |
27 | #define ul_jsonwrt_root_open(_f) ul_jsonwrt_open(_f, NULL, UL_JSON_OBJECT) | |
d124a780 | 28 | #define ul_jsonwrt_root_close(_f) ul_jsonwrt_close(_f, UL_JSON_OBJECT) |
37bcd056 KZ |
29 | |
30 | #define ul_jsonwrt_array_open(_f, _n) ul_jsonwrt_open(_f, _n, UL_JSON_ARRAY) | |
d124a780 | 31 | #define ul_jsonwrt_array_close(_f) ul_jsonwrt_close(_f, UL_JSON_ARRAY) |
37bcd056 KZ |
32 | |
33 | #define ul_jsonwrt_object_open(_f, _n) ul_jsonwrt_open(_f, _n, UL_JSON_OBJECT) | |
d124a780 | 34 | #define ul_jsonwrt_object_close(_f) ul_jsonwrt_close(_f, UL_JSON_OBJECT) |
37bcd056 KZ |
35 | |
36 | #define ul_jsonwrt_value_open(_f, _n) ul_jsonwrt_open(_f, _n, UL_JSON_VALUE) | |
d124a780 | 37 | #define ul_jsonwrt_value_close(_f) ul_jsonwrt_close(_f, UL_JSON_VALUE) |
37bcd056 KZ |
38 | |
39 | ||
40 | void ul_jsonwrt_value_raw(struct ul_jsonwrt *fmt, | |
d124a780 | 41 | const char *name, const char *data); |
37bcd056 | 42 | void ul_jsonwrt_value_s(struct ul_jsonwrt *fmt, |
d124a780 | 43 | const char *name, const char *data); |
37bcd056 | 44 | void ul_jsonwrt_value_u64(struct ul_jsonwrt *fmt, |
d124a780 | 45 | const char *name, uint64_t data); |
37bcd056 | 46 | void ul_jsonwrt_value_boolean(struct ul_jsonwrt *fmt, |
d124a780 | 47 | const char *name, int data); |
f48554d4 TW |
48 | void ul_jsonwrt_value_null(struct ul_jsonwrt *fmt, |
49 | const char *name); | |
37bcd056 KZ |
50 | |
51 | #endif /* UTIL_LINUX_JSONWRT_H */ |