* [PATCH v2] Ethtool: Beautify private flags print
@ 2013-05-26 4:55 Yuval Mintz
2013-07-01 15:58 ` Ben Hutchings
0 siblings, 1 reply; 2+ messages in thread
From: Yuval Mintz @ 2013-05-26 4:55 UTC (permalink / raw)
To: bhutchings, netdev; +Cc: joe, eilong, Yuval Mintz
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] Ethtool: Beautify private flags print
2013-05-26 4:55 [PATCH v2] Ethtool: Beautify private flags print Yuval Mintz
@ 2013-07-01 15:58 ` Ben Hutchings
0 siblings, 0 replies; 2+ messages in thread
From: Ben Hutchings @ 2013-07-01 15:58 UTC (permalink / raw)
To: Yuval Mintz; +Cc: netdev, joe, eilong
On Sun, 2013-05-26 at 07:55 +0300, Yuval Mintz wrote:
> 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.
Applied; sorry for the delay.
Ben.
> ---
> 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");
>
--
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-07-01 15:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-26 4:55 [PATCH v2] Ethtool: Beautify private flags print Yuval Mintz
2013-07-01 15:58 ` Ben Hutchings
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).