mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] cosmetic: improve drivers list display
@ 2012-10-11 20:57 Franck Jullien
  2012-10-12  8:12 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Franck Jullien @ 2012-10-11 20:57 UTC (permalink / raw)
  To: barebox

When the drivers list is printed with devinfo one can have some
unaligned strings because of the arbitrary %10s alignment in the printf.

This adds a first step finding the longest driver name, then the printf
alignment is matched to this value.

Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
---
 drivers/base/driver.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 5b7286a..9dd479e 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -397,6 +397,7 @@ static int do_devinfo(int argc, char *argv[])
 	struct param_d *param;
 	int i;
 	struct resource *res;
+	int max_length = 0;
 
 	if (argc == 1) {
 		printf("devices:\n");
@@ -408,7 +409,12 @@ static int do_devinfo(int argc, char *argv[])
 
 		printf("\ndrivers:\n");
 		for_each_driver(drv)
-			printf("%10s\n",drv->name);
+			if (strlen(drv->name) > max_length)
+				max_length = strlen(drv->name);
+
+		for_each_driver(drv)
+			printf("%*s\n", max_length, drv->name);
+
 	} else {
 		dev = get_device_by_name(argv[1]);
 
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-10-12  8:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-11 20:57 [PATCH] cosmetic: improve drivers list display Franck Jullien
2012-10-12  8:12 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox