-/* $Id: mdoc_validate.c,v 1.264 2014/12/18 19:23:41 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.268 2015/02/04 18:03:47 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
CHECK_EQ
};
-enum check_lvl {
- CHECK_WARN,
- CHECK_ERROR,
-};
-
typedef void (*v_pre)(PRE_ARGS);
typedef void (*v_post)(POST_ARGS);
};
static void check_count(struct mdoc *, enum mdoc_type,
- enum check_lvl, enum check_ineq, int);
+ enum check_ineq, int);
static void check_text(struct mdoc *, int, int, char *);
static void check_argv(struct mdoc *,
struct mdoc_node *, struct mdoc_argv *);
static void
check_count(struct mdoc *mdoc, enum mdoc_type type,
- enum check_lvl lvl, enum check_ineq ineq, int val)
+ enum check_ineq ineq, int val)
{
const char *p;
- enum mandocerr t;
if (mdoc->last->type != type)
return;
/* NOTREACHED */
}
- t = lvl == CHECK_WARN ? MANDOCERR_ARGCWARN : MANDOCERR_ARGCOUNT;
- mandoc_vmsg(t, mdoc->parse, mdoc->last->line,
+ mandoc_vmsg(MANDOCERR_ARGCWARN, mdoc->parse, mdoc->last->line,
mdoc->last->pos, "want %s%d children (have %d)",
p, val, mdoc->last->nchild);
}
static void
bwarn_ge1(POST_ARGS)
{
- check_count(mdoc, MDOC_BODY, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_BODY, CHECK_GT, 0);
}
static void
ewarn_eq1(POST_ARGS)
{
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1);
}
static void
ewarn_ge1(POST_ARGS)
{
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_GT, 0);
}
static void
hwarn_eq0(POST_ARGS)
{
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 0);
+ check_count(mdoc, MDOC_HEAD, CHECK_EQ, 0);
}
static void
const char *stdlibname;
char *libname;
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 1);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1);
n = mdoc->last->child;
assert(MDOC_TEXT == n->type);
post_fo(POST_ARGS)
{
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 1);
+ check_count(mdoc, MDOC_HEAD, CHECK_EQ, 1);
bwarn_ge1(mdoc);
if (mdoc->last->type == MDOC_HEAD && mdoc->last->nchild)
post_fname(mdoc);
static void
post_nm(POST_ARGS)
{
+ struct mdoc_node *n;
+
+ n = mdoc->last;
+
+ if (n->last != NULL &&
+ (n->last->tok == MDOC_Pp ||
+ n->last->tok == MDOC_Lp))
+ mdoc_node_relink(mdoc, n->last);
if (NULL != mdoc->meta.name)
return;
- mdoc_deroff(&mdoc->meta.name, mdoc->last);
+ mdoc_deroff(&mdoc->meta.name, n);
if (NULL == mdoc->meta.name)
mandoc_msg(MANDOCERR_NM_NONAME, mdoc->parse,
- mdoc->last->line, mdoc->last->pos, "Nm");
+ n->line, n->pos, "Nm");
}
static void
post_nd(POST_ARGS)
{
+ struct mdoc_node *n;
+
+ n = mdoc->last;
+
+ if (n->type != MDOC_BODY)
+ return;
+
+ if (n->child == NULL)
+ mandoc_msg(MANDOCERR_ND_EMPTY, mdoc->parse,
+ n->line, n->pos, "Nd");
- check_count(mdoc, MDOC_BODY, CHECK_ERROR, CHECK_GT, 0);
post_hyph(mdoc);
}
np = mdoc->last;
if (AUTH__NONE == np->norm->An.auth) {
if (0 == np->child)
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_GT, 0);
} else if (np->child)
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0);
}
static void
nchild = nbody->child;
while (NULL != nchild) {
- if (MDOC_It == nchild->tok || MDOC_Sm == nchild->tok) {
+ if (nchild->tok == MDOC_It ||
+ (nchild->tok == MDOC_Sm &&
+ nchild->next != NULL &&
+ nchild->next->tok == MDOC_It)) {
nchild = nchild->next;
continue;
}
static void
post_rs(POST_ARGS)
{
- struct mdoc_node *nn, *next, *prev;
+ struct mdoc_node *np, *nch, *next, *prev;
int i, j;
- switch (mdoc->last->type) {
- case MDOC_HEAD:
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_EQ, 0);
- return;
- case MDOC_BODY:
- if (mdoc->last->child)
- break;
- check_count(mdoc, MDOC_BODY, CHECK_WARN, CHECK_GT, 0);
+ np = mdoc->last;
+
+ if (np->type != MDOC_BODY)
return;
- default:
+
+ if (np->child == NULL) {
+ mandoc_msg(MANDOCERR_RS_EMPTY, mdoc->parse,
+ np->line, np->pos, "Rs");
return;
}
*/
next = NULL;
- for (nn = mdoc->last->child->next; nn; nn = next) {
- /* Determine order of `nn'. */
+ for (nch = np->child->next; nch != NULL; nch = next) {
+ /* Determine order number of this child. */
for (i = 0; i < RSORD_MAX; i++)
- if (rsord[i] == nn->tok)
+ if (rsord[i] == nch->tok)
break;
if (i == RSORD_MAX) {
mandoc_msg(MANDOCERR_RS_BAD,
- mdoc->parse, nn->line, nn->pos,
- mdoc_macronames[nn->tok]);
+ mdoc->parse, nch->line, nch->pos,
+ mdoc_macronames[nch->tok]);
i = -1;
- } else if (MDOC__J == nn->tok || MDOC__B == nn->tok)
- mdoc->last->norm->Rs.quote_T++;
+ } else if (nch->tok == MDOC__J || nch->tok == MDOC__B)
+ np->norm->Rs.quote_T++;
/*
- * Remove `nn' from the chain. This somewhat
+ * Remove this child from the chain. This somewhat
* repeats mdoc_node_unlink(), but since we're
* just re-ordering, there's no need for the
* full unlink process.
*/
- if (NULL != (next = nn->next))
- next->prev = nn->prev;
+ if ((next = nch->next) != NULL)
+ next->prev = nch->prev;
- if (NULL != (prev = nn->prev))
- prev->next = nn->next;
+ if ((prev = nch->prev) != NULL)
+ prev->next = nch->next;
- nn->prev = nn->next = NULL;
+ nch->prev = nch->next = NULL;
/*
* Scan back until we reach a node that's
- * ordered before `nn'.
+ * to be ordered before this child.
*/
for ( ; prev ; prev = prev->prev) {
}
/*
- * Set `nn' back into its correct place in front
- * of the `prev' node.
+ * Set this child back into its correct place
+ * in front of the `prev' node.
*/
- nn->prev = prev;
+ nch->prev = prev;
- if (prev) {
- if (prev->next)
- prev->next->prev = nn;
- nn->next = prev->next;
- prev->next = nn;
+ if (prev == NULL) {
+ np->child->prev = nch;
+ nch->next = np->child;
+ np->child = nch;
} else {
- mdoc->last->child->prev = nn;
- nn->next = mdoc->last->child;
- mdoc->last->child = nn;
+ if (prev->next)
+ prev->next->prev = nch;
+ nch->next = prev->next;
+ prev->next = nch;
}
}
}
{
struct mdoc_node *np;
- check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_GT, 0);
+ check_count(mdoc, MDOC_HEAD, CHECK_GT, 0);
post_hyph(mdoc);
if (MDOC_BODY != mdoc->last->type)
struct mdoc_node *np;
if (mdoc->last->tok == MDOC_sp)
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_LT, 2);
+ check_count(mdoc, MDOC_ELEM, CHECK_LT, 2);
else
- check_count(mdoc, MDOC_ELEM, CHECK_WARN, CHECK_EQ, 0);
+ check_count(mdoc, MDOC_ELEM, CHECK_EQ, 0);
if (MDOC_ELEM != mdoc->last->type &&
MDOC_BLOCK != mdoc->last->type)