]> git.cameronkatri.com Git - mandoc.git/blobdiff - main.c
Make the character table available to libroff so it can check the
[mandoc.git] / main.c
diff --git a/main.c b/main.c
index f6597b849890e6306005a2c3d347d3498ea91419..79a2ddd6fd1dd534c9bbfe563c6fc1288299c844 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/*     $Id: main.c,v 1.193 2014/10/18 15:57:34 schwarze Exp $ */
+/*     $Id: main.c,v 1.195 2014/10/28 17:36:19 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -64,7 +64,6 @@ enum  outt {
        OUTT_TREE,      /* -Ttree */
        OUTT_MAN,       /* -Tman */
        OUTT_HTML,      /* -Thtml */
        OUTT_TREE,      /* -Ttree */
        OUTT_MAN,       /* -Tman */
        OUTT_HTML,      /* -Thtml */
-       OUTT_XHTML,     /* -Txhtml */
        OUTT_LINT,      /* -Tlint */
        OUTT_PS,        /* -Tps */
        OUTT_PDF        /* -Tpdf */
        OUTT_LINT,      /* -Tlint */
        OUTT_PS,        /* -Tps */
        OUTT_PDF        /* -Tpdf */
@@ -72,6 +71,7 @@ enum  outt {
 
 struct curparse {
        struct mparse    *mp;
 
 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 */
        enum mandoclevel  wlevel;       /* ignore messages below this */
        int               wstop;        /* stop after a file with a warning */
        enum outt         outtype;      /* which output to use */
@@ -82,6 +82,7 @@ struct        curparse {
        char              outopts[BUFSIZ]; /* buf of output opts */
 };
 
        char              outopts[BUFSIZ]; /* buf of output opts */
 };
 
+static int               koptions(int *, char *);
 static int               moptions(int *, char *);
 static void              mmsg(enum mandocerr, enum mandoclevel,
                                const char *, int, int, const char *);
 static int               moptions(int *, char *);
 static void              mmsg(enum mandocerr, enum mandoclevel,
                                const char *, int, int, const char *);
@@ -149,14 +150,15 @@ main(int argc, char *argv[])
        memset(&curp, 0, sizeof(struct curparse));
        curp.outtype = OUTT_ASCII;
        curp.wlevel  = MANDOCLEVEL_FATAL;
        memset(&curp, 0, sizeof(struct curparse));
        curp.outtype = OUTT_ASCII;
        curp.wlevel  = MANDOCLEVEL_FATAL;
-       options = MPARSE_SO;
+       options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1;
        defos = NULL;
 
        use_pager = 1;
        show_usage = 0;
        outmode = OUTMODE_DEF;
 
        defos = NULL;
 
        use_pager = 1;
        show_usage = 0;
        outmode = OUTMODE_DEF;
 
-       while (-1 != (c = getopt(argc, argv, "aC:cfhI:iklM:m:O:S:s:T:VW:w"))) {
+       while (-1 != (c = getopt(argc, argv,
+                       "aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
                switch (c) {
                case 'a':
                        outmode = OUTMODE_ALL;
                switch (c) {
                case 'a':
                        outmode = OUTMODE_ALL;
@@ -192,6 +194,10 @@ main(int argc, char *argv[])
                case 'i':
                        outmode = OUTMODE_INT;
                        break;
                case 'i':
                        outmode = OUTMODE_INT;
                        break;
+               case 'K':
+                       if ( ! koptions(&options, optarg))
+                               return((int)MANDOCLEVEL_BADARG);
+                       break;
                case 'k':
                        search.argmode = ARG_EXPR;
                        break;
                case 'k':
                        search.argmode = ARG_EXPR;
                        break;
@@ -358,7 +364,9 @@ main(int argc, char *argv[])
        if (use_pager && isatty(STDOUT_FILENO))
                spawn_pager();
 
        if (use_pager && isatty(STDOUT_FILENO))
                spawn_pager();
 
-       curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
+       curp.mchars = mchars_alloc();
+       curp.mp = mparse_alloc(options, curp.wlevel, mmsg,
+           curp.mchars, defos);
 
        /*
         * Conditionally start up the lookaside buffer before parsing.
 
        /*
         * Conditionally start up the lookaside buffer before parsing.
@@ -403,8 +411,8 @@ main(int argc, char *argv[])
 
        if (curp.outfree)
                (*curp.outfree)(curp.outdata);
 
        if (curp.outfree)
                (*curp.outfree)(curp.outdata);
-       if (curp.mp)
-               mparse_free(curp.mp);
+       mparse_free(curp.mp);
+       mchars_free(curp.mchars);
 
 #if HAVE_SQLITE3
 out:
 
 #if HAVE_SQLITE3
 out:
@@ -489,32 +497,34 @@ parse(struct curparse *curp, int fd, const char *file,
 
        if ( ! (curp->outman && curp->outmdoc)) {
                switch (curp->outtype) {
 
        if ( ! (curp->outman && curp->outmdoc)) {
                switch (curp->outtype) {
-               case OUTT_XHTML:
-                       curp->outdata = xhtml_alloc(curp->outopts);
-                       curp->outfree = html_free;
-                       break;
                case OUTT_HTML:
                case OUTT_HTML:
-                       curp->outdata = html_alloc(curp->outopts);
+                       curp->outdata = html_alloc(curp->mchars,
+                           curp->outopts);
                        curp->outfree = html_free;
                        break;
                case OUTT_UTF8:
                        curp->outfree = html_free;
                        break;
                case OUTT_UTF8:
-                       curp->outdata = utf8_alloc(curp->outopts);
+                       curp->outdata = utf8_alloc(curp->mchars,
+                           curp->outopts);
                        curp->outfree = ascii_free;
                        break;
                case OUTT_LOCALE:
                        curp->outfree = ascii_free;
                        break;
                case OUTT_LOCALE:
-                       curp->outdata = locale_alloc(curp->outopts);
+                       curp->outdata = locale_alloc(curp->mchars,
+                           curp->outopts);
                        curp->outfree = ascii_free;
                        break;
                case OUTT_ASCII:
                        curp->outfree = ascii_free;
                        break;
                case OUTT_ASCII:
-                       curp->outdata = ascii_alloc(curp->outopts);
+                       curp->outdata = ascii_alloc(curp->mchars,
+                           curp->outopts);
                        curp->outfree = ascii_free;
                        break;
                case OUTT_PDF:
                        curp->outfree = ascii_free;
                        break;
                case OUTT_PDF:
-                       curp->outdata = pdf_alloc(curp->outopts);
+                       curp->outdata = pdf_alloc(curp->mchars,
+                           curp->outopts);
                        curp->outfree = pspdf_free;
                        break;
                case OUTT_PS:
                        curp->outfree = pspdf_free;
                        break;
                case OUTT_PS:
-                       curp->outdata = ps_alloc(curp->outopts);
+                       curp->outdata = ps_alloc(curp->mchars,
+                           curp->outopts);
                        curp->outfree = pspdf_free;
                        break;
                default:
                        curp->outfree = pspdf_free;
                        break;
                default:
@@ -523,8 +533,6 @@ parse(struct curparse *curp, int fd, const char *file,
 
                switch (curp->outtype) {
                case OUTT_HTML:
 
                switch (curp->outtype) {
                case OUTT_HTML:
-                       /* FALLTHROUGH */
-               case OUTT_XHTML:
                        curp->outman = html_man;
                        curp->outmdoc = html_mdoc;
                        break;
                        curp->outman = html_man;
                        curp->outmdoc = html_mdoc;
                        break;
@@ -598,6 +606,26 @@ fail:
        return(MANDOCLEVEL_SYSERR);
 }
 
        return(MANDOCLEVEL_SYSERR);
 }
 
+static int
+koptions(int *options, char *arg)
+{
+
+       if ( ! strcmp(arg, "utf-8")) {
+               *options |=  MPARSE_UTF8;
+               *options &= ~MPARSE_LATIN1;
+       } else if ( ! strcmp(arg, "iso-8859-1")) {
+               *options |=  MPARSE_LATIN1;
+               *options &= ~MPARSE_UTF8;
+       } else if ( ! strcmp(arg, "us-ascii")) {
+               *options &= ~(MPARSE_UTF8 | MPARSE_LATIN1);
+       } else {
+               fprintf(stderr, "%s: -K%s: Bad argument\n",
+                   progname, arg);
+               return(0);
+       }
+       return(1);
+}
+
 static int
 moptions(int *options, char *arg)
 {
 static int
 moptions(int *options, char *arg)
 {
@@ -639,7 +667,7 @@ toptions(struct curparse *curp, char *arg)
        else if (0 == strcmp(arg, "locale"))
                curp->outtype = OUTT_LOCALE;
        else if (0 == strcmp(arg, "xhtml"))
        else if (0 == strcmp(arg, "locale"))
                curp->outtype = OUTT_LOCALE;
        else if (0 == strcmp(arg, "xhtml"))
-               curp->outtype = OUTT_XHTML;
+               curp->outtype = OUTT_HTML;
        else if (0 == strcmp(arg, "ps"))
                curp->outtype = OUTT_PS;
        else if (0 == strcmp(arg, "pdf"))
        else if (0 == strcmp(arg, "ps"))
                curp->outtype = OUTT_PS;
        else if (0 == strcmp(arg, "pdf"))