=================================================================== RCS file: /cvs/mandoc/tree.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -p -r1.7 -r1.8 --- mandoc/tree.c 2009/02/23 07:09:13 1.7 +++ mandoc/tree.c 2009/03/19 16:17:27 1.8 @@ -1,6 +1,6 @@ -/* $Id: tree.c,v 1.7 2009/02/23 07:09:13 kristaps dead $ */ +/* $Id: tree.c,v 1.8 2009/03/19 16:17:27 kristaps Exp $ */ /* - * Copyright (c) 2008 Kristaps Dzonsons + * Copyright (c) 2008, 2009 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the @@ -16,23 +16,33 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ -#include +#include +#include #include +#include #include "mdoc.h" -#define xprintf (void)printf +static void tree_body(const struct mdoc_node *, int); -static void treeprint_r(const struct mdoc_node *, int); +int +tree_run(void *arg, const struct mdoc *mdoc) +{ + + tree_body(mdoc_node(mdoc), 0); + return(1); +} + + static void -treeprint_r(const struct mdoc_node *n, int indent) +tree_body(const struct mdoc_node *n, int indent) { const char *p, *t; int i, j; size_t argc, sz; char **params; - struct mdoc_arg *argv; + struct mdoc_argv *argv; argv = NULL; argc = sz = 0; @@ -67,7 +77,7 @@ treeprint_r(const struct mdoc_node *n, int indent) switch (n->type) { case (MDOC_TEXT): - p = n->data.text.string; + p = n->string; break; case (MDOC_BODY): p = mdoc_macronames[n->tok]; @@ -80,13 +90,17 @@ treeprint_r(const struct mdoc_node *n, int indent) break; case (MDOC_ELEM): p = mdoc_macronames[n->tok]; - argv = n->data.elem.argv; - argc = n->data.elem.argc; + if (n->args) { + argv = n->args->argv; + argc = n->args->argc; + } break; case (MDOC_BLOCK): p = mdoc_macronames[n->tok]; - argv = n->data.block.argv; - argc = n->data.block.argc; + if (n->args) { + argv = n->args->argv; + argc = n->args->argc; + } break; case (MDOC_ROOT): p = "root"; @@ -97,36 +111,27 @@ treeprint_r(const struct mdoc_node *n, int indent) } for (i = 0; i < indent; i++) - xprintf(" "); - xprintf("%s (%s)", p, t); + (void)printf(" "); + (void)printf("%s (%s)", p, t); for (i = 0; i < (int)argc; i++) { - xprintf(" -%s", mdoc_argnames[argv[i].arg]); + (void)printf(" -%s", mdoc_argnames[argv[i].arg]); if (argv[i].sz > 0) - xprintf(" ["); + (void)printf(" ["); for (j = 0; j < (int)argv[i].sz; j++) - xprintf(" [%s]", argv[i].value[j]); + (void)printf(" [%s]", argv[i].value[j]); if (argv[i].sz > 0) - xprintf(" ]"); + (void)printf(" ]"); } for (i = 0; i < (int)sz; i++) - xprintf(" [%s]", params[i]); + (void)printf(" [%s]", params[i]); - xprintf(" %d:%d\n", n->line, n->pos); + (void)printf(" %d:%d\n", n->line, n->pos); if (n->child) - treeprint_r(n->child, indent + 1); + tree_body(n->child, indent + 1); if (n->next) - treeprint_r(n->next, indent); + tree_body(n->next, indent); } - -/* ARGSUSED */ -void -treeprint(const struct mdoc_node *node, - const struct mdoc_meta *meta) -{ - - treeprint_r(node, 0); -}