summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2015-02-16 19:02:33 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2015-02-16 19:02:33 +0000
commit22cc26342fc648cbca6f1e4dbcbb6b9ca429d232 (patch)
tree1bc74394c754e87dfdf5d4190e57fce0e6a0df14
parentd8a62af12691902d4129264576d5b93f98cca2e9 (diff)
clean up post_dt() validation function;
improved diagnostics, minus six lines of code
-rw-r--r--regress/usr.bin/mandoc/mdoc/Dt/Makefile8
-rw-r--r--regress/usr.bin/mandoc/mdoc/Dt/fourargs.in8
-rw-r--r--regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_ascii9
-rw-r--r--regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_lint1
-rw-r--r--regress/usr.bin/mandoc/mdoc/Dt/noarg.out_lint1
-rw-r--r--usr.bin/mandoc/mandoc.15
-rw-r--r--usr.bin/mandoc/mdoc_validate.c84
7 files changed, 68 insertions, 48 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Dt/Makefile b/regress/usr.bin/mandoc/mdoc/Dt/Makefile
index be4b586ff7e..b0d0b0a8778 100644
--- a/regress/usr.bin/mandoc/mdoc/Dt/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Dt/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.5 2014/11/28 18:07:38 schwarze Exp $
+# $OpenBSD: Makefile,v 1.6 2015/02/16 19:02:32 schwarze Exp $
-REGRESS_TARGETS = badsec case dupe late
+REGRESS_TARGETS = badsec case dupe fourargs late
REGRESS_TARGETS += missing noarg nobody nosec order
-LINT_TARGETS = badsec case dupe late
+LINT_TARGETS = badsec case dupe fourargs late
LINT_TARGETS += missing noarg nobody nosec order
SKIP_GROFF = badsec nobody
@@ -15,6 +15,6 @@ SKIP_ASCII = badsec
# Hence, there is no bug-compatible translation from mdoc(7)
# to man(7) for this case. That's not mandoc(1)'s fault.
-SKIP_TMAN = late missing noarg nosec
+SKIP_TMAN = fourargs late missing noarg nosec
.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/mdoc/Dt/fourargs.in b/regress/usr.bin/mandoc/mdoc/Dt/fourargs.in
new file mode 100644
index 00000000000..9b4293ae429
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Dt/fourargs.in
@@ -0,0 +1,8 @@
+.Dd February 16, 2015
+.Dt DT-FOURARGS 1 amd64 bogus
+.Os OpenBSD
+.Sh NAME
+.Nm Dt-fourargs
+.Nd too many arguments after the \&Dt macro
+.Sh DESCRIPTION
+some text
diff --git a/regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_ascii b/regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_ascii
new file mode 100644
index 00000000000..9fc075e1af6
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_ascii
@@ -0,0 +1,9 @@
+DT-FOURARGS(1) General Commands Manual (amd64) DT-FOURARGS(1)
+
+NNAAMMEE
+ DDtt--ffoouurraarrggss - too many arguments after the Dt macro
+
+DDEESSCCRRIIPPTTIIOONN
+ some text
+
+OpenBSD February 16, 2015 OpenBSD
diff --git a/regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_lint b/regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_lint
new file mode 100644
index 00000000000..0d4d1494343
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Dt/fourargs.out_lint
@@ -0,0 +1 @@
+mandoc: fourargs.in:2:25: ERROR: skipping excess arguments: Dt ... bogus
diff --git a/regress/usr.bin/mandoc/mdoc/Dt/noarg.out_lint b/regress/usr.bin/mandoc/mdoc/Dt/noarg.out_lint
index 3b68668eb6b..b1fafbe4403 100644
--- a/regress/usr.bin/mandoc/mdoc/Dt/noarg.out_lint
+++ b/regress/usr.bin/mandoc/mdoc/Dt/noarg.out_lint
@@ -1 +1,2 @@
mandoc: noarg.in:2:2: WARNING: missing manual title, using UNTITLED: Dt
+mandoc: noarg.in:2:2: WARNING: missing manual section, using "": Dt UNTITLED
diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1
index c62e27e070e..79bc1c3385d 100644
--- a/usr.bin/mandoc/mandoc.1
+++ b/usr.bin/mandoc/mandoc.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mandoc.1,v 1.77 2015/02/16 16:18:02 schwarze Exp $
+.\" $OpenBSD: mandoc.1,v 1.78 2015/02/16 19:02:32 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1687,6 +1687,9 @@ or a request of the
.Ic \&de
family with more than two arguments
.It
+.Ic \&Dt
+with more than three arguments
+.It
.Ic \&TH
with more than five arguments
.It
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 0689a58da40..3d74052cf5d 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.195 2015/02/14 13:22:12 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.196 2015/02/16 19:02:32 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -2147,70 +2147,68 @@ post_dt(POST_ARGS)
mdoc->meta.vol = NULL;
mdoc->meta.arch = NULL;
- /* First check that all characters are uppercase. */
+ /* Mandatory first argument: title. */
- if (NULL != (nn = n->child))
- for (p = nn->string; *p; p++) {
- if (toupper((unsigned char)*p) == *p)
- continue;
- mandoc_vmsg(MANDOCERR_TITLE_CASE,
- mdoc->parse, nn->line,
- nn->pos + (p - nn->string),
- "Dt %s", nn->string);
- break;
- }
-
- /* No argument: msec and arch remain NULL. */
-
- if (NULL == (nn = n->child)) {
+ nn = n->child;
+ if (nn == NULL || *nn->string == '\0') {
mandoc_msg(MANDOCERR_DT_NOTITLE,
mdoc->parse, n->line, n->pos, "Dt");
mdoc->meta.title = mandoc_strdup("UNTITLED");
- mdoc->meta.vol = mandoc_strdup("LOCAL");
- goto out;
+ } else {
+ mdoc->meta.title = mandoc_strdup(nn->string);
+
+ /* Check that all characters are uppercase. */
+
+ for (p = nn->string; *p != '\0'; p++)
+ if (islower((unsigned char)*p)) {
+ mandoc_vmsg(MANDOCERR_TITLE_CASE,
+ mdoc->parse, nn->line,
+ nn->pos + (p - nn->string),
+ "Dt %s", nn->string);
+ break;
+ }
}
- /* One argument: msec and arch remain NULL. */
+ /* Mandatory second argument: section. */
- mdoc->meta.title = mandoc_strdup(
- '\0' == nn->string[0] ? "UNTITLED" : nn->string);
+ if (nn != NULL)
+ nn = nn->next;
- if (NULL == (nn = nn->next)) {
+ if (nn == NULL) {
mandoc_vmsg(MANDOCERR_MSEC_MISSING,
mdoc->parse, n->line, n->pos,
"Dt %s", mdoc->meta.title);
mdoc->meta.vol = mandoc_strdup("LOCAL");
- goto out;
+ goto out; /* msec and arch remain NULL. */
}
- /* Handles: `.Dt TITLE SEC'
- * title = TITLE,
- * volume = SEC is msec ? format(msec) : SEC,
- * msec = SEC is msec ? atoi(msec) : 0,
- * arch = NULL
- */
+ mdoc->meta.msec = mandoc_strdup(nn->string);
+
+ /* Infer volume title from section number. */
cp = mandoc_a2msec(nn->string);
- if (cp) {
- mdoc->meta.vol = mandoc_strdup(cp);
- mdoc->meta.msec = mandoc_strdup(nn->string);
- } else {
+ if (cp == NULL) {
mandoc_vmsg(MANDOCERR_MSEC_BAD, mdoc->parse,
nn->line, nn->pos, "Dt ... %s", nn->string);
mdoc->meta.vol = mandoc_strdup(nn->string);
- mdoc->meta.msec = mandoc_strdup(nn->string);
- }
+ } else
+ mdoc->meta.vol = mandoc_strdup(cp);
- /* Handle an optional architecture */
+ /* Optional third argument: architecture. */
- if ((nn = nn->next) != NULL) {
- for (p = nn->string; *p; p++)
- *p = tolower((unsigned char)*p);
- mdoc->meta.arch = mandoc_strdup(nn->string);
- }
+ if ((nn = nn->next) == NULL)
+ goto out;
+
+ for (p = nn->string; *p != '\0'; p++)
+ *p = tolower((unsigned char)*p);
+ mdoc->meta.arch = mandoc_strdup(nn->string);
+
+ /* Ignore fourth and later arguments. */
+
+ if ((nn = nn->next) != NULL)
+ mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse,
+ nn->line, nn->pos, "Dt ... %s", nn->string);
- /* Ignore any subsequent parameters... */
- /* FIXME: warn about subsequent parameters. */
out:
mdoc_node_delete(mdoc, n);
}