1 /* $Id: tree.c,v 1.49 2013/09/15 17:33:57 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 static void print_box(const struct eqn_box *, int);
33 static void print_man(const struct man_node *, int);
34 static void print_mdoc(const struct mdoc_node *, int);
35 static void print_span(const struct tbl_span *, int);
40 tree_mdoc(void *arg, const struct mdoc *mdoc)
43 print_mdoc(mdoc_node(mdoc), 0);
49 tree_man(void *arg, const struct man *man)
52 print_man(man_node(man), 0);
57 print_mdoc(const struct mdoc_node *n, int indent)
62 struct mdoc_argv *argv;
107 p = mdoc_macronames[n->tok];
110 p = mdoc_macronames[n->tok];
113 p = mdoc_macronames[n->tok];
116 p = mdoc_macronames[n->tok];
118 argv = n->args->argv;
119 argc = n->args->argc;
123 p = mdoc_macronames[n->tok];
125 argv = n->args->argv;
126 argc = n->args->argc;
142 assert(NULL == p && NULL == t);
143 print_span(n->span, indent);
145 assert(NULL == p && NULL == t);
146 print_box(n->eqn->root, indent);
148 for (i = 0; i < indent; i++)
151 printf("%s (%s)", p, t);
153 for (i = 0; i < (int)argc; i++) {
154 printf(" -%s", mdoc_argnames[argv[i].arg]);
157 for (j = 0; j < (int)argv[i].sz; j++)
158 printf(" [%s]", argv[i].value[j]);
164 if (MDOC_LINE & n->flags)
166 printf("%d:%d\n", n->line, n->pos);
170 print_mdoc(n->child, indent + 1);
172 print_mdoc(n->next, indent);
177 print_man(const struct man_node *n, int indent)
228 p = man_macronames[n->tok];
243 assert(NULL == p && NULL == t);
244 print_span(n->span, indent);
246 assert(NULL == p && NULL == t);
247 print_box(n->eqn->root, indent);
249 for (i = 0; i < indent; i++)
251 printf("%s (%s) %d:%d\n", p, t, n->line, n->pos);
255 print_man(n->child, indent + 1);
257 print_man(n->next, indent);
261 print_box(const struct eqn_box *ep, int indent)
268 for (i = 0; i < indent; i++)
291 printf("%s(%d, %d, %d, %d, %d, \"%s\", \"%s\") %s\n",
292 t, EQN_DEFSIZE == ep->size ? 0 : ep->size,
293 ep->pos, ep->font, ep->mark, ep->pile,
294 ep->left ? ep->left : "",
295 ep->right ? ep->right : "",
296 ep->text ? ep->text : "");
298 print_box(ep->first, indent + 1);
299 print_box(ep->next, indent);
303 print_span(const struct tbl_span *sp, int indent)
305 const struct tbl_dat *dp;
308 for (i = 0; i < indent; i++)
312 case (TBL_SPAN_HORIZ):
315 case (TBL_SPAN_DHORIZ):
322 for (dp = sp->first; dp; dp = dp->next) {
324 case (TBL_DATA_HORIZ):
326 case (TBL_DATA_NHORIZ):
329 case (TBL_DATA_DHORIZ):
331 case (TBL_DATA_NDHORIZ):
337 printf("[\"%s\"", dp->string ? dp->string : "");
339 printf("(%d)", dp->spans);
340 if (NULL == dp->layout)
346 printf("(tbl) %d:1\n", sp->line);