Index: Makefile =================================================================== RCS file: /cvs/mdocml/Makefile,v retrieving revision 1.445 diff -u -r1.445 Makefile --- Makefile 25 Oct 2014 01:03:52 -0000 1.445 +++ Makefile 24 Nov 2014 14:32:46 -0000 @@ -236,7 +236,7 @@ MANPAGE_OBJS = manpage.o mansearch.o mansearch_const.o manpath.o -DEMANDOC_OBJS = demandoc.o +DEMANDOC_OBJS = demandoc.o manpath.o WWW_MANS = apropos.1.html \ demandoc.1.html \ Index: read.c =================================================================== RCS file: /cvs/mdocml/read.c,v retrieving revision 1.96 diff -u -r1.96 read.c --- read.c 1 Nov 2014 06:03:13 -0000 1.96 +++ read.c 24 Nov 2014 14:32:46 -0000 @@ -19,6 +19,7 @@ #include "config.h" #include +#include #if HAVE_MMAP #include #include @@ -41,6 +42,7 @@ #include "libmandoc.h" #include "mdoc.h" #include "man.h" +#include "manpath.h" #include "main.h" #define REPARSE_LIMIT 1000 @@ -783,10 +785,61 @@ mparse_readfd(struct mparse *curp, int fd, const char *file) { struct buf blk; + char buf[PATH_MAX]; int with_mmap; int save_filenc; + size_t i; + struct manpaths paths; + struct stat st; + pid_t child_pid; + + child_pid = 0; + + if (-1 == fd && *file != '/') { + do { + /* First try locally */ + if ((fd = open(file, O_RDONLY, 0)) != -1) + break; + + /* Try the gzip version */ + (void)snprintf(buf, sizeof(buf), "%s.gz", file); + if (stat(buf, &st) != -1) + (void)mparse_open(curp, &fd, buf, &child_pid); + if (-1 != fd) { + curp->file = buf; + break; + } + + /* Lookup in the manpath */ + manpath_parse(&paths, NULL, NULL, NULL); + for (i = 0; i < paths.sz; i++) { + (void)snprintf(buf, sizeof(buf), "%s/%s", + paths.paths[i], file); + if (-1 != (fd = open(buf, O_RDONLY, 0))) { + curp->file = buf; + break; + } + (void)snprintf(buf, sizeof(buf), "%s/%s.gz", + paths.paths[i], file); + if (stat(buf, &st) != -1) + (void)mparse_open(curp, &fd, buf, &child_pid); + if (-1 != fd) { + curp->file = buf; + break; + } + } + manpath_free(&paths); + if (-1 != fd) + break; - if (-1 == fd && -1 == (fd = open(file, O_RDONLY, 0))) { + curp->file_status = MANDOCLEVEL_SYSERR; + if (curp->mmsg) + (*curp->mmsg)(MANDOCERR_SYSOPEN, + curp->file_status, + file, 0, 0, strerror(errno)); + return(curp->file_status); + } while (0); + } else if (-1 == fd && -1 == (fd = open(file, O_RDONLY, 0))) { curp->file_status = MANDOCLEVEL_SYSERR; if (curp->mmsg) (*curp->mmsg)(MANDOCERR_SYSOPEN, @@ -818,6 +871,8 @@ if (STDIN_FILENO != fd && -1 == close(fd)) perror(file); + if (child_pid) + mparse_wait(curp, child_pid); return(curp->file_status); }