All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sidong Yang <realwakka@gmail.com>
To: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Cc: Sidong Yang <realwakka@gmail.com>
Subject: [PATCH v3 1/2] btrfs-progs: common: extend fmt_print_start_group handles unnamed group
Date: Fri, 11 Dec 2020 16:48:11 +0000	[thread overview]
Message-ID: <20201211164812.459012-1-realwakka@gmail.com> (raw)

This patch extends fmt_print_start_group() that 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>
---
v3:
 - extend fmt_print_start_group rather than writing new function
---
 common/format-output.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/common/format-output.c b/common/format-output.c
index 8df93ecb..2f74595c 100644
--- a/common/format-output.c
+++ b/common/format-output.c
@@ -181,17 +181,23 @@ void fmt_end_value(struct format_ctx *fctx, const struct rowspec *row)
 void fmt_print_start_group(struct format_ctx *fctx, const char *name,
 		enum json_type jtype)
 {
+	char bracket;
 	if (bconf.output_format == CMD_FORMAT_JSON) {
 		fmt_separator(fctx);
 		fmt_inc_depth(fctx);
 		fctx->jtype[fctx->depth] = jtype;
 		fctx->memb[fctx->depth] = 0;
 		if (jtype == JSON_TYPE_MAP)
-			printf("\"%s\": {", name);
+			bracket = '{';
 		else if (jtype == JSON_TYPE_ARRAY)
-			printf("\"%s\": [", name);
+			bracket = '[';
 		else
 			fmt_error(fctx);
+
+		if (name)
+			printf("\"%s\": %c", name, bracket);
+		else
+			putchar(bracket);
 	}
 }
 
-- 
2.25.1


             reply	other threads:[~2020-12-11 17:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 16:48 Sidong Yang [this message]
2020-12-11 16:48 ` [PATCH v3 2/2] btrfs-progs: device stats: add json output format Sidong Yang
2020-12-11 17:30   ` David Sterba
2020-12-11 17:46     ` David Sterba
2020-12-11 18:09       ` Sidong Yang
2020-12-16 17:23         ` David Sterba
2020-12-16 17:41           ` David Sterba
2020-12-16  6:30       ` Su Yue
2020-12-16 10:52         ` Sidong Yang
2020-12-16 12:52           ` Su Yue
2020-12-16 17:21             ` David Sterba
2020-12-16 17:18         ` David Sterba
2020-12-11 17:31 ` [PATCH v3 1/2] btrfs-progs: common: extend fmt_print_start_group handles unnamed group David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201211164812.459012-1-realwakka@gmail.com \
    --to=realwakka@gmail.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.