summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2021-06-27 17:57:54 +0000
committerIngo Schwarze <schwarze@openbsd.org>2021-06-27 17:57:54 +0000
commit2ec8a158cb2aaa80f61ebc3874b1650780239ef5 (patch)
treebc2f63eaafd788f966ab5f61236a0b8c3cf34a70
parent5e803b18a3083fa5c78121999261879e3c89c0d9 (diff)
downloadmandoc-2ec8a158cb2aaa80f61ebc3874b1650780239ef5.tar.gz
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@
-rw-r--r--libmandoc.h2
-rw-r--r--mandoc.13
-rw-r--r--mandoc.h1
-rw-r--r--mandoc_msg.c1
-rw-r--r--read.c5
-rw-r--r--roff.c10
6 files changed, 19 insertions, 3 deletions
diff --git a/libmandoc.h b/libmandoc.h
index 62635cff..c4d9e7be 100644
--- a/libmandoc.h
+++ b/libmandoc.h
@@ -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/mandoc.1 b/mandoc.1
index 7bd0911a..e9d4e1aa 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -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/mandoc.h b/mandoc.h
index b6e5c981..9d9fef8f 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -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/mandoc_msg.c b/mandoc_msg.c
index 7a127331..64355ddc 100644
--- a/mandoc_msg.c
+++ b/mandoc_msg.c
@@ -73,6 +73,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/read.c b/read.c
index f2790de5..3f375dcf 100644
--- a/read.c
+++ b/read.c
@@ -154,6 +154,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 */
@@ -180,6 +181,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')) {
@@ -279,7 +281,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/roff.c b/roff.c
index 3d0ff481..d7443d2a 100644
--- a/roff.c
+++ b/roff.c
@@ -1823,7 +1823,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;
@@ -1834,6 +1834,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 &&