btrfs-progs: extend fmt_print_start_group to handle unnamed group

Extends fmt_print_start_group() so it can handle when name argument is
NULL. It is useful for printing unnamed array or map.

Signed-off-by: Sidong Yang <realwakka@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Sidong Yang 2020-12-11 16:48:11 +00:00 committed by David Sterba
parent 0c6e59e0b2
commit 2e8906829a

View File

@ -186,10 +186,12 @@ void fmt_print_start_group(struct format_ctx *fctx, const char *name,
fmt_inc_depth(fctx);
fctx->jtype[fctx->depth] = jtype;
fctx->memb[fctx->depth] = 0;
if (name)
printf("\"%s\": ", name);
if (jtype == JSON_TYPE_MAP)
printf("\"%s\": {", name);
putchar('{');
else if (jtype == JSON_TYPE_ARRAY)
printf("\"%s\": [", name);
putchar('[');
else
fmt_error(fctx);
}