]> git.cameronkatri.com Git - mandoc.git/blobdiff - main.c
The name "struct tbl" was badly misleading for two reasons:
[mandoc.git] / main.c
diff --git a/main.c b/main.c
index 2a8eac6da45b52118a3d9c93f8f18f64f0caedee..7e5c7a98aef285cdefcc75c3ea3e5779c4f2222c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,7 +1,7 @@
-/*     $Id: main.c,v 1.160 2011/03/28 21:49:42 kristaps Exp $ */
+/*     $Id: main.c,v 1.167 2012/11/19 17:22:26 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -43,7 +43,10 @@ typedef      void            (*out_free)(void *);
 
 enum   outt {
        OUTT_ASCII = 0, /* -Tascii */
+       OUTT_LOCALE,    /* -Tlocale */
+       OUTT_UTF8,      /* -Tutf8 */
        OUTT_TREE,      /* -Ttree */
+       OUTT_MAN,       /* -Tman */
        OUTT_HTML,      /* -Thtml */
        OUTT_XHTML,     /* -Txhtml */
        OUTT_LINT,      /* -Tlint */
@@ -82,6 +85,7 @@ main(int argc, char *argv[])
        struct curparse  curp;
        enum mparset     type;
        enum mandoclevel rc;
+       char            *defos;
 
        progname = strrchr(argv[0], '/');
        if (progname == NULL)
@@ -94,10 +98,24 @@ main(int argc, char *argv[])
        type = MPARSE_AUTO;
        curp.outtype = OUTT_ASCII;
        curp.wlevel  = MANDOCLEVEL_FATAL;
+       defos = NULL;
 
        /* LINTED */
-       while (-1 != (c = getopt(argc, argv, "m:O:T:VW:")))
+       while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:")))
                switch (c) {
+               case ('I'):
+                       if (strncmp(optarg, "os=", 3)) {
+                               fprintf(stderr, "-I%s: Bad argument\n",
+                                               optarg);
+                               return((int)MANDOCLEVEL_BADARG);
+                       }
+                       if (defos) {
+                               fprintf(stderr, "-I%s: Duplicate argument\n",
+                                               optarg);
+                               return((int)MANDOCLEVEL_BADARG);
+                       }
+                       defos = mandoc_strdup(optarg + 3);
+                       break;
                case ('m'):
                        if ( ! moptions(&type, optarg))
                                return((int)MANDOCLEVEL_BADARG);
@@ -122,7 +140,13 @@ main(int argc, char *argv[])
                        /* NOTREACHED */
                }
 
-       curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp);
+       curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp, defos);
+
+       /*
+        * Conditionally start up the lookaside buffer before parsing.
+        */
+       if (OUTT_MAN == curp.outtype)
+               mparse_keep(curp.mp);
 
        argc -= optind;
        argv += optind;
@@ -143,6 +167,7 @@ main(int argc, char *argv[])
                (*curp.outfree)(curp.outdata);
        if (curp.mp)
                mparse_free(curp.mp);
+       free(defos);
 
        return((int)rc);
 }
@@ -161,12 +186,12 @@ usage(void)
 
        fprintf(stderr, "usage: %s "
                        "[-V] "
-                       "[-foption] "
+                       "[-Ios=name] "
                        "[-mformat] "
                        "[-Ooption] "
                        "[-Toutput] "
-                       "[-Werr] "
-                       "[file...]\n", 
+                       "[-Wlevel]\n"
+                       "\t      [file ...]\n", 
                        progname);
 
        exit((int)MANDOCLEVEL_BADARG);
@@ -206,9 +231,19 @@ parse(struct curparse *curp, int fd,
                switch (curp->outtype) {
                case (OUTT_XHTML):
                        curp->outdata = xhtml_alloc(curp->outopts);
+                       curp->outfree = html_free;
                        break;
                case (OUTT_HTML):
                        curp->outdata = html_alloc(curp->outopts);
+                       curp->outfree = html_free;
+                       break;
+               case (OUTT_UTF8):
+                       curp->outdata = utf8_alloc(curp->outopts);
+                       curp->outfree = ascii_free;
+                       break;
+               case (OUTT_LOCALE):
+                       curp->outdata = locale_alloc(curp->outopts);
+                       curp->outfree = ascii_free;
                        break;
                case (OUTT_ASCII):
                        curp->outdata = ascii_alloc(curp->outopts);
@@ -232,16 +267,23 @@ parse(struct curparse *curp, int fd,
                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_MAN):
+                       curp->outmdoc = man_mdoc;
+                       curp->outman = man_man;
+                       break;
                case (OUTT_PDF):
                        /* FALLTHROUGH */
                case (OUTT_ASCII):
                        /* FALLTHROUGH */
+               case (OUTT_UTF8):
+                       /* FALLTHROUGH */
+               case (OUTT_LOCALE):
+                       /* FALLTHROUGH */
                case (OUTT_PS):
                        curp->outman = terminal_man;
                        curp->outmdoc = terminal_mdoc;
@@ -297,8 +339,14 @@ toptions(struct curparse *curp, char *arg)
                curp->wlevel  = MANDOCLEVEL_WARNING;
        } else if (0 == strcmp(arg, "tree"))
                curp->outtype = OUTT_TREE;
+       else if (0 == strcmp(arg, "man"))
+               curp->outtype = OUTT_MAN;
        else if (0 == strcmp(arg, "html"))
                curp->outtype = OUTT_HTML;
+       else if (0 == strcmp(arg, "utf8"))
+               curp->outtype = OUTT_UTF8;
+       else if (0 == strcmp(arg, "locale"))
+               curp->outtype = OUTT_LOCALE;
        else if (0 == strcmp(arg, "xhtml"))
                curp->outtype = OUTT_XHTML;
        else if (0 == strcmp(arg, "ps"))