From 4d53b36358108c3838a8424f0958934d3dcf1af9 Mon Sep 17 00:00:00 2001
From: Ingo Schwarze <schwarze@openbsd.org>
Date: Wed, 4 Feb 2015 19:20:12 +0000
Subject: [PATCH] improve diagnostics regarding arguments of .An .Pp .Lp .br
 .sp in particular, get rid of check_count(..., CHECK_EQ, 0)

---
 mandoc.1        | 16 ++++++++++++++--
 mdoc_validate.c | 26 +++++++++++++++-----------
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/mandoc.1 b/mandoc.1
index a80634e3..5d811a48 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,4 +1,4 @@
-.\"	$Id: mandoc.1,v 1.143 2015/02/04 18:03:47 schwarze Exp $
+.\"	$Id: mandoc.1,v 1.144 2015/02/04 19:20:12 schwarze Exp $
 .\"
 .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
 .\" Copyright (c) 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1602,6 +1602,8 @@ An
 .Ic \&Ef ,
 .Ic \&Ek ,
 .Ic \&El ,
+.Ic \&Lp ,
+.Ic \&Pp ,
 .Ic \&Re ,
 .Ic \&Rs ,
 or
@@ -1621,14 +1623,24 @@ or
 .Ic \&EN
 macro, or a
 .Xr roff 7
+.Ic \&br
+request or
 .Sq \&..
 block closing request is invoked with at least one argument.
 All arguments are ignored.
 .It Sy "skipping excess arguments"
 .Pq mdoc , man , roff
 The
+.Ic \&An
+macro is invoked with another argument after
+.Fl split
+or
+.Fl nosplit ,
+the
 .Ic \&Bf
-macro is invoked with more than one argument, the
+macro or the
+.Ic \&sp
+request is invoked with more than one argument, the
 .Ic \&RE
 macro is invoked with more than one argument
 or with a non-integer argument, or a request of the
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 417e2161..ebd78482 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/*	$Id: mdoc_validate.c,v 1.268 2015/02/04 18:03:47 schwarze Exp $ */
+/*	$Id: mdoc_validate.c,v 1.269 2015/02/04 19:20:12 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1174,14 +1174,15 @@ post_at(POST_ARGS)
 static void
 post_an(POST_ARGS)
 {
-	struct mdoc_node *np;
+	struct mdoc_node *np, *nch;
 
 	np = mdoc->last;
 	if (AUTH__NONE == np->norm->An.auth) {
 		if (0 == np->child)
 			check_count(mdoc, MDOC_ELEM, CHECK_GT, 0);
-	} else if (np->child)
-		check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0);
+	} else if ((nch = np->child) != NULL)
+		mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
+		    nch->line, nch->pos, "An ... %s", nch->string);
 }
 
 static void
@@ -2134,14 +2135,17 @@ post_par(POST_ARGS)
 {
 	struct mdoc_node *np;
 
-	if (mdoc->last->tok == MDOC_sp)
-		check_count(mdoc, MDOC_ELEM, CHECK_LT, 2);
-	else
-		check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0);
+	np = mdoc->last;
 
-	if (MDOC_ELEM != mdoc->last->type &&
-	    MDOC_BLOCK != mdoc->last->type)
-		return;
+	if (np->tok == MDOC_sp) {
+		if (np->nchild > 1)
+			mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
+			    np->child->next->line, np->child->next->pos,
+			    "sp ... %s", np->child->next->string);
+	} else if (np->child != NULL)
+		mandoc_vmsg(MANDOCERR_ARG_SKIP,
+		    mdoc->parse, np->line, np->pos, "%s %s",
+		    mdoc_macronames[np->tok], np->child->string);
 
 	if (NULL == (np = mdoc->last->prev)) {
 		np = mdoc->last->parent;
-- 
2.47.1