=================================================================== RCS file: /cvs/mandoc/read.c,v retrieving revision 1.28 retrieving revision 1.35 diff -u -p -r1.28 -r1.35 --- mandoc/read.c 2012/02/16 20:51:31 1.28 +++ mandoc/read.c 2013/05/30 03:52:59 1.35 @@ -1,7 +1,7 @@ -/* $Id: read.c,v 1.28 2012/02/16 20:51:31 joerg Exp $ */ +/* $Id: read.c,v 1.35 2013/05/30 03:52:59 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2011 Ingo Schwarze + * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -66,6 +66,7 @@ struct mparse { void *arg; /* argument to mmsg */ const char *file; struct buf *secondary; + char *defos; /* default operating system */ }; static void resize_buf(struct buf *, size_t); @@ -94,6 +95,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "no title in document", "document title should be all caps", "unknown manual section", + "unknown manual volume or arch", "date missing, using today's date", "cannot parse date, using it verbatim", "prologue macros out of order", @@ -105,7 +107,6 @@ static const char * const mandocerrs[MANDOCERR_MAX] = ".so is fragile, better use ln(1)", "NAME section must come first", "bad NAME section contents", - "manual name not yet set", "sections out of conventional order", "duplicate section name", "section not in conventional manual section", @@ -113,6 +114,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = /* related to macros and nesting */ "skipping obsolete macro", "skipping paragraph macro", + "moving paragraph macro out of list", "skipping no-space macro", "blocks badly nested", "child violates parent syntax", @@ -173,10 +175,12 @@ static const char * const mandocerrs[MANDOCERR_MAX] = "input stack limit exceeded, infinite loop?", "skipping bad character", "escaped character not allowed in a name", + "manual name not yet set", "skipping text before the first section header", "skipping unknown macro", "NOT IMPLEMENTED, please use groff: skipping request", "argument count wrong", + "skipping column outside column list", "skipping end of block that is not open", "missing end of block", "scope open on exit", @@ -247,7 +251,8 @@ pset(const char *buf, int pos, struct mparse *curp) switch (curp->inttype) { case (MPARSE_MDOC): if (NULL == curp->pmdoc) - curp->pmdoc = mdoc_alloc(curp->roff, curp); + curp->pmdoc = mdoc_alloc(curp->roff, curp, + curp->defos); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; @@ -263,7 +268,8 @@ pset(const char *buf, int pos, struct mparse *curp) if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) { if (NULL == curp->pmdoc) - curp->pmdoc = mdoc_alloc(curp->roff, curp); + curp->pmdoc = mdoc_alloc(curp->roff, curp, + curp->defos); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; @@ -322,6 +328,15 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int break; } + /* + * Make sure we have space for at least + * one backslash and one other character + * and the trailing NUL byte. + */ + + if (pos + 2 >= (int)ln.sz) + resize_buf(&ln, 256); + /* * Warn about bogus characters. If you're using * non-ASCII encoding, you're screwing your @@ -338,8 +353,6 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int mandoc_msg(MANDOCERR_BADCHAR, curp, curp->line, pos, NULL); i++; - if (pos >= (int)ln.sz) - resize_buf(&ln, 256); ln.buf[pos++] = '?'; continue; } @@ -347,8 +360,6 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int /* Trailing backslash = a plain char. */ if ('\\' != blk.buf[i] || i + 1 == (int)blk.sz) { - if (pos >= (int)ln.sz) - resize_buf(&ln, 256); ln.buf[pos++] = blk.buf[i++]; continue; } @@ -390,11 +401,21 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int break; } - /* Some other escape sequence, copy & cont. */ + /* Catch escaped bogus characters. */ - if (pos + 1 >= (int)ln.sz) - resize_buf(&ln, 256); + c = (unsigned char) blk.buf[i+1]; + if ( ! (isascii(c) && + (isgraph(c) || isblank(c)))) { + mandoc_msg(MANDOCERR_BADCHAR, curp, + curp->line, pos, NULL); + i += 2; + ln.buf[pos++] = '?'; + continue; + } + + /* Some other escape sequence, copy & cont. */ + ln.buf[pos++] = blk.buf[i++]; ln.buf[pos++] = blk.buf[i++]; } @@ -720,7 +741,8 @@ mparse_readfd(struct mparse *curp, int fd, const char } struct mparse * -mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, mandocmsg mmsg, void *arg) +mparse_alloc(enum mparset inttype, enum mandoclevel wlevel, + mandocmsg mmsg, void *arg, char *defos) { struct mparse *curp; @@ -732,8 +754,9 @@ mparse_alloc(enum mparset inttype, enum mandoclevel wl curp->mmsg = mmsg; curp->arg = arg; curp->inttype = inttype; + curp->defos = defos; - curp->roff = roff_alloc(curp); + curp->roff = roff_alloc(inttype, curp); return(curp); }