diff options
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r-- | mdoc_validate.c | 294 |
1 files changed, 73 insertions, 221 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c index 12898f45..8541c8e2 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -31,40 +31,6 @@ #define PRE_ARGS struct mdoc *mdoc, const struct mdoc_node *n #define POST_ARGS struct mdoc *mdoc -enum merr { - ETOOLONG, - EESCAPE, - EPRINT, - ENODATA, - ENOPROLOGUE, - ELINE, - EATT, - ENAME, - ELISTTYPE, - EDISPTYPE, - EMULTIDISP, - ESECNAME, - EMULTILIST, - EARGREP, - EBOOL, - ECOLMIS, - ENESTDISP, - ENOWIDTH, - EMISSWIDTH, - EWRONGMSEC, - ESECOOO, - ESECREP, - EBADSTAND, - ENAMESECINC, - ENOMULTILINE, - EMULTILINE, - ENOLINE, - EPROLOOO, - EPROLREP, - EARGVAL, - EBADSEC, - EBADMSEC -}; typedef int (*v_pre)(PRE_ARGS); typedef int (*v_post)(POST_ARGS); @@ -74,7 +40,6 @@ struct valids { v_post *post; }; -static int perr(struct mdoc *, int, int, enum merr, int); static int check_parent(PRE_ARGS, int, enum mdoc_type); static int check_msec(PRE_ARGS, ...); static int check_sec(PRE_ARGS, ...); @@ -139,11 +104,6 @@ static int post_sh_body(POST_ARGS); static int post_sh_head(POST_ARGS); static int post_st(POST_ARGS); -#define vwarn(m, t) nwarn((m), (m)->last, (t)) -#define verr(m, t) nerr((m), (m)->last, (t)) -#define nwarn(m, n, t) perr((m), (n)->line, (n)->pos, (t), 0) -#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t), 1) - static v_pre pres_an[] = { pre_an, NULL }; static v_pre pres_bd[] = { pre_display, pre_bd, NULL }; static v_pre pres_bl[] = { pre_bl, NULL }; @@ -370,125 +330,12 @@ mdoc_valid_post(struct mdoc *mdoc) static int -perr(struct mdoc *m, int line, int pos, enum merr type, int iserr) -{ - char *p; - - p = NULL; - - switch (type) { - case (ETOOLONG): - p = "text argument too long"; - break; - case (EESCAPE): - p = "invalid escape sequence"; - break; - case (EPRINT): - p = "invalid character"; - break; - case (ENESTDISP): - p = "displays may not be nested"; - break; - case (EBOOL): - p = "expected boolean value"; - break; - case (EARGREP): - p = "argument repeated"; - break; - case (EMULTIDISP): - p = "multiple display types specified"; - break; - case (EMULTILIST): - p = "multiple list types specified"; - break; - case (ELISTTYPE): - p = "missing list type"; - break; - case (EDISPTYPE): - p = "missing display type"; - break; - case (ESECNAME): - p = "the NAME section must come first"; - break; - case (ELINE): - p = "expected line arguments"; - break; - case (ENOPROLOGUE): - p = "document has no prologue"; - break; - case (ENODATA): - p = "document has no data"; - break; - case (ECOLMIS): - p = "column syntax style mismatch"; - break; - case (EATT): - p = "expected valid AT&T symbol"; - break; - case (ENAME): - p = "default name not yet set"; - break; - case (ENOWIDTH): - p = "superfluous width argument"; - break; - case (EMISSWIDTH): - p = "missing width argument"; - break; - case (EWRONGMSEC): - p = "document section in wrong manual section"; - break; - case (ESECOOO): - p = "document section out of conventional order"; - break; - case (ESECREP): - p = "document section repeated"; - break; - case (EBADSTAND): - p = "unknown standard"; - break; - case (ENAMESECINC): - p = "NAME section contents incomplete/badly-ordered"; - break; - case (ENOMULTILINE): - p = "suggested no multi-line arguments"; - break; - case (EMULTILINE): - p = "suggested multi-line arguments"; - break; - case (ENOLINE): - p = "suggested no line arguments"; - break; - case (EPROLOOO): - p = "prologue macros out-of-order"; - break; - case (EPROLREP): - p = "prologue macros repeated"; - break; - case (EARGVAL): - p = "argument value suggested"; - break; - case (EBADMSEC): - p = "inappropriate manual section"; - break; - case (EBADSEC): - p = "inappropriate document section"; - break; - } - - assert(p); - - if (iserr) - return(mdoc_perr(m, line, pos, p)); - - return(mdoc_pwarn(m, line, pos, p)); -} - - -static int warn_print(struct mdoc *m, int ln, int pos) { - return(perr(m, ln, pos, EPRINT, ! (MDOC_IGN_CHARS & m->pflags))); + if (MDOC_IGN_CHARS & m->pflags) + return(mdoc_pwarn(m, ln, pos, EPRINT)); + return(mdoc_perr(m, ln, pos, EPRINT)); } @@ -497,8 +344,8 @@ warn_count(struct mdoc *m, const char *k, int want, const char *v, int has) { - return(mdoc_warn(m, "suggests %s %s %d (has %d)", - v, k, want, has)); + return(mdoc_vwarn(m, m->last->line, m->last->pos, + "suggests %s %s %d (has %d)", v, k, want, has)); } @@ -507,7 +354,7 @@ err_count(struct mdoc *m, const char *k, int want, const char *v, int has) { - return(mdoc_err(m, + return(mdoc_verr(m, m->last->line, m->last->pos, "requires %s %s %d (has %d)", v, k, want, has)); } @@ -581,7 +428,7 @@ check_stdarg(PRE_ARGS) if (n->args && 1 == n->args->argc) if (MDOC_Std == n->args->argv[0].arg) return(1); - return(nwarn(mdoc, n, EARGVAL)); + return(mdoc_nwarn(mdoc, n, EARGVAL)); } @@ -605,7 +452,7 @@ check_sec(PRE_ARGS, ...) } va_end(ap); - return(nwarn(mdoc, n, EBADSEC)); + return(mdoc_nwarn(mdoc, n, EBADSEC)); } @@ -627,7 +474,7 @@ check_msec(PRE_ARGS, ...) } va_end(ap); - return(nwarn(mdoc, n, EBADMSEC)); + return(mdoc_nwarn(mdoc, n, EBADMSEC)); } @@ -662,7 +509,7 @@ check_argv(struct mdoc *m, const struct mdoc_node *n, /* `Nm' name must be set. */ if (v->sz || m->meta.name) return(1); - return(nerr(m, n, ENAME)); + return(mdoc_nerr(m, n, ENAME)); } return(1); @@ -693,8 +540,8 @@ check_text(struct mdoc *mdoc, int line, int pos, const char *p) continue; } if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) - return(perr(mdoc, line, pos, EESCAPE, 1)); - if ( ! perr(mdoc, line, pos, EESCAPE, 0)) + return(mdoc_perr(mdoc, line, pos, EESCAPE)); + if ( ! mdoc_perr(mdoc, line, pos, EESCAPE)) return(0); } @@ -713,7 +560,7 @@ check_parent(PRE_ARGS, int tok, enum mdoc_type t) (t == n->parent->type)) return(1); - return(mdoc_nerr(mdoc, n, "require parent %s", + return(mdoc_verr(mdoc, n->line, n->pos, "require parent %s", MDOC_ROOT == t ? "<root>" : mdoc_macronames[tok])); } @@ -737,7 +584,7 @@ pre_display(PRE_ARGS) if (NULL == node) return(1); - return(nerr(mdoc, n, ENESTDISP)); + return(mdoc_nerr(mdoc, n, ENESTDISP)); } @@ -749,7 +596,7 @@ pre_bl(PRE_ARGS) if (MDOC_BLOCK != n->type) return(1); if (NULL == n->args) - return(nerr(mdoc, n, ELISTTYPE)); + return(mdoc_nerr(mdoc, n, ELISTTYPE)); /* Make sure that only one type of list is specified. */ @@ -780,17 +627,17 @@ pre_bl(PRE_ARGS) /* FALLTHROUGH */ case (MDOC_Column): if (-1 != type) - return(nerr(mdoc, n, EMULTILIST)); + return(mdoc_nerr(mdoc, n, EMULTILIST)); type = n->args->argv[pos].arg; break; case (MDOC_Width): if (-1 != width) - return(nerr(mdoc, n, EARGREP)); + return(mdoc_nerr(mdoc, n, EARGREP)); width = n->args->argv[pos].arg; break; case (MDOC_Offset): if (-1 != offset) - return(nerr(mdoc, n, EARGREP)); + return(mdoc_nerr(mdoc, n, EARGREP)); offset = n->args->argv[pos].arg; break; default: @@ -798,7 +645,7 @@ pre_bl(PRE_ARGS) } if (-1 == type) - return(nerr(mdoc, n, ELISTTYPE)); + return(mdoc_nerr(mdoc, n, ELISTTYPE)); /* * Validate the width field. Some list types don't need width @@ -808,7 +655,7 @@ pre_bl(PRE_ARGS) switch (type) { case (MDOC_Tag): - if (-1 == width && ! nwarn(mdoc, n, EMISSWIDTH)) + if (-1 == width && ! mdoc_nwarn(mdoc, n, EMISSWIDTH)) return(0); break; case (MDOC_Column): @@ -818,7 +665,7 @@ pre_bl(PRE_ARGS) case (MDOC_Inset): /* FALLTHROUGH */ case (MDOC_Item): - if (-1 != width && ! nwarn(mdoc, n, ENOWIDTH)) + if (-1 != width && ! mdoc_nwarn(mdoc, n, ENOWIDTH)) return(0); break; default: @@ -837,7 +684,7 @@ pre_bd(PRE_ARGS) if (MDOC_BLOCK != n->type) return(1); if (NULL == n->args) - return(nerr(mdoc, n, EDISPTYPE)); + return(mdoc_nerr(mdoc, n, EDISPTYPE)); /* Make sure that only one type of display is specified. */ @@ -856,14 +703,14 @@ pre_bd(PRE_ARGS) case (MDOC_File): if (0 == type++) break; - return(nerr(mdoc, n, EMULTIDISP)); + return(mdoc_nerr(mdoc, n, EMULTIDISP)); default: break; } if (type) return(1); - return(nerr(mdoc, n, EDISPTYPE)); + return(mdoc_nerr(mdoc, n, EDISPTYPE)); } @@ -903,7 +750,8 @@ pre_an(PRE_ARGS) if (NULL == n->args || 1 == n->args->argc) return(1); - return(mdoc_nerr(mdoc, n, "only one argument allowed")); + return(mdoc_verr(mdoc, n->line, n->pos, + "only one argument allowed")); } @@ -956,10 +804,10 @@ pre_dt(PRE_ARGS) { if (0 == mdoc->meta.date || mdoc->meta.os) - if ( ! nwarn(mdoc, n, EPROLOOO)) + if ( ! mdoc_nwarn(mdoc, n, EPROLOOO)) return(0); if (mdoc->meta.title) - if ( ! nwarn(mdoc, n, EPROLREP)) + if ( ! mdoc_nwarn(mdoc, n, EPROLREP)) return(0); return(1); } @@ -970,10 +818,10 @@ pre_os(PRE_ARGS) { if (NULL == mdoc->meta.title || 0 == mdoc->meta.date) - if ( ! nwarn(mdoc, n, EPROLOOO)) + if ( ! mdoc_nwarn(mdoc, n, EPROLOOO)) return(0); if (mdoc->meta.os) - if ( ! nwarn(mdoc, n, EPROLREP)) + if ( ! mdoc_nwarn(mdoc, n, EPROLREP)) return(0); return(1); } @@ -984,10 +832,10 @@ pre_dd(PRE_ARGS) { if (mdoc->meta.title || mdoc->meta.os) - if ( ! nwarn(mdoc, n, EPROLOOO)) + if ( ! mdoc_nwarn(mdoc, n, EPROLOOO)) return(0); if (mdoc->meta.date) - if ( ! nwarn(mdoc, n, EPROLREP)) + if ( ! mdoc_nwarn(mdoc, n, EPROLREP)) return(0); return(1); } @@ -1005,12 +853,14 @@ post_bf(POST_ARGS) head = mdoc->last->head; if (mdoc->last->args && head->child) - return(mdoc_err(mdoc, "one argument expected")); + return(mdoc_verr(mdoc, mdoc->last->line, + mdoc->last->pos, "one argument expected")); else if (mdoc->last->args) return(1); if (NULL == head->child || MDOC_TEXT != head->child->type) - return(mdoc_err(mdoc, "text argument expected")); + return(mdoc_verr(mdoc, mdoc->last->line, + mdoc->last->pos, "text argument expected")); p = head->child->string; @@ -1021,7 +871,7 @@ post_bf(POST_ARGS) else if (0 == strcmp(p, "Sm")) return(1); - return(mdoc_nerr(mdoc, head->child, "invalid font mode")); + return(mdoc_nerr(mdoc, head, EFONT)); } @@ -1033,7 +883,7 @@ post_nm(POST_ARGS) return(1); if (mdoc->meta.name) return(1); - return(verr(mdoc, ENAME)); + return(mdoc_nerr(mdoc, mdoc->last, ENAME)); } @@ -1044,10 +894,10 @@ post_at(POST_ARGS) if (NULL == mdoc->last->child) return(1); if (MDOC_TEXT != mdoc->last->child->type) - return(verr(mdoc, EATT)); + return(mdoc_nerr(mdoc, mdoc->last, EATT)); if (mdoc_a2att(mdoc->last->child->string)) return(1); - return(verr(mdoc, EATT)); + return(mdoc_nerr(mdoc, mdoc->last, EATT)); } @@ -1058,12 +908,12 @@ post_an(POST_ARGS) if (mdoc->last->args) { if (NULL == mdoc->last->child) return(1); - return(verr(mdoc, ELINE)); + return(mdoc_nerr(mdoc, mdoc->last, ELINE)); } if (mdoc->last->child) return(1); - return(verr(mdoc, ELINE)); + return(mdoc_nerr(mdoc, mdoc->last, ELINE)); } @@ -1073,7 +923,7 @@ post_args(POST_ARGS) if (mdoc->last->args) return(1); - return(verr(mdoc, ELINE)); + return(mdoc_nerr(mdoc, mdoc->last, ELINE)); } @@ -1088,7 +938,7 @@ post_it(POST_ARGS) n = mdoc->last->parent->parent; if (NULL == n->args) - return(verr(mdoc, ELISTTYPE)); + return(mdoc_nerr(mdoc, mdoc->last, ELISTTYPE)); /* Some types require block-head, some not. */ @@ -1126,12 +976,12 @@ post_it(POST_ARGS) } if (-1 == type) - return(verr(mdoc, ELISTTYPE)); + return(mdoc_nerr(mdoc, mdoc->last, ELISTTYPE)); switch (type) { case (MDOC_Tag): if (NULL == mdoc->last->head->child) - if ( ! vwarn(mdoc, ELINE)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE)) return(0); break; case (MDOC_Hang): @@ -1142,10 +992,10 @@ post_it(POST_ARGS) /* FALLTHROUGH */ case (MDOC_Diag): if (NULL == mdoc->last->head->child) - if ( ! vwarn(mdoc, ELINE)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE)) return(0); if (NULL == mdoc->last->body->child) - if ( ! vwarn(mdoc, EMULTILINE)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, EMULTILINE)) return(0); break; case (MDOC_Bullet): @@ -1158,26 +1008,27 @@ post_it(POST_ARGS) /* FALLTHROUGH */ case (MDOC_Item): if (mdoc->last->head->child) - if ( ! vwarn(mdoc, ENOLINE)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, ENOLINE)) return(0); if (NULL == mdoc->last->body->child) - if ( ! vwarn(mdoc, EMULTILINE)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, EMULTILINE)) return(0); break; case (MDOC_Column): if (NULL == mdoc->last->head->child) - if ( ! vwarn(mdoc, ELINE)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, ELINE)) return(0); if (mdoc->last->body->child) - if ( ! vwarn(mdoc, ENOMULTILINE)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, ENOMULTILINE)) return(0); c = mdoc->last->child; for (i = 0; c && MDOC_HEAD == c->type; c = c->next) i++; if (i == cols) break; - return(mdoc_err(mdoc, "column mismatch (have " - "%d, want %d)", i, cols)); + return(mdoc_verr(mdoc, mdoc->last->line, mdoc->last->pos, + "column mismatch (have %d, want %d)", + i, cols)); default: break; } @@ -1203,7 +1054,7 @@ post_bl_head(POST_ARGS) return(1); if (n->args->argv[i].sz && mdoc->last->child) - return(nerr(mdoc, n, ECOLMIS)); + return(mdoc_nerr(mdoc, n, ECOLMIS)); return(1); } @@ -1226,7 +1077,8 @@ post_bl(POST_ARGS) if (MDOC_BLOCK == n->type) if (MDOC_It == n->tok) continue; - return(mdoc_nerr(mdoc, n, "bad child of parent %s", + return(mdoc_verr(mdoc, n->line, n->pos, + "bad child of parent %s", mdoc_macronames[mdoc->last->tok])); } @@ -1252,7 +1104,7 @@ ebool(struct mdoc *mdoc) if (NULL == n) return(1); - return(nerr(mdoc, n, EBOOL)); + return(mdoc_nerr(mdoc, n, EBOOL)); } @@ -1261,14 +1113,14 @@ post_root(POST_ARGS) { if (NULL == mdoc->first->child) - return(verr(mdoc, ENODATA)); + return(mdoc_nerr(mdoc, mdoc->first, ENODAT)); if ( ! (MDOC_PBODY & mdoc->flags)) - return(verr(mdoc, ENOPROLOGUE)); + return(mdoc_nerr(mdoc, mdoc->first, ENOPROLOGUE)); if (MDOC_BLOCK != mdoc->first->child->type) - return(verr(mdoc, ENODATA)); + return(mdoc_nerr(mdoc, mdoc->first, ENODAT)); if (MDOC_Sh != mdoc->first->child->tok) - return(verr(mdoc, ENODATA)); + return(mdoc_nerr(mdoc, mdoc->first, ENODAT)); return(1); } @@ -1280,7 +1132,7 @@ post_st(POST_ARGS) if (mdoc_a2st(mdoc->last->child->string)) return(1); - return(vwarn(mdoc, EBADSTAND)); + return(mdoc_nwarn(mdoc, mdoc->last, EBADSTAND)); } @@ -1312,20 +1164,20 @@ post_sh_body(POST_ARGS) */ if (NULL == (n = mdoc->last->child)) - return(vwarn(mdoc, ENAMESECINC)); + return(mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC)); for ( ; n && n->next; n = n->next) { if (MDOC_ELEM == n->type && MDOC_Nm == n->tok) continue; if (MDOC_TEXT == n->type) continue; - if ( ! vwarn(mdoc, ENAMESECINC)) + if ( ! mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC)) return(0); } if (MDOC_ELEM == n->type && MDOC_Nd == n->tok) return(1); - return(vwarn(mdoc, ENAMESECINC)); + return(mdoc_nwarn(mdoc, mdoc->last, ENAMESECINC)); } @@ -1350,11 +1202,11 @@ post_sh_head(POST_ARGS) assert(MDOC_TEXT == n->type); if (strlcat(buf, n->string, 64) >= 64) - return(nerr(mdoc, n, ETOOLONG)); + return(mdoc_nerr(mdoc, n, ETOOLONG)); if (NULL == n->next) continue; if (strlcat(buf, " ", 64) >= 64) - return(nerr(mdoc, n, ETOOLONG)); + return(mdoc_nerr(mdoc, n, ETOOLONG)); } sec = mdoc_atosec(buf); @@ -1365,13 +1217,13 @@ post_sh_head(POST_ARGS) */ if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed) - return(verr(mdoc, ESECNAME)); + return(mdoc_nerr(mdoc, mdoc->last, ESECNAME)); if (SEC_CUSTOM == sec) return(1); if (sec == mdoc->lastnamed) - return(vwarn(mdoc, ESECREP)); + return(mdoc_nwarn(mdoc, mdoc->last, ESECREP)); if (sec < mdoc->lastnamed) - return(vwarn(mdoc, ESECOOO)); + return(mdoc_nwarn(mdoc, mdoc->last, ESECOOO)); /* * Check particular section/manual conventions. LIBRARY can @@ -1386,7 +1238,7 @@ post_sh_head(POST_ARGS) case (3): break; default: - return(vwarn(mdoc, EWRONGMSEC)); + return(mdoc_nwarn(mdoc, mdoc->last, EWRONGMSEC)); } break; default: |