=================================================================== RCS file: /cvs/mandoc/read.c,v retrieving revision 1.107 retrieving revision 1.110 diff -u -p -r1.107 -r1.110 --- mandoc/read.c 2015/01/14 17:49:15 1.107 +++ mandoc/read.c 2015/01/15 02:29:26 1.110 @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.107 2015/01/14 17:49:15 schwarze Exp $ */ +/* $Id: read.c,v 1.110 2015/01/15 02:29:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -191,6 +191,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "ignoring macro in table", /* related to document structure and macros */ + NULL, "input stack limit exceeded, infinite loop?", "skipping bad character", "skipping unknown macro", @@ -209,6 +210,8 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "uname(3) system call failed, using UNKNOWN", "unknown standard specifier", "skipping request without numeric argument", + "NOT IMPLEMENTED: .so with absolute path or \"..\"", + ".so request failed", "skipping all arguments", "skipping excess arguments", "divide by zero", @@ -216,13 +219,6 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "generic fatal error", "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] = { @@ -310,10 +306,13 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size { const struct tbl_span *span; struct buf ln; + char *cp; size_t pos; /* byte number in the ln buffer */ enum rofferr rr; int of; int lnn; /* line number in the real file */ + int fd; + pid_t save_child; unsigned char c; memset(&ln, 0, sizeof(ln)); @@ -508,9 +507,6 @@ rerun: case ROFF_IGN: pos = 0; continue; - case ROFF_ERR: - assert(MANDOCLEVEL_FATAL <= curp->file_status); - break; case ROFF_SO: if ( ! (curp->options & MPARSE_SO) && (i >= blk.sz || blk.buf[i] == '\0')) { @@ -525,13 +521,23 @@ rerun: */ if (curp->secondary) curp->secondary->sz -= pos + 1; - mparse_readfd(curp, -1, ln.buf + of); - if (MANDOCLEVEL_FATAL <= curp->file_status) { + save_child = curp->child; + if (mparse_open(curp, &fd, ln.buf + of) == + MANDOCLEVEL_OK) + mparse_readfd(curp, fd, ln.buf + of); + else { mandoc_vmsg(MANDOCERR_SO_FAIL, curp, curp->line, pos, ".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; continue; default: @@ -757,8 +763,6 @@ 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. * Called recursively when an .so request is encountered. */ @@ -768,14 +772,7 @@ mparse_readfd(struct mparse *curp, int fd, const char struct buf blk; int with_mmap; 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)) { save_filenc = curp->filenc; curp->filenc = curp->options & @@ -794,8 +791,6 @@ mparse_readfd(struct mparse *curp, int fd, const char perror(file); mparse_wait(curp); -out: - curp->child = save_child; return(curp->file_status); } @@ -805,9 +800,7 @@ mparse_open(struct mparse *curp, int *fd, const char * int pfd[2]; int save_errno; char *cp; - enum mandocerr err; - pfd[1] = -1; curp->file = file; /* Unless zipped, try to just open the file. */ @@ -831,8 +824,11 @@ mparse_open(struct mparse *curp, int *fd, const char * if (access(file, R_OK) == -1) { if (cp != NULL) errno = save_errno; - err = MANDOCERR_SYSOPEN; - goto out; + free(cp); + *fd = -1; + curp->child = 0; + mandoc_msg(MANDOCERR_FILE, curp, 0, 0, strerror(errno)); + return(MANDOCLEVEL_ERROR); } /* Run gunzip(1). */ @@ -860,18 +856,6 @@ mparse_open(struct mparse *curp, int *fd, const char * *fd = pfd[0]; 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 @@ -887,16 +871,14 @@ mparse_wait(struct mparse *curp) exit((int)MANDOCLEVEL_SYSERR); } if (WIFSIGNALED(status)) { - mandoc_vmsg(MANDOCERR_SYSSIG, curp, 0, 0, - "%d", WTERMSIG(status)); - curp->file_status = MANDOCLEVEL_SYSERR; - return(curp->file_status); + mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, + "gunzip died from signal %d", WTERMSIG(status)); + return(MANDOCLEVEL_ERROR); } if (WEXITSTATUS(status)) { - mandoc_vmsg(MANDOCERR_SYSEXIT, curp, 0, 0, - "%d", WEXITSTATUS(status)); - curp->file_status = MANDOCLEVEL_SYSERR; - return(curp->file_status); + mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, + "gunzip failed with code %d", WEXITSTATUS(status)); + return(MANDOCLEVEL_ERROR); } return(MANDOCLEVEL_OK); } @@ -1009,7 +991,7 @@ mandoc_msg(enum mandocerr er, struct mparse *m, while (er < mandoclimits[level]) level--; - if (level < m->wlevel) + if (level < m->wlevel && er != MANDOCERR_FILE) return; if (m->mmsg)