From: Jakub Kicinski <kuba@kernel.org>
To: netdev@vger.kernel.org, idosch@nvidia.com
Cc: mkubecek@suse.cz, Jakub Kicinski <kuba@kernel.org>
Subject: [RFC ethtool 2/6] json: simplify array print API
Date: Fri, 16 Apr 2021 09:02:48 -0700 [thread overview]
Message-ID: <20210416160252.2830567-3-kuba@kernel.org> (raw)
In-Reply-To: <20210416160252.2830567-1-kuba@kernel.org>
In ethtool when we print an array we usually have a label (non-JSON)
and a key (JSON), because arrays are most often printed on a single
line (unlike iproute2 where the output has multiple params
on a line to cater to multi-interface dumps well).
Build this into the json array API.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
json_print.c | 20 ++++++++++----------
json_print.h | 4 ++--
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/json_print.c b/json_print.c
index 56d5b4337e49..4f62767bdbc9 100644
--- a/json_print.c
+++ b/json_print.c
@@ -73,15 +73,15 @@ void close_json_object(void)
/*
* Start json array or string array using
* the provided string as json key (if not null)
- * or as array delimiter in non-json context.
+ * or array delimiter in non-json context.
*/
-void open_json_array(enum output_type type, const char *str)
+void open_json_array(const char *key, const char *str)
{
- if (_IS_JSON_CONTEXT(type)) {
- if (str)
- jsonw_name(_jw, str);
+ if (is_json_context()) {
+ if (key)
+ jsonw_name(_jw, key);
jsonw_start_array(_jw);
- } else if (_IS_FP_CONTEXT(type)) {
+ } else {
printf("%s", str);
}
}
@@ -89,12 +89,12 @@ void open_json_array(enum output_type type, const char *str)
/*
* End json array or string array
*/
-void close_json_array(enum output_type type, const char *str)
+void close_json_array(const char *delim)
{
- if (_IS_JSON_CONTEXT(type))
+ if (is_json_context())
jsonw_end_array(_jw);
- else if (_IS_FP_CONTEXT(type))
- printf("%s", str);
+ else
+ printf("%s", delim);
}
/*
diff --git a/json_print.h b/json_print.h
index cc0c2ea19b59..df15314bafe2 100644
--- a/json_print.h
+++ b/json_print.h
@@ -37,8 +37,8 @@ void fflush_fp(void);
void open_json_object(const char *str);
void close_json_object(void);
-void open_json_array(enum output_type type, const char *delim);
-void close_json_array(enum output_type type, const char *delim);
+void open_json_array(const char *key, const char *str);
+void close_json_array(const char *delim);
void print_nl(void);
--
2.30.2
next prev parent reply other threads:[~2021-04-16 16:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 16:02 [RFC ethtool 0/6] ethtool: add FEC & std stats support Jakub Kicinski
2021-04-16 16:02 ` [RFC ethtool 1/6] update UAPI header copies Jakub Kicinski
2021-04-16 16:02 ` Jakub Kicinski [this message]
2021-04-16 16:02 ` [RFC ethtool 3/6] netlink: add FEC support Jakub Kicinski
2021-04-16 16:02 ` [RFC ethtool 4/6] netlink: fec: support displaying statistics Jakub Kicinski
2021-04-16 16:02 ` [RFC ethtool 5/6] ethtool: add nlchk for redirecting to netlink Jakub Kicinski
2021-04-16 16:02 ` [RFC ethtool 6/6] netlink: add support for standard stats Jakub Kicinski
2021-04-17 18:14 ` Ido Schimmel
2021-04-17 18:47 ` Jakub Kicinski
2021-04-17 19:22 ` Ido Schimmel
2021-04-17 19:44 ` Jakub Kicinski
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=20210416160252.2830567-3-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=idosch@nvidia.com \
--cc=mkubecek@suse.cz \
--cc=netdev@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.