diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-02-04 22:30:10 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-02-04 22:30:10 +0000 |
commit | 9428c0388cfeb9544f5ffec7200f5fbee7da4727 (patch) | |
tree | 09ad909823009a69446d079d83d7de4a08b95855 /mdoc_validate.c | |
parent | 58bcb2f42259b0f030965cd8437c90e4704edb0e (diff) | |
download | mandoc-9428c0388cfeb9544f5ffec7200f5fbee7da4727.tar.gz |
Discard excess head arguments for .Bd .Bl .Bk and delete hwarn_eq0().
Discard empty .Bk blocks.
Improve related diagnostics.
Diffstat (limited to 'mdoc_validate.c')
-rw-r--r-- | mdoc_validate.c | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/mdoc_validate.c b/mdoc_validate.c index f7d0538c..c246385e 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -70,7 +70,6 @@ static void rewrite_macro2len(char **); static void bwarn_ge1(POST_ARGS); static void ewarn_eq1(POST_ARGS); static void ewarn_ge1(POST_ARGS); -static void hwarn_eq0(POST_ARGS); static void post_an(POST_ARGS); static void post_at(POST_ARGS); @@ -421,12 +420,6 @@ ewarn_ge1(POST_ARGS) } static void -hwarn_eq0(POST_ARGS) -{ - check_count(mdoc, MDOC_HEAD, CHECK_EQ, 0); -} - -static void check_args(struct mdoc *mdoc, struct mdoc_node *n) { int i; @@ -1088,8 +1081,6 @@ static void post_literal(POST_ARGS) { - if (mdoc->last->tok == MDOC_Bd) - hwarn_eq0(mdoc); bwarn_ge1(mdoc); /* @@ -1415,13 +1406,21 @@ post_bl_block_tag(POST_ARGS) static void post_bl_head(POST_ARGS) { - struct mdoc_node *np, *nn, *nnp; + struct mdoc_node *nbl, *nh, *nch, *nnext; struct mdoc_argv *argv; int i, j; - if (LIST_column != mdoc->last->norm->Bl.type) { - /* FIXME: this should be ERROR class... */ - hwarn_eq0(mdoc); + nh = mdoc->last; + + if (nh->norm->Bl.type != LIST_column) { + if ((nch = nh->child) == NULL) + return; + mandoc_vmsg(MANDOCERR_ARG_EXCESS, mdoc->parse, + nch->line, nch->pos, "Bl ... %s", nch->string); + while (nch != NULL) { + mdoc_node_delete(mdoc, nch); + nch = nh->child; + } return; } @@ -1431,17 +1430,15 @@ post_bl_head(POST_ARGS) * lists where they're argument values following -column. */ - if (mdoc->last->child == NULL) + if (nh->child == NULL) return; - np = mdoc->last->parent; - assert(np->args); - - for (j = 0; j < (int)np->args->argc; j++) - if (MDOC_Column == np->args->argv[j].arg) + nbl = nh->parent; + for (j = 0; j < (int)nbl->args->argc; j++) + if (nbl->args->argv[j].arg == MDOC_Column) break; - assert(j < (int)np->args->argc); + assert(j < (int)nbl->args->argc); /* * Accommodate for new-style groff column syntax. Shuffle the @@ -1449,25 +1446,23 @@ post_bl_head(POST_ARGS) * column field. Then, delete the head children. */ - argv = np->args->argv + j; + argv = nbl->args->argv + j; i = argv->sz; - argv->sz += mdoc->last->nchild; + argv->sz += nh->nchild; argv->value = mandoc_reallocarray(argv->value, argv->sz, sizeof(char *)); - mdoc->last->norm->Bl.ncols = argv->sz; - mdoc->last->norm->Bl.cols = (void *)argv->value; + nh->norm->Bl.ncols = argv->sz; + nh->norm->Bl.cols = (void *)argv->value; - for (nn = mdoc->last->child; nn; i++) { - argv->value[i] = nn->string; - nn->string = NULL; - nnp = nn; - nn = nn->next; - mdoc_node_delete(NULL, nnp); + for (nch = nh->child; nch != NULL; nch = nnext) { + argv->value[i++] = nch->string; + nch->string = NULL; + nnext = nch->next; + mdoc_node_delete(NULL, nch); } - - mdoc->last->nchild = 0; - mdoc->last->child = NULL; + nh->nchild = 0; + nh->child = NULL; } static void @@ -1553,9 +1548,15 @@ post_bl(POST_ARGS) static void post_bk(POST_ARGS) { + struct mdoc_node *n; - hwarn_eq0(mdoc); - bwarn_ge1(mdoc); + n = mdoc->last; + + if (n->type == MDOC_BLOCK && n->body->child == NULL) { + mandoc_msg(MANDOCERR_MACRO_EMPTY, + mdoc->parse, n->line, n->pos, "Bk"); + mdoc_node_delete(mdoc, n); + } } static void |