]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.36 2011/02/09 09:18:15 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
;
110 p
= mdoc_macronames
[n
->tok
];
113 p
= mdoc_macronames
[n
->tok
];
116 p
= mdoc_macronames
[n
->tok
];
119 p
= mdoc_macronames
[n
->tok
];
121 argv
= n
->args
->argv
;
122 argc
= n
->args
->argc
;
126 p
= mdoc_macronames
[n
->tok
];
128 argv
= n
->args
->argv
;
129 argc
= n
->args
->argc
;
147 print_span(n
->span
, 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
->line
, n
->pos
);
173 print_mdoc(n
->child
, indent
+ 1);
175 print_mdoc(n
->next
, indent
);
180 print_man(const struct man_node
*n
, int indent
)
228 p
= man_macronames
[n
->tok
];
245 print_span(n
->span
, indent
);
247 for (i
= 0; i
< indent
; i
++)
249 printf("%s (%s) %d:%d", p
, t
, n
->line
, n
->pos
);
255 print_man(n
->child
, indent
+ 1);
257 print_man(n
->next
, indent
);
261 print_span(const struct tbl_span
*sp
, int indent
)
263 const struct tbl_dat
*dp
;
266 for (i
= 0; i
< indent
; i
++)
270 case (TBL_SPAN_HORIZ
):
273 case (TBL_SPAN_DHORIZ
):
280 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
282 case (TBL_DATA_HORIZ
):
284 case (TBL_DATA_NHORIZ
):
287 case (TBL_DATA_DHORIZ
):
289 case (TBL_DATA_NDHORIZ
):
295 printf("[\"%s\"", dp
->string
? dp
->string
: "");
297 printf("(%d)", dp
->spans
);
298 if (NULL
== dp
->layout
)
304 printf("(tbl) %d:1", sp
->line
);