+ /* Execute the out device, if it exists. */
+
+ if (man && curp->outman)
+ (*curp->outman)(curp->outdata, man);
+ if (mdoc && curp->outmdoc)
+ (*curp->outmdoc)(curp->outdata, mdoc);
+
+ cleanup:
+ if (mdoc)
+ mdoc_reset(mdoc);
+ if (man)
+ man_reset(man);
+ if (roff)
+ roff_reset(roff);
+ if (ln.buf)
+ free(ln.buf);
+ if (with_mmap)
+ munmap(blk.buf, blk.sz);
+ else
+ free(blk.buf);
+
+ return;
+
+ bailout:
+ with_error = 1;
+ goto cleanup;
+}
+
+
+static int
+pset(const char *buf, int pos, struct curparse *curp,
+ struct man **man, struct mdoc **mdoc)
+{
+ int i;
+
+ /*
+ * Try to intuit which kind of manual parser should be used. If
+ * passed in by command-line (-man, -mdoc), then use that
+ * explicitly. If passed as -mandoc, then try to guess from the
+ * line: either skip dot-lines, use -mdoc when finding `.Dt', or
+ * default to -man, which is more lenient.
+ */
+
+ if (buf[0] == '.') {
+ for (i = 1; buf[i]; i++)
+ if (' ' != buf[i] && '\t' != buf[i])
+ break;
+ if (0 == buf[i])
+ return(1);
+ }
+
+ switch (curp->inttype) {
+ case (INTT_MDOC):
+ if (NULL == curp->mdoc)
+ curp->mdoc = mdoc_init(curp);
+ if (NULL == (*mdoc = curp->mdoc))
+ return(0);
+ return(1);
+ case (INTT_MAN):
+ if (NULL == curp->man)
+ curp->man = man_init(curp);
+ if (NULL == (*man = curp->man))
+ return(0);
+ return(1);
+ default:
+ break;
+ }
+
+ if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) {
+ if (NULL == curp->mdoc)
+ curp->mdoc = mdoc_init(curp);
+ if (NULL == (*mdoc = curp->mdoc))
+ return(0);
+ return(1);
+ }
+
+ if (NULL == curp->man)
+ curp->man = man_init(curp);
+ if (NULL == (*man = curp->man))
+ return(0);
+ return(1);