From 2e8906829ac2751dffdafc995a4e3aab45cb4fd4 Mon Sep 17 00:00:00 2001 From: Sidong Yang Date: Fri, 11 Dec 2020 16:48:11 +0000 Subject: [PATCH] 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 Signed-off-by: David Sterba --- common/format-output.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/format-output.c b/common/format-output.c index 8df93ecb..ac68a7fa 100644 --- a/common/format-output.c +++ b/common/format-output.c @@ -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); }