=================================================================== RCS file: /cvs/mandoc/read.c,v retrieving revision 1.110 retrieving revision 1.114 diff -u -p -r1.110 -r1.114 --- mandoc/read.c 2015/01/15 02:29:26 1.110 +++ mandoc/read.c 2015/01/22 21:38:16 1.114 @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.110 2015/01/15 02:29:26 schwarze Exp $ */ +/* $Id: read.c,v 1.114 2015/01/22 21:38:16 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -80,7 +80,7 @@ static const enum mandocerr mandoclimits[MANDOCLEVEL_M MANDOCERR_WARNING, MANDOCERR_WARNING, MANDOCERR_ERROR, - MANDOCERR_FATAL, + MANDOCERR_UNSUPP, MANDOCERR_MAX, MANDOCERR_MAX }; @@ -180,21 +180,18 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "unexpected end of equation", /* related to tables */ - "bad table syntax", - "bad table option", - "bad table layout", "no table layout cells specified", "no table data cells specified", "ignore data in cell", "data block still open", "ignoring extra data cells", - "ignoring macro in table", /* related to document structure and macros */ NULL, "input stack limit exceeded, infinite loop?", "skipping bad character", "skipping unknown macro", + "skipping insecure request", "skipping item outside list", "skipping column outside column list", "skipping end of block that is not open", @@ -216,9 +213,14 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "skipping excess arguments", "divide by zero", - "generic fatal error", - + "unsupported feature", "input too large", + "unsupported control character", + "unsupported roff request", + "unsupported table syntax", + "unsupported table option", + "unsupported table layout", + "ignoring macro in table", }; static const char * const mandoclevels[MANDOCLEVEL_MAX] = { @@ -226,7 +228,7 @@ static const char * const mandoclevels[MANDOCLEVEL_MAX "RESERVED", "WARNING", "ERROR", - "FATAL", + "UNSUPP", "BADARG", "SYSERR" }; @@ -306,6 +308,7 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size { const struct tbl_span *span; struct buf ln; + const char *save_file; char *cp; size_t pos; /* byte number in the ln buffer */ enum rofferr rr; @@ -367,9 +370,8 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size if (c & 0x80) { if ( ! (curp->filenc && preconv_encode( &blk, &i, &ln, &pos, &curp->filenc))) { - mandoc_vmsg(MANDOCERR_BADCHAR, - curp, curp->line, pos, - "0x%x", c); + mandoc_vmsg(MANDOCERR_CHAR_BAD, curp, + curp->line, pos, "0x%x", c); ln.buf[pos++] = '?'; i++; } @@ -381,8 +383,10 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size */ if (c == 0x7f || (c < 0x20 && c != 0x09)) { - mandoc_vmsg(MANDOCERR_BADCHAR, curp, - curp->line, pos, "0x%x", c); + mandoc_vmsg(c == 0x00 || c == 0x04 || + c > 0x0a ? MANDOCERR_CHAR_BAD : + MANDOCERR_CHAR_UNSUPP, + curp, curp->line, pos, "0x%x", c); i++; ln.buf[pos++] = '?'; continue; @@ -438,7 +442,7 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size if ( ! (isascii(c) && (isgraph(c) || isblank(c)))) { - mandoc_vmsg(MANDOCERR_BADCHAR, curp, + mandoc_vmsg(MANDOCERR_CHAR_BAD, curp, curp->line, pos, "0x%x", c); i += 2; ln.buf[pos++] = '?'; @@ -521,11 +525,14 @@ rerun: */ if (curp->secondary) curp->secondary->sz -= pos + 1; + save_file = curp->file; save_child = curp->child; if (mparse_open(curp, &fd, ln.buf + of) == - MANDOCLEVEL_OK) + MANDOCLEVEL_OK) { mparse_readfd(curp, fd, ln.buf + of); - else { + curp->file = save_file; + } else { + curp->file = save_file; mandoc_vmsg(MANDOCERR_SO_FAIL, curp, curp->line, pos, ".so %s", ln.buf + of); @@ -545,14 +552,6 @@ rerun: } /* - * If we encounter errors in the recursive parse, make - * sure we don't continue parsing. - */ - - if (MANDOCLEVEL_FATAL <= curp->file_status) - break; - - /* * If input parsers have not been allocated, do so now. * We keep these instanced between parsers, but set them * locally per parse routine since we can use different @@ -623,10 +622,7 @@ read_whole_file(struct mparse *curp, const char *file, if (S_ISREG(st.st_mode)) { if (st.st_size >= (1U << 31)) { - curp->file_status = MANDOCLEVEL_FATAL; - if (curp->mmsg) - (*curp->mmsg)(MANDOCERR_TOOLARGE, - curp->file_status, file, 0, 0, NULL); + mandoc_msg(MANDOCERR_TOOLARGE, curp, 0, 0, NULL); return(0); } *with_mmap = 1; @@ -649,11 +645,8 @@ read_whole_file(struct mparse *curp, const char *file, for (;;) { if (off == fb->sz) { if (fb->sz == (1U << 31)) { - curp->file_status = MANDOCLEVEL_FATAL; - if (curp->mmsg) - (*curp->mmsg)(MANDOCERR_TOOLARGE, - curp->file_status, - file, 0, 0, NULL); + mandoc_msg(MANDOCERR_TOOLARGE, curp, + 0, 0, NULL); break; } resize_buf(fb, 65536); @@ -679,9 +672,6 @@ static void mparse_end(struct mparse *curp) { - if (MANDOCLEVEL_FATAL <= curp->file_status) - return; - if (curp->mdoc == NULL && curp->man == NULL && curp->sodest == NULL) { @@ -695,17 +685,10 @@ mparse_end(struct mparse *curp) curp->man = curp->pman; } } - - if (curp->mdoc && ! mdoc_endparse(curp->mdoc)) { - assert(MANDOCLEVEL_FATAL <= curp->file_status); - return; - } - - if (curp->man && ! man_endparse(curp->man)) { - assert(MANDOCLEVEL_FATAL <= curp->file_status); - return; - } - + if (curp->mdoc) + mdoc_endparse(curp->mdoc); + if (curp->man) + man_endparse(curp->man); roff_endparse(curp->roff); } @@ -742,7 +725,7 @@ mparse_parse_buffer(struct mparse *curp, struct buf bl mparse_buf_r(curp, blk, offset, 1); - if (0 == --recursion_depth && MANDOCLEVEL_FATAL > curp->file_status) + if (--recursion_depth == 0) mparse_end(curp); curp->primary = svprimary; @@ -889,8 +872,6 @@ mparse_alloc(int options, enum mandoclevel wlevel, man { struct mparse *curp; - assert(wlevel <= MANDOCLEVEL_FATAL); - curp = mandoc_calloc(1, sizeof(struct mparse)); curp->options = options; @@ -987,7 +968,7 @@ mandoc_msg(enum mandocerr er, struct mparse *m, { enum mandoclevel level; - level = MANDOCLEVEL_FATAL; + level = MANDOCLEVEL_UNSUPP; while (er < mandoclimits[level]) level--;