[flashrom] [PATCH 1/2] print.c: improve device printing.

Stefan Tauner stefan.tauner at alumni.tuwien.ac.at
Fri May 30 05:15:44 CEST 2014


Add headers and columns (i.e. print device entries in a table-like manner).
Also, add and use test_state_to_text() to support the new test states.

Signed-off-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>
---
 print.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/print.c b/print.c
index 8ca99d5..7bb788e 100644
--- a/print.c
+++ b/print.c
@@ -47,6 +47,18 @@ static char* strtok_r(char *str, const char *delim, char **nextp)
 }
 #endif
 
+static const char *test_state_to_text(enum test_state test_state)
+{
+	switch (test_state) {
+	case OK: return "OK";
+	case BAD: return "Not working";
+	case NA: return "N/A";
+	case DEP: return "Config-dependent";
+	case NT:
+	default: return "Untested";
+	}
+}
+
 /*
  * Return a string corresponding to the bustype parameter.
  * Memory is obtained with malloc() and must be freed with free() by the caller.
@@ -469,13 +481,40 @@ static void print_supported_boards_helper(const struct board_info *boards,
 
 void print_supported_devs(const struct programmer_entry prog, const char *const type)
 {
-	int i;
+	unsigned int i, j;
 
 	const struct dev_entry *const devs = prog.devs.dev;
 	msg_ginfo("\nSupported %s devices for the %s programmer:\n", type, prog.name);
+	unsigned int maxvendorlen = strlen("Vendor") + 1;
+	unsigned int maxdevlen = strlen("Device") + 1;
+
 	for (i = 0; devs[i].vendor_name != NULL; i++) {
-		msg_pinfo("%s %s [%04x:%04x]%s\n", devs[i].vendor_name, devs[i].device_name, devs[i].vendor_id,
-			  devs[i].device_id, (devs[i].status == NT) ? " (untested)" : "");
+		maxvendorlen = max(maxvendorlen, strlen(devs[i].vendor_name));
+		maxdevlen = max(maxdevlen, strlen(devs[i].device_name));
+	}
+	maxvendorlen++;
+	maxdevlen++;
+
+	msg_ginfo("Vendor");
+	for (i = strlen("Vendor"); i < maxvendorlen; i++)
+		msg_ginfo(" ");
+
+	msg_ginfo("Device");
+	for (i = strlen("Device"); i < maxdevlen; i++)
+		msg_ginfo(" ");
+
+	msg_ginfo(" %s IDs    Status\n", type);
+
+	for (i = 0; devs[i].vendor_name != NULL; i++) {
+		msg_ginfo("%s", devs[i].vendor_name);
+		for (j = strlen(devs[i].vendor_name); j < maxvendorlen; j++)
+			msg_ginfo(" ");
+		msg_ginfo("%s", devs[i].device_name);
+		for (j = strlen(devs[i].device_name); j < maxdevlen; j++)
+			msg_ginfo(" ");
+
+		msg_pinfo(" %04x:%04x  %s\n", devs[i].vendor_id, devs[i].device_id,
+			  test_state_to_text(devs[i].status));
 	}
 }
 
-- 
Kind regards, Stefan Tauner





More information about the flashrom mailing list