version 1.329, 2019/07/10 19:39:01 |
version 1.333, 2019/07/26 18:01:43 |
Line 101 static int fs_search(const struct mansearch *, |
|
Line 101 static int fs_search(const struct mansearch *, |
|
static void outdata_alloc(struct curparse *); |
static void outdata_alloc(struct curparse *); |
static void parse(struct curparse *, int, const char *); |
static void parse(struct curparse *, int, const char *); |
static void passthrough(int, int); |
static void passthrough(int, int); |
|
static void run_pager(struct tag_files *); |
static pid_t spawn_pager(struct tag_files *); |
static pid_t spawn_pager(struct tag_files *); |
static void usage(enum argmode) __attribute__((__noreturn__)); |
static void usage(enum argmode) __attribute__((__noreturn__)); |
static int woptions(struct curparse *, char *); |
static int woptions(struct curparse *, char *); |
Line 130 main(int argc, char *argv[]) |
|
Line 131 main(int argc, char *argv[]) |
|
int show_usage; |
int show_usage; |
int options; |
int options; |
int use_pager; |
int use_pager; |
int status, signum; |
|
int c; |
int c; |
pid_t pager_pid, tc_pgid, man_pgid, pid; |
|
|
|
#if HAVE_PROGNAME |
#if HAVE_PROGNAME |
progname = getprogname(); |
progname = getprogname(); |
|
|
manconf_free(&conf); |
manconf_free(&conf); |
mansearch_free(res, sz); |
mansearch_free(res, sz); |
} |
} |
|
|
free(curp.os_s); |
free(curp.os_s); |
|
|
/* |
|
* When using a pager, finish writing both temporary files, |
|
* fork it, wait for the user to close it, and clean up. |
|
*/ |
|
|
|
if (tag_files != NULL) { |
if (tag_files != NULL) { |
fclose(stdout); |
fclose(stdout); |
tag_write(); |
tag_write(); |
man_pgid = getpgid(0); |
run_pager(tag_files); |
tag_files->tcpgid = man_pgid == getpid() ? |
|
getpgid(getppid()) : man_pgid; |
|
pager_pid = 0; |
|
signum = SIGSTOP; |
|
for (;;) { |
|
|
|
/* Stop here until moved to the foreground. */ |
|
|
|
tc_pgid = tcgetpgrp(tag_files->ofd); |
|
if (tc_pgid != man_pgid) { |
|
if (tc_pgid == pager_pid) { |
|
(void)tcsetpgrp(tag_files->ofd, |
|
man_pgid); |
|
if (signum == SIGTTIN) |
|
continue; |
|
} else |
|
tag_files->tcpgid = tc_pgid; |
|
kill(0, signum); |
|
continue; |
|
} |
|
|
|
/* Once in the foreground, activate the pager. */ |
|
|
|
if (pager_pid) { |
|
(void)tcsetpgrp(tag_files->ofd, pager_pid); |
|
kill(pager_pid, SIGCONT); |
|
} else |
|
pager_pid = spawn_pager(tag_files); |
|
|
|
/* Wait for the pager to stop or exit. */ |
|
|
|
while ((pid = waitpid(pager_pid, &status, |
|
WUNTRACED)) == -1 && errno == EINTR) |
|
continue; |
|
|
|
if (pid == -1) { |
|
mandoc_msg(MANDOCERR_WAIT, 0, 0, |
|
"%s", strerror(errno)); |
|
break; |
|
} |
|
if (!WIFSTOPPED(status)) |
|
break; |
|
|
|
signum = WSTOPSIG(status); |
|
} |
|
tag_unlink(); |
tag_unlink(); |
} |
} else if (curp.outtype != OUTT_LINT && |
|
(search.argmode == ARG_FILE || sz > 0)) |
|
mandoc_msg_summary(); |
|
|
return (int)mandoc_msg_getrc(); |
return (int)mandoc_msg_getrc(); |
} |
} |
|
|
Line 1148 woptions(struct curparse *curp, char *arg) |
|
Line 1099 woptions(struct curparse *curp, char *arg) |
|
return 0; |
return 0; |
} |
} |
|
|
|
/* |
|
* Wait until moved to the foreground, |
|
* then fork the pager and wait for the user to close it. |
|
*/ |
|
static void |
|
run_pager(struct tag_files *tag_files) |
|
{ |
|
int signum, status; |
|
pid_t man_pgid, tc_pgid; |
|
pid_t pager_pid, wait_pid; |
|
|
|
man_pgid = getpgid(0); |
|
tag_files->tcpgid = man_pgid == getpid() ? getpgid(getppid()) : |
|
man_pgid; |
|
pager_pid = 0; |
|
signum = SIGSTOP; |
|
|
|
for (;;) { |
|
/* Stop here until moved to the foreground. */ |
|
|
|
tc_pgid = tcgetpgrp(tag_files->ofd); |
|
if (tc_pgid != man_pgid) { |
|
if (tc_pgid == pager_pid) { |
|
(void)tcsetpgrp(tag_files->ofd, man_pgid); |
|
if (signum == SIGTTIN) |
|
continue; |
|
} else |
|
tag_files->tcpgid = tc_pgid; |
|
kill(0, signum); |
|
continue; |
|
} |
|
|
|
/* Once in the foreground, activate the pager. */ |
|
|
|
if (pager_pid) { |
|
(void)tcsetpgrp(tag_files->ofd, pager_pid); |
|
kill(pager_pid, SIGCONT); |
|
} else |
|
pager_pid = spawn_pager(tag_files); |
|
|
|
/* Wait for the pager to stop or exit. */ |
|
|
|
while ((wait_pid = waitpid(pager_pid, &status, |
|
WUNTRACED)) == -1 && errno == EINTR) |
|
continue; |
|
|
|
if (wait_pid == -1) { |
|
mandoc_msg(MANDOCERR_WAIT, 0, 0, |
|
"%s", strerror(errno)); |
|
break; |
|
} |
|
if (!WIFSTOPPED(status)) |
|
break; |
|
|
|
signum = WSTOPSIG(status); |
|
} |
|
} |
|
|
static pid_t |
static pid_t |
spawn_pager(struct tag_files *tag_files) |
spawn_pager(struct tag_files *tag_files) |
{ |
{ |
Line 1191 spawn_pager(struct tag_files *tag_files) |
|
Line 1200 spawn_pager(struct tag_files *tag_files) |
|
|
|
use_ofn = 1; |
use_ofn = 1; |
#if HAVE_LESS_T |
#if HAVE_LESS_T |
if ((cmdlen = strlen(argv[0])) >= 4) { |
if (*tag_files->tfn != '\0' && (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) { |
argv[argc++] = mandoc_strdup("-T"); |
argv[argc++] = mandoc_strdup("-T"); |