diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-02-27 16:02:10 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-02-27 16:02:10 +0000 |
commit | 1a83fe0518c070d90a4989d137927b786a7732d4 (patch) | |
tree | 8ff9bf6798357bdb8a1cf2e05accfe3e574c3e3f /main.c | |
parent | 970476b50a74492edd4cf5202324ba6c1edc6229 (diff) | |
download | mandoc-1a83fe0518c070d90a4989d137927b786a7732d4.tar.gz |
When man(1) and apropos(1) look for a file man1/foo.1 but it's unavailable,
fall back to glob(man1/foo.*), which is more like what old man(1) did.
Do this both for file names from the database and for fs_lookup().
This is relevant because some ports install files like man1/xset.1x.
Regression reported by patrick keshishian <pkeshish at gmail dot com>.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -25,6 +25,7 @@ #include <ctype.h> #include <errno.h> #include <fcntl.h> +#include <glob.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> @@ -517,16 +518,16 @@ fs_lookup(const struct manpaths *paths, size_t ipath, const char *sec, const char *arch, const char *name, struct manpage **res, size_t *ressz) { + glob_t globinfo; struct manpage *page; char *file; - int form; + int form, globres; + form = FORM_SRC; mandoc_asprintf(&file, "%s/man%s/%s.%s", paths->paths[ipath], sec, name, sec); - if (access(file, R_OK) != -1) { - form = FORM_SRC; + if (access(file, R_OK) != -1) goto found; - } free(file); mandoc_asprintf(&file, "%s/cat%s/%s.0", @@ -540,13 +541,23 @@ fs_lookup(const struct manpaths *paths, size_t ipath, if (arch != NULL) { mandoc_asprintf(&file, "%s/man%s/%s/%s.%s", paths->paths[ipath], sec, arch, name, sec); - if (access(file, R_OK) != -1) { - form = FORM_SRC; + if (access(file, R_OK) != -1) goto found; - } free(file); } - return(0); + + mandoc_asprintf(&file, "%s/man%s/%s.*", + paths->paths[ipath], sec, name); + globres = glob(file, 0, NULL, &globinfo); + if (globres != 0 && globres != GLOB_NOMATCH) + fprintf(stderr, "%s: %s: glob: %s\n", + progname, file, strerror(errno)); + free(file); + if (globres == 0) + file = mandoc_strdup(*globinfo.gl_pathv); + globfree(&globinfo); + if (globres != 0) + return(0); found: #if HAVE_SQLITE3 |