From f7533420b4169a963edd4f40b0a649cc92f47bd4 Mon Sep 17 00:00:00 2001 From: Carl-Daniel Hailfinger Date: Sat, 17 Jul 2010 23:21:12 +0000 Subject: Print supported flash chips as narrow as possible Fix a bug where 4 GB of spaces would be printed per line if a vendor name was longer than 10 chars. This patch is needed to commit MoselVitelic chip support. Corresponding to flashrom svn r1090. Signed-off-by: Carl-Daniel Hailfinger Acked-by: Uwe Hermann --- print.c | 61 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/print.c b/print.c index 65ff1e3..cc0ec91 100644 --- a/print.c +++ b/print.c @@ -76,26 +76,33 @@ static int digits(int n) static void print_supported_chips(void) { int okcol = 0, pos = 0, i, chipcount = 0; + int maxchiplen = 0, maxvendorlen = 0; struct flashchip *f; for (f = flashchips; f->name != NULL; f++) { - if (GENERIC_DEVICE_ID == f->model_id) + /* Ignore "unknown XXXX SPI chip" entries. */ + if (!strncmp(f->name, "unknown", 7)) continue; - okcol = max(okcol, strlen(f->vendor) + 1 + strlen(f->name)); - } - okcol = (okcol + 7) & ~7; - - for (f = flashchips; f->name != NULL; f++) chipcount++; - - printf("\nSupported flash chips (total: %d):\n\n", chipcount); - POS_PRINT("Vendor: Device:"); - while (pos < okcol) { - printf("\t"); - pos += 8 - (pos % 8); + maxvendorlen = max(maxvendorlen, strlen(f->vendor)); + maxchiplen = max(maxchiplen, strlen(f->name)); } + maxvendorlen++; + maxchiplen++; + okcol = maxvendorlen + maxchiplen; - printf("Tested OK:\tKnown BAD: Size/KB: Type:\n\n"); + printf("\nSupported flash chips (total: %d):\n\n", chipcount); + printf("Vendor"); + for (i = strlen("Vendor"); i < maxvendorlen; i++) + printf(" "); + printf("Device"); + for (i = strlen("Device"); i < maxchiplen; i++) + printf(" "); + + printf("Tested Known Size/KB: Type:\n"); + for (i = 0; i < okcol; i++) + printf(" "); + printf("OK Broken\n\n"); printf("(P = PROBE, R = READ, E = ERASE, W = WRITE)\n\n"); for (f = flashchips; f->name != NULL; f++) { @@ -104,15 +111,13 @@ static void print_supported_chips(void) continue; printf("%s", f->vendor); - for (i = 0; i < 10 - strlen(f->vendor); i++) + for (i = strlen(f->vendor); i < maxvendorlen; i++) printf(" "); printf("%s", f->name); + for (i = strlen(f->name); i < maxchiplen; i++) + printf(" "); - pos = 10 + strlen(f->name); - while (pos < okcol) { - printf("\t"); - pos += 8 - (pos % 8); - } + pos = maxvendorlen + maxchiplen; if ((f->tested & TEST_OK_MASK)) { if ((f->tested & TEST_OK_PROBE)) POS_PRINT("P "); @@ -124,21 +129,25 @@ static void print_supported_chips(void) POS_PRINT("W "); } while (pos < okcol + 9) { - printf("\t"); - pos += 8 - (pos % 8); + printf(" "); + pos++; } if ((f->tested & TEST_BAD_MASK)) { if ((f->tested & TEST_BAD_PROBE)) - printf("P "); + POS_PRINT("P "); if ((f->tested & TEST_BAD_READ)) - printf("R "); + POS_PRINT("R "); if ((f->tested & TEST_BAD_ERASE)) - printf("E "); + POS_PRINT("E "); if ((f->tested & TEST_BAD_WRITE)) - printf("W "); + POS_PRINT("W "); } - printf("\t %d", f->total_size); + while (pos < okcol + 18) { + printf(" "); + pos++; + } + printf("%d", f->total_size); for (i = 0; i < 10 - digits(f->total_size); i++) printf(" "); printf("%s\n", flashbuses_to_text(f->bustype)); -- cgit v1.1