=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -p -r1.38 -r1.39 --- mandoc/main.c 2009/07/07 09:52:08 1.38 +++ mandoc/main.c 2009/07/24 14:00:59 1.39 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.38 2009/07/07 09:52:08 kristaps Exp $ */ +/* $Id: main.c,v 1.39 2009/07/24 14:00:59 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -72,6 +72,7 @@ struct curparse { #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. */ enum intt inttype; /* Input parsers... */ struct man *man; struct man *lastman; @@ -161,13 +162,21 @@ main(int argc, char *argv[]) if (NULL == *argv) { curp.file = ""; curp.fd = STDIN_FILENO; - if ( ! fdesc(&blk, &ln, &curp)) - rc = 0; + + c = fdesc(&blk, &ln, &curp); + if ( ! (IGN_ERRORS & curp.fflags)) + rc = 1 == c ? 1 : 0; + else + rc = -1 == c ? 0 : 1; } while (rc && *argv) { - if ( ! ffile(&blk, &ln, *argv, &curp)) - rc = 0; + c = ffile(&blk, &ln, *argv, &curp); + if ( ! (IGN_ERRORS & curp.fflags)) + rc = 1 == c ? 1 : 0; + else + rc = -1 == c ? 0 : 1; + argv++; if (*argv && rc) { if (curp.lastman) @@ -283,7 +292,7 @@ ffile(struct buf *blk, struct buf *ln, curp->file = file; if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) { warn("%s", curp->file); - return(0); + return(-1); } c = fdesc(blk, ln, curp); @@ -324,7 +333,7 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse blk->buf = realloc(blk->buf, sz); if (NULL == blk->buf) { warn("realloc"); - return(0); + return(-1); } blk->sz = sz; } @@ -334,7 +343,7 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse for (lnn = pos = comment = 0; ; ) { if (-1 == (ssz = read(curp->fd, blk->buf, sz))) { warn("%s", curp->file); - return(0); + return(-1); } else if (0 == ssz) break; @@ -346,7 +355,7 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse ln->buf = realloc(ln->buf, ln->sz); if (NULL == ln->buf) { warn("realloc"); - return(0); + return(-1); } } @@ -393,7 +402,7 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse if ( ! (man || mdoc) && ! pset(ln->buf, pos, curp, &man, &mdoc)) - return(0); + return(-1); pos = comment = 0; @@ -441,10 +450,10 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse if (man && curp->outman) if ( ! (*curp->outman)(curp->outdata, man)) - return(0); + return(-1); if (mdoc && curp->outmdoc) if ( ! (*curp->outmdoc)(curp->outdata, mdoc)) - return(0); + return(-1); return(1); } @@ -551,14 +560,15 @@ static int foptions(int *fflags, char *arg) { char *v, *o; - char *toks[6]; + char *toks[7]; toks[0] = "ign-scope"; toks[1] = "no-ign-escape"; toks[2] = "no-ign-macro"; toks[3] = "no-ign-chars"; - toks[4] = "strict"; - toks[5] = NULL; + toks[4] = "ign-errors"; + toks[5] = "strict"; + toks[6] = NULL; while (*arg) { o = arg; @@ -576,6 +586,9 @@ foptions(int *fflags, char *arg) *fflags |= NO_IGN_CHARS; break; case (4): + *fflags |= IGN_ERRORS; + break; + case (5): *fflags |= NO_IGN_ESCAPE | NO_IGN_MACRO | NO_IGN_CHARS; break;