=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.39 retrieving revision 1.47 diff -u -p -r1.39 -r1.47 --- mandoc/main.c 2009/07/24 14:00:59 1.39 +++ mandoc/main.c 2009/10/26 04:15:42 1.47 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.39 2009/07/24 14:00:59 kristaps Exp $ */ +/* $Id: main.c,v 1.47 2009/10/26 04:15:42 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); @@ -418,7 +420,8 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse /* NOTE a parser may not have been assigned, yet. */ if ( ! (man || mdoc)) { - warnx("%s: not a manual", curp->file); + (void)fprintf(stderr, "%s: not a manual\n", + curp->file); return(0); } @@ -431,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; @@ -449,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); } @@ -547,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); @@ -560,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"; @@ -572,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; @@ -606,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"; @@ -614,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; @@ -639,8 +648,8 @@ merr(void *arg, int line, int col, const char *msg) curp = (struct curparse *)arg; - warnx("%s:%d: error: %s (column %d)", - curp->file, line, msg, col); + (void)fprintf(stderr, "%s:%d:%d: error: %s\n", + curp->file, line, col + 1, msg); return(0); } @@ -656,13 +665,12 @@ mwarn(void *arg, int line, int col, const char *msg) if ( ! (curp->wflags & WARN_WALL)) return(1); - warnx("%s:%d: warning: %s (column %d)", - curp->file, line, msg, col); + (void)fprintf(stderr, "%s:%d:%d: warning: %s\n", + curp->file, line, col + 1, msg); if ( ! (curp->wflags & WARN_WERR)) return(1); - warnx("considering warnings as errors"); return(0); }