aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-02-23 13:31:03 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-02-23 13:31:03 +0000
commitf219a129fd68f9a8fd81fca8b18ef3fb534854a0 (patch)
tree8ab19745b42717079a9ed97cff0fc84d08247a1d /mdoc_validate.c
parent71840fc752bb2b731194aa9d32165cd967d262b2 (diff)
downloadmandoc-f219a129fd68f9a8fd81fca8b18ef3fb534854a0.tar.gz
mandoc-f219a129fd68f9a8fd81fca8b18ef3fb534854a0.tar.zst
mandoc-f219a129fd68f9a8fd81fca8b18ef3fb534854a0.zip
improve NAME section diagnostics;
confusing messages reported by Jan Stary <hans at stare dot cz>
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r--mdoc_validate.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 082e49a6..7e8e9005 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.281 2015/02/17 20:37:17 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.282 2015/02/23 13:31:04 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1748,34 +1748,34 @@ static void
post_sh_name(POST_ARGS)
{
struct mdoc_node *n;
+ int hasnm, hasnd;
- /*
- * Warn if the NAME section doesn't contain the `Nm' and `Nd'
- * macros (can have multiple `Nm' and one `Nd'). Note that the
- * children of the BODY declaration can also be "text".
- */
-
- if (NULL == (n = mdoc->last->child)) {
- mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
- mdoc->last->line, mdoc->last->pos, "empty");
- return;
- }
+ hasnm = hasnd = 0;
- for ( ; n && n->next; n = n->next) {
- if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
- continue;
- if (MDOC_TEXT == n->type)
- continue;
- mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
- n->line, n->pos, mdoc_macronames[n->tok]);
+ for (n = mdoc->last->child; n != NULL; n = n->next) {
+ switch (n->tok) {
+ case MDOC_Nm:
+ hasnm = 1;
+ break;
+ case MDOC_Nd:
+ hasnd = 1;
+ if (n->next != NULL)
+ mandoc_msg(MANDOCERR_NAMESEC_ND,
+ mdoc->parse, n->line, n->pos, NULL);
+ break;
+ default:
+ mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
+ n->line, n->pos, mdoc_macronames[n->tok]);
+ break;
+ }
}
- assert(n);
- if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok)
- return;
-
- mandoc_msg(MANDOCERR_NAMESEC_BAD, mdoc->parse,
- n->line, n->pos, mdoc_macronames[n->tok]);
+ if ( ! hasnm)
+ mandoc_msg(MANDOCERR_NAMESEC_NONM, mdoc->parse,
+ mdoc->last->line, mdoc->last->pos, NULL);
+ if ( ! hasnd)
+ mandoc_msg(MANDOCERR_NAMESEC_NOND, mdoc->parse,
+ mdoc->last->line, mdoc->last->pos, NULL);
}
static void