diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-09-07 23:24:34 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-09-07 23:24:34 +0000 |
commit | 639b660f2d3935709fa004684578b82b7ae541ec (patch) | |
tree | ba389ba6db7aae66a915e622d677d76369e2515a /usr.bin/mandoc | |
parent | 1430e0c1fd42ea5a87f4861445e4c30809e4da57 (diff) |
warn about AUTHORS sections without .An macros, inspired by mdoclint(1)
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 49 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 3 |
3 files changed, 44 insertions, 11 deletions
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 782be62a1ec..ccaaa32fe01 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.97 2014/09/03 23:20:33 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.98 2014/09/07 23:24:33 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -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/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 5a1e55e3c37..f0c76d64146 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_validate.c,v 1.163 2014/09/07 00:04:47 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.164 2014/09/07 23:24:33 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -66,6 +66,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); @@ -113,8 +114,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); @@ -1846,22 +1848,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) } 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) { struct mdoc_node *n; diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index f9e72d58025..0ead04577dc 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.61 2014/09/07 02:17:36 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.62 2014/09/07 23:24:33 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -111,6 +111,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", |