From 78f3b980a3571b0a981193a493a0291762bd2aca Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 6 Mar 2017 17:26:04 +0000 Subject: Using .Nd only makes sense in the NAME section. Warn if that macro occurs elsewhere. Triggered by a question from Dag-Erling Smoergrav . --- mandoc.1 | 8 ++++++++ mandoc.h | 1 + mdoc_validate.c | 4 ++++ read.c | 1 + regress/mdoc/Nd/broken.out_lint | 2 ++ 5 files changed, 16 insertions(+) diff --git a/mandoc.1 b/mandoc.1 index a9b7d694..ab49f5e8 100644 --- a/mandoc.1 +++ b/mandoc.1 @@ -908,6 +908,14 @@ The .Ic \&Nd macro lacks the required argument. The title line of the manual will end after the dash. +.It Sy "description line outside NAME section" +.Pq mdoc +An +.Ic \&Nd +macro appears outside the NAME section. +The arguments are printed anyway and the following text is used for +.Xr apropos 1 , +but none of that behaviour is portable. .It Sy "sections out of conventional order" .Pq mdoc A standard section occurs after another section it usually precedes. diff --git a/mandoc.h b/mandoc.h index b9b738db..be0693f3 100644 --- a/mandoc.h +++ b/mandoc.h @@ -71,6 +71,7 @@ enum mandocerr { MANDOCERR_NAMESEC_BAD, /* bad NAME section content: macro */ MANDOCERR_NAMESEC_PUNCT, /* missing comma before name: Nm name */ MANDOCERR_ND_EMPTY, /* missing description line, using "" */ + MANDOCERR_ND_LATE, /* description line outside NAME section */ MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */ MANDOCERR_SEC_REP, /* duplicate section title: Sh title */ MANDOCERR_SEC_MSEC, /* unexpected section: Sh title for ... only */ diff --git a/mdoc_validate.c b/mdoc_validate.c index 48d4fd31..95abef4f 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1035,6 +1035,10 @@ post_nd(POST_ARGS) if (n->type != ROFFT_BODY) return; + if (n->sec != SEC_NAME) + mandoc_msg(MANDOCERR_ND_LATE, mdoc->parse, + n->line, n->pos, "Nd"); + if (n->child == NULL) mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse, n->line, n->pos, "Nd"); diff --git a/read.c b/read.c index 043eee79..71eb3976 100644 --- a/read.c +++ b/read.c @@ -113,6 +113,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "bad NAME section content", "missing comma before name", "missing description line, using \"\"", + "description line outside NAME section", "sections out of conventional order", "duplicate section title", "unexpected section", diff --git a/regress/mdoc/Nd/broken.out_lint b/regress/mdoc/Nd/broken.out_lint index 181ec60b..d187e8c3 100644 --- a/regress/mdoc/Nd/broken.out_lint +++ b/regress/mdoc/Nd/broken.out_lint @@ -3,5 +3,7 @@ mandoc: broken.in:5:2: WARNING: bad NAME section content: Oo mandoc: broken.in:9:1: WARNING: bad NAME section content: text mandoc: broken.in:4:2: WARNING: NAME section without Nm before Nd mandoc: broken.in:4:2: WARNING: NAME section without description +mandoc: broken.in:16:2: WARNING: description line outside NAME section: Nd mandoc: broken.in:13:2: WARNING: moving content out of list: Bl mandoc: broken.in:18:1: WARNING: moving content out of list: text +mandoc: broken.in:27:2: WARNING: description line outside NAME section: Nd -- cgit