diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-10-06 22:29:12 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-10-06 22:29:12 +0000 |
commit | 2835b2c808e87f26f06bd8ec3a2c581923777902 (patch) | |
tree | 4ecad31be3626da3f4f731014abab81403337a9a /read.c | |
parent | 6f9df825574a6b5616f7b42b6687a5b608cc8717 (diff) | |
download | mandoc-2835b2c808e87f26f06bd8ec3a2c581923777902.tar.gz |
If -Tman is specified and input is -man, echo the preprocessed (`so'
replaced by file) input. This replaces earlier behaviour of doing
nothing, which I found unexpected (mandoc should always output).
This requires a buffer in read.c that saves the input lines before being
parsed, with a special hook if `so' is invoked. This buffer is just
flushed to output if -mman is the input.
While mucking around doing this, I also alpha-ordered the mandoc.h
functions.
Ok schwarze@, with no screaming when the polished patch was published.
Diffstat (limited to 'read.c')
-rw-r--r-- | read.c | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -63,6 +63,7 @@ struct mparse { mandocmsg mmsg; /* warning/error message handler */ void *arg; /* argument to mmsg */ const char *file; + struct buf *secondary; }; static void resize_buf(struct buf *, size_t); @@ -411,6 +412,27 @@ mparse_buf_r(struct mparse *curp, struct buf blk, int start) of = 0; + /* + * Maintain a lookaside buffer of all parsed lines. We + * only do this if mparse_keep() has been invoked (the + * buffer may be accessed with mparse_getkeep()). + */ + + 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'; + curp->secondary->sz++; + curp->secondary->buf + [curp->secondary->sz] = '\0'; + } rerun: rr = roff_parseln (curp->roff, curp->line, @@ -437,6 +459,12 @@ rerun: assert(MANDOCLEVEL_FATAL <= curp->file_status); break; case (ROFF_SO): + /* + * We remove `so' clauses from our lookaside + * buffer because we're going to descend into + * the file recursively. + */ + curp->secondary->sz -= pos + 1; mparse_readfd_r(curp, -1, ln.buf + of, 1); if (MANDOCLEVEL_FATAL <= curp->file_status) break; @@ -704,6 +732,8 @@ mparse_reset(struct mparse *curp) mdoc_reset(curp->mdoc); if (curp->man) man_reset(curp->man); + if (curp->secondary) + curp->secondary->sz = 0; curp->file_status = MANDOCLEVEL_OK; curp->mdoc = NULL; @@ -720,7 +750,10 @@ mparse_free(struct mparse *curp) man_free(curp->pman); if (curp->roff) roff_free(curp->roff); + if (curp->secondary) + free(curp->secondary->buf); + free(curp->secondary); free(curp); } @@ -780,3 +813,19 @@ mparse_strlevel(enum mandoclevel lvl) { return(mandoclevels[lvl]); } + +void +mparse_keep(struct mparse *p) +{ + + assert(NULL == p->secondary); + p->secondary = mandoc_calloc(1, sizeof(struct buf)); +} + +const char * +mparse_getkeep(const struct mparse *p) +{ + + assert(p->secondary); + return(p->secondary->sz ? p->secondary->buf : NULL); +} |