version 1.40, 2010/10/22 14:08:53 |
version 1.41, 2011/05/25 14:36:04 |
|
|
static void build_page(char *, char **); |
static void build_page(char *, char **); |
static void cat(char *); |
static void cat(char *); |
static char *check_pager(char *); |
static char *check_pager(char *); |
static int cleanup(void); |
static int cleanup(int); |
static void how(char *); |
static void how(char *); |
static void jump(char **, char *, char *); |
static void jump(char **, char *, char *); |
static int manual(char *, TAG *, glob_t *); |
static int manual(char *, TAG *, glob_t *); |
|
|
|
|
/* 6: If nothing found, we're done. */ |
/* 6: If nothing found, we're done. */ |
if (!found) { |
if (!found) { |
(void)cleanup(); |
(void)cleanup(0); |
exit (1); |
exit (1); |
} |
} |
|
|
|
|
continue; |
continue; |
cat(*ap); |
cat(*ap); |
} |
} |
exit (cleanup()); |
exit (cleanup(0)); |
} |
} |
if (f_how) { |
if (f_how) { |
for (ap = pg.gl_pathv; *ap != NULL; ++ap) { |
for (ap = pg.gl_pathv; *ap != NULL; ++ap) { |
|
|
continue; |
continue; |
how(*ap); |
how(*ap); |
} |
} |
exit(cleanup()); |
exit(cleanup(0)); |
} |
} |
if (f_where) { |
if (f_where) { |
for (ap = pg.gl_pathv; *ap != NULL; ++ap) { |
for (ap = pg.gl_pathv; *ap != NULL; ++ap) { |
|
|
continue; |
continue; |
(void)puts(*ap); |
(void)puts(*ap); |
} |
} |
exit(cleanup()); |
exit(cleanup(0)); |
} |
} |
|
|
/* |
/* |
|
|
} |
} |
if ((cmd = malloc(len)) == NULL) { |
if ((cmd = malloc(len)) == NULL) { |
warn(NULL); |
warn(NULL); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
p = cmd; |
p = cmd; |
|
|
/* Use system(3) in case someone's pager is "pager arg1 arg2". */ |
/* Use system(3) in case someone's pager is "pager arg1 arg2". */ |
(void)system(cmd); |
(void)system(cmd); |
|
|
exit(cleanup()); |
exit(cleanup(0)); |
} |
} |
|
|
/* |
/* |
|
|
GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT | GLOB_QUOTE, |
GLOB_APPEND | GLOB_BRACE | GLOB_NOSORT | GLOB_QUOTE, |
NULL, pg)) { |
NULL, pg)) { |
warn("globbing"); |
warn("globbing"); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
if (pg->gl_matchc == 0) |
if (pg->gl_matchc == 0) |
|
|
if ((ep = malloc(sizeof(ENTRY))) == NULL || |
if ((ep = malloc(sizeof(ENTRY))) == NULL || |
(ep->s = strdup(page)) == NULL) { |
(ep->s = strdup(page)) == NULL) { |
warn(NULL); |
warn(NULL); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
TAILQ_INSERT_TAIL(&missp->list, ep, q); |
TAILQ_INSERT_TAIL(&missp->list, ep, q); |
|
|
(void)strlcpy(tpath, _PATH_TMPFILE, sizeof(tpath)); |
(void)strlcpy(tpath, _PATH_TMPFILE, sizeof(tpath)); |
if ((fd = mkstemp(tpath)) == -1) { |
if ((fd = mkstemp(tpath)) == -1) { |
warn("%s", tpath); |
warn("%s", tpath); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
(void)snprintf(buf, sizeof(buf), "%s > %s", fmt, tpath); |
(void)snprintf(buf, sizeof(buf), "%s > %s", fmt, tpath); |
|
|
(void)close(fd); |
(void)close(fd); |
if ((*pathp = strdup(tpath)) == NULL) { |
if ((*pathp = strdup(tpath)) == NULL) { |
warn(NULL); |
warn(NULL); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
|
|
/* Link the built file into the remove-when-done list. */ |
/* Link the built file into the remove-when-done list. */ |
if ((ep = malloc(sizeof(ENTRY))) == NULL) { |
if ((ep = malloc(sizeof(ENTRY))) == NULL) { |
warn(NULL); |
warn(NULL); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
ep->s = *pathp; |
ep->s = *pathp; |
|
|
|
sigprocmask(SIG_BLOCK, &blocksigs, &osigs); |
TAILQ_INSERT_TAIL(&intmpp->list, ep, q); |
TAILQ_INSERT_TAIL(&intmpp->list, ep, q); |
|
sigprocmask(SIG_SETMASK, &osigs, NULL); |
} |
} |
|
|
/* |
/* |
|
|
|
|
if (!(fp = fopen(fname, "r"))) { |
if (!(fp = fopen(fname, "r"))) { |
warn("%s", fname); |
warn("%s", fname); |
(void)cleanup(); |
(void)cleanup(0); |
exit (1); |
exit (1); |
} |
} |
#define S1 "SYNOPSIS" |
#define S1 "SYNOPSIS" |
|
|
|
|
if ((fd = open(fname, O_RDONLY, 0)) < 0) { |
if ((fd = open(fname, O_RDONLY, 0)) < 0) { |
warn("%s", fname); |
warn("%s", fname); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
while ((n = read(fd, buf, sizeof(buf))) > 0) |
while ((n = read(fd, buf, sizeof(buf))) > 0) |
if (write(STDOUT_FILENO, buf, n) != n) { |
if (write(STDOUT_FILENO, buf, n) != n) { |
warn("write"); |
warn("write"); |
(void)cleanup(); |
(void)cleanup(0); |
exit (1); |
exit (1); |
} |
} |
if (n == -1) { |
if (n == -1) { |
warn("read"); |
warn("read"); |
(void)cleanup(); |
(void)cleanup(0); |
exit(1); |
exit(1); |
} |
} |
(void)close(fd); |
(void)close(fd); |
|
|
static void |
static void |
onsig(int signo) |
onsig(int signo) |
{ |
{ |
(void)cleanup(); /* XXX signal race */ |
(void)cleanup(1); |
|
|
(void)signal(signo, SIG_DFL); |
(void)signal(signo, SIG_DFL); |
(void)kill(getpid(), signo); |
(void)kill(getpid(), signo); |
|
|
* Clean up temporary files, show any error messages. |
* Clean up temporary files, show any error messages. |
*/ |
*/ |
static int |
static int |
cleanup(void) |
cleanup(int insig) |
{ |
{ |
TAG *intmpp, *missp; |
TAG *intmpp, *missp; |
ENTRY *ep; |
ENTRY *ep; |
int rval; |
int rval = 0; |
|
|
rval = 0; |
if (insig == 0) { |
ep = (missp = getlist("_missing")) == NULL ? |
ep = (missp = getlist("_missing")) == NULL ? |
NULL : TAILQ_FIRST(&missp->list); |
NULL : TAILQ_FIRST(&missp->list); |
if (ep != NULL) |
if (ep != NULL) |
for (; ep != NULL; ep = TAILQ_NEXT(ep, q)) { |
for (; ep != NULL; ep = TAILQ_NEXT(ep, q)) { |
if (section) |
if (section) |
warnx("no entry for %s in section %s of the manual.", |
warnx("no entry for %s in " |
ep->s, section->s); |
"section %s of the manual.", |
else |
ep->s, section->s); |
warnx("no entry for %s in the manual.", ep->s); |
else |
rval = 1; |
warnx("no entry for %s in the manual.", |
} |
ep->s); |
|
rval = 1; |
|
} |
|
} |
|
|
ep = (intmpp = getlist("_intmp")) == NULL ? |
ep = (intmpp = getlist("_intmp")) == NULL ? |
NULL : TAILQ_FIRST(&intmpp->list); |
NULL : TAILQ_FIRST(&intmpp->list); |