=================================================================== RCS file: /cvs/mandoc/read.c,v retrieving revision 1.99 retrieving revision 1.107 diff -u -p -r1.99 -r1.107 --- mandoc/read.c 2014/11/27 23:40:19 1.99 +++ mandoc/read.c 2015/01/14 17:49:15 1.107 @@ -1,7 +1,7 @@ -/* $Id: read.c,v 1.99 2014/11/27 23:40:19 schwarze Exp $ */ +/* $Id: read.c,v 1.107 2015/01/14 17:49:15 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010-2014 Ingo Schwarze + * Copyright (c) 2010-2015 Ingo Schwarze * Copyright (c) 2010, 2012 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any @@ -41,7 +41,6 @@ #include "libmandoc.h" #include "mdoc.h" #include "man.h" -#include "main.h" #define REPARSE_LIMIT 1000 @@ -97,7 +96,6 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "lower case character in document title", "missing manual section, using \"\"", "unknown manual section", - "unknown manual volume or arch", "missing date, using today's date", "cannot parse date, using it verbatim", "missing Os macro, using \"\"", @@ -121,6 +119,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = /* related to macros and nesting */ "obsolete macro", + "macro neither callable nor escaped", "skipping paragraph macro", "moving paragraph macro out of list", "skipping no-space macro", @@ -146,6 +145,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "empty list item", "missing font type, using \\fR", "unknown font type, using \\fR", + "nothing follows prefix", "missing -std argument, adding it", "missing eqn box, using \"\"", @@ -188,6 +188,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "ignore data in cell", "data block still open", "ignoring extra data cells", + "ignoring macro in table", /* related to document structure and macros */ "input stack limit exceeded, infinite loop?", @@ -219,16 +220,9 @@ static const char * const mandocerrs[MANDOCERR_MAX] = ".so request failed", /* system errors */ - "cannot dup file descriptor", - "cannot exec", "gunzip failed with code", - "cannot fork", NULL, - "cannot open pipe", - "cannot read file", "gunzip died from signal", - "cannot stat file", - "wait failed", }; static const char * const mandoclevels[MANDOCLEVEL_MAX] = { @@ -297,7 +291,8 @@ choose_parser(struct mparse *curp) /* Fall back to man(7) as a last resort. */ if (NULL == curp->pman) - curp->pman = man_alloc(curp->roff, curp, + curp->pman = man_alloc( + curp->roff, curp, curp->defos, MPARSE_QUICK & curp->options ? 1 : 0); assert(curp->pman); curp->man = curp->pman; @@ -317,7 +312,7 @@ mparse_buf_r(struct mparse *curp, struct buf blk, size struct buf ln; size_t pos; /* byte number in the ln buffer */ enum rofferr rr; - int of, rc; + int of; int lnn; /* line number in the real file */ unsigned char c; @@ -570,35 +565,22 @@ rerun: * Do the same for ROFF_EQN. */ - rc = -1; + if (rr == ROFF_TBL) { + while ((span = roff_span(curp->roff)) != NULL) + if (curp->man == NULL) + mdoc_addspan(curp->mdoc, span); + else + man_addspan(curp->man, span); + } else if (rr == ROFF_EQN) { + if (curp->man == NULL) + mdoc_addeqn(curp->mdoc, roff_eqn(curp->roff)); + else + man_addeqn(curp->man, roff_eqn(curp->roff)); + } else if ((curp->man == NULL ? + mdoc_parseln(curp->mdoc, curp->line, ln.buf, of) : + man_parseln(curp->man, curp->line, ln.buf, of)) == 2) + break; - if (ROFF_TBL == rr) - while (NULL != (span = roff_span(curp->roff))) { - rc = curp->man ? - man_addspan(curp->man, span) : - mdoc_addspan(curp->mdoc, span); - if (0 == rc) - break; - } - else if (ROFF_EQN == rr) - rc = curp->mdoc ? - mdoc_addeqn(curp->mdoc, - roff_eqn(curp->roff)) : - man_addeqn(curp->man, - roff_eqn(curp->roff)); - else if (curp->man || curp->mdoc) - rc = curp->man ? - man_parseln(curp->man, - curp->line, ln.buf, of) : - mdoc_parseln(curp->mdoc, - curp->line, ln.buf, of); - - if (0 == rc) { - assert(MANDOCLEVEL_FATAL <= curp->file_status); - break; - } else if (2 == rc) - break; - /* Temporary buffers typically are not full. */ if (0 == start && '\0' == blk.buf[i]) @@ -622,11 +604,8 @@ read_whole_file(struct mparse *curp, const char *file, #if HAVE_MMAP struct stat st; if (-1 == fstat(fd, &st)) { - curp->file_status = MANDOCLEVEL_SYSERR; - if (curp->mmsg) - (*curp->mmsg)(MANDOCERR_SYSSTAT, curp->file_status, - file, 0, 0, strerror(errno)); - return(0); + perror(file); + exit((int)MANDOCLEVEL_SYSERR); } /* @@ -679,12 +658,8 @@ read_whole_file(struct mparse *curp, const char *file, return(1); } if (ssz == -1) { - curp->file_status = MANDOCLEVEL_SYSERR; - if (curp->mmsg) - (*curp->mmsg)(MANDOCERR_SYSREAD, - curp->file_status, file, 0, 0, - strerror(errno)); - break; + perror(file); + exit((int)MANDOCLEVEL_SYSERR); } off += (size_t)ssz; } @@ -708,7 +683,8 @@ mparse_end(struct mparse *curp) curp->mdoc = curp->pmdoc; else { if (curp->pman == NULL) - curp->pman = man_alloc(curp->roff, curp, + curp->pman = man_alloc( + curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); curp->man = curp->pman; } @@ -768,12 +744,12 @@ mparse_parse_buffer(struct mparse *curp, struct buf bl } enum mandoclevel -mparse_readmem(struct mparse *curp, const void *buf, size_t len, +mparse_readmem(struct mparse *curp, void *buf, size_t len, const char *file) { struct buf blk; - blk.buf = UNCONST(buf); + blk.buf = buf; blk.sz = len; mparse_parse_buffer(curp, blk, file); @@ -862,26 +838,23 @@ mparse_open(struct mparse *curp, int *fd, const char * /* Run gunzip(1). */ if (pipe(pfd) == -1) { - err = MANDOCERR_SYSPIPE; - goto out; + perror("pipe"); + exit((int)MANDOCLEVEL_SYSERR); } switch (curp->child = fork()) { case -1: - err = MANDOCERR_SYSFORK; - close(pfd[0]); - close(pfd[1]); - pfd[1] = -1; - break; + perror("fork"); + exit((int)MANDOCLEVEL_SYSERR); case 0: close(pfd[0]); if (dup2(pfd[1], STDOUT_FILENO) == -1) { - err = MANDOCERR_SYSDUP; - break; + perror("dup"); + exit((int)MANDOCLEVEL_SYSERR); } execlp("gunzip", "gunzip", "-c", file, NULL); - err = MANDOCERR_SYSEXEC; - break; + perror("exec"); + exit((int)MANDOCLEVEL_SYSERR); default: close(pfd[1]); *fd = pfd[0]; @@ -910,10 +883,8 @@ mparse_wait(struct mparse *curp) return(MANDOCLEVEL_OK); if (waitpid(curp->child, &status, 0) == -1) { - mandoc_msg(MANDOCERR_SYSWAIT, curp, 0, 0, - strerror(errno)); - curp->file_status = MANDOCLEVEL_SYSERR; - return(curp->file_status); + perror("wait"); + exit((int)MANDOCLEVEL_SYSERR); } if (WIFSIGNALED(status)) { mandoc_vmsg(MANDOCERR_SYSSIG, curp, 0, 0, @@ -952,7 +923,8 @@ mparse_alloc(int options, enum mandoclevel wlevel, man curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); if (curp->options & MPARSE_MAN) - curp->pman = man_alloc(curp->roff, curp, + curp->pman = man_alloc( + curp->roff, curp, curp->defos, curp->options & MPARSE_QUICK ? 1 : 0); return(curp);