=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/read.c,v retrieving revision 1.24 retrieving revision 1.25 diff -c -r1.24 -r1.25 *** src/usr.bin/mandoc/read.c 2014/03/21 22:17:01 1.24 --- src/usr.bin/mandoc/read.c 2014/04/20 16:44:44 1.25 *************** *** 1,4 **** ! /* $Id: read.c,v 1.24 2014/03/21 22:17:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze --- 1,4 ---- ! /* $Id: read.c,v 1.25 2014/04/20 16:44:44 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze *************** *** 38,44 **** #define REPARSE_LIMIT 1000 struct buf { ! char *buf; /* binary input buffer */ size_t sz; /* size of binary buffer */ }; --- 38,44 ---- #define REPARSE_LIMIT 1000 struct buf { ! char *buf; /* binary input buffer */ size_t sz; /* size of binary buffer */ }; *************** *** 55,61 **** char *sodest; /* filename pointed to by .so */ int reparse_count; /* finite interp. stack */ mandocmsg mmsg; /* warning/error message handler */ ! const char *file; struct buf *secondary; char *defos; /* default operating system */ }; --- 55,61 ---- char *sodest; /* filename pointed to by .so */ int reparse_count; /* finite interp. stack */ mandocmsg mmsg; /* warning/error message handler */ ! const char *file; struct buf *secondary; char *defos; /* default operating system */ }; *************** *** 145,151 **** /* related to equations */ "unexpected literal in equation", ! "generic error", /* related to equations */ --- 145,151 ---- /* related to equations */ "unexpected literal in equation", ! "generic error", /* related to equations */ *************** *** 216,221 **** --- 216,222 ---- "SYSERR" }; + static void resize_buf(struct buf *buf, size_t initial) { *************** *** 249,255 **** } if (MPARSE_MDOC & curp->options) { ! if (NULL == curp->pmdoc) curp->pmdoc = mdoc_alloc( curp->roff, curp, curp->defos, MPARSE_QUICK & curp->options ? 1 : 0); --- 250,256 ---- } if (MPARSE_MDOC & curp->options) { ! if (NULL == curp->pmdoc) curp->pmdoc = mdoc_alloc( curp->roff, curp, curp->defos, MPARSE_QUICK & curp->options ? 1 : 0); *************** *** 257,263 **** curp->mdoc = curp->pmdoc; return; } else if (MPARSE_MAN & curp->options) { ! if (NULL == curp->pman) curp->pman = man_alloc(curp->roff, curp, MPARSE_QUICK & curp->options ? 1 : 0); assert(curp->pman); --- 258,264 ---- curp->mdoc = curp->pmdoc; return; } else if (MPARSE_MAN & curp->options) { ! if (NULL == curp->pman) curp->pman = man_alloc(curp->roff, curp, MPARSE_QUICK & curp->options ? 1 : 0); assert(curp->pman); *************** *** 266,281 **** } if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) { ! if (NULL == curp->pmdoc) curp->pmdoc = mdoc_alloc( curp->roff, curp, curp->defos, MPARSE_QUICK & curp->options ? 1 : 0); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; ! } ! if (NULL == curp->pman) curp->pman = man_alloc(curp->roff, curp, MPARSE_QUICK & curp->options ? 1 : 0); assert(curp->pman); --- 267,282 ---- } if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) { ! if (NULL == curp->pmdoc) curp->pmdoc = mdoc_alloc( curp->roff, curp, curp->defos, MPARSE_QUICK & curp->options ? 1 : 0); assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; ! } ! if (NULL == curp->pman) curp->pman = man_alloc(curp->roff, curp, MPARSE_QUICK & curp->options ? 1 : 0); assert(curp->pman); *************** *** 300,307 **** memset(&ln, 0, sizeof(struct buf)); ! lnn = curp->line; ! pos = 0; for (i = 0; i < (int)blk.sz; ) { if (0 == pos && '\0' == blk.buf[i]) --- 301,308 ---- memset(&ln, 0, sizeof(struct buf)); ! lnn = curp->line; ! pos = 0; for (i = 0; i < (int)blk.sz; ) { if (0 == pos && '\0' == blk.buf[i]) *************** *** 338,344 **** 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 * readers. Since I'd rather this not happen, --- 339,345 ---- 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 * readers. Since I'd rather this not happen, *************** *** 349,358 **** c = (unsigned char) blk.buf[i]; ! if ( ! (isascii(c) && ! (isgraph(c) || isblank(c)))) { mandoc_msg(MANDOCERR_BADCHAR, curp, ! curp->line, pos, NULL); i++; ln.buf[pos++] = '?'; continue; --- 350,359 ---- c = (unsigned char) blk.buf[i]; ! if ( ! (isascii(c) && ! (isgraph(c) || isblank(c)))) { mandoc_msg(MANDOCERR_BADCHAR, curp, ! curp->line, pos, NULL); i++; ln.buf[pos++] = '?'; continue; *************** *** 406,415 **** 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; --- 407,416 ---- 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; *************** *** 421,427 **** ln.buf[pos++] = blk.buf[i++]; } ! if (pos >= (int)ln.sz) resize_buf(&ln, 256); ln.buf[pos] = '\0'; --- 422,428 ---- ln.buf[pos++] = blk.buf[i++]; } ! if (pos >= (int)ln.sz) resize_buf(&ln, 256); ln.buf[pos] = '\0'; *************** *** 444,456 **** */ if (curp->secondary) { ! curp->secondary->buf = ! mandoc_realloc ! (curp->secondary->buf, ! curp->secondary->sz + pos + 2); ! memcpy(curp->secondary->buf + ! curp->secondary->sz, ! ln.buf, pos); curp->secondary->sz += pos; curp->secondary->buf [curp->secondary->sz] = '\n'; --- 445,456 ---- */ if (curp->secondary) { ! curp->secondary->buf = mandoc_realloc( ! curp->secondary->buf, ! curp->secondary->sz + pos + 2); ! memcpy(curp->secondary->buf + ! curp->secondary->sz, ! ln.buf, pos); curp->secondary->sz += pos; curp->secondary->buf [curp->secondary->sz] = '\n'; *************** *** 459,489 **** [curp->secondary->sz] = '\0'; } rerun: ! rr = roff_parseln ! (curp->roff, curp->line, ! &ln.buf, &ln.sz, of, &of); switch (rr) { ! case (ROFF_REPARSE): if (REPARSE_LIMIT >= ++curp->reparse_count) mparse_buf_r(curp, ln, 0); else mandoc_msg(MANDOCERR_ROFFLOOP, curp, ! curp->line, pos, NULL); pos = 0; continue; ! case (ROFF_APPEND): pos = (int)strlen(ln.buf); continue; ! case (ROFF_RERUN): goto rerun; ! case (ROFF_IGN): pos = 0; continue; ! case (ROFF_ERR): assert(MANDOCLEVEL_FATAL <= curp->file_status); break; ! case (ROFF_SO): if (0 == (MPARSE_SO & curp->options) && (i >= (int)blk.sz || '\0' == blk.buf[i])) { curp->sodest = mandoc_strdup(ln.buf + of); --- 459,488 ---- [curp->secondary->sz] = '\0'; } rerun: ! rr = roff_parseln(curp->roff, curp->line, ! &ln.buf, &ln.sz, of, &of); switch (rr) { ! case ROFF_REPARSE: if (REPARSE_LIMIT >= ++curp->reparse_count) mparse_buf_r(curp, ln, 0); else mandoc_msg(MANDOCERR_ROFFLOOP, curp, ! curp->line, pos, NULL); pos = 0; continue; ! case ROFF_APPEND: pos = (int)strlen(ln.buf); continue; ! case ROFF_RERUN: goto rerun; ! case ROFF_IGN: pos = 0; continue; ! case ROFF_ERR: assert(MANDOCLEVEL_FATAL <= curp->file_status); break; ! case ROFF_SO: if (0 == (MPARSE_SO & curp->options) && (i >= (int)blk.sz || '\0' == blk.buf[i])) { curp->sodest = mandoc_strdup(ln.buf + of); *************** *** 495,501 **** * buffer because we're going to descend into * the file recursively. */ ! if (curp->secondary) curp->secondary->sz -= pos + 1; mparse_readfd(curp, -1, ln.buf + of); if (MANDOCLEVEL_FATAL <= curp->file_status) --- 494,500 ---- * buffer because we're going to descend into * the file recursively. */ ! if (curp->secondary) curp->secondary->sz -= pos + 1; mparse_readfd(curp, -1, ln.buf + of); if (MANDOCLEVEL_FATAL <= curp->file_status) *************** *** 524,530 **** if ( ! (curp->man || curp->mdoc)) pset(ln.buf + of, pos - of, curp); ! /* * Lastly, push down into the parsers themselves. One * of these will have already been set in the pset() * routine. --- 523,529 ---- if ( ! (curp->man || curp->mdoc)) pset(ln.buf + of, pos - of, curp); ! /* * Lastly, push down into the parsers themselves. One * of these will have already been set in the pset() * routine. *************** *** 540,562 **** 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); --- 539,561 ---- 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); *************** *** 835,841 **** } void ! mandoc_msg(enum mandocerr er, struct mparse *m, int ln, int col, const char *msg) { enum mandoclevel level; --- 834,840 ---- } void ! mandoc_msg(enum mandocerr er, struct mparse *m, int ln, int col, const char *msg) { enum mandoclevel level;