+ /* NOTE a parser may not have been assigned, yet. */
+
+ if ( ! (man || mdoc)) {
+ warnx("%s: not a manual", curp->file);
+ return(0);
+ }
+
+ if (mdoc && ! mdoc_endparse(mdoc))
+ return(0);
+ if (man && ! man_endparse(man))
+ return(0);
+
+ /* If unset, allocate output dev now (if applicable). */
+
+ if ( ! (curp->outman && curp->outmdoc)) {
+ switch (curp->outtype) {
+ case (OUTT_TREE):
+ curp->outman = tree_man;
+ curp->outmdoc = tree_mdoc;
+ break;
+ case (OUTT_LINT):
+ break;
+ default:
+ curp->outdata = ascii_alloc();
+ curp->outman = terminal_man;
+ curp->outmdoc = terminal_mdoc;
+ curp->outfree = terminal_free;
+ break;
+ }
+ }
+
+ /* Execute the out device, if it exists. */
+
+ if (man && curp->outman)
+ if ( ! (*curp->outman)(curp->outdata, man))
+ return(0);
+ if (mdoc && curp->outmdoc)
+ if ( ! (*curp->outmdoc)(curp->outdata, mdoc))
+ return(0);
+
+ return(1);
+}
+
+
+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);
+ curp->lastmdoc = *mdoc;
+ return(1);
+ case (INTT_MAN):
+ if (NULL == curp->man)
+ curp->man = man_init(curp);
+ if (NULL == (*man = curp->man))
+ return(0);
+ curp->lastman = *man;
+ 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);
+ curp->lastmdoc = *mdoc;
+ return(1);
+ }
+
+ if (NULL == curp->man)
+ curp->man = man_init(curp);
+ if (NULL == (*man = curp->man))
+ return(0);
+ curp->lastman = *man;
+ return(1);
+}
+
+
+static int
+moptions(enum intt *tflags, char *arg)
+{
+
+ if (0 == strcmp(arg, "doc"))
+ *tflags = INTT_MDOC;
+ else if (0 == strcmp(arg, "andoc"))
+ *tflags = INTT_AUTO;
+ else if (0 == strcmp(arg, "an"))
+ *tflags = INTT_MAN;
+ else {
+ warnx("bad argument: -m%s", arg);
+ return(0);
+ }
+
+ return(1);