version 1.107, 2015/01/14 17:49:15 |
version 1.110, 2015/01/15 02:29:26 |
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 \"..\"", |
|
".so request failed", |
"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 219 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", |
|
|
|
/* system errors */ |
|
"gunzip failed with code", |
|
NULL, |
|
"gunzip died from signal", |
|
}; |
}; |
|
|
static const char * const mandoclevels[MANDOCLEVEL_MAX] = { |
static const char * const mandoclevels[MANDOCLEVEL_MAX] = { |
Line 310 mparse_buf_r(struct mparse *curp, struct buf blk, size |
|
Line 306 mparse_buf_r(struct mparse *curp, struct buf blk, size |
|
{ |
{ |
const struct tbl_span *span; |
const struct tbl_span *span; |
struct buf ln; |
struct buf ln; |
|
char *cp; |
size_t pos; /* byte number in the ln buffer */ |
size_t pos; /* byte number in the ln buffer */ |
enum rofferr rr; |
enum rofferr rr; |
int of; |
int of; |
int lnn; /* line number in the real file */ |
int lnn; /* line number in the real file */ |
|
int fd; |
|
pid_t save_child; |
unsigned char c; |
unsigned char c; |
|
|
memset(&ln, 0, sizeof(ln)); |
memset(&ln, 0, sizeof(ln)); |
|
|
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')) { |
|
|
*/ |
*/ |
if (curp->secondary) |
if (curp->secondary) |
curp->secondary->sz -= pos + 1; |
curp->secondary->sz -= pos + 1; |
mparse_readfd(curp, -1, ln.buf + of); |
save_child = curp->child; |
if (MANDOCLEVEL_FATAL <= curp->file_status) { |
if (mparse_open(curp, &fd, ln.buf + of) == |
|
MANDOCLEVEL_OK) |
|
mparse_readfd(curp, fd, ln.buf + of); |
|
else { |
mandoc_vmsg(MANDOCERR_SO_FAIL, |
mandoc_vmsg(MANDOCERR_SO_FAIL, |
curp, curp->line, pos, |
curp, curp->line, pos, |
".so %s", ln.buf + of); |
".so %s", ln.buf + of); |
break; |
ln.sz = mandoc_asprintf(&cp, |
|
".sp\nSee the file %s.\n.sp", |
|
ln.buf + of); |
|
free(ln.buf); |
|
ln.buf = cp; |
|
of = 0; |
|
mparse_buf_r(curp, ln, of, 0); |
} |
} |
|
curp->child = save_child; |
pos = 0; |
pos = 0; |
continue; |
continue; |
default: |
default: |
Line 757 mparse_readmem(struct mparse *curp, void *buf, size_t |
|
Line 763 mparse_readmem(struct mparse *curp, void *buf, size_t |
|
} |
} |
|
|
/* |
/* |
* If a file descriptor is given, use it and assume it points |
|
* to the named file. Otherwise, open the named file. |
|
* Read the whole file into memory and call the parsers. |
* Read the whole file into memory and call the parsers. |
* Called recursively when an .so request is encountered. |
* Called recursively when an .so request is encountered. |
*/ |
*/ |
Line 768 mparse_readfd(struct mparse *curp, int fd, const char |
|
Line 772 mparse_readfd(struct mparse *curp, int fd, const char |
|
struct buf blk; |
struct buf blk; |
int with_mmap; |
int with_mmap; |
int save_filenc; |
int save_filenc; |
pid_t save_child; |
|
|
|
save_child = curp->child; |
|
if (fd != -1) |
|
curp->child = 0; |
|
else if (mparse_open(curp, &fd, file) >= MANDOCLEVEL_SYSERR) |
|
goto out; |
|
|
|
if (read_whole_file(curp, file, fd, &blk, &with_mmap)) { |
if (read_whole_file(curp, file, fd, &blk, &with_mmap)) { |
save_filenc = curp->filenc; |
save_filenc = curp->filenc; |
curp->filenc = curp->options & |
curp->filenc = curp->options & |
Line 794 mparse_readfd(struct mparse *curp, int fd, const char |
|
Line 791 mparse_readfd(struct mparse *curp, int fd, const char |
|
perror(file); |
perror(file); |
|
|
mparse_wait(curp); |
mparse_wait(curp); |
out: |
|
curp->child = save_child; |
|
return(curp->file_status); |
return(curp->file_status); |
} |
} |
|
|
Line 805 mparse_open(struct mparse *curp, int *fd, const char * |
|
Line 800 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 831 mparse_open(struct mparse *curp, int *fd, const char * |
|
Line 824 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). */ |
Line 860 mparse_open(struct mparse *curp, int *fd, const char * |
|
Line 856 mparse_open(struct mparse *curp, int *fd, const char * |
|
*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 887 mparse_wait(struct mparse *curp) |
|
Line 871 mparse_wait(struct mparse *curp) |
|
exit((int)MANDOCLEVEL_SYSERR); |
exit((int)MANDOCLEVEL_SYSERR); |
} |
} |
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 1009 mandoc_msg(enum mandocerr er, struct mparse *m, |
|
Line 991 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) |