From 0f85db22b3f2c60809983e5495443feb430f3a3e Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Fri, 28 Mar 2014 23:25:55 +0000 Subject: Allow leading and trailing vertical lines, and format them in the same way as groff. While here, do not require whitespace before vertical lines in layout specifications. Issues found by bentley@ in mpv(1). --- regress/usr.bin/mandoc/tbl/Makefile | 6 ++--- regress/usr.bin/mandoc/tbl/vert.in | 39 +++++++++++++++++++++++++++++++ regress/usr.bin/mandoc/tbl/vert.out_ascii | 37 +++++++++++++++++++++++++++++ usr.bin/mandoc/mandoc.h | 3 ++- usr.bin/mandoc/tbl_layout.c | 13 +++++++++-- usr.bin/mandoc/tbl_term.c | 10 ++++---- 6 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 regress/usr.bin/mandoc/tbl/vert.in create mode 100644 regress/usr.bin/mandoc/tbl/vert.out_ascii diff --git a/regress/usr.bin/mandoc/tbl/Makefile b/regress/usr.bin/mandoc/tbl/Makefile index 8e0a5eb7678..25c061d66f7 100644 --- a/regress/usr.bin/mandoc/tbl/Makefile +++ b/regress/usr.bin/mandoc/tbl/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.1 2012/05/27 02:01:38 schwarze Exp $ +# $OpenBSD: Makefile,v 1.2 2014/03/28 23:25:54 schwarze Exp $ -REGRESS_TARGETS=center numbers span +REGRESS_TARGETS = center numbers span vert SKIP_TMAN ?= ALL -TBL=/usr/local/bin/tbl +TBL = /usr/local/bin/tbl .for t in ${REGRESS_TARGETS} ${t}.out_ascii: ${t}.in diff --git a/regress/usr.bin/mandoc/tbl/vert.in b/regress/usr.bin/mandoc/tbl/vert.in new file mode 100644 index 00000000000..c892401c88e --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/vert.in @@ -0,0 +1,39 @@ +.TH TBL-VERT 1 +.SH NAME +tbl-vert \- vertical lines +.SH DESCRIPTION +no boxing: +.TS +tab(:); +l l. +a:b +c:d +.TE +.sp +automatic boxing: +.TS +tab(:) box; +l l. +a:b +c:d +.TE +.sp +manual boxing: +.TS +tab(:); +||l||l||. +_ +a:b +_ +c:d +_ +.TE +.sp +automatic and manual boxing: +.TS +tab(:) box; +||l||l||. +a:b +_ +c:d +.TE diff --git a/regress/usr.bin/mandoc/tbl/vert.out_ascii b/regress/usr.bin/mandoc/tbl/vert.out_ascii new file mode 100644 index 00000000000..c8c630c083d --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/vert.out_ascii @@ -0,0 +1,37 @@ +TBL-VERT(1) OpenBSD Reference Manual TBL-VERT(1) + + + +NNAAMMEE + tbl-vert - vertical lines + +DDEESSCCRRIIPPTTIIOONN + no boxing: + + a b + c d + + automatic boxing: + + +------+ + |a b | + |c d | + +------+ + manual boxing: + + +--++--+ + |a ||b | + +--++--+ + |c ||d | + +--++--+ + + automatic and manual boxing: + + +--++--+ + |a ||b | + +--++--+ + |c ||d | + +--++--+ + + + TBL-VERT(1) diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 2ec65964e1a..d9b32241f2b 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.62 2014/03/21 22:17:01 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.63 2014/03/28 23:25:54 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -240,6 +240,7 @@ struct tbl_row { struct tbl_row *next; struct tbl_cell *first; struct tbl_cell *last; + int vert; /* trailing vertical line */ }; enum tbl_datt { diff --git a/usr.bin/mandoc/tbl_layout.c b/usr.bin/mandoc/tbl_layout.c index 717e7c7dd1a..c07ddd22739 100644 --- a/usr.bin/mandoc/tbl_layout.c +++ b/usr.bin/mandoc/tbl_layout.c @@ -1,7 +1,7 @@ -/* $Id: tbl_layout.c,v 1.12 2014/03/21 22:17:01 schwarze Exp $ */ +/* $Id: tbl_layout.c,v 1.13 2014/03/28 23:25:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2012 Ingo Schwarze + * Copyright (c) 2012, 2014 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -96,6 +96,8 @@ mod: case (','): /* FALLTHROUGH */ case ('.'): + /* FALLTHROUGH */ + case ('|'): return(1); default: break; @@ -214,6 +216,13 @@ cell(struct tbl_node *tbl, struct tbl_row *rp, while (' ' == p[*pos]) (*pos)++; + /* Handle trailing vertical lines */ + + if ('.' == p[*pos] || '\0' == p[*pos]) { + rp->vert = vert; + return(1); + } + /* Parse the column position (`c', `l', `r', ...). */ for (i = 0; i < KEYS_MAX; i++) diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c index 06f6abf1a2e..5b806d88644 100644 --- a/usr.bin/mandoc/tbl_term.c +++ b/usr.bin/mandoc/tbl_term.c @@ -1,7 +1,7 @@ -/* $Id: tbl_term.c,v 1.14 2013/05/31 21:37:09 schwarze Exp $ */ +/* $Id: tbl_term.c,v 1.15 2014/03/28 23:25:54 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons - * Copyright (c) 2011, 2012 Ingo Schwarze + * Copyright (c) 2011, 2012, 2014 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -101,7 +101,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) /* Vertical frame at the start of each row. */ - if (TBL_OPT_BOX & sp->opts->opts || TBL_OPT_DBOX & sp->opts->opts) + if ((TBL_OPT_BOX | TBL_OPT_DBOX) & sp->opts->opts || + sp->head->vert) term_word(tp, TBL_SPAN_HORIZ == sp->pos || TBL_SPAN_DHORIZ == sp->pos ? "+" : "|"); @@ -155,7 +156,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) /* Vertical frame at the end of each row. */ - if (TBL_OPT_BOX & sp->opts->opts || TBL_OPT_DBOX & sp->opts->opts) + if ((TBL_OPT_BOX | TBL_OPT_DBOX) & sp->opts->opts || + sp->layout->vert) term_word(tp, TBL_SPAN_HORIZ == sp->pos || TBL_SPAN_DHORIZ == sp->pos ? "+" : " |"); term_flushln(tp); -- cgit v1.2.3