version 1.216, 2015/01/16 21:15:05 |
version 1.218, 2015/02/03 21:16:02 |
Line 83 struct curparse { |
|
Line 83 struct curparse { |
|
char outopts[BUFSIZ]; /* buf of output opts */ |
char outopts[BUFSIZ]; /* buf of output opts */ |
}; |
}; |
|
|
#if HAVE_SQLITE3 |
|
static int fs_lookup(const struct manpaths *, |
static int fs_lookup(const struct manpaths *, |
size_t ipath, const char *, |
size_t ipath, const char *, |
const char *, const char *, |
const char *, const char *, |
Line 91 static int fs_lookup(const struct manpaths *, |
|
Line 90 static int fs_lookup(const struct manpaths *, |
|
static void fs_search(const struct mansearch *, |
static void fs_search(const struct mansearch *, |
const struct manpaths *, int, char**, |
const struct manpaths *, int, char**, |
struct manpage **, size_t *); |
struct manpage **, size_t *); |
#endif |
|
static int koptions(int *, char *); |
static int koptions(int *, char *); |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
int mandocdb(int, char**); |
int mandocdb(int, char**); |
Line 101 static void mmsg(enum mandocerr, enum mandoclevel, |
|
Line 99 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 *); |
#if HAVE_SQLITE3 |
|
static enum mandoclevel passthrough(const char *, int, int); |
static enum mandoclevel passthrough(const char *, int, int); |
#endif |
|
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 125 main(int argc, char *argv[]) |
|
Line 121 main(int argc, char *argv[]) |
|
char *auxpaths; |
char *auxpaths; |
char *defos; |
char *defos; |
unsigned char *uc; |
unsigned char *uc; |
#if HAVE_SQLITE3 |
|
struct manpage *res, *resp; |
struct manpage *res, *resp; |
char *conf_file, *defpaths; |
char *conf_file, *defpaths; |
size_t isec, i, sz; |
size_t isec, i, sz; |
int prio, best_prio, synopsis_only; |
int prio, best_prio, synopsis_only; |
char sec; |
char sec; |
#endif |
|
enum mandoclevel rc, rctmp; |
enum mandoclevel rc, rctmp; |
enum outmode outmode; |
enum outmode outmode; |
int fd; |
int fd; |
Line 154 main(int argc, char *argv[]) |
|
Line 148 main(int argc, char *argv[]) |
|
/* Search options. */ |
/* Search options. */ |
|
|
memset(&paths, 0, sizeof(struct manpaths)); |
memset(&paths, 0, sizeof(struct manpaths)); |
#if HAVE_SQLITE3 |
|
conf_file = defpaths = NULL; |
conf_file = defpaths = NULL; |
#endif |
|
auxpaths = NULL; |
auxpaths = NULL; |
|
|
memset(&search, 0, sizeof(struct mansearch)); |
memset(&search, 0, sizeof(struct mansearch)); |
Line 183 main(int argc, char *argv[]) |
|
Line 175 main(int argc, char *argv[]) |
|
|
|
use_pager = 1; |
use_pager = 1; |
show_usage = 0; |
show_usage = 0; |
#if HAVE_SQLITE3 |
|
synopsis_only = 0; |
synopsis_only = 0; |
#endif |
|
outmode = OUTMODE_DEF; |
outmode = OUTMODE_DEF; |
|
|
while (-1 != (c = getopt(argc, argv, |
while (-1 != (c = getopt(argc, argv, |
Line 195 main(int argc, char *argv[]) |
|
Line 185 main(int argc, char *argv[]) |
|
outmode = OUTMODE_ALL; |
outmode = OUTMODE_ALL; |
break; |
break; |
case 'C': |
case 'C': |
#if HAVE_SQLITE3 |
|
conf_file = optarg; |
conf_file = optarg; |
#endif |
|
break; |
break; |
case 'c': |
case 'c': |
use_pager = 0; |
use_pager = 0; |
Line 207 main(int argc, char *argv[]) |
|
Line 195 main(int argc, char *argv[]) |
|
break; |
break; |
case 'h': |
case 'h': |
(void)strlcat(curp.outopts, "synopsis,", BUFSIZ); |
(void)strlcat(curp.outopts, "synopsis,", BUFSIZ); |
#if HAVE_SQLITE3 |
|
synopsis_only = 1; |
synopsis_only = 1; |
#endif |
|
use_pager = 0; |
use_pager = 0; |
outmode = OUTMODE_ALL; |
outmode = OUTMODE_ALL; |
break; |
break; |
Line 243 main(int argc, char *argv[]) |
|
Line 229 main(int argc, char *argv[]) |
|
outmode = OUTMODE_ALL; |
outmode = OUTMODE_ALL; |
break; |
break; |
case 'M': |
case 'M': |
#if HAVE_SQLITE3 |
|
defpaths = optarg; |
defpaths = optarg; |
#endif |
|
break; |
break; |
case 'm': |
case 'm': |
auxpaths = optarg; |
auxpaths = optarg; |
Line 305 main(int argc, char *argv[]) |
|
Line 289 main(int argc, char *argv[]) |
|
|
|
argc -= optind; |
argc -= optind; |
argv += optind; |
argv += optind; |
#if HAVE_SQLITE3 |
|
resp = NULL; |
resp = NULL; |
#endif |
|
|
|
/* |
/* |
* Quirks for help(1) |
* Quirks for help(1) |
Line 340 main(int argc, char *argv[]) |
|
Line 322 main(int argc, char *argv[]) |
|
/* man(1), whatis(1), apropos(1) */ |
/* man(1), whatis(1), apropos(1) */ |
|
|
if (search.argmode != ARG_FILE) { |
if (search.argmode != ARG_FILE) { |
#if HAVE_SQLITE3 |
|
if (argc == 0) |
if (argc == 0) |
usage(search.argmode); |
usage(search.argmode); |
|
|
Line 351 main(int argc, char *argv[]) |
|
Line 332 main(int argc, char *argv[]) |
|
/* Access the mandoc database. */ |
/* Access the mandoc database. */ |
|
|
manpath_parse(&paths, conf_file, defpaths, auxpaths); |
manpath_parse(&paths, conf_file, defpaths, auxpaths); |
|
#if HAVE_SQLITE3 |
mansearch_setup(1); |
mansearch_setup(1); |
if( ! mansearch(&search, &paths, argc, argv, &res, &sz)) |
if( ! mansearch(&search, &paths, argc, argv, &res, &sz)) |
usage(search.argmode); |
usage(search.argmode); |
|
#else |
|
if (search.argmode != ARG_NAME) { |
|
fputs("mandoc: database support not compiled in\n", |
|
stderr); |
|
return((int)MANDOCLEVEL_BADARG); |
|
} |
|
sz = 0; |
|
#endif |
|
|
if (sz == 0 && search.argmode == ARG_NAME) |
if (sz == 0 && search.argmode == ARG_NAME) |
fs_search(&search, &paths, argc, argv, &res, &sz); |
fs_search(&search, &paths, argc, argv, &res, &sz); |
Line 407 main(int argc, char *argv[]) |
|
Line 397 main(int argc, char *argv[]) |
|
|
|
if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST) |
if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST) |
goto out; |
goto out; |
#else |
|
fputs("mandoc: database support not compiled in\n", |
|
stderr); |
|
return((int)MANDOCLEVEL_BADARG); |
|
#endif |
|
} |
} |
|
|
/* mandoc(1) */ |
/* mandoc(1) */ |
Line 437 main(int argc, char *argv[]) |
|
Line 422 main(int argc, char *argv[]) |
|
|
|
while (argc) { |
while (argc) { |
rctmp = mparse_open(curp.mp, &fd, |
rctmp = mparse_open(curp.mp, &fd, |
#if HAVE_SQLITE3 |
resp != NULL ? resp->file : *argv); |
resp != NULL ? resp->file : |
|
#endif |
|
*argv); |
|
if (rc < rctmp) |
if (rc < rctmp) |
rc = rctmp; |
rc = rctmp; |
|
|
Line 449 main(int argc, char *argv[]) |
|
Line 431 main(int argc, char *argv[]) |
|
spawn_pager(); |
spawn_pager(); |
use_pager = 0; |
use_pager = 0; |
|
|
#if HAVE_SQLITE3 |
|
if (resp == NULL) |
if (resp == NULL) |
#endif |
|
parse(&curp, fd, *argv, &rc); |
parse(&curp, fd, *argv, &rc); |
#if HAVE_SQLITE3 |
|
else if (resp->form & FORM_SRC) { |
else if (resp->form & FORM_SRC) { |
/* For .so only; ignore failure. */ |
/* For .so only; ignore failure. */ |
chdir(paths.paths[resp->ipath]); |
chdir(paths.paths[resp->ipath]); |
Line 464 main(int argc, char *argv[]) |
|
Line 443 main(int argc, char *argv[]) |
|
if (rc < rctmp) |
if (rc < rctmp) |
rc = rctmp; |
rc = rctmp; |
} |
} |
#endif |
|
|
|
rctmp = mparse_wait(curp.mp); |
rctmp = mparse_wait(curp.mp); |
if (rc < rctmp) |
if (rc < rctmp) |
Line 477 main(int argc, char *argv[]) |
|
Line 455 main(int argc, char *argv[]) |
|
if (MANDOCLEVEL_OK != rc && curp.wstop) |
if (MANDOCLEVEL_OK != rc && curp.wstop) |
break; |
break; |
|
|
#if HAVE_SQLITE3 |
|
if (resp != NULL) |
if (resp != NULL) |
resp++; |
resp++; |
else |
else |
#endif |
|
argv++; |
argv++; |
if (--argc) |
if (--argc) |
mparse_reset(curp.mp); |
mparse_reset(curp.mp); |
Line 492 main(int argc, char *argv[]) |
|
Line 468 main(int argc, char *argv[]) |
|
mparse_free(curp.mp); |
mparse_free(curp.mp); |
mchars_free(curp.mchars); |
mchars_free(curp.mchars); |
|
|
#if HAVE_SQLITE3 |
|
out: |
out: |
if (search.argmode != ARG_FILE) { |
if (search.argmode != ARG_FILE) { |
manpath_free(&paths); |
manpath_free(&paths); |
|
#if HAVE_SQLITE3 |
mansearch_free(res, sz); |
mansearch_free(res, sz); |
mansearch_setup(0); |
mansearch_setup(0); |
} |
|
#endif |
#endif |
|
} |
|
|
free(defos); |
free(defos); |
|
|
Line 545 usage(enum argmode argmode) |
|
Line 521 usage(enum argmode argmode) |
|
exit((int)MANDOCLEVEL_BADARG); |
exit((int)MANDOCLEVEL_BADARG); |
} |
} |
|
|
#if HAVE_SQLITE3 |
|
static int |
static int |
fs_lookup(const struct manpaths *paths, size_t ipath, |
fs_lookup(const struct manpaths *paths, size_t ipath, |
const char *sec, const char *arch, const char *name, |
const char *sec, const char *arch, const char *name, |
Line 583 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 558 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
return(0); |
return(0); |
|
|
found: |
found: |
|
#if HAVE_SQLITE3 |
fprintf(stderr, "%s: outdated mandoc.db lacks %s(%s) entry,\n" |
fprintf(stderr, "%s: outdated mandoc.db lacks %s(%s) entry,\n" |
" consider running # makewhatis %s\n", |
" consider running # makewhatis %s\n", |
progname, name, sec, paths->paths[ipath]); |
progname, name, sec, paths->paths[ipath]); |
|
#endif |
|
|
*res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); |
*res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); |
page = *res + (*ressz - 1); |
page = *res + (*ressz - 1); |
Line 635 fs_search(const struct mansearch *cfg, const struct ma |
|
Line 612 fs_search(const struct mansearch *cfg, const struct ma |
|
argc--; |
argc--; |
} |
} |
} |
} |
#endif |
|
|
|
static void |
static void |
parse(struct curparse *curp, int fd, const char *file, |
parse(struct curparse *curp, int fd, const char *file, |
|
|
*level = rc; |
*level = rc; |
} |
} |
|
|
#if HAVE_SQLITE3 |
|
static enum mandoclevel |
static enum mandoclevel |
passthrough(const char *file, int fd, int synopsis_only) |
passthrough(const char *file, int fd, int synopsis_only) |
{ |
{ |
|
|
progname, file, syscall, strerror(errno)); |
progname, file, syscall, strerror(errno)); |
return(MANDOCLEVEL_SYSERR); |
return(MANDOCLEVEL_SYSERR); |
} |
} |
#endif |
|
|
|
static int |
static int |
koptions(int *options, char *arg) |
koptions(int *options, char *arg) |
|
|
woptions(struct curparse *curp, char *arg) |
woptions(struct curparse *curp, char *arg) |
{ |
{ |
char *v, *o; |
char *v, *o; |
const char *toks[6]; |
const char *toks[7]; |
|
|
toks[0] = "stop"; |
toks[0] = "stop"; |
toks[1] = "all"; |
toks[1] = "all"; |
toks[2] = "warning"; |
toks[2] = "warning"; |
toks[3] = "error"; |
toks[3] = "error"; |
toks[4] = "fatal"; |
toks[4] = "unsupp"; |
toks[5] = NULL; |
toks[5] = "fatal"; |
|
toks[6] = NULL; |
|
|
while (*arg) { |
while (*arg) { |
o = arg; |
o = arg; |
Line 913 woptions(struct curparse *curp, char *arg) |
|
Line 888 woptions(struct curparse *curp, char *arg) |
|
curp->wlevel = MANDOCLEVEL_ERROR; |
curp->wlevel = MANDOCLEVEL_ERROR; |
break; |
break; |
case 4: |
case 4: |
|
curp->wlevel = MANDOCLEVEL_UNSUPP; |
|
break; |
|
case 5: |
curp->wlevel = MANDOCLEVEL_BADARG; |
curp->wlevel = MANDOCLEVEL_BADARG; |
break; |
break; |
default: |
default: |