error printing, as this is superseded by exit_status in main.c.
Make check_argv() and check_text() return void.
Make MDOC_Std test in check_argv() to pre_std().
Re-write post_root() to check more conditions before returning.
-/* $Id: mdoc_validate.c,v 1.132 2010/11/30 12:59:20 kristaps Exp $ */
+/* $Id: mdoc_validate.c,v 1.133 2010/11/30 14:27:37 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
static int check_count(struct mdoc *, enum mdoc_type,
enum check_lvl, enum check_ineq, int);
static int check_parent(PRE_ARGS, enum mdoct, enum mdoc_type);
static int check_count(struct mdoc *, enum mdoc_type,
enum check_lvl, enum check_ineq, int);
static int check_parent(PRE_ARGS, enum mdoct, enum mdoc_type);
-static int check_stdarg(PRE_ARGS);
-static int check_text(struct mdoc *, int, int, char *);
-static int check_argv(struct mdoc *,
+static void check_text(struct mdoc *, int, int, char *);
+static void check_argv(struct mdoc *,
struct mdoc_node *, struct mdoc_argv *);
struct mdoc_node *, struct mdoc_argv *);
-static int check_args(struct mdoc *, struct mdoc_node *);
+static void check_args(struct mdoc *, struct mdoc_node *);
static int concat(struct mdoc *, char *,
const struct mdoc_node *, size_t);
static int concat(struct mdoc *, char *,
const struct mdoc_node *, size_t);
static int pre_literal(PRE_ARGS);
static int pre_os(PRE_ARGS);
static int pre_par(PRE_ARGS);
static int pre_literal(PRE_ARGS);
static int pre_os(PRE_ARGS);
static int pre_par(PRE_ARGS);
-static int pre_rv(PRE_ARGS);
static int pre_sh(PRE_ARGS);
static int pre_ss(PRE_ARGS);
static int pre_sh(PRE_ARGS);
static int pre_ss(PRE_ARGS);
+static int pre_std(PRE_ARGS);
static v_post posts_an[] = { post_an, NULL };
static v_post posts_at[] = { post_at, post_defaults, NULL };
static v_post posts_an[] = { post_an, NULL };
static v_post posts_at[] = { post_at, post_defaults, NULL };
static v_pre pres_dd[] = { pre_dd, NULL };
static v_pre pres_dt[] = { pre_dt, NULL };
static v_pre pres_er[] = { NULL, NULL };
static v_pre pres_dd[] = { pre_dd, NULL };
static v_pre pres_dt[] = { pre_dt, NULL };
static v_pre pres_er[] = { NULL, NULL };
-static v_pre pres_ex[] = { NULL, NULL };
static v_pre pres_fd[] = { NULL, NULL };
static v_pre pres_it[] = { pre_it, NULL };
static v_pre pres_os[] = { pre_os, NULL };
static v_pre pres_pp[] = { pre_par, NULL };
static v_pre pres_fd[] = { NULL, NULL };
static v_pre pres_it[] = { pre_it, NULL };
static v_pre pres_os[] = { pre_os, NULL };
static v_pre pres_pp[] = { pre_par, NULL };
-static v_pre pres_rv[] = { pre_rv, NULL };
static v_pre pres_sh[] = { pre_sh, NULL };
static v_pre pres_ss[] = { pre_ss, NULL };
static v_pre pres_sh[] = { pre_sh, NULL };
static v_pre pres_ss[] = { pre_ss, NULL };
+static v_pre pres_std[] = { pre_std, NULL };
const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* Ap */
const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* Ap */
{ NULL, NULL }, /* Dv */
{ pres_er, posts_text }, /* Er */
{ NULL, NULL }, /* Ev */
{ NULL, NULL }, /* Dv */
{ pres_er, posts_text }, /* Er */
{ NULL, NULL }, /* Ev */
- { pres_ex, posts_std }, /* Ex */
+ { pres_std, posts_std }, /* Ex */
{ NULL, NULL }, /* Fa */
{ pres_fd, posts_wtext }, /* Fd */
{ NULL, NULL }, /* Fl */
{ NULL, NULL }, /* Fa */
{ pres_fd, posts_wtext }, /* Fd */
{ NULL, NULL }, /* Fl */
{ NULL, posts_wline }, /* Op */
{ NULL, NULL }, /* Ot */
{ NULL, posts_defaults }, /* Pa */
{ NULL, posts_wline }, /* Op */
{ NULL, NULL }, /* Ot */
{ NULL, posts_defaults }, /* Pa */
- { pres_rv, posts_std }, /* Rv */
+ { pres_std, posts_std }, /* Rv */
{ NULL, posts_st }, /* St */
{ NULL, NULL }, /* Va */
{ NULL, posts_vt }, /* Vt */
{ NULL, posts_st }, /* St */
{ NULL, NULL }, /* Va */
{ NULL, posts_vt }, /* Vt */
tp = n->string;
line = n->line;
pos = n->pos;
tp = n->string;
line = n->line;
pos = n->pos;
- return(check_text(mdoc, line, pos, tp));
+ check_text(mdoc, line, pos, tp);
+ return(1);
- if ( ! check_args(mdoc, n))
- return(0);
if (NULL == mdoc_valids[n->tok].pre)
return(1);
for (p = mdoc_valids[n->tok].pre; *p; p++)
if (NULL == mdoc_valids[n->tok].pre)
return(1);
for (p = mdoc_valids[n->tok].pre; *p; p++)
if (val == m->last->nchild)
return(1);
break;
if (val == m->last->nchild)
return(1);
break;
+ default:
+ abort();
+ /* NOTREACHED */
}
if (CHECK_WARN == lvl) {
}
if (CHECK_WARN == lvl) {
p, val, m->last->nchild));
}
p, val, m->last->nchild));
}
+ /* FIXME: THIS IS THE SAME AS THE ABOVE. */
+
return(mdoc_vmsg(m, MANDOCERR_ARGCOUNT,
m->last->line, m->last->pos,
"require %s%d children (have %d)",
return(mdoc_vmsg(m, MANDOCERR_ARGCOUNT,
m->last->line, m->last->pos,
"require %s%d children (have %d)",
return(check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_LT, 2));
}
return(check_count(mdoc, MDOC_HEAD, CHECK_WARN, CHECK_LT, 2));
}
-
-static int
-check_stdarg(PRE_ARGS)
-{
-
- if (n->args && 1 == n->args->argc)
- if (MDOC_Std == n->args->argv[0].arg)
- return(1);
- return(mdoc_nmsg(mdoc, n, MANDOCERR_NOARGV));
-}
-
-
-static int
check_args(struct mdoc *m, struct mdoc_node *n)
{
int i;
if (NULL == n->args)
check_args(struct mdoc *m, struct mdoc_node *n)
{
int i;
if (NULL == n->args)
assert(n->args->argc);
for (i = 0; i < (int)n->args->argc; i++)
assert(n->args->argc);
for (i = 0; i < (int)n->args->argc; i++)
- if ( ! check_argv(m, n, &n->args->argv[i]))
- return(0);
-
- return(1);
+ check_argv(m, n, &n->args->argv[i]);
check_argv(struct mdoc *m, struct mdoc_node *n, struct mdoc_argv *v)
{
int i;
for (i = 0; i < (int)v->sz; i++)
check_argv(struct mdoc *m, struct mdoc_node *n, struct mdoc_argv *v)
{
int i;
for (i = 0; i < (int)v->sz; i++)
- if ( ! check_text(m, v->line, v->pos, v->value[i]))
- return(0);
+ check_text(m, v->line, v->pos, v->value[i]);
- if (MDOC_Std == v->arg) {
- if (v->sz || m->meta.name)
- return(1);
- if ( ! mdoc_nmsg(m, n, MANDOCERR_NONAME))
- return(0);
- }
+ /* FIXME: move to post_std(). */
+ if (MDOC_Std == v->arg)
+ if ( ! (v->sz || m->meta.name))
+ mdoc_nmsg(m, n, MANDOCERR_NONAME);
check_text(struct mdoc *m, int ln, int pos, char *p)
{
int c;
check_text(struct mdoc *m, int ln, int pos, char *p)
{
int c;
pos += (int)sz;
if ('\t' == *p) {
pos += (int)sz;
if ('\t' == *p) {
- if (MDOC_LITERAL & m->flags)
- continue;
- if (mdoc_pmsg(m, ln, pos, MANDOCERR_BADTAB))
- continue;
- return(0);
+ if ( ! (MDOC_LITERAL & m->flags))
+ mdoc_pmsg(m, ln, pos, MANDOCERR_BADTAB);
+ continue;
- /* Check the special character. */
-
- c = mandoc_special(p);
- if (c) {
- p += c - 1;
- pos += c - 1;
- } else
+ if (0 == (c = mandoc_special(p))) {
mdoc_pmsg(m, ln, pos, MANDOCERR_BADESCAPE);
mdoc_pmsg(m, ln, pos, MANDOCERR_BADESCAPE);
+ p += c - 1;
+ pos += c - 1;
+ }
static int
check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)
{
static int
check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)
{
dup = (NULL != n->data.Bl->offs);
break;
}
dup = (NULL != n->data.Bl->offs);
break;
}
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
break;
default:
continue;
break;
default:
continue;
/* Check: duplicate auxiliary arguments. */
/* Check: duplicate auxiliary arguments. */
- if (dup && ! mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP))
- return(0);
+ if (dup)
+ mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP);
if (comp && ! dup)
n->data.Bl->comp = comp;
if (comp && ! dup)
n->data.Bl->comp = comp;
/* Check: multiple list types. */
if (LIST__NONE != lt && n->data.Bl->type != LIST__NONE)
/* Check: multiple list types. */
if (LIST__NONE != lt && n->data.Bl->type != LIST__NONE)
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTREP))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_LISTREP);
if (n->data.Bl->width ||
n->data.Bl->offs ||
n->data.Bl->comp)
if (n->data.Bl->width ||
n->data.Bl->offs ||
n->data.Bl->comp)
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_LISTFIRST);
/* Allow lists to default to LIST_item. */
if (LIST__NONE == n->data.Bl->type) {
/* Allow lists to default to LIST_item. */
if (LIST__NONE == n->data.Bl->type) {
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_LISTTYPE);
n->data.Bl->type = LIST_item;
}
n->data.Bl->type = LIST_item;
}
case (LIST_tag):
if (n->data.Bl->width)
break;
case (LIST_tag):
if (n->data.Bl->width)
break;
- if (mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG))
- break;
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG);
+ break;
case (LIST_column):
/* FALLTHROUGH */
case (LIST_diag):
case (LIST_column):
/* FALLTHROUGH */
case (LIST_diag):
case (LIST_item):
if (NULL == n->data.Bl->width)
break;
case (LIST_item):
if (NULL == n->data.Bl->width)
break;
- if (mdoc_nmsg(mdoc, n, MANDOCERR_WIDTHARG))
- break;
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_WIDTHARG);
+ break;
dup = (NULL != n->data.Bd->offs);
break;
}
dup = (NULL != n->data.Bd->offs);
break;
}
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV);
break;
case (MDOC_Compact):
comp = 1;
break;
case (MDOC_Compact):
comp = 1;
/* Check whether we have duplicates. */
/* Check whether we have duplicates. */
- if (dup && ! mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP))
- return(0);
+ if (dup)
+ mdoc_nmsg(mdoc, n, MANDOCERR_ARGVREP);
/* Make our auxiliary assignments. */
/* Make our auxiliary assignments. */
/* Check whether a type has already been assigned. */
if (DISP__NONE != dt && n->data.Bd->type != DISP__NONE)
/* Check whether a type has already been assigned. */
if (DISP__NONE != dt && n->data.Bd->type != DISP__NONE)
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_DISPREP);
/* Make our type assignment. */
/* Make our type assignment. */
}
if (DISP__NONE == n->data.Bd->type) {
}
if (DISP__NONE == n->data.Bd->type) {
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_DISPTYPE);
n->data.Bd->type = DISP_ragged;
}
n->data.Bd->type = DISP_ragged;
}
if (MDOC_BLOCK != n->type)
return(1);
if (MDOC_BLOCK != n->type)
return(1);
/*
* FIXME: this can probably be lifted if we make the It into
* something else on-the-fly?
/*
* FIXME: this can probably be lifted if we make the It into
* something else on-the-fly?
return(1);
for (i = 1; i < (int)n->args->argc; i++)
return(1);
for (i = 1; i < (int)n->args->argc; i++)
- if ( ! mdoc_pmsg(mdoc, n->args->argv[i].line,
- n->args->argv[i].pos, MANDOCERR_IGNARGV))
- return(0);
+ mdoc_pmsg(mdoc, n->args->argv[i].line,
+ n->args->argv[i].pos, MANDOCERR_IGNARGV);
if (MDOC_Split == n->args->argv[0].arg)
n->data.An.auth = AUTH_split;
if (MDOC_Split == n->args->argv[0].arg)
n->data.An.auth = AUTH_split;
- return(check_stdarg(mdoc, n));
+ if (n->args && 1 == n->args->argc)
+ if (MDOC_Std == n->args->argv[0].arg)
+ return(1);
+
+ mdoc_nmsg(mdoc, n, MANDOCERR_NOARGV);
+ return(1);
{
if (0 == mdoc->meta.date || mdoc->meta.os)
{
if (0 == mdoc->meta.date || mdoc->meta.os)
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO);
+
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP);
+
{
if (NULL == mdoc->meta.title || 0 == mdoc->meta.date)
{
if (NULL == mdoc->meta.title || 0 == mdoc->meta.date)
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO);
+
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP);
+
{
if (mdoc->meta.title || mdoc->meta.os)
{
if (mdoc->meta.title || mdoc->meta.os)
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGOOO);
+
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_PROLOGREP);
+
if (np->parent->args && np->child) {
mdoc_nmsg(mdoc, np, MANDOCERR_SYNTARGVCOUNT);
return(0);
if (np->parent->args && np->child) {
mdoc_nmsg(mdoc, np, MANDOCERR_SYNTARGVCOUNT);
return(0);
- } else if (NULL == np->parent->args && NULL == np->child)
- return(mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE));
+ } else if (NULL == np->parent->args && NULL == np->child) {
+ mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE);
+ return(1);
+ }
/* Extract argument into data. */
/* Extract argument into data. */
np->data.Bf->font = FONT_Li;
else if (0 == strcmp(np->child->string, "Sy"))
np->data.Bf->font = FONT_Sy;
np->data.Bf->font = FONT_Li;
else if (0 == strcmp(np->child->string, "Sy"))
np->data.Bf->font = FONT_Sy;
- else if ( ! mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE))
- return(0);
+ else
+ mdoc_nmsg(mdoc, np, MANDOCERR_FONTTYPE);
- if (NULL == mdoc->last->child)
- return(1);
- return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST));
+ if (mdoc->last->child)
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST);
+ return(1);
for (n = mdoc->last->child; n; n = n->next)
if (MDOC_TEXT != n->type)
for (n = mdoc->last->child; n; n = n->next)
if (MDOC_TEXT != n->type)
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_CHILD))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_CHILD);
np = mdoc->last;
if (AUTH__NONE != np->data.An.auth && np->child)
return(eerr_eq0(mdoc));
np = mdoc->last;
if (AUTH__NONE != np->data.An.auth && np->child)
return(eerr_eq0(mdoc));
/*
* FIXME: make this ewarn and make sure that the front-ends
* don't print the arguments.
*/
if (AUTH__NONE != np->data.An.auth || np->child)
return(1);
/*
* FIXME: make this ewarn and make sure that the front-ends
* don't print the arguments.
*/
if (AUTH__NONE != np->data.An.auth || np->child)
return(1);
- return(mdoc_nmsg(mdoc, np, MANDOCERR_NOARGS));
+
+ mdoc_nmsg(mdoc, np, MANDOCERR_NOARGS);
+ return(1);
if (LIST__NONE == lt) {
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE);
if (LIST__NONE == lt) {
mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_LISTTYPE);
if (mdoc->last->head->child)
break;
/* FIXME: give this a dummy value. */
if (mdoc->last->head->child)
break;
/* FIXME: give this a dummy value. */
- if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
- return(0);
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS);
break;
case (LIST_hang):
/* FALLTHROUGH */
break;
case (LIST_hang):
/* FALLTHROUGH */
/* FALLTHROUGH */
case (LIST_diag):
if (NULL == mdoc->last->head->child)
/* FALLTHROUGH */
case (LIST_diag):
if (NULL == mdoc->last->head->child)
- if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
- return(0);
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS);
break;
case (LIST_bullet):
/* FALLTHROUGH */
break;
case (LIST_bullet):
/* FALLTHROUGH */
/* FALLTHROUGH */
case (LIST_hyphen):
if (NULL == mdoc->last->body->child)
/* FALLTHROUGH */
case (LIST_hyphen):
if (NULL == mdoc->last->body->child)
- if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
- return(0);
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY);
/* FALLTHROUGH */
case (LIST_item):
if (mdoc->last->head->child)
/* FALLTHROUGH */
case (LIST_item):
if (mdoc->last->head->child)
- if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST))
- return(0);
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST);
break;
case (LIST_column):
cols = (int)n->data.Bl->ncols;
break;
case (LIST_column):
cols = (int)n->data.Bl->ncols;
assert(NULL == mdoc->last->head->child);
if (NULL == mdoc->last->body->child)
assert(NULL == mdoc->last->head->child);
if (NULL == mdoc->last->body->child)
- if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
- return(0);
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY);
for (i = 0, c = mdoc->last->child; c; c = c->next)
if (MDOC_BODY == c->type)
for (i = 0, c = mdoc->last->child; c; c = c->next)
if (MDOC_BODY == c->type)
width = 6;
else if (MDOC_MAX == (tok = mdoc_hash_find(n->data.Bl->width)))
return(1);
width = 6;
else if (MDOC_MAX == (tok = mdoc_hash_find(n->data.Bl->width)))
return(1);
- else if (0 == (width = mdoc_macro2len(tok)))
- return(mdoc_nmsg(mdoc, n, MANDOCERR_BADWIDTH));
+ else if (0 == (width = mdoc_macro2len(tok))) {
+ mdoc_nmsg(mdoc, n, MANDOCERR_BADWIDTH);
+ return(1);
+ }
/* The value already exists: free and reallocate it. */
/* The value already exists: free and reallocate it. */
if (nn == NULL) {
/* No -width for .Bl and first .It is emtpy */
if (nn == NULL) {
/* No -width for .Bl and first .It is emtpy */
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG);
if (0 != (ssz = mdoc_macro2len(nn->tok)))
sz = ssz;
if (0 != (ssz = mdoc_macro2len(nn->tok)))
sz = ssz;
- else if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG))
- return(0);
+ else
+ mdoc_nmsg(mdoc, n, MANDOCERR_NOWIDTHARG);
static int
ebool(struct mdoc *mdoc)
{
static int
ebool(struct mdoc *mdoc)
{
- /* LINTED */
- for (n = mdoc->last->child; n; n = n->next) {
- if (MDOC_TEXT != n->type)
- break;
- if (0 == strcmp(n->string, "on"))
- continue;
- if (0 == strcmp(n->string, "off"))
- continue;
- break;
- }
+ if (NULL == mdoc->last->child)
+ return(1);
+
+ assert(MDOC_TEXT == mdoc->last->child->type);
+ if (0 == strcmp(mdoc->last->child->string, "on"))
+ return(1);
+ if (0 == strcmp(mdoc->last->child->string, "off"))
- return(mdoc_nmsg(mdoc, n, MANDOCERR_BADBOOL));
-}
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADBOOL);
+ return(1);
+}
static int
post_root(POST_ARGS)
{
static int
post_root(POST_ARGS)
{
+ int erc;
+ struct mdoc_node *n;
- if (NULL == mdoc->first->child)
- mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY);
- else if ( ! (MDOC_PBODY & mdoc->flags))
+ erc = 0;
+
+ /* Check that we have a finished prologue. */
+
+ if ( ! (MDOC_PBODY & mdoc->flags)) {
+ erc++;
mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG);
mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCPROLOG);
- else if (MDOC_BLOCK != mdoc->first->child->type)
- mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY);
- else if (MDOC_Sh != mdoc->first->child->tok)
- mdoc_nmsg(mdoc, mdoc->first, MANDOCERR_NODOCBODY);
- else
- return(1);
+ n = mdoc->first;
+ assert(n);
+
+ /* Check that we begin with a proper `Sh'. */
+
+ if (NULL == n->child) {
+ erc++;
+ mdoc_nmsg(mdoc, n, MANDOCERR_NODOCBODY);
+ } else if (MDOC_BLOCK != n->child->type ||
+ MDOC_Sh != n->child->tok) {
+ erc++;
+ /* Can this be lifted? See rxdebug.1 for example. */
+ mdoc_nmsg(mdoc, n, MANDOCERR_NODOCBODY);
+ }
+
+ return(erc ? 0 : 1);
static int
post_sh(POST_ARGS)
{
static int
post_sh(POST_ARGS)
{
static int
post_sh_body(POST_ARGS)
{
static int
post_sh_body(POST_ARGS)
{
* children of the BODY declaration can also be "text".
*/
* children of the BODY declaration can also be "text".
*/
- if (NULL == (n = mdoc->last->child))
- return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC));
+ if (NULL == (n = mdoc->last->child)) {
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC);
+ return(1);
+ }
for ( ; n && n->next; n = n->next) {
if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
continue;
if (MDOC_TEXT == n->type)
continue;
for ( ; n && n->next; n = n->next) {
if (MDOC_ELEM == n->type && MDOC_Nm == n->tok)
continue;
if (MDOC_TEXT == n->type)
continue;
- if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC))
- return(0);
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC);
}
assert(n);
if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok)
return(1);
}
assert(n);
if (MDOC_BLOCK == n->type && MDOC_Nd == n->tok)
return(1);
- return(mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC));
-}
+ mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_BADNAMESEC);
+ return(1);
+}
static int
post_sh_head(POST_ARGS)
static int
post_sh_head(POST_ARGS)
if (NULL == n->child) {
mdoc->meta.date = time(NULL);
if (NULL == n->child) {
mdoc->meta.date = time(NULL);
- return(post_prol(mdoc));
}
if ( ! concat(mdoc, buf, n->child, DATESIZ))
}
if ( ! concat(mdoc, buf, n->child, DATESIZ))
(MTIME_MDOCDATE | MTIME_CANONICAL, buf);
if (0 == mdoc->meta.date) {
(MTIME_MDOCDATE | MTIME_CANONICAL, buf);
if (0 == mdoc->meta.date) {
- if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_BADDATE))
- return(0);
+ mdoc_nmsg(mdoc, n, MANDOCERR_BADDATE);
mdoc->meta.date = time(NULL);
}
mdoc->meta.date = time(NULL);
}
for (p = nn->string; *p; p++) {
if (toupper((u_char)*p) == *p)
continue;
for (p = nn->string; *p; p++) {
if (toupper((u_char)*p) == *p)
continue;
- if ( ! mdoc_nmsg(mdoc, nn, MANDOCERR_UPPERCASE))
- return(0);
+
+ /*
+ * FIXME: don't be lazy: have this make all
+ * characters be uppercase and just warn once.
+ */
+ mdoc_nmsg(mdoc, nn, MANDOCERR_UPPERCASE);
if (cp) {
mdoc->meta.vol = mandoc_strdup(cp);
mdoc->meta.msec = mandoc_strdup(nn->string);
if (cp) {
mdoc->meta.vol = mandoc_strdup(cp);
mdoc->meta.msec = mandoc_strdup(nn->string);
- } else if (mdoc_nmsg(mdoc, n, MANDOCERR_BADMSEC)) {
+ } else {
+ mdoc_nmsg(mdoc, n, MANDOCERR_BADMSEC);
mdoc->meta.vol = mandoc_strdup(nn->string);
mdoc->meta.msec = mandoc_strdup(nn->string);
mdoc->meta.vol = mandoc_strdup(nn->string);
mdoc->meta.msec = mandoc_strdup(nn->string);
if (NULL == (nn = nn->next))
return(1);
if (NULL == (nn = nn->next))
return(1);
if (NULL == mdoc->meta.name)
return(1);
if (NULL == mdoc->meta.name)
return(1);
if ( ! mdoc_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name))
return(0);
if ( ! mdoc_word_alloc(mdoc, n->line, n->pos, mdoc->meta.name))
return(0);
mdoc->last = nn;
return(1);
}
mdoc->last = nn;
return(1);
}
/*
* Concatenate sibling nodes together. All siblings must be of
* type MDOC_TEXT or an assertion is raised. Concatenation is
/*
* Concatenate sibling nodes together. All siblings must be of
* type MDOC_TEXT or an assertion is raised. Concatenation is
- * separated by a single whitespace.
+ * separated by a single whitespace. Returns 0 on fatal (string
+ * overrun) error.
*/
for ( ; n; n = n->next) {
*/
for ( ; n; n = n->next) {