=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.224 retrieving revision 1.228 diff -u -p -r1.224 -r1.228 --- mandoc/roff.c 2014/08/01 17:27:44 1.224 +++ mandoc/roff.c 2014/09/06 23:24:32 1.228 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.224 2014/08/01 17:27:44 schwarze Exp $ */ +/* $Id: roff.c,v 1.228 2014/09/06 23:24:32 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -15,10 +15,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif +#include + #include #include #include @@ -27,8 +27,8 @@ #include "mandoc.h" #include "mandoc_aux.h" -#include "libroff.h" #include "libmandoc.h" +#include "libroff.h" /* Maximum number of nested if-else conditionals. */ #define RSTACK_MAX 128 @@ -122,6 +122,7 @@ struct roff { int options; /* parse options */ int rstacksz; /* current size limit of rstack */ int rstackpos; /* position in rstack */ + int format; /* current file in mdoc or man format */ char control; /* control character */ }; @@ -456,6 +457,7 @@ roff_reset(struct roff *r) { roff_free1(r); + r->format = r->options & (MPARSE_MDOC | MPARSE_MAN); r->control = 0; } @@ -475,6 +477,7 @@ roff_alloc(struct mparse *parse, int options) r = mandoc_calloc(1, sizeof(struct roff)); r->parse = parse; r->options = options; + r->format = options & (MPARSE_MDOC | MPARSE_MAN); r->rstackpos = -1; roffhash_init(); @@ -756,6 +759,15 @@ roff_parseln(struct roff *r, int ln, char **bufp, return(roff_parsetext(bufp, szp, pos, offs)); } + /* Skip empty request lines. */ + + if ((*bufp)[pos] == '"') { + mandoc_msg(MANDOCERR_COMMENT_BAD, r->parse, + ln, pos, NULL); + return(ROFF_IGN); + } else if ((*bufp)[pos] == '\0') + return(ROFF_IGN); + /* * If a scope is open, go to the child handler for that macro, * as it may want to preprocess before doing anything with it. @@ -1776,10 +1788,13 @@ roff_Dd(ROFF_ARGS) { const char *const *cp; - if (0 == ((MPARSE_MDOC | MPARSE_QUICK) & r->options)) + if ((r->options & (MPARSE_MDOC | MPARSE_QUICK)) == 0) for (cp = __mdoc_reserved; *cp; cp++) roff_setstr(r, *cp, NULL, 0); + if (r->format == 0) + r->format = MPARSE_MDOC; + return(ROFF_CONT); } @@ -1788,10 +1803,13 @@ roff_TH(ROFF_ARGS) { const char *const *cp; - if (0 == (MPARSE_QUICK & r->options)) + if ((r->options & MPARSE_QUICK) == 0) for (cp = __man_reserved; *cp; cp++) roff_setstr(r, *cp, NULL, 0); + if (r->format == 0) + r->format = MPARSE_MAN; + return(ROFF_CONT); } @@ -2305,6 +2323,13 @@ roff_strdup(const struct roff *r, const char *p) res[(int)ssz] = '\0'; return(res); +} + +int +roff_getformat(const struct roff *r) +{ + + return(r->format); } /*