=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.41 retrieving revision 1.46 diff -u -p -r1.41 -r1.46 --- mandoc/main.c 2009/07/28 10:15:12 1.41 +++ mandoc/main.c 2009/10/13 10:57:25 1.46 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.41 2009/07/28 10:15:12 kristaps Exp $ */ +/* $Id: main.c,v 1.46 2009/10/13 10:57:25 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -20,13 +20,17 @@ #include #include #include +#include #include #include #include #include "mdoc.h" #include "man.h" +#include "main.h" +#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) + /* Account for FreeBSD and Linux in our declarations. */ #ifdef __linux__ @@ -40,8 +44,8 @@ extern int getsubopt(char **, char * const *, char # endif #endif -typedef int (*out_mdoc)(void *, const struct mdoc *); -typedef int (*out_man)(void *, const struct man *); +typedef void (*out_mdoc)(void *, const struct mdoc *); +typedef void (*out_man)(void *, const struct man *); typedef void (*out_free)(void *); struct buf { @@ -58,6 +62,7 @@ enum intt { enum outt { OUTT_ASCII = 0, OUTT_TREE, + OUTT_HTML, OUTT_LINT }; @@ -83,15 +88,9 @@ struct curparse { out_man outman; out_free outfree; void *outdata; + char *outopts; }; -extern void *ascii_alloc(void); -extern int tree_mdoc(void *, const struct mdoc *); -extern int tree_man(void *, const struct man *); -extern int terminal_mdoc(void *, const struct mdoc *); -extern int terminal_man(void *, const struct man *); -extern void terminal_free(void *); - static int foptions(int *, char *); static int toptions(enum outt *, char *); static int moptions(enum intt *, char *); @@ -125,7 +124,7 @@ main(int argc, char *argv[]) curp.outtype = OUTT_ASCII; /* LINTED */ - while (-1 != (c = getopt(argc, argv, "f:m:VW:T:"))) + while (-1 != (c = getopt(argc, argv, "f:m:o:T:VW:"))) switch (c) { case ('f'): if ( ! foptions(&curp.fflags, optarg)) @@ -135,6 +134,9 @@ main(int argc, char *argv[]) if ( ! moptions(&curp.inttype, optarg)) return(EXIT_FAILURE); break; + case ('o'): + curp.outopts = optarg; + break; case ('T'): if ( ! toptions(&curp.outtype, optarg)) return(EXIT_FAILURE); @@ -432,6 +434,12 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse if ( ! (curp->outman && curp->outmdoc)) { switch (curp->outtype) { + case (OUTT_HTML): + curp->outdata = html_alloc(curp->outopts); + curp->outman = html_man; + curp->outmdoc = html_mdoc; + curp->outfree = html_free; + break; case (OUTT_TREE): curp->outman = tree_man; curp->outmdoc = tree_mdoc; @@ -450,11 +458,9 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse /* Execute the out device, if it exists. */ if (man && curp->outman) - if ( ! (*curp->outman)(curp->outdata, man)) - return(-1); + (*curp->outman)(curp->outdata, man); if (mdoc && curp->outmdoc) - if ( ! (*curp->outmdoc)(curp->outdata, mdoc)) - return(-1); + (*curp->outmdoc)(curp->outdata, mdoc); return(1); } @@ -548,6 +554,8 @@ toptions(enum outt *tflags, char *arg) *tflags = OUTT_LINT; else if (0 == strcmp(arg, "tree")) *tflags = OUTT_TREE; + else if (0 == strcmp(arg, "html")) + *tflags = OUTT_HTML; else { warnx("bad argument: -T%s", arg); return(0); @@ -561,7 +569,7 @@ static int foptions(int *fflags, char *arg) { char *v, *o; - char *toks[7]; + const char *toks[7]; toks[0] = "ign-scope"; toks[1] = "no-ign-escape"; @@ -573,7 +581,7 @@ foptions(int *fflags, char *arg) while (*arg) { o = arg; - switch (getsubopt(&arg, toks, &v)) { + switch (getsubopt(&arg, UNCONST(toks), &v)) { case (0): *fflags |= IGN_SCOPE; break; @@ -607,7 +615,7 @@ static int woptions(int *wflags, char *arg) { char *v, *o; - char *toks[3]; + const char *toks[3]; toks[0] = "all"; toks[1] = "error"; @@ -615,7 +623,7 @@ woptions(int *wflags, char *arg) while (*arg) { o = arg; - switch (getsubopt(&arg, toks, &v)) { + switch (getsubopt(&arg, UNCONST(toks), &v)) { case (0): *wflags |= WARN_WALL; break;