-/* $Id: man_validate.c,v 1.11 2009/06/18 10:32:00 kristaps Exp $ */
+/* $Id: man_validate.c,v 1.15 2009/07/04 09:01:55 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
#include <stdlib.h>
#include "libman.h"
+#include "libmandoc.h"
#define POSTARGS struct man *m, const struct man_node *n
-enum merr {
- WPRINT
-};
-
typedef int (*v_post)(POSTARGS);
struct man_valid {
static int check_le2(POSTARGS);
static int check_le5(POSTARGS);
static int check_text(POSTARGS);
-static int perr(struct man *, int, int, int, enum merr);
+static int check_root(POSTARGS);
static v_post posts_le1[] = { check_le1, NULL };
static v_post posts_le2[] = { check_le2, NULL };
case (MAN_TEXT):
return(check_text(m, m->last));
case (MAN_ROOT):
- return(1);
+ return(check_root(m, m->last));
default:
break;
}
static int
-perr(struct man *m, int line, int pos,
- int iserr, enum merr type)
+check_root(POSTARGS)
{
- const char *p;
- p = NULL;
- switch (type) {
- case (WPRINT):
- p = "invalid character";
- break;
- }
- assert(p);
+ if (NULL == m->first->child)
+ return(man_nerr(m, n, WNODATA));
+ if (NULL == m->meta.title)
+ return(man_nerr(m, n, WNOTITLE));
- if (iserr)
- return(man_verr(m, line, pos, p));
-
- return(man_vwarn(m, line, pos, p));
+ return(1);
}
check_text(POSTARGS)
{
const char *p;
- int pos;
+ int pos, c;
assert(n->string);
for (p = n->string, pos = n->pos + 1; *p; p++, pos++) {
- if ('\t' == *p || isprint((u_char)*p))
+ if ('\\' == *p) {
+ c = mandoc_special(p);
+ if (c) {
+ p += c - 1;
+ pos += c - 1;
+ continue;
+ }
+ if ( ! (MAN_IGN_ESCAPE & m->pflags))
+ return(man_perr(m, n->line, pos, WESCAPE));
+ if ( ! man_pwarn(m, n->line, pos, WESCAPE))
+ return(0);
+ continue;
+ }
+
+ if ('\t' == *p || isprint((u_char)*p))
continue;
if (MAN_IGN_CHARS & m->pflags)
- return(perr(m, n->line, pos, 0, WPRINT));
- return(perr(m, n->line, pos, 1, WPRINT));
+ return(man_pwarn(m, n->line, pos, WNPRINT));
+ return(man_perr(m, n->line, pos, WNPRINT));
}
return(1);