From 17e372422bb3f249e0ae66d7ce3e482b646a8fc9 Mon Sep 17 00:00:00 2001 From: schwarze Date: Wed, 21 Jan 2015 00:45:16 +0000 Subject: [PATCH] blank lines in tables do not need special handling; simplifies code and reduces groff/mandoc differences in base by about 1% --- regress/usr.bin/mandoc/tbl/Makefile | 7 ++-- regress/usr.bin/mandoc/tbl/blankline.in | 14 ++++++++ .../usr.bin/mandoc/tbl/blankline.out_ascii | 18 ++++++++++ usr.bin/mandoc/libroff.h | 4 +-- usr.bin/mandoc/tbl.c | 9 ++--- usr.bin/mandoc/tbl_data.c | 36 +++++++------------ 6 files changed, 54 insertions(+), 34 deletions(-) create mode 100644 regress/usr.bin/mandoc/tbl/blankline.in create mode 100644 regress/usr.bin/mandoc/tbl/blankline.out_ascii diff --git a/regress/usr.bin/mandoc/tbl/Makefile b/regress/usr.bin/mandoc/tbl/Makefile index 4213a0626ed..270fcf9c0bb 100644 --- a/regress/usr.bin/mandoc/tbl/Makefile +++ b/regress/usr.bin/mandoc/tbl/Makefile @@ -1,6 +1,7 @@ -# $OpenBSD: Makefile,v 1.6 2014/12/24 15:37:23 schwarze Exp $ +# $OpenBSD: Makefile,v 1.7 2015/01/21 00:45:16 schwarze Exp $ -REGRESS_TARGETS = center fonts macro misalign nested numbers span vert +REGRESS_TARGETS = blankline center fonts macro misalign +REGRESS_TARGETS += nested numbers span vert LINT_TARGETS = macro nested # groff-1.22.3 defect: @@ -13,7 +14,7 @@ LINT_TARGETS = macro nested # .TS in a table causes a blank table line in GNU tbl(1), but not in mandoc. SKIP_GROFF = misalign nested -SKIP_TMAN ?= ALL +SKIP_TMAN ?= ALL SILENT TBL = /usr/local/bin/tbl diff --git a/regress/usr.bin/mandoc/tbl/blankline.in b/regress/usr.bin/mandoc/tbl/blankline.in new file mode 100644 index 00000000000..7c42c265622 --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/blankline.in @@ -0,0 +1,14 @@ +.TH TBL-BLANKLINE 1 "January 21, 2015" OpenBSD +.SH NAME +tbl-blankline \- blank line in a table +.SH DESCRIPTION +normal text +.TS +lb +li +lb. +first + +last +.TE +normal text diff --git a/regress/usr.bin/mandoc/tbl/blankline.out_ascii b/regress/usr.bin/mandoc/tbl/blankline.out_ascii new file mode 100644 index 00000000000..ae78127c8ca --- /dev/null +++ b/regress/usr.bin/mandoc/tbl/blankline.out_ascii @@ -0,0 +1,18 @@ +TBL-BLANKLINE(1) General Commands Manual TBL-BLANKLINE(1) + + + +NNAAMMEE + tbl-blankline - blank line in a table + +DDEESSCCRRIIPPTTIIOONN + normal text + + ffiirrsstt + + llaasstt + normal text + + + +OpenBSD January 21, 2015 TBL-BLANKLINE(1) diff --git a/usr.bin/mandoc/libroff.h b/usr.bin/mandoc/libroff.h index 6767a87ba0b..cd51b20f35c 100644 --- a/usr.bin/mandoc/libroff.h +++ b/usr.bin/mandoc/libroff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libroff.h,v 1.12 2015/01/14 22:44:51 schwarze Exp $ */ +/* $OpenBSD: libroff.h,v 1.13 2015/01/21 00:45:16 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -71,7 +71,7 @@ void tbl_reset(struct tbl_node *); enum rofferr tbl_read(struct tbl_node *, int, const char *, int); void tbl_option(struct tbl_node *, int, const char *); void tbl_layout(struct tbl_node *, int, const char *); -int tbl_data(struct tbl_node *, int, const char *); +void tbl_data(struct tbl_node *, int, const char *); int tbl_cdata(struct tbl_node *, int, const char *); const struct tbl_span *tbl_span(struct tbl_node *); void tbl_end(struct tbl_node **); diff --git a/usr.bin/mandoc/tbl.c b/usr.bin/mandoc/tbl.c index 91503becb34..ab6667c0dff 100644 --- a/usr.bin/mandoc/tbl.c +++ b/usr.bin/mandoc/tbl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl.c,v 1.12 2015/01/14 22:44:51 schwarze Exp $ */ +/* $OpenBSD: tbl.c,v 1.13 2015/01/21 00:45:16 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -64,11 +64,8 @@ tbl_read(struct tbl_node *tbl, int ln, const char *p, int offs) break; } - /* - * This only returns zero if the line is empty, so we ignore it - * and continue on. - */ - return(tbl_data(tbl, ln, p) ? ROFF_TBL : ROFF_IGN); + tbl_data(tbl, ln, p); + return(ROFF_TBL); } struct tbl_node * diff --git a/usr.bin/mandoc/tbl_data.c b/usr.bin/mandoc/tbl_data.c index d83c6121aaf..f5f28ea972d 100644 --- a/usr.bin/mandoc/tbl_data.c +++ b/usr.bin/mandoc/tbl_data.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_data.c,v 1.19 2014/11/28 19:25:03 schwarze Exp $ */ +/* $OpenBSD: tbl_data.c,v 1.20 2015/01/21 00:45:16 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -28,13 +28,13 @@ #include "libmandoc.h" #include "libroff.h" -static int getdata(struct tbl_node *, struct tbl_span *, +static void getdata(struct tbl_node *, struct tbl_span *, int, const char *, int *); static struct tbl_span *newspan(struct tbl_node *, int, struct tbl_row *); -static int +static void getdata(struct tbl_node *tbl, struct tbl_span *dp, int ln, const char *p, int *pos) { @@ -67,7 +67,7 @@ getdata(struct tbl_node *tbl, struct tbl_span *dp, /* Skip to the end... */ while (p[*pos]) (*pos)++; - return(1); + return; } dat = mandoc_calloc(1, sizeof(struct tbl_dat)); @@ -102,7 +102,7 @@ getdata(struct tbl_node *tbl, struct tbl_span *dp, if (*pos - sv == 2 && 'T' == p[sv] && '{' == p[sv + 1]) { tbl->part = TBL_PART_CDATA; - return(1); + return; } assert(*pos - sv >= 0); @@ -132,7 +132,7 @@ getdata(struct tbl_node *tbl, struct tbl_span *dp, mandoc_msg(MANDOCERR_TBLIGNDATA, tbl->parse, ln, sv, NULL); - return(1); + return; } int @@ -151,7 +151,8 @@ tbl_cdata(struct tbl_node *tbl, int ln, const char *p) if (p[pos] == tbl->opts.tab) { tbl->part = TBL_PART_DATA; pos++; - return(getdata(tbl, tbl->last_span, ln, p, &pos)); + getdata(tbl, tbl->last_span, ln, p, &pos); + return(1); } else if ('\0' == p[pos]) { tbl->part = TBL_PART_DATA; return(1); @@ -200,20 +201,13 @@ newspan(struct tbl_node *tbl, int line, struct tbl_row *rp) return(dp); } -int +void tbl_data(struct tbl_node *tbl, int ln, const char *p) { struct tbl_span *dp; struct tbl_row *rp; int pos; - pos = 0; - - if ('\0' == p[pos]) { - mandoc_msg(MANDOCERR_TBL, tbl->parse, ln, pos, NULL); - return(0); - } - /* * Choose a layout row: take the one following the last parsed * span's. If that doesn't exist, use the last parsed span's. @@ -255,19 +249,15 @@ tbl_data(struct tbl_node *tbl, int ln, const char *p) if ( ! strcmp(p, "_")) { dp->pos = TBL_SPAN_HORIZ; - return(1); + return; } else if ( ! strcmp(p, "=")) { dp->pos = TBL_SPAN_DHORIZ; - return(1); + return; } dp->pos = TBL_SPAN_DATA; - /* This returns 0 when TBL_PART_CDATA is entered. */ - + pos = 0; while ('\0' != p[pos]) - if ( ! getdata(tbl, dp, ln, p, &pos)) - return(0); - - return(1); + getdata(tbl, dp, ln, p, &pos); } -- 2.20.1