version 1.16, 2009/01/05 14:14:04 |
version 1.22, 2009/01/09 15:07:04 |
|
|
|
|
#include "private.h" |
#include "private.h" |
|
|
/* FIXME: `.St' can only have one argument set. */ |
|
|
|
typedef int (*v_args_sz)(struct mdoc *, int, int, int); |
typedef int (*v_pre)(struct mdoc *, struct mdoc_node *); |
typedef int (*v_args)(struct mdoc *, int, int, |
typedef int (*v_post)(struct mdoc *); |
int, const char *[], |
|
int, const struct mdoc_arg *); |
|
typedef int (*v_tree)(struct mdoc *, int, int); |
|
|
|
|
|
struct valids { |
struct valids { |
v_args_sz sz; |
v_pre pre; |
v_args args; |
v_post *post; |
v_tree tree_pre; |
|
v_tree tree_post; |
|
}; |
}; |
|
|
|
|
static int assert_eq0(struct mdoc *, int, int, int); |
static int pre_prologue(struct mdoc *, struct mdoc_node *); |
static int assert_le1(struct mdoc *, int, int, int); |
static int pre_prologue(struct mdoc *, struct mdoc_node *); |
static int need_eq0(struct mdoc *, int, int, int); |
static int pre_prologue(struct mdoc *, struct mdoc_node *); |
static int need_eq1(struct mdoc *, int, int, int); |
static int post_headchild_err_ge1(struct mdoc *); |
static int need_ge1(struct mdoc *, int, int, int); |
static int post_elemchild_err_ge1(struct mdoc *); |
static int need_le2(struct mdoc *, int, int, int); |
static int post_elemchild_warn_eq0(struct mdoc *); |
static int want_eq0(struct mdoc *, int, int, int); |
static int post_bodychild_warn_ge1(struct mdoc *); |
static int want_ge1(struct mdoc *, int, int, int); |
static int post_sh(struct mdoc *); |
|
|
static int tree_pre_ref(struct mdoc *, int, int); |
static v_post posts_sh[] = { post_headchild_err_ge1, |
static int tree_pre_display(struct mdoc *, int, int); |
post_bodychild_warn_ge1, post_sh, NULL }; |
|
static v_post posts_ss[] = { post_headchild_err_ge1, NULL }; |
|
static v_post posts_pp[] = { post_elemchild_warn_eq0, NULL }; |
|
static v_post posts_dd[] = { post_elemchild_err_ge1, NULL }; |
|
|
static int tree_post_onlyhead(struct mdoc *, int, int); |
|
static int tree_post_onlybody(struct mdoc *, int, int); |
|
static int tree_post_warnemptybody(struct mdoc *, int, int); |
|
|
|
static int args_bool(struct mdoc *, int, int, |
|
int, const char *[], |
|
int, const struct mdoc_arg *); |
|
static int args_sh(struct mdoc *, int, int, |
|
int, const char *[], |
|
int, const struct mdoc_arg *); |
|
static int args_an(struct mdoc *, int, int, |
|
int, const char *[], |
|
int, const struct mdoc_arg *); |
|
static int args_nopunct(struct mdoc *, int, int, |
|
int, const char *[], |
|
int, const struct mdoc_arg *); |
|
static int args_xr(struct mdoc *, int, int, |
|
int, const char *[], |
|
int, const struct mdoc_arg *); |
|
|
|
|
|
const struct valids mdoc_valids[MDOC_MAX] = { |
const struct valids mdoc_valids[MDOC_MAX] = { |
{ NULL, NULL, NULL, NULL }, /* \" */ |
{ NULL, NULL }, /* \" */ |
{ NULL, NULL, NULL, NULL }, /* Dd */ /* TODO */ |
{ pre_prologue, posts_dd }, /* Dd */ |
{ NULL, NULL, NULL, NULL }, /* Dt */ /* TODO */ |
{ pre_prologue, NULL }, /* Dt */ |
{ NULL, NULL, NULL, NULL }, /* Os */ /* TODO */ |
{ pre_prologue, NULL }, /* Os */ |
{ want_ge1, args_sh, NULL, NULL }, /* Sh */ /* FIXME: preceding Pp. */ |
{ NULL, posts_sh }, /* Sh */ /* FIXME: preceding Pp. */ |
{ want_ge1, NULL, NULL, NULL }, /* Ss */ /* FIXME: preceding Pp. */ |
{ NULL, posts_ss }, /* Ss */ /* FIXME: preceding Pp. */ |
{ want_eq0, NULL, NULL, NULL }, /* Pp */ |
{ NULL, posts_pp }, /* Pp */ /* FIXME: proceeding... */ |
{ assert_eq0, NULL, tree_pre_display, tree_post_onlyhead }, /* D1 */ |
{ NULL, NULL }, /* D1 */ |
{ assert_eq0, NULL, tree_pre_display, tree_post_onlyhead }, /* Dl */ |
{ NULL, NULL }, /* Dl */ |
{ want_eq0, NULL, tree_pre_display, tree_post_warnemptybody }, /* Bd */ /* FIXME: preceding Pp. */ |
{ NULL, NULL }, /* Bd */ /* FIXME: preceding Pp. */ |
{ assert_eq0, NULL, NULL, tree_post_onlybody }, /* Ed */ |
{ NULL, NULL }, /* Ed */ |
{ want_eq0, NULL, NULL, NULL }, /* Bl */ /* FIXME: preceding Pp. */ |
{ NULL, NULL }, /* Bl */ /* FIXME: preceding Pp. */ |
{ assert_eq0, NULL, NULL, tree_post_onlybody }, /* El */ |
{ NULL, NULL }, /* El */ |
{ NULL, NULL, NULL, NULL }, /* It */ |
{ NULL, NULL }, /* It */ |
{ need_ge1, NULL, NULL, NULL }, /* Ad */ |
{ NULL, NULL }, /* Ad */ |
{ NULL, args_an, NULL, NULL }, /* An */ |
{ NULL, NULL }, /* An */ |
{ NULL, NULL, NULL, NULL }, /* Ar */ |
{ NULL, NULL }, /* Ar */ |
{ need_ge1, NULL, NULL, NULL }, /* Cd */ |
{ NULL, NULL }, /* Cd */ |
{ NULL, NULL, NULL, NULL }, /* Cm */ |
{ NULL, NULL }, /* Cm */ |
{ need_ge1, NULL, NULL, NULL }, /* Dv */ |
{ NULL, NULL }, /* Dv */ |
{ need_ge1, NULL, NULL, NULL }, /* Er */ |
{ NULL, NULL }, /* Er */ |
{ need_ge1, NULL, NULL, NULL }, /* Ev */ |
{ NULL, NULL }, /* Ev */ |
{ NULL, NULL, NULL, NULL }, /* Ex */ |
{ NULL, NULL }, /* Ex */ |
{ need_ge1, NULL, NULL, NULL }, /* Fa */ |
{ NULL, NULL }, /* Fa */ |
{ NULL, NULL, NULL, NULL }, /* Fd */ |
{ NULL, NULL }, /* Fd */ |
{ NULL, NULL, NULL, NULL }, /* Fl */ |
{ NULL, NULL }, /* Fl */ |
{ need_ge1, NULL, NULL, NULL }, /* Fn */ |
{ NULL, NULL }, /* Fn */ |
{ want_ge1, NULL, NULL, NULL }, /* Ft */ |
{ NULL, NULL }, /* Ft */ |
{ need_ge1, NULL, NULL, NULL }, /* Ic */ |
{ NULL, NULL }, /* Ic */ |
{ need_eq1, NULL, NULL, NULL }, /* In */ |
{ NULL, NULL }, /* In */ |
{ want_ge1, NULL, NULL, NULL }, /* Li */ |
{ NULL, NULL }, /* Li */ |
{ want_ge1, NULL, NULL, NULL }, /* Nd */ |
{ NULL, NULL }, /* Nd */ |
{ NULL, NULL, NULL, NULL }, /* Nm */ |
{ NULL, NULL }, /* Nm */ |
{ NULL, NULL, NULL, NULL }, /* Op */ |
{ NULL, NULL }, /* Op */ |
{ NULL, NULL, NULL, NULL }, /* Ot */ |
{ NULL, NULL }, /* Ot */ |
{ want_ge1, NULL, NULL, NULL }, /* Pa */ |
{ NULL, NULL }, /* Pa */ |
{ NULL, NULL, NULL, NULL }, /* Rv */ |
{ NULL, NULL }, /* Rv */ |
{ NULL, NULL, NULL, NULL }, /* St */ |
{ NULL, NULL }, /* St */ |
{ need_ge1, NULL, NULL, NULL }, /* Va */ |
{ NULL, NULL }, /* Va */ |
{ need_ge1, NULL, NULL, NULL }, /* Vt */ |
{ NULL, NULL }, /* Vt */ |
{ need_le2, args_xr, NULL, NULL }, /* Xr */ |
{ NULL, NULL }, /* Xr */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %A */ |
{ NULL, NULL }, /* %A */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %B */ |
{ NULL, NULL }, /* %B */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %D */ |
{ NULL, NULL }, /* %D */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %I */ |
{ NULL, NULL }, /* %I */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %J */ |
{ NULL, NULL }, /* %J */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %N */ |
{ NULL, NULL }, /* %N */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %O */ |
{ NULL, NULL }, /* %O */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %P */ |
{ NULL, NULL }, /* %P */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %R */ |
{ NULL, NULL }, /* %R */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %T */ |
{ NULL, NULL }, /* %T */ |
{ need_ge1, NULL, tree_pre_ref, NULL }, /* %V */ |
{ NULL, NULL }, /* %V */ |
{ NULL, NULL, NULL, NULL }, /* Ac */ |
{ NULL, NULL }, /* Ac */ |
{ NULL, NULL, NULL, NULL }, /* Ao */ |
{ NULL, NULL }, /* Ao */ |
{ NULL, NULL, NULL, NULL }, /* Aq */ |
{ NULL, NULL }, /* Aq */ |
{ need_le2, args_nopunct, NULL, NULL }, /* At */ /* FIXME */ |
{ NULL, NULL }, /* At */ /* FIXME */ |
{ NULL, NULL, NULL, NULL }, /* Bc */ |
{ NULL, NULL }, /* Bc */ |
{ NULL, NULL, NULL, NULL }, /* Bf */ |
{ NULL, NULL }, /* Bf */ |
{ NULL, NULL, NULL, NULL }, /* Bo */ |
{ NULL, NULL }, /* Bo */ |
{ NULL, NULL, NULL, NULL }, /* Bq */ |
{ NULL, NULL }, /* Bq */ |
{ assert_le1, NULL, NULL, NULL }, /* Bsx */ |
{ NULL, NULL }, /* Bsx */ |
{ assert_le1, NULL, NULL, NULL }, /* Bx */ |
{ NULL, NULL }, /* Bx */ |
{ need_eq1, args_bool, NULL, NULL }, /* Db */ |
{ NULL, NULL }, /* Db */ |
{ NULL, NULL, NULL, NULL }, /* Dc */ |
{ NULL, NULL }, /* Dc */ |
{ NULL, NULL, NULL, NULL }, /* Do */ |
{ NULL, NULL }, /* Do */ |
{ NULL, NULL, NULL, NULL }, /* Dq */ |
{ NULL, NULL }, /* Dq */ |
{ NULL, NULL, NULL, NULL }, /* Ec */ |
{ NULL, NULL }, /* Ec */ |
{ NULL, NULL, NULL, NULL }, /* Ef */ /* -symbolic, etc. */ |
{ NULL, NULL }, /* Ef */ /* -symbolic, etc. */ |
{ need_ge1, NULL, NULL, NULL }, /* Em */ |
{ NULL, NULL }, /* Em */ |
{ NULL, NULL, NULL, NULL }, /* Eo */ |
{ NULL, NULL }, /* Eo */ |
{ assert_le1, NULL, NULL, NULL }, /* Fx */ |
{ NULL, NULL }, /* Fx */ |
{ want_ge1, NULL, NULL, NULL }, /* Ms */ |
{ NULL, NULL }, /* Ms */ |
{ NULL, NULL, NULL, NULL }, /* No */ |
{ NULL, NULL }, /* No */ |
{ NULL, NULL, NULL, NULL }, /* Ns */ |
{ NULL, NULL }, /* Ns */ |
{ assert_le1, NULL, NULL, NULL }, /* Nx */ |
{ NULL, NULL }, /* Nx */ |
{ assert_le1, NULL, NULL, NULL }, /* Ox */ |
{ NULL, NULL }, /* Ox */ |
{ NULL, NULL, NULL, NULL }, /* Pc */ |
{ NULL, NULL }, /* Pc */ |
{ NULL, NULL, NULL, NULL }, /* Pf */ /* 2 or more arguments */ |
{ NULL, NULL }, /* Pf */ /* 2 or more arguments */ |
{ NULL, NULL, NULL, NULL }, /* Po */ |
{ NULL, NULL }, /* Po */ |
{ NULL, NULL, NULL, NULL }, /* Pq */ /* FIXME: ignore following Sh/Ss */ |
{ NULL, NULL }, /* Pq */ /* FIXME: ignore following Sh/Ss */ |
{ NULL, NULL, NULL, NULL }, /* Qc */ |
{ NULL, NULL }, /* Qc */ |
{ NULL, NULL, NULL, NULL }, /* Ql */ |
{ NULL, NULL }, /* Ql */ |
{ NULL, NULL, NULL, NULL }, /* Qo */ |
{ NULL, NULL }, /* Qo */ |
{ NULL, NULL, NULL, NULL }, /* Qq */ |
{ NULL, NULL }, /* Qq */ |
{ NULL, NULL, NULL, NULL }, /* Re */ |
{ NULL, NULL }, /* Re */ |
{ NULL, NULL, NULL, NULL }, /* Rs */ |
{ NULL, NULL }, /* Rs */ |
{ NULL, NULL, NULL, NULL }, /* Sc */ |
{ NULL, NULL }, /* Sc */ |
{ NULL, NULL, NULL, NULL }, /* So */ |
{ NULL, NULL }, /* So */ |
{ NULL, NULL, NULL, NULL }, /* Sq */ |
{ NULL, NULL }, /* Sq */ |
{ need_eq1, args_bool, NULL, NULL }, /* Sm */ |
{ NULL, NULL }, /* Sm */ |
{ need_ge1, NULL, NULL, NULL }, /* Sx */ |
{ NULL, NULL }, /* Sx */ |
{ need_ge1, NULL, NULL, NULL }, /* Sy */ |
{ NULL, NULL }, /* Sy */ |
{ want_ge1, NULL, NULL, NULL }, /* Tn */ |
{ NULL, NULL }, /* Tn */ |
{ assert_eq0, NULL, NULL, NULL }, /* Ux */ |
{ NULL, NULL }, /* Ux */ |
{ NULL, NULL, NULL, NULL }, /* Xc */ |
{ NULL, NULL }, /* Xc */ |
{ NULL, NULL, NULL, NULL }, /* Xo */ |
{ NULL, NULL }, /* Xo */ |
{ NULL, NULL, NULL, NULL }, /* Fo */ |
{ NULL, NULL }, /* Fo */ |
{ NULL, NULL, NULL, NULL }, /* Fc */ |
{ NULL, NULL }, /* Fc */ |
{ NULL, NULL, NULL, NULL }, /* Oo */ |
{ NULL, NULL }, /* Oo */ |
{ NULL, NULL, NULL, NULL }, /* Oc */ |
{ NULL, NULL }, /* Oc */ |
{ NULL, NULL, NULL, NULL }, /* Bk */ |
{ NULL, NULL }, /* Bk */ |
{ NULL, NULL, NULL, NULL }, /* Ek */ |
{ NULL, NULL }, /* Ek */ |
{ need_eq0, NULL, NULL, NULL }, /* Bt */ |
{ NULL, NULL }, /* Bt */ |
{ need_eq1, NULL, NULL, NULL }, /* Hf */ |
{ NULL, NULL }, /* Hf */ |
{ NULL, NULL, NULL, NULL }, /* Fr */ |
{ NULL, NULL }, /* Fr */ |
{ need_eq0, NULL, NULL, NULL }, /* Ud */ |
{ NULL, NULL }, /* Ud */ |
}; |
}; |
|
|
|
|
static int |
static int |
need_le2(struct mdoc *mdoc, int tok, int pos, int sz) |
post_bodychild_warn_ge1(struct mdoc *mdoc) |
{ |
{ |
if (sz <= 2) |
|
return(1); |
|
return(mdoc_err(mdoc, tok, pos, ERR_ARGS_LE2)); |
|
} |
|
|
|
|
if (MDOC_BODY != mdoc->last->type) |
static int |
|
want_ge1(struct mdoc *mdoc, int tok, int pos, int sz) |
|
{ |
|
if (sz > 0) |
|
return(1); |
return(1); |
return(mdoc_warn(mdoc, tok, pos, WARN_ARGS_GE1)); |
if (mdoc->last->child) |
} |
|
|
|
|
|
static int |
|
want_eq0(struct mdoc *mdoc, int tok, int pos, int sz) |
|
{ |
|
if (sz == 0) |
|
return(1); |
return(1); |
return(mdoc_warn(mdoc, tok, pos, WARN_ARGS_EQ0)); |
|
} |
|
|
|
|
return(mdoc_warn(mdoc, WARN_ARGS_GE1)); |
static int |
|
need_eq0(struct mdoc *mdoc, int tok, int pos, int sz) |
|
{ |
|
if (sz == 0) |
|
return(1); |
|
return(mdoc_err(mdoc, tok, pos, ERR_ARGS_EQ0)); |
|
} |
} |
|
|
|
|
static int |
static int |
assert_le1(struct mdoc *mdoc, int tok, int pos, int sz) |
post_elemchild_warn_eq0(struct mdoc *mdoc) |
{ |
{ |
|
|
assert(sz <= 1); |
assert(MDOC_ELEM == mdoc->last->type); |
return(1); |
if (NULL == mdoc->last->child) |
|
return(1); |
|
return(mdoc_warn(mdoc, WARN_ARGS_EQ0)); |
} |
} |
|
|
|
|
static int |
static int |
assert_eq0(struct mdoc *mdoc, int tok, int pos, int sz) |
post_elemchild_err_ge1(struct mdoc *mdoc) |
{ |
{ |
|
|
assert(sz == 0); |
assert(MDOC_ELEM == mdoc->last->type); |
return(1); |
if (mdoc->last->child) |
|
return(1); |
|
return(mdoc_err(mdoc, ERR_ARGS_GE1)); |
} |
} |
|
|
|
|
static int |
static int |
need_eq1(struct mdoc *mdoc, int tok, int pos, int sz) |
post_headchild_err_ge1(struct mdoc *mdoc) |
{ |
{ |
if (sz == 1) |
|
|
if (MDOC_HEAD != mdoc->last->type) |
return(1); |
return(1); |
return(mdoc_err(mdoc, tok, pos, ERR_ARGS_EQ1)); |
if (mdoc->last->child) |
|
return(1); |
|
return(mdoc_err(mdoc, ERR_ARGS_GE1)); |
} |
} |
|
|
|
|
static int |
static int |
need_ge1(struct mdoc *mdoc, int tok, int pos, int sz) |
pre_prologue(struct mdoc *mdoc, struct mdoc_node *node) |
{ |
{ |
if (sz > 0) |
|
return(1); |
|
return(mdoc_err(mdoc, tok, pos, ERR_ARGS_GE1)); |
|
} |
|
|
|
|
if (SEC_PROLOGUE != mdoc->sec_lastn) |
|
return(mdoc_verr(mdoc, node, ERR_SEC_NPROLOGUE)); |
|
assert(MDOC_ELEM == node->type); |
|
|
static int |
/* Check for ordering. */ |
tree_post_onlybody(struct mdoc *mdoc, int tok, int pos) |
|
{ |
|
struct mdoc_node *n; |
|
|
|
assert(mdoc->last); |
switch (node->data.elem.tok) { |
n = mdoc->last; |
case (MDOC_Os): |
|
if (mdoc->meta.title[0] && mdoc->meta.date) |
|
break; |
|
return(mdoc_verr(mdoc, node, ERR_SEC_PROLOGUE_OO)); |
|
case (MDOC_Dt): |
|
if (0 == mdoc->meta.title[0] && mdoc->meta.date) |
|
break; |
|
return(mdoc_verr(mdoc, node, ERR_SEC_PROLOGUE_OO)); |
|
case (MDOC_Dd): |
|
if (0 == mdoc->meta.title[0] && 0 == mdoc->meta.date) |
|
break; |
|
return(mdoc_verr(mdoc, node, ERR_SEC_PROLOGUE_OO)); |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
assert(MDOC_BLOCK == n->type); |
/* Check for repetition. */ |
assert(n->child); |
|
|
|
if (MDOC_BODY == n->child->type) { |
switch (node->data.elem.tok) { |
if (n->child->child) |
case (MDOC_Os): |
|
if (0 == mdoc->meta.os[0]) |
return(1); |
return(1); |
return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_EMPTYBODY)); |
break; |
|
case (MDOC_Dd): |
|
if (0 == mdoc->meta.date) |
|
return(1); |
|
break; |
|
case (MDOC_Dt): |
|
if (0 == mdoc->meta.title[0]) |
|
return(1); |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
} |
} |
|
|
return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_CHILDBODY)); |
return(mdoc_verr(mdoc, node, ERR_SEC_PROLOGUE_REP)); |
} |
} |
|
|
|
|
|
/* |
|
* Warn if sections (those that are with a known title, such as NAME, |
|
* DESCRIPTION, and so forth) are out of the conventional order. |
|
*/ |
static int |
static int |
tree_post_warnemptybody(struct mdoc *mdoc, int tok, int pos) |
post_sh(struct mdoc *mdoc) |
{ |
{ |
|
enum mdoc_sec sec; |
|
int i; |
struct mdoc_node *n; |
struct mdoc_node *n; |
|
char *args[MDOC_LINEARG_MAX]; |
|
|
assert(mdoc->last); |
if (MDOC_HEAD != mdoc->last->type) |
n = mdoc->last; |
|
|
|
assert(MDOC_BLOCK == n->type); |
|
assert(n->child); |
|
|
|
for (n = n->child; n; n = n->next) |
|
if (MDOC_BODY == n->type) |
|
break; |
|
|
|
if (n && n->child) |
|
return(1); |
return(1); |
return(mdoc_warn(mdoc, tok, pos, WARN_SYNTAX_EMPTYBODY)); |
|
} |
assert(MDOC_Sh == mdoc->last->data.head.tok); |
|
|
|
n = mdoc->last->child; |
|
assert(n); |
|
|
static int |
for (i = 0; n && i < MDOC_LINEARG_MAX; n = n->next, i++) { |
tree_post_onlyhead(struct mdoc *mdoc, int tok, int pos) |
assert(MDOC_TEXT == n->type); |
{ |
assert(NULL == n->child); |
struct mdoc_node *n; |
assert(n->data.text.string); |
|
args[i] = n->data.text.string; |
|
} |
|
|
assert(mdoc->last); |
sec = mdoc_atosec((size_t)i, (const char **)args); |
n = mdoc->last; |
if (SEC_CUSTOM == sec) |
|
|
assert(MDOC_BLOCK == n->type); |
|
assert(n->child); |
|
|
|
n = n->child; |
|
|
|
if (MDOC_HEAD != n->type) |
|
return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_CHILDHEAD)); |
|
if (n->child) |
|
return(1); |
return(1); |
return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_EMPTYHEAD)); |
if (sec > mdoc->sec_lastn) |
} |
return(1); |
|
|
|
if (sec == mdoc->sec_lastn) |
static int |
return(mdoc_warn(mdoc, WARN_SEC_REP)); |
args_an(struct mdoc *mdoc, int tok, int pos, |
return(mdoc_warn(mdoc, WARN_SEC_OO)); |
int sz, const char *args[], |
|
int argc, const struct mdoc_arg *argv) |
|
{ |
|
|
|
if (0 != argc && 0 != sz) |
|
return(mdoc_warn(mdoc, tok, pos, WARN_ARGS_EQ0)); |
|
return(1); |
|
} |
} |
|
|
|
|
static int |
int |
args_sh(struct mdoc *mdoc, int tok, int pos, |
mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *node) |
int sz, const char *args[], |
|
int argc, const struct mdoc_arg *argv) |
|
{ |
{ |
enum mdoc_sec sec; |
int t; |
|
|
sec = mdoc_atosec((size_t)sz, args); |
switch (node->type) { |
if (SEC_CUSTOM != sec && sec < mdoc->sec_lastn) |
case (MDOC_BODY): |
if ( ! mdoc_warn(mdoc, tok, pos, WARN_SEC_OO)) |
t = node->data.body.tok; |
return(0); |
break; |
if (SEC_BODY == mdoc->sec_last && SEC_NAME != sec) |
case (MDOC_ELEM): |
return(mdoc_err(mdoc, tok, pos, ERR_SEC_NAME)); |
t = node->data.elem.tok; |
|
break; |
return(1); |
case (MDOC_BLOCK): |
} |
t = node->data.block.tok; |
|
break; |
|
case (MDOC_HEAD): |
static int |
t = node->data.head.tok; |
args_bool(struct mdoc *mdoc, int tok, int pos, |
break; |
int sz, const char *args[], |
default: |
int argc, const struct mdoc_arg *argv) |
|
{ |
|
int i; |
|
|
|
for (i = 0; i < sz; i++) { |
|
if (xstrcmp(args[i], "on")) |
|
continue; |
|
if (xstrcmp(args[i], "off")) |
|
continue; |
|
return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_ARGBAD)); |
|
} |
|
return(1); |
|
} |
|
|
|
|
|
static int |
|
tree_pre_ref(struct mdoc *mdoc, int tok, int pos) |
|
{ |
|
struct mdoc_node *n; |
|
|
|
assert(mdoc->last); |
|
for (n = mdoc->last ; n; n = n->parent) { |
|
if (MDOC_BLOCK != n->type) |
|
continue; |
|
if (MDOC_Rs != n->data.block.tok) |
|
break; |
|
return(1); |
return(1); |
} |
} |
|
|
return(mdoc_err(mdoc, tok, pos, ERR_SCOPE_NOCTX)); |
if (NULL == mdoc_valids[t].pre) |
} |
|
|
|
|
|
static int |
|
args_xr(struct mdoc *mdoc, int tok, int pos, |
|
int sz, const char *args[], |
|
int argc, const struct mdoc_arg *argv) |
|
{ |
|
|
|
if (1 == sz) |
|
return(1); |
return(1); |
if (0 == sz) |
return((*mdoc_valids[t].pre)(mdoc, node)); |
return(mdoc_err(mdoc, tok, pos, ERR_ARGS_GE1)); |
|
if (MSEC_DEFAULT == mdoc_atomsec(args[1])) |
|
return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_ARGFORM)); |
|
return(1); |
|
} |
} |
|
|
|
|
static int |
int |
args_nopunct(struct mdoc *mdoc, int tok, int pos, |
mdoc_valid_post(struct mdoc *mdoc) |
int sz, const char *args[], |
|
int argc, const struct mdoc_arg *argv) |
|
{ |
{ |
int i; |
v_post *p; |
|
int t; |
|
|
if (0 == sz) |
switch (mdoc->last->type) { |
|
case (MDOC_BODY): |
|
t = mdoc->last->data.body.tok; |
|
break; |
|
case (MDOC_ELEM): |
|
t = mdoc->last->data.elem.tok; |
|
break; |
|
case (MDOC_BLOCK): |
|
t = mdoc->last->data.block.tok; |
|
break; |
|
case (MDOC_HEAD): |
|
t = mdoc->last->data.head.tok; |
|
break; |
|
default: |
return(1); |
return(1); |
|
|
i = 0; |
|
if (ATT_DEFAULT == mdoc_atoatt(args[i])) |
|
i++; |
|
for ( ; i < sz; i++) { |
|
if ( ! mdoc_isdelim(args[i])) |
|
continue; |
|
return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_NOPUNCT)); |
|
} |
} |
return(1); |
|
} |
|
|
|
|
if (NULL == mdoc_valids[t].post) |
static int |
|
tree_pre_display(struct mdoc *mdoc, int tok, int pos) |
|
{ |
|
struct mdoc_node *node; |
|
|
|
assert(mdoc->last); |
|
|
|
/* Displays may not be nested in other displays. */ |
|
|
|
/* LINTED */ |
|
for (node = mdoc->last; node; node = node->parent) { |
|
if (node->type != MDOC_BLOCK) |
|
continue; |
|
if (node->data.block.tok != MDOC_Bd) |
|
continue; |
|
break; |
|
} |
|
if (NULL == node) |
|
return(1); |
return(1); |
return(mdoc_err(mdoc, tok, pos, ERR_SCOPE_NONEST)); |
|
} |
|
|
|
|
for (p = mdoc_valids[t].post; *p; p++) |
int |
if ( ! (*p)(mdoc)) |
mdoc_valid_pre(struct mdoc *mdoc, int tok, int pos, |
return(0); |
int argc, const struct mdoc_arg *argv) |
|
{ |
|
|
|
return(1); |
|
} |
|
|
|
|
|
int |
|
mdoc_valid_post(struct mdoc *mdoc, int tok, int pos) |
|
{ |
|
|
|
return(1); |
return(1); |
} |
} |