[flashrom] [PATCH 4/7] squash! print_wiki.c fix columns calculations

Stefan Tauner stefan.tauner at student.tuwien.ac.at
Sat Mar 3 21:11:12 CET 2012


- boards

Signed-off-by: Stefan Tauner <stefan.tauner at student.tuwien.ac.at>
---
 print_wiki.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/print_wiki.c b/print_wiki.c
index e0b5ff3..d55563c 100644
--- a/print_wiki.c
+++ b/print_wiki.c
@@ -134,11 +134,12 @@ static void print_supported_chipsets_wiki(int cols)
 static void print_supported_boards_wiki_helper(const char *devicetype, int cols,
 			const struct board_info boards[])
 {
-	int i, j, k = 0, color = 1;
+	int i, k = 0, color = 1;
 	int num_notes = 0;
 	char *notes = calloc(1, 1);
 	const struct board_match *b = board_matches;
 	unsigned int boardcount = 0, boardcount_good = 0, boardcount_bad = 0;
+	unsigned int lines_per_col;
 	char tmp[900 + 1];
 
 	for (i = 0; boards[i].vendor != NULL; i++) {
@@ -149,12 +150,17 @@ static void print_supported_boards_wiki_helper(const char *devicetype, int cols,
 		boardcount++;
 	}
 
+	/* +1 to force the resulting number of columns to be < cols */
+	lines_per_col = boardcount / cols + ((boardcount%cols) > 0 ? 1 : 0);
+
 	printf("\n\nTotal amount of supported %s: '''%d'''. "
 	       "Not yet supported (i.e., known-bad): '''%d'''.\n\n"
-	       "{| border=\"0\" valign=\"top\"\n| valign=\"top\"|\n\n%s",
-	       devicetype, boardcount_good, boardcount_bad, board_th);
+	       "{| border=\"0\" valign=\"top\"\n",
+	       devicetype, boardcount_good, boardcount_bad);
 
-	for (i = 0, j = 0; boards[i].vendor != NULL; i++, j++) {
+	for (i = 0; boards[i].vendor != NULL; i++) {
+		if ((i % lines_per_col) == 0)
+			printf("| valign=\"top\"|\n\n%s", board_th);
 
 		/* Alternate colors if the vendor changes. */
 		if (i > 0 && strcmp(boards[i].vendor, boards[i - 1].vendor))
@@ -190,14 +196,14 @@ static void print_supported_boards_wiki_helper(const char *devicetype, int cols,
 			printf("\n");
 		}
 
-		/* Split table in 'cols' columns. */
-		if (j >= (boardcount / cols + 1)) {
-			printf("\n|}\n\n| valign=\"top\"|\n\n%s", board_th);
-			j = 0;
-		}
+		if (((i % lines_per_col) + 1) == lines_per_col)
+			printf("\n|}\n\n");
 	}
 
-	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|}\n");
 
 	if (num_notes > 0)
 		printf("\n<small>\n%s</small>\n", notes);
-- 
1.7.1





More information about the flashrom mailing list