-/* $Id: validate.c,v 1.64 2009/02/28 13:47:36 kristaps Exp $ */
+/* $Id: validate.c,v 1.68 2009/03/05 13:12:12 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
#include "private.h"
+/* FIXME: .Bl -diag can't have non-text children in HEAD. */
+
/*
* Pre- and post-validate macros as they're parsed. Pre-validation
* occurs when the macro has been detected and its arguments parsed.
static int check_text(struct mdoc *,
int, int, const char *);
+static int check_argv(struct mdoc *,
+ const struct mdoc_node *,
+ const struct mdoc_arg *);
static int err_child_lt(struct mdoc *, const char *, int);
static int warn_child_lt(struct mdoc *, const char *, int);
node->data.elem.argc;
for (i = 0; i < (int)argc; i++) {
- if (0 == argv[i].sz)
- continue;
for (j = 0; j < (int)argv[i].sz; j++) {
tp = argv[i].value[j];
line = argv[i].line;
if ( ! check_text(mdoc, line, pos, tp))
return(0);
}
+ if ( ! check_argv(mdoc, node, &argv[i]))
+ return(0);
}
}
}
+/*
+ * Check over an argument. When this has more stuff in it, make this
+ * into a table-driven function; until then, a switch is fine.
+ */
+static int
+check_argv(struct mdoc *mdoc,
+ const struct mdoc_node *node,
+ const struct mdoc_arg *argv)
+{
+
+
+ switch (argv->arg) {
+ case (MDOC_Std):
+ switch (node->tok) {
+ case (MDOC_Ex):
+ /*
+ * If the -std does not have an argument, then
+ * set it with the default name (if set). This
+ * only happens with MDOC_Ex.
+ */
+ if (1 == argv->sz)
+ return(1);
+ assert(0 == argv->sz);
+ if (mdoc->meta.name)
+ return(1);
+ return(mdoc_nerr(mdoc, node,
+ "default name not yet set"));
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return(1);
+}
+
+
static int
check_text(struct mdoc *mdoc, int line, int pos, const char *p)
{
/* XXX - indicate deprecated escapes \*(xx and \*x. */
for ( ; *p; p++) {
- if ( ! isprint((int)*p) && '\t' != *p)
+ if ( ! isprint((u_char)*p) && '\t' != *p)
return(mdoc_perr(mdoc, line, pos,
- "invalid characters"));
+ "invalid non-printing characters"));
if ('\\' != *p)
continue;
if ((c = mdoc_isescape(p))) {
p += (int)c - 1;
continue;
}
- return(mdoc_perr(mdoc, line, pos,
- "invalid escape sequence"));
+ return(mdoc_perr(mdoc, line, pos,
+ "invalid escape sequence"));
}
return(1);