summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2015-02-04 16:38:32 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2015-02-04 16:38:32 +0000
commit203bd5d9c4f0078a07e5c626d95626aaeb40d522 (patch)
treed345ad4b15028cf0f4df3f169daa23833e5e95a2
parent274afcab6cb3e2d96930762c629c3dd152f7a4d3 (diff)
more specific .Nd diagnostics, allowing to get rid of enum check_lvl
and the respective argument of check_count()
-rw-r--r--regress/usr.bin/mandoc/mdoc/Nd/Makefile5
-rw-r--r--regress/usr.bin/mandoc/mdoc/Nd/noarg.out_lint1
-rw-r--r--regress/usr.bin/mandoc/mdoc/Nd/par.in15
-rw-r--r--regress/usr.bin/mandoc/mdoc/Nd/par.out_ascii13
-rw-r--r--usr.bin/mandoc/mandoc.h3
-rw-r--r--usr.bin/mandoc/mdoc_validate.c52
-rw-r--r--usr.bin/mandoc/read.c3
7 files changed, 63 insertions, 29 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Nd/Makefile b/regress/usr.bin/mandoc/mdoc/Nd/Makefile
index 82154800c72..2087e87e2e8 100644
--- a/regress/usr.bin/mandoc/mdoc/Nd/Makefile
+++ b/regress/usr.bin/mandoc/mdoc/Nd/Makefile
@@ -1,5 +1,6 @@
-# $OpenBSD: Makefile,v 1.3 2013/10/06 22:45:13 schwarze Exp $
+# $OpenBSD: Makefile,v 1.4 2015/02/04 16:38:31 schwarze Exp $
-REGRESS_TARGETS = noarg hyph
+REGRESS_TARGETS = hyph noarg par
+LINT_TARGETS = noarg
.include <bsd.regress.mk>
diff --git a/regress/usr.bin/mandoc/mdoc/Nd/noarg.out_lint b/regress/usr.bin/mandoc/mdoc/Nd/noarg.out_lint
new file mode 100644
index 00000000000..04e1d91fdb7
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Nd/noarg.out_lint
@@ -0,0 +1 @@
+mandoc: noarg.in:6:2: WARNING: missing description line, using "": Nd
diff --git a/regress/usr.bin/mandoc/mdoc/Nd/par.in b/regress/usr.bin/mandoc/mdoc/Nd/par.in
new file mode 100644
index 00000000000..b056f754e39
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Nd/par.in
@@ -0,0 +1,15 @@
+.Dd February 3, 2015
+.Dt ND-PAR 1
+.Os OpenBSD
+.Sh NAME
+.Nm Nd-par
+.Nd paragraph macro
+after one-line description
+.Pp
+Usually, there shouldn't be additional text in the NAME section.
+.Sh DESCRIPTION
+The text belongs here.
+.Nd stray
+description macro
+.Pp
+Back to normal state.
diff --git a/regress/usr.bin/mandoc/mdoc/Nd/par.out_ascii b/regress/usr.bin/mandoc/mdoc/Nd/par.out_ascii
new file mode 100644
index 00000000000..c87847b81eb
--- /dev/null
+++ b/regress/usr.bin/mandoc/mdoc/Nd/par.out_ascii
@@ -0,0 +1,13 @@
+ND-PAR(1) General Commands Manual ND-PAR(1)
+
+NNAAMMEE
+ NNdd--ppaarr - paragraph macro after one-line description
+
+ Usually, there shouldn't be additional text in the NAME section.
+
+DDEESSCCRRIIPPTTIIOONN
+ The text belongs here. - stray description macro
+
+ Back to normal state.
+
+OpenBSD February 3, 2015 OpenBSD
diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h
index 71f3f940e87..cd752d11127 100644
--- a/usr.bin/mandoc/mandoc.h
+++ b/usr.bin/mandoc/mandoc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mandoc.h,v 1.136 2015/01/30 17:31:20 schwarze Exp $ */
+/* $OpenBSD: mandoc.h,v 1.137 2015/02/04 16:38:31 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -66,6 +66,7 @@ enum mandocerr {
MANDOCERR_SEC_BEFORE, /* content before first section header: macro */
MANDOCERR_NAMESEC_FIRST, /* first section is not NAME: Sh title */
MANDOCERR_NAMESEC_BAD, /* bad NAME section contents: macro */
+ MANDOCERR_ND_EMPTY, /* missing description line, using "" */
MANDOCERR_SEC_ORDER, /* sections out of conventional order: Sh title */
MANDOCERR_SEC_REP, /* duplicate section title: Sh title */
MANDOCERR_SEC_MSEC, /* unexpected section: Sh title for ... only */
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index 38c8e5fb0f5..772969ce183 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_validate.c,v 1.182 2015/02/03 00:48:27 schwarze Exp $ */
+/* $OpenBSD: mdoc_validate.c,v 1.183 2015/02/04 16:38:31 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -46,11 +46,6 @@ enum check_ineq {
CHECK_EQ
};
-enum check_lvl {
- CHECK_WARN,
- CHECK_ERROR,
-};
-
typedef void (*v_pre)(PRE_ARGS);
typedef void (*v_post)(POST_ARGS);
@@ -60,7 +55,7 @@ struct valids {
};
static void check_count(struct mdoc *, enum mdoc_type,
- enum check_lvl, enum check_ineq, int);
+ enum check_ineq, int);
static void check_text(struct mdoc *, int, int, char *);
static void check_argv(struct mdoc *,
struct mdoc_node *, struct mdoc_argv *);
@@ -372,10 +367,9 @@ mdoc_valid_post(struct mdoc *mdoc)
static void
check_count(struct mdoc *mdoc, enum mdoc_type type,
- enum check_lvl lvl, enum check_ineq ineq, int val)
+ enum check_ineq ineq, int val)
{
const char *p;
- enum mandocerr t;
if (mdoc->last->type != type)
return;
@@ -401,8 +395,7 @@ check_count(struct mdoc *mdoc, enum mdoc_type type,
/* NOTREACHED */
}
- t = lvl == CHECK_WARN ? MANDOCERR_ARGCWARN : MANDOCERR_ARGCOUNT;
- mandoc_vmsg(t, mdoc->parse, mdoc->last->line,
+ mandoc_vmsg(MANDOCERR_ARGCWARN, mdoc->parse, mdoc->last->line,
mdoc->last->pos, "want %s%d children (have %d)",
p, val, mdoc->last->nchild);
}
@@ -410,25 +403,25 @@ check_count(struct mdoc *mdoc, enum mdoc_type type,
static void
bwarn_ge1(POST_ARGS)
{
- check_count(mdoc, MDOC_BODY, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_BODY, CHECK_GT, 0);
}
static void
ewarn_eq1(POST_ARGS)
{
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1);
}
static void
ewarn_ge1(POST_ARGS)
{
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_GT, 0);
}
static void
hwarn_eq0(POST_ARGS)
{
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 0);
+ check_count(mdoc, MDOC_HEAD, CHECK_EQ, 0);
}
static void
@@ -938,7 +931,7 @@ post_lb(POST_ARGS)
struct mdoc_node *n;
char *libname;
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1);
n = mdoc->last->child;
assert(MDOC_TEXT == n->type);
mandoc_asprintf(&libname, "library \\(lq%s\\(rq", n->string);
@@ -986,7 +979,7 @@ static void
post_fo(POST_ARGS)
{
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 1);
+ check_count(mdoc, MDOC_HEAD, CHECK_EQ, 1);
bwarn_ge1(mdoc);
if (mdoc->last->type == MDOC_HEAD && mdoc->last->nchild)
post_fname(mdoc);
@@ -1060,8 +1053,17 @@ post_nm(POST_ARGS)
static void
post_nd(POST_ARGS)
{
+ struct mdoc_node *n;
+
+ n = mdoc->last;
+
+ if (n->type != MDOC_BODY)
+ return;
+
+ if (n->child == NULL)
+ mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse,
+ n->line, n->pos, "Nd");
- check_count(mdoc, MDOC_BODY, CHECK_ERROR, CHECK_GT, 0);
post_hyph(mdoc);
}
@@ -1168,9 +1170,9 @@ post_an(POST_ARGS)
np = mdoc->last;
if (AUTH__NONE == np->norm->An.auth) {
if (0 == np->child)
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_GT, 0);
} else if (np->child)
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0);
}
static void
@@ -1652,12 +1654,12 @@ post_rs(POST_ARGS)
switch (mdoc->last->type) {
case MDOC_HEAD:
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 0);
+ check_count(mdoc, MDOC_HEAD, CHECK_EQ, 0);
return;
case MDOC_BODY:
if (mdoc->last->child)
break;
- check_count(mdoc, MDOC_BODY, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_BODY, CHECK_GT, 0);
return;
default:
return;
@@ -2063,7 +2065,7 @@ post_ignpar(POST_ARGS)
{
struct mdoc_node *np;
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_HEAD, CHECK_GT, 0);
post_hyph(mdoc);
if (MDOC_BODY != mdoc->last->type)
@@ -2126,9 +2128,9 @@ post_par(POST_ARGS)
struct mdoc_node *np;
if (mdoc->last->tok == MDOC_sp)
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_LT, 2);
+ check_count(mdoc, MDOC_ELEM, CHECK_LT, 2);
else
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0);
if (MDOC_ELEM != mdoc->last->type &&
MDOC_BLOCK != mdoc->last->type)
diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c
index 0fdae06fdbc..9282797b95e 100644
--- a/usr.bin/mandoc/read.c
+++ b/usr.bin/mandoc/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.95 2015/01/28 21:10:28 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.96 2015/02/04 16:38:31 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -105,6 +105,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"content before first section header",
"first section is not \"NAME\"",
"bad NAME section contents",
+ "missing description line, using \"\"",
"sections out of conventional order",
"duplicate section title",
"unexpected section",