Author: stefanct
Date: Sun Jun  1 04:13:23 2014
New Revision: 1807
URL: http://flashrom.org/trac/flashrom/changeset/1807

Log:
print.c: improve device printing.

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 <[email protected]>
Acked-by: Carl-Daniel Hailfinger <[email protected]>

Modified:
   trunk/print.c

Modified: trunk/print.c
==============================================================================
--- trunk/print.c       Fri May 30 21:34:00 2014        (r1806)
+++ trunk/print.c       Sun Jun  1 04:13:23 2014        (r1807)
@@ -47,6 +47,18 @@
 }
 #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 @@
 
 void print_supported_devs(const struct programmer_entry prog, const char 
*const type)
 {
-       int i;
-
        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;
+
+       unsigned int i;
+       for (i = 0; devs[i].vendor_name != NULL; i++) {
+               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_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)" : "");
+               msg_ginfo("%s", devs[i].vendor_name);
+               unsigned int j;
+               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));
        }
 }
 

_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to