David Hendricks has uploaded this change for review.
print.c: Fix alignment in print_supported_boards_helper()
Commit 61e16e5 eliminated some duplicate logic for printing test status,
but in doing so introduced a regression where some entries in `flashrom
-L` output became unaligned.
Up until then, it was assumed that the status field will always be
8-wide, including space for padding. This patch fixes alignment when
using test_state_to_text() by making the padding consistent with other
fields where a for-loop is used to pad the field up to a maximum width.
Change-Id: Ie0a0b45c6466d14447aca443c2697e2048c6ef14
Signed-off-by: David Hendricks <david.hendricks@gmail.com>
---
M flash.h
M print.c
2 files changed, 29 insertions(+), 14 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/07/37407/1
diff --git a/flash.h b/flash.h
index 1a9bd9f..e7b1c89 100644
--- a/flash.h
+++ b/flash.h
@@ -145,10 +145,11 @@
enum test_state {
OK = 0,
- NT = 1, /* Not tested */
- BAD, /* Known to not work */
- DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */
- NA, /* Not applicable (e.g. write support on ROM chips) */
+ NT = 1, /* Not tested */
+ BAD, /* Known to not work */
+ DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */
+ NA, /* Not applicable (e.g. write support on ROM chips) */
+ TEST_STATE_END, /* Not a test state, just an indicator of how many are defined. */
};
#define TEST_UNTESTED (struct tested){ .probe = NT, .read = NT, .erase = NT, .write = NT }
diff --git a/print.c b/print.c
index 6a7ff5d..e5be6b6 100644
--- a/print.c
+++ b/print.c
@@ -35,6 +35,20 @@
}
}
+static size_t max_test_state_len(void)
+{
+ int i;
+ size_t max_len;
+
+ for (i = max_len = 0; i < TEST_STATE_END; i++) {
+ size_t len = strlen(test_state_to_text(i));
+ if (len > max_len)
+ max_len = len;
+ }
+
+ return max_len;
+}
+
static int print_supported_chips(void)
{
const char *delim = "/";
@@ -388,8 +402,12 @@
for (i = strlen("Board"); i < maxboardlen; i++)
msg_ginfo(" ");
- msg_ginfo("Status Required value for\n");
- for (i = 0; i < maxvendorlen + maxboardlen + strlen("Status "); i++)
+ msg_ginfo("Status");
+ for (i = strlen("Status"); i < max_test_state_len(); i++)
+ msg_ginfo(" ");
+
+ msg_ginfo("Required value for\n");
+ for (i = 0; i < maxvendorlen + maxboardlen + max_test_state_len(); i++)
msg_ginfo(" ");
msg_ginfo("-p internal:mainboard=\n");
@@ -401,14 +419,10 @@
for (i = 0; i < maxboardlen - strlen(b->name); i++)
msg_ginfo(" ");
- switch (b->working) {
- case OK: msg_ginfo("OK "); break;
- case NT: msg_ginfo("NT "); break;
- case DEP: msg_ginfo("DEP "); break;
- case NA: msg_ginfo("N/A "); break;
- case BAD:
- default: msg_ginfo("BAD "); break;
- }
+ const char *test_state = test_state_to_text(b->working);
+ msg_ginfo("%s", test_state);
+ for (i = 0; i < max_test_state_len() - strlen(test_state); i++)
+ msg_ginfo(" ");
for (e = board_matches; e->vendor_name != NULL; e++) {
if (strcmp(e->vendor_name, b->vendor)
To view, visit change 37407. To unsubscribe, or for help writing mail filters, visit settings.