-/* $Id: mdoc_validate.c,v 1.5 2009/04/12 19:45:26 kristaps Exp $ */
+/* $Id: mdoc_validate.c,v 1.14 2009/06/17 14:08:47 kristaps Exp $ */
/*
- * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
+ * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
ELISTTYPE,
EDISPTYPE,
EMULTIDISP,
+ ESECNAME,
EMULTILIST,
EARGREP,
EBOOL,
+ ECOLMIS,
ENESTDISP
};
enum mwarn {
WPRINT,
+ WNOWIDTH,
+ WMISSWIDTH,
WESCAPE,
+ WDEPESC,
+ WDEPCOL,
WWRONGMSEC,
WSECOOO,
WSECREP,
static int pre_it(PRE_ARGS);
static int pre_lb(PRE_ARGS);
static int pre_os(PRE_ARGS);
-static int pre_prologue(PRE_ARGS);
static int pre_rv(PRE_ARGS);
static int pre_sh(PRE_ARGS);
static int pre_ss(PRE_ARGS);
static int post_at(POST_ARGS);
static int post_bf(POST_ARGS);
static int post_bl(POST_ARGS);
+static int post_bl_head(POST_ARGS);
static int post_it(POST_ARGS);
static int post_nm(POST_ARGS);
static int post_root(POST_ARGS);
static v_pre pres_bd[] = { pre_display, pre_bd, NULL };
static v_pre pres_bl[] = { pre_bl, NULL };
static v_pre pres_cd[] = { pre_cd, NULL };
-static v_pre pres_dd[] = { pre_prologue, pre_dd, NULL };
+static v_pre pres_dd[] = { pre_dd, NULL };
static v_pre pres_d1[] = { pre_display, NULL };
-static v_pre pres_dt[] = { pre_prologue, pre_dt, NULL };
+static v_pre pres_dt[] = { pre_dt, NULL };
static v_pre pres_er[] = { pre_er, NULL };
static v_pre pres_ex[] = { pre_ex, NULL };
static v_pre pres_fd[] = { pre_fd, NULL };
static v_pre pres_it[] = { pre_it, NULL };
static v_pre pres_lb[] = { pre_lb, NULL };
-static v_pre pres_os[] = { pre_prologue, pre_os, NULL };
+static v_pre pres_os[] = { pre_os, 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_post posts_notext[] = { eerr_eq0, NULL };
static v_post posts_wline[] = { bwarn_ge1, herr_eq0, NULL };
static v_post posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL };
-static v_post posts_bl[] = { herr_eq0, bwarn_ge1, post_bl, NULL };
+static v_post posts_bl[] = { bwarn_ge1, post_bl, NULL };
static v_post posts_it[] = { post_it, NULL };
static v_post posts_in[] = { ewarn_eq1, NULL };
static v_post posts_ss[] = { herr_ge1, NULL };
static v_post posts_fo[] = { hwarn_eq1, bwarn_ge1, NULL };
const struct valids mdoc_valids[MDOC_MAX] = {
- { NULL, NULL }, /* \" */
+ { NULL, NULL }, /* Ap */
{ pres_dd, posts_text }, /* Dd */
{ pres_dt, NULL }, /* Dt */
{ pres_os, NULL }, /* Os */
{ NULL, NULL }, /* Fr */
{ NULL, posts_notext }, /* Ud */
{ pres_lb, posts_lb }, /* Lb */
- { NULL, NULL }, /* Ap */
{ NULL, posts_pp }, /* Lp */
- { NULL, posts_text }, /* Lk */
+ { NULL, NULL }, /* Lk */
{ NULL, posts_text }, /* Mt */
{ NULL, posts_wline }, /* Brq */
{ NULL, NULL }, /* Bro */
case (EDISPTYPE):
p = "missing display type";
break;
+ case (ESECNAME):
+ p = "the NAME section must come first";
+ break;
case (ELINE):
p = "expected line arguments";
break;
case (ENODATA):
p = "document has no data";
break;
+ case (ECOLMIS):
+ p = "column syntax style mismatch";
+ break;
case (EATT):
p = "expected valid AT&T symbol";
break;
p = "prologue macros out-of-order";
c = WARN_COMPAT;
break;
+ case (WDEPCOL):
+ p = "deprecated column argument syntax";
+ c = WARN_COMPAT;
+ break;
+ case (WNOWIDTH):
+ p = "superfluous width argument";
+ break;
+ case (WMISSWIDTH):
+ p = "missing width argument";
+ break;
case (WPRINT):
p = "invalid character";
break;
case (WESCAPE):
p = "invalid escape sequence";
break;
+ case (WDEPESC):
+ p = "deprecated special-character escape";
+ break;
case (WNOLINE):
p = "suggested no line arguments";
break;
{
size_t c;
- /* FIXME: indicate deprecated escapes \*(xx and \*x. */
-
for ( ; *p; p++) {
if ('\t' == *p) {
if ( ! (MDOC_LITERAL & mdoc->flags))
c = mdoc_isescape(p);
if (c) {
+ /* See if form is deprecated. */
+ if ('*' == p[1])
+ if ( ! pwarn(mdoc, line, pos, WDEPESC))
+ return(0);
p += (int)c - 1;
continue;
}
static int
pre_bl(PRE_ARGS)
{
- int i, type, width, offset;
+ int pos, col, type, width, offset;
if (MDOC_BLOCK != n->type)
return(1);
/* Make sure that only one type of list is specified. */
- type = offset = width = -1;
+ type = offset = width = col = -1;
/* LINTED */
- for (i = 0; i < (int)n->args->argc; i++)
- switch (n->args->argv[i].arg) {
+ for (pos = 0; pos < (int)n->args->argc; pos++)
+ switch (n->args->argv[pos].arg) {
case (MDOC_Bullet):
/* FALLTHROUGH */
case (MDOC_Dash):
case (MDOC_Inset):
/* FALLTHROUGH */
case (MDOC_Column):
- if (-1 == type) {
- type = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EMULTILIST));
+ if (-1 != type)
+ return(nerr(mdoc, n, EMULTILIST));
+ type = n->args->argv[pos].arg;
+ col = pos;
+ break;
case (MDOC_Width):
- if (-1 == width) {
- width = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EARGREP));
+ if (-1 != width)
+ return(nerr(mdoc, n, EARGREP));
+ width = n->args->argv[pos].arg;
+ break;
case (MDOC_Offset):
- if (-1 == offset) {
- offset = n->args->argv[i].arg;
- break;
- }
- return(nerr(mdoc, n, EARGREP));
+ if (-1 != offset)
+ return(nerr(mdoc, n, EARGREP));
+ offset = n->args->argv[pos].arg;
+ break;
default:
break;
}
if (-1 == type)
return(nerr(mdoc, n, ELISTTYPE));
+ /*
+ * Validate the width field. Some list types don't need width
+ * types and should be warned about them. Others should have it
+ * and must also be warned.
+ */
+
switch (type) {
+ case (MDOC_Tag):
+ if (-1 == width && ! nwarn(mdoc, n, WMISSWIDTH))
+ return(0);
+ break;
case (MDOC_Column):
/* FALLTHROUGH */
case (MDOC_Diag):
case (MDOC_Inset):
/* FALLTHROUGH */
case (MDOC_Item):
- if (-1 == width)
- break;
- return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,
- "superfluous %s argument",
- mdoc_argnames[MDOC_Width]));
- case (MDOC_Tag):
- if (-1 != width)
- break;
- return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,
- "suggest %s argument",
- mdoc_argnames[MDOC_Width]));
+ if (-1 != width && ! nwarn(mdoc, n, WNOWIDTH))
+ return(0);
+ break;
default:
break;
}
pre_er(PRE_ARGS)
{
- return(check_msec(mdoc, n, 2, 0));
+ return(check_msec(mdoc, n, 2, 3, 9, 0));
}
}
-static int
-pre_prologue(PRE_ARGS)
-{
-
- return(check_sec(mdoc, n, SEC_PROLOGUE, SEC_CUSTOM));
-}
-
-
static int
pre_dt(PRE_ARGS)
{
head = mdoc->last->head;
- if (NULL == mdoc->last->args) {
- if (NULL == head->child ||
- MDOC_TEXT != head->child->type)
- return(mdoc_err(mdoc, "text argument expected"));
+ if (mdoc->last->args && head->child)
+ return(mdoc_err(mdoc, "one argument expected"));
+ else if (mdoc->last->args)
+ return(1);
- p = head->child->string;
- if (0 == strcmp(p, "Em"))
- return(1);
- else if (0 == strcmp(p, "Li"))
- return(1);
- else if (0 == strcmp(p, "Sm"))
- return(1);
- return(mdoc_nerr(mdoc, head->child, "invalid font"));
- }
+ if (NULL == head->child || MDOC_TEXT != head->child->type)
+ return(mdoc_err(mdoc, "text argument expected"));
- if (head->child)
- return(mdoc_err(mdoc, "one argument expected"));
+ p = head->child->string;
- return(1);
+ if (0 == strcmp(p, "Em"))
+ return(1);
+ else if (0 == strcmp(p, "Li"))
+ return(1);
+ else if (0 == strcmp(p, "Sm"))
+ return(1);
+
+ return(mdoc_nerr(mdoc, head->child, "invalid font mode"));
}
}
+static int
+post_bl_head(POST_ARGS)
+{
+ int i;
+ const struct mdoc_node *n;
+
+ n = mdoc->last->parent;
+ assert(n->args);
+
+ for (i = 0; i < (int)n->args->argc; i++)
+ if (n->args->argv[i].arg == MDOC_Column)
+ break;
+
+ if (i == (int)n->args->argc)
+ return(1);
+
+ if (n->args->argv[i].sz && mdoc->last->child)
+ return(nerr(mdoc, n, ECOLMIS));
+
+ return(1);
+}
+
+
static int
post_bl(POST_ARGS)
{
struct mdoc_node *n;
+ if (MDOC_HEAD == mdoc->last->type)
+ return(post_bl_head(mdoc));
if (MDOC_BODY != mdoc->last->type)
return(1);
if (NULL == mdoc->last->child)
if (NULL == mdoc->first->child)
return(verr(mdoc, ENODATA));
- if (SEC_PROLOGUE == mdoc->lastnamed)
+ if ( ! (MDOC_PBODY & mdoc->flags))
return(verr(mdoc, ENOPROLOGUE));
if (MDOC_BLOCK != mdoc->first->child->type)
* certain manual sections.
*/
- assert(MDOC_Sh == mdoc->last->tok);
-
- /* This is just concat() inlined, which is irritating. */
-
buf[0] = 0;
+
for (n = mdoc->last->child; n; n = n->next) {
+ /* XXX - copied from compact(). */
assert(MDOC_TEXT == n->type);
+
if (strlcat(buf, n->string, 64) >= 64)
return(nerr(mdoc, n, ETOOLONG));
if (NULL == n->next)
sec = mdoc_atosec(buf);
- /* The NAME section should always be first. */
+ /*
+ * Check: NAME should always be first, CUSTOM has no roles,
+ * non-CUSTOM has a conventional order to be followed.
+ */
- if (SEC_BODY == mdoc->lastnamed && SEC_NAME != sec)
- return(vwarn(mdoc, WSECOOO));
+ if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)
+ return(verr(mdoc, ESECNAME));
if (SEC_CUSTOM == sec)
return(1);
-
- /* Check for repeated or out-of-order sections. */
-
if (sec == mdoc->lastnamed)
return(vwarn(mdoc, WSECREP));
if (sec < mdoc->lastnamed)
return(vwarn(mdoc, WSECOOO));
- /* Check particular section/manual section conventions. */
+ /*
+ * Check particular section/manual conventions. LIBRARY can
+ * only occur in msec 2, 3 (TODO: are there more of these?).
+ */
switch (sec) {
case (SEC_LIBRARY):