=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.188 retrieving revision 1.192 diff -u -p -r1.188 -r1.192 --- mandoc/main.c 2014/08/30 18:08:10 1.188 +++ mandoc/main.c 2014/09/03 23:21:47 1.192 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.188 2014/08/30 18:08:10 schwarze Exp $ */ +/* $Id: main.c,v 1.192 2014/09/03 23:21:47 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze @@ -87,7 +87,7 @@ static void mmsg(enum mandocerr, enum mandoclevel, const char *, int, int, const char *); static void parse(struct curparse *, int, const char *, enum mandoclevel *); -static enum mandoclevel passthrough(const char *); +static enum mandoclevel passthrough(const char *, int); static void spawn_pager(void); static int toptions(struct curparse *, char *); static void usage(enum argmode) __attribute__((noreturn)); @@ -114,6 +114,8 @@ main(int argc, char *argv[]) #endif enum mandoclevel rc; enum outmode outmode; + pid_t child_pid; + int fd; int show_usage; int use_pager; int options; @@ -154,7 +156,7 @@ main(int argc, char *argv[]) show_usage = 0; outmode = OUTMODE_DEF; - while (-1 != (c = getopt(argc, argv, "aC:cfI:iklM:m:O:S:s:T:VW:w"))) { + while (-1 != (c = getopt(argc, argv, "aC:cfhI:iklM:m:O:S:s:T:VW:w"))) { switch (c) { case 'a': outmode = OUTMODE_ALL; @@ -168,6 +170,10 @@ main(int argc, char *argv[]) case 'f': search.argmode = ARG_WORD; break; + case 'h': + (void)strlcat(curp.outopts, "synopsis,", BUFSIZ); + outmode = OUTMODE_ALL; + break; case 'I': if (strncmp(optarg, "os=", 3)) { fprintf(stderr, @@ -284,7 +290,6 @@ main(int argc, char *argv[]) mansearch_setup(1); if( ! mansearch(&search, &paths, argc, argv, &res, &sz)) usage(search.argmode); - manpath_free(&paths); resp = res; if (sz == 0) { @@ -367,14 +372,30 @@ main(int argc, char *argv[]) while (argc) { #if HAVE_SQLITE3 if (resp != NULL) { - if (resp->form) - parse(&curp, -1, resp->file, &rc); - else - rc = passthrough(resp->file); + rc = mparse_open(curp.mp, &fd, resp->file, + &child_pid); + if (fd == -1) + /* nothing */; + else if (resp->form & FORM_SRC) { + /* For .so only; ignore failure. */ + chdir(paths.paths[resp->ipath]); + parse(&curp, fd, resp->file, &rc); + } else + rc = passthrough(resp->file, fd); resp++; } else #endif - parse(&curp, -1, *argv++, &rc); + { + rc = mparse_open(curp.mp, &fd, *argv++, + &child_pid); + if (fd != -1) + parse(&curp, fd, argv[-1], &rc); + } + + if (child_pid && + mparse_wait(curp.mp, child_pid) != MANDOCLEVEL_OK) + rc = MANDOCLEVEL_SYSERR; + if (MANDOCLEVEL_OK != rc && curp.wstop) break; argc--; @@ -388,6 +409,7 @@ main(int argc, char *argv[]) #if HAVE_SQLITE3 out: if (search.argmode != ARG_FILE) { + manpath_free(&paths); mansearch_free(res, sz); mansearch_setup(0); } @@ -412,7 +434,7 @@ usage(enum argmode argmode) switch (argmode) { case ARG_FILE: - fputs("usage: mandoc [-acfklV] [-Ios=name] " + fputs("usage: mandoc [-acfhklV] [-Ios=name] " "[-mformat] [-Ooption] [-Toutput] [-Wlevel]\n" "\t [file ...]\n", stderr); break; @@ -422,12 +444,12 @@ usage(enum argmode argmode) "\t [section] name ...\n", stderr); break; case ARG_WORD: - fputs("usage: whatis [-acfklVw] [-C file] " + fputs("usage: whatis [-acfhklVw] [-C file] " "[-M path] [-m path] [-O outkey] [-S arch]\n" "\t [-s section] name ...\n", stderr); break; case ARG_EXPR: - fputs("usage: apropos [-acfklVw] [-C file] " + fputs("usage: apropos [-acfhklVw] [-C file] " "[-M path] [-m path] [-O outkey] [-S arch]\n" "\t [-s section] expression ...\n", stderr); break; @@ -549,18 +571,11 @@ parse(struct curparse *curp, int fd, const char *file, } static enum mandoclevel -passthrough(const char *file) +passthrough(const char *file, int fd) { char buf[BUFSIZ]; const char *syscall; ssize_t nr, nw, off; - int fd; - - fd = open(file, O_RDONLY); - if (fd == -1) { - syscall = "open"; - goto fail; - } while ((nr = read(fd, buf, BUFSIZ)) != -1 && nr != 0) for (off = 0; off < nr; off += nw)