version 1.338, 2019/07/28 18:23:17 |
version 1.341, 2020/01/20 10:37:15 |
|
|
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <glob.h> |
#include <glob.h> |
|
#include <limits.h> |
#if HAVE_SANDBOX_INIT |
#if HAVE_SANDBOX_INIT |
#include <sandbox.h> |
#include <sandbox.h> |
#endif |
#endif |
Line 95 static int fs_lookup(const struct manpaths *, |
|
Line 96 static int fs_lookup(const struct manpaths *, |
|
const char *, const char *, |
const char *, const char *, |
struct manpage **, size_t *); |
struct manpage **, size_t *); |
static int fs_search(const struct mansearch *, |
static int fs_search(const struct mansearch *, |
const struct manpaths *, int, char**, |
const struct manpaths *, const char *, |
struct manpage **, size_t *); |
struct manpage **, size_t *); |
static void outdata_alloc(struct outstate *, struct manoutput *); |
static void outdata_alloc(struct outstate *, struct manoutput *); |
static void parse(struct mparse *, int, const char *, |
static void parse(struct mparse *, int, const char *, |
Line 443 main(int argc, char *argv[]) |
|
Line 444 main(int argc, char *argv[]) |
|
1, argv, &resn, &resnsz); |
1, argv, &resn, &resnsz); |
if (resnsz == 0) |
if (resnsz == 0) |
(void)fs_search(&search, &conf.manpath, |
(void)fs_search(&search, &conf.manpath, |
1, argv, &resn, &resnsz); |
*argv, &resn, &resnsz); |
|
if (resnsz == 0 && strchr(*argv, '/') == NULL) { |
|
if (search.arch != NULL && |
|
arch_valid(search.arch, OSENUM) == 0) |
|
warnx("Unknown architecture \"%s\".", |
|
search.arch); |
|
else if (search.sec != NULL) |
|
warnx("No entry for %s in " |
|
"section %s of the manual.", |
|
*argv, search.sec); |
|
else |
|
warnx("No entry for %s in " |
|
"the manual.", *argv); |
|
mandoc_msg_setrc(MANDOCLEVEL_BADARG); |
|
continue; |
|
} |
if (resnsz == 0) { |
if (resnsz == 0) { |
if (strchr(*argv, '/') == NULL) { |
|
mandoc_msg_setrc(MANDOCLEVEL_BADARG); |
|
continue; |
|
} |
|
if (access(*argv, R_OK) == -1) { |
if (access(*argv, R_OK) == -1) { |
mandoc_msg_setinfilename(*argv); |
mandoc_msg_setinfilename(*argv); |
mandoc_msg(MANDOCERR_BADARG_BAD, |
mandoc_msg(MANDOCERR_BADARG_BAD, |
Line 544 main(int argc, char *argv[]) |
|
Line 556 main(int argc, char *argv[]) |
|
break; |
break; |
} |
} |
|
|
#if HAVE_PLEDGE |
|
if (outst.use_pager) { |
|
if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) { |
|
mandoc_msg(MANDOCERR_PLEDGE, 0, 0, |
|
"%s", strerror(errno)); |
|
return mandoc_msg_getrc(); |
|
} |
|
} else { |
|
if (pledge("stdio rpath", NULL) == -1) { |
|
mandoc_msg(MANDOCERR_PLEDGE, 0, 0, |
|
"%s", strerror(errno)); |
|
return mandoc_msg_getrc(); |
|
} |
|
} |
|
#endif |
|
|
|
if (search.argmode == ARG_FILE && auxpaths != NULL) { |
if (search.argmode == ARG_FILE && auxpaths != NULL) { |
if (strcmp(auxpaths, "doc") == 0) |
if (strcmp(auxpaths, "doc") == 0) |
options |= MPARSE_MDOC; |
options |= MPARSE_MDOC; |
|
|
|
|
static int |
static int |
fs_search(const struct mansearch *cfg, const struct manpaths *paths, |
fs_search(const struct mansearch *cfg, const struct manpaths *paths, |
int argc, char **argv, struct manpage **res, size_t *ressz) |
const char *name, struct manpage **res, size_t *ressz) |
{ |
{ |
const char *const sections[] = |
const char *const sections[] = |
{"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"}; |
{"1", "8", "6", "2", "3", "5", "7", "4", "9", "3p"}; |
const size_t nsec = sizeof(sections)/sizeof(sections[0]); |
const size_t nsec = sizeof(sections)/sizeof(sections[0]); |
|
|
size_t ipath, isec, lastsz; |
size_t ipath, isec; |
|
|
assert(cfg->argmode == ARG_NAME); |
assert(cfg->argmode == ARG_NAME); |
|
|
if (res != NULL) |
if (res != NULL) |
*res = NULL; |
*res = NULL; |
*ressz = lastsz = 0; |
*ressz = 0; |
while (argc) { |
for (ipath = 0; ipath < paths->sz; ipath++) { |
for (ipath = 0; ipath < paths->sz; ipath++) { |
if (cfg->sec != NULL) { |
if (cfg->sec != NULL) { |
if (fs_lookup(paths, ipath, cfg->sec, cfg->arch, |
if (fs_lookup(paths, ipath, cfg->sec, |
name, res, ressz) != -1 && cfg->firstmatch) |
cfg->arch, *argv, res, ressz) != -1 && |
return 0; |
cfg->firstmatch) |
} else { |
return 0; |
for (isec = 0; isec < nsec; isec++) |
} else for (isec = 0; isec < nsec; isec++) |
|
if (fs_lookup(paths, ipath, sections[isec], |
if (fs_lookup(paths, ipath, sections[isec], |
cfg->arch, *argv, res, ressz) != -1 && |
cfg->arch, name, res, ressz) != -1 && |
cfg->firstmatch) |
cfg->firstmatch) |
return 0; |
return 0; |
} |
} |
if (res != NULL && *ressz == lastsz && |
|
strchr(*argv, '/') == NULL) { |
|
if (cfg->arch != NULL && |
|
arch_valid(cfg->arch, OSENUM) == 0) |
|
warnx("Unknown architecture \"%s\".", |
|
cfg->arch); |
|
else if (cfg->sec == NULL) |
|
warnx("No entry for %s in the manual.", |
|
*argv); |
|
else |
|
warnx("No entry for %s in section %s " |
|
"of the manual.", *argv, cfg->sec); |
|
} |
|
lastsz = *ressz; |
|
argv++; |
|
argc--; |
|
} |
} |
return -1; |
return -1; |
} |
} |
|
|
search.firstmatch = 1; |
search.firstmatch = 1; |
if (mansearch(&search, &paths, 1, &xr->name, NULL, &sz)) |
if (mansearch(&search, &paths, 1, &xr->name, NULL, &sz)) |
continue; |
continue; |
if (fs_search(&search, &paths, 1, &xr->name, NULL, &sz) != -1) |
if (fs_search(&search, &paths, xr->name, NULL, &sz) != -1) |
continue; |
continue; |
if (xr->count == 1) |
if (xr->count == 1) |
mandoc_msg(MANDOCERR_XR_BAD, xr->line, |
mandoc_msg(MANDOCERR_XR_BAD, xr->line, |