From: "Yuval Mintz" <yuvalmin@broadcom.com>
To: bhutchings@solarflare.com, netdev@vger.kernel.org
Cc: joe@perches.com, eilong@broadcom.com,
"Yuval Mintz" <yuvalmin@broadcom.com>
Subject: [PATCH v2] Ethtool: Beautify private flags print
Date: Sun, 26 May 2013 07:55:55 +0300 [thread overview]
Message-ID: <1369544155-12279-1-git-send-email-yuvalmin@broadcom.com> (raw)
When printing the private flags of the device, align all strings
to have the same length.
Signed-off-by: Yuval Mintz <yuvalmin@broadcom.com>
---
Changes from V1:
- use "%-*s" instead of printing white spaces in for-loop.
---
ethtool.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/ethtool.c b/ethtool.c
index 8cc10b5..57a6e01 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -3445,6 +3445,7 @@ static int do_gprivflags(struct cmd_context *ctx)
struct ethtool_gstrings *strings;
struct ethtool_value flags;
unsigned int i;
+ int max_len = 0, cur_len;
if (ctx->argc != 0)
exit_bad_args();
@@ -3472,9 +3473,18 @@ static int do_gprivflags(struct cmd_context *ctx)
return 1;
}
+ /* Find longest string and align all strings accordingly */
+ for (i = 0; i < strings->len; i++) {
+ cur_len = strlen((const char*)strings->data +
+ i * ETH_GSTRING_LEN);
+ if (cur_len > max_len)
+ max_len = cur_len;
+ }
+
printf("Private flags for %s:\n", ctx->devname);
for (i = 0; i < strings->len; i++)
- printf("%s: %s\n",
+ printf("%-*s: %s\n",
+ max_len,
(const char *)strings->data + i * ETH_GSTRING_LEN,
(flags.data & (1U << i)) ? "on" : "off");
--
1.8.1.227.g44fe835
next reply other threads:[~2013-05-26 4:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-26 4:55 Yuval Mintz [this message]
2013-07-01 15:58 ` [PATCH v2] Ethtool: Beautify private flags print Ben Hutchings
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=1369544155-12279-1-git-send-email-yuvalmin@broadcom.com \
--to=yuvalmin@broadcom.com \
--cc=bhutchings@solarflare.com \
--cc=eilong@broadcom.com \
--cc=joe@perches.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).