summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-26 22:13:59 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2010-10-26 22:13:59 +0000
commitfc9cda06c721bcd7f705d4d834df218f2df42688 (patch)
tree3a1bcd21c204519f3f974862473e5f8c82978ba2
parentf3e98b5d75919954908260771ba2a987309c7fa0 (diff)
Refactoring, no functional change:
Seperate the code to read and parse a PART of a page (new function pdesc()) from the code to finish and output a FULL page (function fdesc()); in preparation for .so support.
-rw-r--r--usr.bin/mandoc/main.c233
1 files changed, 125 insertions, 108 deletions
diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
index 55cccbd03bf..9878f75f7f9 100644
--- a/usr.bin/mandoc/main.c
+++ b/usr.bin/mandoc/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.50 2010/10/24 18:15:43 schwarze Exp $ */
+/* $Id: main.c,v 1.51 2010/10/26 22:13:58 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
@@ -178,6 +178,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"static buffer exhausted",
};
+static void pdesc(struct curparse *);
static void fdesc(struct curparse *);
static void ffile(const char *, struct curparse *);
static int moptions(enum intt *, char *);
@@ -391,6 +392,124 @@ read_whole_file(struct curparse *curp, struct buf *fb, int *with_mmap)
static void
fdesc(struct curparse *curp)
{
+ struct man *man;
+ struct mdoc *mdoc;
+ struct roff *roff;
+
+ pdesc(curp);
+
+ man = curp->man;
+ mdoc = curp->mdoc;
+ roff = curp->roff;
+
+ if (MANDOCLEVEL_FATAL <= exit_status)
+ goto cleanup;
+
+ /* NOTE a parser may not have been assigned, yet. */
+
+ if ( ! (man || mdoc)) {
+ fprintf(stderr, "%s: Not a manual\n", curp->file);
+ exit_status = MANDOCLEVEL_FATAL;
+ goto cleanup;
+ }
+
+ /* Clean up the parse routine ASTs. */
+
+ if (mdoc && ! mdoc_endparse(mdoc)) {
+ assert(MANDOCLEVEL_FATAL <= exit_status);
+ goto cleanup;
+ }
+ if (man && ! man_endparse(man)) {
+ assert(MANDOCLEVEL_FATAL <= exit_status);
+ goto cleanup;
+ }
+ if (roff && ! roff_endparse(roff)) {
+ assert(MANDOCLEVEL_FATAL <= exit_status);
+ goto cleanup;
+ }
+
+ /*
+ * With -Wstop and warnings or errors of at least
+ * the requested level, do not produce output.
+ */
+
+ if (MANDOCLEVEL_OK != exit_status && curp->wstop)
+ goto cleanup;
+
+ /* If unset, allocate output dev now (if applicable). */
+
+ if ( ! (curp->outman && curp->outmdoc)) {
+ switch (curp->outtype) {
+ case (OUTT_XHTML):
+ curp->outdata = xhtml_alloc(curp->outopts);
+ break;
+ case (OUTT_HTML):
+ curp->outdata = html_alloc(curp->outopts);
+ break;
+ case (OUTT_ASCII):
+ curp->outdata = ascii_alloc(curp->outopts);
+ curp->outfree = ascii_free;
+ break;
+ case (OUTT_PDF):
+ curp->outdata = pdf_alloc(curp->outopts);
+ curp->outfree = pspdf_free;
+ break;
+ case (OUTT_PS):
+ curp->outdata = ps_alloc(curp->outopts);
+ curp->outfree = pspdf_free;
+ break;
+ default:
+ break;
+ }
+
+ switch (curp->outtype) {
+ case (OUTT_HTML):
+ /* FALLTHROUGH */
+ case (OUTT_XHTML):
+ curp->outman = html_man;
+ curp->outmdoc = html_mdoc;
+ curp->outfree = html_free;
+ break;
+ case (OUTT_TREE):
+ curp->outman = tree_man;
+ curp->outmdoc = tree_mdoc;
+ break;
+ case (OUTT_PDF):
+ /* FALLTHROUGH */
+ case (OUTT_ASCII):
+ /* FALLTHROUGH */
+ case (OUTT_PS):
+ curp->outman = terminal_man;
+ curp->outmdoc = terminal_mdoc;
+ break;
+ default:
+ break;
+ }
+ }
+
+ /* 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:
+ memset(&curp->regs, 0, sizeof(struct regset));
+ if (mdoc)
+ mdoc_reset(mdoc);
+ if (man)
+ man_reset(man);
+ if (roff)
+ roff_reset(roff);
+
+ return;
+}
+
+
+static void
+pdesc(struct curparse *curp)
+{
struct buf ln, blk;
int i, pos, lnn, lnn_start, with_mmap, of;
enum rofferr re;
@@ -399,10 +518,6 @@ fdesc(struct curparse *curp)
struct mdoc *mdoc;
struct roff *roff;
- man = NULL;
- mdoc = NULL;
- roff = NULL;
-
memset(&ln, 0, sizeof(struct buf));
/*
@@ -419,6 +534,8 @@ fdesc(struct curparse *curp)
curp->roff = roff_alloc(&curp->regs, curp, mmsg);
assert(curp->roff);
roff = curp->roff;
+ mdoc = curp->mdoc;
+ man = curp->man;
for (i = 0, lnn = 1; i < (int)blk.sz;) {
pos = 0;
@@ -511,7 +628,7 @@ fdesc(struct curparse *curp)
continue;
} else if (ROFF_ERR == re) {
assert(MANDOCLEVEL_FATAL <= exit_status);
- goto cleanup;
+ break;
}
/*
@@ -528,119 +645,19 @@ fdesc(struct curparse *curp)
if (man && ! man_parseln(man, lnn_start, ln.buf, of)) {
assert(MANDOCLEVEL_FATAL <= exit_status);
- goto cleanup;
+ break;
}
if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf, of)) {
assert(MANDOCLEVEL_FATAL <= exit_status);
- goto cleanup;
- }
- }
-
- /* NOTE a parser may not have been assigned, yet. */
-
- if ( ! (man || mdoc)) {
- fprintf(stderr, "%s: Not a manual\n", curp->file);
- exit_status = MANDOCLEVEL_FATAL;
- goto cleanup;
- }
-
- /* Clean up the parse routine ASTs. */
-
- if (mdoc && ! mdoc_endparse(mdoc)) {
- assert(MANDOCLEVEL_FATAL <= exit_status);
- goto cleanup;
- }
- if (man && ! man_endparse(man)) {
- assert(MANDOCLEVEL_FATAL <= exit_status);
- goto cleanup;
- }
- if (roff && ! roff_endparse(roff)) {
- assert(MANDOCLEVEL_FATAL <= exit_status);
- goto cleanup;
- }
-
- /*
- * With -Wstop and warnings or errors of at least
- * the requested level, do not produce output.
- */
-
- if (MANDOCLEVEL_OK != exit_status && curp->wstop)
- goto cleanup;
-
- /* If unset, allocate output dev now (if applicable). */
-
- if ( ! (curp->outman && curp->outmdoc)) {
- switch (curp->outtype) {
- case (OUTT_XHTML):
- curp->outdata = xhtml_alloc(curp->outopts);
- break;
- case (OUTT_HTML):
- curp->outdata = html_alloc(curp->outopts);
- break;
- case (OUTT_ASCII):
- curp->outdata = ascii_alloc(curp->outopts);
- curp->outfree = ascii_free;
- break;
- case (OUTT_PDF):
- curp->outdata = pdf_alloc(curp->outopts);
- curp->outfree = pspdf_free;
- break;
- case (OUTT_PS):
- curp->outdata = ps_alloc(curp->outopts);
- curp->outfree = pspdf_free;
- break;
- default:
- break;
- }
-
- switch (curp->outtype) {
- case (OUTT_HTML):
- /* FALLTHROUGH */
- case (OUTT_XHTML):
- curp->outman = html_man;
- curp->outmdoc = html_mdoc;
- curp->outfree = html_free;
- break;
- case (OUTT_TREE):
- curp->outman = tree_man;
- curp->outmdoc = tree_mdoc;
- break;
- case (OUTT_PDF):
- /* FALLTHROUGH */
- case (OUTT_ASCII):
- /* FALLTHROUGH */
- case (OUTT_PS):
- curp->outman = terminal_man;
- curp->outmdoc = terminal_mdoc;
- break;
- default:
break;
}
}
- /* 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:
- memset(&curp->regs, 0, sizeof(struct regset));
- if (mdoc)
- mdoc_reset(mdoc);
- if (man)
- man_reset(man);
- if (roff)
- roff_reset(roff);
- if (ln.buf)
- free(ln.buf);
+ free(ln.buf);
if (with_mmap)
munmap(blk.buf, blk.sz);
else
free(blk.buf);
-
- return;
}