=================================================================== RCS file: /cvs/mandoc/Attic/validate.c,v retrieving revision 1.83 retrieving revision 1.91 diff -u -p -r1.83 -r1.91 --- mandoc/Attic/validate.c 2009/03/13 13:56:13 1.83 +++ mandoc/Attic/validate.c 2009/03/21 13:47:02 1.91 @@ -1,6 +1,6 @@ -/* $Id: validate.c,v 1.83 2009/03/13 13:56:13 kristaps Exp $ */ +/* $Id: validate.c,v 1.91 2009/03/21 13:47:02 kristaps Exp $ */ /* - * Copyright (c) 2008 Kristaps Dzonsons + * Copyright (c) 2008, 2009 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the @@ -40,6 +40,8 @@ #define POST_ARGS struct mdoc *mdoc enum merr { + EESCAPE, + EPRINT, ENODATA, ENOPROLOGUE, ELINE, @@ -55,6 +57,7 @@ enum merr { }; enum mwarn { + WESCAPE, WWRONGMSEC, WSECOOO, WSECREP, @@ -81,16 +84,13 @@ struct valids { /* Utility checks. */ -static int nwarn(struct mdoc *, - const struct mdoc_node *, enum mwarn); -static int nerr(struct mdoc *, - const struct mdoc_node *, enum merr); +static int pwarn(struct mdoc *, int, int, enum mwarn); +static int perr(struct mdoc *, int, int, enum merr); static int check_parent(PRE_ARGS, int, enum mdoc_type); static int check_msec(PRE_ARGS, ...); static int check_sec(PRE_ARGS, ...); static int check_stdarg(PRE_ARGS); -static int check_text(struct mdoc *, - int, int, const char *); +static int check_text(struct mdoc *, int, int, const char *); static int check_argv(struct mdoc *, const struct mdoc_node *, const struct mdoc_argv *); @@ -151,6 +151,11 @@ static int post_sh_body(POST_ARGS); static int post_sh_head(POST_ARGS); static int post_st(POST_ARGS); +#define mwarn(m, t) nwarn((m), (m)->last, (t)) +#define merr(m, t) nerr((m), (m)->last, (t)) +#define nwarn(m, n, t) pwarn((m), (n)->line, (n)->pos, (t)) +#define nerr(m, n, t) perr((m), (n)->line, (n)->pos, (t)) + 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 }; @@ -189,10 +194,7 @@ static v_post posts_at[] = { post_at, NULL }; static v_post posts_xr[] = { eerr_ge1, eerr_le2, NULL }; static v_post posts_nm[] = { post_nm, NULL }; static v_post posts_bf[] = { hwarn_le1, post_bf, NULL }; -static v_post posts_rs[] = { herr_eq0, bwarn_ge1, NULL }; static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL }; -static v_post posts_bk[] = { herr_eq0, bwarn_ge1, NULL }; -static v_post posts_fd[] = { ewarn_ge1, NULL }; const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* \" */ @@ -214,18 +216,18 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Ar */ { pres_cd, posts_text }, /* Cd */ { NULL, NULL }, /* Cm */ - { NULL, posts_text }, /* Dv */ + { NULL, NULL }, /* Dv */ { pres_er, posts_text }, /* Er */ - { NULL, posts_text }, /* Ev */ + { NULL, NULL }, /* Ev */ { pres_ex, posts_ex }, /* Ex */ - { NULL, posts_text }, /* Fa */ - { pres_fd, posts_fd }, /* Fd */ + { NULL, NULL }, /* Fa */ + { pres_fd, posts_wtext }, /* Fd */ { NULL, NULL }, /* Fl */ { NULL, posts_text }, /* Fn */ { NULL, posts_wtext }, /* Ft */ { NULL, posts_text }, /* Ic */ { NULL, posts_in }, /* In */ - { NULL, posts_text }, /* Li */ + { NULL, NULL }, /* Li */ { NULL, posts_wtext }, /* Nd */ { NULL, posts_nm }, /* Nm */ { NULL, posts_wline }, /* Op */ @@ -233,7 +235,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Pa */ { pres_rv, posts_rv }, /* Rv */ { NULL, posts_st }, /* St */ - { NULL, posts_text }, /* Va */ + { NULL, NULL }, /* Va */ { NULL, posts_text }, /* Vt */ { NULL, posts_xr }, /* Xr */ { NULL, posts_text }, /* %A */ @@ -263,7 +265,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, posts_wline }, /* Dq */ { NULL, NULL }, /* Ec */ { NULL, NULL }, /* Ef */ - { NULL, posts_text }, /* Em */ + { NULL, NULL }, /* Em */ { NULL, NULL }, /* Eo */ { NULL, NULL }, /* Fx */ { NULL, posts_text }, /* Ms */ @@ -280,7 +282,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Qo */ { NULL, posts_wline }, /* Qq */ { NULL, NULL }, /* Re */ - { NULL, posts_rs }, /* Rs */ + { NULL, posts_wline }, /* Rs */ { NULL, NULL }, /* Sc */ { NULL, NULL }, /* So */ { NULL, posts_wline }, /* Sq */ @@ -295,7 +297,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Fc */ { NULL, NULL }, /* Oo */ { NULL, NULL }, /* Oc */ - { NULL, posts_bk }, /* Bk */ + { NULL, posts_wline }, /* Bk */ { NULL, NULL }, /* Ek */ { NULL, posts_notext }, /* Bt */ { NULL, NULL }, /* Hf */ @@ -310,30 +312,34 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Bro */ { NULL, NULL }, /* Brc */ { NULL, posts_text }, /* %C */ + { NULL, NULL }, /* Es */ + { NULL, NULL }, /* En */ + { NULL, NULL }, /* Dx */ + { NULL, posts_text }, /* %Q */ }; int mdoc_valid_pre(struct mdoc *mdoc, - const struct mdoc_node *node) + const struct mdoc_node *n) { v_pre *p; int line, pos; const char *tp; - if (MDOC_TEXT == node->type) { - tp = node->string; - line = node->line; - pos = node->pos; + if (MDOC_TEXT == n->type) { + tp = n->string; + line = n->line; + pos = n->pos; return(check_text(mdoc, line, pos, tp)); } - if ( ! check_args(mdoc, node)) + if ( ! check_args(mdoc, n)) return(0); - if (NULL == mdoc_valids[node->tok].pre) + if (NULL == mdoc_valids[n->tok].pre) return(1); - for (p = mdoc_valids[node->tok].pre; *p; p++) - if ( ! (*p)(mdoc, node)) + for (p = mdoc_valids[n->tok].pre; *p; p++) + if ( ! (*p)(mdoc, n)) return(0); return(1); } @@ -371,15 +377,19 @@ mdoc_valid_post(struct mdoc *mdoc) } -#define merr(m, t) nerr((m), (m)->last, (t)) static int -nerr(struct mdoc *m, const struct mdoc_node *n, enum merr type) +perr(struct mdoc *m, int line, int pos, enum merr type) { char *p; p = NULL; - switch (type) { + case (EESCAPE): + p = "invalid escape sequence"; + break; + case (EPRINT): + p = "invalid character"; + break; case (ENESTDISP): p = "displays may not be nested"; break; @@ -417,22 +427,19 @@ nerr(struct mdoc *m, const struct mdoc_node *n, enum m p = "default name not yet set"; break; } - assert(p); - return(mdoc_nerr(m, n, p)); + return(mdoc_perr(m, line, pos, p)); } -#define mwarn(m, t) nwarn((m), (m)->last, (t)) static int -nwarn(struct mdoc *m, const struct mdoc_node *n, enum mwarn type) +pwarn(struct mdoc *m, int line, int pos, enum mwarn type) { char *p; enum mdoc_warn c; c = WARN_SYNTAX; p = NULL; - switch (type) { case (WBADMSEC): p = "inappropriate manual section"; @@ -454,6 +461,9 @@ nwarn(struct mdoc *m, const struct mdoc_node *n, enum p = "prologue macros out-of-order"; c = WARN_COMPAT; break; + case (WESCAPE): + p = "invalid escape sequence"; + break; case (WNOLINE): p = "suggested no line arguments"; break; @@ -484,7 +494,7 @@ nwarn(struct mdoc *m, const struct mdoc_node *n, enum break; } assert(p); - return(mdoc_nwarn(m, n, c, p)); + return(mdoc_pwarn(m, line, pos, c, p)); } @@ -685,23 +695,26 @@ check_text(struct mdoc *mdoc, int line, int pos, const { size_t c; - /* XXX - indicate deprecated escapes \*(xx and \*x. */ + /* FIXME: indicate deprecated escapes \*(xx and \*x. */ for ( ; *p; p++) { - if ( ! isprint((u_char)*p) && '\t' != *p) - return(mdoc_perr(mdoc, line, pos, - "invalid non-printing character")); + if ('\t' == *p) { + if ( ! (MDOC_LITERAL & mdoc->flags)) + return(perr(mdoc, line, pos, EPRINT)); + } else if ( ! isprint((u_char)*p)) + return(perr(mdoc, line, pos, EPRINT)); + if ('\\' != *p) continue; - if ((c = mdoc_isescape(p))) { + + c = mdoc_isescape(p); + if (c) { p += (int)c - 1; continue; } if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) - return(mdoc_perr(mdoc, line, pos, - "invalid escape sequence")); - if ( ! mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX, - "invalid escape sequence")) + return(perr(mdoc, line, pos, EESCAPE)); + if ( ! pwarn(mdoc, line, pos, WESCAPE)) return(0); }