1 /* $Id: tree.c,v 1.62 2015/02/05 00:14:13 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
33 static void print_box(const struct eqn_box *, int);
34 static void print_man(const struct man_node *, int);
35 static void print_mdoc(const struct mdoc_node *, int);
36 static void print_span(const struct tbl_span *, int);
40 tree_mdoc(void *arg, const struct mdoc *mdoc)
43 print_mdoc(mdoc_node(mdoc)->child, 0);
47 tree_man(void *arg, const struct man *man)
50 print_man(man_node(man)->child, 0);
54 print_mdoc(const struct mdoc_node *n, int indent)
59 struct mdoc_argv *argv;
108 p = mdoc_macronames[n->tok];
111 p = mdoc_macronames[n->tok];
114 p = mdoc_macronames[n->tok];
117 p = mdoc_macronames[n->tok];
119 argv = n->args->argv;
120 argc = n->args->argc;
124 p = mdoc_macronames[n->tok];
126 argv = n->args->argv;
127 argc = n->args->argc;
144 assert(NULL == p && NULL == t);
145 print_span(n->span, indent);
147 for (i = 0; i < indent; i++)
150 printf("%s (%s)", p, t);
152 for (i = 0; i < (int)argc; i++) {
153 printf(" -%s", mdoc_argnames[argv[i].arg]);
156 for (j = 0; j < (int)argv[i].sz; j++)
157 printf(" [%s]", argv[i].value[j]);
163 if (MDOC_LINE & n->flags)
165 printf("%d:%d\n", n->line, n->pos + 1);
169 print_box(n->eqn->root->first, indent + 4);
171 print_mdoc(n->child, indent +
172 (n->type == MDOC_BLOCK ? 2 : 4));
174 print_mdoc(n->next, indent);
178 print_man(const struct man_node *n, int indent)
228 p = man_macronames[n->tok];
244 assert(NULL == p && NULL == t);
245 print_span(n->span, indent);
247 for (i = 0; i < indent; i++)
249 printf("%s (%s) ", p, t);
250 if (MAN_LINE & n->flags)
252 printf("%d:%d\n", n->line, n->pos + 1);
256 print_box(n->eqn->root->first, indent + 4);
258 print_man(n->child, indent +
259 (n->type == MAN_BLOCK ? 2 : 4));
261 print_man(n->next, indent);
265 print_box(const struct eqn_box *ep, int indent)
270 static const char *posnames[] = {
271 NULL, "sup", "subsup", "sub",
272 "to", "from", "fromto",
273 "over", "sqrt", NULL };
277 for (i = 0; i < indent; i++)
305 printf(" pos=%s", posnames[ep->pos]);
307 printf(" left=\"%s\"", ep->left);
309 printf(" right=\"%s\"", ep->right);
311 printf(" top=\"%s\"", ep->top);
313 printf(" bottom=\"%s\"", ep->bottom);
315 printf(" text=\"%s\"", ep->text);
317 printf(" font=%d", ep->font);
318 if (ep->size != EQN_DEFSIZE)
319 printf(" size=%d", ep->size);
320 if (ep->expectargs != UINT_MAX && ep->expectargs != ep->args)
321 printf(" badargs=%zu(%zu)", ep->args, ep->expectargs);
323 printf(" args=%zu", ep->args);
326 print_box(ep->first, indent + 4);
327 print_box(ep->next, indent);
331 print_span(const struct tbl_span *sp, int indent)
333 const struct tbl_dat *dp;
336 for (i = 0; i < indent; i++)
343 case TBL_SPAN_DHORIZ:
350 for (dp = sp->first; dp; dp = dp->next) {
354 case TBL_DATA_NHORIZ:
357 case TBL_DATA_DHORIZ:
359 case TBL_DATA_NDHORIZ:
365 printf("[\"%s\"", dp->string ? dp->string : "");
367 printf("(%d)", dp->spans);
368 if (NULL == dp->layout)
374 printf("(tbl) %d:1\n", sp->line);