summaryrefslogtreecommitdiffstats
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
commit37fc9452eae26c51be7df689f984abae6d78ccea (patch)
tree0066a63ed50561d168fdd765aa6669cb3b72c8b9
parentf55f857f8f078275f8f6d914367c3075c9e25022 (diff)
downloadmandoc-37fc9452eae26c51be7df689f984abae6d78ccea.tar.gz
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.c10
-rw-r--r--man.h1
-rw-r--r--man_term.c9
-rw-r--r--man_validate.c10
-rw-r--r--mandoc.112
-rw-r--r--mandoc.h3
-rw-r--r--mdoc_validate.c22
-rw-r--r--read.c5
8 files changed, 42 insertions, 30 deletions
diff --git a/main.c b/main.c
index 00cdfb76..c1e5ba9f 100644
--- a/main.c
+++ b/main.c
@@ -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 fd6b9f91..13fa660f 100644
--- a/man.h
+++ b/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 {
diff --git a/man_term.c b/man_term.c
index e1d9c488..409fd784 100644
--- a/man_term.c
+++ b/man_term.c
@@ -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 0088e6f8..6ebf6cea 100644
--- a/man_validate.c
+++ b/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);
/*
diff --git a/mandoc.1 b/mandoc.1
index ddbcb38a..c8b7aa47 100644
--- a/mandoc.1
+++ b/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 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 27e7bddc..5627d4d8 100644
--- a/mandoc.h
+++ b/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 */
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 0078f8cc..d62dc6cf 100644
--- a/mdoc_validate.c
+++ b/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
diff --git a/read.c b/read.c
index 482af0db..965d354e 100644
--- a/read.c
+++ b/read.c
@@ -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;
}