-/* $Id: mdoc_validate.c,v 1.158 2011/03/07 01:35:51 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.169 2011/04/30 10:18:24 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
#include <string.h>
#include <time.h>
+#include "mdoc.h"
#include "mandoc.h"
#include "libmdoc.h"
#include "libmandoc.h"
static int concat(struct mdoc *, char *,
const struct mdoc_node *, size_t);
+static enum mdoc_sec a2sec(const char *);
+static size_t macro2len(enum mdoct);
static int ebool(POST_ARGS);
static int berr_ge1(POST_ARGS);
static v_post posts_ns[] = { post_ns, NULL };
static v_post posts_os[] = { post_os, post_prol, NULL };
static v_post posts_rs[] = { post_rs, NULL };
-static v_post posts_sh[] = { post_ignpar, hwarn_ge1, bwarn_ge1, post_sh, NULL };
+static v_post posts_sh[] = { post_ignpar, hwarn_ge1, post_sh, NULL };
static v_post posts_sp[] = { ewarn_le1, NULL };
-static v_post posts_ss[] = { post_ignpar, hwarn_ge1, bwarn_ge1, NULL };
+static v_post posts_ss[] = { post_ignpar, hwarn_ge1, NULL };
static v_post posts_st[] = { post_st, NULL };
static v_post posts_std[] = { post_std, NULL };
static v_post posts_text[] = { ewarn_ge1, NULL };
static v_pre pres_ss[] = { pre_ss, NULL };
static v_pre pres_std[] = { pre_std, NULL };
-const struct valids mdoc_valids[MDOC_MAX] = {
+static const struct valids mdoc_valids[MDOC_MAX] = {
{ NULL, NULL }, /* Ap */
{ pres_dd, posts_dd }, /* Dd */
{ pres_dt, posts_dt }, /* Dt */
MDOC__U
};
+static const char * const secnames[SEC__MAX] = {
+ NULL,
+ "NAME",
+ "LIBRARY",
+ "SYNOPSIS",
+ "DESCRIPTION",
+ "IMPLEMENTATION NOTES",
+ "RETURN VALUES",
+ "ENVIRONMENT",
+ "FILES",
+ "EXIT STATUS",
+ "EXAMPLES",
+ "DIAGNOSTICS",
+ "COMPATIBILITY",
+ "ERRORS",
+ "SEE ALSO",
+ "STANDARDS",
+ "HISTORY",
+ "AUTHORS",
+ "CAVEATS",
+ "BUGS",
+ "SECURITY CONSIDERATIONS",
+ NULL
+};
int
mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *n)
}
t = lvl == CHECK_WARN ? MANDOCERR_ARGCWARN : MANDOCERR_ARGCOUNT;
-
- return(mdoc_vmsg(m, t, m->last->line, m->last->pos,
+ mandoc_vmsg(t, m->parse, m->last->line, m->last->pos,
"want %s%d children (have %d)",
- p, val, m->last->nchild));
+ p, val, m->last->nchild);
+ return(1);
}
static int
static void
check_text(struct mdoc *m, int ln, int pos, char *p)
{
- int c;
+ char *cpp, *pp;
size_t sz;
- for ( ; *p; p++, pos++) {
+ while ('\0' != *p) {
sz = strcspn(p, "\t\\");
- p += (int)sz;
-
- if ('\0' == *p)
- break;
+ p += (int)sz;
pos += (int)sz;
if ('\t' == *p) {
if ( ! (MDOC_LITERAL & m->flags))
mdoc_pmsg(m, ln, pos, MANDOCERR_BADTAB);
+ p++;
+ pos++;
continue;
- }
+ } else if ('\0' == *p)
+ break;
+
+ pos++;
+ pp = ++p;
- if (0 == (c = mandoc_special(p))) {
+ if (ESCAPE_ERROR == mandoc_escape
+ ((const char **)&pp, NULL, NULL)) {
mdoc_pmsg(m, ln, pos, MANDOCERR_BADESCAPE);
- continue;
+ break;
}
- p += c - 1;
- pos += c - 1;
+ cpp = p;
+ while (NULL != (cpp = memchr(cpp, ASCII_HYPH, pp - cpp)))
+ *cpp = '-';
+
+ pos += pp - p;
+ p = pp;
}
}
(t == n->parent->type))
return(1);
- mdoc_vmsg(mdoc, MANDOCERR_SYNTCHILD,
- n->line, n->pos, "want parent %s",
- MDOC_ROOT == t ? "<root>" :
- mdoc_macronames[tok]);
+ mandoc_vmsg(MANDOCERR_SYNTCHILD, mdoc->parse, n->line,
+ n->pos, "want parent %s", MDOC_ROOT == t ?
+ "<root>" : mdoc_macronames[tok]);
return(0);
}
static int
post_it(POST_ARGS)
{
- int i, cols, rc;
+ int i, cols;
enum mdoc_list lt;
struct mdoc_node *n, *c;
enum mandocerr er;
else
er = MANDOCERR_SYNTARGCOUNT;
- rc = mdoc_vmsg(mdoc, er,
- mdoc->last->line, mdoc->last->pos,
+ mandoc_vmsg(er, mdoc->parse, mdoc->last->line,
+ mdoc->last->pos,
"columns == %d (have %d)", cols, i);
- return(rc);
+ return(MANDOCERR_ARGCOUNT == er);
default:
break;
}
width = 6;
else if (MDOC_MAX == (tok = mdoc_hash_find(n->norm->Bl.width)))
return(1);
- else if (0 == (width = mdoc_macro2len(tok))) {
+ else if (0 == (width = macro2len(tok))) {
mdoc_nmsg(mdoc, n, MANDOCERR_BADWIDTH);
return(1);
}
break;
}
- if (0 != (ssz = mdoc_macro2len(nn->tok)))
+ if (0 != (ssz = macro2len(nn->tok)))
sz = ssz;
break;
assert(0 == np->args->argv[j].sz);
/*
- * Accomodate for new-style groff column syntax. Shuffle the
+ * Accommodate for new-style groff column syntax. Shuffle the
* child nodes, all of which must be TEXT, as arguments for the
* column field. Then, delete the head children.
*/
if ( ! concat(mdoc, buf, mdoc->last->child, BUFSIZ))
return(0);
- sec = mdoc_str2sec(buf);
+ sec = a2sec(buf);
/* The NAME should be first. */
n = mdoc->last;
if (NULL == n->child || '\0' == n->child->string[0]) {
- mdoc->meta.date = mandoc_normdate(NULL,
- mdoc->msg, mdoc->data, n->line, n->pos);
+ mdoc->meta.date = mandoc_normdate
+ (mdoc->parse, NULL, n->line, n->pos);
return(1);
}
if ( ! concat(mdoc, buf, n->child, DATESIZE))
return(0);
- mdoc->meta.date = mandoc_normdate(buf,
- mdoc->msg, mdoc->data, n->line, n->pos);
+ mdoc->meta.date = mandoc_normdate
+ (mdoc->parse, buf, n->line, n->pos);
return(1);
}
n = mdoc->last->child;
if (n && NULL != (n = n->next))
- *n->string = toupper((unsigned char)*n->string);
+ *n->string = (char)toupper
+ ((unsigned char)*n->string);
return(1);
}
return(0);
}
#else /*!OSNAME */
- if (uname(&utsname)) {
+ if (-1 == uname(&utsname)) {
mdoc_nmsg(mdoc, n, MANDOCERR_UNAME);
mdoc->meta.os = mandoc_strdup("UNKNOWN");
return(post_prol(mdoc));
return(1);
}
+static enum mdoc_sec
+a2sec(const char *p)
+{
+ int i;
+
+ for (i = 0; i < (int)SEC__MAX; i++)
+ if (secnames[i] && 0 == strcmp(p, secnames[i]))
+ return((enum mdoc_sec)i);
+
+ return(SEC_CUSTOM);
+}
+
+static size_t
+macro2len(enum mdoct macro)
+{
+
+ switch (macro) {
+ case(MDOC_Ad):
+ return(12);
+ case(MDOC_Ao):
+ return(12);
+ case(MDOC_An):
+ return(12);
+ case(MDOC_Aq):
+ return(12);
+ case(MDOC_Ar):
+ return(12);
+ case(MDOC_Bo):
+ return(12);
+ case(MDOC_Bq):
+ return(12);
+ case(MDOC_Cd):
+ return(12);
+ case(MDOC_Cm):
+ return(10);
+ case(MDOC_Do):
+ return(10);
+ case(MDOC_Dq):
+ return(12);
+ case(MDOC_Dv):
+ return(12);
+ case(MDOC_Eo):
+ return(12);
+ case(MDOC_Em):
+ return(10);
+ case(MDOC_Er):
+ return(17);
+ case(MDOC_Ev):
+ return(15);
+ case(MDOC_Fa):
+ return(12);
+ case(MDOC_Fl):
+ return(10);
+ case(MDOC_Fo):
+ return(16);
+ case(MDOC_Fn):
+ return(16);
+ case(MDOC_Ic):
+ return(10);
+ case(MDOC_Li):
+ return(16);
+ case(MDOC_Ms):
+ return(6);
+ case(MDOC_Nm):
+ return(10);
+ case(MDOC_No):
+ return(12);
+ case(MDOC_Oo):
+ return(10);
+ case(MDOC_Op):
+ return(14);
+ case(MDOC_Pa):
+ return(32);
+ case(MDOC_Pf):
+ return(12);
+ case(MDOC_Po):
+ return(12);
+ case(MDOC_Pq):
+ return(12);
+ case(MDOC_Ql):
+ return(16);
+ case(MDOC_Qo):
+ return(12);
+ case(MDOC_So):
+ return(12);
+ case(MDOC_Sq):
+ return(12);
+ case(MDOC_Sy):
+ return(6);
+ case(MDOC_Sx):
+ return(16);
+ case(MDOC_Tn):
+ return(10);
+ case(MDOC_Va):
+ return(12);
+ case(MDOC_Vt):
+ return(12);
+ case(MDOC_Xr):
+ return(10);
+ default:
+ break;
+ };
+ return(0);
+}