summaryrefslogtreecommitdiffstatshomepage
path: root/validate.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-01-09 14:45:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-01-09 14:45:44 +0000
commitd4119897e8e1f98438694ef49e678e47661a3ae5 (patch)
tree446ad2426ee9788d516b5967a7c89a76a52c6368 /validate.c
parent1b6424e34de2a96aaa28ac28d0b0d83c0b46bdf4 (diff)
downloadmandoc-d4119897e8e1f98438694ef49e678e47661a3ae5.tar.gz
mandoc-d4119897e8e1f98438694ef49e678e47661a3ae5.tar.zst
mandoc-d4119897e8e1f98438694ef49e678e47661a3ae5.zip
*** empty log message ***
Diffstat (limited to 'validate.c')
-rw-r--r--validate.c70
1 files changed, 48 insertions, 22 deletions
diff --git a/validate.c b/validate.c
index 0fe1045b..ca556197 100644
--- a/validate.c
+++ b/validate.c
@@ -1,4 +1,4 @@
-/* $Id: validate.c,v 1.20 2009/01/08 15:59:58 kristaps Exp $ */
+/* $Id: validate.c,v 1.21 2009/01/09 14:45:44 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -32,25 +32,25 @@ struct valids {
};
-static int pre_sh(struct mdoc *, struct mdoc_node *);
static int pre_prologue(struct mdoc *, struct mdoc_node *);
static int pre_prologue(struct mdoc *, struct mdoc_node *);
static int pre_prologue(struct mdoc *, struct mdoc_node *);
static int post_headchild_err_ge1(struct mdoc *);
-static int post_headchild_err_le8(struct mdoc *);
+static int post_elemchild_err_ge1(struct mdoc *);
static int post_bodychild_warn_ge1(struct mdoc *);
+static int post_sh(struct mdoc *);
-static v_post posts_sh[] = { post_headchild_err_ge1,
- post_bodychild_warn_ge1,
- post_headchild_err_le8, NULL };
+static v_post posts_sh[] = { post_headchild_err_ge1,
+ post_bodychild_warn_ge1, post_sh, NULL };
+static v_post posts_dd[] = { post_elemchild_err_ge1, NULL };
const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* \" */
- { pre_prologue, NULL }, /* Dd */ /* TODO: pre: ordering, repetition */
- { pre_prologue, NULL }, /* Dt */ /* TODO ... */
- { pre_prologue, NULL }, /* Os */ /* TODO ... */
- { pre_sh, posts_sh }, /* Sh */ /* FIXME: preceding Pp. */
+ { pre_prologue, posts_dd }, /* Dd */
+ { pre_prologue, NULL }, /* Dt */
+ { pre_prologue, NULL }, /* Os */
+ { NULL, posts_sh }, /* Sh */ /* FIXME: preceding Pp. */
{ NULL, NULL }, /* Ss */ /* FIXME: preceding Pp. */
{ NULL, NULL }, /* Pp */
{ NULL, NULL }, /* D1 */
@@ -169,11 +169,10 @@ post_bodychild_warn_ge1(struct mdoc *mdoc)
static int
-post_headchild_err_ge1(struct mdoc *mdoc)
+post_elemchild_err_ge1(struct mdoc *mdoc)
{
- if (MDOC_HEAD != mdoc->last->type)
- return(1);
+ assert(MDOC_ELEM == mdoc->last->type);
if (mdoc->last->child)
return(1);
return(mdoc_err(mdoc, ERR_ARGS_GE1));
@@ -181,18 +180,14 @@ post_headchild_err_ge1(struct mdoc *mdoc)
static int
-post_headchild_err_le8(struct mdoc *mdoc)
+post_headchild_err_ge1(struct mdoc *mdoc)
{
- int i;
- struct mdoc_node *n;
if (MDOC_HEAD != mdoc->last->type)
return(1);
- for (i = 0, n = mdoc->last->child; n; n = n->next, i++)
- /* Do nothing. */ ;
- if (i <= 8)
+ if (mdoc->last->child)
return(1);
- return(mdoc_err(mdoc, ERR_ARGS_LE8));
+ return(mdoc_err(mdoc, ERR_ARGS_GE1));
}
@@ -248,11 +243,42 @@ pre_prologue(struct mdoc *mdoc, struct mdoc_node *node)
}
+/*
+ * Warn if sections (those that are with a known title, such as NAME,
+ * DESCRIPTION, and so forth) are out of the conventional order.
+ */
static int
-pre_sh(struct mdoc *mdoc, struct mdoc_node *node)
+post_sh(struct mdoc *mdoc)
{
+ enum mdoc_sec sec;
+ int i;
+ struct mdoc_node *n;
+ char *args[MDOC_LINEARG_MAX];
- return(1);
+ if (MDOC_HEAD != mdoc->last->type)
+ return(1);
+
+ assert(MDOC_Sh == mdoc->last->data.head.tok);
+
+ n = mdoc->last->child;
+ assert(n);
+
+ for (i = 0; n && i < MDOC_LINEARG_MAX; n = n->next, i++) {
+ assert(MDOC_TEXT == n->type);
+ assert(NULL == n->child);
+ assert(n->data.text.string);
+ args[i] = n->data.text.string;
+ }
+
+ sec = mdoc_atosec((size_t)i, (const char **)args);
+ if (SEC_CUSTOM == sec)
+ return(1);
+ if (sec > mdoc->sec_lastn)
+ return(1);
+
+ if (sec == mdoc->sec_lastn)
+ return(mdoc_warn(mdoc, WARN_SEC_REP));
+ return(mdoc_warn(mdoc, WARN_SEC_OO));
}