From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: dwagner@suse.de, hare@suse.com, kbusch@kernel.org, hch@lst.de,
gjoyce@linux.ibm.com, wenxiong@linux.ibm.com
Subject: [PATCH 2/7] nvme: use table_get_value_width() in table_print_centered()
Date: Thu, 30 Apr 2026 16:22:23 +0530 [thread overview]
Message-ID: <20260430105234.1172446-3-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260430105234.1172446-1-nilay@linux.ibm.com>
table_print_centered() open-codes the logic to determine the width of a
table value, even though a helper already exists for this purpose.
Replace the open-coded width calculation with a call to
table_get_value_width() to avoid duplication and keep the behavior
consistent across the table helpers.
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
util/table.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/util/table.c b/util/table.c
index cad88d39d..1a69cd39a 100644
--- a/util/table.c
+++ b/util/table.c
@@ -53,28 +53,10 @@ static int table_get_value_width(struct value *v)
static void table_print_centered(struct value *val, int width, enum fmt_type type)
{
int i, len, left_pad, right_pad;
- char buf[64];
- switch (type) {
- case FMT_STRING:
- len = strlen(val->s);
- break;
- case FMT_INT:
- len = snprintf(buf, sizeof(buf), "%d", val->i);
- break;
- case FMT_UNSIGNED:
- len = snprintf(buf, sizeof(buf), "%u", val->u);
- break;
- case FMT_LONG:
- len = snprintf(buf, sizeof(buf), "%ld", val->ld);
- break;
- case FMT_UNSIGNED_LONG:
- len = snprintf(buf, sizeof(buf), "%lu", val->lu);
- break;
- default:
- fprintf(stderr, "Invalid format!\n");
+ len = table_get_value_width(val);
+ if (!len)
return;
- }
left_pad = (width - len) / 2;
right_pad = width - len - left_pad;
@@ -84,7 +66,7 @@ static void table_print_centered(struct value *val, int width, enum fmt_type typ
putchar(' ');
/* print value */
- switch (type) {
+ switch (val->type) {
case FMT_STRING:
printf("%s", val->s);
break;
--
2.53.0
next prev parent reply other threads:[~2026-04-30 10:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 10:52 [PATCH 0/7] nvme-cli: add nvme top command for real-time monitoring Nilay Shroff
2026-04-30 10:52 ` [PATCH 1/7] nvme: add support for unsigned and long types in table_get_value_width() Nilay Shroff
2026-04-30 10:52 ` Nilay Shroff [this message]
2026-04-30 10:52 ` [PATCH 3/7] nvme: add support for float and double types in table_print_XXX() Nilay Shroff
2026-04-30 10:52 ` [PATCH 4/7] nvme: allow table output to be directed to a FILE stream Nilay Shroff
2026-04-30 10:52 ` [PATCH 5/7] nvme: add sigaction for SIGWINCH Nilay Shroff
2026-04-30 10:52 ` [PATCH 6/7] nvme: add generic top-like dashboard framework Nilay Shroff
2026-04-30 10:52 ` [PATCH 7/7] nvme: add nvme top command Nilay Shroff
2026-05-03 17:40 ` [PATCH 0/7] nvme-cli: add nvme top command for real-time monitoring Daniel Wagner
2026-05-07 16:28 ` Daniel Wagner
2026-05-11 5:46 ` Nilay Shroff
2026-05-10 22:34 ` Sagi Grimberg
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=20260430105234.1172446-3-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=dwagner@suse.de \
--cc=gjoyce@linux.ibm.com \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=wenxiong@linux.ibm.com \
/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