1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 02:21:44 +03:00

json: introduce explicit type for json formatting flags

This commit is contained in:
Lennart Poettering 2018-12-03 20:27:55 +01:00
parent 63e688cc3b
commit 897f099bb0
2 changed files with 8 additions and 8 deletions

View File

@ -1236,7 +1236,7 @@ int json_variant_get_source(JsonVariant *v, const char **ret_source, unsigned *r
return 0;
}
static int print_source(FILE *f, JsonVariant *v, unsigned flags, bool whitespace) {
static int print_source(FILE *f, JsonVariant *v, JsonFormatFlags flags, bool whitespace) {
size_t w, k;
if (!FLAGS_SET(flags, JSON_FORMAT_SOURCE|JSON_FORMAT_PRETTY))
@ -1289,7 +1289,7 @@ static int print_source(FILE *f, JsonVariant *v, unsigned flags, bool whitespace
return 0;
}
static int json_format(FILE *f, JsonVariant *v, unsigned flags, const char *prefix) {
static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const char *prefix) {
int r;
assert(f);
@ -1546,7 +1546,7 @@ static int json_format(FILE *f, JsonVariant *v, unsigned flags, const char *pref
return 0;
}
int json_variant_format(JsonVariant *v, unsigned flags, char **ret) {
int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret) {
_cleanup_free_ char *s = NULL;
size_t sz = 0;
int r;
@ -1576,7 +1576,7 @@ int json_variant_format(JsonVariant *v, unsigned flags, char **ret) {
return (int) sz;
}
void json_variant_dump(JsonVariant *v, unsigned flags, FILE *f, const char *prefix) {
void json_variant_dump(JsonVariant *v, JsonFormatFlags flags, FILE *f, const char *prefix) {
if (!v)
return;

View File

@ -150,17 +150,17 @@ struct json_variant_foreach_state {
int json_variant_get_source(JsonVariant *v, const char **ret_source, unsigned *ret_line, unsigned *ret_column);
enum {
typedef enum JsonFormatFlags {
JSON_FORMAT_NEWLINE = 1 << 0, /* suffix with newline */
JSON_FORMAT_PRETTY = 1 << 1, /* add internal whitespace to appeal to human readers */
JSON_FORMAT_COLOR = 1 << 2, /* insert ANSI color sequences */
JSON_FORMAT_SOURCE = 1 << 3, /* prefix with source filename/line/column */
JSON_FORMAT_SSE = 1 << 4, /* prefix/suffix with W3C server-sent events */
JSON_FORMAT_SEQ = 1 << 5, /* prefix/suffix with RFC 7464 application/json-seq */
};
} JsonFormatFlags;
int json_variant_format(JsonVariant *v, unsigned flags, char **ret);
void json_variant_dump(JsonVariant *v, unsigned flags, FILE *f, const char *prefix);
int json_variant_format(JsonVariant *v, JsonFormatFlags flags, char **ret);
void json_variant_dump(JsonVariant *v, JsonFormatFlags flags, FILE *f, const char *prefix);
int json_parse(const char *string, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column);
int json_parse_continue(const char **p, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column);