- chips

Signed-off-by: Stefan Tauner <[email protected]>
---
 print_wiki.c |   30 ++++++++++++++++++------------
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/print_wiki.c b/print_wiki.c
index d55563c..43fab47 100644
--- a/print_wiki.c
+++ b/print_wiki.c
@@ -224,6 +224,7 @@ static void print_supported_chips_wiki(int cols)
 {
        int i = 0, c = 1, chipcount = 0;
        const struct flashchip *f, *old = NULL;
+       unsigned int lines_per_col;
        uint32_t t;
        char *s;
        char vmax[6];
@@ -238,21 +239,28 @@ static void print_supported_chips_wiki(int cols)
                chipcount++;
        }
 
+       /* +1 to force the resulting number of columns to be < cols */
+       lines_per_col = chipcount / cols + ((chipcount%cols) > 0 ? 1 : 0);
+
        printf("\n== Supported chips ==\n\nTotal amount of supported "
-              "chips: '''%d'''\n\n{| border=\"0\" valign=\"top\"\n"
-               "| valign=\"top\"|\n\n%s", chipcount, chip_th);
+              "chips: '''%d'''\n\n{| border=\"0\" valign=\"top\"\n",
+              chipcount);
 
-       for (f = flashchips; f->name != NULL; f++, i++) {
+       for (f = flashchips; f->name != NULL; f++) {
                /* Don't print generic entries. */
                if (!strncmp(f->vendor, "Unknown", 7) ||
                    !strncmp(f->vendor, "Programmer", 10) ||
                    !strncmp(f->name, "unknown", 7))
                        continue;
 
+               if ((i % lines_per_col) == 0)
+                       printf("| valign=\"top\"|\n\n%s", chip_th);
+
                /* Alternate colors if the vendor changes. */
                if (old != NULL && strcmp(old->vendor, f->vendor))
                        c = !c;
 
+               old = f;
                t = f->tested;
                s = flashbuses_to_text(f->bustype);
                sprintf(vmin, "%0.03f", f->voltage.min / (double)1000);
@@ -276,16 +284,14 @@ static void print_supported_chips_wiki(int cols)
                       f->voltage.min ? vmax : "N/A");
                free(s);
 
-               /* Split table into 'cols' columns. */
-               if (i >= (chipcount / cols + 1)) {
-                       printf("\n|}\n\n| valign=\"top\"|\n\n%s", chip_th);
-                       i = 0;
-               }
-
-               old = f;
+               if (((i % lines_per_col) + 1) == lines_per_col)
+                       printf("\n|}\n\n");
+               i++;
        }
-
-       printf("\n|}\n\n|}\n");
+       /* end inner table if it did not fill the last column fully */
+       if (((i % lines_per_col)) > 0)
+               printf("\n|}\n\n");
+       printf("|}\n\n");
 }
 
 /* Not needed for CONFIG_INTERNAL, but for all other PCI-based programmers. */
-- 
1.7.1


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

Reply via email to