From 874ac26ff8affa95d651832b3050f9fd13ae9aca Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 7 Sep 2014 23:25:01 +0000 Subject: warn about AUTHORS sections without .An macros, inspired by mdoclint(1) --- mandoc.1 | 10 ++++++++-- mandoc.h | 3 ++- mdoc_validate.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- read.c | 3 ++- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/mandoc.1 b/mandoc.1 index 6df15edc..ee4c4c51 100644 --- a/mandoc.1 +++ b/mandoc.1 @@ -1,4 +1,4 @@ -.\" $Id: mandoc.1,v 1.110 2014/09/03 05:22:45 schwarze Exp $ +.\" $Id: mandoc.1,v 1.111 2014/09/07 23:25:01 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2012, 2014 Ingo Schwarze @@ -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: September 3 2014 $ +.Dd $Mdocdate: September 7 2014 $ .Dt MANDOC 1 .Os .Sh NAME @@ -766,6 +766,12 @@ The same standard section title occurs more than once. .Pq mdoc A standard section header occurs in a section of the manual where it normally isn't useful. +.It Sy "AUTHORS section without An macro" +.Pq mdoc +An AUTHORS sections contains no +.Ic \&An +macros, or only empty ones. +Probably, there are author names lacking markup. .El .Ss "Warnings related to macros and nesting" .Bl -ohang diff --git a/mandoc.h b/mandoc.h index a4211454..af8f4fc9 100644 --- a/mandoc.h +++ b/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.153 2014/09/03 23:21:47 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.154 2014/09/07 23:25:01 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -72,6 +72,7 @@ enum mandocerr { 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 */ + MANDOCERR_AN_MISSING, /* AUTHORS section without An macro */ /* related to macros and nesting */ MANDOCERR_MACRO_OBS, /* obsolete macro: macro */ diff --git a/mdoc_validate.c b/mdoc_validate.c index ff691ba6..c89de9c9 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.246 2014/09/07 00:05:28 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.247 2014/09/07 23:25:01 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -67,6 +67,7 @@ static void check_text(struct mdoc *, int, int, char *); static void check_argv(struct mdoc *, struct mdoc_node *, struct mdoc_argv *); static void check_args(struct mdoc *, struct mdoc_node *); +static int child_an(const struct mdoc_node *); static enum mdoc_sec a2sec(const char *); static size_t macro2len(enum mdoct); @@ -114,8 +115,9 @@ static int post_par(POST_ARGS); static int post_root(POST_ARGS); static int post_rs(POST_ARGS); static int post_sh(POST_ARGS); -static int post_sh_body(POST_ARGS); static int post_sh_head(POST_ARGS); +static int post_sh_name(POST_ARGS); +static int post_sh_authors(POST_ARGS); static int post_st(POST_ARGS); static int post_vt(POST_ARGS); static int pre_an(PRE_ARGS); @@ -1847,22 +1849,31 @@ post_sh(POST_ARGS) post_ignpar(mdoc); - if (MDOC_HEAD == mdoc->last->type) + switch (mdoc->last->type) { + case MDOC_HEAD: return(post_sh_head(mdoc)); - if (MDOC_BODY == mdoc->last->type) - return(post_sh_body(mdoc)); + case MDOC_BODY: + switch (mdoc->lastsec) { + case SEC_NAME: + return(post_sh_name(mdoc)); + case SEC_AUTHORS: + return(post_sh_authors(mdoc)); + default: + break; + } + break; + default: + break; + } return(1); } static int -post_sh_body(POST_ARGS) +post_sh_name(POST_ARGS) { struct mdoc_node *n; - if (SEC_NAME != mdoc->lastsec) - return(1); - /* * Warn if the NAME section doesn't contain the `Nm' and `Nd' * macros (can have multiple `Nm' and one `Nd'). Note that the @@ -1893,6 +1904,26 @@ post_sh_body(POST_ARGS) return(1); } +static int +child_an(const struct mdoc_node *n) +{ + + for (n = n->child; n != NULL; n = n->next) + if ((n->tok == MDOC_An && n->nchild) || child_an(n)) + return(1); + return(0); +} + +static int +post_sh_authors(POST_ARGS) +{ + + if ( ! child_an(mdoc->last)) + mandoc_msg(MANDOCERR_AN_MISSING, mdoc->parse, + mdoc->last->line, mdoc->last->pos, NULL); + return(1); +} + static int post_sh_head(POST_ARGS) { diff --git a/read.c b/read.c index 2b67ace1..97d09cdf 100644 --- a/read.c +++ b/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.85 2014/09/07 02:17:40 schwarze Exp $ */ +/* $Id: read.c,v 1.86 2014/09/07 23:25:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -117,6 +117,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "sections out of conventional order", "duplicate section title", "unexpected section", + "AUTHORS section without An macro", /* related to macros and nesting */ "obsolete macro", -- cgit v1.2.3