All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Sidong Yang <realwakka@gmail.com>
Cc: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: Re: [PATCH v3 1/2] btrfs-progs: common: extend fmt_print_start_group handles unnamed group
Date: Fri, 11 Dec 2020 18:31:23 +0100	[thread overview]
Message-ID: <20201211173123.GP6430@twin.jikos.cz> (raw)
In-Reply-To: <20201211164812.459012-1-realwakka@gmail.com>

On Fri, Dec 11, 2020 at 04:48:11PM +0000, Sidong Yang wrote:
> 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;

This can be simplified a bit, the name can be conditionally printed here

>  		if (jtype == JSON_TYPE_MAP)
> -			printf("\"%s\": {", name);
> +			bracket = '{';

and this just does the right putchar(). With this change now added to
devel, thanks.

>  		else if (jtype == JSON_TYPE_ARRAY)
> -			printf("\"%s\": [", name);
> +			bracket = '[';
>  		else
>  			fmt_error(fctx);
> +
> +		if (name)
> +			printf("\"%s\": %c", name, bracket);
> +		else
> +			putchar(bracket);

      parent reply	other threads:[~2020-12-11 19:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 16:48 [PATCH v3 1/2] btrfs-progs: common: extend fmt_print_start_group handles unnamed group Sidong Yang
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 ` David Sterba [this message]

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=20201211173123.GP6430@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=realwakka@gmail.com \
    /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.