From patchwork Sun May 26 04:55:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuval Mintz X-Patchwork-Id: 246368 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AFAAE2C0077 for ; Sun, 26 May 2013 14:56:28 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753312Ab3EZE4W (ORCPT ); Sun, 26 May 2013 00:56:22 -0400 Received: from mms3.broadcom.com ([216.31.210.19]:2227 "EHLO mms3.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751925Ab3EZE4R (ORCPT ); Sun, 26 May 2013 00:56:17 -0400 Received: from [10.9.208.55] by mms3.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.5)); Sat, 25 May 2013 21:47:15 -0700 X-Server-Uuid: B86B6450-0931-4310-942E-F00ED04CA7AF Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS07.corp.ad.broadcom.com (10.9.208.55) with Microsoft SMTP Server (TLS) id 14.1.438.0; Sat, 25 May 2013 21:55:59 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.1.438.0; Sat, 25 May 2013 21:55:59 -0700 Received: from lb-tlvb-yuvalmin.il.broadcom.com ( lb-tlvb-yuvalmin.il.broadcom.com [10.185.6.94]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id DA653F2D72; Sat, 25 May 2013 21:55:57 -0700 (PDT) From: "Yuval Mintz" To: bhutchings@solarflare.com, netdev@vger.kernel.org cc: joe@perches.com, eilong@broadcom.com, "Yuval Mintz" Subject: [PATCH v2] Ethtool: Beautify private flags print Date: Sun, 26 May 2013 07:55:55 +0300 Message-ID: <1369544155-12279-1-git-send-email-yuvalmin@broadcom.com> X-Mailer: git-send-email 1.8.1.227.g44fe835 MIME-Version: 1.0 X-WSS-ID: 7DBF4C592L822937323-01-01 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When printing the private flags of the device, align all strings to have the same length. Signed-off-by: Yuval Mintz --- 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");