=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc_validate.c,v retrieving revision 1.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- src/usr.bin/mandoc/mdoc_validate.c 2010/05/15 18:25:51 1.54 +++ src/usr.bin/mandoc/mdoc_validate.c 2010/05/23 22:45:01 1.55 @@ -1,4 +1,4 @@ -/* $Id: mdoc_validate.c,v 1.54 2010/05/15 18:25:51 schwarze Exp $ */ +/* $Id: mdoc_validate.c,v 1.55 2010/05/23 22:45:01 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -22,6 +22,7 @@ #include #include +#include "mandoc.h" #include "libmdoc.h" #include "libmandoc.h" @@ -317,8 +318,9 @@ int want, const char *v, int has) { - return(mdoc_vwarn(m, m->last->line, m->last->pos, - "suggests %s %s %d (has %d)", v, k, want, has)); + return(mdoc_vmsg(m, MANDOCERR_ARGCOUNT, + m->last->line, m->last->pos, + "%s %s %d (have %d)", v, k, want, has)); } @@ -327,8 +329,11 @@ int want, const char *v, int has) { - return(mdoc_verr(m, m->last->line, m->last->pos, - "requires %s %s %d (has %d)", v, k, want, has)); + mdoc_vmsg(m, MANDOCERR_SYNTARGCOUNT, + m->last->line, m->last->pos, + "%s %s %d (have %d)", + v, k, want, has); + return(0); } @@ -401,7 +406,7 @@ if (n->args && 1 == n->args->argc) if (MDOC_Std == n->args->argv[0].arg) return(1); - return(mdoc_nwarn(mdoc, n, EARGVAL)); + return(mdoc_nmsg(mdoc, n, MANDOCERR_NOARGV)); } @@ -433,10 +438,10 @@ return(0); if (MDOC_Std == v->arg) { - /* `Nm' name must be set. */ if (v->sz || m->meta.name) return(1); - return(mdoc_nerr(m, n, ENAME)); + if ( ! mdoc_nmsg(m, n, MANDOCERR_NONAME)) + return(0); } return(1); @@ -451,10 +456,10 @@ for ( ; *p; p++, pos++) { if ('\t' == *p) { if ( ! (MDOC_LITERAL & mdoc->flags)) - if ( ! mdoc_pwarn(mdoc, line, pos, EPRINT)) + if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR)) return(0); } else if ( ! isprint((u_char)*p)) - if ( ! mdoc_pwarn(mdoc, line, pos, EPRINT)) + if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR)) return(0); if ('\\' != *p) @@ -466,10 +471,10 @@ pos += c - 1; continue; } - if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) - return(mdoc_perr(mdoc, line, pos, EESCAPE)); - if ( ! mdoc_pwarn(mdoc, line, pos, EESCAPE)) - return(0); + + c = mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADESCAPE); + if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags) && ! c) + return(c); } return(1); @@ -487,8 +492,11 @@ (t == n->parent->type)) return(1); - return(mdoc_verr(mdoc, n->line, n->pos, "require parent %s", - MDOC_ROOT == t ? "" : mdoc_macronames[tok])); + mdoc_vmsg(mdoc, MANDOCERR_SYNTCHILD, + n->line, n->pos, "want parent %s", + MDOC_ROOT == t ? "" : + mdoc_macronames[tok]); + return(0); } @@ -511,7 +519,8 @@ if (NULL == node) return(1); - return(mdoc_nerr(mdoc, n, ENESTDISP)); + mdoc_nmsg(mdoc, n, MANDOCERR_NESTEDDISP); + return(0); } @@ -522,8 +531,10 @@ if (MDOC_BLOCK != n->type) return(1); - if (NULL == n->args) - return(mdoc_nerr(mdoc, n, ELISTTYPE)); + if (NULL == n->args) { + mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE); + return(0); + } /* Make sure that only one type of list is specified. */ @@ -563,7 +574,7 @@ * FIXME: this should occur in mdoc_action.c. */ if (type >= 0) { - if ( ! mdoc_nwarn(mdoc, n, EMULTILIST)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTREP)) return(0); mdoc_argn_free(n->args, pos); break; @@ -571,20 +582,22 @@ type = n->args->argv[pos].arg; break; case (MDOC_Compact): - if (type < 0 && ! mdoc_nwarn(mdoc, n, ENOTYPE)) + if (type < 0 && ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST)) return(0); break; case (MDOC_Width): if (width >= 0) - return(mdoc_nerr(mdoc, n, EARGREP)); - if (type < 0 && ! mdoc_nwarn(mdoc, n, ENOTYPE)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP)) + return(0); + if (type < 0 && ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST)) return(0); width = n->args->argv[pos].arg; break; case (MDOC_Offset): if (offset >= 0) - return(mdoc_nerr(mdoc, n, EARGREP)); - if (type < 0 && ! mdoc_nwarn(mdoc, n, ENOTYPE)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP)) + return(0); + if (type < 0 && ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST)) return(0); offset = n->args->argv[pos].arg; break; @@ -592,8 +605,10 @@ break; } - if (type < 0) - return(mdoc_nerr(mdoc, n, ELISTTYPE)); + if (type < 0) { + mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE); + return(0); + } /* * Validate the width field. Some list types don't need width @@ -603,7 +618,7 @@ switch (type) { case (MDOC_Tag): - if (width < 0 && ! mdoc_nwarn(mdoc, n, EMISSWIDTH)) + if (width < 0 && ! mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG)) return(0); break; case (MDOC_Column): @@ -615,7 +630,7 @@ case (MDOC_Inset): /* FALLTHROUGH */ case (MDOC_Item): - if (width >= 0 && ! mdoc_nwarn(mdoc, n, ENOWIDTH)) + if (width >= 0 && ! mdoc_nmsg(mdoc, n, MANDOCERR_WIDTHARG)) return(0); break; default: @@ -633,8 +648,10 @@ if (MDOC_BLOCK != n->type) return(1); - if (NULL == n->args) - return(mdoc_nerr(mdoc, n, EDISPTYPE)); + if (NULL == n->args) { + mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE); + return(0); + } /* Make sure that only one type of display is specified. */ @@ -653,14 +670,17 @@ case (MDOC_Literal): if (0 == type++) break; - return(mdoc_nerr(mdoc, n, EMULTIDISP)); + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP)) + return(0); + break; default: break; } if (type) return(1); - return(mdoc_nerr(mdoc, n, EDISPTYPE)); + mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE); + return(0); } @@ -690,6 +710,10 @@ if (MDOC_BLOCK != n->type) return(1); + /* + * FIXME: this can probably be lifted if we make the It into + * something else on-the-fly? + */ return(check_parent(mdoc, n, MDOC_Bl, MDOC_BODY)); } @@ -700,8 +724,11 @@ if (NULL == n->args || 1 == n->args->argc) return(1); - return(mdoc_verr(mdoc, n->line, n->pos, - "only one argument allowed")); + mdoc_vmsg(mdoc, MANDOCERR_SYNTARGCOUNT, + n->line, n->pos, + "line arguments == 1 (have %d)", + n->args->argc); + return(0); } @@ -720,10 +747,10 @@ /* FIXME: make sure is capitalised. */ if (0 == mdoc->meta.date || mdoc->meta.os) - if ( ! mdoc_nwarn(mdoc, n, EPROLOOO)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO)) return(0); if (mdoc->meta.title) - if ( ! mdoc_nwarn(mdoc, n, EPROLREP)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP)) return(0); return(1); } @@ -734,10 +761,10 @@ { if (NULL == mdoc->meta.title || 0 == mdoc->meta.date) - if ( ! mdoc_nwarn(mdoc, n, EPROLOOO)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO)) return(0); if (mdoc->meta.os) - if ( ! mdoc_nwarn(mdoc, n, EPROLREP)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP)) return(0); return(1); } @@ -748,10 +775,10 @@ { if (mdoc->meta.title || mdoc->meta.os) - if ( ! mdoc_nwarn(mdoc, n, EPROLOOO)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO)) return(0); if (mdoc->meta.date) - if ( ! mdoc_nwarn(mdoc, n, EPROLREP)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP)) return(0); return(1); } @@ -768,13 +795,18 @@ head = mdoc->last->head; - if (mdoc->last->args && head->child) - return(mdoc_nerr(mdoc, mdoc->last, ELINE)); - else if (mdoc->last->args) + if (mdoc->last->args && head->child) { + /* FIXME: this should provide a default. */ + mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SYNTARGVCOUNT); + return(0); + } else if (mdoc->last->args) return(1); - if (NULL == head->child || MDOC_TEXT != head->child->type) - return(mdoc_nerr(mdoc, mdoc->last, ELINE)); + if (NULL == head->child || MDOC_TEXT != head->child->type) { + /* FIXME: this should provide a default. */ + mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SYNTARGVCOUNT); + return(0); + } p = head->child->string; @@ -785,7 +817,8 @@ else if (0 == strcmp(p, "Sy")) return(1); - return(mdoc_nerr(mdoc, head, EFONT)); + mdoc_nmsg(mdoc, head, MANDOCERR_FONTTYPE); + return(0); } @@ -795,7 +828,7 @@ if (mdoc_a2lib(mdoc->last->child->string)) return(1); - return(mdoc_nwarn(mdoc, mdoc->last, ELIB)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADLIB)); } @@ -818,7 +851,7 @@ for (n = mdoc->last->child; n; n = n->next) if (MDOC_TEXT != n->type) - if ( ! mdoc_nwarn(mdoc, n, EBADCHILD)) + if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_CHILD)) return(0); return(1); @@ -833,7 +866,7 @@ return(1); if (mdoc->meta.name) return(1); - return(mdoc_nerr(mdoc, mdoc->last, ENAME)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME)); } @@ -843,11 +876,10 @@ if (NULL == mdoc->last->child) return(1); - if (MDOC_TEXT != mdoc->last->child->type) - return(mdoc_nerr(mdoc, mdoc->last, EATT)); + assert(MDOC_TEXT == mdoc->last->child->type); if (mdoc_a2att(mdoc->last->child->string)) return(1); - return(mdoc_nwarn(mdoc, mdoc->last, EATT)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADATT)); } @@ -858,12 +890,12 @@ if (mdoc->last->args) { if (NULL == mdoc->last->child) return(1); - return(mdoc_nerr(mdoc, mdoc->last, ENOLINE)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGCOUNT)); } if (mdoc->last->child) return(1); - return(mdoc_nerr(mdoc, mdoc->last, ELINE)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS)); } @@ -877,8 +909,10 @@ return(1); n = mdoc->last->parent->parent; - if (NULL == n->args) - return(mdoc_nerr(mdoc, mdoc->last, ELISTTYPE)); + if (NULL == n->args) { + mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE); + return(0); + } /* Some types require block-head, some not. */ @@ -915,13 +949,15 @@ break; } - if (-1 == type) - return(mdoc_nerr(mdoc, mdoc->last, ELISTTYPE)); + if (-1 == type) { + mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE); + return(0); + } switch (type) { case (MDOC_Tag): if (NULL == mdoc->last->head->child) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS)) return(0); break; case (MDOC_Hang): @@ -932,10 +968,10 @@ /* FALLTHROUGH */ case (MDOC_Diag): if (NULL == mdoc->last->head->child) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS)) return(0); if (NULL == mdoc->last->body->child) - if ( ! mdoc_nwarn(mdoc, mdoc->last, EMULTILINE)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY)) return(0); break; case (MDOC_Bullet): @@ -948,36 +984,38 @@ /* FALLTHROUGH */ case (MDOC_Item): if (mdoc->last->head->child) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ENOLINE)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST)) return(0); if (NULL == mdoc->last->body->child) - if ( ! mdoc_nwarn(mdoc, mdoc->last, EMULTILINE)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY)) return(0); break; case (MDOC_Column): if (NULL == mdoc->last->head->child) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS)) return(0); if (mdoc->last->body->child) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ENOMULTILINE)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BODYLOST)) return(0); c = mdoc->last->child; for (i = 0; c && MDOC_HEAD == c->type; c = c->next) i++; if (i < cols) { - if ( ! mdoc_vwarn(mdoc, mdoc->last->line, - mdoc->last->pos, "column " - "mismatch: have %d, want %d", - i, cols)) + if ( ! mdoc_vmsg(mdoc, MANDOCERR_ARGCOUNT, + mdoc->last->line, + mdoc->last->pos, + "columns == %d (have %d)", + cols, i)) return(0); break; } else if (i == cols || i == cols + 1) break; - return(mdoc_verr(mdoc, mdoc->last->line, - mdoc->last->pos, "column mismatch: " - "have %d, want %d", i, cols)); + mdoc_vmsg(mdoc, MANDOCERR_SYNTARGCOUNT, + mdoc->last->line, mdoc->last->pos, + "columns == %d (have %d)", cols, i); + return(0); default: break; } @@ -1000,7 +1038,7 @@ a = &n->args->argv[i]; if (a->arg == MDOC_Column) { if (a->sz && mdoc->last->nchild) - return(mdoc_nerr(mdoc, n, ECOLMIS)); + return(mdoc_nmsg(mdoc, n, MANDOCERR_COLUMNS)); return(1); } } @@ -1035,7 +1073,8 @@ continue; if (MDOC_Sm == n->tok) continue; - return(mdoc_nerr(mdoc, n, EBADCHILD)); + mdoc_nmsg(mdoc, n, MANDOCERR_SYNTCHILD); + return(0); } return(1); @@ -1060,7 +1099,7 @@ if (NULL == n) return(1); - return(mdoc_nerr(mdoc, n, EBOOL)); + return(mdoc_nmsg(mdoc, n, MANDOCERR_BADBOOL)); } @@ -1069,16 +1108,17 @@ { if (NULL == mdoc->first->child) - return(mdoc_nerr(mdoc, mdoc->first, ENODAT)); - if ( ! (MDOC_PBODY & mdoc->flags)) - return(mdoc_nerr(mdoc, mdoc->first, ENOPROLOGUE)); + mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY); + else if ( ! (MDOC_PBODY & mdoc->flags)) + mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG); + else if (MDOC_BLOCK != mdoc->first->child->type) + mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY); + else if (MDOC_Sh != mdoc->first->child->tok) + mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY); + else + return(1); - if (MDOC_BLOCK != mdoc->first->child->type) - return(mdoc_nerr(mdoc, mdoc->first, ENODAT)); - if (MDOC_Sh != mdoc->first->child->tok) - return(mdoc_nerr(mdoc, mdoc->first, ENODAT)); - - return(1); + return(0); } @@ -1088,7 +1128,7 @@ if (mdoc_a2st(mdoc->last->child->string)) return(1); - return(mdoc_nwarn(mdoc, mdoc->last, EBADSTAND)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADSTANDARD)); } @@ -1131,7 +1171,8 @@ case(MDOC__V): break; default: - return(mdoc_nerr(mdoc, nn, EBADCHILD)); + mdoc_nmsg(mdoc, nn, MANDOCERR_SYNTCHILD); + return(0); } return(1); @@ -1166,21 +1207,21 @@ */ if (NULL == (n = mdoc->last->child)) - return(mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC)); for ( ; n && n->next; n = n->next) { if (MDOC_ELEM == n->type && MDOC_Nm == n->tok) continue; if (MDOC_TEXT == n->type) continue; - if ( ! mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC)) return(0); } assert(n); if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok) return(1); - return(mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC)); } @@ -1198,18 +1239,27 @@ * certain manual sections. */ - buf[0] = 0; + buf[0] = '\0'; + /* + * FIXME: yes, these can use a dynamic buffer, but I don't do so + * in the interests of simplicity. + */ + for (n = mdoc->last->child; n; n = n->next) { /* XXX - copied from compact(). */ assert(MDOC_TEXT == n->type); - if (strlcat(buf, n->string, 64) >= 64) - return(mdoc_nerr(mdoc, n, ETOOLONG)); + if (strlcat(buf, n->string, 64) >= 64) { + mdoc_nmsg(mdoc, n, MANDOCERR_MEM); + return(0); + } if (NULL == n->next) continue; - if (strlcat(buf, " ", 64) >= 64) - return(mdoc_nerr(mdoc, n, ETOOLONG)); + if (strlcat(buf, " ", 64) >= 64) { + mdoc_nmsg(mdoc, n, MANDOCERR_MEM); + return(0); + } } sec = mdoc_str2sec(buf); @@ -1220,18 +1270,18 @@ */ if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ESECNAME)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NAMESECFIRST)) return(0); if (SEC_CUSTOM == sec) return(1); if (sec == mdoc->lastnamed) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ESECREP)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECREP)) return(0); if (sec < mdoc->lastnamed) - if ( ! mdoc_nwarn(mdoc, mdoc->last, ESECOOO)) + if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECOOO)) return(0); /* @@ -1248,7 +1298,7 @@ break; if (*mdoc->meta.msec == '9') break; - return(mdoc_nwarn(mdoc, mdoc->last, EWRONGMSEC)); + return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_SECMSEC)); default: break; }