]>
git.cameronkatri.com Git - mandoc.git/blob - mdoctree.c
1 /* $Id: mdoctree.c,v 1.6 2009/03/08 14:01:46 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_argv
*argv
;
98 p
= mdoc_macronames
[n
->tok
];
101 p
= mdoc_macronames
[n
->tok
];
104 p
= mdoc_macronames
[n
->tok
];
107 p
= mdoc_macronames
[n
->tok
];
109 argv
= n
->args
->argv
;
110 argc
= n
->args
->argc
;
114 p
= mdoc_macronames
[n
->tok
];
116 argv
= n
->args
->argv
;
117 argc
= n
->args
->argc
;
128 for (i
= 0; i
< indent
; i
++)
130 xprintf("%s (%s)", p
, t
);
132 for (i
= 0; i
< (int)argc
; i
++) {
133 xprintf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
136 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
137 xprintf(" [%s]", argv
[i
].value
[j
]);
142 for (i
= 0; i
< (int)sz
; i
++)
143 xprintf(" [%s]", params
[i
]);
145 xprintf(" %d:%d\n", n
->line
, n
->pos
);
148 doprint(n
->child
, indent
+ 1);
150 doprint(n
->next
, indent
);