summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/mdoc_validate.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2009-06-18 20:59:50 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2009-06-18 20:59:50 +0000
commit2d49899ff2bfce3628bef190f23bacd2c82c2ed8 (patch)
treebde099e10bc5c6bef007ee42bf18bf815f3ae1d4 /usr.bin/mandoc/mdoc_validate.c
parent8e9d054b4bbc6e3c9b88c6f76bbd48fa0e5cb64a (diff)
sync to 1.7.16: use dedicated warning types for list validation
instead of hand-rolled warnings
Diffstat (limited to 'usr.bin/mandoc/mdoc_validate.c')
-rw-r--r--usr.bin/mandoc/mdoc_validate.c95
1 files changed, 62 insertions, 33 deletions
diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c
index ca8913e0bb7..a576afcea3d 100644
--- a/usr.bin/mandoc/mdoc_validate.c
+++ b/usr.bin/mandoc/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.4 2009/06/18 01:19:02 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.5 2009/06/18 20:59:49 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -50,7 +50,10 @@ enum merr {
enum mwarn {
WPRINT,
+ WNOWIDTH,
+ WMISSWIDTH,
WESCAPE,
+ WDEPCOL,
WWRONGMSEC,
WSECOOO,
WSECREP,
@@ -435,9 +438,6 @@ pwarn(struct mdoc *m, int line, int pos, enum mwarn type)
c = WARN_SYNTAX;
p = NULL;
switch (type) {
- case (WPRINT):
- p = "invalid character";
- break;
case (WBADMSEC):
p = "inappropriate manual section";
c = WARN_COMPAT;
@@ -458,6 +458,19 @@ pwarn(struct mdoc *m, int line, int pos, enum mwarn type)
p = "prologue macros out-of-order";
c = WARN_COMPAT;
break;
+ case (WDEPCOL):
+ p = "deprecated column argument syntax";
+ c = WARN_COMPAT;
+ break;
+ case (WNOWIDTH):
+ p = "superfluous width argument";
+ break;
+ case (WMISSWIDTH):
+ p = "missing width argument";
+ break;
+ case (WPRINT):
+ p = "invalid character";
+ break;
case (WESCAPE):
p = "invalid escape sequence";
break;
@@ -771,7 +784,7 @@ pre_display(PRE_ARGS)
static int
pre_bl(PRE_ARGS)
{
- int i, type, width, offset;
+ int pos, col, type, width, offset;
if (MDOC_BLOCK != n->type)
return(1);
@@ -780,11 +793,11 @@ pre_bl(PRE_ARGS)
/* Make sure that only one type of list is specified. */
- type = offset = width = -1;
+ type = offset = width = col = -1;
/* LINTED */
- for (i = 0; i < (int)n->args->argc; i++)
- switch (n->args->argv[i].arg) {
+ for (pos = 0; pos < (int)n->args->argc; pos++)
+ switch (n->args->argv[pos].arg) {
case (MDOC_Bullet):
/* FALLTHROUGH */
case (MDOC_Dash):
@@ -806,23 +819,21 @@ pre_bl(PRE_ARGS)
case (MDOC_Inset):
/* FALLTHROUGH */
case (MDOC_Column):
- if (-1 == type) {
- type = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EMULTILIST));
+ if (-1 != type)
+ return(nerr(mdoc, n, EMULTILIST));
+ type = n->args->argv[pos].arg;
+ col = pos;
+ break;
case (MDOC_Width):
- if (-1 == width) {
- width = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EARGREP));
+ if (-1 != width)
+ return(nerr(mdoc, n, EARGREP));
+ width = n->args->argv[pos].arg;
+ break;
case (MDOC_Offset):
- if (-1 == offset) {
- offset = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EARGREP));
+ if (-1 != offset)
+ return(nerr(mdoc, n, EARGREP));
+ offset = n->args->argv[pos].arg;
+ break;
default:
break;
}
@@ -830,7 +841,17 @@ pre_bl(PRE_ARGS)
if (-1 == type)
return(nerr(mdoc, n, ELISTTYPE));
+ /*
+ * Validate the width field. Some list types don't need width
+ * types and should be warned about them. Others should have it
+ * and must also be warned.
+ */
+
switch (type) {
+ case (MDOC_Tag):
+ if (-1 == width && ! nwarn(mdoc, n, WMISSWIDTH))
+ return(0);
+ break;
case (MDOC_Column):
/* FALLTHROUGH */
case (MDOC_Diag):
@@ -838,17 +859,25 @@ pre_bl(PRE_ARGS)
case (MDOC_Inset):
/* FALLTHROUGH */
case (MDOC_Item):
- if (-1 == width)
- break;
- return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,
- "superfluous %s argument",
- mdoc_argnames[MDOC_Width]));
- case (MDOC_Tag):
- if (-1 != width)
+ if (-1 != width && ! nwarn(mdoc, n, WNOWIDTH))
+ return(0);
+ break;
+ default:
+ break;
+ }
+
+ /*
+ * General validation of fields.
+ */
+
+ switch (type) {
+ case (MDOC_Column):
+ assert(col >= 0);
+ if (0 == n->args->argv[col].sz)
break;
- return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,
- "suggest %s argument",
- mdoc_argnames[MDOC_Width]));
+ if ( ! nwarn(mdoc, n, WDEPCOL))
+ return(0);
+ break;
default:
break;
}