version 1.229, 2015/03/27 17:37:25 |
version 1.238, 2015/04/29 11:04:17 |
|
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "mandoc.h" |
|
#include "mandoc_aux.h" |
#include "mandoc_aux.h" |
#include "main.h" |
#include "mandoc.h" |
|
#include "roff.h" |
#include "mdoc.h" |
#include "mdoc.h" |
#include "man.h" |
#include "man.h" |
|
#include "main.h" |
#include "manconf.h" |
#include "manconf.h" |
#include "mansearch.h" |
#include "mansearch.h" |
|
|
|
|
OUTMODE_ONE |
OUTMODE_ONE |
}; |
}; |
|
|
typedef void (*out_mdoc)(void *, const struct mdoc *); |
typedef void (*out_mdoc)(void *, const struct roff_man *); |
typedef void (*out_man)(void *, const struct man *); |
typedef void (*out_man)(void *, const struct roff_man *); |
typedef void (*out_free)(void *); |
typedef void (*out_free)(void *); |
|
|
enum outt { |
enum outt { |
Line 83 struct curparse { |
|
Line 84 struct curparse { |
|
out_man outman; /* man output ptr */ |
out_man outman; /* man output ptr */ |
out_free outfree; /* free output ptr */ |
out_free outfree; /* free output ptr */ |
void *outdata; /* data for output */ |
void *outdata; /* data for output */ |
char outopts[BUFSIZ]; /* buf of output opts */ |
struct manoutput *outopts; /* output options */ |
}; |
}; |
|
|
static int fs_lookup(const struct manpaths *, |
static int fs_lookup(const struct manpaths *, |
Line 127 main(int argc, char *argv[]) |
|
Line 128 main(int argc, char *argv[]) |
|
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; |
char sec; |
char sec; |
enum mandoclevel rctmp; |
enum mandoclevel rctmp; |
enum outmode outmode; |
enum outmode outmode; |
Line 174 main(int argc, char *argv[]) |
|
Line 175 main(int argc, char *argv[]) |
|
memset(&curp, 0, sizeof(struct curparse)); |
memset(&curp, 0, sizeof(struct curparse)); |
curp.outtype = OUTT_LOCALE; |
curp.outtype = OUTT_LOCALE; |
curp.wlevel = MANDOCLEVEL_BADARG; |
curp.wlevel = MANDOCLEVEL_BADARG; |
|
curp.outopts = &conf.output; |
options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1; |
options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1; |
defos = NULL; |
defos = NULL; |
|
|
pager_pid = 1; |
pager_pid = 1; |
show_usage = 0; |
show_usage = 0; |
synopsis_only = 0; |
|
outmode = OUTMODE_DEF; |
outmode = OUTMODE_DEF; |
|
|
while (-1 != (c = getopt(argc, argv, |
while (-1 != (c = getopt(argc, argv, |
Line 198 main(int argc, char *argv[]) |
|
Line 199 main(int argc, char *argv[]) |
|
search.argmode = ARG_WORD; |
search.argmode = ARG_WORD; |
break; |
break; |
case 'h': |
case 'h': |
(void)strlcat(curp.outopts, "synopsis,", BUFSIZ); |
conf.output.synopsisonly = 1; |
synopsis_only = 1; |
|
pager_pid = 0; |
pager_pid = 0; |
outmode = OUTMODE_ALL; |
outmode = OUTMODE_ALL; |
break; |
break; |
Line 240 main(int argc, char *argv[]) |
|
Line 240 main(int argc, char *argv[]) |
|
break; |
break; |
case 'O': |
case 'O': |
search.outkey = optarg; |
search.outkey = optarg; |
(void)strlcat(curp.outopts, optarg, BUFSIZ); |
while (optarg != NULL) |
(void)strlcat(curp.outopts, ",", BUFSIZ); |
manconf_output(&conf.output, |
|
strsep(&optarg, ",")); |
break; |
break; |
case 'S': |
case 'S': |
search.arch = optarg; |
search.arch = optarg; |
Line 351 main(int argc, char *argv[]) |
|
Line 352 main(int argc, char *argv[]) |
|
sz = 0; |
sz = 0; |
#endif |
#endif |
|
|
if (sz == 0 && search.argmode == ARG_NAME) |
if (sz == 0) { |
fs_search(&search, &conf.manpath, |
if (search.argmode == ARG_NAME) |
argc, argv, &res, &sz); |
fs_search(&search, &conf.manpath, |
|
argc, argv, &res, &sz); |
|
else |
|
fprintf(stderr, |
|
"%s: nothing appropriate\n", |
|
progname); |
|
} |
|
|
if (sz == 0) { |
if (sz == 0) { |
rc = MANDOCLEVEL_BADARG; |
rc = MANDOCLEVEL_BADARG; |
Line 444 main(int argc, char *argv[]) |
|
Line 451 main(int argc, char *argv[]) |
|
chdir(conf.manpath.paths[resp->ipath]); |
chdir(conf.manpath.paths[resp->ipath]); |
parse(&curp, fd, resp->file); |
parse(&curp, fd, resp->file); |
} else |
} else |
passthrough(resp->file, fd, synopsis_only); |
passthrough(resp->file, fd, |
|
conf.output.synopsisonly); |
|
|
rctmp = mparse_wait(curp.mp); |
rctmp = mparse_wait(curp.mp); |
if (rc < rctmp) |
if (rc < rctmp) |
Line 574 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 582 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
|
|
found: |
found: |
#if HAVE_SQLITE3 |
#if HAVE_SQLITE3 |
fprintf(stderr, "%s: outdated mandoc.db lacks %s(%s) entry,\n" |
fprintf(stderr, "%s: outdated mandoc.db lacks %s(%s) entry, run " |
" consider running # makewhatis %s\n", |
"makewhatis %s\n", progname, name, sec, paths->paths[ipath]); |
progname, name, sec, paths->paths[ipath]); |
|
#endif |
#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); |
page->file = file; |
page->file = file; |
|
|
parse(struct curparse *curp, int fd, const char *file) |
parse(struct curparse *curp, int fd, const char *file) |
{ |
{ |
enum mandoclevel rctmp; |
enum mandoclevel rctmp; |
struct mdoc *mdoc; |
struct roff_man *man; |
struct man *man; |
|
|
|
/* Begin by parsing the file itself. */ |
/* Begin by parsing the file itself. */ |
|
|
Line 720 parse(struct curparse *curp, int fd, const char *file) |
|
Line 725 parse(struct curparse *curp, int fd, const char *file) |
|
} |
} |
} |
} |
|
|
mparse_result(curp->mp, &mdoc, &man, NULL); |
mparse_result(curp->mp, &man, NULL); |
|
|
/* Execute the out device, if it exists. */ |
/* Execute the out device, if it exists. */ |
|
|
if (man && curp->outman) |
if (man == NULL) |
|
return; |
|
if (curp->outmdoc != NULL && man->macroset == MACROSET_MDOC) |
|
(*curp->outmdoc)(curp->outdata, man); |
|
if (curp->outman != NULL && man->macroset == MACROSET_MAN) |
(*curp->outman)(curp->outdata, man); |
(*curp->outman)(curp->outdata, man); |
if (mdoc && curp->outmdoc) |
|
(*curp->outmdoc)(curp->outdata, mdoc); |
|
} |
} |
|
|
static void |
static void |
Line 995 spawn_pager(void) |
|
Line 1002 spawn_pager(void) |
|
if (pager == NULL || *pager == '\0') |
if (pager == NULL || *pager == '\0') |
pager = getenv("PAGER"); |
pager = getenv("PAGER"); |
if (pager == NULL || *pager == '\0') |
if (pager == NULL || *pager == '\0') |
pager = "/usr/bin/more -s"; |
pager = "more -s"; |
cp = mandoc_strdup(pager); |
cp = mandoc_strdup(pager); |
|
|
/* |
/* |
Line 1020 spawn_pager(void) |
|
Line 1027 spawn_pager(void) |
|
/* Hand over to the pager. */ |
/* Hand over to the pager. */ |
|
|
execvp(argv[0], argv); |
execvp(argv[0], argv); |
fprintf(stderr, "%s: exec: %s\n", |
fprintf(stderr, "%s: exec %s: %s\n", |
progname, strerror(errno)); |
progname, argv[0], strerror(errno)); |
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |