From dd9cc97dc57dc8cd11cfeabfe41fae0f79ee576a Mon Sep 17 00:00:00 2001 From: schwarze Date: Sun, 27 Jun 2021 17:57:13 +0000 Subject: [PATCH] add a style message about overlong text lines, trying very hard to avoid false positives, not at all trying to catch as many cases as possible; feature originally suggested by tb@, OK tb@ kn@ jmc@ --- usr.bin/mandoc/libmandoc.h | 4 ++-- usr.bin/mandoc/mandoc.1 | 7 +++++-- usr.bin/mandoc/mandoc.h | 3 ++- usr.bin/mandoc/mandoc_msg.c | 3 ++- usr.bin/mandoc/read.c | 7 +++++-- usr.bin/mandoc/roff.c | 12 ++++++++++-- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index b29163159bc..354845ff6f1 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libmandoc.h,v 1.64 2020/04/03 11:34:19 schwarze Exp $ */ +/* $OpenBSD: libmandoc.h,v 1.65 2021/06/27 17:57:13 schwarze Exp $ */ /* * Copyright (c) 2013-2015,2017,2018,2020 Ingo Schwarze * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons @@ -73,7 +73,7 @@ void roff_reset(struct roff *); void roff_man_free(struct roff_man *); struct roff_man *roff_man_alloc(struct roff *, const char *, int); void roff_man_reset(struct roff_man *); -int roff_parseln(struct roff *, int, struct buf *, int *); +int roff_parseln(struct roff *, int, struct buf *, int *, size_t); void roff_userret(struct roff *); void roff_endparse(struct roff *); void roff_setreg(struct roff *, const char *, int, char); diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index acb737ca6c9..cfa47b4b81a 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.175 2021/06/02 18:27:36 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.176 2021/06/27 17:57:13 schwarze Exp $ .\" .\" Copyright (c) 2012, 2014-2021 Ingo Schwarze .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 2 2021 $ +.Dd $Mdocdate: June 27 2021 $ .Dt MANDOC 1 .Os .Sh NAME @@ -1066,6 +1066,9 @@ An request occurs even though the document already switched to no-fill mode and did not switch back to fill mode yet. It has no effect. +.It Sy "input text line longer than 80 bytes" +Consider breaking the input text line +at one of the blank characters before column 80. .It Sy "verbatim \(dq--\(dq, maybe consider using \e(em" .Pq mdoc Even though the ASCII output device renders an em-dash as diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 40f54b88bc3..0bd681cba91 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.212 2021/06/02 18:27:37 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.213 2021/06/27 17:57:13 schwarze Exp $ */ /* * Copyright (c) 2012-2020 Ingo Schwarze * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons @@ -72,6 +72,7 @@ enum mandocerr { MANDOCERR_DELIM_NB, /* no blank before trailing delimiter: macro ... */ MANDOCERR_FI_SKIP, /* fill mode already enabled, skipping: fi */ MANDOCERR_NF_SKIP, /* fill mode already disabled, skipping: nf */ + MANDOCERR_TEXT_LONG, /* input text line longer than 80 bytes */ MANDOCERR_DASHDASH, /* verbatim "--", maybe consider using \(em */ MANDOCERR_FUNC, /* function name without markup: name() */ MANDOCERR_SPACE_EOL, /* whitespace at end of input line */ diff --git a/usr.bin/mandoc/mandoc_msg.c b/usr.bin/mandoc/mandoc_msg.c index c6f2c7205b9..1d20cfc1bf2 100644 --- a/usr.bin/mandoc/mandoc_msg.c +++ b/usr.bin/mandoc/mandoc_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc_msg.c,v 1.11 2021/06/02 18:27:37 schwarze Exp $ */ +/* $OpenBSD: mandoc_msg.c,v 1.12 2021/06/27 17:57:13 schwarze Exp $ */ /* * Copyright (c) 2014-2020 Ingo Schwarze * Copyright (c) 2010, 2011 Kristaps Dzonsons @@ -71,6 +71,7 @@ static const char *const type_message[MANDOCERR_MAX] = { "no blank before trailing delimiter", "fill mode already enabled, skipping", "fill mode already disabled, skipping", + "input text line longer than 80 bytes", "verbatim \"--\", maybe consider using \\(em", "function name without markup", "whitespace at end of input line", diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index a6a25de677a..223dc826d6c 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.190 2020/04/24 11:58:02 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.191 2021/06/27 17:57:13 schwarze Exp $ */ /* * Copyright (c) 2010-2020 Ingo Schwarze * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons @@ -152,6 +152,7 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start) struct buf *firstln, *lastln, *thisln, *loop; char *cp; size_t pos; /* byte number in the ln buffer */ + size_t spos; /* at the start of the current line parse */ int line_result, result; int of; int lnn; /* line number in the real file */ @@ -178,6 +179,7 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start) curp->filenc & MPARSE_LATIN1) curp->filenc = preconv_cue(&blk, i); } + spos = pos; while (i < blk.sz && (start || blk.buf[i] != '\0')) { @@ -277,7 +279,8 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start) of = 0; rerun: - line_result = roff_parseln(curp->roff, curp->line, &ln, &of); + line_result = roff_parseln(curp->roff, curp->line, + &ln, &of, start && spos == 0 ? pos : 0); /* Process options. */ diff --git a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c index 00db7b800fc..8518d1901b1 100644 --- a/usr.bin/mandoc/roff.c +++ b/usr.bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: roff.c,v 1.248 2020/08/27 12:58:00 schwarze Exp $ */ +/* $OpenBSD: roff.c,v 1.249 2021/06/27 17:57:13 schwarze Exp $ */ /* * Copyright (c) 2010-2015, 2017-2020 Ingo Schwarze * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons @@ -1821,7 +1821,7 @@ roff_parsetext(struct roff *r, struct buf *buf, int pos, int *offs) } int -roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs) +roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs, size_t len) { enum roff_tok t; int e; @@ -1832,6 +1832,14 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs) ppos = pos = *offs; + if (len > 80 && r->tbl == NULL && r->eqn == NULL && + (r->man->flags & ROFF_NOFILL) == 0 && + strchr(" .\\", buf->buf[pos]) == NULL && + buf->buf[pos] != r->control && + strcspn(buf->buf, " ") < 80) + mandoc_msg(MANDOCERR_TEXT_LONG, ln, (int)len - 1, + "%.20s...", buf->buf + pos); + /* Handle in-line equation delimiters. */ if (r->tbl == NULL && -- 2.20.1