version 1.238, 2015/04/29 11:04:17 |
version 1.241, 2015/07/19 00:07:42 |
|
|
#include "roff.h" |
#include "roff.h" |
#include "mdoc.h" |
#include "mdoc.h" |
#include "man.h" |
#include "man.h" |
|
#include "tag.h" |
#include "main.h" |
#include "main.h" |
#include "manconf.h" |
#include "manconf.h" |
#include "mansearch.h" |
#include "mansearch.h" |
Line 418 main(int argc, char *argv[]) |
|
Line 419 main(int argc, char *argv[]) |
|
if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) |
if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) |
return((int)MANDOCLEVEL_BADARG); |
return((int)MANDOCLEVEL_BADARG); |
|
|
|
if (pager_pid == 1 && isatty(STDOUT_FILENO) == 0) |
|
pager_pid = 0; |
|
|
curp.mchars = mchars_alloc(); |
curp.mchars = mchars_alloc(); |
curp.mp = mparse_alloc(options, curp.wlevel, mmsg, |
curp.mp = mparse_alloc(options, curp.wlevel, mmsg, |
curp.mchars, defos); |
curp.mchars, defos); |
Line 429 main(int argc, char *argv[]) |
|
Line 433 main(int argc, char *argv[]) |
|
mparse_keep(curp.mp); |
mparse_keep(curp.mp); |
|
|
if (argc < 1) { |
if (argc < 1) { |
if (pager_pid == 1 && isatty(STDOUT_FILENO)) |
if (pager_pid == 1) |
pager_pid = spawn_pager(); |
pager_pid = spawn_pager(); |
parse(&curp, STDIN_FILENO, "<stdin>"); |
parse(&curp, STDIN_FILENO, "<stdin>"); |
} |
} |
Line 441 main(int argc, char *argv[]) |
|
Line 445 main(int argc, char *argv[]) |
|
rc = rctmp; |
rc = rctmp; |
|
|
if (fd != -1) { |
if (fd != -1) { |
if (pager_pid == 1 && isatty(STDOUT_FILENO)) |
if (pager_pid == 1) |
pager_pid = spawn_pager(); |
pager_pid = spawn_pager(); |
|
|
if (resp == NULL) |
if (resp == NULL) |
|
|
|
|
if (pager_pid != 0 && pager_pid != 1) { |
if (pager_pid != 0 && pager_pid != 1) { |
fclose(stdout); |
fclose(stdout); |
|
tag_write(); |
waitpid(pager_pid, NULL, 0); |
waitpid(pager_pid, NULL, 0); |
|
tag_unlink(); |
} |
} |
|
|
return((int)rc); |
return((int)rc); |
Line 567 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
Line 573 fs_lookup(const struct manpaths *paths, size_t ipath, |
|
free(file); |
free(file); |
} |
} |
|
|
mandoc_asprintf(&file, "%s/man%s/%s.*", |
mandoc_asprintf(&file, "%s/man%s/%s.[01-9]*", |
paths->paths[ipath], sec, name); |
paths->paths[ipath], sec, name); |
globres = glob(file, 0, NULL, &globinfo); |
globres = glob(file, 0, NULL, &globinfo); |
if (globres != 0 && globres != GLOB_NOMATCH) |
if (globres != 0 && globres != GLOB_NOMATCH) |
Line 959 spawn_pager(void) |
|
Line 965 spawn_pager(void) |
|
char *argv[MAX_PAGER_ARGS]; |
char *argv[MAX_PAGER_ARGS]; |
const char *pager; |
const char *pager; |
char *cp; |
char *cp; |
|
size_t cmdlen; |
int fildes[2]; |
int fildes[2]; |
int argc; |
int argc; |
pid_t pager_pid; |
pid_t pager_pid; |
|
|
|
pager = getenv("MANPAGER"); |
|
if (pager == NULL || *pager == '\0') |
|
pager = getenv("PAGER"); |
|
if (pager == NULL || *pager == '\0') |
|
pager = "more -s"; |
|
cp = mandoc_strdup(pager); |
|
|
|
/* |
|
* Parse the pager command into words. |
|
* Intentionally do not do anything fancy here. |
|
*/ |
|
|
|
argc = 0; |
|
while (argc + 4 < MAX_PAGER_ARGS) { |
|
argv[argc++] = cp; |
|
cp = strchr(cp, ' '); |
|
if (cp == NULL) |
|
break; |
|
*cp++ = '\0'; |
|
while (*cp == ' ') |
|
cp++; |
|
if (*cp == '\0') |
|
break; |
|
} |
|
|
|
/* Read all text right away and use the tag file. */ |
|
|
|
if ((cmdlen = strlen(argv[0])) >= 4) { |
|
cp = argv[0] + cmdlen - 4; |
|
if (strcmp(cp, "less") == 0 || |
|
strcmp(cp, "more") == 0) { |
|
tag_init(); |
|
argv[argc++] = mandoc_strdup("+G1G"); |
|
argv[argc++] = mandoc_strdup("-T"); |
|
argv[argc++] = tag_filename(); |
|
} |
|
} |
|
argv[argc] = NULL; |
|
|
if (pipe(fildes) == -1) { |
if (pipe(fildes) == -1) { |
fprintf(stderr, "%s: pipe: %s\n", |
fprintf(stderr, "%s: pipe: %s\n", |
progname, strerror(errno)); |
progname, strerror(errno)); |
Line 997 spawn_pager(void) |
|
Line 1043 spawn_pager(void) |
|
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
close(fildes[0]); |
close(fildes[0]); |
|
|
pager = getenv("MANPAGER"); |
|
if (pager == NULL || *pager == '\0') |
|
pager = getenv("PAGER"); |
|
if (pager == NULL || *pager == '\0') |
|
pager = "more -s"; |
|
cp = mandoc_strdup(pager); |
|
|
|
/* |
|
* Parse the pager command into words. |
|
* Intentionally do not do anything fancy here. |
|
*/ |
|
|
|
argc = 0; |
|
while (argc + 1 < MAX_PAGER_ARGS) { |
|
argv[argc++] = cp; |
|
cp = strchr(cp, ' '); |
|
if (cp == NULL) |
|
break; |
|
*cp++ = '\0'; |
|
while (*cp == ' ') |
|
cp++; |
|
if (*cp == '\0') |
|
break; |
|
} |
|
argv[argc] = NULL; |
|
|
|
/* Hand over to the pager. */ |
/* Hand over to the pager. */ |
|
|