]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.45 2011/07/22 09:57:04 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
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.
32 static void print_box(const struct eqn_box
*, int);
33 static void print_man(const struct man_node
*, int);
34 static void print_mdoc(const struct mdoc_node
*, int);
35 static void print_span(const struct tbl_span
*, int);
40 tree_mdoc(void *arg
, const struct mdoc
*mdoc
)
43 print_mdoc(mdoc_node(mdoc
), 0);
49 tree_man(void *arg
, const struct man
*man
)
52 print_man(man_node(man
), 0);
57 print_mdoc(const struct mdoc_node
*n
, int indent
)
63 struct mdoc_argv
*argv
;
109 p
= mdoc_macronames
[n
->tok
];
112 p
= mdoc_macronames
[n
->tok
];
115 p
= mdoc_macronames
[n
->tok
];
118 p
= mdoc_macronames
[n
->tok
];
120 argv
= n
->args
->argv
;
121 argc
= n
->args
->argc
;
125 p
= mdoc_macronames
[n
->tok
];
127 argv
= n
->args
->argv
;
128 argc
= n
->args
->argc
;
144 assert(NULL
== p
&& NULL
== t
);
145 print_span(n
->span
, indent
);
147 assert(NULL
== p
&& NULL
== t
);
148 print_box(n
->eqn
->root
, indent
);
150 for (i
= 0; i
< indent
; i
++)
153 printf("%s (%s)", p
, t
);
155 for (i
= 0; i
< (int)argc
; i
++) {
156 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
159 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
160 printf(" [%s]", argv
[i
].value
[j
]);
165 for (i
= 0; i
< (int)sz
; i
++)
166 printf(" [%s]", params
[i
]);
168 printf(" %d:%d\n", n
->line
, n
->pos
);
172 print_mdoc(n
->child
, indent
+ 1);
174 print_mdoc(n
->next
, indent
);
179 print_man(const struct man_node
*n
, int indent
)
230 p
= man_macronames
[n
->tok
];
245 assert(NULL
== p
&& NULL
== t
);
246 print_span(n
->span
, indent
);
248 assert(NULL
== p
&& NULL
== t
);
249 print_box(n
->eqn
->root
, indent
);
251 for (i
= 0; i
< indent
; i
++)
253 printf("%s (%s) %d:%d\n", p
, t
, n
->line
, n
->pos
);
257 print_man(n
->child
, indent
+ 1);
259 print_man(n
->next
, indent
);
263 print_box(const struct eqn_box
*ep
, int indent
)
269 for (i
= 0; i
< indent
; i
++)
274 printf("eqn-root(%d, %d, %d, %d)\n",
275 EQN_DEFSIZE
== ep
->size
? 0 : ep
->size
,
276 ep
->pos
, ep
->font
, ep
->mark
);
277 print_box(ep
->first
, indent
+ 1);
280 printf("eqn-list(%d, %d, %d, %d, %d, %d, \"%s\", \"%s\")\n",
281 EQN_DEFSIZE
== ep
->size
? 0 : ep
->size
,
282 ep
->pos
, ep
->font
, ep
->mark
,
284 ep
->left
? ep
->left
: "",
285 ep
->right
? ep
->right
: "");
286 print_box(ep
->first
, indent
+ 1);
289 printf("eqn-subxpr(%d, %d, %d, %d, %d, %d, \"%s\", \"%s\")\n",
290 EQN_DEFSIZE
== ep
->size
? 0 : ep
->size
,
291 ep
->pos
, ep
->font
, ep
->mark
,
293 ep
->left
? ep
->left
: "",
294 ep
->right
? ep
->right
: "");
295 print_box(ep
->first
, indent
+ 1);
298 printf("eqn-text(%d, %d, %d, %d): [%s]\n",
299 EQN_DEFSIZE
== ep
->size
? 0 : ep
->size
,
300 ep
->pos
, ep
->font
, ep
->mark
, ep
->text
);
306 print_box(ep
->next
, indent
);
310 print_span(const struct tbl_span
*sp
, int indent
)
312 const struct tbl_dat
*dp
;
315 for (i
= 0; i
< indent
; i
++)
319 case (TBL_SPAN_HORIZ
):
322 case (TBL_SPAN_DHORIZ
):
329 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
331 case (TBL_DATA_HORIZ
):
333 case (TBL_DATA_NHORIZ
):
336 case (TBL_DATA_DHORIZ
):
338 case (TBL_DATA_NDHORIZ
):
344 printf("[\"%s\"", dp
->string
? dp
->string
: "");
346 printf("(%d)", dp
->spans
);
347 if (NULL
== dp
->layout
)
353 printf("(tbl) %d:1\n", sp
->line
);