=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc_validate.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- src/usr.bin/mandoc/mdoc_validate.c 2009/06/18 01:19:02 1.4 +++ src/usr.bin/mandoc/mdoc_validate.c 2009/06/18 20:59:49 1.5 @@ -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 * @@ -50,7 +50,10 @@ enum mwarn { WPRINT, + WNOWIDTH, + WMISSWIDTH, WESCAPE, + WDEPCOL, WWRONGMSEC, WSECOOO, WSECREP, @@ -435,9 +438,6 @@ 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 @@ 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 @@ 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 @@ /* 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 @@ 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 @@ 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 @@ case (MDOC_Inset): /* FALLTHROUGH */ case (MDOC_Item): - 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, - "superfluous %s argument", - mdoc_argnames[MDOC_Width])); - case (MDOC_Tag): - if (-1 != width) - 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; }