]> git.cameronkatri.com Git - mandoc.git/blobdiff - main.c
move man(7) validation into the dedicated validation phase, too
[mandoc.git] / main.c
diff --git a/main.c b/main.c
index e4d42b55544f1769550646d2a5f0b8826db15903..31dc9994cc17c2b4b690be72e103ec4aa67dd54d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/*     $Id: main.c,v 1.248 2015/10/12 00:08:15 schwarze Exp $ */
+/*     $Id: main.c,v 1.253 2015/10/22 21:54:23 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -59,10 +59,6 @@ enum outmode {
        OUTMODE_ONE
 };
 
-typedef        void            (*out_mdoc)(void *, const struct roff_man *);
-typedef        void            (*out_man)(void *, const struct roff_man *);
-typedef        void            (*out_free)(void *);
-
 enum   outt {
        OUTT_ASCII = 0, /* -Tascii */
        OUTT_LOCALE,    /* -Tlocale */
@@ -77,13 +73,9 @@ enum outt {
 
 struct curparse {
        struct mparse    *mp;
-       struct mchars    *mchars;       /* character table */
        enum mandoclevel  wlevel;       /* ignore messages below this */
        int               wstop;        /* stop after a file with a warning */
        enum outt         outtype;      /* which output to use */
-       out_mdoc          outmdoc;      /* mdoc output ptr */
-       out_man           outman;       /* man output ptr */
-       out_free          outfree;      /* free output ptr */
        void             *outdata;      /* data for output */
        struct manoutput *outopts;      /* output options */
 };
@@ -422,9 +414,8 @@ main(int argc, char *argv[])
        if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths))
                return (int)MANDOCLEVEL_BADARG;
 
-       curp.mchars = mchars_alloc();
-       curp.mp = mparse_alloc(options, curp.wlevel, mmsg,
-           curp.mchars, defos);
+       mchars_alloc();
+       curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
 
        /*
         * Conditionally start up the lookaside buffer before parsing.
@@ -475,10 +466,26 @@ main(int argc, char *argv[])
                        mparse_reset(curp.mp);
        }
 
-       if (curp.outfree)
-               (*curp.outfree)(curp.outdata);
+       if (curp.outdata != NULL) {
+               switch (curp.outtype) {
+               case OUTT_HTML:
+                       html_free(curp.outdata);
+                       break;
+               case OUTT_UTF8:
+               case OUTT_LOCALE:
+               case OUTT_ASCII:
+                       ascii_free(curp.outdata);
+                       break;
+               case OUTT_PDF:
+               case OUTT_PS:
+                       pspdf_free(curp.outdata);
+                       break;
+               default:
+                       break;
+               }
+       }
        mparse_free(curp.mp);
-       mchars_free(curp.mchars);
+       mchars_free();
 
 out:
        if (search.argmode != ARG_FILE) {
@@ -659,78 +666,83 @@ parse(struct curparse *curp, int fd, const char *file)
 
        /* If unset, allocate output dev now (if applicable). */
 
-       if ( ! (curp->outman && curp->outmdoc)) {
+       if (curp->outdata == NULL) {
                switch (curp->outtype) {
                case OUTT_HTML:
-                       curp->outdata = html_alloc(curp->mchars,
-                           curp->outopts);
-                       curp->outfree = html_free;
+                       curp->outdata = html_alloc(curp->outopts);
                        break;
                case OUTT_UTF8:
-                       curp->outdata = utf8_alloc(curp->mchars,
-                           curp->outopts);
-                       curp->outfree = ascii_free;
+                       curp->outdata = utf8_alloc(curp->outopts);
                        break;
                case OUTT_LOCALE:
-                       curp->outdata = locale_alloc(curp->mchars,
-                           curp->outopts);
-                       curp->outfree = ascii_free;
+                       curp->outdata = locale_alloc(curp->outopts);
                        break;
                case OUTT_ASCII:
-                       curp->outdata = ascii_alloc(curp->mchars,
-                           curp->outopts);
-                       curp->outfree = ascii_free;
+                       curp->outdata = ascii_alloc(curp->outopts);
                        break;
                case OUTT_PDF:
-                       curp->outdata = pdf_alloc(curp->mchars,
-                           curp->outopts);
-                       curp->outfree = pspdf_free;
+                       curp->outdata = pdf_alloc(curp->outopts);
                        break;
                case OUTT_PS:
-                       curp->outdata = ps_alloc(curp->mchars,
-                           curp->outopts);
-                       curp->outfree = pspdf_free;
+                       curp->outdata = ps_alloc(curp->outopts);
                        break;
                default:
                        break;
                }
+       }
 
+       mparse_result(curp->mp, &man, NULL);
+
+       /* Execute the out device, if it exists. */
+
+       if (man == NULL)
+               return;
+       if (man->macroset == MACROSET_MDOC) {
+               mdoc_validate(man);
                switch (curp->outtype) {
                case OUTT_HTML:
-                       curp->outman = html_man;
-                       curp->outmdoc = html_mdoc;
+                       html_mdoc(curp->outdata, man);
                        break;
                case OUTT_TREE:
-                       curp->outman = tree_man;
-                       curp->outmdoc = tree_mdoc;
+                       tree_mdoc(curp->outdata, man);
                        break;
                case OUTT_MAN:
-                       curp->outmdoc = man_mdoc;
-                       curp->outman = man_man;
+                       man_mdoc(curp->outdata, man);
                        break;
                case OUTT_PDF:
                case OUTT_ASCII:
                case OUTT_UTF8:
                case OUTT_LOCALE:
                case OUTT_PS:
-                       curp->outman = terminal_man;
-                       curp->outmdoc = terminal_mdoc;
+                       terminal_mdoc(curp->outdata, man);
+                       break;
+               default:
+                       break;
+               }
+       }
+       if (man->macroset == MACROSET_MAN) {
+               man_validate(man);
+               switch (curp->outtype) {
+               case OUTT_HTML:
+                       html_man(curp->outdata, man);
+                       break;
+               case OUTT_TREE:
+                       tree_man(curp->outdata, man);
+                       break;
+               case OUTT_MAN:
+                       man_man(curp->outdata, man);
+                       break;
+               case OUTT_PDF:
+               case OUTT_ASCII:
+               case OUTT_UTF8:
+               case OUTT_LOCALE:
+               case OUTT_PS:
+                       terminal_man(curp->outdata, man);
                        break;
                default:
                        break;
                }
        }
-
-       mparse_result(curp->mp, &man, NULL);
-
-       /* Execute the out device, if it exists. */
-
-       if (man == NULL)
-               return;
-       if (curp->outmdoc != NULL && man->macroset == MACROSET_MDOC)
-               (*curp->outmdoc)(curp->outdata, man);
-       if (curp->outman != NULL && man->macroset == MACROSET_MAN)
-               (*curp->outman)(curp->outdata, man);
 }
 
 static void