=================================================================== RCS file: /cvs/mandoc/mdoc_validate.c,v retrieving revision 1.7 retrieving revision 1.11 diff -u -p -r1.7 -r1.11 --- mandoc/mdoc_validate.c 2009/06/10 20:18:43 1.7 +++ mandoc/mdoc_validate.c 2009/06/17 09:41:00 1.11 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.7 2009/06/10 20:18:43 kristaps Exp $ */ +/* $Id: mdoc_validate.c,v 1.11 2009/06/17 09:41:00 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -50,7 +50,11 @@ enum merr { enum mwarn { WPRINT, + WNOWIDTH, + WMISSWIDTH, WESCAPE, + WDEPESC, + WDEPCOL, WWRONGMSEC, WSECOOO, WSECREP, @@ -188,7 +192,7 @@ static v_post posts_bf[] = { hwarn_le1, post_bf, NULL static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL }; const struct valids mdoc_valids[MDOC_MAX] = { - { NULL, NULL }, /* \" */ + { NULL, NULL }, /* Ap */ { pres_dd, posts_text }, /* Dd */ { pres_dt, NULL }, /* Dt */ { pres_os, NULL }, /* Os */ @@ -295,9 +299,8 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Fr */ { NULL, posts_notext }, /* Ud */ { pres_lb, posts_lb }, /* Lb */ - { NULL, NULL }, /* Ap */ { NULL, posts_pp }, /* Lp */ - { NULL, posts_text }, /* Lk */ + { NULL, NULL }, /* Lk */ { NULL, posts_text }, /* Mt */ { NULL, posts_wline }, /* Brq */ { NULL, NULL }, /* Bro */ @@ -460,12 +463,25 @@ pwarn(struct mdoc *m, int line, int pos, enum mwarn ty 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; + case (WDEPESC): + p = "deprecated special-character escape"; + break; case (WNOLINE): p = "suggested no line arguments"; break; @@ -705,8 +721,6 @@ check_text(struct mdoc *mdoc, int line, int pos, const { size_t c; - /* FIXME: indicate deprecated escapes \*(xx and \*x. */ - for ( ; *p; p++) { if ('\t' == *p) { if ( ! (MDOC_LITERAL & mdoc->flags)) @@ -721,6 +735,10 @@ check_text(struct mdoc *mdoc, int line, int pos, const c = mdoc_isescape(p); if (c) { + /* See if form is deprecated. */ + if ('*' == p[1]) + if ( ! pwarn(mdoc, line, pos, WDEPESC)) + return(0); p += (int)c - 1; continue; } @@ -776,7 +794,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); @@ -785,11 +803,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): @@ -811,23 +829,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; } @@ -835,7 +851,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): @@ -843,17 +869,25 @@ pre_bl(PRE_ARGS) 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; }