summaryrefslogtreecommitdiff
path: root/contrib/mandoc
diff options
context:
space:
mode:
authorYuri Pankov <yuripv@FreeBSD.org>2018-10-16 17:17:11 +0000
committerYuri Pankov <yuripv@FreeBSD.org>2018-10-16 17:17:11 +0000
commita10034cb47925150ecf57d24860c512f57a35d8f (patch)
tree3519fd78e297f7a35f1e2936f282c35799585717 /contrib/mandoc
parent9d5d89b209e660c2fc55783cb14a5419a9af6098 (diff)
downloadsrc-test-a10034cb47925150ecf57d24860c512f57a35d8f.tar.gz
src-test-a10034cb47925150ecf57d24860c512f57a35d8f.zip
apropos/whatis: use output of manpath(1) to set defpaths if -M is not
specified. This fixes searching the paths specified in /usr/local/etc/man.d/*.conf, as currently apropos/whatis from mandoc suite aren't aware about them. PR: 227922 Reviewed by: bapt Approved by: re (gjb), kib (mentor) Differential Revision: https://reviews.freebsd.org/D17454
Notes
Notes: svn path=/head/; revision=339385
Diffstat (limited to 'contrib/mandoc')
-rw-r--r--contrib/mandoc/main.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/contrib/mandoc/main.c b/contrib/mandoc/main.c
index 302320bba56a0..9693ee06ba310 100644
--- a/contrib/mandoc/main.c
+++ b/contrib/mandoc/main.c
@@ -248,7 +248,13 @@ main(int argc, char *argv[])
outmode = OUTMODE_ALL;
break;
case 'M':
+#ifdef __FreeBSD__
+ defpaths = strdup(optarg);
+ if (defpaths == NULL)
+ err(1, "strdup");
+#else
defpaths = optarg;
+#endif
break;
case 'm':
auxpaths = optarg;
@@ -380,9 +386,34 @@ main(int argc, char *argv[])
outmode == OUTMODE_ONE)
search.firstmatch = 1;
+#ifdef __FreeBSD__
+ /*
+ * Use manpath(1) to populate defpaths if -M is not specified.
+ * Don't treat any failures as fatal.
+ */
+ if (defpaths == NULL) {
+ FILE *fp;
+ size_t linecap = 0;
+ ssize_t linelen;
+
+ if ((fp = popen("/usr/bin/manpath -q", "r")) != NULL) {
+ if ((linelen = getline(&defpaths,
+ &linecap, fp)) > 0) {
+ /* Strip trailing newline */
+ defpaths[linelen - 1] = '\0';
+ }
+ pclose(fp);
+ }
+ }
+#endif
+
/* Access the mandoc database. */
manconf_parse(&conf, conf_file, defpaths, auxpaths);
+#ifdef __FreeBSD__
+ free(defpaths);
+#endif
+
if ( ! mansearch(&search, &conf.manpath,
argc, argv, &res, &sz))
usage(search.argmode);