=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.43 retrieving revision 1.49 diff -u -p -r1.43 -r1.49 --- mandoc/main.c 2009/09/16 22:17:27 1.43 +++ mandoc/main.c 2009/10/26 08:42:37 1.49 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.43 2009/09/16 22:17:27 kristaps Exp $ */ +/* $Id: main.c,v 1.49 2009/10/26 08:42:37 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -20,17 +20,22 @@ #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__ extern int getsubopt(char **, char * const *, char **); +extern size_t strlcat(char *, const char *, size_t); # ifndef __dead # define __dead __attribute__((__noreturn__)) # endif @@ -58,9 +63,7 @@ enum intt { enum outt { OUTT_ASCII = 0, OUTT_TREE, -#if 1 OUTT_HTML, -#endif OUTT_LINT }; @@ -86,21 +89,9 @@ struct curparse { out_man outman; out_free outfree; void *outdata; + char outopts[BUFSIZ]; }; -#if 1 -extern void *html_alloc(void); -extern void html_mdoc(void *, const struct mdoc *); -extern void html_man(void *, const struct man *); -extern void html_free(void *); -#endif -extern void *ascii_alloc(void); -extern void tree_mdoc(void *, const struct mdoc *); -extern void tree_man(void *, const struct man *); -extern void terminal_mdoc(void *, const struct mdoc *); -extern void 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 *); @@ -134,7 +125,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)) @@ -144,6 +135,10 @@ main(int argc, char *argv[]) if ( ! moptions(&curp.inttype, optarg)) return(EXIT_FAILURE); break; + case ('O'): + (void)strlcat(curp.outopts, optarg, BUFSIZ); + (void)strlcat(curp.outopts, ",", BUFSIZ); + break; case ('T'): if ( ! toptions(&curp.outtype, optarg)) return(EXIT_FAILURE); @@ -228,8 +223,8 @@ usage(void) { (void)fprintf(stderr, "usage: %s [-V] [-foption...] " - "[-mformat] [-Toutput] [-Werr...]\n", - __progname); + "[-mformat] [-Ooption] [-Toutput] " + "[-Werr...]\n", __progname); exit(EXIT_FAILURE); } @@ -441,14 +436,12 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse if ( ! (curp->outman && curp->outmdoc)) { switch (curp->outtype) { -#if 1 case (OUTT_HTML): - curp->outdata = html_alloc(); + curp->outdata = html_alloc(curp->outopts); curp->outman = html_man; curp->outmdoc = html_mdoc; curp->outfree = html_free; break; -#endif case (OUTT_TREE): curp->outman = tree_man; curp->outmdoc = tree_mdoc; @@ -563,10 +556,8 @@ toptions(enum outt *tflags, char *arg) *tflags = OUTT_LINT; else if (0 == strcmp(arg, "tree")) *tflags = OUTT_TREE; -#if 1 else if (0 == strcmp(arg, "html")) *tflags = OUTT_HTML; -#endif else { warnx("bad argument: -T%s", arg); return(0); @@ -580,7 +571,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"; @@ -592,7 +583,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; @@ -626,7 +617,7 @@ static int woptions(int *wflags, char *arg) { char *v, *o; - char *toks[3]; + const char *toks[3]; toks[0] = "all"; toks[1] = "error"; @@ -634,7 +625,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;