From ac1f49d01ceff2a47571d14f0fdc829b542b4eee Mon Sep 17 00:00:00 2001 From: schwarze Date: Fri, 8 Aug 2014 15:21:17 +0000 Subject: [PATCH] Remove two useless FATAL errors. When a file contains neither text nor macros, treat it as an empty document. When the mdoc(7) document prologue is incomplete, use some default values. --- usr.bin/mandoc/mandoc.h | 4 +--- usr.bin/mandoc/mdoc_validate.c | 24 +++++++++++++------- usr.bin/mandoc/read.c | 40 +++++++++++++++++++--------------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 80fd8e69429..8b0ea9bddf1 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.88 2014/08/08 15:15:27 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.89 2014/08/08 15:21:17 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -160,14 +160,12 @@ enum mandocerr { MANDOCERR_FATAL, /* ===== start of fatal errors ===== */ MANDOCERR_TOOLARGE, /* input too large */ - MANDOCERR_NOTMANUAL, /* not a manual */ MANDOCERR_COLUMNS, /* column syntax is inconsistent */ MANDOCERR_BADDISP, /* NOT IMPLEMENTED: .Bd -file */ MANDOCERR_SYNTCHILD, /* child violates parent syntax */ MANDOCERR_SYNTARGCOUNT, /* argument count wrong, violates syntax */ MANDOCERR_SO_PATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */ MANDOCERR_SO_FAIL, /* .so request failed */ - MANDOCERR_NODOCPROLOG, /* no document prologue */ MANDOCERR_MEM, /* static buffer exhausted */ /* ===== system errors ===== */ diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 71d959f7c74..6dc6bda5f79 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.151 2014/08/08 15:15:27 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.152 2014/08/08 15:21:17 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -1679,16 +1679,24 @@ ebool(struct mdoc *mdoc) static int post_root(POST_ARGS) { - int ret; struct mdoc_node *n; - ret = 1; - - /* Check that we have a finished prologue. */ + /* Add missing prologue data. */ if ( ! (MDOC_PBODY & mdoc->flags)) { - ret = 0; - mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG); + mandoc_msg(MANDOCERR_PROLOG_BAD, mdoc->parse, 0, 0, "EOF"); + if (mdoc->meta.date == NULL) + mdoc->meta.date = mdoc->quick ? + mandoc_strdup("") : + mandoc_normdate(mdoc->parse, NULL, 0, 0); + if (mdoc->meta.title == NULL) + mdoc->meta.title = mandoc_strdup("UNKNOWN"); + if (mdoc->meta.vol == NULL) + mdoc->meta.vol = mandoc_strdup("LOCAL"); + if (mdoc->meta.arch == NULL) + mdoc->meta.msec = mandoc_strdup("1"); + if (mdoc->meta.os == NULL) + mdoc->meta.os = mandoc_strdup("UNKNOWN"); } n = mdoc->first; @@ -1703,7 +1711,7 @@ post_root(POST_ARGS) n->child->line, n->child->pos, mdoc_macronames[n->child->tok]); - return(ret); + return(1); } static int diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 2422c2d4f23..c7d67756a51 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.49 2014/08/08 15:15:27 schwarze Exp $ */ +/* $Id: read.c,v 1.50 2014/08/08 15:21:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2014 Ingo Schwarze @@ -196,14 +196,12 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "generic fatal error", "input too large", - "not a manual", "column syntax is inconsistent", "NOT IMPLEMENTED: .Bd -file", "child violates parent syntax", "argument count wrong, violates syntax", "NOT IMPLEMENTED: .so with absolute path or \"..\"", ".so request failed", - "no document prologue", "static buffer exhausted", /* system errors */ @@ -256,18 +254,9 @@ pset(const char *buf, int pos, struct mparse *curp) } if (MPARSE_MDOC & curp->options) { - if (NULL == curp->pmdoc) - curp->pmdoc = mdoc_alloc( - curp->roff, curp, curp->defos, - MPARSE_QUICK & curp->options ? 1 : 0); - assert(curp->pmdoc); curp->mdoc = curp->pmdoc; return; } else if (MPARSE_MAN & curp->options) { - if (NULL == curp->pman) - curp->pman = man_alloc(curp->roff, curp, - MPARSE_QUICK & curp->options ? 1 : 0); - assert(curp->pman); curp->man = curp->pman; return; } @@ -673,6 +662,19 @@ mparse_end(struct mparse *curp) if (MANDOCLEVEL_FATAL <= curp->file_status) return; + if (curp->mdoc == NULL && + curp->man == NULL && + curp->sodest == NULL) { + if (curp->options & MPARSE_MDOC) + curp->mdoc = curp->pmdoc; + else { + if (curp->pman == NULL) + curp->pman = man_alloc(curp->roff, curp, + curp->options & MPARSE_QUICK ? 1 : 0); + curp->man = curp->pman; + } + } + if (curp->mdoc && ! mdoc_endparse(curp->mdoc)) { assert(MANDOCLEVEL_FATAL <= curp->file_status); return; @@ -683,12 +685,6 @@ mparse_end(struct mparse *curp) return; } - if ( ! (curp->mdoc || curp->man || curp->sodest)) { - mandoc_msg(MANDOCERR_NOTMANUAL, curp, 0, 0, NULL); - curp->file_status = MANDOCLEVEL_FATAL; - return; - } - roff_endparse(curp->roff); } @@ -771,6 +767,14 @@ mparse_alloc(int options, enum mandoclevel wlevel, curp->defos = defos; curp->roff = roff_alloc(curp, options); + if (curp->options & MPARSE_MDOC) + curp->pmdoc = mdoc_alloc( + curp->roff, curp, curp->defos, + curp->options & MPARSE_QUICK ? 1 : 0); + if (curp->options & MPARSE_MAN) + curp->pman = man_alloc(curp->roff, curp, + curp->options & MPARSE_QUICK ? 1 : 0); + return(curp); } -- 2.20.1