version 1.185, 2014/08/22 18:07:15 |
version 1.187, 2014/08/23 22:26:06 |
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <errno.h> |
#include <errno.h> |
|
#include <fcntl.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdint.h> |
#include <stdint.h> |
#include <stdlib.h> |
#include <stdlib.h> |
Line 86 static void mmsg(enum mandocerr, enum mandoclevel, |
|
Line 87 static void mmsg(enum mandocerr, enum mandoclevel, |
|
const char *, int, int, const char *); |
const char *, int, int, const char *); |
static void parse(struct curparse *, int, |
static void parse(struct curparse *, int, |
const char *, enum mandoclevel *); |
const char *, enum mandoclevel *); |
|
static enum mandoclevel passthrough(const char *); |
static void spawn_pager(void); |
static void spawn_pager(void); |
static int toptions(struct curparse *, char *); |
static int toptions(struct curparse *, char *); |
static void usage(enum argmode) __attribute__((noreturn)); |
static void usage(enum argmode) __attribute__((noreturn)); |
Line 105 main(int argc, char *argv[]) |
|
Line 107 main(int argc, char *argv[]) |
|
char *conf_file, *defpaths, *auxpaths; |
char *conf_file, *defpaths, *auxpaths; |
char *defos; |
char *defos; |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
struct manpage *res; |
struct manpage *res, *resp; |
char **auxargv; |
|
size_t isec, i, sz; |
size_t isec, i, sz; |
int prio, best_prio; |
int prio, best_prio; |
char sec; |
char sec; |
Line 250 main(int argc, char *argv[]) |
|
Line 251 main(int argc, char *argv[]) |
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
auxargv = NULL; |
resp = NULL; |
#endif |
#endif |
|
|
/* Quirk for a man(1) section argument without -s. */ |
/* Quirk for a man(1) section argument without -s. */ |
Line 280 main(int argc, char *argv[]) |
|
Line 281 main(int argc, char *argv[]) |
|
if( ! mansearch(&search, &paths, argc, argv, &res, &sz)) |
if( ! mansearch(&search, &paths, argc, argv, &res, &sz)) |
usage(search.argmode); |
usage(search.argmode); |
manpath_free(&paths); |
manpath_free(&paths); |
|
resp = res; |
|
|
|
if (sz == 0) { |
|
if (search.argmode == ARG_NAME) |
|
fprintf(stderr, "%s: No entry for %s " |
|
"in the manual.\n", progname, argv[0]); |
|
rc = MANDOCLEVEL_BADARG; |
|
goto out; |
|
} |
|
|
/* |
/* |
* For standard man(1) and -a output mode, |
* For standard man(1) and -a output mode, |
* prepare for copying filename pointers |
* prepare for copying filename pointers |
Line 289 main(int argc, char *argv[]) |
|
Line 299 main(int argc, char *argv[]) |
|
|
|
if (outmode == OUTMODE_ONE) { |
if (outmode == OUTMODE_ONE) { |
argc = 1; |
argc = 1; |
argv[0] = res[0].file; |
|
argv[1] = NULL; |
|
best_prio = 10; |
best_prio = 10; |
} else if (outmode == OUTMODE_ALL) { |
} else if (outmode == OUTMODE_ALL) |
argc = (int)sz; |
argc = (int)sz; |
argv = auxargv = mandoc_reallocarray( |
|
NULL, sz + 1, sizeof(char *)); |
|
argv[argc] = NULL; |
|
} |
|
|
|
/* Iterate all matching manuals. */ |
/* Iterate all matching manuals. */ |
|
|
Line 308 main(int argc, char *argv[]) |
|
Line 312 main(int argc, char *argv[]) |
|
printf("%s - %s\n", res[i].names, |
printf("%s - %s\n", res[i].names, |
res[i].output == NULL ? "" : |
res[i].output == NULL ? "" : |
res[i].output); |
res[i].output); |
else if (outmode == OUTMODE_ALL) |
else if (outmode == OUTMODE_ONE) { |
argv[i] = res[i].file; |
|
else { |
|
/* Search for the best section. */ |
/* Search for the best section. */ |
isec = strcspn(res[i].file, "123456789"); |
isec = strcspn(res[i].file, "123456789"); |
sec = res[i].file[isec]; |
sec = res[i].file[isec]; |
Line 320 main(int argc, char *argv[]) |
|
Line 322 main(int argc, char *argv[]) |
|
if (prio >= best_prio) |
if (prio >= best_prio) |
continue; |
continue; |
best_prio = prio; |
best_prio = prio; |
argv[0] = res[i].file; |
resp = res + i; |
} |
} |
} |
} |
|
|
Line 355 main(int argc, char *argv[]) |
|
Line 357 main(int argc, char *argv[]) |
|
if (OUTT_MAN == curp.outtype) |
if (OUTT_MAN == curp.outtype) |
mparse_keep(curp.mp); |
mparse_keep(curp.mp); |
|
|
if (NULL == *argv) |
if (argc == 0) |
parse(&curp, STDIN_FILENO, "<stdin>", &rc); |
parse(&curp, STDIN_FILENO, "<stdin>", &rc); |
|
|
while (*argv) { |
while (argc) { |
parse(&curp, -1, *argv, &rc); |
#if HAVE_SQLITE3 |
|
if (resp != NULL) { |
|
if (resp->form) |
|
parse(&curp, -1, resp->file, &rc); |
|
else |
|
rc = passthrough(resp->file); |
|
resp++; |
|
} else |
|
#endif |
|
parse(&curp, -1, *argv++, &rc); |
if (MANDOCLEVEL_OK != rc && curp.wstop) |
if (MANDOCLEVEL_OK != rc && curp.wstop) |
break; |
break; |
++argv; |
argc--; |
} |
} |
|
|
if (curp.outfree) |
if (curp.outfree) |
|
|
if (search.argmode != ARG_FILE) { |
if (search.argmode != ARG_FILE) { |
mansearch_free(res, sz); |
mansearch_free(res, sz); |
mansearch_setup(0); |
mansearch_setup(0); |
free(auxargv); |
|
} |
} |
#endif |
#endif |
|
|
Line 531 parse(struct curparse *curp, int fd, const char *file, |
|
Line 541 parse(struct curparse *curp, int fd, const char *file, |
|
|
|
if (*level < rc) |
if (*level < rc) |
*level = rc; |
*level = rc; |
|
} |
|
|
|
static enum mandoclevel |
|
passthrough(const char *file) |
|
{ |
|
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) |
|
if ((nw = write(STDOUT_FILENO, buf + off, |
|
(size_t)(nr - off))) == -1 || nw == 0) { |
|
syscall = "write"; |
|
goto fail; |
|
} |
|
|
|
if (nr == 0) { |
|
close(fd); |
|
return(MANDOCLEVEL_OK); |
|
} |
|
|
|
syscall = "read"; |
|
fail: |
|
fprintf(stderr, "%s: %s: SYSERR: %s: %s", |
|
progname, file, syscall, strerror(errno)); |
|
return(MANDOCLEVEL_SYSERR); |
} |
} |
|
|
static int |
static int |