=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.162 retrieving revision 1.172 diff -u -p -r1.162 -r1.172 --- mandoc/main.c 2011/05/17 14:38:34 1.162 +++ mandoc/main.c 2014/03/23 11:25:26 1.172 @@ -1,7 +1,8 @@ -/* $Id: main.c,v 1.162 2011/05/17 14:38:34 kristaps Exp $ */ +/* $Id: main.c,v 1.172 2014/03/23 11:25:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2011 Ingo Schwarze + * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze + * Copyright (c) 2010 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -27,6 +28,7 @@ #include #include "mandoc.h" +#include "mandoc_aux.h" #include "main.h" #include "mdoc.h" #include "man.h" @@ -44,7 +46,9 @@ 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 */ @@ -64,7 +68,7 @@ struct curparse { char outopts[BUFSIZ]; /* buf of output opts */ }; -static int moptions(enum mparset *, char *); +static int moptions(int *, char *); static void mmsg(enum mandocerr, enum mandoclevel, const char *, int, int, const char *); static void parse(struct curparse *, int, @@ -81,8 +85,9 @@ main(int argc, char *argv[]) { int c; struct curparse curp; - enum mparset type; + int options; enum mandoclevel rc; + char *defos; progname = strrchr(argv[0], '/'); if (progname == NULL) @@ -92,15 +97,29 @@ main(int argc, char *argv[]) memset(&curp, 0, sizeof(struct curparse)); - type = MPARSE_AUTO; + options = MPARSE_SO; 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)) + if ( ! moptions(&options, optarg)) return((int)MANDOCLEVEL_BADARG); break; case ('O'): @@ -123,8 +142,14 @@ main(int argc, char *argv[]) /* NOTREACHED */ } - curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp); + curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos); + /* + * Conditionally start up the lookaside buffer before parsing. + */ + if (OUTT_MAN == curp.outtype) + mparse_keep(curp.mp); + argc -= optind; argv += optind; @@ -144,6 +169,7 @@ main(int argc, char *argv[]) (*curp.outfree)(curp.outdata); if (curp.mp) mparse_free(curp.mp); + free(defos); return((int)rc); } @@ -162,12 +188,12 @@ usage(void) fprintf(stderr, "usage: %s " "[-V] " - "[-foption] " + "[-Ios=name] " "[-mformat] " "[-Ooption] " "[-Toutput] " - "[-Wlevel] " - "[file...]\n", + "[-Wlevel]\n" + "\t [file ...]\n", progname); exit((int)MANDOCLEVEL_BADARG); @@ -213,6 +239,10 @@ parse(struct curparse *curp, int fd, 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; @@ -244,10 +274,16 @@ parse(struct curparse *curp, int fd, 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): @@ -259,7 +295,7 @@ parse(struct curparse *curp, int fd, } } - mparse_result(curp->mp, &mdoc, &man); + mparse_result(curp->mp, &mdoc, &man, NULL); /* Execute the out device, if it exists. */ @@ -277,15 +313,15 @@ parse(struct curparse *curp, int fd, } static int -moptions(enum mparset *tflags, char *arg) +moptions(int *options, char *arg) { if (0 == strcmp(arg, "doc")) - *tflags = MPARSE_MDOC; + *options |= MPARSE_MDOC; else if (0 == strcmp(arg, "andoc")) - *tflags = MPARSE_AUTO; + /* nothing to do */; else if (0 == strcmp(arg, "an")) - *tflags = MPARSE_MAN; + *options |= MPARSE_MAN; else { fprintf(stderr, "%s: Bad argument\n", arg); return(0); @@ -305,8 +341,12 @@ 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"))