summaryrefslogtreecommitdiffstatshomepage
path: root/tree.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-03-23 15:20:51 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-03-23 15:20:51 +0000
commit1b03ebdce412e8ef752ed49e9aba8d666cdc9bf2 (patch)
tree961feffeeaf7e4b586c02cd6ba5c3ba04fe0d90e /tree.c
parent9e1962924d277421ea2bce83eed6738227fc0b54 (diff)
downloadmandoc-1b03ebdce412e8ef752ed49e9aba8d666cdc9bf2.tar.gz
mandoc-1b03ebdce412e8ef752ed49e9aba8d666cdc9bf2.tar.zst
mandoc-1b03ebdce412e8ef752ed49e9aba8d666cdc9bf2.zip
-man printing linked to -Ttree.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c66
1 files changed, 59 insertions, 7 deletions
diff --git a/tree.c b/tree.c
index edd28ed9..0d8835fb 100644
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.9 2009/03/19 16:20:37 kristaps Exp $ */
+/* $Id: tree.c,v 1.10 2009/03/23 15:20:51 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
*
@@ -22,22 +22,28 @@
#include <stdlib.h>
#include "mdoc.h"
+#include "man.h"
-static void tree_body(const struct mdoc_node *, int);
+static void tree_mdoc(const struct mdoc_node *, int);
+static void tree_man(const struct man_node *, int);
/* ARGSUSED */
int
-tree_run(void *arg, const struct mdoc *mdoc)
+tree_run(void *arg, const struct man *man,
+ const struct mdoc *mdoc)
{
- tree_body(mdoc_node(mdoc), 0);
+ if (man)
+ tree_man(man_node(man), 0);
+ if (mdoc)
+ tree_mdoc(mdoc_node(mdoc), 0);
return(1);
}
static void
-tree_body(const struct mdoc_node *n, int indent)
+tree_mdoc(const struct mdoc_node *n, int indent)
{
const char *p, *t;
int i, j;
@@ -131,8 +137,54 @@ tree_body(const struct mdoc_node *n, int indent)
(void)printf(" %d:%d\n", n->line, n->pos);
if (n->child)
- tree_body(n->child, indent + 1);
+ tree_mdoc(n->child, indent + 1);
if (n->next)
- tree_body(n->next, indent);
+ tree_mdoc(n->next, indent);
}
+
+static void
+tree_man(const struct man_node *n, int indent)
+{
+ const char *p, *t;
+ int i;
+
+ switch (n->type) {
+ case (MAN_ROOT):
+ t = "root";
+ break;
+ case (MAN_ELEM):
+ t = "elem";
+ break;
+ case (MAN_TEXT):
+ t = "text";
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+
+ switch (n->type) {
+ case (MAN_TEXT):
+ p = n->string;
+ break;
+ case (MAN_ELEM):
+ p = man_macronames[n->tok];
+ break;
+ case (MAN_ROOT):
+ p = "root";
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+
+ for (i = 0; i < indent; i++)
+ (void)printf(" ");
+ (void)printf("%s (%s) %d:%d\n", p, t, n->line, n->pos);
+
+ if (n->child)
+ tree_man(n->child, indent + 1);
+ if (n->next)
+ tree_man(n->next, indent);
+}