aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-06-20 23:02:31 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-06-20 23:02:31 +0000
commitb4c01f5c60dab8debad192bef6f9db1c465255b9 (patch)
treee78d628565794d197118e581bb2357acd6ba5f4f
parentb3b89a43d7165af5fd4fe84f88cdeef6cb5ee1aa (diff)
downloadmandoc-b4c01f5c60dab8debad192bef6f9db1c465255b9.tar.gz
mandoc-b4c01f5c60dab8debad192bef6f9db1c465255b9.tar.zst
mandoc-b4c01f5c60dab8debad192bef6f9db1c465255b9.zip
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.
-rw-r--r--main.c12
-rw-r--r--man.h3
-rw-r--r--man_term.c11
-rw-r--r--man_validate.c12
-rw-r--r--mandoc.116
-rw-r--r--mandoc.h5
-rw-r--r--mdoc_validate.c24
-rw-r--r--read.c7
8 files changed, 51 insertions, 39 deletions
diff --git a/main.c b/main.c
index c1497761..f7f107a1 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.174 2014/06/20 16:11:42 schwarze Exp $ */
+/* $Id: main.c,v 1.175 2014/06/20 23:02:31 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -408,9 +408,13 @@ mmsg(enum mandocerr t, enum mandoclevel lvl,
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);
diff --git a/man.h b/man.h
index 26c2747b..aa80b673 100644
--- a/man.h
+++ b/man.h
@@ -1,4 +1,4 @@
-/* $Id: man.h,v 1.64 2014/03/30 19:47:48 schwarze Exp $ */
+/* $Id: man.h,v 1.65 2014/06/20 23:02:31 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 {
diff --git a/man_term.c b/man_term.c
index e308f6a3..c91c0746 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.148 2014/04/23 16:08:33 schwarze Exp $ */
+/* $Id: man_term.c,v 1.149 2014/06/20 23:02:31 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1061,7 +1061,8 @@ print_man_foot(struct termp *p, const void *arg)
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 void *arg)
*/
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) {
diff --git a/man_validate.c b/man_validate.c
index 15c34e08..8e786842 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -1,4 +1,4 @@
-/* $Id: man_validate.c,v 1.92 2014/06/20 17:24:00 schwarze Exp $ */
+/* $Id: man_validate.c,v 1.93 2014/06/20 23:02:31 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -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);
/*
diff --git a/mandoc.1 b/mandoc.1
index 0657bc66..cb800e04 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,4 +1,4 @@
-.\" $Id: mandoc.1,v 1.103 2013/07/13 19:41:16 schwarze Exp $
+.\" $Id: mandoc.1,v 1.104 2014/06/20 23:02:31 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2012 Ingo Schwarze <schwarze@openbsd.org>
@@ -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: July 13 2013 $
+.Dd $Mdocdate: June 20 2014 $
.Dt MANDOC 1
.Os
.Sh NAME
@@ -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 word.
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
diff --git a/mandoc.h b/mandoc.h
index 12cc9919..3f4ea86a 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.121 2014/06/20 17:24:00 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.122 2014/06/20 23:02:31 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -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 */
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 6e8ef19b..bb7025b9 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.215 2014/06/20 17:24:00 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.216 2014/06/20 23:02:31 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -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
diff --git a/read.c b/read.c
index 3c68b42d..b47c5e10 100644
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.49 2014/06/20 17:24:00 schwarze Exp $ */
+/* $Id: read.c,v 1.50 2014/06/20 23:02:31 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -106,6 +106,8 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
/* 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[MANDOCERR_MAX] = {
"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;
}