diff options
-rw-r--r-- | regress/usr.bin/mandoc/tbl/layout/Makefile | 12 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/tbl/layout/empty.in | 15 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/tbl/layout/empty.out_ascii | 19 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/tbl/layout/empty.out_lint | 2 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/tbl/layout/emptyline.in | 24 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/tbl/layout/emptyline.out_ascii | 24 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_layout.c | 42 |
7 files changed, 124 insertions, 14 deletions
diff --git a/regress/usr.bin/mandoc/tbl/layout/Makefile b/regress/usr.bin/mandoc/tbl/layout/Makefile index 69d5444872d..9ad5d7f93b6 100644 --- a/regress/usr.bin/mandoc/tbl/layout/Makefile +++ b/regress/usr.bin/mandoc/tbl/layout/Makefile @@ -1,6 +1,12 @@ -# $OpenBSD: Makefile,v 1.1.1.1 2015/01/29 23:24:24 schwarze Exp $ +# $OpenBSD: Makefile,v 1.2 2015/01/30 00:27:09 schwarze Exp $ -REGRESS_TARGETS = center complex numbers span -LINT_TARGETS = complex +REGRESS_TARGETS = center complex empty emptyline numbers span +LINT_TARGETS = complex empty + +# groff-1.22.3 defect: +# - When the layout is completely empty, +# GNU eqn produces no output whatsoever for the whole table. + +SKIP_GROFF = empty .include <bsd.regress.mk> diff --git a/regress/usr.bin/mandoc/tbl/layout/empty.in b/regress/usr.bin/mandoc/tbl/layout/empty.in new file mode 100644 index 00000000000..3afff9557a9 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/layout/empty.in @@ -0,0 +1,15 @@ +.TH TBL-LAYOUT-EMPTY 1 "January 29, 2015" OpenBSD +.SH NAME +tbl-layout-empty \- empty table layout +.SH DESCRIPTION +completely empty layout: +.TS +. +table text +.TE +layout only contains a bar: +.TS +|. +table text +.TE +normal text diff --git a/regress/usr.bin/mandoc/tbl/layout/empty.out_ascii b/regress/usr.bin/mandoc/tbl/layout/empty.out_ascii new file mode 100644 index 00000000000..96d224fa391 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/layout/empty.out_ascii @@ -0,0 +1,19 @@ +TBL-LAYOUT-EMPTY(1) General Commands Manual TBL-LAYOUT-EMPTY(1) + + + +NNAAMMEE + tbl-layout-empty - empty table layout + +DDEESSCCRRIIPPTTIIOONN + completely empty layout: + + table text + layout only contains a bar: + + |table text + normal text + + + +OpenBSD January 29, 2015 TBL-LAYOUT-EMPTY(1) diff --git a/regress/usr.bin/mandoc/tbl/layout/empty.out_lint b/regress/usr.bin/mandoc/tbl/layout/empty.out_lint new file mode 100644 index 00000000000..20ae24a5530 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/layout/empty.out_lint @@ -0,0 +1,2 @@ +mandoc: empty.in:7:2: ERROR: empty tbl layout +mandoc: empty.in:12:3: ERROR: empty tbl layout diff --git a/regress/usr.bin/mandoc/tbl/layout/emptyline.in b/regress/usr.bin/mandoc/tbl/layout/emptyline.in new file mode 100644 index 00000000000..647b70dbefe --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/layout/emptyline.in @@ -0,0 +1,24 @@ +.TH TBL-LAYOUT-EMPTYLINE 1 "January 29, 2015" OpenBSD +.SH NAME +tbl-layout-emptyline \- empty lines in table layouts +.SH DESCRIPTION +An empty line in the middle of a table joins with the next: +.TS +l +| +r. +table text +_ +bar +right +.TE +.PP +An empty line at the end of a table is discarded: +.TS +l +r +|. +table text +right +.TE +normal text diff --git a/regress/usr.bin/mandoc/tbl/layout/emptyline.out_ascii b/regress/usr.bin/mandoc/tbl/layout/emptyline.out_ascii new file mode 100644 index 00000000000..230cc597a33 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/layout/emptyline.out_ascii @@ -0,0 +1,24 @@ +TBL-LAYOUT-EMPTYLINE(1) General Commands Manual TBL-LAYOUT-EMPTYLINE(1) + + + +NNAAMMEE + tbl-layout-emptyline - empty lines in table layouts + +DDEESSCCRRIIPPTTIIOONN + An empty line in the middle of a table joins with the next: + + table text + +----------- + | bar + | right + + An empty line at the end of a table is discarded: + + table text + right + normal text + + + +OpenBSD January 29, 2015 TBL-LAYOUT-EMPTYLINE(1) diff --git a/usr.bin/mandoc/tbl_layout.c b/usr.bin/mandoc/tbl_layout.c index 407f77199af..250c00d00c4 100644 --- a/usr.bin/mandoc/tbl_layout.c +++ b/usr.bin/mandoc/tbl_layout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_layout.c,v 1.21 2015/01/28 15:02:25 schwarze Exp $ */ +/* $OpenBSD: tbl_layout.c,v 1.22 2015/01/30 00:27:09 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -260,11 +260,14 @@ tbl_layout(struct tbl_node *tbl, int ln, const char *p, int pos) */ if (tbl->first_row == NULL) { + tbl->first_row = tbl->last_row = + mandoc_calloc(1, sizeof(*rp)); + } + if (tbl->first_row->first == NULL) { mandoc_msg(MANDOCERR_TBLLAYOUT_NONE, tbl->parse, ln, pos, NULL); - rp = mandoc_calloc(1, sizeof(*rp)); - cell_alloc(tbl, rp, TBL_CELL_LEFT); - tbl->first_row = tbl->last_row = rp; + cell_alloc(tbl, tbl->first_row, + TBL_CELL_LEFT); return; } @@ -280,19 +283,36 @@ tbl_layout(struct tbl_node *tbl, int ln, const char *p, int pos) rp->last->head == tbl->last_head && tbl->opts.rvert < rp->last->vert) tbl->opts.rvert = rp->last->vert; + + /* If the last line is empty, drop it. */ + + if (rp->next != NULL && + rp->next->first == NULL) { + free(rp->next); + rp->next = NULL; + } } return; default: /* Cell. */ break; } - if (rp == NULL) { /* First cell on this line. */ - rp = mandoc_calloc(1, sizeof(*rp)); - if (tbl->last_row) - tbl->last_row->next = rp; - else - tbl->first_row = rp; - tbl->last_row = rp; + /* + * If the last line had at least one cell, + * start a new one; otherwise, continue it. + */ + + if (rp == NULL) { + if (tbl->last_row == NULL || + tbl->last_row->first != NULL) { + rp = mandoc_calloc(1, sizeof(*rp)); + if (tbl->last_row) + tbl->last_row->next = rp; + else + tbl->first_row = rp; + tbl->last_row = rp; + } else + rp = tbl->last_row; } cell(tbl, rp, ln, p, &pos); } |