From 7bdbb5bab590c0be795fba46a5e9ed4366fb2d4b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 03 Oct 2021 14:23:42 -0400 Subject: [PATCH] Disallows differing row lengths in table scdoc will now fail if the rows in a table don't all have the same length. A test has also been added to check this behavior, and scdoc(5) has been updated to clarify the behavior. Signed-off-by: Sebastian --- scdoc.5.scd | 3 ++- src/main.c | 9 +++++++-- test/tables | 15 +++++++++++++++ diff --git a/scdoc.5.scd b/scdoc.5.scd index b548b81a4e1f702843d66ae6b3ee5b4cb8dab48b..7c7071b0e3f21824cdf01226f77c87e31f43fec7 100644 --- a/scdoc.5.scd +++ b/scdoc.5.scd @@ -122,7 +122,8 @@ respectively (or space to continue the previous cell on multiple lines), followed by [ or - or ] to align the contents to the left, center, or right, followed by a space and the contents of that cell. You may use a space instead of an alignment specifier to inherit the alignment of the same column in the -previous row. +previous row. Each row must have the same number of columns; empty columns are +permitted. The first character of the first row is not limited to | and has special meaning. [ will produce a table with borders around each cell. | will produce a diff --git a/src/main.c b/src/main.c index f11706ab1f17bcaa0952ea0ef1b56013cebfb774..9660f4710a2c2069a95c9de45afb3c50c22e15d5 100644 --- a/src/main.c +++ b/src/main.c @@ -481,6 +481,7 @@ struct table_row *table = NULL; struct table_row *currow = NULL, *prevrow = NULL; struct table_cell *curcell = NULL; int column = 0; + int numcolumns = -1; uint32_t ch; parser_pushch(p, '|'); @@ -495,12 +496,16 @@ case '|': prevrow = currow; currow = xcalloc(1, sizeof(struct table_row)); if (prevrow) { - // TODO: Verify the number of columns match + if (column != numcolumns && numcolumns != -1) { + parser_fatal(p, "Each row must have the " + "same number of columns"); + } + numcolumns = column; + column = 0; prevrow->next = currow; } curcell = xcalloc(1, sizeof(struct table_cell)); currow->cell = curcell; - column = 0; if (!table) { table = currow; } diff --git a/test/tables b/test/tables index 37ed9ec9d52c2df4f221c20b69fbfaaffed390db..14111fc05fe769d0f809b9f9be554d791729b92c 100755 --- a/test/tables +++ b/test/tables @@ -10,3 +10,18 @@ :- :- EOF end 0 + +begin "Disallows differing row lengths" +scdoc </dev/null +bug-example(1) + +[- +:- +:- +|- +:- +|- +:- +:- +EOF +end 1 -- 2.48.1