-/* $OpenBSD: main.c,v 1.199 2017/07/01 12:53:56 schwarze Exp $ */
+/* $OpenBSD: main.c,v 1.200 2017/07/02 15:31:48 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
if (man == NULL)
return;
- if (curp->mmin < MANDOCERR_STYLE)
- mandoc_xr_reset();
+ mandoc_xr_reset();
if (man->macroset == MACROSET_MDOC) {
if (curp->outtype != OUTT_TREE || !curp->outopts->noval)
mdoc_validate(man);
break;
}
}
- check_xr(file);
+ if (curp->mmin < MANDOCERR_STYLE)
+ check_xr(file);
mparse_updaterc(curp->mp, &rc);
}
manpath_base(&paths);
for (xr = mandoc_xr_get(); xr != NULL; xr = xr->next) {
+ if (xr->line == -1)
+ continue;
search.arch = NULL;
search.sec = xr->sec;
search.outkey = NULL;
-.\" $OpenBSD: mandoc.1,v 1.134 2017/07/01 09:47:23 schwarze Exp $
+.\" $OpenBSD: mandoc.1,v 1.135 2017/07/02 15:31:48 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: July 1 2017 $
+.Dd $Mdocdate: July 2 2017 $
.Dt MANDOC 1
.Os
.Sh NAME
.Pq mdoc
A standard section header occurs in a section of the manual
where it normally isn't useful.
+.It Sy "cross reference to self"
+.Pq mdoc
+An
+.Ic \&Xr
+macro refers to a name and section matching the section of the present
+manual page and a name mentioned in an
+.Ic \&Nm
+macro in the NAME or SYNOPSIS section, or in an
+.Ic \&Fn
+or
+.Ic \&Fo
+macro in the SYNOPSIS.
+Consider using
+.Ic \&Nm
+or
+.Ic \&Fn
+instead of
+.Ic \&Xr .
.It Sy "unusual Xr order"
.Pq mdoc
In the SEE ALSO section, an
-/* $OpenBSD: mandoc.h,v 1.180 2017/07/01 09:47:23 schwarze Exp $ */
+/* $OpenBSD: mandoc.h,v 1.181 2017/07/02 15:31:48 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */
MANDOCERR_SEC_REP, /* duplicate section title: Sh title */
MANDOCERR_SEC_MSEC, /* unexpected section: Sh title for ... only */
+ MANDOCERR_XR_SELF, /* cross reference to self: Xr name sec */
MANDOCERR_XR_ORDER, /* unusual Xr order: ... after ... */
MANDOCERR_XR_PUNCT, /* unusual Xr punctuation: ... after ... */
MANDOCERR_AN_MISSING, /* AUTHORS section without An macro */
-/* $OpenBSD: mandoc_xr.c,v 1.1 2017/07/01 09:47:23 schwarze Exp $ */
+/* $OpenBSD: mandoc_xr.c,v 1.2 2017/07/02 15:31:48 schwarze Exp $ */
/*
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
*
xr_first = xr_last = NULL;
}
-void
+int
mandoc_xr_add(const char *sec, const char *name, int line, int pos)
{
- struct mandoc_xr *xr;
+ struct mandoc_xr *xr, *oxr;
const char *pend;
size_t ssz, nsz, tsz;
unsigned int slot;
+ int ret;
uint32_t hv;
if (xr_hash == NULL)
- return;
+ return 0;
ssz = strlen(sec) + 1;
nsz = strlen(name) + 1;
pend = xr->hashkey + tsz;
hv = ohash_interval(xr->hashkey, &pend);
slot = ohash_lookup_memory(xr_hash, xr->hashkey, tsz, hv);
- if (ohash_find(xr_hash, slot) == NULL) {
+ if ((oxr = ohash_find(xr_hash, slot)) == NULL) {
ohash_insert(xr_hash, slot, xr);
if (xr_first == NULL)
xr_first = xr;
else
xr_last->next = xr;
xr_last = xr;
- } else
- free(xr);
+ return 0;
+ }
+
+ ret = (oxr->line == -1) ^ (xr->line == -1);
+ if (xr->line == -1)
+ oxr->line = -1;
+ free(xr);
+ return ret;
}
struct mandoc_xr *
-/* $OpenBSD: mandoc_xr.h,v 1.1 2017/07/01 09:47:23 schwarze Exp $ */
+/* $OpenBSD: mandoc_xr.h,v 1.2 2017/07/02 15:31:48 schwarze Exp $ */
/*
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
*
struct mandoc_xr *next;
char *sec;
char *name;
- int line;
+ int line; /* Or -1 for this page's own names. */
int pos;
char hashkey[];
};
void mandoc_xr_reset(void);
-void mandoc_xr_add(const char *, const char *, int, int);
+int mandoc_xr_add(const char *, const char *, int, int);
struct mandoc_xr *mandoc_xr_get(void);
void mandoc_xr_free(void);
-/* $OpenBSD: mdoc_validate.c,v 1.261 2017/07/01 09:47:23 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.262 2017/07/02 15:31:48 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*')))
mandoc_msg(MANDOCERR_FN_PAREN, mdoc->parse,
n->line, n->pos + pos, n->string);
+ if (n->sec == SEC_SYNOPSIS && mdoc->meta.msec != NULL)
+ mandoc_xr_add(mdoc->meta.msec, n->string, -1, -1);
}
static void
n = mdoc->last;
+ if ((n->sec == SEC_NAME || n->sec == SEC_SYNOPSIS) &&
+ n->child != NULL && n->child->type == ROFFT_TEXT &&
+ mdoc->meta.msec != NULL)
+ mandoc_xr_add(mdoc->meta.msec, n->child->string, -1, -1);
+
if (n->last != NULL &&
(n->last->tok == MDOC_Pp ||
n->last->tok == MDOC_Lp))
n->line, n->pos, "Xr %s", nch->string);
} else {
assert(nch->next == n->last);
- mandoc_xr_add(nch->next->string, nch->string,
- nch->line, nch->pos);
+ if(mandoc_xr_add(nch->next->string, nch->string,
+ nch->line, nch->pos))
+ mandoc_vmsg(MANDOCERR_XR_SELF, mdoc->parse,
+ nch->line, nch->pos, "Xr %s %s",
+ nch->string, nch->next->string);
}
post_delim(mdoc);
}
-/* $OpenBSD: read.c,v 1.156 2017/07/01 09:47:23 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.157 2017/07/02 15:31:48 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
"sections out of conventional order",
"duplicate section title",
"unexpected section",
+ "cross reference to self",
"unusual Xr order",
"unusual Xr punctuation",
"AUTHORS section without An macro",