]> git.cameronkatri.com Git - mandoc.git/blob - tree.c
Initial separation of tree/mdocml.1.
[mandoc.git] / tree.c
1 /* $Id: tree.c,v 1.1 2009/01/16 15:58:50 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
4 *
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
8 * copies.
9 *
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.
18 */
19 #include <stdlib.h>
20
21 #include "mdoc.h"
22
23
24 #if 0
25 /* TODO: remove this to a print-tree output filter. */
26 static void
27 print_node(const struct mdoc_node *n, int indent)
28 {
29 const char *p, *t;
30 int i, j;
31 size_t argc, sz;
32 char **params;
33 struct mdoc_arg *argv;
34
35 argv = NULL;
36 argc = sz = 0;
37 params = NULL;
38
39 t = mdoc_type2a(n->type);
40
41 switch (n->type) {
42 case (MDOC_TEXT):
43 p = n->data.text.string;
44 break;
45 case (MDOC_BODY):
46 p = mdoc_macronames[n->tok];
47 break;
48 case (MDOC_HEAD):
49 p = mdoc_macronames[n->tok];
50 break;
51 case (MDOC_TAIL):
52 p = mdoc_macronames[n->tok];
53 break;
54 case (MDOC_ELEM):
55 p = mdoc_macronames[n->tok];
56 argv = n->data.elem.argv;
57 argc = n->data.elem.argc;
58 break;
59 case (MDOC_BLOCK):
60 p = mdoc_macronames[n->tok];
61 argv = n->data.block.argv;
62 argc = n->data.block.argc;
63 break;
64 case (MDOC_ROOT):
65 p = "root";
66 break;
67 default:
68 abort();
69 /* NOTREACHED */
70 }
71
72 for (i = 0; i < indent; i++)
73 xprintf(" ");
74 xprintf("%s (%s)", p, t);
75
76 for (i = 0; i < (int)argc; i++) {
77 xprintf(" -%s", mdoc_argnames[argv[i].arg]);
78 if (argv[i].sz > 0)
79 xprintf(" [");
80 for (j = 0; j < (int)argv[i].sz; j++)
81 xprintf(" [%s]", argv[i].value[j]);
82 if (argv[i].sz > 0)
83 xprintf(" ]");
84 }
85
86 for (i = 0; i < (int)sz; i++)
87 xprintf(" [%s]", params[i]);
88
89 xprintf(" %d:%d\n", n->line, n->pos);
90
91 if (n->child)
92 print_node(n->child, indent + 1);
93 if (n->next)
94 print_node(n->next, indent);
95 }
96 #endif
97
98 int
99 treeprint(const struct mdoc_node *node, const char *out)
100 {
101 }