From df927bb6d9e77516bd651a336da98edf7c9a40b2 Mon Sep 17 00:00:00 2001 From: schwarze Date: Thu, 15 Jan 2015 04:26:06 +0000 Subject: [PATCH] Fatal errors no longer exist. If a file can be opened, mandoc will produce some output; at worst, the output may be almost empty. Simplifies error handling and frees a message type for future use. --- usr.bin/mandoc/cgi.c | 14 +++------- usr.bin/mandoc/libmandoc.h | 6 ++--- usr.bin/mandoc/main.c | 11 +++----- usr.bin/mandoc/man.1 | 16 ++++++------ usr.bin/mandoc/man.c | 5 ++-- usr.bin/mandoc/mandoc.1 | 25 +++++++----------- usr.bin/mandoc/mandoc.h | 7 ++--- usr.bin/mandoc/mandocdb.c | 15 +++++------ usr.bin/mandoc/mdoc.c | 5 ++-- usr.bin/mandoc/read.c | 53 +++++++++----------------------------- 10 files changed, 51 insertions(+), 106 deletions(-) diff --git a/usr.bin/mandoc/cgi.c b/usr.bin/mandoc/cgi.c index e80d895d9a0..e12f7677328 100644 --- a/usr.bin/mandoc/cgi.c +++ b/usr.bin/mandoc/cgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cgi.c,v 1.41 2014/11/26 00:57:32 schwarze Exp $ */ +/* $OpenBSD: cgi.c,v 1.42 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -820,7 +820,6 @@ format(const struct req *req, const char *file) struct man *man; void *vp; char *opts; - enum mandoclevel rc; int fd; int usepath; @@ -830,18 +829,11 @@ format(const struct req *req, const char *file) } mchars = mchars_alloc(); - mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_FATAL, NULL, + mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_BADARG, NULL, mchars, req->q.manpath); - rc = mparse_readfd(mp, fd, file); + mparse_readfd(mp, fd, file); close(fd); - if (rc >= MANDOCLEVEL_FATAL) { - fprintf(stderr, "fatal mandoc error: %s/%s\n", - req->q.manpath, file); - pg_error_internal(); - return; - } - usepath = strcmp(req->q.manpath, req->p[0]); mandoc_asprintf(&opts, "fragment,man=%s?query=%%N&sec=%%S%s%s%s%s", diff --git a/usr.bin/mandoc/libmandoc.h b/usr.bin/mandoc/libmandoc.h index 84a55c31bc3..d01454c643c 100644 --- a/usr.bin/mandoc/libmandoc.h +++ b/usr.bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libmandoc.h,v 1.40 2015/01/14 22:57:57 schwarze Exp $ */ +/* $OpenBSD: libmandoc.h,v 1.41 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -57,7 +57,7 @@ struct mdoc *mdoc_alloc(struct roff *, struct mparse *, const char *, int); void mdoc_reset(struct mdoc *); int mdoc_parseln(struct mdoc *, int, char *, int); -int mdoc_endparse(struct mdoc *); +void mdoc_endparse(struct mdoc *); void mdoc_addspan(struct mdoc *, const struct tbl_span *); void mdoc_addeqn(struct mdoc *, const struct eqn *); @@ -66,7 +66,7 @@ struct man *man_alloc(struct roff *, struct mparse *, const char *, int); void man_reset(struct man *); int man_parseln(struct man *, int, char *, int); -int man_endparse(struct man *); +void man_endparse(struct man *); void man_addspan(struct man *, const struct tbl_span *); void man_addeqn(struct man *, const struct eqn *); diff --git a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c index 6631b905724..c19fd36527a 100644 --- a/usr.bin/mandoc/main.c +++ b/usr.bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.120 2015/01/14 21:27:01 schwarze Exp $ */ +/* $OpenBSD: main.c,v 1.121 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -158,7 +158,7 @@ main(int argc, char *argv[]) memset(&curp, 0, sizeof(struct curparse)); curp.outtype = OUTT_LOCALE; - curp.wlevel = MANDOCLEVEL_FATAL; + curp.wlevel = MANDOCLEVEL_BADARG; options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1; defos = NULL; @@ -600,11 +600,6 @@ parse(struct curparse *curp, int fd, const char *file, rc = mparse_readfd(curp->mp, fd, file); - /* Stop immediately if the parse has failed. */ - - if (MANDOCLEVEL_FATAL <= rc) - goto cleanup; - /* * With -Wstop and warnings or errors of at least the requested * level, do not produce output. @@ -864,7 +859,7 @@ woptions(struct curparse *curp, char *arg) curp->wlevel = MANDOCLEVEL_ERROR; break; case 4: - curp->wlevel = MANDOCLEVEL_FATAL; + curp->wlevel = MANDOCLEVEL_BADARG; break; default: fprintf(stderr, "%s: -W %s: Bad argument\n", diff --git a/usr.bin/mandoc/man.1 b/usr.bin/mandoc/man.1 index b27ebbdd4de..654ee65ba2a 100644 --- a/usr.bin/mandoc/man.1 +++ b/usr.bin/mandoc/man.1 @@ -1,9 +1,9 @@ -.\" $OpenBSD: man.1,v 1.8 2014/12/28 14:39:08 schwarze Exp $ +.\" $OpenBSD: man.1,v 1.9 2015/01/15 04:26:06 schwarze Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. .\" Copyright (c) 2003, 2007, 2008, 2014 Jason McIntyre -.\" Copyright (c) 2010, 2011 Ingo Schwarze +.\" Copyright (c) 2010, 2011, 2014, 2015 Ingo Schwarze .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -31,7 +31,7 @@ .\" .\" @(#)man.1 8.2 (Berkeley) 1/2/94 .\" -.Dd $Mdocdate: December 28 2014 $ +.Dd $Mdocdate: January 15 2015 $ .Dt MAN 1 .Os .Sh NAME @@ -300,15 +300,15 @@ to be reported on the standard error output and to affect the exit status. The .Ar level can be -.Cm warning , -.Cm error , +.Cm warning or -.Cm fatal . -The default is -.Cm fatal ; +.Cm error ; .Cm all is an alias for .Cm warning . +By default, +.Nm +is silent. See the .Xr mandoc 1 manual for details. diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index c3a5dc8103b..29e57e56fd9 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man.c,v 1.94 2014/12/28 14:39:08 schwarze Exp $ */ +/* $OpenBSD: man.c,v 1.95 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -107,12 +107,11 @@ man_alloc(struct roff *roff, struct mparse *parse, return(p); } -int +void man_endparse(struct man *man) { man_macroend(man); - return(1); } int diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 266f40cf5bc..97899117fa2 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.71 2015/01/14 22:02:00 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.72 2015/01/15 04:26:06 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2012, 2014, 2015 Ingo Schwarze @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 14 2015 $ +.Dd $Mdocdate: January 15 2015 $ .Dt MANDOC 1 .Os .Sh NAME @@ -159,15 +159,15 @@ to be reported on the standard error output and to affect the exit status. The .Ar level can be -.Cm warning , -.Cm error , +.Cm warning or -.Cm fatal . -The default is -.Fl W Ns Cm fatal ; -.Fl W Ns Cm all +.Cm error ; +.Cm all is an alias for -.Fl W Ns Cm warning . +.Cm warning . +By default, +.Nm +is silent. See .Sx EXIT STATUS and @@ -532,13 +532,11 @@ At least one warning occurred, but no error, and .Fl W Ns Cm warning was specified. .It 3 -At least one parsing error occurred, but no fatal error, and +At least one parsing error occurred, and .Fl W Ns Cm error or .Fl W Ns Cm warning was specified. -.It 4 -A fatal parsing error occurred. .It 5 Invalid command line arguments were specified. No input files have been read. @@ -603,9 +601,6 @@ fields. .Pp Message levels have the following meanings: .Bl -tag -width "warning" -.It Cm fatal -The parser is unable to parse a given input file at all. -No formatted output is produced from that input file. .It Cm error An input file contains syntax that cannot be safely interpreted, either because it is invalid or because diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index e289c539922..5d5fb015317 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.123 2015/01/15 02:29:07 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.124 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -148,6 +148,7 @@ enum mandocerr { /* related to document structure and macros */ MANDOCERR_FILE, /* cannot open file */ + MANDOCERR_TOOLARGE, /* input too large */ MANDOCERR_ROFFLOOP, /* input stack limit exceeded, infinite loop? */ MANDOCERR_BADCHAR, /* skipping bad character: number */ MANDOCERR_MACRO, /* skipping unknown macro: macro */ @@ -172,10 +173,6 @@ enum mandocerr { MANDOCERR_ARG_EXCESS, /* skipping excess arguments: macro ... args */ MANDOCERR_DIVZERO, /* divide by zero */ - MANDOCERR_FATAL, /* ===== start of fatal errors ===== */ - - MANDOCERR_TOOLARGE, /* input too large */ - MANDOCERR_MAX }; diff --git a/usr.bin/mandoc/mandocdb.c b/usr.bin/mandoc/mandocdb.c index 560e259530d..d9c3f0a486d 100644 --- a/usr.bin/mandoc/mandocdb.c +++ b/usr.bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mandocdb.c,v 1.136 2015/01/03 12:54:49 schwarze Exp $ */ +/* $OpenBSD: mandocdb.c,v 1.137 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2015 Ingo Schwarze @@ -432,7 +432,7 @@ mandocdb(int argc, char *argv[]) exitcode = (int)MANDOCLEVEL_OK; mchars = mchars_alloc(); - mp = mparse_alloc(mparse_options, MANDOCLEVEL_FATAL, NULL, + mp = mparse_alloc(mparse_options, MANDOCLEVEL_BADARG, NULL, mchars, NULL); ohash_init(&mpages, 6, &mpages_info); ohash_init(&mlinks, 6, &mlinks_info); @@ -1092,7 +1092,6 @@ mpages_merge(struct mparse *mp) char *cp; int fd; unsigned int pslot; - enum mandoclevel lvl; str_info.alloc = hash_alloc; str_info.calloc = hash_calloc; @@ -1126,14 +1125,12 @@ mpages_merge(struct mparse *mp) } /* - * Try interpreting the file as mdoc(7) or man(7) - * source code, unless it is already known to be - * formatted. Fall back to formatted mode. + * Interpret the file as mdoc(7) or man(7) source + * code, unless it is known to be formatted. */ if (mlink->dform != FORM_CAT || mlink->fform != FORM_CAT) { - lvl = mparse_readfd(mp, fd, mlink->file); - if (lvl < MANDOCLEVEL_FATAL) - mparse_result(mp, &mdoc, &man, &sodest); + mparse_readfd(mp, fd, mlink->file); + mparse_result(mp, &mdoc, &man, &sodest); } if (sodest != NULL) { diff --git a/usr.bin/mandoc/mdoc.c b/usr.bin/mandoc/mdoc.c index b2b1b8951bb..035f639cd40 100644 --- a/usr.bin/mandoc/mdoc.c +++ b/usr.bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc.c,v 1.122 2014/11/28 06:26:46 schwarze Exp $ */ +/* $OpenBSD: mdoc.c,v 1.123 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze @@ -188,12 +188,11 @@ mdoc_alloc(struct roff *roff, struct mparse *parse, return(p); } -int +void mdoc_endparse(struct mdoc *mdoc) { mdoc_macroend(mdoc); - return(1); } void diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 7c470169ded..a38cb5f7916 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.85 2015/01/15 02:29:07 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.86 2015/01/15 04:26:06 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2015 Ingo Schwarze @@ -75,7 +75,7 @@ static const enum mandocerr mandoclimits[MANDOCLEVEL_MAX] = { MANDOCERR_WARNING, MANDOCERR_WARNING, MANDOCERR_ERROR, - MANDOCERR_FATAL, + MANDOCERR_MAX, MANDOCERR_MAX, MANDOCERR_MAX }; @@ -187,6 +187,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { /* related to document structure and macros */ NULL, + "input too large", "input stack limit exceeded, infinite loop?", "skipping bad character", "skipping unknown macro", @@ -210,10 +211,6 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "skipping all arguments", "skipping excess arguments", "divide by zero", - - "generic fatal error", - - "input too large", }; static const char * const mandoclevels[MANDOCLEVEL_MAX] = { @@ -539,14 +536,6 @@ rerun: break; } - /* - * If we encounter errors in the recursive parse, make - * sure we don't continue parsing. - */ - - if (MANDOCLEVEL_FATAL <= curp->file_status) - break; - /* * If input parsers have not been allocated, do so now. * We keep these instanced between parsers, but set them @@ -617,10 +606,7 @@ read_whole_file(struct mparse *curp, const char *file, int fd, if (S_ISREG(st.st_mode)) { if (st.st_size >= (1U << 31)) { - curp->file_status = MANDOCLEVEL_FATAL; - if (curp->mmsg) - (*curp->mmsg)(MANDOCERR_TOOLARGE, - curp->file_status, file, 0, 0, NULL); + mandoc_msg(MANDOCERR_TOOLARGE, curp, 0, 0, NULL); return(0); } *with_mmap = 1; @@ -642,11 +628,8 @@ read_whole_file(struct mparse *curp, const char *file, int fd, for (;;) { if (off == fb->sz) { if (fb->sz == (1U << 31)) { - curp->file_status = MANDOCLEVEL_FATAL; - if (curp->mmsg) - (*curp->mmsg)(MANDOCERR_TOOLARGE, - curp->file_status, - file, 0, 0, NULL); + mandoc_msg(MANDOCERR_TOOLARGE, curp, + 0, 0, NULL); break; } resize_buf(fb, 65536); @@ -672,9 +655,6 @@ static void mparse_end(struct mparse *curp) { - if (MANDOCLEVEL_FATAL <= curp->file_status) - return; - if (curp->mdoc == NULL && curp->man == NULL && curp->sodest == NULL) { @@ -688,17 +668,10 @@ mparse_end(struct mparse *curp) curp->man = curp->pman; } } - - if (curp->mdoc && ! mdoc_endparse(curp->mdoc)) { - assert(MANDOCLEVEL_FATAL <= curp->file_status); - return; - } - - if (curp->man && ! man_endparse(curp->man)) { - assert(MANDOCLEVEL_FATAL <= curp->file_status); - return; - } - + if (curp->mdoc) + mdoc_endparse(curp->mdoc); + if (curp->man) + man_endparse(curp->man); roff_endparse(curp->roff); } @@ -735,7 +708,7 @@ mparse_parse_buffer(struct mparse *curp, struct buf blk, const char *file) mparse_buf_r(curp, blk, offset, 1); - if (0 == --recursion_depth && MANDOCLEVEL_FATAL > curp->file_status) + if (--recursion_depth == 0) mparse_end(curp); curp->primary = svprimary; @@ -867,8 +840,6 @@ mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg, { struct mparse *curp; - assert(wlevel <= MANDOCLEVEL_FATAL); - curp = mandoc_calloc(1, sizeof(struct mparse)); curp->options = options; @@ -965,7 +936,7 @@ mandoc_msg(enum mandocerr er, struct mparse *m, { enum mandoclevel level; - level = MANDOCLEVEL_FATAL; + level = MANDOCLEVEL_ERROR; while (er < mandoclimits[level]) level--; -- 2.20.1