summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-07-05 01:11:34 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-07-05 01:11:34 +0000
commit1e7c3f59836fc395283cd75fcf7a9229c2157602 (patch)
treeabead363fb129d7fc9488b1baa60c33c5422245e
parent6097cb332d18be0b620a77386e97d76c8c3aeeed (diff)
Cleanup regarding -offset and -width:
* Bugfix: Last one wins, not first one. * Fix .Bl -width without argument: it means 0n, so do not ignore it. * Report macro names, argument names and fallbacks in related messages. * Simplify: Garbage collect auxiliary variables in pre_bd() and pre_bl().
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/Makefile6
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/badargs.in17
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/badargs.out_ascii13
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint4
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/Makefile10
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/badargs.in44
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii26
-rw-r--r--regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint10
-rw-r--r--usr.bin/mandoc/mandoc.h5
-rw-r--r--usr.bin/mandoc/mdoc_validate.c108
-rw-r--r--usr.bin/mandoc/read.c3
11 files changed, 180 insertions, 66 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/Makefile b/regress/usr.bin/mandoc/mdoc/Bd/Makefile
index 1231c86730b..f13a8ad186c 100644
--- a/regress/usr.bin/mandoc/mdoc/Bd/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Bd/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.11 2014/07/04 01:50:03 schwarze Exp $
+# $OpenBSD: Makefile,v 1.12 2014/07/05 01:11:33 schwarze Exp $
REGRESS_TARGETS = blank nested spacing
-REGRESS_TARGETS += notype empty offset-empty
+REGRESS_TARGETS += notype badargs empty offset-empty
REGRESS_TARGETS += break broken
-LINT_TARGETS = nested notype break broken
+LINT_TARGETS = nested notype badargs break broken
# groff defect:
# - a display breaking another block continues indefinitely
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/badargs.in b/regress/usr.bin/mandoc/mdoc/Bd/badargs.in
new file mode 100644
index 00000000000..5177d9c6e13
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bd/badargs.in
@@ -0,0 +1,17 @@
+.Dd July 4, 2014
+.Dt BD-BADARGS 1
+.Os OpenBSD
+.Sh NAME
+.Nm Bd-badargs
+.Nd display block with bad arguments
+.Sh DESCRIPTION
+trailing -offset:
+.Bd -ragged -offset
+is
+ignored
+.Ed tail argument
+double -compact and -offset
+.Bd -ragged -compact -offset 42n -compact -offset 6n
+last
+wins
+.Ed
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_ascii b/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_ascii
new file mode 100644
index 00000000000..c0ecc18ca48
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_ascii
@@ -0,0 +1,13 @@
+BD-BADARGS(1) OpenBSD Reference Manual BD-BADARGS(1)
+
+NNAAMMEE
+ BBdd--bbaaddaarrggss - display block with bad arguments
+
+DDEESSCCRRIIPPTTIIOONN
+ trailing -offset:
+
+ is ignored
+ double -compact and -offset
+ last wins
+
+OpenBSD July 4, 2014 OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint b/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint
new file mode 100644
index 00000000000..83076847fba
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bd/badargs.out_lint
@@ -0,0 +1,4 @@
+mandoc: badargs.in:9:20: WARNING: skipping empty argument: Bd -offset
+mandoc: badargs.in:12:2: ERROR: skipping all arguments: Ed tail argument
+mandoc: badargs.in:14:43: WARNING: duplicate argument: Bd -compact
+mandoc: badargs.in:14:51: WARNING: duplicate argument: Bd -offset 6n
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/Makefile b/regress/usr.bin/mandoc/mdoc/Bl/Makefile
index bb848afc905..6c18108a512 100644
--- a/regress/usr.bin/mandoc/mdoc/Bl/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Bl/Makefile
@@ -1,13 +1,15 @@
-# $OpenBSD: Makefile,v 1.21 2014/07/04 01:50:03 schwarze Exp $
+# $OpenBSD: Makefile,v 1.22 2014/07/05 01:11:33 schwarze Exp $
REGRESS_TARGETS = item inset diag ohang bullet dash enum hang tag
REGRESS_TARGETS += column extend nested
-REGRESS_TARGETS += notype multitype multitag
-REGRESS_TARGETS += empty noIt emptyhead emptytag emptyitem
+REGRESS_TARGETS += notype multitype badargs
+REGRESS_TARGETS += empty noIt emptyhead emptytag emptyitem multitag
REGRESS_TARGETS += bareTa unclosed break broken
-LINT_TARGETS = notype noIt emptyhead emptytag emptyitem break broken
+LINT_TARGETS = notype badargs
+LINT_TARGETS += noIt emptyhead emptytag emptyitem
+LINT_TARGETS += break broken
# groff-1.22.2 defects:
# - lists with missing or late type ruin indentation
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/badargs.in b/regress/usr.bin/mandoc/mdoc/Bl/badargs.in
new file mode 100644
index 00000000000..7424610b9fb
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bl/badargs.in
@@ -0,0 +1,44 @@
+.Dd July 4, 2014
+.Dt BL-BADARGS 1
+.Os OpenBSD
+.Sh NAME
+.Nm Bl-badargs
+.Nd list with bad arguments
+.Sh DESCRIPTION
+trailing -offset:
+.Bl -bullet -offset
+.It
+is ignored
+.El
+trailing -width:
+.Bl -bullet -width
+.It
+bullet
+.El
+.Bl -dash -width
+.It
+dash
+.El
+.\" XXX Doesn't work with -Tman yet.
+.\" .Bl -enum -width
+.\" .It
+.\" enum
+.\" .El
+.Bl -hyphen -width
+.It
+hyphen
+.El
+.Bl -hang -width
+.It hang
+item
+.El
+.Bl -tag -width
+.It tag
+Here we need a very long line.
+It must be sufficiently long such that it wraps the line.
+.El
+double arguments:
+.Bl -tag -compact -offset 20n -width 20n -compact -offset 2n -width 6n
+.It last
+wins
+.El tail argument
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii
new file mode 100644
index 00000000000..f865b9680a5
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_ascii
@@ -0,0 +1,26 @@
+BL-BADARGS(1) OpenBSD Reference Manual BL-BADARGS(1)
+
+NNAAMMEE
+ BBll--bbaaddaarrggss - list with bad arguments
+
+DDEESSCCRRIIPPTTIIOONN
+ trailing -offset:
+
+ oo is ignored
+ trailing -width:
+
+ oo bullet
+
+ -- dash
+
+ -- hyphen
+
+ hang item
+
+ tag
+ Here we need a very long line. It must be sufficiently long such that
+ it wraps the line.
+ double arguments:
+ last wins
+
+OpenBSD July 4, 2014 OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint
new file mode 100644
index 00000000000..dc119687440
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Bl/badargs.out_lint
@@ -0,0 +1,10 @@
+mandoc: badargs.in:9:20: WARNING: empty argument, using 0n: Bl -offset
+mandoc: badargs.in:14:19: WARNING: empty argument, using 0n: Bl -width
+mandoc: badargs.in:18:17: WARNING: empty argument, using 0n: Bl -width
+mandoc: badargs.in:27:19: WARNING: empty argument, using 0n: Bl -width
+mandoc: badargs.in:31:17: WARNING: empty argument, using 0n: Bl -width
+mandoc: badargs.in:35:16: WARNING: empty argument, using 0n: Bl -width
+mandoc: badargs.in:41:51: WARNING: duplicate argument: Bl -compact
+mandoc: badargs.in:41:59: WARNING: duplicate argument: Bl -offset 2n
+mandoc: badargs.in:41:69: WARNING: duplicate argument: Bl -width 6n
+mandoc: badargs.in:44:2: ERROR: skipping all arguments: El tail argument
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index 63e84a82d02..e3cdd684e9a 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.78 2014/07/04 16:11:41 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.79 2014/07/05 01:11:33 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -87,6 +87,7 @@ enum mandocerr {
MANDOCERR_REQ_EMPTY, /* skipping empty request: request */
MANDOCERR_COND_EMPTY, /* conditional request controls empty scope */
MANDOCERR_MACRO_EMPTY, /* skipping empty macro: macro */
+ MANDOCERR_ARG_EMPTY, /* empty argument, using 0n: macro arg */
MANDOCERR_ARGCWARN, /* argument count wrong */
MANDOCERR_BD_NOTYPE, /* missing display type, using -ragged */
MANDOCERR_BL_LATETYPE, /* list type is not the first argument: arg */
@@ -99,7 +100,7 @@ enum mandocerr {
/* related to bad macro arguments */
MANDOCERR_IGNARGV, /* skipping argument */
- MANDOCERR_ARGVREP, /* duplicate argument */
+ MANDOCERR_ARG_REP, /* duplicate argument: macro arg */
MANDOCERR_DISPREP, /* duplicate display type */
MANDOCERR_LISTREP, /* duplicate list type */
MANDOCERR_BADATT, /* unknown AT&T UNIX version */
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index a1ff663a527..67ca6daa37c 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.144 2014/07/04 16:11:41 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.145 2014/07/05 01:11:33 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -590,10 +590,10 @@ pre_display(PRE_ARGS)
static int
pre_bl(PRE_ARGS)
{
- int i, comp, dup;
- const char *offs, *width;
- enum mdoc_list lt;
struct mdoc_node *np;
+ struct mdoc_argv *argv;
+ int i;
+ enum mdoc_list lt;
if (MDOC_BLOCK != n->type) {
if (ENDBODY_NOT != n->end) {
@@ -615,10 +615,9 @@ pre_bl(PRE_ARGS)
*/
for (i = 0; n->args && i < (int)n->args->argc; i++) {
+ argv = n->args->argv + i;
lt = LIST__NONE;
- dup = comp = 0;
- width = offs = NULL;
- switch (n->args->argv[i].arg) {
+ switch (argv->arg) {
/* Set list types. */
case MDOC_Bullet:
lt = LIST_bullet;
@@ -655,43 +654,45 @@ pre_bl(PRE_ARGS)
break;
/* Set list arguments. */
case MDOC_Compact:
- dup = n->norm->Bl.comp;
- comp = 1;
+ if (n->norm->Bl.comp)
+ mandoc_msg(MANDOCERR_ARG_REP,
+ mdoc->parse, argv->line,
+ argv->pos, "Bl -compact");
+ n->norm->Bl.comp = 1;
break;
case MDOC_Width:
- /* NB: this can be empty! */
- if (n->args->argv[i].sz) {
- width = n->args->argv[i].value[0];
- dup = (NULL != n->norm->Bl.width);
+ if (0 == argv->sz) {
+ mandoc_msg(MANDOCERR_ARG_EMPTY,
+ mdoc->parse, argv->line,
+ argv->pos, "Bl -width");
+ n->norm->Bl.width = "0n";
break;
}
- mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
+ if (NULL != n->norm->Bl.width)
+ mandoc_vmsg(MANDOCERR_ARG_REP,
+ mdoc->parse, argv->line,
+ argv->pos, "Bl -width %s",
+ argv->value[0]);
+ n->norm->Bl.width = argv->value[0];
break;
case MDOC_Offset:
- /* NB: this can be empty! */
- if (n->args->argv[i].sz) {
- offs = n->args->argv[i].value[0];
- dup = (NULL != n->norm->Bl.offs);
+ if (0 == argv->sz) {
+ mandoc_msg(MANDOCERR_ARG_EMPTY,
+ mdoc->parse, argv->line,
+ argv->pos, "Bl -offset");
break;
}
- mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
+ if (NULL != n->norm->Bl.offs)
+ mandoc_vmsg(MANDOCERR_ARG_REP,
+ mdoc->parse, argv->line,
+ argv->pos, "Bl -offset %s",
+ argv->value[0]);
+ n->norm->Bl.offs = argv->value[0];
break;
default:
continue;
}
- /* Check: duplicate auxiliary arguments. */
-
- if (dup)
- mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP);
-
- if (comp && ! dup)
- n->norm->Bl.comp = comp;
- if (offs && ! dup)
- n->norm->Bl.offs = offs;
- if (width && ! dup)
- n->norm->Bl.width = width;
-
/* Check: multiple list types. */
if (LIST__NONE != lt && n->norm->Bl.type != LIST__NONE)
@@ -775,10 +776,10 @@ pre_bl(PRE_ARGS)
static int
pre_bd(PRE_ARGS)
{
- int i, dup, comp;
- enum mdoc_disp dt;
- const char *offs;
struct mdoc_node *np;
+ struct mdoc_argv *argv;
+ int i;
+ enum mdoc_disp dt;
if (MDOC_BLOCK != n->type) {
if (ENDBODY_NOT != n->end) {
@@ -794,11 +795,10 @@ pre_bd(PRE_ARGS)
}
for (i = 0; n->args && i < (int)n->args->argc; i++) {
+ argv = n->args->argv + i;
dt = DISP__NONE;
- dup = comp = 0;
- offs = NULL;
- switch (n->args->argv[i].arg) {
+ switch (argv->arg) {
case MDOC_Centred:
dt = DISP_centred;
break;
@@ -818,35 +818,31 @@ pre_bd(PRE_ARGS)
mdoc_nmsg(mdoc, n, MANDOCERR_BADDISP);
return(0);
case MDOC_Offset:
- /* NB: this can be empty! */
- if (n->args->argv[i].sz) {
- offs = n->args->argv[i].value[0];
- dup = (NULL != n->norm->Bd.offs);
+ if (0 == argv->sz) {
+ mandoc_msg(MANDOCERR_ARG_EMPTY,
+ mdoc->parse, argv->line,
+ argv->pos, "Bd -offset");
break;
}
- mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
+ if (NULL != n->norm->Bd.offs)
+ mandoc_vmsg(MANDOCERR_ARG_REP,
+ mdoc->parse, argv->line,
+ argv->pos, "Bd -offset %s",
+ argv->value[0]);
+ n->norm->Bd.offs = argv->value[0];
break;
case MDOC_Compact:
- comp = 1;
- dup = n->norm->Bd.comp;
+ if (n->norm->Bd.comp)
+ mandoc_msg(MANDOCERR_ARG_REP,
+ mdoc->parse, argv->line,
+ argv->pos, "Bd -compact");
+ n->norm->Bd.comp = 1;
break;
default:
abort();
/* NOTREACHED */
}
- /* Check whether we have duplicates. */
-
- if (dup)
- mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP);
-
- /* Make our auxiliary assignments. */
-
- if (offs && ! dup)
- n->norm->Bd.offs = offs;
- if (comp && ! dup)
- n->norm->Bd.comp = comp;
-
/* Check whether a type has already been assigned. */
if (DISP__NONE != dt && n->norm->Bd.type != DISP__NONE)
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 920cf2f6065..3642c63a027 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.39 2014/07/04 16:11:41 schwarze Exp $ */
+/* $Id: read.c,v 1.40 2014/07/05 01:11:33 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -123,6 +123,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"skipping empty request",
"conditional request controls empty scope",
"skipping empty macro",
+ "empty argument, using 0n",
"argument count wrong",
"missing display type, using -ragged",
"list type is not the first argument",