summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2021-06-02 18:28:19 +0000
committerIngo Schwarze <schwarze@openbsd.org>2021-06-02 18:28:19 +0000
commit81fed4ca2ec0fa379abfe067dedb8a3a4b32ab82 (patch)
treefc90cb868eb26afd126066004b40e633765d76e7
parente4b7709a1c43fd251397020963a1ce703c8229b4 (diff)
downloadmandoc-81fed4ca2ec0fa379abfe067dedb8a3a4b32ab82.tar.gz
In -W style mode, check .Xr links along the full manpath because
that is more useful for validating manuals of non-base software. Nothing changes in -W all mode: by default for -T lint, we still assume we want to check base system conventions, including usually not wanting to link to non-base manual pages. The use case, a partial idea how to handle it, and a preliminary patch was originally presented by kn@, then refined by me. Final patch tested and OK'ed by kn@.
-rw-r--r--main.c41
-rw-r--r--mandoc.139
-rw-r--r--mandoc.h2
-rw-r--r--mandoc_msg.c2
4 files changed, 54 insertions, 30 deletions
diff --git a/main.c b/main.c
index db2ed168..58954f61 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2012, 2014-2021 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
*
@@ -93,7 +93,7 @@ struct outstate {
int mandocdb(int, char *[]);
-static void check_xr(void);
+static void check_xr(struct manpaths *);
static int fs_lookup(const struct manpaths *,
size_t ipath, const char *,
const char *, const char *,
@@ -104,7 +104,7 @@ static int fs_search(const struct mansearch *,
static void glob_esc(char **, const char *, const char *);
static void outdata_alloc(struct outstate *, struct manoutput *);
static void parse(struct mparse *, int, const char *,
- struct outstate *, struct manoutput *);
+ struct outstate *, struct manconf *);
static void passthrough(int, int);
static void process_onefile(struct mparse *, struct manpage *,
int, struct outstate *, struct manconf *);
@@ -452,7 +452,8 @@ main(int argc, char *argv[])
/* Read the configuration file. */
- if (search.argmode != ARG_FILE)
+ if (search.argmode != ARG_FILE ||
+ mandoc_msg_getmin() == MANDOCERR_STYLE)
manconf_parse(&conf, conf_file, defpaths, auxpaths);
/* man(1): Resolve each name individually. */
@@ -865,7 +866,7 @@ process_onefile(struct mparse *mp, struct manpage *resp, int startdir,
}
if (resp->form == FORM_SRC)
- parse(mp, fd, resp->file, outst, &conf->output);
+ parse(mp, fd, resp->file, outst, conf);
else {
passthrough(fd, conf->output.synopsisonly);
outst->had_output = 1;
@@ -886,8 +887,9 @@ process_onefile(struct mparse *mp, struct manpage *resp, int startdir,
static void
parse(struct mparse *mp, int fd, const char *file,
- struct outstate *outst, struct manoutput *outconf)
+ struct outstate *outst, struct manconf *conf)
{
+ static struct manpaths basepaths;
static int previous;
struct roff_meta *meta;
@@ -913,7 +915,7 @@ parse(struct mparse *mp, int fd, const char *file,
return;
if (outst->outdata == NULL)
- outdata_alloc(outst, outconf);
+ outdata_alloc(outst, &conf->output);
else if (outst->outtype == OUTT_HTML)
html_reset(outst->outdata);
@@ -970,24 +972,25 @@ parse(struct mparse *mp, int fd, const char *file,
break;
}
}
- if (outconf->tag != NULL && outconf->tag_found == 0 &&
- tag_exists(outconf->tag))
- outconf->tag_found = 1;
- if (mandoc_msg_getmin() < MANDOCERR_STYLE)
- check_xr();
+ if (conf->output.tag != NULL && conf->output.tag_found == 0 &&
+ tag_exists(conf->output.tag))
+ conf->output.tag_found = 1;
+
+ if (mandoc_msg_getmin() < MANDOCERR_STYLE) {
+ if (basepaths.sz == 0)
+ manpath_base(&basepaths);
+ check_xr(&basepaths);
+ } else if (mandoc_msg_getmin() < MANDOCERR_WARNING)
+ check_xr(&conf->manpath);
}
static void
-check_xr(void)
+check_xr(struct manpaths *paths)
{
- static struct manpaths paths;
struct mansearch search;
struct mandoc_xr *xr;
size_t sz;
- if (paths.sz == 0)
- manpath_base(&paths);
-
for (xr = mandoc_xr_get(); xr != NULL; xr = xr->next) {
if (xr->line == -1)
continue;
@@ -996,9 +999,9 @@ check_xr(void)
search.outkey = NULL;
search.argmode = ARG_NAME;
search.firstmatch = 1;
- if (mansearch(&search, &paths, 1, &xr->name, NULL, &sz))
+ if (mansearch(&search, paths, 1, &xr->name, NULL, &sz))
continue;
- if (fs_search(&search, &paths, xr->name, NULL, &sz) != -1)
+ if (fs_search(&search, paths, xr->name, NULL, &sz) != -1)
continue;
if (xr->count == 1)
mandoc_msg(MANDOCERR_XR_BAD, xr->line,
diff --git a/mandoc.1 b/mandoc.1
index ffc291dd..7bd0911a 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,6 +1,6 @@
.\" $OpenBSD: mandoc.1,v 1.166 2020/02/15 15:28:01 schwarze Exp $
.\"
-.\" Copyright (c) 2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
+.\" Copyright (c) 2012, 2014-2021 Ingo Schwarze <schwarze@openbsd.org>
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
@@ -922,14 +922,6 @@ generated by CVS
or
.Ic NetBSD
keyword substitution as conventionally used in these operating systems.
-.It Sy "referenced manual not found"
-.Pq mdoc
-An
-.Ic \&Xr
-macro references a manual page that is not found in the base system.
-The path to look for base system manuals is configurable at compile
-time and defaults to
-.Pa /usr/share/man : /usr/X11R6/man .
.El
.Ss Style suggestions
.Bl -ohang
@@ -1016,6 +1008,35 @@ list contains two consecutive
entries describing the same
.Ic \&Er
number.
+.It Sy "referenced manual not found"
+.Pq mdoc
+An
+.Ic \&Xr
+macro references a manual page that was not found.
+When running with
+.Fl W Cm base ,
+the search is restricted to the base system, by default to
+.Pa /usr/share/man : Ns Pa /usr/X11R6/man .
+This path can be configured at compile time using the
+.Dv MANPATH_BASE
+preprocessor macro.
+When running with
+.Fl W Cm style ,
+the search is done along the full search path as described in the
+.Xr man 1
+manual page, respecting the
+.Fl m
+and
+.Fl M
+command line options, the
+.Ev MANPATH
+environment variable, the
+.Xr man.conf 5
+file and falling back to the default of
+.Pa /usr/share/man : Ns Pa /usr/X11R6/man : Ns Pa /usr/local/man ,
+also configurable at compile time using the
+.Dv MANPATH_DEFAULT
+preprocessor macro.
.It Sy "trailing delimiter"
.Pq mdoc
The last argument of an
diff --git a/mandoc.h b/mandoc.h
index 81941ffe..b6e5c981 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -54,7 +54,6 @@ enum mandocerr {
MANDOCERR_ARCH_BAD, /* unknown architecture: Dt ... arch */
MANDOCERR_OS_ARG, /* operating system explicitly specified: Os ... */
MANDOCERR_RCS_MISSING, /* RCS id missing */
- MANDOCERR_XR_BAD, /* referenced manual not found: Xr name sec */
MANDOCERR_STYLE, /* ===== start of style suggestions ===== */
@@ -68,6 +67,7 @@ enum mandocerr {
MANDOCERR_BX, /* consider using OS macro: macro */
MANDOCERR_ER_ORDER, /* errnos out of order: Er ... */
MANDOCERR_ER_REP, /* duplicate errno: Er ... */
+ MANDOCERR_XR_BAD, /* referenced manual not found: Xr name sec */
MANDOCERR_DELIM, /* trailing delimiter: macro ... */
MANDOCERR_DELIM_NB, /* no blank before trailing delimiter: macro ... */
MANDOCERR_FI_SKIP, /* fill mode already enabled, skipping: fi */
diff --git a/mandoc_msg.c b/mandoc_msg.c
index 3ec86744..7a127331 100644
--- a/mandoc_msg.c
+++ b/mandoc_msg.c
@@ -55,7 +55,6 @@ static const char *const type_message[MANDOCERR_MAX] = {
"unknown architecture",
"operating system explicitly specified",
"RCS id missing",
- "referenced manual not found",
"generic style suggestion",
@@ -69,6 +68,7 @@ static const char *const type_message[MANDOCERR_MAX] = {
"consider using OS macro",
"errnos out of order",
"duplicate errno",
+ "referenced manual not found",
"trailing delimiter",
"no blank before trailing delimiter",
"fill mode already enabled, skipping",