=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.56 retrieving revision 1.61 diff -u -p -r1.56 -r1.61 --- mandoc/main.c 2009/11/02 08:13:48 1.56 +++ mandoc/main.c 2010/04/12 19:27:22 1.61 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.56 2009/11/02 08:13:48 kristaps Exp $ */ +/* $Id: main.c,v 1.61 2010/04/12 19:27:22 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -14,6 +14,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include @@ -38,11 +42,6 @@ # endif #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ -#ifdef __linux__ -extern int getsubopt(char **, char * const *, char **); -extern size_t strlcat(char *, const char *, size_t); -#endif - typedef void (*out_mdoc)(void *, const struct mdoc *); typedef void (*out_man)(void *, const struct man *); typedef void (*out_free)(void *); @@ -62,6 +61,7 @@ enum outt { OUTT_ASCII = 0, OUTT_TREE, OUTT_HTML, + OUTT_XHTML, OUTT_LINT }; @@ -72,11 +72,11 @@ struct curparse { #define WARN_WALL (1 << 0) /* All-warnings mask. */ #define WARN_WERR (1 << 2) /* Warnings->errors. */ int fflags; -#define IGN_SCOPE (1 << 0) /* Ignore scope errors. */ -#define NO_IGN_ESCAPE (1 << 1) /* Don't ignore bad escapes. */ -#define NO_IGN_MACRO (1 << 2) /* Don't ignore bad macros. */ -#define NO_IGN_CHARS (1 << 3) /* Don't ignore bad chars. */ -#define IGN_ERRORS (1 << 4) /* Ignore failed parse. */ +#define FL_IGN_SCOPE (1 << 0) /* Ignore scope errors. */ +#define FL_NIGN_ESCAPE (1 << 1) /* Don't ignore bad escapes. */ +#define FL_NIGN_MACRO (1 << 2) /* Don't ignore bad macros. */ +#define FL_NIGN_CHARS (1 << 3) /* Don't ignore bad chars. */ +#define FL_IGN_ERRORS (1 << 4) /* Ignore failed parse. */ enum intt inttype; /* Input parsers... */ struct man *man; struct man *lastman; @@ -90,8 +90,12 @@ struct curparse { char outopts[BUFSIZ]; }; +#define FL_STRICT FL_NIGN_ESCAPE | \ + FL_NIGN_MACRO | \ + FL_NIGN_CHARS + static int foptions(int *, char *); -static int toptions(enum outt *, char *); +static int toptions(struct curparse *, char *); static int moptions(enum intt *, char *); static int woptions(int *, char *); static int merr(void *, int, int, const char *); @@ -144,7 +148,7 @@ main(int argc, char *argv[]) (void)strlcat(curp.outopts, ",", BUFSIZ); break; case ('T'): - if ( ! toptions(&curp.outtype, optarg)) + if ( ! toptions(&curp, optarg)) return(EXIT_FAILURE); break; case ('W'): @@ -172,7 +176,7 @@ main(int argc, char *argv[]) curp.fd = STDIN_FILENO; c = fdesc(&blk, &ln, &curp); - if ( ! (IGN_ERRORS & curp.fflags)) + if ( ! (FL_IGN_ERRORS & curp.fflags)) rc = 1 == c ? 1 : 0; else rc = -1 == c ? 0 : 1; @@ -180,7 +184,7 @@ main(int argc, char *argv[]) while (rc && *argv) { c = ffile(&blk, &ln, *argv, &curp); - if ( ! (IGN_ERRORS & curp.fflags)) + if ( ! (FL_IGN_ERRORS & curp.fflags)) rc = 1 == c ? 1 : 0; else rc = -1 == c ? 0 : 1; @@ -224,9 +228,9 @@ static void usage(void) { - (void)fprintf(stderr, "usage: %s [-V] [-foption...] " + (void)fprintf(stderr, "usage: %s [-V] [-foption] " "[-mformat] [-Ooption] [-Toutput] " - "[-Werr...]\n", progname); + "[-Werr] [file...]\n", progname); exit(EXIT_FAILURE); } @@ -244,11 +248,11 @@ man_init(struct curparse *curp) pflags = MAN_IGN_MACRO | MAN_IGN_ESCAPE | MAN_IGN_CHARS; - if (curp->fflags & NO_IGN_MACRO) + if (curp->fflags & FL_NIGN_MACRO) pflags &= ~MAN_IGN_MACRO; - if (curp->fflags & NO_IGN_CHARS) + if (curp->fflags & FL_NIGN_CHARS) pflags &= ~MAN_IGN_CHARS; - if (curp->fflags & NO_IGN_ESCAPE) + if (curp->fflags & FL_NIGN_ESCAPE) pflags &= ~MAN_IGN_ESCAPE; return(man_alloc(curp, pflags, &mancb)); @@ -268,13 +272,13 @@ mdoc_init(struct curparse *curp) pflags = MDOC_IGN_MACRO | MDOC_IGN_ESCAPE | MDOC_IGN_CHARS; - if (curp->fflags & IGN_SCOPE) + if (curp->fflags & FL_IGN_SCOPE) pflags |= MDOC_IGN_SCOPE; - if (curp->fflags & NO_IGN_ESCAPE) + if (curp->fflags & FL_NIGN_ESCAPE) pflags &= ~MDOC_IGN_ESCAPE; - if (curp->fflags & NO_IGN_MACRO) + if (curp->fflags & FL_NIGN_MACRO) pflags &= ~MDOC_IGN_MACRO; - if (curp->fflags & NO_IGN_CHARS) + if (curp->fflags & FL_NIGN_CHARS) pflags &= ~MDOC_IGN_CHARS; return(mdoc_alloc(curp, pflags, &mdoccb)); @@ -376,6 +380,12 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse comment = 1; pos -= 2; + for (; pos > 0; --pos) { + if (ln->buf[pos] != ' ') + break; + if (ln->buf[pos - 1] == '\\') + break; + } continue; } @@ -429,6 +439,12 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse if ( ! (curp->outman && curp->outmdoc)) { switch (curp->outtype) { + case (OUTT_XHTML): + curp->outdata = xhtml_alloc(curp->outopts); + curp->outman = html_man; + curp->outmdoc = html_mdoc; + curp->outfree = html_free; + break; case (OUTT_HTML): curp->outdata = html_alloc(curp->outopts); curp->outman = html_man; @@ -531,7 +547,7 @@ moptions(enum intt *tflags, char *arg) else if (0 == strcmp(arg, "an")) *tflags = INTT_MAN; else { - fprintf(stderr, "%s: Bad argument", arg); + fprintf(stderr, "%s: Bad argument\n", arg); return(0); } @@ -540,19 +556,24 @@ moptions(enum intt *tflags, char *arg) static int -toptions(enum outt *tflags, char *arg) +toptions(struct curparse *curp, char *arg) { if (0 == strcmp(arg, "ascii")) - *tflags = OUTT_ASCII; - else if (0 == strcmp(arg, "lint")) - *tflags = OUTT_LINT; + curp->outtype = OUTT_ASCII; + else if (0 == strcmp(arg, "lint")) { + curp->outtype = OUTT_LINT; + curp->wflags |= WARN_WALL; + curp->fflags |= FL_STRICT; + } else if (0 == strcmp(arg, "tree")) - *tflags = OUTT_TREE; + curp->outtype = OUTT_TREE; else if (0 == strcmp(arg, "html")) - *tflags = OUTT_HTML; + curp->outtype = OUTT_HTML; + else if (0 == strcmp(arg, "xhtml")) + curp->outtype = OUTT_XHTML; else { - fprintf(stderr, "%s: Bad argument", arg); + fprintf(stderr, "%s: Bad argument\n", arg); return(0); } @@ -579,29 +600,28 @@ foptions(int *fflags, char *arg) o = arg; switch (getsubopt(&arg, UNCONST(toks), &v)) { case (0): - *fflags |= IGN_SCOPE; + *fflags |= FL_IGN_SCOPE; break; case (1): - *fflags |= NO_IGN_ESCAPE; + *fflags |= FL_NIGN_ESCAPE; break; case (2): - *fflags |= NO_IGN_MACRO; + *fflags |= FL_NIGN_MACRO; break; case (3): - *fflags |= NO_IGN_CHARS; + *fflags |= FL_NIGN_CHARS; break; case (4): - *fflags |= IGN_ERRORS; + *fflags |= FL_IGN_ERRORS; break; case (5): - *fflags |= NO_IGN_ESCAPE | - NO_IGN_MACRO | NO_IGN_CHARS; + *fflags |= FL_STRICT; break; case (6): - *fflags &= ~NO_IGN_ESCAPE; + *fflags &= ~FL_NIGN_ESCAPE; break; default: - fprintf(stderr, "%s: Bad argument", o); + fprintf(stderr, "%s: Bad argument\n", o); return(0); } } @@ -630,7 +650,7 @@ woptions(int *wflags, char *arg) *wflags |= WARN_WERR; break; default: - fprintf(stderr, "%s: Bad argument", o); + fprintf(stderr, "%s: Bad argument\n", o); return(0); } }