summaryrefslogtreecommitdiffstats
path: root/tree.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 11:34:53 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-07-21 11:34:53 +0000
commit5777d1fb503dd116e90a489fa562f0a89752541c (patch)
treea6d24495ae536ef90d93b7c33a0fa5cbc73082c7 /tree.c
parent49de222b7899f01575a6ac00a26bc345864dc826 (diff)
downloadmandoc-5777d1fb503dd116e90a489fa562f0a89752541c.tar.gz
Flip eqn into using parsed nodes. I've temporarily disabled printing
these in the front-ends except for -Ttree, which will display the parsed tree. While here, fix that quoted strings aren't scanned for replacement parts.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c68
1 files changed, 44 insertions, 24 deletions
diff --git a/tree.c b/tree.c
index bf43242d..b4f14523 100644
--- a/tree.c
+++ b/tree.c
@@ -28,8 +28,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);
@@ -63,6 +64,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):
@@ -90,18 +92,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;
@@ -130,9 +128,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";
@@ -143,8 +140,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');
@@ -164,11 +164,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)
@@ -182,6 +180,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";
@@ -205,18 +205,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;
@@ -236,9 +232,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();
@@ -246,16 +241,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)
@@ -263,6 +259,30 @@ print_man(const struct man_node *n, int indent)
}
static void
+print_box(const struct eqn_box *ep, int indent)
+{
+ int i;
+
+ if (NULL == ep)
+ return;
+ for (i = 0; i < indent; i++)
+ putchar('\t');
+
+ switch (ep->type) {
+ case (EQN_ROOT):
+ puts("eqn-root");
+ print_box(ep->child, indent + 1);
+ return;
+ case (EQN_TEXT):
+ printf("eqn-text: [%s]\n", ep->text);
+ print_box(ep->next, indent);
+ return;
+ default:
+ break;
+ }
+}
+
+static void
print_span(const struct tbl_span *sp, int indent)
{
const struct tbl_dat *dp;
@@ -306,5 +326,5 @@ print_span(const struct tbl_span *sp, int indent)
putchar(' ');
}
- printf("(tbl) %d:1", sp->line);
+ printf("(tbl) %d:1\n", sp->line);
}