From: schwarze Date: Wed, 2 Jun 2021 18:27:36 +0000 (+0000) Subject: In -W style mode, check .Xr links along the full manpath because X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=28ca454f357c592e5d7a31e2814073999a4b9b72;p=openbsd 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@. --- diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 0647c2e585c..d309d969a41 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,6 +1,6 @@ -/* $OpenBSD: main.c,v 1.256 2021/02/19 19:49:49 kn Exp $ */ +/* $OpenBSD: main.c,v 1.257 2021/06/02 18:27:36 schwarze Exp $ */ /* - * Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze + * Copyright (c) 2010-2012, 2014-2021 Ingo Schwarze * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010 Joerg Sonnenberger * @@ -92,7 +92,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 *, @@ -103,7 +103,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 *); @@ -430,7 +430,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. */ @@ -841,7 +842,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; @@ -862,8 +863,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; @@ -889,7 +891,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); @@ -946,24 +948,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; @@ -972,9 +975,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/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 5f6bd39ce59..acb737ca6c9 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,6 +1,6 @@ -.\" $OpenBSD: mandoc.1,v 1.174 2021/04/04 06:18:58 jmc Exp $ +.\" $OpenBSD: mandoc.1,v 1.175 2021/06/02 18:27:36 schwarze Exp $ .\" -.\" Copyright (c) 2012, 2014-2020 Ingo Schwarze +.\" Copyright (c) 2012, 2014-2021 Ingo Schwarze .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" .\" Permission to use, copy, modify, and distribute this software for any @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 4 2021 $ +.Dd $Mdocdate: June 2 2021 $ .Dt MANDOC 1 .Os .Sh NAME @@ -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 : Ns Pa /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/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 3d1a3f92fcc..40f54b88bc3 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.211 2020/09/01 18:24:09 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.212 2021/06/02 18:27:37 schwarze Exp $ */ /* * Copyright (c) 2012-2020 Ingo Schwarze * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons @@ -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/usr.bin/mandoc/mandoc_msg.c b/usr.bin/mandoc/mandoc_msg.c index d40b7e582bf..c6f2c7205b9 100644 --- a/usr.bin/mandoc/mandoc_msg.c +++ b/usr.bin/mandoc/mandoc_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc_msg.c,v 1.10 2020/09/01 18:24:10 schwarze Exp $ */ +/* $OpenBSD: mandoc_msg.c,v 1.11 2021/06/02 18:27:37 schwarze Exp $ */ /* * Copyright (c) 2014-2020 Ingo Schwarze * Copyright (c) 2010, 2011 Kristaps Dzonsons @@ -53,7 +53,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", @@ -67,6 +66,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",