version 1.321, 2019/03/04 18:15:06 |
version 1.328, 2019/07/06 20:05:27 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
#include <sys/param.h> /* MACHINE */ |
#include <sys/param.h> /* MACHINE */ |
|
#include <sys/stat.h> |
#include <sys/wait.h> |
#include <sys/wait.h> |
|
|
#include <assert.h> |
#include <assert.h> |
Line 125 main(int argc, char *argv[]) |
|
Line 126 main(int argc, char *argv[]) |
|
char *conf_file, *defpaths, *auxpaths; |
char *conf_file, *defpaths, *auxpaths; |
char *oarg, *tagarg; |
char *oarg, *tagarg; |
unsigned char *uc; |
unsigned char *uc; |
size_t i, sz; |
size_t i, sz, ssz; |
int prio, best_prio; |
int prio, best_prio; |
enum outmode outmode; |
enum outmode outmode; |
int fd, startdir; |
int fd, startdir; |
Line 299 main(int argc, char *argv[]) |
|
Line 300 main(int argc, char *argv[]) |
|
search.outkey = oarg; |
search.outkey = oarg; |
else { |
else { |
while (oarg != NULL) { |
while (oarg != NULL) { |
thisarg = oarg; |
|
if (manconf_output(&conf.output, |
if (manconf_output(&conf.output, |
strsep(&oarg, ","), 0) == 0) |
strsep(&oarg, ","), 0) == -1) |
continue; |
return (int)MANDOCLEVEL_BADARG; |
warnx("-O %s: Bad argument", thisarg); |
|
return (int)MANDOCLEVEL_BADARG; |
|
} |
} |
} |
} |
} |
} |
Line 355 main(int argc, char *argv[]) |
|
Line 353 main(int argc, char *argv[]) |
|
} else if (argc > 1 && |
} else if (argc > 1 && |
((uc = (unsigned char *)argv[0]) != NULL) && |
((uc = (unsigned char *)argv[0]) != NULL) && |
((isdigit(uc[0]) && (uc[1] == '\0' || |
((isdigit(uc[0]) && (uc[1] == '\0' || |
(isalpha(uc[1]) && uc[2] == '\0'))) || |
isalpha(uc[1]))) || |
(uc[0] == 'n' && uc[1] == '\0'))) { |
(uc[0] == 'n' && uc[1] == '\0'))) { |
search.sec = (char *)uc; |
search.sec = (char *)uc; |
argv++; |
argv++; |
Line 411 main(int argc, char *argv[]) |
|
Line 409 main(int argc, char *argv[]) |
|
res[sz].file = mandoc_strdup(argv[c]); |
res[sz].file = mandoc_strdup(argv[c]); |
res[sz].names = NULL; |
res[sz].names = NULL; |
res[sz].output = NULL; |
res[sz].output = NULL; |
|
res[sz].bits = 0; |
res[sz].ipath = SIZE_MAX; |
res[sz].ipath = SIZE_MAX; |
res[sz].sec = 10; |
res[sz].sec = 10; |
res[sz].form = FORM_SRC; |
res[sz].form = FORM_SRC; |
Line 433 main(int argc, char *argv[]) |
|
Line 432 main(int argc, char *argv[]) |
|
|
|
if (outmode == OUTMODE_ONE) { |
if (outmode == OUTMODE_ONE) { |
argc = 1; |
argc = 1; |
best_prio = 20; |
best_prio = 40; |
} else if (outmode == OUTMODE_ALL) |
} else if (outmode == OUTMODE_ALL) |
argc = (int)sz; |
argc = (int)sz; |
|
|
Line 452 main(int argc, char *argv[]) |
|
Line 451 main(int argc, char *argv[]) |
|
sec = res[i].file; |
sec = res[i].file; |
sec += strcspn(sec, "123456789"); |
sec += strcspn(sec, "123456789"); |
if (sec[0] == '\0') |
if (sec[0] == '\0') |
continue; |
continue; /* No section at all. */ |
prio = sec_prios[sec[0] - '1']; |
prio = sec_prios[sec[0] - '1']; |
if (sec[1] != '/') |
if (search.sec != NULL) { |
prio += 10; |
ssz = strlen(search.sec); |
|
if (strncmp(sec, search.sec, ssz) == 0) |
|
sec += ssz; |
|
} else |
|
sec++; /* Prefer without suffix. */ |
|
if (*sec != '/') |
|
prio += 10; /* Wrong dir name. */ |
|
if (search.sec != NULL && |
|
(strlen(sec) <= ssz + 3 || |
|
strcmp(sec + strlen(sec) - ssz, |
|
search.sec) != 0)) |
|
prio += 20; /* Wrong file ext. */ |
if (prio >= best_prio) |
if (prio >= best_prio) |
continue; |
continue; |
best_prio = prio; |
best_prio = prio; |
Line 494 main(int argc, char *argv[]) |
|
Line 504 main(int argc, char *argv[]) |
|
if (argc < 1) { |
if (argc < 1) { |
if (use_pager) { |
if (use_pager) { |
tag_files = tag_init(); |
tag_files = tag_init(); |
tag_files->tagname = conf.output.tag; |
if (tag_files != NULL) |
|
tag_files->tagname = conf.output.tag; |
} |
} |
thisarg = "<stdin>"; |
thisarg = "<stdin>"; |
mandoc_msg_setinfilename(thisarg); |
mandoc_msg_setinfilename(thisarg); |
Line 532 main(int argc, char *argv[]) |
|
Line 543 main(int argc, char *argv[]) |
|
if (use_pager) { |
if (use_pager) { |
use_pager = 0; |
use_pager = 0; |
tag_files = tag_init(); |
tag_files = tag_init(); |
tag_files->tagname = conf.output.tag; |
if (tag_files != NULL) |
|
tag_files->tagname = conf.output.tag; |
} |
} |
|
|
mandoc_msg_setinfilename(thisarg); |
mandoc_msg_setinfilename(thisarg); |
Line 701 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 713 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, |
struct manpage **res, size_t *ressz) |
struct manpage **res, size_t *ressz) |
{ |
{ |
|
struct stat sb; |
glob_t globinfo; |
glob_t globinfo; |
struct manpage *page; |
struct manpage *page; |
char *file; |
char *file; |
Line 710 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 723 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
form = FORM_SRC; |
form = FORM_SRC; |
mandoc_asprintf(&file, "%s/man%s/%s.%s", |
mandoc_asprintf(&file, "%s/man%s/%s.%s", |
paths->paths[ipath], sec, name, sec); |
paths->paths[ipath], sec, name, sec); |
if (access(file, R_OK) != -1) |
if (stat(file, &sb) != -1) |
goto found; |
goto found; |
free(file); |
free(file); |
|
|
mandoc_asprintf(&file, "%s/cat%s/%s.0", |
mandoc_asprintf(&file, "%s/cat%s/%s.0", |
paths->paths[ipath], sec, name); |
paths->paths[ipath], sec, name); |
if (access(file, R_OK) != -1) { |
if (stat(file, &sb) != -1) { |
form = FORM_CAT; |
form = FORM_CAT; |
goto found; |
goto found; |
} |
} |
Line 725 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 738 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
if (arch != NULL) { |
if (arch != NULL) { |
mandoc_asprintf(&file, "%s/man%s/%s/%s.%s", |
mandoc_asprintf(&file, "%s/man%s/%s/%s.%s", |
paths->paths[ipath], sec, arch, name, sec); |
paths->paths[ipath], sec, arch, name, sec); |
if (access(file, R_OK) != -1) |
if (stat(file, &sb) != -1) |
goto found; |
goto found; |
free(file); |
free(file); |
} |
} |
Line 739 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 752 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
if (globres == 0) |
if (globres == 0) |
file = mandoc_strdup(*globinfo.gl_pathv); |
file = mandoc_strdup(*globinfo.gl_pathv); |
globfree(&globinfo); |
globfree(&globinfo); |
if (globres == 0) |
if (globres == 0) { |
goto found; |
if (stat(file, &sb) != -1) |
|
goto found; |
|
free(file); |
|
} |
if (res != NULL || ipath + 1 != paths->sz) |
if (res != NULL || ipath + 1 != paths->sz) |
return 0; |
return 0; |
|
|
mandoc_asprintf(&file, "%s.%s", name, sec); |
mandoc_asprintf(&file, "%s.%s", name, sec); |
globres = access(file, R_OK); |
globres = stat(file, &sb); |
free(file); |
free(file); |
return globres != -1; |
return globres != -1; |
|
|
|
|
page->file = file; |
page->file = file; |
page->names = NULL; |
page->names = NULL; |
page->output = NULL; |
page->output = NULL; |
|
page->bits = NAME_FILE & NAME_MASK; |
page->ipath = ipath; |
page->ipath = ipath; |
page->sec = (*sec >= '1' && *sec <= '9') ? *sec - '1' + 1 : 10; |
page->sec = (*sec >= '1' && *sec <= '9') ? *sec - '1' + 1 : 10; |
page->form = form; |
page->form = form; |
Line 1161 spawn_pager(struct tag_files *tag_files) |
|
Line 1178 spawn_pager(struct tag_files *tag_files) |
|
char *argv[MAX_PAGER_ARGS]; |
char *argv[MAX_PAGER_ARGS]; |
const char *pager; |
const char *pager; |
char *cp; |
char *cp; |
|
#if HAVE_LESS_T |
size_t cmdlen; |
size_t cmdlen; |
|
#endif |
int argc, use_ofn; |
int argc, use_ofn; |
pid_t pager_pid; |
pid_t pager_pid; |
|
|
Line 1193 spawn_pager(struct tag_files *tag_files) |
|
Line 1212 spawn_pager(struct tag_files *tag_files) |
|
/* For less(1), use the tag file. */ |
/* For less(1), use the tag file. */ |
|
|
use_ofn = 1; |
use_ofn = 1; |
|
#if HAVE_LESS_T |
if ((cmdlen = strlen(argv[0])) >= 4) { |
if ((cmdlen = strlen(argv[0])) >= 4) { |
cp = argv[0] + cmdlen - 4; |
cp = argv[0] + cmdlen - 4; |
if (strcmp(cp, "less") == 0) { |
if (strcmp(cp, "less") == 0) { |
Line 1205 spawn_pager(struct tag_files *tag_files) |
|
Line 1225 spawn_pager(struct tag_files *tag_files) |
|
} |
} |
} |
} |
} |
} |
|
#endif |
if (use_ofn) |
if (use_ofn) |
argv[argc++] = tag_files->ofn; |
argv[argc++] = tag_files->ofn; |
argv[argc] = NULL; |
argv[argc] = NULL; |