-/* $Id: mdoc.c,v 1.31 2009/01/15 17:38:57 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.39 2009/01/20 12:51:28 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
{ macro_scoped_close, MDOC_EXPLICIT }, /* El */
{ macro_scoped, MDOC_PARSED | MDOC_TABSEP}, /* It */
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */
- { macro_constant, MDOC_PARSED }, /* An */
+ { macro_text, MDOC_PARSED }, /* An */
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */
{ macro_constant, MDOC_QUOTABLE }, /* Cd */
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */
{ macro_constant, 0 }, /* Fd */
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */
{ macro_text, MDOC_CALLABLE | MDOC_QUOTABLE | MDOC_PARSED }, /* Fn */
- { macro_text, MDOC_PARSED }, /* Ft */
+ { macro_text, MDOC_PARSED | MDOC_QUOTABLE }, /* Ft */
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */
{ macro_constant, 0 }, /* In */
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */
{ macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ao */
{ macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Aq */
- { macro_constant, 0 }, /* At */
+ { macro_constant_delimited, 0 }, /* At */
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Bc */
{ macro_scoped, MDOC_EXPLICIT }, /* Bf */
{ macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Bo */
{ macro_constant_delimited, MDOC_PARSED }, /* Nx */
{ macro_constant_delimited, MDOC_PARSED }, /* Ox */
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */
- { macro_constant, MDOC_PARSED }, /* Pf */
+ { macro_constant_delimited, MDOC_PARSED }, /* Pf */
{ macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Po */
{ macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pq */
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */
static void argcpy(struct mdoc_arg *,
const struct mdoc_arg *);
-static void mdoc_node_freelist(struct mdoc_node *);
static int mdoc_node_append(struct mdoc *,
struct mdoc_node *);
static void mdoc_elem_free(struct mdoc_elem *);
const struct mdoc_node *
-mdoc_result(struct mdoc *mdoc)
+mdoc_node(struct mdoc *mdoc)
{
return(mdoc->first);
}
+const struct mdoc_meta *
+mdoc_meta(struct mdoc *mdoc)
+{
+
+ return(&mdoc->meta);
+}
+
+
void
mdoc_free(struct mdoc *mdoc)
{
mdoc_node_freelist(mdoc->first);
if (mdoc->htab)
mdoc_tokhash_free(mdoc->htab);
-
+ if (mdoc->meta.title)
+ free(mdoc->meta.title);
+ if (mdoc->meta.os)
+ free(mdoc->meta.os);
+ if (mdoc->meta.name)
+ free(mdoc->meta.name);
+
free(mdoc);
}
p = xcalloc(1, sizeof(struct mdoc));
p->data = data;
- (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
+ if (cb)
+ (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
p->last = xcalloc(1, sizeof(struct mdoc_node));
p->last->type = MDOC_ROOT;
if (MDOC_HALT & mdoc->flags)
return(0);
+ mdoc->linetok = 0;
+
if ('.' != *buf) {
- if (SEC_PROLOGUE != mdoc->sec_lastn) {
- if ( ! mdoc_word_alloc(mdoc, line, 0, buf))
- return(0);
- mdoc->next = MDOC_NEXT_SIBLING;
- return(1);
- }
- return(mdoc_perr(mdoc, line, 0, "text disallowed"));
+ if ( ! (MDOC_BODYPARSE & mdoc->flags))
+ return(mdoc_perr(mdoc, line, 0, "text disallowed"));
+ if ( ! mdoc_word_alloc(mdoc, line, 0, buf))
+ return(0);
+ mdoc->next = MDOC_NEXT_SIBLING;
+ return(1);
}
if (buf[1] && '\\' == buf[1])
assert(mdoc_macros[tok].fp);
if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
- SEC_PROLOGUE == mdoc->sec_lastn)
- return(mdoc_perr(mdoc, ln, ppos, "macro disallowed in document prologue"));
+ ! (MDOC_BODYPARSE & mdoc->flags))
+ return(mdoc_perr(mdoc, ln, ppos, "macro disallowed: not in document body"));
if (1 != ppos && ! (MDOC_CALLABLE & mdoc_macros[tok].flags))
return(mdoc_perr(mdoc, ln, ppos, "macro not callable"));
return((*mdoc_macros[tok].fp)(mdoc, tok, ln, ppos, pos, buf));
assert(mdoc->first);
assert(MDOC_ROOT != p->type);
+ /* See if we exceed the suggest line-max. */
+
+ switch (p->type) {
+ case (MDOC_TEXT):
+ /* FALLTHROUGH */
+ case (MDOC_ELEM):
+ /* FALLTHROUGH */
+ case (MDOC_BLOCK):
+ mdoc->linetok++;
+ break;
+ default:
+ break;
+ }
+
+ if (mdoc->linetok > MDOC_LINEARG_SOFTMAX)
+ if ( ! mdoc_nwarn(mdoc, p, WARN_COMPAT,
+ "suggested %d tokens per line exceeded (has %d)",
+ MDOC_LINEARG_SOFTMAX, mdoc->linetok))
+ return(0);
+
if (MDOC_TEXT == mdoc->last->type)
on = "<text>";
else if (MDOC_ROOT == mdoc->last->type)
if ( ! mdoc_valid_pre(mdoc, p))
return(0);
- if ( ! mdoc_action_pre(mdoc, p))
- return(0);
switch (p->type) {
case (MDOC_HEAD):
}
-static void
+void
mdoc_node_freelist(struct mdoc_node *p)
{
return(pp);
}
+
+/* FIXME: deprecate. */
+char *
+mdoc_node2a(struct mdoc_node *node)
+{
+ static char buf[64];
+
+ assert(node);
+
+ buf[0] = 0;
+ (void)xstrlcat(buf, mdoc_type2a(node->type), 64);
+ if (MDOC_ROOT == node->type)
+ return(buf);
+ (void)xstrlcat(buf, " `", 64);
+ if (MDOC_TEXT == node->type)
+ (void)xstrlcat(buf, node->data.text.string, 64);
+ else
+ (void)xstrlcat(buf, mdoc_macronames[node->tok], 64);
+ (void)xstrlcat(buf, "'", 64);
+
+ return(buf);
+}
+
+