aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-02-06 11:54:36 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-02-06 11:54:36 +0000
commit70a62057d81d665dae089691140a2714bd510348 (patch)
treeb185288c4c94bfce1a688ffe35c19fe8813d2099
parent21757403990ffaeb488a62351a28bc9c74eef267 (diff)
downloadmandoc-70a62057d81d665dae089691140a2714bd510348.tar.gz
mandoc-70a62057d81d665dae089691140a2714bd510348.tar.zst
mandoc-70a62057d81d665dae089691140a2714bd510348.zip
better error reporting regarding .OP .RS .UR .TH arguments
-rw-r--r--man_macro.c28
-rw-r--r--man_validate.c43
-rw-r--r--mandoc.159
-rw-r--r--mandoc.h4
-rw-r--r--read.c4
5 files changed, 80 insertions, 58 deletions
diff --git a/man_macro.c b/man_macro.c
index 96f3f581..c86ab6f1 100644
--- a/man_macro.c
+++ b/man_macro.c
@@ -1,4 +1,4 @@
-/* $Id: man_macro.c,v 1.97 2015/02/06 09:38:43 schwarze Exp $ */
+/* $Id: man_macro.c,v 1.98 2015/02/06 11:54:36 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012, 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -337,31 +337,25 @@ blk_close(MACRO_PROT_ARGS)
void
blk_exp(MACRO_PROT_ARGS)
{
- struct man_node *n;
- int la;
+ struct man_node *head;
char *p;
+ int la;
rew_scope(MAN_BLOCK, man, tok);
man_block_alloc(man, line, ppos, tok);
man_head_alloc(man, line, ppos, tok);
+ head = man->last;
- for (;;) {
- la = *pos;
- if ( ! man_args(man, line, pos, buf, &p))
- break;
+ la = *pos;
+ if (man_args(man, line, pos, buf, &p))
man_word_alloc(man, line, la, p);
- }
-
- assert(man);
- assert(tok != MAN_MAX);
- for (n = man->last; n; n = n->parent)
- if (n->tok == tok) {
- assert(n->type == MAN_HEAD);
- man_unscope(man, n);
- break;
- }
+ if (buf[*pos] != '\0')
+ mandoc_vmsg(MANDOCERR_ARG_EXCESS,
+ man->parse, line, *pos, "%s ... %s",
+ man_macronames[tok], buf + *pos);
+ man_unscope(man, head);
man_body_alloc(man, line, ppos, tok);
}
diff --git a/man_validate.c b/man_validate.c
index 4a4c3560..93ee9b3f 100644
--- a/man_validate.c
+++ b/man_validate.c
@@ -1,7 +1,7 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -38,8 +38,6 @@
typedef void (*v_check)(CHKARGS);
-static void check_eq2(CHKARGS);
-static void check_le5(CHKARGS);
static void check_par(CHKARGS);
static void check_part(CHKARGS);
static void check_root(CHKARGS);
@@ -51,6 +49,7 @@ static void post_vs(CHKARGS);
static void post_fi(CHKARGS);
static void post_ft(CHKARGS);
static void post_nf(CHKARGS);
+static void post_OP(CHKARGS);
static void post_TH(CHKARGS);
static void post_UC(CHKARGS);
static void post_UR(CHKARGS);
@@ -88,7 +87,7 @@ static v_check man_valids[MAN_MAX] = {
post_AT, /* AT */
NULL, /* in */
post_ft, /* ft */
- check_eq2, /* OP */
+ post_OP, /* OP */
post_nf, /* EX */
post_fi, /* EE */
post_UR, /* UR */
@@ -169,27 +168,27 @@ check_text(CHKARGS)
n->line, n->pos + (p - cp), NULL);
}
-#define INEQ_DEFINE(x, ineq, name) \
-static void \
-check_##name(CHKARGS) \
-{ \
- if (n->nchild ineq (x)) \
- return; \
- mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \
- "line arguments %s %d (have %d)", \
- #ineq, (x), n->nchild); \
-}
+static void
+post_OP(CHKARGS)
+{
-INEQ_DEFINE(2, ==, eq2)
-INEQ_DEFINE(5, <=, le5)
+ if (n->nchild == 0)
+ mandoc_msg(MANDOCERR_OP_EMPTY, man->parse,
+ n->line, n->pos, "OP");
+ else if (n->nchild > 2) {
+ n = n->child->next->next;
+ mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse,
+ n->line, n->pos, "OP ... %s", n->string);
+ }
+}
static void
post_UR(CHKARGS)
{
- if (MAN_HEAD == n->type && 1 != n->nchild)
- mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,
- n->pos, "line arguments eq 1 (have %d)", n->nchild);
+ if (n->type == MAN_HEAD && n->child == NULL)
+ mandoc_vmsg(MANDOCERR_UR_NOHEAD, man->parse,
+ n->line, n->pos, "UR");
check_part(man, n);
}
@@ -303,8 +302,6 @@ post_TH(CHKARGS)
struct man_node *nb;
const char *p;
- check_le5(man, n);
-
free(man->meta.title);
free(man->meta.vol);
free(man->meta.source);
@@ -382,6 +379,10 @@ post_TH(CHKARGS)
(NULL != (p = mandoc_a2msec(man->meta.msec))))
man->meta.vol = mandoc_strdup(p);
+ if (n != NULL && (n = n->next) != NULL)
+ mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse,
+ n->line, n->pos, "TH ... %s", n->string);
+
/*
* Remove the `TH' node after we've processed it for our
* meta-data.
diff --git a/mandoc.1 b/mandoc.1
index 19964788..7f08e5a3 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -1,4 +1,4 @@
-.\" $Id: mandoc.1,v 1.149 2015/02/06 09:38:43 schwarze Exp $
+.\" $Id: mandoc.1,v 1.150 2015/02/06 11:54:36 schwarze Exp $
.\"
.\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
.\" Copyright (c) 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -1125,6 +1125,18 @@ The
utility assumes
.Fl std
even when it is not specified, but other implementations may not.
+.It Sy "missing option string, using \(dq\(dq"
+.Pq man
+The
+.Ic \&OP
+macro is invoked without any argument.
+An empty pair of square brackets is shown.
+.It Sy "missing resource identifier, using \(dq\(dq"
+.Pq man
+The
+.Ic \&UR
+macro is invoked without any argument.
+An empty pair of angle brackets is shown.
.It Sy "missing eqn box, using \(dq\(dq"
.Pq eqn
A diacritic mark or a binary operator is found,
@@ -1645,30 +1657,41 @@ block closing request is invoked with at least one argument.
All arguments are ignored.
.It Sy "skipping excess arguments"
.Pq mdoc , man , roff
-The
+A macro or request is invoked with too many arguments:
+.Bl -dash -offset 2n -width 2n -compact
+.It
+.Ic \&Fo ,
+.Ic \&PD ,
+.Ic \&RS ,
+.Ic \&UR ,
+.Ic \&ft ,
+or
+.Ic \&sp
+with more than one argument
+.It
.Ic \&An
-macro is invoked with another argument after
+with another argument after
.Fl split
or
-.Fl nosplit ,
-.Ic \&Fo
-is invoked with more than one argument,
+.Fl nosplit
+.It
+.Ic \&RE
+with more than one argument or with a non-integer argument
+.It
+.Ic \&OP
+or a request of the
+.Ic \&de
+family with more than two arguments
+.It
+.Ic \&TH
+with more than five arguments
+.It
.Ic \&Bd ,
.Ic \&Bk ,
or
.Ic \&Bl
-are invoked with invalid arguments, the
-.Ic \&RE
-macro is invoked with more than one argument
-or with a non-integer argument, the
-.Ic \&PD
-macro or the
-.Ic \&ft
-or
-.Ic \&sp
-request is invoked with more than one argument, or a request of the
-.Ic \&de
-family is invoked with more than two arguments.
+with invalid arguments
+.El
The excess arguments are ignored.
.El
.Ss Unsupported features
diff --git a/mandoc.h b/mandoc.h
index 250c5ef2..0b94ed7d 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -1,4 +1,4 @@
-/* $Id: mandoc.h,v 1.198 2015/02/06 07:13:14 schwarze Exp $ */
+/* $Id: mandoc.h,v 1.199 2015/02/06 11:54:36 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -106,6 +106,8 @@ enum mandocerr {
MANDOCERR_PF_SKIP, /* nothing follows prefix: Pf arg */
MANDOCERR_RS_EMPTY, /* empty reference block: Rs */
MANDOCERR_ARG_STD, /* missing -std argument, adding it: macro */
+ MANDOCERR_OP_EMPTY, /* missing option string, using "": OP */
+ MANDOCERR_UR_NOHEAD, /* missing resource identifier, using "": UR */
MANDOCERR_EQN_NOBOX, /* missing eqn box, using "": op */
/* related to bad arguments */
diff --git a/read.c b/read.c
index a52bfb1c..523d0cf5 100644
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/* $Id: read.c,v 1.124 2015/02/06 07:13:14 schwarze Exp $ */
+/* $Id: read.c,v 1.125 2015/02/06 11:54:36 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -150,6 +150,8 @@ static const char * const mandocerrs[MANDOCERR_MAX] = {
"nothing follows prefix",
"empty reference block",
"missing -std argument, adding it",
+ "missing option string, using \"\"",
+ "missing resource identifier, using \"\"",
"missing eqn box, using \"\"",
/* related to bad macro arguments */