aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-01-05 16:11:14 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-01-05 16:11:14 +0000
commit15ff2c88b54b3a9deb82db8f12168847c99a1904 (patch)
tree531dde04cf25d86a5f9e4f440ab5e0d5c7fa7a86
parentdffebd8f3a78d88f60b2dc8706c4b9227071f1de (diff)
downloadmandoc-15ff2c88b54b3a9deb82db8f12168847c99a1904.tar.gz
mandoc-15ff2c88b54b3a9deb82db8f12168847c99a1904.tar.zst
mandoc-15ff2c88b54b3a9deb82db8f12168847c99a1904.zip
Finished initial parse sequence.
-rw-r--r--action.c4
-rw-r--r--argv.c7
-rw-r--r--macro.c308
-rw-r--r--mdoc.c87
-rw-r--r--mdoc.h10
-rw-r--r--mdocml.c6
-rw-r--r--private.h9
-rw-r--r--prologue.c6
8 files changed, 340 insertions, 97 deletions
diff --git a/action.c b/action.c
index c099803a..c7f27266 100644
--- a/action.c
+++ b/action.c
@@ -1,4 +1,4 @@
-/* $Id: action.c,v 1.1 2009/01/05 14:14:04 kristaps Exp $ */
+/* $Id: action.c,v 1.2 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -160,5 +160,7 @@ mdoc_action(struct mdoc *mdoc, int tok, int pos)
default:
break;
}
+
+ MDOC_Nm... ?
#endif
diff --git a/argv.c b/argv.c
index cae607ee..69d2fa08 100644
--- a/argv.c
+++ b/argv.c
@@ -1,4 +1,4 @@
-/* $Id: argv.c,v 1.6 2009/01/02 14:06:16 kristaps Exp $ */
+/* $Id: argv.c,v 1.7 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -162,6 +162,11 @@ lookup(int tok, const char *argv)
return(MDOC_Offset);
break;
+ case (MDOC_Bk):
+ if (xstrcmp(argv, "words"))
+ return(MDOC_Words);
+ break;
+
case (MDOC_Bl):
if (xstrcmp(argv, "bullet"))
return(MDOC_Bullet);
diff --git a/macro.c b/macro.c
index d5ad4331..c529ab5e 100644
--- a/macro.c
+++ b/macro.c
@@ -1,4 +1,4 @@
-/* $Id: macro.c,v 1.21 2009/01/05 14:14:04 kristaps Exp $ */
+/* $Id: macro.c,v 1.22 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -30,9 +30,10 @@
/* FIXME: maxlineargs should be per LINE, no per TOKEN. */
static int rewind_elem(struct mdoc *, int, int);
-static int rewind_imp(struct mdoc *, int, int);
-static int rewind_exp(struct mdoc *, int, int, int);
-static int rewind_line(struct mdoc *, int, int);
+static int rewind_impblock(struct mdoc *, int, int);
+static int rewind_expblock(struct mdoc *, int, int, int);
+static int rewind_head(struct mdoc *, int, int);
+static int rewind_body(struct mdoc *, int, int, int);
static int append_delims(struct mdoc *, int, int *, char *);
@@ -56,7 +57,30 @@ rewind_elem(struct mdoc *mdoc, int ppos, int tok)
static int
-rewind_line(struct mdoc *mdoc, int ppos, int tok)
+rewind_body(struct mdoc *mdoc, int ppos, int tok, int tt)
+{
+ struct mdoc_node *n;
+
+ /* LINTED */
+ for (n = mdoc->last; n; n = n->parent) {
+ if (MDOC_BODY != n->type)
+ continue;
+ if (tt == n->data.head.tok)
+ break;
+ if ( ! (MDOC_EXPLICIT & mdoc_macros[tt].flags))
+ continue;
+ return(mdoc_err(mdoc, tok, ppos, ERR_SCOPE_BREAK));
+ }
+
+ mdoc->last = n ? n : mdoc->last;
+ mdoc->next = MDOC_NEXT_SIBLING;
+ /* XXX - no validation, we do this only for blocks/elements. */
+ return(1);
+}
+
+
+static int
+rewind_head(struct mdoc *mdoc, int ppos, int tok)
{
struct mdoc_node *n;
int t;
@@ -80,7 +104,7 @@ rewind_line(struct mdoc *mdoc, int ppos, int tok)
static int
-rewind_exp(struct mdoc *mdoc, int ppos, int tok, int tt)
+rewind_expblock(struct mdoc *mdoc, int ppos, int tok, int tt)
{
struct mdoc_node *n;
@@ -92,6 +116,8 @@ rewind_exp(struct mdoc *mdoc, int ppos, int tok, int tt)
continue;
if (tt == n->data.block.tok)
break;
+ if (MDOC_NESTED & mdoc_macros[n->data.block.tok].flags)
+ continue;
return(mdoc_err(mdoc, tok, ppos, ERR_SCOPE_BREAK));
}
@@ -106,7 +132,7 @@ rewind_exp(struct mdoc *mdoc, int ppos, int tok, int tt)
static int
-rewind_imp(struct mdoc *mdoc, int ppos, int tok)
+rewind_impblock(struct mdoc *mdoc, int ppos, int tok)
{
struct mdoc_node *n;
int t;
@@ -132,58 +158,159 @@ rewind_imp(struct mdoc *mdoc, int ppos, int tok)
}
+static int
+append_delims(struct mdoc *mdoc, int tok, int *pos, char *buf)
+{
+ int c, lastarg;
+ char *p;
+
+ if (0 == buf[*pos])
+ return(1);
+
+ for (;;) {
+ lastarg = *pos;
+ c = mdoc_args(mdoc, tok, pos, buf, 0, &p);
+ if (ARGS_ERROR == c)
+ return(0);
+ else if (ARGS_EOLN == c)
+ break;
+ assert(mdoc_isdelim(p));
+ mdoc_word_alloc(mdoc, lastarg, p);
+ mdoc->next = MDOC_NEXT_SIBLING;
+ }
+
+ return(1);
+}
+
+
/* ARGSUSED */
int
macro_close_explicit(MACRO_PROT_ARGS)
{
- int tt;
+ int tt, j, c, lastarg, maxargs, flushed;
+ char *p;
switch (tok) {
- case (MDOC_El):
- tt = MDOC_Bl;
+ case (MDOC_Ac):
+ tt = MDOC_Ao;
+ break;
+ case (MDOC_Bc):
+ tt = MDOC_Bo;
+ break;
+ case (MDOC_Dc):
+ tt = MDOC_Do;
+ break;
+ case (MDOC_Ec):
+ tt = MDOC_Eo;
break;
case (MDOC_Ed):
tt = MDOC_Bd;
break;
+ case (MDOC_Ef):
+ tt = MDOC_Bf;
+ break;
+ case (MDOC_Ek):
+ tt = MDOC_Bk;
+ break;
+ case (MDOC_El):
+ tt = MDOC_Bl;
+ break;
+ case (MDOC_Fo):
+ tt = MDOC_Fc;
+ break;
+ case (MDOC_Oc):
+ tt = MDOC_Oo;
+ break;
+ case (MDOC_Pc):
+ tt = MDOC_Po;
+ break;
+ case (MDOC_Qc):
+ tt = MDOC_Qo;
+ break;
case (MDOC_Re):
tt = MDOC_Rs;
break;
- case (MDOC_Ef):
- tt = MDOC_Bf;
+ case (MDOC_Sc):
+ tt = MDOC_So;
+ break;
+ case (MDOC_Xc):
+ tt = MDOC_Xo;
break;
default:
abort();
/* NOTREACHED */
}
- if (0 != buf[*pos])
- return(mdoc_err(mdoc, tok, ppos, ERR_ARGS_EQ0));
- return(rewind_exp(mdoc, ppos, tok, tt));
-}
+ switch (tok) {
+ case (MDOC_Ec):
+ maxargs = 1;
+ break;
+ default:
+ maxargs = 0;
+ break;
+ }
+ if ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) {
+ if ( ! rewind_expblock(mdoc, ppos, tok, tt))
+ return(0);
+ if (0 != buf[*pos])
+ return(mdoc_err(mdoc, tok, *pos, ERR_ARGS_EQ0));
+ return(1);
+ }
-static int
-append_delims(struct mdoc *mdoc, int tok, int *pos, char *buf)
-{
- int c, lastarg;
- char *p;
+ if ( ! rewind_body(mdoc, ppos, tok, tt))
+ return(0);
- if (0 == buf[*pos])
- return(1);
+ lastarg = ppos;
+ flushed = 0;
- for (;;) {
+ if (maxargs > 0) {
+ mdoc_tail_alloc(mdoc, ppos, tt);
+ mdoc->next = MDOC_NEXT_CHILD;
+ }
+
+ for (j = 0; j < MDOC_LINEARG_MAX; j++) {
lastarg = *pos;
- c = mdoc_args(mdoc, tok, pos, buf, 0, &p);
+
+ if (j == maxargs && ! flushed) {
+ if ( ! rewind_expblock(mdoc, ppos, tok, tt))
+ return(0);
+ flushed = 1;
+ }
+
+ c = mdoc_args(mdoc, tok, pos, buf, ARGS_DELIM, &p);
if (ARGS_ERROR == c)
return(0);
- else if (ARGS_EOLN == c)
+ if (ARGS_PUNCT == c)
break;
- assert(mdoc_isdelim(p));
+ if (ARGS_EOLN == c)
+ break;
+
+ if (MDOC_MAX != (c = mdoc_find(mdoc, p))) {
+ if ( ! flushed) {
+ if ( ! rewind_expblock(mdoc, ppos, tok, tt))
+ return(0);
+ flushed = 1;
+ }
+ if ( ! mdoc_macro(mdoc, c, lastarg, pos, buf))
+ return(0);
+ break;
+ }
+
mdoc_word_alloc(mdoc, lastarg, p);
mdoc->next = MDOC_NEXT_SIBLING;
}
- return(1);
+ if (MDOC_LINEARG_MAX == j)
+ return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
+
+ if ( ! flushed)
+ if ( ! rewind_expblock(mdoc, ppos, tok, tt))
+ return(0);
+
+ if (ppos > 1)
+ return(1);
+ return(append_delims(mdoc, tok, pos, buf));
}
@@ -298,8 +425,9 @@ macro_scoped(MACRO_PROT_ARGS)
assert ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags));
- if ( ! (MDOC_EXPLICIT & mdoc_macros[tok].flags))
- if ( ! rewind_imp(mdoc, ppos, tok))
+ if ( ! (MDOC_EXPLICIT & mdoc_macros[tok].flags) &&
+ ! (MDOC_NESTED & mdoc_macros[tok].flags))
+ if ( ! rewind_impblock(mdoc, ppos, tok))
return(0);
lastarg = ppos;
@@ -334,27 +462,13 @@ macro_scoped(MACRO_PROT_ARGS)
mdoc_word_alloc(mdoc, lastarg, &buf[*pos]);
mdoc->next = MDOC_NEXT_SIBLING;
- if ( ! rewind_line(mdoc, ppos, tok))
+ if ( ! rewind_head(mdoc, ppos, tok))
return(0);
while (buf[*pos])
(*pos)++;
}
-#if 0
- /* Post-processing. */
- switch (tok) {
- case (MDOC_Sh):
- sec = mdoc_atosec((size_t)sz, _CC(args));
- if (SEC_CUSTOM != sec)
- mdoc->sec_lastn = sec;
- mdoc->sec_last = sec;
- break;
- default:
- break;
- }
-#endif
-
mdoc_body_alloc(mdoc, ppos, tok);
mdoc->next = MDOC_NEXT_CHILD;
@@ -412,12 +526,104 @@ macro_scoped_line(MACRO_PROT_ARGS)
return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
if (1 == ppos) {
- if ( ! rewind_line(mdoc, ppos, tok))
+ if ( ! rewind_head(mdoc, ppos, tok))
return(0);
if ( ! append_delims(mdoc, tok, pos, buf))
return(0);
}
- return(rewind_imp(mdoc, ppos, tok));
+ return(rewind_impblock(mdoc, ppos, tok));
+}
+
+
+int
+macro_constant_scoped(MACRO_PROT_ARGS)
+{
+ int lastarg, flushed, j, c, maxargs;
+ char *p;
+
+ lastarg = ppos;
+ flushed = 0;
+
+ switch (tok) {
+ case (MDOC_Eo):
+ maxargs = 1;
+ break;
+ default:
+ maxargs = 0;
+ break;
+ }
+
+ if ( ! mdoc_valid_pre(mdoc, tok, ppos, 0, NULL))
+ return(0);
+
+ mdoc_block_alloc(mdoc, ppos, tok, 0, NULL);
+ mdoc->next = MDOC_NEXT_CHILD;
+
+ if (0 == maxargs) {
+ mdoc_body_alloc(mdoc, ppos, tok);
+ flushed = 1;
+ } else
+ mdoc_head_alloc(mdoc, ppos, tok);
+
+ mdoc->next = MDOC_NEXT_CHILD;
+
+ for (j = 0; j < MDOC_LINEARG_MAX; j++) {
+ lastarg = *pos;
+
+ if (j == maxargs && ! flushed) {
+ if ( ! rewind_head(mdoc, ppos, tok))
+ return(0);
+ flushed = 1;
+ mdoc_body_alloc(mdoc, ppos, tok);
+ mdoc->next = MDOC_NEXT_CHILD;
+ }
+
+ c = mdoc_args(mdoc, tok, pos, buf, ARGS_DELIM, &p);
+ if (ARGS_ERROR == c)
+ return(0);
+ if (ARGS_PUNCT == c)
+ break;
+ if (ARGS_EOLN == c)
+ break;
+
+ if (MDOC_MAX != (c = mdoc_find(mdoc, p))) {
+ if ( ! flushed) {
+ if ( ! rewind_head(mdoc, ppos, tok))
+ return(0);
+ flushed = 1;
+ mdoc_body_alloc(mdoc, ppos, tok);
+ mdoc->next = MDOC_NEXT_CHILD;
+ }
+ if ( ! mdoc_macro(mdoc, c, lastarg, pos, buf))
+ return(0);
+ break;
+ }
+
+ if ( ! flushed && mdoc_isdelim(p)) {
+ if ( ! rewind_head(mdoc, ppos, tok))
+ return(0);
+ flushed = 1;
+ mdoc_body_alloc(mdoc, ppos, tok);
+ mdoc->next = MDOC_NEXT_CHILD;
+ }
+
+ mdoc_word_alloc(mdoc, lastarg, p);
+ mdoc->next = MDOC_NEXT_SIBLING;
+ }
+
+ if (MDOC_LINEARG_MAX == j)
+ return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
+
+ if ( ! flushed) {
+ if ( ! rewind_head(mdoc, ppos, tok))
+ return(0);
+ mdoc_body_alloc(mdoc, ppos, tok);
+ mdoc->next = MDOC_NEXT_CHILD;
+ }
+
+ if (ppos > 1)
+ return(1);
+ return(append_delims(mdoc, tok, pos, buf));
}
@@ -478,7 +684,7 @@ macro_constant_delimited(MACRO_PROT_ARGS)
break;
}
- if (mdoc_isdelim(p)) {
+ if ( ! flushed && mdoc_isdelim(p)) {
if ( ! rewind_elem(mdoc, ppos, tok))
return(0);
flushed = 1;
@@ -488,12 +694,12 @@ macro_constant_delimited(MACRO_PROT_ARGS)
mdoc->next = MDOC_NEXT_SIBLING;
}
- if ( ! flushed && rewind_elem(mdoc, ppos, tok))
- return(0);
-
if (MDOC_LINEARG_MAX == j)
return(mdoc_err(mdoc, tok, lastarg, ERR_ARGS_MANY));
+ if ( ! flushed && rewind_elem(mdoc, ppos, tok))
+ return(0);
+
if (ppos > 1)
return(1);
return(append_delims(mdoc, tok, pos, buf));
diff --git a/mdoc.c b/mdoc.c
index fe175850..876e773c 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.16 2009/01/05 14:14:04 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.17 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -85,9 +85,9 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
{ NULL, 0 }, /* \" */
- { NULL, MDOC_PROLOGUE }, /* Dd */
- { NULL, MDOC_PROLOGUE }, /* Dt */
- { NULL, MDOC_PROLOGUE }, /* Os */
+ { macro_prologue, MDOC_PROLOGUE }, /* Dd */
+ { macro_prologue, MDOC_PROLOGUE }, /* Dt */
+ { macro_prologue, MDOC_PROLOGUE }, /* Os */
{ macro_scoped, 0 }, /* Sh */
{ macro_scoped, 0 }, /* Ss */
{ macro_text, 0 }, /* Pp */
@@ -97,7 +97,7 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
{ macro_close_explicit, 0 }, /* Ed */
{ macro_scoped, MDOC_EXPLICIT }, /* Bl */
{ macro_close_explicit, 0 }, /* El */
- { NULL, 0 }, /* It */
+ { macro_scoped, MDOC_NESTED }, /* It */
{ macro_text, MDOC_CALLABLE }, /* Ad */
{ macro_constant, 0 }, /* An */
{ macro_text, MDOC_CALLABLE }, /* Ar */
@@ -116,7 +116,7 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
{ macro_constant, 0 }, /* In */
{ macro_text, MDOC_CALLABLE }, /* Li */
{ macro_constant, 0 }, /* Nd */
- { NULL, 0 }, /* Nm */
+ { macro_text, MDOC_CALLABLE }, /* Nm */
{ macro_scoped_line, MDOC_CALLABLE }, /* Op */
{ macro_obsolete, 0 }, /* Ot */
{ macro_text, MDOC_CALLABLE }, /* Pa */
@@ -136,56 +136,56 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
{ macro_constant, MDOC_QUOTABLE }, /* %R */
{ macro_constant, MDOC_QUOTABLE }, /* %T */
{ macro_constant, MDOC_QUOTABLE }, /* %V */
- { NULL, 0 }, /* Ac */
- { NULL, 0 }, /* Ao */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Ac */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Ao */
{ macro_scoped_line, MDOC_CALLABLE }, /* Aq */
{ macro_constant, 0 }, /* At */
- { NULL, 0 }, /* Bc */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Bc */
{ macro_scoped, MDOC_EXPLICIT }, /* Bf */
- { NULL, 0 }, /* Bo */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Bo */
{ macro_scoped_line, MDOC_CALLABLE }, /* Bq */
{ macro_constant_delimited, 0 }, /* Bsx */
{ macro_constant_delimited, 0 }, /* Bx */
{ macro_constant, 0 }, /* Db */
- { NULL, 0 }, /* Dc */
- { NULL, 0 }, /* Do */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Dc */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Do */
{ macro_scoped_line, MDOC_CALLABLE }, /* Dq */
- { NULL, 0 }, /* Ec */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Ec */
{ macro_close_explicit, 0 }, /* Ef */
{ macro_text, MDOC_CALLABLE }, /* Em */
- { NULL, 0 }, /* Eo */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Eo */
{ macro_constant_delimited, 0 }, /* Fx */
{ macro_text, 0 }, /* Ms */
{ macro_constant_delimited, MDOC_CALLABLE }, /* No */
{ macro_constant_delimited, MDOC_CALLABLE }, /* Ns */
{ macro_constant_delimited, 0 }, /* Nx */
{ macro_constant_delimited, 0 }, /* Ox */
- { NULL, 0 }, /* Pc */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Pc */
{ macro_constant, 0 }, /* Pf */
- { NULL, 0 }, /* Po */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Po */
{ macro_scoped_line, MDOC_CALLABLE }, /* Pq */
- { NULL, 0 }, /* Qc */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Qc */
{ macro_scoped_line, MDOC_CALLABLE }, /* Ql */
- { NULL, 0 }, /* Qo */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Qo */
{ macro_scoped_line, MDOC_CALLABLE }, /* Qq */
{ macro_scoped, MDOC_EXPLICIT }, /* Re */
{ macro_scoped, MDOC_EXPLICIT }, /* Rs */
- { NULL, 0 }, /* Sc */
- { NULL, 0 }, /* So */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Sc */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* So */
{ macro_scoped_line, MDOC_CALLABLE }, /* Sq */
{ macro_constant, 0 }, /* Sm */
{ macro_text, MDOC_CALLABLE }, /* Sx */
{ macro_text, MDOC_CALLABLE }, /* Sy */
{ macro_text, MDOC_CALLABLE }, /* Tn */
{ macro_constant_delimited, 0 }, /* Ux */
- { NULL, 0 }, /* Xc */
- { NULL, 0 }, /* Xo */
- { NULL, 0 }, /* Fo */
- { NULL, 0 }, /* Fc */
- { NULL, 0 }, /* Oo */
- { NULL, 0 }, /* Oc */
- { NULL, 0 }, /* Bk */
- { NULL, 0 }, /* Ek */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Xc */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Xo */
+ { macro_scoped, MDOC_EXPLICIT }, /* Fo */ /* XXX - supposed to be (but isn't) callable. */
+ { macro_close_explicit, 0 }, /* Fc */ /* XXX - supposed to be (but isn't) callable. */
+ { macro_constant_scoped, MDOC_CALLABLE }, /* Oo */
+ { macro_close_explicit, MDOC_CALLABLE }, /* Oc */
+ { macro_scoped, MDOC_EXPLICIT }, /* Bk */
+ { macro_close_explicit, 0 }, /* Ek */
{ macro_constant, 0 }, /* Bt */
{ macro_constant, 0 }, /* Hf */
{ macro_obsolete, 0 }, /* Fr */
@@ -326,11 +326,8 @@ int
mdoc_macro(struct mdoc *mdoc, int tok, int ppos, int *pos, char *buf)
{
- if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
+ if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
SEC_PROLOGUE == mdoc->sec_lastn)
- return(macro_prologue(mdoc, tok, ppos, pos, buf));
-
- if (SEC_PROLOGUE == mdoc->sec_lastn)
return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE));
if (NULL == (mdoc_macros[tok].fp)) {
@@ -369,6 +366,10 @@ mdoc_node_append(struct mdoc *mdoc, int pos, struct mdoc_node *p)
nn = mdoc_macronames[p->data.head.tok];
nt = "head";
break;
+ case (MDOC_TAIL):
+ nn = mdoc_macronames[p->data.tail.tok];
+ nt = "tail";
+ break;
case (MDOC_BLOCK):
nn = mdoc_macronames[p->data.block.tok];
nt = "block";
@@ -403,6 +404,10 @@ mdoc_node_append(struct mdoc *mdoc, int pos, struct mdoc_node *p)
on = mdoc_macronames[mdoc->last->data.head.tok];
ot = "head";
break;
+ case (MDOC_TAIL):
+ on = mdoc_macronames[mdoc->last->data.tail.tok];
+ ot = "tail";
+ break;
case (MDOC_BLOCK):
on = mdoc_macronames[mdoc->last->data.block.tok];
ot = "block";
@@ -437,6 +442,23 @@ mdoc_node_append(struct mdoc *mdoc, int pos, struct mdoc_node *p)
void
+mdoc_tail_alloc(struct mdoc *mdoc, int pos, int tok)
+{
+ struct mdoc_node *p;
+
+ assert(mdoc->first);
+ assert(mdoc->last);
+
+ p = xcalloc(1, sizeof(struct mdoc_node));
+
+ p->type = MDOC_TAIL;
+ p->data.tail.tok = tok;
+
+ mdoc_node_append(mdoc, pos, p);
+}
+
+
+void
mdoc_head_alloc(struct mdoc *mdoc, int pos, int tok)
{
struct mdoc_node *p;
@@ -496,7 +518,6 @@ mdoc_elem_alloc(struct mdoc *mdoc, int pos, int tok,
p = xcalloc(1, sizeof(struct mdoc_node));
p->type = MDOC_ELEM;
p->data.elem.tok = tok;
- /* FIXME: freeing of params... */
p->data.elem.argc = argsz;
p->data.elem.argv = argdup(argsz, args);
diff --git a/mdoc.h b/mdoc.h
index 7301217b..1d8b0b0c 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.13 2009/01/03 18:38:39 kristaps Exp $ */
+/* $Id: mdoc.h,v 1.14 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -265,6 +265,7 @@ enum mdoc_type {
MDOC_TEXT,
MDOC_ELEM,
MDOC_HEAD,
+ MDOC_TAIL,
MDOC_BODY,
MDOC_BLOCK
};
@@ -376,8 +377,10 @@ struct mdoc_block {
};
struct mdoc_head {
- size_t sz;
- char **args;
+ int tok;
+};
+
+struct mdoc_tail {
int tok;
};
@@ -398,6 +401,7 @@ union mdoc_data {
struct mdoc_elem elem;
struct mdoc_body body;
struct mdoc_head head;
+ struct mdoc_tail tail;
struct mdoc_block block;
};
diff --git a/mdocml.c b/mdocml.c
index 284e0483..7ebd50a0 100644
--- a/mdocml.c
+++ b/mdocml.c
@@ -1,4 +1,4 @@
-/* $Id: mdocml.c,v 1.33 2009/01/03 22:10:22 kristaps Exp $ */
+/* $Id: mdocml.c,v 1.34 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -206,6 +206,10 @@ print_node(const struct mdoc_node *n, int indent)
p = mdoc_macronames[n->data.head.tok];
t = "block-head";
break;
+ case (MDOC_TAIL):
+ p = mdoc_macronames[n->data.tail.tok];
+ t = "block-tail";
+ break;
case (MDOC_ELEM):
p = mdoc_macronames[n->data.elem.tok];
t = "element";
diff --git a/private.h b/private.h
index b78dcdb6..051e22e7 100644
--- a/private.h
+++ b/private.h
@@ -1,4 +1,4 @@
-/* $Id: private.h,v 1.54 2009/01/05 14:14:04 kristaps Exp $ */
+/* $Id: private.h,v 1.55 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -46,6 +46,7 @@ struct mdoc_macro {
#define MDOC_EXPLICIT (1 << 1)
#define MDOC_QUOTABLE (1 << 2)
#define MDOC_PROLOGUE (1 << 3)
+#define MDOC_NESTED (1 << 4)
};
extern const struct mdoc_macro *const mdoc_macros;
@@ -66,6 +67,7 @@ void mdoc_elem_alloc(struct mdoc *, int, int,
void mdoc_block_alloc(struct mdoc *, int, int,
size_t, const struct mdoc_arg *);
void mdoc_head_alloc(struct mdoc *, int, int);
+void mdoc_tail_alloc(struct mdoc *, int, int);
void mdoc_body_alloc(struct mdoc *, int, int);
void mdoc_node_free(struct mdoc_node *);
void mdoc_sibling(struct mdoc *, int, struct mdoc_node **,
@@ -111,16 +113,13 @@ void *xcalloc(size_t, size_t);
char *xstrdup(const char *);
int macro_obsolete(MACRO_PROT_ARGS);
-int macro_constant_quoted(MACRO_PROT_ARGS);
-int macro_constant_obsolete(MACRO_PROT_ARGS);
-int macro_constant_argv(MACRO_PROT_ARGS);
int macro_constant(MACRO_PROT_ARGS);
+int macro_constant_scoped(MACRO_PROT_ARGS);
int macro_constant_delimited(MACRO_PROT_ARGS);
int macro_text(MACRO_PROT_ARGS);
int macro_scoped(MACRO_PROT_ARGS);
int macro_close_explicit(MACRO_PROT_ARGS);
int macro_scoped_line(MACRO_PROT_ARGS);
-int macro_scoped_pline(MACRO_PROT_ARGS);
int macro_prologue(MACRO_PROT_ARGS);
__END_DECLS
diff --git a/prologue.c b/prologue.c
index 30713dbe..5790e4a2 100644
--- a/prologue.c
+++ b/prologue.c
@@ -1,4 +1,4 @@
-/* $Id: prologue.c,v 1.2 2009/01/02 14:06:16 kristaps Exp $ */
+/* $Id: prologue.c,v 1.3 2009/01/05 16:11:14 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -24,6 +24,8 @@
#include "private.h"
+/* FIXME: deprecate into actions.c! */
+
static int prologue_dt(MACRO_PROT_ARGS);
static int prologue_dd(MACRO_PROT_ARGS);
static int prologue_os(MACRO_PROT_ARGS);
@@ -180,7 +182,7 @@ again:
return(0);
if (0 == j) {
- if (xstrcmp("$Mdocdate: January 2 2009 $", args[j])) {
+ if (xstrcmp("$Mdocdate: January 5 2009 $", args[j])) {
mdoc->meta.date = time(NULL);
goto again;
} else if (xstrcmp("$Mdocdate:", args[j]))