]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.42 2011/07/21 14:13:00 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_box(const struct eqn_box
*, int);
32 static void print_man(const struct man_node
*, int);
33 static void print_mdoc(const struct mdoc_node
*, int);
34 static void print_span(const struct tbl_span
*, int);
39 tree_mdoc(void *arg
, const struct mdoc
*mdoc
)
42 print_mdoc(mdoc_node(mdoc
), 0);
48 tree_man(void *arg
, const struct man
*man
)
51 print_man(man_node(man
), 0);
56 print_mdoc(const struct mdoc_node
*n
, int indent
)
62 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
]);
164 for (i
= 0; i
< (int)sz
; i
++)
165 printf(" [%s]", params
[i
]);
167 printf(" %d:%d\n", n
->line
, n
->pos
);
171 print_mdoc(n
->child
, indent
+ 1);
173 print_mdoc(n
->next
, indent
);
178 print_man(const struct man_node
*n
, int indent
)
229 p
= man_macronames
[n
->tok
];
244 assert(NULL
== p
&& NULL
== t
);
245 print_span(n
->span
, indent
);
247 assert(NULL
== p
&& NULL
== t
);
248 print_box(n
->eqn
->root
, indent
);
250 for (i
= 0; i
< indent
; i
++)
252 printf("%s (%s) %d:%d\n", p
, t
, n
->line
, n
->pos
);
256 print_man(n
->child
, indent
+ 1);
258 print_man(n
->next
, indent
);
262 print_box(const struct eqn_box
*ep
, int indent
)
268 for (i
= 0; i
< indent
; i
++)
273 printf("eqn-root(%d, %d, %d)\n",
274 ep
->pos
, ep
->font
, ep
->mark
);
275 print_box(ep
->child
, indent
+ 1);
278 printf("eqn-subxpr(%d, %d, %d)\n",
279 ep
->pos
, ep
->font
, ep
->mark
);
280 print_box(ep
->child
, indent
+ 1);
283 printf("eqn-text(%d, %d, %d): [%s]\n",
284 ep
->pos
, ep
->font
, ep
->mark
, ep
->text
);
290 print_box(ep
->next
, indent
);
294 print_span(const struct tbl_span
*sp
, int indent
)
296 const struct tbl_dat
*dp
;
299 for (i
= 0; i
< indent
; i
++)
303 case (TBL_SPAN_HORIZ
):
306 case (TBL_SPAN_DHORIZ
):
313 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
315 case (TBL_DATA_HORIZ
):
317 case (TBL_DATA_NHORIZ
):
320 case (TBL_DATA_DHORIZ
):
322 case (TBL_DATA_NDHORIZ
):
328 printf("[\"%s\"", dp
->string
? dp
->string
: "");
330 printf("(%d)", dp
->spans
);
331 if (NULL
== dp
->layout
)
337 printf("(tbl) %d:1\n", sp
->line
);