]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.10 2009/03/23 15:20:51 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
27 static void tree_mdoc(const struct mdoc_node
*, int);
28 static void tree_man(const struct man_node
*, int);
33 tree_run(void *arg
, const struct man
*man
,
34 const struct mdoc
*mdoc
)
38 tree_man(man_node(man
), 0);
40 tree_mdoc(mdoc_node(mdoc
), 0);
46 tree_mdoc(const struct mdoc_node
*n
, int indent
)
52 struct mdoc_argv
*argv
;
90 p
= mdoc_macronames
[n
->tok
];
93 p
= mdoc_macronames
[n
->tok
];
96 p
= mdoc_macronames
[n
->tok
];
99 p
= mdoc_macronames
[n
->tok
];
101 argv
= n
->args
->argv
;
102 argc
= n
->args
->argc
;
106 p
= mdoc_macronames
[n
->tok
];
108 argv
= n
->args
->argv
;
109 argc
= n
->args
->argc
;
120 for (i
= 0; i
< indent
; i
++)
122 (void)printf("%s (%s)", p
, t
);
124 for (i
= 0; i
< (int)argc
; i
++) {
125 (void)printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
128 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
129 (void)printf(" [%s]", argv
[i
].value
[j
]);
134 for (i
= 0; i
< (int)sz
; i
++)
135 (void)printf(" [%s]", params
[i
]);
137 (void)printf(" %d:%d\n", n
->line
, n
->pos
);
140 tree_mdoc(n
->child
, indent
+ 1);
142 tree_mdoc(n
->next
, indent
);
147 tree_man(const struct man_node
*n
, int indent
)
172 p
= man_macronames
[n
->tok
];
182 for (i
= 0; i
< indent
; i
++)
184 (void)printf("%s (%s) %d:%d\n", p
, t
, n
->line
, n
->pos
);
187 tree_man(n
->child
, indent
+ 1);
189 tree_man(n
->next
, indent
);