source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: As suggested by jmc@, only include line and column numbers into
@ 2014-06-20 23:02 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-06-20 23:02 UTC (permalink / raw)
  To: source

Log Message:
-----------
As suggested by jmc@, only include line and column numbers into messages
when they are meaningful, to avoid confusing stuff like this:
$ mandoc /dev/null
mandoc: /dev/null:0:1: FATAL: not a manual
Instead, just say:
mandoc: /dev/null: FATAL: not a manual

Another example this applies to is documents having a prologue,
but lacking a body.  Do not throw a FATAL error for these; instead,
issue a WARNING and show the empty document, in the man(7) case with
the same amount of blank lines as groff does.  Also downgrade mdoc(7)
documents having content before the first .Sh from FATAL to WARNING.

Modified Files:
--------------
    mdocml:
        main.c
        man.h
        man_term.c
        man_validate.c
        mandoc.1
        mandoc.h
        mdoc_validate.c
        read.c

Revision Data
-------------
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.121
retrieving revision 1.122
diff -Lmandoc.h -Lmandoc.h -u -p -r1.121 -r1.122
--- mandoc.h
+++ mandoc.h
@@ -62,6 +62,8 @@ enum	mandocerr {
 
 	/* related to document structure */
 	MANDOCERR_SO, /* .so is fragile, better use ln(1) */
+	MANDOCERR_DOC_EMPTY, /* no document body */
+	MANDOCERR_SEC_BEFORE, /* content before the first section header */
 	MANDOCERR_NAMESECFIRST, /* NAME section must come first */
 	MANDOCERR_BADNAMESEC, /* bad NAME section contents */
 	MANDOCERR_SECOOO, /* sections out of conventional order */
@@ -161,7 +163,6 @@ enum	mandocerr {
 	MANDOCERR_SYNTCHILD, /* child violates parent syntax */
 	MANDOCERR_SYNTARGCOUNT, /* argument count wrong, violates syntax */
 	MANDOCERR_SOPATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */
-	MANDOCERR_NODOCBODY, /* no document body */
 	MANDOCERR_NODOCPROLOG, /* no document prologue */
 	MANDOCERR_MEM, /* static buffer exhausted */
 
Index: main.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -Lmain.c -Lmain.c -u -p -r1.174 -r1.175
--- main.c
+++ main.c
@@ -408,9 +408,13 @@ mmsg(enum mandocerr t, enum mandoclevel 
 		const char *file, int line, int col, const char *msg)
 {
 
-	fprintf(stderr, "%s: %s:%d:%d: %s: %s", progname,
-	    file, line, col + 1,
-	    mparse_strlevel(lvl), mparse_strerror(t));
+	fprintf(stderr, "%s: %s:", progname, file);
+
+	if (line)
+		fprintf(stderr, "%d:%d:", line, col + 1);
+
+	fprintf(stderr, " %s: %s", mparse_strlevel(lvl),
+	    mparse_strerror(t));
 
 	if (msg)
 		fprintf(stderr, ": %s", msg);
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.148
retrieving revision 1.149
diff -Lman_term.c -Lman_term.c -u -p -r1.148 -r1.149
--- man_term.c
+++ man_term.c
@@ -1061,7 +1061,8 @@ print_man_foot(struct termp *p, const vo
 
 	term_fontrepl(p, TERMFONT_NONE);
 
-	term_vspace(p);
+	if (meta->hasbody)
+		term_vspace(p);
 
 	/*
 	 * Temporary, undocumented option to imitate mdoc(7) output.
@@ -1070,8 +1071,10 @@ print_man_foot(struct termp *p, const vo
 	 */
 
 	if ( ! p->mdocstyle) {
-		term_vspace(p);
-		term_vspace(p);
+		if (meta->hasbody) {
+			term_vspace(p);
+			term_vspace(p);
+		}
 		mandoc_asprintf(&title, "%s(%s)",
 		    meta->title, meta->msec);
 	} else if (meta->source) {
Index: mandoc.1
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.1,v
retrieving revision 1.103
retrieving revision 1.104
diff -Lmandoc.1 -Lmandoc.1 -u -p -r1.103 -r1.104
--- mandoc.1
+++ mandoc.1
@@ -498,9 +498,7 @@ parser:
 .Sh DIAGNOSTICS
 Standard error messages reporting parsing errors are prefixed by
 .Pp
-.Sm off
-.D1 Ar file : line : column : \ level :
-.Sm on
+.D1 Nm Ns : Ar file : Ns Ar line : Ns Ar column : level :
 .Pp
 where the fields have the following meanings:
 .Bl -tag -width "column"
@@ -518,6 +516,12 @@ points to the first character of the wor
 The message level, printed in capital letters.
 .El
 .Pp
+The
+.Ar line
+and
+.Ar column
+fields are omitted when meaningless.
+.Pp
 Message levels have the following meanings:
 .Bl -tag -width "warning"
 .It Cm fatal
@@ -557,7 +561,7 @@ The
 utility may also print messages related to invalid command line arguments
 or operating system errors, for example when memory is exhausted or
 input files cannot be read.
-Such messages do not carry the prefix described above.
+Such messages may not carry the prefix described above.
 .Sh COMPATIBILITY
 This section summarises
 .Nm
Index: man.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -Lman.h -Lman.h -u -p -r1.64 -r1.65
--- man.h
+++ man.h
@@ -79,6 +79,7 @@ struct	man_meta {
 	char		*vol; /* `TH' volume */
 	char		*title; /* `TH' title (e.g., FOO) */
 	char		*source; /* `TH' source (e.g., GNU) */
+	int		 hasbody; /* document is not empty */
 };
 
 struct	man_node {
Index: mdoc_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_validate.c,v
retrieving revision 1.215
retrieving revision 1.216
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.215 -r1.216
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -1645,15 +1645,15 @@ ebool(struct mdoc *mdoc)
 static int
 post_root(POST_ARGS)
 {
-	int		  erc;
+	int		  ret;
 	struct mdoc_node *n;
 
-	erc = 0;
+	ret = 1;
 
 	/* Check that we have a finished prologue. */
 
 	if ( ! (MDOC_PBODY & mdoc->flags)) {
-		erc++;
+		ret = 0;
 		mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG);
 	}
 
@@ -1662,17 +1662,13 @@ post_root(POST_ARGS)
 
 	/* Check that we begin with a proper `Sh'. */
 
-	if (NULL == n->child) {
-		erc++;
-		mdoc_nmsg(mdoc, n, MANDOCERR_NODOCBODY);
-	} else if (MDOC_BLOCK != n->child->type ||
-	    MDOC_Sh != n->child->tok) {
-		erc++;
-		/* Can this be lifted?  See rxdebug.1 for example. */
-		mdoc_nmsg(mdoc, n, MANDOCERR_NODOCBODY);
-	}
+	if (NULL == n->child)
+		mdoc_nmsg(mdoc, n, MANDOCERR_DOC_EMPTY);
+	else if (MDOC_BLOCK != n->child->type ||
+	    MDOC_Sh != n->child->tok)
+		mdoc_nmsg(mdoc, n->child, MANDOCERR_SEC_BEFORE);
 
-	return(erc ? 0 : 1);
+	return(ret);
 }
 
 static int
Index: man_validate.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_validate.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -Lman_validate.c -Lman_validate.c -u -p -r1.92 -r1.93
--- man_validate.c
+++ man_validate.c
@@ -198,10 +198,12 @@ check_root(CHKARGS)
 	man->flags &= ~MAN_BLINE;
 	man->flags &= ~MAN_ELINE;
 
-	if (NULL == man->first->child) {
-		man_nmsg(man, n, MANDOCERR_NODOCBODY);
-		return(0);
-	} else if (NULL == man->meta.title) {
+	if (NULL == man->first->child)
+		man_nmsg(man, n, MANDOCERR_DOC_EMPTY);
+	else
+		man->meta.hasbody = 1;
+
+	if (NULL == man->meta.title) {
 		man_nmsg(man, n, MANDOCERR_TH_MISSING);
 
 		/*
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -Lread.c -Lread.c -u -p -r1.49 -r1.50
--- read.c
+++ read.c
@@ -106,6 +106,8 @@ static	const char * const	mandocerrs[MAN
 
 	/* related to document structure */
 	".so is fragile, better use ln(1)",
+	"no document body",
+	"content before the first section header",
 	"NAME section must come first",
 	"bad NAME section contents",
 	"sections out of conventional order",
@@ -204,7 +206,6 @@ static	const char * const	mandocerrs[MAN
 	"child violates parent syntax",
 	"argument count wrong, violates syntax",
 	"NOT IMPLEMENTED: .so with absolute path or \"..\"",
-	"no document body",
 	"no document prologue",
 	"static buffer exhausted",
 
@@ -684,7 +685,7 @@ mparse_end(struct mparse *curp)
 	}
 
 	if ( ! (curp->mdoc || curp->man || curp->sodest)) {
-		mandoc_msg(MANDOCERR_NOTMANUAL, curp, 1, 0, NULL);
+		mandoc_msg(MANDOCERR_NOTMANUAL, curp, 0, 0, NULL);
 		curp->file_status = MANDOCLEVEL_FATAL;
 		return;
 	}
--
 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-06-20 23:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-20 23:02 mdocml: As suggested by jmc@, only include line and column numbers into 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).