summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/mandoc/tree.c')
-rw-r--r--usr.bin/mandoc/tree.c89
1 files changed, 64 insertions, 25 deletions
diff --git a/usr.bin/mandoc/tree.c b/usr.bin/mandoc/tree.c
index 19b91d7f9bd..8d97dfb46e7 100644
--- a/usr.bin/mandoc/tree.c
+++ b/usr.bin/mandoc/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.15 2011/04/24 16:22:02 schwarze Exp $ */
+/* $Id: tree.c,v 1.16 2011/09/18 10:25:28 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -15,6 +15,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <assert.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@@ -24,8 +25,9 @@
#include "man.h"
#include "main.h"
-static void print_mdoc(const struct mdoc_node *, int);
+static void print_box(const struct eqn_box *, int);
static void print_man(const struct man_node *, int);
+static void print_mdoc(const struct mdoc_node *, int);
static void print_span(const struct tbl_span *, int);
@@ -59,6 +61,7 @@ print_mdoc(const struct mdoc_node *n, int indent)
argv = NULL;
argc = sz = 0;
params = NULL;
+ t = p = NULL;
switch (n->type) {
case (MDOC_ROOT):
@@ -86,18 +89,14 @@ print_mdoc(const struct mdoc_node *n, int indent)
t = "text";
break;
case (MDOC_TBL):
- t = "tbl";
- break;
+ /* FALLTHROUGH */
case (MDOC_EQN):
- t = "eqn";
break;
default:
abort();
/* NOTREACHED */
}
- p = NULL;
-
switch (n->type) {
case (MDOC_TEXT):
p = n->string;
@@ -126,9 +125,8 @@ print_mdoc(const struct mdoc_node *n, int indent)
}
break;
case (MDOC_TBL):
- break;
+ /* FALLTHROUGH */
case (MDOC_EQN):
- p = n->eqn->data;
break;
case (MDOC_ROOT):
p = "root";
@@ -139,8 +137,11 @@ print_mdoc(const struct mdoc_node *n, int indent)
}
if (n->span) {
- assert(NULL == p);
+ assert(NULL == p && NULL == t);
print_span(n->span, indent);
+ } else if (n->eqn) {
+ assert(NULL == p && NULL == t);
+ print_box(n->eqn->root, indent);
} else {
for (i = 0; i < indent; i++)
putchar('\t');
@@ -160,11 +161,9 @@ print_mdoc(const struct mdoc_node *n, int indent)
for (i = 0; i < (int)sz; i++)
printf(" [%s]", params[i]);
- printf(" %d:%d", n->line, n->pos);
+ printf(" %d:%d\n", n->line, n->pos);
}
- putchar('\n');
-
if (n->child)
print_mdoc(n->child, indent + 1);
if (n->next)
@@ -178,6 +177,8 @@ print_man(const struct man_node *n, int indent)
const char *p, *t;
int i;
+ t = p = NULL;
+
switch (n->type) {
case (MAN_ROOT):
t = "root";
@@ -201,18 +202,14 @@ print_man(const struct man_node *n, int indent)
t = "block-tail";
break;
case (MAN_TBL):
- t = "tbl";
- break;
+ /* FALLTHROUGH */
case (MAN_EQN):
- t = "eqn";
break;
default:
abort();
/* NOTREACHED */
}
- p = NULL;
-
switch (n->type) {
case (MAN_TEXT):
p = n->string;
@@ -232,9 +229,8 @@ print_man(const struct man_node *n, int indent)
p = "root";
break;
case (MAN_TBL):
- break;
+ /* FALLTHROUGH */
case (MAN_EQN):
- p = n->eqn->data;
break;
default:
abort();
@@ -242,16 +238,17 @@ print_man(const struct man_node *n, int indent)
}
if (n->span) {
- assert(NULL == p);
+ assert(NULL == p && NULL == t);
print_span(n->span, indent);
+ } else if (n->eqn) {
+ assert(NULL == p && NULL == t);
+ print_box(n->eqn->root, indent);
} else {
for (i = 0; i < indent; i++)
putchar('\t');
- printf("%s (%s) %d:%d", p, t, n->line, n->pos);
+ printf("%s (%s) %d:%d\n", p, t, n->line, n->pos);
}
- putchar('\n');
-
if (n->child)
print_man(n->child, indent + 1);
if (n->next)
@@ -259,6 +256,48 @@ print_man(const struct man_node *n, int indent)
}
static void
+print_box(const struct eqn_box *ep, int indent)
+{
+ int i;
+ const char *t;
+
+ if (NULL == ep)
+ return;
+ for (i = 0; i < indent; i++)
+ putchar('\t');
+
+ t = NULL;
+ switch (ep->type) {
+ case (EQN_ROOT):
+ t = "eqn-root";
+ break;
+ case (EQN_LIST):
+ t = "eqn-list";
+ break;
+ case (EQN_SUBEXPR):
+ t = "eqn-expr";
+ break;
+ case (EQN_TEXT):
+ t = "eqn-text";
+ break;
+ case (EQN_MATRIX):
+ t = "eqn-matrix";
+ break;
+ }
+
+ assert(t);
+ printf("%s(%d, %d, %d, %d, %d, \"%s\", \"%s\") %s\n",
+ t, EQN_DEFSIZE == ep->size ? 0 : ep->size,
+ ep->pos, ep->font, ep->mark, ep->pile,
+ ep->left ? ep->left : "",
+ ep->right ? ep->right : "",
+ ep->text ? ep->text : "");
+
+ print_box(ep->first, indent + 1);
+ print_box(ep->next, indent);
+}
+
+static void
print_span(const struct tbl_span *sp, int indent)
{
const struct tbl_dat *dp;
@@ -302,5 +341,5 @@ print_span(const struct tbl_span *sp, int indent)
putchar(' ');
}
- printf("(tbl) %d:1", sp->line);
+ printf("(tbl) %d:1\n", sp->line);
}