summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2016-12-28 17:34:18 +0000
committerIngo Schwarze <schwarze@openbsd.org>2016-12-28 17:34:18 +0000
commitd7c46d2d16226010fc23d4fc28e1515a70a52ed3 (patch)
treedaef3e4a96ce67b1d9d64938fca56436df268077
parente3f5b4421b6d2e53c29f596fe31bbca8f1b4ca0c (diff)
downloadmandoc-d7c46d2d16226010fc23d4fc28e1515a70a52ed3.tar.gz
Make the second, section number argument of .Xr mandatory.
In fact, we have been requiring it for many years. The only reason to not warn when it was missing was excessive traditionalism - it was optional in 4.4BSD.
-rw-r--r--mandoc.17
-rw-r--r--mandoc.h1
-rw-r--r--mdoc.77
-rw-r--r--mdoc_validate.c20
-rw-r--r--read.c1
5 files changed, 30 insertions, 6 deletions
diff --git a/mandoc.1 b/mandoc.1
index c8ed310f..65616272 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1147,6 +1147,13 @@ macro is immediately followed by an
.Ic \&Re
macro on the next input line.
Such an empty block does not produce any output.
+.It Sy "missing section argument"
+.Pq mdoc
+An
+.Ic \&Xr
+macro lacks its second, section number argument.
+The first argument, i.e. the name, is printed, but without subsequent
+parantheses.
.It Sy "missing -std argument, adding it"
.Pq mdoc
An
diff --git a/mandoc.h b/mandoc.h
index 90ebe9c3..79756aec 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -107,6 +107,7 @@ enum mandocerr {
MANDOCERR_BF_BADFONT, /* unknown font type, using \fR: Bf font */
MANDOCERR_PF_SKIP, /* nothing follows prefix: Pf arg */
MANDOCERR_RS_EMPTY, /* empty reference block: Rs */
+ MANDOCERR_XR_NOSEC, /* missing section argument: Xr arg */
MANDOCERR_ARG_STD, /* missing -std argument, adding it: macro */
MANDOCERR_OP_EMPTY, /* missing option string, using "": OP */
MANDOCERR_UR_NOHEAD, /* missing resource identifier, using "": UR */
diff --git a/mdoc.7 b/mdoc.7
index bf5d9afd..a283254d 100644
--- a/mdoc.7
+++ b/mdoc.7
@@ -2714,14 +2714,13 @@ Link to another manual
.Pq Qq cross-reference .
Its syntax is as follows:
.Pp
-.D1 Pf \. Sx \&Xr Ar name Op section
+.D1 Pf \. Sx \&Xr Ar name section
.Pp
Cross reference the
.Ar name
and
.Ar section
-number of another man page;
-omitting the section number is rarely useful.
+number of another man page.
.Pp
Examples:
.Dl \&.Xr mandoc 1
@@ -3033,7 +3032,7 @@ then the macro accepts an arbitrary number of arguments.
.It Sx \&Ux Ta Yes Ta Yes Ta n
.It Sx \&Va Ta Yes Ta Yes Ta n
.It Sx \&Vt Ta Yes Ta Yes Ta >0
-.It Sx \&Xr Ta Yes Ta Yes Ta >0
+.It Sx \&Xr Ta Yes Ta Yes Ta 2
.It Sx \&br Ta \&No Ta \&No Ta 0
.It Sx \&sp Ta \&No Ta \&No Ta 1
.El
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 97985558..f5f73df0 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -103,6 +103,7 @@ static void post_sh_authors(POST_ARGS);
static void post_sm(POST_ARGS);
static void post_st(POST_ARGS);
static void post_std(POST_ARGS);
+static void post_xr(POST_ARGS);
static v_post mdoc_valids[MDOC_MAX] = {
NULL, /* Ap */
@@ -145,7 +146,7 @@ static v_post mdoc_valids[MDOC_MAX] = {
post_st, /* St */
NULL, /* Va */
NULL, /* Vt */
- NULL, /* Xr */
+ post_xr, /* Xr */
NULL, /* %A */
post_hyph, /* %B */ /* FIXME: can be used outside Rs/Re. */
NULL, /* %D */
@@ -1807,6 +1808,21 @@ post_sh_head(POST_ARGS)
}
static void
+post_xr(POST_ARGS)
+{
+ struct roff_node *n, *nch;
+
+ n = mdoc->last;
+ nch = n->child;
+ if (nch->next == NULL) {
+ mandoc_vmsg(MANDOCERR_XR_NOSEC, mdoc->parse,
+ n->line, n->pos, "Xr %s", nch->string);
+ return;
+ }
+ assert(nch->next == n->last);
+}
+
+static void
post_ignpar(POST_ARGS)
{
struct roff_node *np;
@@ -2002,7 +2018,7 @@ post_dt(POST_ARGS)
}
}
- /* Mandatory second argument: section. */
+ /* Mandatory second argument: section. */
if (nn != NULL)
nn = nn->next;
diff --git a/read.c b/read.c
index 851e9153..9bfe2bda 100644
--- a/read.c
+++ b/read.c
@@ -150,6 +150,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"unknown font type, using \\fR",
"nothing follows prefix",
"empty reference block",
+ "missing section argument",
"missing -std argument, adding it",
"missing option string, using \"\"",
"missing resource identifier, using \"\"",