From b8c7224b007d9673c637669ba26ff55f38effe12 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Tue, 4 Dec 2018 02:53:51 +0000 Subject: Clean up the validation of .Pp, .PP, .sp, and .br. Make sure all combinations are handled, and are handled in a systematic manner. This resolves some erratic duplicate handling, handles a number of missing cases, and improves diagnostics in various respects. Move validation of .br and .sp to the roff validation module rather than doing that twice in the mdoc and man validation modules. Move the node relinking function to the roff library where it belongs. In validation functions, only look at the node itself, at previous nodes, and at descendants, not at following nodes or ancestors, such that only nodes are inspected which are already validated. --- roff_validate.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'roff_validate.c') diff --git a/roff_validate.c b/roff_validate.c index 6a76a1fb..3e301c05 100644 --- a/roff_validate.c +++ b/roff_validate.c @@ -1,4 +1,4 @@ -/* $Id: roff_validate.c,v 1.10 2018/08/10 20:40:45 schwarze Exp $ */ +/* $Id: roff_validate.c,v 1.11 2018/12/04 02:53:51 schwarze Exp $ */ /* * Copyright (c) 2010, 2017, 2018 Ingo Schwarze * @@ -29,17 +29,19 @@ typedef void (*roff_valid_fp)(ROFF_VALID_ARGS); +static void roff_valid_br(ROFF_VALID_ARGS); static void roff_valid_ft(ROFF_VALID_ARGS); +static void roff_valid_sp(ROFF_VALID_ARGS); static const roff_valid_fp roff_valids[ROFF_MAX] = { - NULL, /* br */ + roff_valid_br, /* br */ NULL, /* ce */ roff_valid_ft, /* ft */ NULL, /* ll */ NULL, /* mc */ NULL, /* po */ NULL, /* rj */ - NULL, /* sp */ + roff_valid_sp, /* sp */ NULL, /* ta */ NULL, /* ti */ }; @@ -56,6 +58,31 @@ roff_validate(struct roff_man *man) (*roff_valids[n->tok])(man, n); } +static void +roff_valid_br(ROFF_VALID_ARGS) +{ + struct roff_node *np; + + if (n->child != NULL) + mandoc_vmsg(MANDOCERR_ARG_SKIP, man->parse, + n->line, n->pos, "br %s", n->child->string); + + if ((np = n->prev) == NULL) + return; + + switch (np->tok) { + case ROFF_br: + case ROFF_sp: + case MDOC_Pp: + mandoc_vmsg(MANDOCERR_PAR_SKIP, man->parse, + n->line, n->pos, "br after %s", roff_name[np->tok]); + roff_node_delete(man, n); + break; + default: + break; + } +} + static void roff_valid_ft(ROFF_VALID_ARGS) { @@ -97,3 +124,32 @@ roff_valid_ft(ROFF_VALID_ARGS) n->line, n->pos, "ft %s", cp); roff_node_delete(man, n); } + +static void +roff_valid_sp(ROFF_VALID_ARGS) +{ + struct roff_node *np; + + if (n->child != NULL && n->child->next != NULL) + mandoc_vmsg(MANDOCERR_ARG_EXCESS, man->parse, + n->child->next->line, n->child->next->pos, + "sp ... %s", n->child->next->string); + + if ((np = n->prev) == NULL) + return; + + switch (np->tok) { + case ROFF_br: + mandoc_msg(MANDOCERR_PAR_SKIP, man->parse, + np->line, np->pos, "br before sp"); + roff_node_delete(man, np); + break; + case MDOC_Pp: + mandoc_msg(MANDOCERR_PAR_SKIP, man->parse, + n->line, n->pos, "sp after Pp"); + roff_node_delete(man, n); + break; + default: + break; + } +} -- cgit v1.2.3-56-ge451