=================================================================== RCS file: /cvs/mandoc/Attic/validate.c,v retrieving revision 1.39 retrieving revision 1.41 diff -u -p -r1.39 -r1.41 --- mandoc/Attic/validate.c 2009/01/19 17:02:59 1.39 +++ mandoc/Attic/validate.c 2009/01/19 23:11:12 1.41 @@ -1,4 +1,4 @@ -/* $Id: validate.c,v 1.39 2009/01/19 17:02:59 kristaps Exp $ */ +/* $Id: validate.c,v 1.41 2009/01/19 23:11:12 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -44,11 +44,11 @@ static int pre_check_msecs(struct mdoc *, struct mdoc_ int, enum mdoc_msec *); static int pre_check_stdarg(struct mdoc *, struct mdoc_node *); static int post_check_children_count(struct mdoc *); -static int post_check_children_lt(struct mdoc *, int); -static int post_check_children_gt(struct mdoc *, int); -static int post_check_children_wgt(struct mdoc *, int); -static int post_check_children_eq(struct mdoc *, int); -static int post_check_children_weq(struct mdoc *, int); +static int post_check_children_lt(struct mdoc *, const char *, int); +static int post_check_children_gt(struct mdoc *, const char *, int); +static int post_check_children_wgt(struct mdoc *, const char *, int); +static int post_check_children_eq(struct mdoc *, const char *, int); +static int post_check_children_weq(struct mdoc *, const char *, int); /* Specific pre-child-parse routines. */ @@ -71,6 +71,7 @@ static int pre_prologue(struct mdoc *, struct mdoc_nod /* Specific post-child-parse routines. */ static int herr_ge1(struct mdoc *); +static int herr_le1(struct mdoc *); static int hwarn_ge1(struct mdoc *); static int herr_eq0(struct mdoc *); static int eerr_eq0(struct mdoc *); @@ -92,6 +93,7 @@ static int post_an(struct mdoc *); static int post_at(struct mdoc *); static int post_xr(struct mdoc *); static int post_nm(struct mdoc *); +static int post_bf(struct mdoc *); static int post_root(struct mdoc *); /* Collections of pre-child-parse routines. */ @@ -130,6 +132,7 @@ static v_post posts_an[] = { post_an, NULL }; static v_post posts_at[] = { post_at, NULL }; static v_post posts_xr[] = { eerr_ge1, eerr_le2, post_xr, NULL }; static v_post posts_nm[] = { post_nm, NULL }; +static v_post posts_bf[] = { herr_le1, post_bf, NULL }; /* Per-macro pre- and post-child-check routine collections. */ @@ -193,7 +196,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, posts_wline }, /* Aq */ { NULL, posts_at }, /* At */ { NULL, NULL }, /* Bc */ - { NULL, NULL }, /* Bf */ /* FIXME */ + { NULL, posts_bf }, /* Bf */ /* FIXME */ { NULL, NULL }, /* Bo */ { NULL, posts_wline }, /* Bq */ { NULL, NULL }, /* Bsx */ @@ -258,62 +261,62 @@ post_check_children_count(struct mdoc *mdoc) static int -post_check_children_wgt(struct mdoc *mdoc, int sz) +post_check_children_wgt(struct mdoc *mdoc, const char *p, int sz) { int i; if ((i = post_check_children_count(mdoc)) > sz) return(1); return(mdoc_warn(mdoc, WARN_SYNTAX, "macro suggests more " - "than %d parameters (has %d)", sz, i)); + "than %d %s (has %d)", sz, p, i)); } static int -post_check_children_gt(struct mdoc *mdoc, int sz) +post_check_children_gt(struct mdoc *mdoc, const char *p, int sz) { int i; if ((i = post_check_children_count(mdoc)) > sz) return(1); return(mdoc_err(mdoc, "macro requires more than %d " - "parameters (has %d)", sz, i)); + "%s (has %d)", sz, p, i)); } static int -post_check_children_weq(struct mdoc *mdoc, int sz) +post_check_children_weq(struct mdoc *mdoc, const char *p, int sz) { int i; if ((i = post_check_children_count(mdoc)) == sz) return(1); return(mdoc_warn(mdoc, WARN_SYNTAX, "macro suggests %d " - "parameters (has %d)", sz, i)); + "%s (has %d)", sz, p, i)); } static int -post_check_children_eq(struct mdoc *mdoc, int sz) +post_check_children_eq(struct mdoc *mdoc, const char *p, int sz) { int i; if ((i = post_check_children_count(mdoc)) == sz) return(1); - return(mdoc_err(mdoc, "macro requires %d parameters " - "(have %d)", sz, i)); + return(mdoc_err(mdoc, "macro requires %d %s " + "(have %d)", sz, p, i)); } static int -post_check_children_lt(struct mdoc *mdoc, int sz) +post_check_children_lt(struct mdoc *mdoc, const char *p, int sz) { int i; if ((i = post_check_children_count(mdoc)) < sz) return(1); return(mdoc_err(mdoc, "macro requires less than %d " - "parameters (have %d)", sz, i)); + "%s (have %d)", sz, p, i)); } @@ -367,7 +370,7 @@ berr_eq0(struct mdoc *mdoc) if (MDOC_BODY != mdoc->last->type) return(1); - return(post_check_children_eq(mdoc, 0)); + return(post_check_children_eq(mdoc, "body children", 0)); } @@ -377,7 +380,7 @@ bwarn_ge1(struct mdoc *mdoc) if (MDOC_BODY != mdoc->last->type) return(1); - return(post_check_children_wgt(mdoc, 0)); + return(post_check_children_wgt(mdoc, "body children", 0)); } @@ -386,7 +389,7 @@ ewarn_eq1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_weq(mdoc, 1)); + return(post_check_children_weq(mdoc, "parameters", 1)); } @@ -395,7 +398,7 @@ ewarn_eq0(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_weq(mdoc, 0)); + return(post_check_children_weq(mdoc, "parameters", 0)); } @@ -404,7 +407,7 @@ ewarn_ge1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_wgt(mdoc, 0)); + return(post_check_children_wgt(mdoc, "parameters", 0)); } @@ -413,7 +416,7 @@ eerr_eq1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_eq(mdoc, 1)); + return(post_check_children_eq(mdoc, "parameters", 1)); } @@ -422,7 +425,7 @@ eerr_le2(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_lt(mdoc, 3)); + return(post_check_children_lt(mdoc, "parameters", 3)); } @@ -431,7 +434,7 @@ eerr_le1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_lt(mdoc, 2)); + return(post_check_children_lt(mdoc, "parameters", 2)); } @@ -440,7 +443,7 @@ eerr_eq0(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_eq(mdoc, 0)); + return(post_check_children_eq(mdoc, "parameters", 0)); } @@ -449,7 +452,7 @@ eerr_ge1(struct mdoc *mdoc) { assert(MDOC_ELEM == mdoc->last->type); - return(post_check_children_gt(mdoc, 0)); + return(post_check_children_gt(mdoc, "parameters", 0)); } @@ -459,7 +462,7 @@ herr_eq0(struct mdoc *mdoc) if (MDOC_HEAD != mdoc->last->type) return(1); - return(post_check_children_eq(mdoc, 0)); + return(post_check_children_eq(mdoc, "parameters", 0)); } @@ -469,17 +472,26 @@ hwarn_ge1(struct mdoc *mdoc) if (MDOC_HEAD != mdoc->last->type) return(1); - return(post_check_children_wgt(mdoc, 0)); + return(post_check_children_wgt(mdoc, "parameters", 0)); } static int +herr_le1(struct mdoc *mdoc) +{ + if (MDOC_HEAD != mdoc->last->type) + return(1); + return(post_check_children_lt(mdoc, "parameters", 2)); +} + + +static int herr_ge1(struct mdoc *mdoc) { if (MDOC_HEAD != mdoc->last->type) return(1); - return(post_check_children_gt(mdoc, 0)); + return(post_check_children_gt(mdoc, "parameters", 0)); } @@ -763,6 +775,40 @@ pre_prologue(struct mdoc *mdoc, struct mdoc_node *node } return(mdoc_nerr(mdoc, node, "prologue macro repeated")); +} + + +static int +post_bf(struct mdoc *mdoc) +{ + char *p; + struct mdoc_node *head; + + if (MDOC_BLOCK != mdoc->last->type) + return(1); + assert(MDOC_Bf == mdoc->last->tok); + head = mdoc->last->data.block.head; + assert(head); + + if (0 == mdoc->last->data.block.argc) { + if (head->child) { + assert(MDOC_TEXT == head->child->type); + p = head->child->data.text.string; + if (xstrcmp(p, "Em")) + return(1); + else if (xstrcmp(p, "Li")) + return(1); + else if (xstrcmp(p, "Sm")) + return(1); + return(mdoc_nerr(mdoc, head->child, "invalid font mode")); + } + return(mdoc_err(mdoc, "macro expects an argument or parameter")); + } + if (head->child) + return(mdoc_err(mdoc, "macro expects an argument or parameter")); + if (1 == mdoc->last->data.block.argc) + return(1); + return(mdoc_err(mdoc, "macro expects an argument or parameter")); }