1 /* $Id: tree.c,v 1.60 2014/11/28 05:51:32 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013, 2014 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), 0);
47 tree_man(void *arg, const struct man *man)
50 print_man(man_node(man), 0);
54 print_mdoc(const struct mdoc_node *n, int indent)
59 struct mdoc_argv *argv;
105 p = mdoc_macronames[n->tok];
108 p = mdoc_macronames[n->tok];
111 p = mdoc_macronames[n->tok];
114 p = mdoc_macronames[n->tok];
116 argv = n->args->argv;
117 argc = n->args->argc;
121 p = mdoc_macronames[n->tok];
123 argv = n->args->argv;
124 argc = n->args->argc;
141 assert(NULL == p && NULL == t);
142 print_span(n->span, indent);
144 for (i = 0; i < indent; i++)
147 printf("%s (%s)", p, t);
149 for (i = 0; i < (int)argc; i++) {
150 printf(" -%s", mdoc_argnames[argv[i].arg]);
153 for (j = 0; j < (int)argv[i].sz; j++)
154 printf(" [%s]", argv[i].value[j]);
160 if (MDOC_LINE & n->flags)
162 printf("%d:%d", n->line, n->pos + 1);
163 if (n->lastline != n->line)
164 printf("-%d", n->lastline);
169 print_box(n->eqn->root->first, indent + 1);
171 print_mdoc(n->child, indent + 1);
173 print_mdoc(n->next, indent);
177 print_man(const struct man_node *n, int indent)
224 p = man_macronames[n->tok];
240 assert(NULL == p && NULL == t);
241 print_span(n->span, indent);
243 for (i = 0; i < indent; i++)
245 printf("%s (%s) ", p, t);
246 if (MAN_LINE & n->flags)
248 printf("%d:%d\n", n->line, n->pos + 1);
252 print_box(n->eqn->root->first, indent + 1);
254 print_man(n->child, indent + 1);
256 print_man(n->next, indent);
260 print_box(const struct eqn_box *ep, int indent)
265 static const char *posnames[] = {
266 NULL, "sup", "subsup", "sub",
267 "to", "from", "fromto",
268 "over", "sqrt", NULL };
272 for (i = 0; i < indent; i++)
300 printf(" pos=%s", posnames[ep->pos]);
302 printf(" left=\"%s\"", ep->left);
304 printf(" right=\"%s\"", ep->right);
306 printf(" top=\"%s\"", ep->top);
308 printf(" bottom=\"%s\"", ep->bottom);
310 printf(" text=\"%s\"", ep->text);
312 printf(" font=%d", ep->font);
313 if (ep->size != EQN_DEFSIZE)
314 printf(" size=%d", ep->size);
315 if (ep->expectargs != UINT_MAX && ep->expectargs != ep->args)
316 printf(" badargs=%zu(%zu)", ep->args, ep->expectargs);
318 printf(" args=%zu", ep->args);
321 print_box(ep->first, indent + 1);
322 print_box(ep->next, indent);
326 print_span(const struct tbl_span *sp, int indent)
328 const struct tbl_dat *dp;
331 for (i = 0; i < indent; i++)
338 case TBL_SPAN_DHORIZ:
345 for (dp = sp->first; dp; dp = dp->next) {
349 case TBL_DATA_NHORIZ:
352 case TBL_DATA_DHORIZ:
354 case TBL_DATA_NDHORIZ:
360 printf("[\"%s\"", dp->string ? dp->string : "");
362 printf("(%d)", dp->spans);
363 if (NULL == dp->layout)
369 printf("(tbl) %d:1\n", sp->line);