static void mparse_readfd_r(struct mparse *curp, int fd, const char *file, int re) { const char *svfile; if (-1 == fd) if (-1 == (fd = open(file, O_RDONLY, 0))) { perror(file); curp->file_status = MANDOCLEVEL_SYSERR; return; } svfile = curp->file; curp->file = file; pdesc(curp, file, fd); if (0 == re && MANDOCLEVEL_FATAL > curp->file_status) mparse_end(curp); if (STDIN_FILENO != fd && -1 == close(fd)) perror(file); curp->file = svfile; }
static void mparse_parse_buffer(struct mparse *curp, struct buf blk, const char *file) { struct buf *svprimary; const char *svfile; size_t offset; static int recursion_depth; if (64 < recursion_depth) { mandoc_msg(MANDOCERR_ROFFLOOP, curp, curp->line, 0, NULL); return; } /* Line number is per-file. */ svfile = curp->file; curp->file = file; svprimary = curp->primary; curp->primary = &blk; curp->line = 1; recursion_depth++; /* Skip an UTF-8 byte order mark. */ if (curp->filenc & MPARSE_UTF8 && blk.sz > 2 && (unsigned char)blk.buf[0] == 0xef && (unsigned char)blk.buf[1] == 0xbb && (unsigned char)blk.buf[2] == 0xbf) { offset = 3; curp->filenc &= ~MPARSE_LATIN1; } else offset = 0; mparse_buf_r(curp, blk, offset, 1); if (--recursion_depth == 0) mparse_end(curp); curp->primary = svprimary; curp->file = svfile; }
static void mparse_parse_buffer(struct mparse *curp, struct buf blk, const char *file) { const char *svfile; static int recursion_depth; if (64 < recursion_depth) { mandoc_msg(MANDOCERR_ROFFLOOP, curp, curp->line, 0, NULL); return; } /* Line number is per-file. */ svfile = curp->file; curp->file = file; curp->line = 1; recursion_depth++; mparse_buf_r(curp, blk, 1); if (0 == --recursion_depth && MANDOCLEVEL_FATAL > curp->file_status) mparse_end(curp); curp->file = svfile; }