From: "Yuval Mintz" <yuvalmin@broadcom.com>
To: bhutchings@solarflare.com, netdev@vger.kernel.org
Cc: eilong@broadcom.com, "Yuval Mintz" <yuvalmin@broadcom.com>
Subject: [PATCH] Ethtool: Beautify private flags print
Date: Thu, 23 May 2013 20:55:51 +0300 [thread overview]
Message-ID: <1369331751-32543-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>
---
ethtool.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/ethtool.c b/ethtool.c
index 8cc10b5..1244c74 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,11 +3473,28 @@ 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",
- (const char *)strings->data + i * ETH_GSTRING_LEN,
- (flags.data & (1U << i)) ? "on" : "off");
+ for (i = 0; i < strings->len; i++) {
+ int j;
+
+ printf("%s", (const char *)strings->data +
+ i * ETH_GSTRING_LEN);
+
+ cur_len = strlen((const char*)strings->data +
+ i * ETH_GSTRING_LEN);
+ for (j = 0; j < max_len - cur_len; j++)
+ printf(" ");
+
+ printf(": %s\n", (flags.data & (1U << i)) ? "on" : "off");
+ }
return 0;
}
--
1.8.1.227.g44fe835
next reply other threads:[~2013-05-23 17:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-23 17:55 Yuval Mintz [this message]
2013-05-23 18:30 ` [PATCH] Ethtool: Beautify private flags print Joe Perches
2013-05-24 3:50 ` Yuval Mintz
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=1369331751-32543-1-git-send-email-yuvalmin@broadcom.com \
--to=yuvalmin@broadcom.com \
--cc=bhutchings@solarflare.com \
--cc=eilong@broadcom.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