-/* $Id: tree.c,v 1.30 2011/01/02 20:34:05 kristaps Exp $ */
+/* $Id: tree.c,v 1.42 2011/07/21 14:13:00 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
#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);
argv = NULL;
argc = sz = 0;
params = NULL;
+ t = p = NULL;
switch (n->type) {
case (MDOC_ROOT):
t = "text";
break;
case (MDOC_TBL):
- t = "tbl";
+ /* FALLTHROUGH */
+ case (MDOC_EQN):
break;
default:
abort();
/* NOTREACHED */
}
- p = NULL;
-
switch (n->type) {
case (MDOC_TEXT):
p = n->string;
}
break;
case (MDOC_TBL):
+ /* FALLTHROUGH */
+ case (MDOC_EQN):
break;
case (MDOC_ROOT):
p = "root";
}
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');
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)
const char *p, *t;
int i;
+ t = p = NULL;
+
switch (n->type) {
case (MAN_ROOT):
t = "root";
case (MAN_BODY):
t = "block-body";
break;
+ case (MAN_TAIL):
+ t = "block-tail";
+ break;
case (MAN_TBL):
- t = "tbl";
+ /* FALLTHROUGH */
+ case (MAN_EQN):
break;
default:
abort();
/* NOTREACHED */
}
- p = NULL;
-
switch (n->type) {
case (MAN_TEXT):
p = n->string;
/* FALLTHROUGH */
case (MAN_HEAD):
/* FALLTHROUGH */
+ case (MAN_TAIL):
+ /* FALLTHROUGH */
case (MAN_BODY):
p = man_macronames[n->tok];
break;
p = "root";
break;
case (MAN_TBL):
+ /* FALLTHROUGH */
+ case (MAN_EQN):
break;
default:
abort();
}
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)
}
static void
-print_span(const struct tbl_span *sp, int indent)
+print_box(const struct eqn_box *ep, int indent)
{
- const struct tbl_dat *dp;
- const struct tbl_head *hp;
int i;
- if (TBL_SPAN_FIRST & sp->flags) {
- for (i = 0; i < indent; i++)
- putchar('\t');
- printf("tbl-head: ");
- for (hp = sp->head; hp; hp = hp->next) {
- printf("[%d]", hp->width);
- if (hp->next)
- putchar(' ');
- }
- putchar('\n');
+ if (NULL == ep)
+ return;
+ for (i = 0; i < indent; i++)
+ putchar('\t');
+
+ switch (ep->type) {
+ case (EQN_ROOT):
+ printf("eqn-root(%d, %d, %d)\n",
+ ep->pos, ep->font, ep->mark);
+ print_box(ep->child, indent + 1);
+ break;
+ case (EQN_SUBEXPR):
+ printf("eqn-subxpr(%d, %d, %d)\n",
+ ep->pos, ep->font, ep->mark);
+ print_box(ep->child, indent + 1);
+ break;
+ case (EQN_TEXT):
+ printf("eqn-text(%d, %d, %d): [%s]\n",
+ ep->pos, ep->font, ep->mark, ep->text);
+ break;
+ default:
+ break;
}
+ print_box(ep->next, indent);
+}
+
+static void
+print_span(const struct tbl_span *sp, int indent)
+{
+ const struct tbl_dat *dp;
+ int i;
+
for (i = 0; i < indent; i++)
putchar('\t');
- printf("tbl: ");
-
switch (sp->pos) {
case (TBL_SPAN_HORIZ):
putchar('-');
default:
break;
}
- printf("[%s%s]", dp->string, dp->layout ? "" : "*");
- if (dp->next)
- putchar(' ');
+ printf("[\"%s\"", dp->string ? dp->string : "");
+ if (dp->spans)
+ printf("(%d)", dp->spans);
+ if (NULL == dp->layout)
+ putchar('*');
+ putchar(']');
+ putchar(' ');
}
+
+ printf("(tbl) %d:1\n", sp->line);
}