version 1.105, 2014/12/16 23:44:41 |
version 1.109, 2015/01/14 22:58:16 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> |
* Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
Line 191 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 191 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"ignoring macro in table", |
"ignoring macro in table", |
|
|
/* related to document structure and macros */ |
/* related to document structure and macros */ |
|
NULL, |
"input stack limit exceeded, infinite loop?", |
"input stack limit exceeded, infinite loop?", |
"skipping bad character", |
"skipping bad character", |
"skipping unknown macro", |
"skipping unknown macro", |
Line 209 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 210 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"uname(3) system call failed, using UNKNOWN", |
"uname(3) system call failed, using UNKNOWN", |
"unknown standard specifier", |
"unknown standard specifier", |
"skipping request without numeric argument", |
"skipping request without numeric argument", |
|
"NOT IMPLEMENTED: .so with absolute path or \"..\"", |
"skipping all arguments", |
"skipping all arguments", |
"skipping excess arguments", |
"skipping excess arguments", |
"divide by zero", |
"divide by zero", |
Line 216 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 218 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"generic fatal error", |
"generic fatal error", |
|
|
"input too large", |
"input too large", |
"NOT IMPLEMENTED: .so with absolute path or \"..\"", |
|
".so request failed", |
".so request failed", |
|
|
/* system errors */ |
|
"cannot dup file descriptor", |
|
"cannot exec", |
|
"gunzip failed with code", |
|
"cannot fork", |
|
NULL, |
|
"cannot open pipe", |
|
"cannot read file", |
|
"gunzip died from signal", |
|
"cannot stat file", |
|
"wait failed", |
|
}; |
}; |
|
|
static const char * const mandoclevels[MANDOCLEVEL_MAX] = { |
static const char * const mandoclevels[MANDOCLEVEL_MAX] = { |
Line 298 choose_parser(struct mparse *curp) |
|
Line 287 choose_parser(struct mparse *curp) |
|
/* Fall back to man(7) as a last resort. */ |
/* Fall back to man(7) as a last resort. */ |
|
|
if (NULL == curp->pman) |
if (NULL == curp->pman) |
curp->pman = man_alloc(curp->roff, curp, |
curp->pman = man_alloc( |
|
curp->roff, curp, curp->defos, |
MPARSE_QUICK & curp->options ? 1 : 0); |
MPARSE_QUICK & curp->options ? 1 : 0); |
assert(curp->pman); |
assert(curp->pman); |
curp->man = curp->pman; |
curp->man = curp->pman; |
|
|
case ROFF_IGN: |
case ROFF_IGN: |
pos = 0; |
pos = 0; |
continue; |
continue; |
case ROFF_ERR: |
|
assert(MANDOCLEVEL_FATAL <= curp->file_status); |
|
break; |
|
case ROFF_SO: |
case ROFF_SO: |
if ( ! (curp->options & MPARSE_SO) && |
if ( ! (curp->options & MPARSE_SO) && |
(i >= blk.sz || blk.buf[i] == '\0')) { |
(i >= blk.sz || blk.buf[i] == '\0')) { |
Line 610 read_whole_file(struct mparse *curp, const char *file, |
|
Line 597 read_whole_file(struct mparse *curp, const char *file, |
|
#if HAVE_MMAP |
#if HAVE_MMAP |
struct stat st; |
struct stat st; |
if (-1 == fstat(fd, &st)) { |
if (-1 == fstat(fd, &st)) { |
curp->file_status = MANDOCLEVEL_SYSERR; |
perror(file); |
if (curp->mmsg) |
exit((int)MANDOCLEVEL_SYSERR); |
(*curp->mmsg)(MANDOCERR_SYSSTAT, curp->file_status, |
|
file, 0, 0, strerror(errno)); |
|
return(0); |
|
} |
} |
|
|
/* |
/* |
Line 667 read_whole_file(struct mparse *curp, const char *file, |
|
Line 651 read_whole_file(struct mparse *curp, const char *file, |
|
return(1); |
return(1); |
} |
} |
if (ssz == -1) { |
if (ssz == -1) { |
curp->file_status = MANDOCLEVEL_SYSERR; |
perror(file); |
if (curp->mmsg) |
exit((int)MANDOCLEVEL_SYSERR); |
(*curp->mmsg)(MANDOCERR_SYSREAD, |
|
curp->file_status, file, 0, 0, |
|
strerror(errno)); |
|
break; |
|
} |
} |
off += (size_t)ssz; |
off += (size_t)ssz; |
} |
} |
Line 696 mparse_end(struct mparse *curp) |
|
Line 676 mparse_end(struct mparse *curp) |
|
curp->mdoc = curp->pmdoc; |
curp->mdoc = curp->pmdoc; |
else { |
else { |
if (curp->pman == NULL) |
if (curp->pman == NULL) |
curp->pman = man_alloc(curp->roff, curp, |
curp->pman = man_alloc( |
|
curp->roff, curp, curp->defos, |
curp->options & MPARSE_QUICK ? 1 : 0); |
curp->options & MPARSE_QUICK ? 1 : 0); |
curp->man = curp->pman; |
curp->man = curp->pman; |
} |
} |
Line 785 mparse_readfd(struct mparse *curp, int fd, const char |
|
Line 766 mparse_readfd(struct mparse *curp, int fd, const char |
|
save_child = curp->child; |
save_child = curp->child; |
if (fd != -1) |
if (fd != -1) |
curp->child = 0; |
curp->child = 0; |
else if (mparse_open(curp, &fd, file) >= MANDOCLEVEL_SYSERR) |
else if (mparse_open(curp, &fd, file) != MANDOCLEVEL_OK) |
goto out; |
goto out; |
|
|
if (read_whole_file(curp, file, fd, &blk, &with_mmap)) { |
if (read_whole_file(curp, file, fd, &blk, &with_mmap)) { |
Line 817 mparse_open(struct mparse *curp, int *fd, const char * |
|
Line 798 mparse_open(struct mparse *curp, int *fd, const char * |
|
int pfd[2]; |
int pfd[2]; |
int save_errno; |
int save_errno; |
char *cp; |
char *cp; |
enum mandocerr err; |
|
|
|
pfd[1] = -1; |
|
curp->file = file; |
curp->file = file; |
|
|
/* Unless zipped, try to just open the file. */ |
/* Unless zipped, try to just open the file. */ |
Line 843 mparse_open(struct mparse *curp, int *fd, const char * |
|
Line 822 mparse_open(struct mparse *curp, int *fd, const char * |
|
if (access(file, R_OK) == -1) { |
if (access(file, R_OK) == -1) { |
if (cp != NULL) |
if (cp != NULL) |
errno = save_errno; |
errno = save_errno; |
err = MANDOCERR_SYSOPEN; |
free(cp); |
goto out; |
*fd = -1; |
|
curp->child = 0; |
|
mandoc_msg(MANDOCERR_FILE, curp, 0, 0, strerror(errno)); |
|
return(MANDOCLEVEL_ERROR); |
} |
} |
|
|
/* Run gunzip(1). */ |
/* Run gunzip(1). */ |
|
|
if (pipe(pfd) == -1) { |
if (pipe(pfd) == -1) { |
err = MANDOCERR_SYSPIPE; |
perror("pipe"); |
goto out; |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
|
|
switch (curp->child = fork()) { |
switch (curp->child = fork()) { |
case -1: |
case -1: |
err = MANDOCERR_SYSFORK; |
perror("fork"); |
close(pfd[0]); |
exit((int)MANDOCLEVEL_SYSERR); |
close(pfd[1]); |
|
pfd[1] = -1; |
|
break; |
|
case 0: |
case 0: |
close(pfd[0]); |
close(pfd[0]); |
if (dup2(pfd[1], STDOUT_FILENO) == -1) { |
if (dup2(pfd[1], STDOUT_FILENO) == -1) { |
err = MANDOCERR_SYSDUP; |
perror("dup"); |
break; |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
execlp("gunzip", "gunzip", "-c", file, NULL); |
execlp("gunzip", "gunzip", "-c", file, NULL); |
err = MANDOCERR_SYSEXEC; |
perror("exec"); |
break; |
exit((int)MANDOCLEVEL_SYSERR); |
default: |
default: |
close(pfd[1]); |
close(pfd[1]); |
*fd = pfd[0]; |
*fd = pfd[0]; |
return(MANDOCLEVEL_OK); |
return(MANDOCLEVEL_OK); |
} |
} |
|
|
out: |
|
free(cp); |
|
*fd = -1; |
|
curp->child = 0; |
|
curp->file_status = MANDOCLEVEL_SYSERR; |
|
if (curp->mmsg) |
|
(*curp->mmsg)(err, curp->file_status, curp->file, |
|
0, 0, strerror(errno)); |
|
if (pfd[1] != -1) |
|
exit(1); |
|
return(curp->file_status); |
|
} |
} |
|
|
enum mandoclevel |
enum mandoclevel |
Line 898 mparse_wait(struct mparse *curp) |
|
Line 865 mparse_wait(struct mparse *curp) |
|
return(MANDOCLEVEL_OK); |
return(MANDOCLEVEL_OK); |
|
|
if (waitpid(curp->child, &status, 0) == -1) { |
if (waitpid(curp->child, &status, 0) == -1) { |
mandoc_msg(MANDOCERR_SYSWAIT, curp, 0, 0, |
perror("wait"); |
strerror(errno)); |
exit((int)MANDOCLEVEL_SYSERR); |
curp->file_status = MANDOCLEVEL_SYSERR; |
|
return(curp->file_status); |
|
} |
} |
if (WIFSIGNALED(status)) { |
if (WIFSIGNALED(status)) { |
mandoc_vmsg(MANDOCERR_SYSSIG, curp, 0, 0, |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
"%d", WTERMSIG(status)); |
"gunzip died from signal %d", WTERMSIG(status)); |
curp->file_status = MANDOCLEVEL_SYSERR; |
return(MANDOCLEVEL_ERROR); |
return(curp->file_status); |
|
} |
} |
if (WEXITSTATUS(status)) { |
if (WEXITSTATUS(status)) { |
mandoc_vmsg(MANDOCERR_SYSEXIT, curp, 0, 0, |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
"%d", WEXITSTATUS(status)); |
"gunzip failed with code %d", WEXITSTATUS(status)); |
curp->file_status = MANDOCLEVEL_SYSERR; |
return(MANDOCLEVEL_ERROR); |
return(curp->file_status); |
|
} |
} |
return(MANDOCLEVEL_OK); |
return(MANDOCLEVEL_OK); |
} |
} |
Line 940 mparse_alloc(int options, enum mandoclevel wlevel, man |
|
Line 903 mparse_alloc(int options, enum mandoclevel wlevel, man |
|
curp->roff, curp, curp->defos, |
curp->roff, curp, curp->defos, |
curp->options & MPARSE_QUICK ? 1 : 0); |
curp->options & MPARSE_QUICK ? 1 : 0); |
if (curp->options & MPARSE_MAN) |
if (curp->options & MPARSE_MAN) |
curp->pman = man_alloc(curp->roff, curp, |
curp->pman = man_alloc( |
|
curp->roff, curp, curp->defos, |
curp->options & MPARSE_QUICK ? 1 : 0); |
curp->options & MPARSE_QUICK ? 1 : 0); |
|
|
return(curp); |
return(curp); |
Line 1025 mandoc_msg(enum mandocerr er, struct mparse *m, |
|
Line 989 mandoc_msg(enum mandocerr er, struct mparse *m, |
|
while (er < mandoclimits[level]) |
while (er < mandoclimits[level]) |
level--; |
level--; |
|
|
if (level < m->wlevel) |
if (level < m->wlevel && er != MANDOCERR_FILE) |
return; |
return; |
|
|
if (m->mmsg) |
if (m->mmsg) |