=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.33 retrieving revision 1.38 diff -u -p -r1.33 -r1.38 --- mandoc/mdoc.c 2009/01/16 15:58:50 1.33 +++ mandoc/mdoc.c 2009/01/19 17:53:54 1.38 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.33 2009/01/16 15:58:50 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.38 2009/01/19 17:53:54 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -85,9 +85,9 @@ const char *const __mdoc_argnames[MDOC_ARG_MAX] = { const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { NULL, 0 }, /* \" */ - { macro_constant, MDOC_PROLOGUE }, /* Dd */ - { macro_constant, MDOC_PROLOGUE }, /* Dt */ - { macro_constant, MDOC_PROLOGUE }, /* Os */ + { macro_constant, MDOC_PROLOGUE | MDOC_NOKEEP }, /* Dd */ + { macro_constant, MDOC_PROLOGUE | MDOC_NOKEEP }, /* Dt */ + { macro_constant, MDOC_PROLOGUE | MDOC_NOKEEP }, /* Os */ { macro_scoped, 0 }, /* Sh */ { macro_scoped, 0 }, /* Ss */ { macro_text, 0 }, /* Pp */ @@ -140,7 +140,7 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { 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 */ @@ -205,7 +205,6 @@ static void argfree(size_t, struct mdoc_arg *); 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 *); @@ -213,13 +212,21 @@ static void mdoc_text_free(struct mdoc_text *); 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) { @@ -228,7 +235,13 @@ 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); } @@ -440,8 +453,6 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node * if ( ! mdoc_valid_pre(mdoc, p)) return(0); - if ( ! mdoc_action_pre(mdoc, p)) - return(0); switch (p->type) { case (MDOC_HEAD): @@ -660,7 +671,7 @@ mdoc_node_free(struct mdoc_node *p) } -static void +void mdoc_node_freelist(struct mdoc_node *p) { @@ -712,4 +723,28 @@ argdup(size_t argsz, const struct mdoc_arg *args) 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); +} +