aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/main.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2020-02-10 13:49:15 +0000
committerIngo Schwarze <schwarze@openbsd.org>2020-02-10 13:49:15 +0000
commit743fd1a5d4483427e1ee6b931441657400dd87bf (patch)
tree6deb707fe7e8cbe5830550fd5fd9715fe179c2ab /main.c
parent181a689064792fe61edda70bb2ade55b524dbef8 (diff)
downloadmandoc-743fd1a5d4483427e1ee6b931441657400dd87bf.tar.gz
mandoc-743fd1a5d4483427e1ee6b931441657400dd87bf.tar.zst
mandoc-743fd1a5d4483427e1ee6b931441657400dd87bf.zip
For compatibility with the man(1) implementations of the man-1.6
and man-db packages, print the manpath if the -w option is given without a following name argument. This quirk has been in man-1.6 since at least man-1.5e (1998) and in man-db since 2012. Using this feature in portable software is a dubious idea because the internal organization of manual page directories varies in about a dozen respects among operating systems, so even if you get the answer, there is no portable way to use it for looking up anything inside. However, Matej Cepl <mcepl at suse dot cz> made me aware that some software, for example the manual viewing functionality in the newest editors/neovim code, unwisely relies on this feature anyway. No objections were raised when this patch was shown on tech@.
Diffstat (limited to 'main.c')
-rw-r--r--main.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/main.c b/main.c
index c74a3a83..b84a9a2b 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.342 2020/02/06 19:41:40 schwarze Exp $ */
+/* $Id: main.c,v 1.343 2020/02/10 13:49:15 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2012, 2014-2020 Ingo Schwarze <schwarze@openbsd.org>
@@ -448,8 +448,20 @@ main(int argc, char *argv[])
/* man(1): Resolve each name individually. */
if (search.argmode == ARG_NAME) {
- if (argc < 1)
- usage(ARG_NAME);
+ if (argc < 1) {
+ if (outmode != OUTMODE_FLN)
+ usage(ARG_NAME);
+ if (conf.manpath.sz == 0) {
+ warnx("The manpath is empty.");
+ mandoc_msg_setrc(MANDOCLEVEL_BADARG);
+ } else {
+ for (i = 0; i + 1 < conf.manpath.sz; i++)
+ printf("%s:", conf.manpath.paths[i]);
+ printf("%s\n", conf.manpath.paths[i]);
+ }
+ manconf_free(&conf);
+ return (int)mandoc_msg_getrc();
+ }
for (res = NULL, ressz = 0; argc > 0; argc--, argv++) {
(void)mansearch(&search, &conf.manpath,
1, argv, &resn, &resnsz);