summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2015-02-04 22:29:29 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2015-02-04 22:29:29 +0000
commit008c7a11668624e6d96870e4567bdbf9074e46ba (patch)
treea44cb1edba188611dac70f9fa0a6515801f26fc0
parent0a590d1c07dbb852b481db08aa55ce673d3725f4 (diff)
Discard excess head arguments for .Bd .Bl .Bk and delete hwarn_eq0().
Discard empty .Bk blocks. Improve related diagnostics.
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/badargs.in2
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint1
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bk/badarg.in2
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bk/badarg.out_lint10
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/badargs.in27
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii16
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint14
-rw-r--r--usr.bin/mandoc/mdoc_macro.c10
-rw-r--r--usr.bin/mandoc/mdoc_validate.c73
9 files changed, 104 insertions, 51 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/badargs.in b/regress/usr.bin/mandoc/mdoc/Bd/badargs.in
index 0dbd2931160..4b06a528776 100644
--- a/regress/usr.bin/mandoc/mdoc/Bd/badargs.in
+++ b/regress/usr.bin/mandoc/mdoc/Bd/badargs.in
@@ -16,7 +16,7 @@ last
wins
.Ed
no type:
-.Bd -offset 0n
+.Bd -offset 0n -bogus args
displayed
text
.Ed
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint b/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint
index 25d51a2efb4..554577d4062 100644
--- a/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint
+++ b/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint
@@ -3,6 +3,7 @@ mandoc: badargs.in:12:2: ERROR: skipping all arguments: Ed tail argument
mandoc: badargs.in:14:34: WARNING: duplicate argument: Bd -compact
mandoc: badargs.in:14:43: WARNING: duplicate argument: Bd -offset 6n
mandoc: badargs.in:19:2: WARNING: missing display type, using -ragged: Bd
+mandoc: badargs.in:19:16: ERROR: skipping excess arguments: Bd ... -bogus
mandoc: badargs.in:24:2: WARNING: skipping duplicate display type: Bd -unfilled
mandoc: badargs.in:28:2: WARNING: skipping duplicate display type: Bd -ragged
mandoc: badargs.in:33:2: ERROR: NOT IMPLEMENTED: Bd -file
diff --git a/regress/usr.bin/mandoc/mdoc/Bk/badarg.in b/regress/usr.bin/mandoc/mdoc/Bk/badarg.in
index 1f331e56519..c3338e701bf 100644
--- a/regress/usr.bin/mandoc/mdoc/Bk/badarg.in
+++ b/regress/usr.bin/mandoc/mdoc/Bk/badarg.in
@@ -46,7 +46,7 @@
.Ar x x x x x x x x
.Ar x x x x x x x x
.Ar x x x x x x
-.Bk -words -murks
+.Bk -words -murks bogus
.Op o Ar a
.Ek
.Sh DESCRIPTION
diff --git a/regress/usr.bin/mandoc/mdoc/Bk/badarg.out_lint b/regress/usr.bin/mandoc/mdoc/Bk/badarg.out_lint
index 3ced9f1087d..310c156d58d 100644
--- a/regress/usr.bin/mandoc/mdoc/Bk/badarg.out_lint
+++ b/regress/usr.bin/mandoc/mdoc/Bk/badarg.out_lint
@@ -1,6 +1,6 @@
-mandoc: badarg.in:13:2: WARNING: argument count wrong: want 0 children (have 1)
-mandoc: badarg.in:22:2: WARNING: argument count wrong: want 0 children (have 1)
+mandoc: badarg.in:13:5: ERROR: skipping excess arguments: Bk ... -badarg
+mandoc: badarg.in:22:5: ERROR: skipping excess arguments: Bk ... -lines
mandoc: badarg.in:24:2: ERROR: skipping all arguments: Ek tail argument
-mandoc: badarg.in:31:2: WARNING: argument count wrong: want 0 children (have 1)
-mandoc: badarg.in:49:2: WARNING: argument count wrong: want 0 children (have 1)
-mandoc: badarg.in:54:2: WARNING: argument count wrong: want more than 0 children (have 0)
+mandoc: badarg.in:31:5: ERROR: skipping excess arguments: Bk ... -line
+mandoc: badarg.in:49:12: ERROR: skipping excess arguments: Bk ... -murks
+mandoc: badarg.in:54:2: WARNING: skipping empty macro: Bk
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/badargs.in b/regress/usr.bin/mandoc/mdoc/Bl/badargs.in
index 93a7de83d71..9c825b5ea86 100644
--- a/regress/usr.bin/mandoc/mdoc/Bl/badargs.in
+++ b/regress/usr.bin/mandoc/mdoc/Bl/badargs.in
@@ -1,4 +1,4 @@
-.Dd July 5, 2014
+.Dd February 4, 2015
.Dt BL-BADARGS 1
.Os OpenBSD
.Sh NAME
@@ -46,6 +46,31 @@ bullet enum
.It
enum bullet
.El
+unknown arguments:
+.Bl -bullet -bogus args
+.It
+bullet text
+.El
+.Bl -enum -bogus args
+.It
+enum text
+.El
+.Bl -inset -bogus args
+.It inset
+text
+.El
+.Bl -item -bogus args
+.It
+item text
+.El
+.Bl -ohang -bogus args
+.It ohang
+text
+.El
+.Bl -tag -width Ds -bogus args
+.It tag
+text
+.El
double arguments:
.Bl -tag -compact -offset 20n -width 20n -compact -offset 2n -width 6n
.It last
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii
index cdefa4da21b..ad1707b1edd 100644
--- a/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii
+++ b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii
@@ -23,7 +23,21 @@ DDEESSCCRRIIPPTTIIOONN
double type:
++oo bullet enum
1. enum bullet
+ unknown arguments:
+
+ ++oo bullet text
+
+ 1. enum text
+
+ inset text
+
+ item text
+
+ ohang
+ text
+
+ tag text
double arguments:
last wins
-OpenBSD July 5, 2014 OpenBSD
+OpenBSD February 4, 2015 OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint
index 84dc961ba06..df7541a4828 100644
--- a/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint
+++ b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint
@@ -6,7 +6,13 @@ mandoc: badargs.in:31:11: WARNING: empty argument, using 0n: Bl -width
mandoc: badargs.in:35:10: WARNING: empty argument, using 0n: Bl -width
mandoc: badargs.in:41:2: WARNING: skipping duplicate list type: Bl -enum
mandoc: badargs.in:45:2: WARNING: skipping duplicate list type: Bl -bullet
-mandoc: badargs.in:50:42: WARNING: duplicate argument: Bl -compact
-mandoc: badargs.in:50:51: WARNING: duplicate argument: Bl -offset 2n
-mandoc: badargs.in:50:62: WARNING: duplicate argument: Bl -width 6n
-mandoc: badargs.in:53:2: ERROR: skipping all arguments: El tail argument
+mandoc: badargs.in:50:13: ERROR: skipping excess arguments: Bl ... -bogus
+mandoc: badargs.in:54:11: ERROR: skipping excess arguments: Bl ... -bogus
+mandoc: badargs.in:58:12: ERROR: skipping excess arguments: Bl ... -bogus
+mandoc: badargs.in:62:11: ERROR: skipping excess arguments: Bl ... -bogus
+mandoc: badargs.in:66:12: ERROR: skipping excess arguments: Bl ... -bogus
+mandoc: badargs.in:70:20: ERROR: skipping excess arguments: Bl ... -bogus
+mandoc: badargs.in:75:42: WARNING: duplicate argument: Bl -compact
+mandoc: badargs.in:75:51: WARNING: duplicate argument: Bl -offset 2n
+mandoc: badargs.in:75:62: WARNING: duplicate argument: Bl -width 6n
+mandoc: badargs.in:78:2: ERROR: skipping all arguments: El tail argument
diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c
index b4e81d68608..679d9c92349 100644
--- a/usr.bin/mandoc/mdoc_macro.c
+++ b/usr.bin/mandoc/mdoc_macro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_macro.c,v 1.129 2015/02/04 18:03:28 schwarze Exp $ */
+/* $OpenBSD: mdoc_macro.c,v 1.130 2015/02/04 22:29:27 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1040,6 +1040,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);
@@ -1103,7 +1109,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;
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 00018254a0c..1930d9861d0 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.185 2015/02/04 19:11:17 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.186 2015/02/04 22:29:28 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -68,7 +68,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);
@@ -419,12 +418,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;
@@ -1079,8 +1072,6 @@ static void
post_literal(POST_ARGS)
{
- if (mdoc->last->tok == MDOC_Bd)
- hwarn_eq0(mdoc);
bwarn_ge1(mdoc);
/*
@@ -1406,13 +1397,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;
}
@@ -1422,17 +1421,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
@@ -1440,25 +1437,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
@@ -1544,9 +1539,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