]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.64 2015/04/02 22:48:18 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
34 static void print_box(const struct eqn_box
*, int);
35 static void print_man(const struct roff_node
*, int);
36 static void print_mdoc(const struct roff_node
*, int);
37 static void print_span(const struct tbl_span
*, int);
41 tree_mdoc(void *arg
, const struct mdoc
*mdoc
)
44 print_mdoc(mdoc_node(mdoc
)->child
, 0);
48 tree_man(void *arg
, const struct man
*man
)
51 print_man(man_node(man
)->child
, 0);
55 print_mdoc(const struct roff_node
*n
, int indent
)
60 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
;
145 assert(NULL
== p
&& NULL
== t
);
146 print_span(n
->span
, indent
);
148 for (i
= 0; i
< indent
; i
++)
151 printf("%s (%s)", p
, t
);
153 for (i
= 0; i
< (int)argc
; i
++) {
154 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
157 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
158 printf(" [%s]", argv
[i
].value
[j
]);
164 if (MDOC_LINE
& n
->flags
)
166 printf("%d:%d\n", n
->line
, n
->pos
+ 1);
170 print_box(n
->eqn
->root
->first
, indent
+ 4);
172 print_mdoc(n
->child
, indent
+
173 (n
->type
== ROFFT_BLOCK
? 2 : 4));
175 print_mdoc(n
->next
, indent
);
179 print_man(const struct roff_node
*n
, int indent
)
229 p
= man_macronames
[n
->tok
];
245 assert(NULL
== p
&& NULL
== t
);
246 print_span(n
->span
, indent
);
248 for (i
= 0; i
< indent
; i
++)
250 printf("%s (%s) ", p
, t
);
251 if (MAN_LINE
& n
->flags
)
253 printf("%d:%d\n", n
->line
, n
->pos
+ 1);
257 print_box(n
->eqn
->root
->first
, indent
+ 4);
259 print_man(n
->child
, indent
+
260 (n
->type
== ROFFT_BLOCK
? 2 : 4));
262 print_man(n
->next
, indent
);
266 print_box(const struct eqn_box
*ep
, int indent
)
271 static const char *posnames
[] = {
272 NULL
, "sup", "subsup", "sub",
273 "to", "from", "fromto",
274 "over", "sqrt", NULL
};
278 for (i
= 0; i
< indent
; i
++)
306 printf(" pos=%s", posnames
[ep
->pos
]);
308 printf(" left=\"%s\"", ep
->left
);
310 printf(" right=\"%s\"", ep
->right
);
312 printf(" top=\"%s\"", ep
->top
);
314 printf(" bottom=\"%s\"", ep
->bottom
);
316 printf(" text=\"%s\"", ep
->text
);
318 printf(" font=%d", ep
->font
);
319 if (ep
->size
!= EQN_DEFSIZE
)
320 printf(" size=%d", ep
->size
);
321 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
322 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
324 printf(" args=%zu", ep
->args
);
327 print_box(ep
->first
, indent
+ 4);
328 print_box(ep
->next
, indent
);
332 print_span(const struct tbl_span
*sp
, int indent
)
334 const struct tbl_dat
*dp
;
337 for (i
= 0; i
< indent
; i
++)
344 case TBL_SPAN_DHORIZ
:
351 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
355 case TBL_DATA_NHORIZ
:
358 case TBL_DATA_DHORIZ
:
360 case TBL_DATA_NDHORIZ
:
366 printf("[\"%s\"", dp
->string
? dp
->string
: "");
368 printf("(%d)", dp
->spans
);
369 if (NULL
== dp
->layout
)
375 printf("(tbl) %d:1\n", sp
->line
);