=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.24 retrieving revision 1.28 diff -u -p -r1.24 -r1.28 --- mandoc/main.c 2009/04/12 19:19:57 1.24 +++ mandoc/main.c 2009/06/15 10:36:01 1.28 @@ -1,20 +1,18 @@ -/* $Id: main.c,v 1.24 2009/04/12 19:19:57 kristaps Exp $ */ +/* $Id: main.c,v 1.28 2009/06/15 10:36:01 kristaps Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons + * Copyright (c) 2008, 2009 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the - * above copyright notice and this permission notice appear in all - * copies. + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE - * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include @@ -192,6 +190,8 @@ main(int argc, char *argv[]) free(blk.buf); if (ln.buf) free(ln.buf); + + /* TODO: have a curp_free routine. */ if (curp.outfree) (*curp.outfree)(curp.outdata); if (curp.mdoc) @@ -233,8 +233,15 @@ man_init(struct curparse *curp) mancb.man_err = merr; mancb.man_warn = manwarn; - pflags = MAN_IGN_MACRO; /* XXX */ + /* + * Default behaviour is to ignore unknown macros. This is + * specified in mandoc.1. + */ + pflags = MAN_IGN_MACRO; + + /* Override default behaviour... */ + if (curp->fflags & NO_IGN_MACRO) pflags &= ~MAN_IGN_MACRO; @@ -252,12 +259,19 @@ mdoc_init(struct curparse *curp) struct mdoc *mdoc; struct mdoc_cb mdoccb; - mdoccb.mdoc_msg = NULL; mdoccb.mdoc_err = merr; mdoccb.mdoc_warn = mdocwarn; + /* + * Default behaviour is to ignore unknown macros, escape + * sequences and characters (very liberal). This is specified + * in mandoc.1. + */ + pflags = MDOC_IGN_MACRO | MDOC_IGN_ESCAPE | MDOC_IGN_CHARS; + /* Override default behaviour... */ + if (curp->fflags & IGN_SCOPE) pflags |= MDOC_IGN_SCOPE; if (curp->fflags & NO_IGN_ESCAPE) @@ -365,7 +379,7 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse continue; } - /* Check for CPP-escaped newline. */ + /* Check for CPP-escaped newline. */ if (pos > 0 && '\\' == ln->buf[pos - 1]) { for (j = pos - 1; j >= 0; j--) @@ -632,9 +646,10 @@ merr(void *arg, int line, int col, const char *msg) struct curparse *curp; curp = (struct curparse *)arg; - warnx("%s:%d: error: %s (column %d)", curp->file, line, msg, col); + + /* Always exit on errors... */ return(0); } @@ -668,6 +683,11 @@ mdocwarn(void *arg, int line, int col, if ( ! (curp->wflags & WARN_WERR)) return(1); + + /* + * If the -Werror flag is passed in, as in gcc, then all + * warnings are considered as errors. + */ warnx("%s: considering warnings as errors", __progname); @@ -690,6 +710,11 @@ manwarn(void *arg, int line, int col, const char *msg) if ( ! (curp->wflags & WARN_WERR)) return(1); + + /* + * If the -Werror flag is passed in, as in gcc, then all + * warnings are considered as errors. + */ warnx("%s: considering warnings as errors", __progname);