summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-05-16 10:59:36 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-05-16 10:59:36 +0000
commit110e3743cb6c70af4d1a25c2527e9d923e1f163b (patch)
treeaad4e38ad6261d3903a43823cbfc9c9ee51dc014 /main.c
parent110ec8e74f50c3c583a7b5930b26eede65e6f8e7 (diff)
downloadmandoc-110e3743cb6c70af4d1a25c2527e9d923e1f163b.tar.gz
Allow roff_parseln() to be re-run.
Allow roff_parseln() to manipulate the line buffer offset. This is used in situations like `.ie n .TH FOO 1' or `.ie n .ie n', where the line buffer offset is recalculated then the roff parser re-run. Fix mdoc_parseln() and man_parseln() to accept the initial line offset. WARNING: backed-out ALL roff macros whilst accomodating for how roff handles multi-line conditionals (in short, re-running the parser).
Diffstat (limited to 'main.c')
-rw-r--r--main.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/main.c b/main.c
index d7bac760..65fde5c3 100644
--- a/main.c
+++ b/main.c
@@ -386,7 +386,7 @@ static void
fdesc(struct curparse *curp)
{
struct buf ln, blk;
- int i, pos, lnn, lnn_start, with_mmap;
+ int i, pos, lnn, lnn_start, with_mmap, of;
enum rofferr re;
struct man *man;
struct mdoc *mdoc;
@@ -467,22 +467,42 @@ fdesc(struct curparse *curp)
goto bailout;
ln.buf[pos] = '\0';
- re = roff_parseln(roff, lnn_start, &ln.buf, &ln.sz);
+ /*
+ * A significant amount of complexity is contained by
+ * the roff preprocessor. It's line-oriented but can be
+ * expressed on one line, so we need at times to
+ * readjust our starting point and re-run it. The roff
+ * preprocessor can also readjust the buffers with new
+ * data, so we pass them in wholesale.
+ */
+
+ of = 0;
+ do {
+ re = roff_parseln(roff, lnn_start,
+ &ln.buf, &ln.sz, of, &of);
+ } while (ROFF_RERUN == re);
+
if (ROFF_IGN == re)
continue;
else if (ROFF_ERR == re)
goto bailout;
- /* If unset, assign parser in pset(). */
+ /*
+ * If input parsers have not been allocated, do so now.
+ * We keep these instanced betwen parsers, but set them
+ * locally per parse routine since we can use different
+ * parsers with each one.
+ */
- if ( ! (man || mdoc) && ! pset(ln.buf, pos, curp, &man, &mdoc))
- goto bailout;
+ if ( ! (man || mdoc))
+ if ( ! pset(ln.buf + of, pos - of, curp, &man, &mdoc))
+ goto bailout;
- /* Pass down into parsers. */
+ /* Lastly, push down into the parsers themselves. */
- if (man && ! man_parseln(man, lnn_start, ln.buf))
+ if (man && ! man_parseln(man, lnn_start, ln.buf, of))
goto bailout;
- if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf))
+ if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf, of))
goto bailout;
}
@@ -493,6 +513,8 @@ fdesc(struct curparse *curp)
goto bailout;
}
+ /* Clean up the parse routine ASTs. */
+
if (mdoc && ! mdoc_endparse(mdoc))
goto bailout;
if (man && ! man_endparse(man))