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 (or a smaller version) is needed to commit MoselVitelic chip support.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-chiplist_narrow/print.c =================================================================== --- flashrom-chiplist_narrow/print.c (Revision 1087) +++ flashrom-chiplist_narrow/print.c (Arbeitskopie) @@ -76,26 +76,33 @@ 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)); + chipcount++; + maxvendorlen = max(maxvendorlen, strlen(f->vendor)); + maxchiplen = max(maxchiplen, strlen(f->name)); } - okcol = (okcol + 7) & ~7; + maxvendorlen++; + maxchiplen++; + okcol = maxvendorlen + maxchiplen;
- 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); - } + printf("Vendor"); + for (i = strlen("Vendor"); i < maxvendorlen; i++) + printf(" "); + printf("Device"); + for (i = strlen("Device"); i < maxchiplen; i++) + printf(" ");
- printf("Tested OK:\tKnown BAD: Size/KB: Type:\n\n"); + 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 @@ 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 @@ 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));
On Sat, Jul 17, 2010 at 05:31:12PM +0200, Carl-Daniel Hailfinger wrote:
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 (or a smaller version) is needed to commit MoselVitelic chip support.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Tested, looks OK.
Acked-by: Uwe Hermann uwe@hermann-uwe.de
The simple fix would have looked somewhat like this:
Index: print.c =================================================================== --- print.c (Revision 1088) +++ print.c (Arbeitskopie) @@ -104,11 +104,11 @@ continue;
printf("%s", f->vendor); - for (i = 0; i < 10 - strlen(f->vendor); i++) + for (i = 0; i < 14 - strlen(f->vendor); i++) printf(" "); printf("%s", f->name);
- pos = 10 + strlen(f->name); + pos = 14 + strlen(f->name); while (pos < okcol) { printf("\t"); pos += 8 - (pos % 8);
But admittedly, your patch is more generic and fixes the problem permanently.
Uwe.
On 17.07.2010 17:31, Carl-Daniel Hailfinger wrote:
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 (or a smaller version) is needed to commit MoselVitelic chip support.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
(for patchwork which bundled the ack with the alternative patch)
Acked-by: Uwe Hermann uwe@hermann-uwe.de
Thanks, committed in r1090.
Regards, Carl-Daniel