version 1.204, 2018/12/14 01:24:49 |
version 1.205, 2018/12/14 02:16:21 |
Line 65 static void resize_buf(struct buf *, size_t); |
|
Line 65 static void resize_buf(struct buf *, size_t); |
|
static int mparse_buf_r(struct mparse *, struct buf, size_t, int); |
static int mparse_buf_r(struct mparse *, struct buf, size_t, int); |
static int read_whole_file(struct mparse *, int, struct buf *, int *); |
static int read_whole_file(struct mparse *, int, struct buf *, int *); |
static void mparse_end(struct mparse *); |
static void mparse_end(struct mparse *); |
static void mparse_parse_buffer(struct mparse *, struct buf, |
|
const char *); |
|
|
|
|
|
static void |
static void |
Line 538 mparse_end(struct mparse *curp) |
|
Line 536 mparse_end(struct mparse *curp) |
|
roff_endparse(curp->roff); |
roff_endparse(curp->roff); |
} |
} |
|
|
static void |
/* |
mparse_parse_buffer(struct mparse *curp, struct buf blk, const char *file) |
* Read the whole file into memory and call the parsers. |
|
* Called recursively when an .so request is encountered. |
|
*/ |
|
void |
|
mparse_readfd(struct mparse *curp, int fd, const char *filename) |
{ |
{ |
struct buf *svprimary; |
|
const char *svfile; |
|
size_t offset; |
|
static int recursion_depth; |
static int recursion_depth; |
|
|
if (64 < recursion_depth) { |
struct buf blk; |
|
struct buf *save_primary; |
|
const char *save_filename; |
|
size_t offset; |
|
int save_filenc, save_lineno; |
|
int with_mmap; |
|
|
|
if (recursion_depth > 64) { |
mandoc_msg(MANDOCERR_ROFFLOOP, curp, curp->line, 0, NULL); |
mandoc_msg(MANDOCERR_ROFFLOOP, curp, curp->line, 0, NULL); |
return; |
return; |
} |
} |
|
if (read_whole_file(curp, fd, &blk, &with_mmap) == 0) |
|
return; |
|
|
/* Line number is per-file. */ |
/* |
svfile = mandoc_msg_getinfilename(); |
* Save some properties of the parent file. |
mandoc_msg_setinfilename(file); |
*/ |
svprimary = curp->primary; |
|
|
save_primary = curp->primary; |
|
save_filenc = curp->filenc; |
|
save_lineno = curp->line; |
|
save_filename = mandoc_msg_getinfilename(); |
|
|
curp->primary = &blk; |
curp->primary = &blk; |
|
curp->filenc = curp->options & (MPARSE_UTF8 | MPARSE_LATIN1); |
curp->line = 1; |
curp->line = 1; |
recursion_depth++; |
mandoc_msg_setinfilename(filename); |
|
|
/* Skip an UTF-8 byte order mark. */ |
/* Skip an UTF-8 byte order mark. */ |
if (curp->filenc & MPARSE_UTF8 && blk.sz > 2 && |
if (curp->filenc & MPARSE_UTF8 && blk.sz > 2 && |
Line 569 mparse_parse_buffer(struct mparse *curp, struct buf bl |
|
Line 583 mparse_parse_buffer(struct mparse *curp, struct buf bl |
|
} else |
} else |
offset = 0; |
offset = 0; |
|
|
|
recursion_depth++; |
mparse_buf_r(curp, blk, offset, 1); |
mparse_buf_r(curp, blk, offset, 1); |
|
|
if (--recursion_depth == 0) |
if (--recursion_depth == 0) |
mparse_end(curp); |
mparse_end(curp); |
|
|
curp->primary = svprimary; |
/* |
if (svfile != NULL) |
* Clean up and restore saved parent properties. |
mandoc_msg_setinfilename(svfile); |
*/ |
} |
|
|
|
/* |
if (with_mmap) |
* Read the whole file into memory and call the parsers. |
munmap(blk.buf, blk.sz); |
* Called recursively when an .so request is encountered. |
else |
*/ |
free(blk.buf); |
void |
|
mparse_readfd(struct mparse *curp, int fd, const char *file) |
|
{ |
|
struct buf blk; |
|
int with_mmap; |
|
int save_filenc; |
|
|
|
if (read_whole_file(curp, fd, &blk, &with_mmap)) { |
curp->primary = save_primary; |
save_filenc = curp->filenc; |
curp->filenc = save_filenc; |
curp->filenc = curp->options & |
curp->line = save_lineno; |
(MPARSE_UTF8 | MPARSE_LATIN1); |
if (save_filename != NULL) |
mparse_parse_buffer(curp, blk, file); |
mandoc_msg_setinfilename(save_filename); |
curp->filenc = save_filenc; |
|
if (with_mmap) |
|
munmap(blk.buf, blk.sz); |
|
else |
|
free(blk.buf); |
|
} |
|
} |
} |
|
|
int |
int |