From 137b7894f98df8048a9fb82e36cc9c8c65efcc65 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 28 Jan 2017 23:30:08 +0000 Subject: Add a warning "new sentence, new line". This does not attempt to pinpoint each and every offender, but instead tries very hard to avoid false positives: Currently, there are only two false positives in the whole OpenBSD base system. Only do this in mdoc(7), not in man(7), because manuals written in man(7) typically have much worse problems than this. OK jmc@ on a previous version of the patch --- mandoc.1 | 4 ++++ mandoc.h | 1 + mdoc.c | 18 +++++++++++++++++- read.c | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mandoc.1 b/mandoc.1 index 90bf94a3..9dbfa07a 100644 --- a/mandoc.1 +++ b/mandoc.1 @@ -1357,6 +1357,10 @@ it is hard to predict which tab stop position the tab will advance to. Whitespace at the end of input lines is almost never semantically significant \(em but in the odd case where it might be, it is extremely confusing when reviewing and maintaining documents. +.It Sy "new sentence, new line" +.Pq mdoc +A new sentence starts in the middle of a text line. +Start it on a new input line to help formatters produce correct spacing. .It Sy "bad comment style" .Pq roff Comment lines start with a dot, a backslash, and a double-quote character. diff --git a/mandoc.h b/mandoc.h index 5b75e882..b9b738db 100644 --- a/mandoc.h +++ b/mandoc.h @@ -134,6 +134,7 @@ enum mandocerr { MANDOCERR_FI_BLANK, /* blank line in fill mode, using .sp */ MANDOCERR_FI_TAB, /* tab in filled text */ MANDOCERR_SPACE_EOL, /* whitespace at end of input line */ + MANDOCERR_EOS, /* new sentence, new line */ MANDOCERR_COMMENT_BAD, /* bad comment style */ MANDOCERR_ESC_BAD, /* invalid escape sequence: esc */ MANDOCERR_STR_UNDEF, /* undefined string, using "": name */ diff --git a/mdoc.c b/mdoc.c index 487bebb0..988e27cc 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012-2016 Ingo Schwarze + * Copyright (c) 2010, 2012-2017 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 @@ -312,6 +312,22 @@ mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs) if (mandoc_eos(buf+offs, (size_t)(end-buf-offs))) mdoc->last->flags |= NODE_EOS; + + for (c = buf + offs; c != NULL; c = strchr(c + 1, '.')) { + if (c - buf < offs + 2) + continue; + if (end - c < 4) + break; + if (isalpha((unsigned char)c[-2]) && + isalpha((unsigned char)c[-1]) && + c[1] == ' ' && + isupper((unsigned char)(c[2] == ' ' ? c[3] : c[2])) && + (c[-2] != 'n' || c[-1] != 'c') && + (c[-2] != 'v' || c[-1] != 's')) + mandoc_msg(MANDOCERR_EOS, mdoc->parse, + line, (int)(c - buf), NULL); + } + return 1; } diff --git a/read.c b/read.c index 936586a7..fd0f1957 100644 --- a/read.c +++ b/read.c @@ -177,6 +177,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "blank line in fill mode, using .sp", "tab in filled text", "whitespace at end of input line", + "new sentence, new line", "bad comment style", "invalid escape sequence", "undefined string, using \"\"", -- cgit