source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Remove two useless FATAL errors.
@ 2014-07-30 14:50 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-07-30 14:50 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        mandoc.h
        mdoc_validate.c
        read.c

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.233
retrieving revision 1.234
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.233 -r1.234
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -1683,16 +1683,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;
@@ -1707,7 +1715,7 @@ post_root(POST_ARGS)
 		    n->child->line, n->child->pos,
 		    mdoc_macronames[n->child->tok]);
 
-	return(ret);
+	return(1);
 }
 
 static int
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.144
retrieving revision 1.145
diff -Lmandoc.h -Lmandoc.h -u -p -r1.144 -r1.145
--- mandoc.h
+++ mandoc.h
@@ -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 ===== */
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -Lread.c -Lread.c -u -p -r1.71 -r1.72
--- read.c
+++ read.c
@@ -204,14 +204,12 @@ static	const char * const	mandocerrs[MAN
 	"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 */
@@ -264,18 +262,9 @@ pset(const char *buf, int pos, struct mp
 	}
 
 	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;
 	}
@@ -683,6 +672,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;
@@ -693,12 +695,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);
 }
 
@@ -796,6 +792,14 @@ mparse_alloc(int options, enum mandoclev
 	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);
 }
 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-07-30 14:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-30 14:50 mdocml: Remove two useless FATAL errors schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).