]>
git.cameronkatri.com Git - mandoc.git/blob - mdoctree.c
1 /* $Id: mdoctree.c,v 1.5 2009/03/06 14:13:47 kristaps Exp $ */
3 * Copyright (c) 2008 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
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 #define xprintf (void)printf
29 static void doprint(const struct mdoc_node
*, int);
32 main(int argc
, char *argv
[])
36 const struct mdoc
*mdoc
;
40 c
= mmain_getopt(p
, argc
, argv
, NULL
, NULL
, NULL
, NULL
);
42 mmain_exit(p
, -1 == c
? 1 : 0);
44 if (NULL
== (mdoc
= mmain_mdoc(p
)))
47 doprint(mdoc_node(mdoc
), 0);
54 doprint(const struct mdoc_node
*n
, int indent
)
60 struct mdoc_arg
*argv
;
95 p
= n
->data
.text
.string
;
98 p
= mdoc_macronames
[n
->tok
];
101 p
= mdoc_macronames
[n
->tok
];
104 p
= mdoc_macronames
[n
->tok
];
107 p
= mdoc_macronames
[n
->tok
];
108 argv
= n
->data
.elem
.argv
;
109 argc
= n
->data
.elem
.argc
;
112 p
= mdoc_macronames
[n
->tok
];
113 argv
= n
->data
.block
.argv
;
114 argc
= n
->data
.block
.argc
;
124 for (i
= 0; i
< indent
; i
++)
126 xprintf("%s (%s)", p
, t
);
128 for (i
= 0; i
< (int)argc
; i
++) {
129 xprintf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
132 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
133 xprintf(" [%s]", argv
[i
].value
[j
]);
138 for (i
= 0; i
< (int)sz
; i
++)
139 xprintf(" [%s]", params
[i
]);
141 xprintf(" %d:%d\n", n
->line
, n
->pos
);
144 doprint(n
->child
, indent
+ 1);
146 doprint(n
->next
, indent
);