1 /* Id: tree.c,v 1.50 2013/12/24 19:11:46 schwarze Exp */
3 * Copyright (c) 2008, 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013 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.
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);
41 tree_mdoc(void *arg
, const struct mdoc
*mdoc
)
44 print_mdoc(mdoc_node(mdoc
), 0);
50 tree_man(void *arg
, const struct man
*man
)
53 print_man(man_node(man
), 0);
58 print_mdoc(const struct mdoc_node
*n
, int indent
)
63 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
;
143 assert(NULL
== p
&& NULL
== t
);
144 print_span(n
->span
, indent
);
146 assert(NULL
== p
&& NULL
== t
);
147 print_box(n
->eqn
->root
, indent
);
149 for (i
= 0; i
< indent
; i
++)
152 printf("%s (%s)", p
, t
);
154 for (i
= 0; i
< (int)argc
; i
++) {
155 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
158 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
159 printf(" [%s]", argv
[i
].value
[j
]);
165 if (MDOC_LINE
& n
->flags
)
167 printf("%d:%d", n
->line
, n
->pos
);
168 if (n
->lastline
!= n
->line
)
169 printf("-%d", n
->lastline
);
174 print_mdoc(n
->child
, indent
+ 1);
176 print_mdoc(n
->next
, indent
);
181 print_man(const struct man_node
*n
, int indent
)
232 p
= man_macronames
[n
->tok
];
247 assert(NULL
== p
&& NULL
== t
);
248 print_span(n
->span
, indent
);
250 assert(NULL
== p
&& NULL
== t
);
251 print_box(n
->eqn
->root
, indent
);
253 for (i
= 0; i
< indent
; i
++)
255 printf("%s (%s) %d:%d\n", p
, t
, n
->line
, n
->pos
);
259 print_man(n
->child
, indent
+ 1);
261 print_man(n
->next
, indent
);
265 print_box(const struct eqn_box
*ep
, int indent
)
272 for (i
= 0; i
< indent
; i
++)
295 printf("%s(%d, %d, %d, %d, %d, \"%s\", \"%s\") %s\n",
296 t
, EQN_DEFSIZE
== ep
->size
? 0 : ep
->size
,
297 ep
->pos
, ep
->font
, ep
->mark
, ep
->pile
,
298 ep
->left
? ep
->left
: "",
299 ep
->right
? ep
->right
: "",
300 ep
->text
? ep
->text
: "");
302 print_box(ep
->first
, indent
+ 1);
303 print_box(ep
->next
, indent
);
307 print_span(const struct tbl_span
*sp
, int indent
)
309 const struct tbl_dat
*dp
;
312 for (i
= 0; i
< indent
; i
++)
316 case (TBL_SPAN_HORIZ
):
319 case (TBL_SPAN_DHORIZ
):
326 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
328 case (TBL_DATA_HORIZ
):
330 case (TBL_DATA_NHORIZ
):
333 case (TBL_DATA_DHORIZ
):
335 case (TBL_DATA_NDHORIZ
):
341 printf("[\"%s\"", dp
->string
? dp
->string
: "");
343 printf("(%d)", dp
->spans
);
344 if (NULL
== dp
->layout
)
350 printf("(tbl) %d:1\n", sp
->line
);