1 /* $Vendor-Id: tree.c,v 1.18 2009/10/30 18:53:09 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
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.
26 static void print_mdoc(const struct mdoc_node
*, int);
27 static void print_man(const struct man_node
*, int);
32 tree_mdoc(void *arg
, const struct mdoc
*mdoc
)
35 print_mdoc(mdoc_node(mdoc
), 0);
41 tree_man(void *arg
, const struct man
*man
)
44 print_man(man_node(man
), 0);
49 print_mdoc(const struct mdoc_node
*n
, int indent
)
55 struct mdoc_argv
*argv
;
93 p
= mdoc_macronames
[n
->tok
];
96 p
= mdoc_macronames
[n
->tok
];
99 p
= mdoc_macronames
[n
->tok
];
102 p
= mdoc_macronames
[n
->tok
];
104 argv
= n
->args
->argv
;
105 argc
= n
->args
->argc
;
109 p
= mdoc_macronames
[n
->tok
];
111 argv
= n
->args
->argv
;
112 argc
= n
->args
->argc
;
123 for (i
= 0; i
< indent
; i
++)
125 (void)printf("%s (%s)", p
, t
);
127 for (i
= 0; i
< (int)argc
; i
++) {
128 (void)printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
131 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
132 (void)printf(" [%s]", argv
[i
].value
[j
]);
137 for (i
= 0; i
< (int)sz
; i
++)
138 (void)printf(" [%s]", params
[i
]);
140 (void)printf(" %d:%d\n", n
->line
, n
->pos
);
143 print_mdoc(n
->child
, indent
+ 1);
145 print_mdoc(n
->next
, indent
);
150 print_man(const struct man_node
*n
, int indent
)
190 p
= man_macronames
[n
->tok
];
200 for (i
= 0; i
< indent
; i
++)
202 (void)printf("%s (%s) %d:%d\n", p
, t
, n
->line
, n
->pos
);
205 print_man(n
->child
, indent
+ 1);
207 print_man(n
->next
, indent
);