summaryrefslogtreecommitdiffstats
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
commitd9ef974d05cb710d89c63e8ee474a0eb00e2d56b (patch)
tree8fe4c115973611db8d2d44351bf3f89847e38b30 /mdoc_validate.c
parent4c2af21a8a623f5d22f660bdcfff1e1c23b9bcd2 (diff)
downloadmandoc-d9ef974d05cb710d89c63e8ee474a0eb00e2d56b.tar.gz
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.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 150fc827..c434d2b3 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -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