=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.50 retrieving revision 1.51 diff -c -r1.50 -r1.51 *** src/usr.bin/mandoc/main.c 2010/10/24 18:15:43 1.50 --- src/usr.bin/mandoc/main.c 2010/10/26 22:13:58 1.51 *************** *** 1,4 **** ! /* $Id: main.c,v 1.50 2010/10/24 18:15:43 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze --- 1,4 ---- ! /* $Id: main.c,v 1.51 2010/10/26 22:13:58 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze *************** *** 178,183 **** --- 178,184 ---- "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,396 **** --- 392,515 ---- 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,408 **** struct mdoc *mdoc; struct roff *roff; - man = NULL; - mdoc = NULL; - roff = NULL; - memset(&ln, 0, sizeof(struct buf)); /* --- 518,523 ---- *************** *** 419,424 **** --- 534,541 ---- 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,517 **** continue; } else if (ROFF_ERR == re) { assert(MANDOCLEVEL_FATAL <= exit_status); ! goto cleanup; } /* --- 628,634 ---- continue; } else if (ROFF_ERR == re) { assert(MANDOCLEVEL_FATAL <= exit_status); ! break; } /* *************** *** 528,646 **** if (man && ! man_parseln(man, lnn_start, ln.buf, of)) { assert(MANDOCLEVEL_FATAL <= exit_status); ! goto cleanup; } 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); if (with_mmap) munmap(blk.buf, blk.sz); else free(blk.buf); - - return; } --- 645,663 ---- if (man && ! man_parseln(man, lnn_start, ln.buf, of)) { assert(MANDOCLEVEL_FATAL <= exit_status); ! break; } if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf, of)) { assert(MANDOCLEVEL_FATAL <= exit_status); break; } } ! free(ln.buf); if (with_mmap) munmap(blk.buf, blk.sz); else free(blk.buf); }