source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: add a style message about overlong text lines, trying very hard
@ 2021-06-27 17:58 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2021-06-27 17:58 UTC (permalink / raw)
  To: source

Log Message:
-----------
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@

Modified Files:
--------------
    mandoc:
        libmandoc.h
        mandoc.1
        mandoc.h
        mandoc_msg.c
        read.c
        roff.c

Revision Data
-------------
Index: read.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/read.c,v
retrieving revision 1.219
retrieving revision 1.220
diff -Lread.c -Lread.c -u -p -r1.219 -r1.220
--- read.c
+++ read.c
@@ -154,6 +154,7 @@ mparse_buf_r(struct mparse *curp, struct
 	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
 			    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
 
 		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. */
 
Index: mandoc.1
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.1,v
retrieving revision 1.249
retrieving revision 1.250
diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.249 -r1.250
--- mandoc.1
+++ 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
Index: libmandoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/libmandoc.h,v
retrieving revision 1.79
retrieving revision 1.80
diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.79 -r1.80
--- libmandoc.h
+++ 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);
Index: mandoc.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc.h,v
retrieving revision 1.270
retrieving revision 1.271
diff -Lmandoc.h -Lmandoc.h -u -p -r1.270 -r1.271
--- mandoc.h
+++ 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 */
Index: mandoc_msg.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandoc_msg.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -Lmandoc_msg.c -Lmandoc_msg.c -u -p -r1.13 -r1.14
--- mandoc_msg.c
+++ mandoc_msg.c
@@ -73,6 +73,7 @@ static	const char *const type_message[MA
 	"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",
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.376
retrieving revision 1.377
diff -Lroff.c -Lroff.c -u -p -r1.376 -r1.377
--- roff.c
+++ roff.c
@@ -1823,7 +1823,7 @@ roff_parsetext(struct roff *r, struct bu
 }
 
 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;
@@ -1833,6 +1833,14 @@ roff_parseln(struct roff *r, int ln, str
 	int		 ctl;	/* macro line (boolean) */
 
 	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. */
 
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-27 17:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 17:58 mandoc: add a style message about overlong text lines, trying very hard schwarze

source@mandoc.bsd.lv

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/mandoc-source

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 mandoc-source mandoc-source/ http://inbox.vuxu.org/mandoc-source \
		source@mandoc.bsd.lv
	public-inbox-index mandoc-source

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.mandoc.source


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git