version 1.78, 2009/03/09 14:19:59 |
version 1.91, 2009/03/21 13:47:02 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the |
* purpose with or without fee is hereby granted, provided that the |
|
|
#define POST_ARGS struct mdoc *mdoc |
#define POST_ARGS struct mdoc *mdoc |
|
|
enum merr { |
enum merr { |
|
EESCAPE, |
|
EPRINT, |
ENODATA, |
ENODATA, |
ENOPROLOGUE, |
ENOPROLOGUE, |
ELINE, |
ELINE, |
|
|
}; |
}; |
|
|
enum mwarn { |
enum mwarn { |
|
WESCAPE, |
WWRONGMSEC, |
WWRONGMSEC, |
WSECOOO, |
WSECOOO, |
WSECREP, |
WSECREP, |
|
|
|
|
/* Utility checks. */ |
/* Utility checks. */ |
|
|
static int nwarn(struct mdoc *, |
static int pwarn(struct mdoc *, int, int, enum mwarn); |
const struct mdoc_node *, enum mwarn); |
static int perr(struct mdoc *, int, int, enum merr); |
static int nerr(struct mdoc *, |
|
const struct mdoc_node *, enum merr); |
|
static int check_parent(PRE_ARGS, int, enum mdoc_type); |
static int check_parent(PRE_ARGS, int, enum mdoc_type); |
static int check_msec(PRE_ARGS, ...); |
static int check_msec(PRE_ARGS, ...); |
static int check_sec(PRE_ARGS, ...); |
static int check_sec(PRE_ARGS, ...); |
static int check_stdarg(PRE_ARGS); |
static int check_stdarg(PRE_ARGS); |
static int check_text(struct mdoc *, |
static int check_text(struct mdoc *, int, int, const char *); |
int, int, const char *); |
|
static int check_argv(struct mdoc *, |
static int check_argv(struct mdoc *, |
const struct mdoc_node *, |
const struct mdoc_node *, |
const struct mdoc_argv *); |
const struct mdoc_argv *); |
Line 139 static int ewarn_ge1(POST_ARGS); |
|
Line 139 static int ewarn_ge1(POST_ARGS); |
|
static int ebool(POST_ARGS); |
static int ebool(POST_ARGS); |
|
|
static int post_an(POST_ARGS); |
static int post_an(POST_ARGS); |
|
static int post_args(POST_ARGS); |
static int post_at(POST_ARGS); |
static int post_at(POST_ARGS); |
static int post_bf(POST_ARGS); |
static int post_bf(POST_ARGS); |
static int post_bl(POST_ARGS); |
static int post_bl(POST_ARGS); |
static int post_ex(POST_ARGS); |
|
static int post_it(POST_ARGS); |
static int post_it(POST_ARGS); |
static int post_nm(POST_ARGS); |
static int post_nm(POST_ARGS); |
static int post_root(POST_ARGS); |
static int post_root(POST_ARGS); |
Line 151 static int post_sh_body(POST_ARGS); |
|
Line 151 static int post_sh_body(POST_ARGS); |
|
static int post_sh_head(POST_ARGS); |
static int post_sh_head(POST_ARGS); |
static int post_st(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_an[] = { pre_an, NULL }; |
static v_pre pres_bd[] = { pre_display, pre_bd, NULL }; |
static v_pre pres_bd[] = { pre_display, pre_bd, NULL }; |
static v_pre pres_bl[] = { pre_bl, NULL }; |
static v_pre pres_bl[] = { pre_bl, NULL }; |
Line 180 static v_post posts_in[] = { ewarn_eq1, NULL }; |
|
Line 185 static v_post posts_in[] = { ewarn_eq1, NULL }; |
|
static v_post posts_ss[] = { herr_ge1, NULL }; |
static v_post posts_ss[] = { herr_ge1, NULL }; |
static v_post posts_pf[] = { eerr_eq1, NULL }; |
static v_post posts_pf[] = { eerr_eq1, NULL }; |
static v_post posts_lb[] = { eerr_eq1, NULL }; |
static v_post posts_lb[] = { eerr_eq1, NULL }; |
static v_post posts_mt[] = { eerr_ge1, NULL }; |
|
static v_post posts_st[] = { eerr_eq1, post_st, NULL }; |
static v_post posts_st[] = { eerr_eq1, post_st, NULL }; |
static v_post posts_pp[] = { ewarn_eq0, NULL }; |
static v_post posts_pp[] = { ewarn_eq0, NULL }; |
static v_post posts_ex[] = { eerr_eq0, post_ex, NULL }; |
static v_post posts_ex[] = { eerr_eq0, post_args, NULL }; |
|
static v_post posts_rv[] = { eerr_eq0, post_args, NULL }; |
static v_post posts_an[] = { post_an, NULL }; |
static v_post posts_an[] = { post_an, NULL }; |
static v_post posts_at[] = { post_at, NULL }; |
static v_post posts_at[] = { post_at, NULL }; |
static v_post posts_xr[] = { eerr_ge1, eerr_le2, NULL }; |
static v_post posts_xr[] = { eerr_ge1, eerr_le2, NULL }; |
static v_post posts_lk[] = { eerr_ge1, NULL }; |
|
static v_post posts_nm[] = { post_nm, NULL }; |
static v_post posts_nm[] = { post_nm, NULL }; |
static v_post posts_bf[] = { hwarn_le1, post_bf, 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_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] = { |
const struct valids mdoc_valids[MDOC_MAX] = { |
{ NULL, NULL }, /* \" */ |
{ NULL, NULL }, /* \" */ |
Line 215 const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 216 const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Ar */ |
{ NULL, NULL }, /* Ar */ |
{ pres_cd, posts_text }, /* Cd */ |
{ pres_cd, posts_text }, /* Cd */ |
{ NULL, NULL }, /* Cm */ |
{ NULL, NULL }, /* Cm */ |
{ NULL, posts_text }, /* Dv */ |
{ NULL, NULL }, /* Dv */ |
{ pres_er, posts_text }, /* Er */ |
{ pres_er, posts_text }, /* Er */ |
{ NULL, posts_text }, /* Ev */ |
{ NULL, NULL }, /* Ev */ |
{ pres_ex, posts_ex }, /* Ex */ |
{ pres_ex, posts_ex }, /* Ex */ |
{ NULL, posts_text }, /* Fa */ |
{ NULL, NULL }, /* Fa */ |
{ pres_fd, posts_fd }, /* Fd */ |
{ pres_fd, posts_wtext }, /* Fd */ |
{ NULL, NULL }, /* Fl */ |
{ NULL, NULL }, /* Fl */ |
{ NULL, posts_text }, /* Fn */ |
{ NULL, posts_text }, /* Fn */ |
{ NULL, posts_wtext }, /* Ft */ |
{ NULL, posts_wtext }, /* Ft */ |
{ NULL, posts_text }, /* Ic */ |
{ NULL, posts_text }, /* Ic */ |
{ NULL, posts_in }, /* In */ |
{ NULL, posts_in }, /* In */ |
{ NULL, posts_text }, /* Li */ |
{ NULL, NULL }, /* Li */ |
{ NULL, posts_wtext }, /* Nd */ |
{ NULL, posts_wtext }, /* Nd */ |
{ NULL, posts_nm }, /* Nm */ |
{ NULL, posts_nm }, /* Nm */ |
{ NULL, posts_wline }, /* Op */ |
{ NULL, posts_wline }, /* Op */ |
{ NULL, NULL }, /* Ot */ |
{ NULL, NULL }, /* Ot */ |
{ NULL, NULL }, /* Pa */ |
{ NULL, NULL }, /* Pa */ |
{ pres_rv, posts_notext }, /* Rv */ |
{ pres_rv, posts_rv }, /* Rv */ |
{ NULL, posts_st }, /* St */ |
{ NULL, posts_st }, /* St */ |
{ NULL, posts_text }, /* Va */ |
{ NULL, NULL }, /* Va */ |
{ NULL, posts_text }, /* Vt */ |
{ NULL, posts_text }, /* Vt */ |
{ NULL, posts_xr }, /* Xr */ |
{ NULL, posts_xr }, /* Xr */ |
{ NULL, posts_text }, /* %A */ |
{ NULL, posts_text }, /* %A */ |
Line 264 const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 265 const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, posts_wline }, /* Dq */ |
{ NULL, posts_wline }, /* Dq */ |
{ NULL, NULL }, /* Ec */ |
{ NULL, NULL }, /* Ec */ |
{ NULL, NULL }, /* Ef */ |
{ NULL, NULL }, /* Ef */ |
{ NULL, posts_text }, /* Em */ |
{ NULL, NULL }, /* Em */ |
{ NULL, NULL }, /* Eo */ |
{ NULL, NULL }, /* Eo */ |
{ NULL, NULL }, /* Fx */ |
{ NULL, NULL }, /* Fx */ |
{ NULL, posts_text }, /* Ms */ |
{ NULL, posts_text }, /* Ms */ |
Line 281 const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 282 const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Qo */ |
{ NULL, NULL }, /* Qo */ |
{ NULL, posts_wline }, /* Qq */ |
{ NULL, posts_wline }, /* Qq */ |
{ NULL, NULL }, /* Re */ |
{ NULL, NULL }, /* Re */ |
{ NULL, posts_rs }, /* Rs */ |
{ NULL, posts_wline }, /* Rs */ |
{ NULL, NULL }, /* Sc */ |
{ NULL, NULL }, /* Sc */ |
{ NULL, NULL }, /* So */ |
{ NULL, NULL }, /* So */ |
{ NULL, posts_wline }, /* Sq */ |
{ NULL, posts_wline }, /* Sq */ |
Line 296 const struct valids mdoc_valids[MDOC_MAX] = { |
|
Line 297 const struct valids mdoc_valids[MDOC_MAX] = { |
|
{ NULL, NULL }, /* Fc */ |
{ NULL, NULL }, /* Fc */ |
{ NULL, NULL }, /* Oo */ |
{ NULL, NULL }, /* Oo */ |
{ NULL, NULL }, /* Oc */ |
{ NULL, NULL }, /* Oc */ |
{ NULL, posts_bk }, /* Bk */ |
{ NULL, posts_wline }, /* Bk */ |
{ NULL, NULL }, /* Ek */ |
{ NULL, NULL }, /* Ek */ |
{ NULL, posts_notext }, /* Bt */ |
{ NULL, posts_notext }, /* Bt */ |
{ NULL, NULL }, /* Hf */ |
{ NULL, NULL }, /* Hf */ |
{ NULL, NULL }, /* Fr */ |
{ NULL, NULL }, /* Fr */ |
{ NULL, posts_notext }, /* Ud */ |
{ NULL, posts_notext }, /* Ud */ |
{ pres_lb, posts_lb }, /* Lb */ |
{ pres_lb, posts_lb }, /* Lb */ |
{ NULL, NULL }, /* Lb */ |
{ NULL, NULL }, /* Ap */ |
{ NULL, posts_pp }, /* Pp */ |
{ NULL, posts_pp }, /* Lp */ |
{ NULL, posts_lk }, /* Lk */ |
{ NULL, posts_text }, /* Lk */ |
{ NULL, posts_mt }, /* Mt */ |
{ NULL, posts_text }, /* Mt */ |
|
{ NULL, posts_wline }, /* Brq */ |
|
{ NULL, NULL }, /* Bro */ |
|
{ NULL, NULL }, /* Brc */ |
|
{ NULL, posts_text }, /* %C */ |
|
{ NULL, NULL }, /* Es */ |
|
{ NULL, NULL }, /* En */ |
|
{ NULL, NULL }, /* Dx */ |
|
{ NULL, posts_text }, /* %Q */ |
}; |
}; |
|
|
|
|
int |
int |
mdoc_valid_pre(struct mdoc *mdoc, |
mdoc_valid_pre(struct mdoc *mdoc, |
const struct mdoc_node *node) |
const struct mdoc_node *n) |
{ |
{ |
v_pre *p; |
v_pre *p; |
int line, pos; |
int line, pos; |
const char *tp; |
const char *tp; |
|
|
if (MDOC_TEXT == node->type) { |
if (MDOC_TEXT == n->type) { |
tp = node->string; |
tp = n->string; |
line = node->line; |
line = n->line; |
pos = node->pos; |
pos = n->pos; |
return(check_text(mdoc, line, pos, tp)); |
return(check_text(mdoc, line, pos, tp)); |
} |
} |
|
|
if ( ! check_args(mdoc, node)) |
if ( ! check_args(mdoc, n)) |
return(0); |
return(0); |
if (NULL == mdoc_valids[node->tok].pre) |
if (NULL == mdoc_valids[n->tok].pre) |
return(1); |
return(1); |
for (p = mdoc_valids[node->tok].pre; *p; p++) |
for (p = mdoc_valids[n->tok].pre; *p; p++) |
if ( ! (*p)(mdoc, node)) |
if ( ! (*p)(mdoc, n)) |
return(0); |
return(0); |
return(1); |
return(1); |
} |
} |
Line 368 mdoc_valid_post(struct mdoc *mdoc) |
|
Line 377 mdoc_valid_post(struct mdoc *mdoc) |
|
} |
} |
|
|
|
|
#define merr(m, t) nerr((m), (m)->last, (t)) |
|
static int |
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; |
char *p; |
|
|
p = NULL; |
p = NULL; |
|
|
switch (type) { |
switch (type) { |
|
case (EESCAPE): |
|
p = "invalid escape sequence"; |
|
break; |
|
case (EPRINT): |
|
p = "invalid character"; |
|
break; |
case (ENESTDISP): |
case (ENESTDISP): |
p = "displays may not be nested"; |
p = "displays may not be nested"; |
break; |
break; |
Line 414 nerr(struct mdoc *m, const struct mdoc_node *n, enum m |
|
Line 427 nerr(struct mdoc *m, const struct mdoc_node *n, enum m |
|
p = "default name not yet set"; |
p = "default name not yet set"; |
break; |
break; |
} |
} |
|
|
assert(p); |
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 |
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; |
char *p; |
enum mdoc_warn c; |
enum mdoc_warn c; |
|
|
c = WARN_SYNTAX; |
c = WARN_SYNTAX; |
p = NULL; |
p = NULL; |
|
|
switch (type) { |
switch (type) { |
case (WBADMSEC): |
case (WBADMSEC): |
p = "inappropriate manual section"; |
p = "inappropriate manual section"; |
Line 451 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
Line 461 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
p = "prologue macros out-of-order"; |
p = "prologue macros out-of-order"; |
c = WARN_COMPAT; |
c = WARN_COMPAT; |
break; |
break; |
|
case (WESCAPE): |
|
p = "invalid escape sequence"; |
|
break; |
case (WNOLINE): |
case (WNOLINE): |
p = "suggested no line arguments"; |
p = "suggested no line arguments"; |
break; |
break; |
Line 481 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
Line 494 nwarn(struct mdoc *m, const struct mdoc_node *n, enum |
|
break; |
break; |
} |
} |
assert(p); |
assert(p); |
return(mdoc_nwarn(m, n, c, p)); |
return(mdoc_pwarn(m, line, pos, c, p)); |
} |
} |
|
|
|
|
Line 666 check_argv(struct mdoc *m, const struct mdoc_node *n, |
|
Line 679 check_argv(struct mdoc *m, const struct mdoc_node *n, |
|
if ( ! check_text(m, v->line, v->pos, v->value[i])) |
if ( ! check_text(m, v->line, v->pos, v->value[i])) |
return(0); |
return(0); |
|
|
if (MDOC_Std == v->arg && MDOC_Ex == n->tok) { |
if (MDOC_Std == v->arg) { |
/* `Nm' name must be set. */ |
/* `Nm' name must be set. */ |
if (v->sz || m->meta.name) |
if (v->sz || m->meta.name) |
return(1); |
return(1); |
Line 682 check_text(struct mdoc *mdoc, int line, int pos, const |
|
Line 695 check_text(struct mdoc *mdoc, int line, int pos, const |
|
{ |
{ |
size_t c; |
size_t c; |
|
|
/* XXX - indicate deprecated escapes \*(xx and \*x. */ |
/* FIXME: indicate deprecated escapes \*(xx and \*x. */ |
|
|
for ( ; *p; p++) { |
for ( ; *p; p++) { |
if ( ! isprint((u_char)*p) && '\t' != *p) |
if ('\t' == *p) { |
return(mdoc_perr(mdoc, line, pos, |
if ( ! (MDOC_LITERAL & mdoc->flags)) |
"invalid non-printing character")); |
return(perr(mdoc, line, pos, EPRINT)); |
|
} else if ( ! isprint((u_char)*p)) |
|
return(perr(mdoc, line, pos, EPRINT)); |
|
|
if ('\\' != *p) |
if ('\\' != *p) |
continue; |
continue; |
if ((c = mdoc_isescape(p))) { |
|
|
c = mdoc_isescape(p); |
|
if (c) { |
p += (int)c - 1; |
p += (int)c - 1; |
continue; |
continue; |
} |
} |
if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) |
if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags)) |
return(mdoc_perr(mdoc, line, pos, |
return(perr(mdoc, line, pos, EESCAPE)); |
"invalid escape sequence")); |
if ( ! pwarn(mdoc, line, pos, WESCAPE)) |
if ( ! mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX, |
|
"invalid escape sequence")) |
|
return(0); |
return(0); |
} |
} |
|
|
Line 1081 post_an(POST_ARGS) |
|
Line 1097 post_an(POST_ARGS) |
|
|
|
|
|
static int |
static int |
post_ex(POST_ARGS) |
post_args(POST_ARGS) |
{ |
{ |
|
|
if (mdoc->last->args) |
if (mdoc->last->args) |
Line 1184 post_it(POST_ARGS) |
|
Line 1200 post_it(POST_ARGS) |
|
if (mdoc->last->body->child) |
if (mdoc->last->body->child) |
if ( ! mwarn(mdoc, WNOMULTILINE)) |
if ( ! mwarn(mdoc, WNOMULTILINE)) |
return(0); |
return(0); |
c = mdoc->last->head->child; |
c = mdoc->last->child; |
for (i = 0; c; c = c->next) |
for (i = 0; c && MDOC_HEAD == c->type; c = c->next) |
i++; |
i++; |
if (i == cols) |
if (i == cols) |
break; |
break; |
if ( ! mdoc_warn(mdoc, WARN_SYNTAX, |
return(mdoc_err(mdoc, "column mismatch (have " |
"column mismatch (have %d, want %d)", i, cols)) |
"%d, want %d)", i, cols)); |
return(0); |
|
break; |
|
default: |
default: |
break; |
break; |
} |
} |