source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Discard excess head arguments for .Bd .Bl .Bk and delete
@ 2015-02-04 22:30 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-02-04 22:30 UTC (permalink / raw)
  To: source

Log Message:
-----------
Discard excess head arguments for .Bd .Bl .Bk and delete hwarn_eq0().
Discard empty .Bk blocks.
Improve related diagnostics.

Modified Files:
--------------
    mdocml:
        mandoc.1
        mdoc_macro.c
        mdoc_validate.c

Revision Data
-------------
Index: mandoc.1
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mandoc.1,v
retrieving revision 1.144
retrieving revision 1.145
diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.144 -r1.145
--- mandoc.1
+++ mandoc.1
@@ -994,7 +994,8 @@ except that it may control a following
 clause.
 .It Sy "skipping empty macro"
 .Pq mdoc
-The indicated macro has no arguments and hence no effect.
+The indicated macro has no arguments or no body content
+and hence no effect.
 .It Sy "empty argument, using 0n"
 .Pq mdoc
 The required width is missing after
@@ -1636,14 +1637,16 @@ macro is invoked with another argument a
 .Fl split
 or
 .Fl nosplit ,
-the
-.Ic \&Bf
-macro or the
-.Ic \&sp
-request is invoked with more than one argument, the
+.Ic \&Bd ,
+.Ic \&Bk ,
+or
+.Ic \&Bl
+are invoked with invalid arguments, the
 .Ic \&RE
 macro is invoked with more than one argument
-or with a non-integer argument, or a request of the
+or with a non-integer argument, the
+.Ic \&sp
+request is invoked with more than one argument, or a request of the
 .Ic \&de
 family is invoked with more than two arguments.
 The excess arguments are ignored.
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_validate.c,v
retrieving revision 1.269
retrieving revision 1.270
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.269 -r1.270
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -70,7 +70,6 @@ static	void	 rewrite_macro2len(char **);
 static	void	 bwarn_ge1(POST_ARGS);
 static	void	 ewarn_eq1(POST_ARGS);
 static	void	 ewarn_ge1(POST_ARGS);
-static	void	 hwarn_eq0(POST_ARGS);
 
 static	void	 post_an(POST_ARGS);
 static	void	 post_at(POST_ARGS);
@@ -421,12 +420,6 @@ ewarn_ge1(POST_ARGS)
 }
 
 static void
-hwarn_eq0(POST_ARGS)
-{
-	check_count(mdoc, MDOC_HEAD, CHECK_EQ, 0);
-}
-
-static void
 check_args(struct mdoc *mdoc, struct mdoc_node *n)
 {
 	int		 i;
@@ -1088,8 +1081,6 @@ static void
 post_literal(POST_ARGS)
 {
 
-	if (mdoc->last->tok == MDOC_Bd)
-		hwarn_eq0(mdoc);
 	bwarn_ge1(mdoc);
 
 	/*
@@ -1415,13 +1406,21 @@ post_bl_block_tag(POST_ARGS)
 static void
 post_bl_head(POST_ARGS)
 {
-	struct mdoc_node *np, *nn, *nnp;
+	struct mdoc_node *nbl, *nh, *nch, *nnext;
 	struct mdoc_argv *argv;
 	int		  i, j;
 
-	if (LIST_column != mdoc->last->norm->Bl.type) {
-		/* FIXME: this should be ERROR class... */
-		hwarn_eq0(mdoc);
+	nh = mdoc->last;
+
+	if (nh->norm->Bl.type != LIST_column) {
+		if ((nch = nh->child) == NULL)
+			return;
+		mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
+		    nch->line, nch->pos, "Bl ... %s", nch->string);
+		while (nch != NULL) {
+			mdoc_node_delete(mdoc, nch);
+			nch = nh->child;
+		}
 		return;
 	}
 
@@ -1431,17 +1430,15 @@ post_bl_head(POST_ARGS)
 	 * lists where they're argument values following -column.
 	 */
 
-	if (mdoc->last->child == NULL)
+	if (nh->child == NULL)
 		return;
 
-	np = mdoc->last->parent;
-	assert(np->args);
-
-	for (j = 0; j < (int)np->args->argc; j++)
-		if (MDOC_Column == np->args->argv[j].arg)
+	nbl = nh->parent;
+	for (j = 0; j < (int)nbl->args->argc; j++)
+		if (nbl->args->argv[j].arg == MDOC_Column)
 			break;
 
-	assert(j < (int)np->args->argc);
+	assert(j < (int)nbl->args->argc);
 
 	/*
 	 * Accommodate for new-style groff column syntax.  Shuffle the
@@ -1449,25 +1446,23 @@ post_bl_head(POST_ARGS)
 	 * column field.  Then, delete the head children.
 	 */
 
-	argv = np->args->argv + j;
+	argv = nbl->args->argv + j;
 	i = argv->sz;
-	argv->sz += mdoc->last->nchild;
+	argv->sz += nh->nchild;
 	argv->value = mandoc_reallocarray(argv->value,
 	    argv->sz, sizeof(char *));
 
-	mdoc->last->norm->Bl.ncols = argv->sz;
-	mdoc->last->norm->Bl.cols = (void *)argv->value;
+	nh->norm->Bl.ncols = argv->sz;
+	nh->norm->Bl.cols = (void *)argv->value;
 
-	for (nn = mdoc->last->child; nn; i++) {
-		argv->value[i] = nn->string;
-		nn->string = NULL;
-		nnp = nn;
-		nn = nn->next;
-		mdoc_node_delete(NULL, nnp);
+	for (nch = nh->child; nch != NULL; nch = nnext) {
+		argv->value[i++] = nch->string;
+		nch->string = NULL;
+		nnext = nch->next;
+		mdoc_node_delete(NULL, nch);
 	}
-
-	mdoc->last->nchild = 0;
-	mdoc->last->child = NULL;
+	nh->nchild = 0;
+	nh->child = NULL;
 }
 
 static void
@@ -1553,9 +1548,15 @@ post_bl(POST_ARGS)
 static void
 post_bk(POST_ARGS)
 {
+	struct mdoc_node	*n;
 
-	hwarn_eq0(mdoc);
-	bwarn_ge1(mdoc);
+	n = mdoc->last;
+
+	if (n->type == MDOC_BLOCK && n->body->child == NULL) {
+		mandoc_msg(MANDOCERR_MACRO_EMPTY,
+		    mdoc->parse, n->line, n->pos, "Bk");
+		mdoc_node_delete(mdoc, n);
+	}
 }
 
 static void
Index: mdoc_macro.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_macro.c,v
retrieving revision 1.173
retrieving revision 1.174
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.173 -r1.174
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -1042,6 +1042,12 @@ blk_full(MACRO_PROT_ARGS)
 			body = mdoc_body_alloc(mdoc, line, ppos, tok);
 			break;
 		}
+		if (tok == MDOC_Bd || tok == MDOC_Bk) {
+			mandoc_vmsg(MANDOCERR_ARG_EXCESS,
+			    mdoc->parse, line, la, "%s ... %s",
+			    mdoc_macronames[tok], buf + la);
+			break;
+		}
 		if (tok == MDOC_Rs) {
 			mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse,
 			    line, la, "Rs %s", buf + la);
@@ -1105,7 +1111,7 @@ blk_full(MACRO_PROT_ARGS)
 		return;
 	if (head == NULL)
 		head = mdoc_head_alloc(mdoc, line, ppos, tok);
-	if (nl && tok != MDOC_Rs)
+	if (nl && tok != MDOC_Bd && tok != MDOC_Bl && tok != MDOC_Rs)
 		append_delims(mdoc, line, pos, buf);
 	if (body != NULL)
 		goto out;
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-04 22:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-04 22:30 mdocml: Discard excess head arguments for .Bd .Bl .Bk and delete schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).