1 /* $Id: tree.c,v 1.31 2011/01/03 13:59:21 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 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.
31 static void print_mdoc(const struct mdoc_node *, int);
32 static void print_man(const struct man_node *, int);
33 static void print_span(const struct tbl_span *, int);
38 tree_mdoc(void *arg, const struct mdoc *mdoc)
41 print_mdoc(mdoc_node(mdoc), 0);
47 tree_man(void *arg, const struct man *man)
50 print_man(man_node(man), 0);
55 print_mdoc(const struct mdoc_node *n, int indent)
61 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;
141 print_span(n->span, indent);
143 for (i = 0; i < indent; i++)
146 printf("%s (%s)", p, t);
148 for (i = 0; i < (int)argc; i++) {
149 printf(" -%s", mdoc_argnames[argv[i].arg]);
152 for (j = 0; j < (int)argv[i].sz; j++)
153 printf(" [%s]", argv[i].value[j]);
158 for (i = 0; i < (int)sz; i++)
159 printf(" [%s]", params[i]);
161 printf(" %d:%d", n->line, n->pos);
167 print_mdoc(n->child, indent + 1);
169 print_mdoc(n->next, indent);
174 print_man(const struct man_node *n, int indent)
219 p = man_macronames[n->tok];
233 print_span(n->span, indent);
235 for (i = 0; i < indent; i++)
237 printf("%s (%s) %d:%d", p, t, n->line, n->pos);
243 print_man(n->child, indent + 1);
245 print_man(n->next, indent);
249 print_span(const struct tbl_span *sp, int indent)
251 const struct tbl_dat *dp;
254 for (i = 0; i < indent; i++)
260 case (TBL_SPAN_HORIZ):
263 case (TBL_SPAN_DHORIZ):
270 for (dp = sp->first; dp; dp = dp->next) {
272 case (TBL_DATA_HORIZ):
274 case (TBL_DATA_NHORIZ):
277 case (TBL_DATA_DHORIZ):
279 case (TBL_DATA_NDHORIZ):
285 printf("[%s%s]", dp->string, dp->layout ? "" : "*");