]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.68 2015/09/26 12:55:16 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 roff_man
*mdoc
)
44 print_mdoc(mdoc
->first
->child
, 0);
48 tree_man(void *arg
, const struct roff_man
*man
)
51 print_man(man
->first
->child
, 0);
55 print_mdoc(const struct roff_node
*n
, int indent
)
60 struct mdoc_argv
*argv
;
108 p
= mdoc_macronames
[n
->tok
];
111 p
= mdoc_macronames
[n
->tok
];
114 p
= mdoc_macronames
[n
->tok
];
117 p
= mdoc_macronames
[n
->tok
];
119 argv
= n
->args
->argv
;
120 argc
= n
->args
->argc
;
124 p
= mdoc_macronames
[n
->tok
];
126 argv
= n
->args
->argv
;
127 argc
= n
->args
->argc
;
143 assert(NULL
== p
&& NULL
== t
);
144 print_span(n
->span
, indent
);
146 for (i
= 0; i
< indent
; i
++)
149 printf("%s (%s)", p
, t
);
151 for (i
= 0; i
< (int)argc
; i
++) {
152 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
155 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
156 printf(" [%s]", argv
[i
].value
[j
]);
162 if (MDOC_DELIMO
& n
->flags
)
164 if (MDOC_LINE
& n
->flags
)
166 printf("%d:%d", n
->line
, n
->pos
+ 1);
167 if (MDOC_DELIMC
& n
->flags
)
169 if (MDOC_EOS
& n
->flags
)
175 print_box(n
->eqn
->root
->first
, indent
+ 4);
177 print_mdoc(n
->child
, indent
+
178 (n
->type
== ROFFT_BLOCK
? 2 : 4));
180 print_mdoc(n
->next
, indent
);
184 print_man(const struct roff_node
*n
, int indent
)
233 p
= man_macronames
[n
->tok
];
248 assert(NULL
== p
&& NULL
== t
);
249 print_span(n
->span
, indent
);
251 for (i
= 0; i
< indent
; i
++)
253 printf("%s (%s) ", p
, t
);
254 if (MAN_LINE
& n
->flags
)
256 printf("%d:%d", n
->line
, n
->pos
+ 1);
257 if (MAN_EOS
& n
->flags
)
263 print_box(n
->eqn
->root
->first
, indent
+ 4);
265 print_man(n
->child
, indent
+
266 (n
->type
== ROFFT_BLOCK
? 2 : 4));
268 print_man(n
->next
, indent
);
272 print_box(const struct eqn_box
*ep
, int indent
)
277 static const char *posnames
[] = {
278 NULL
, "sup", "subsup", "sub",
279 "to", "from", "fromto",
280 "over", "sqrt", NULL
};
284 for (i
= 0; i
< indent
; i
++)
312 printf(" pos=%s", posnames
[ep
->pos
]);
314 printf(" left=\"%s\"", ep
->left
);
316 printf(" right=\"%s\"", ep
->right
);
318 printf(" top=\"%s\"", ep
->top
);
320 printf(" bottom=\"%s\"", ep
->bottom
);
322 printf(" text=\"%s\"", ep
->text
);
324 printf(" font=%d", ep
->font
);
325 if (ep
->size
!= EQN_DEFSIZE
)
326 printf(" size=%d", ep
->size
);
327 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
328 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
330 printf(" args=%zu", ep
->args
);
333 print_box(ep
->first
, indent
+ 4);
334 print_box(ep
->next
, indent
);
338 print_span(const struct tbl_span
*sp
, int indent
)
340 const struct tbl_dat
*dp
;
343 for (i
= 0; i
< indent
; i
++)
350 case TBL_SPAN_DHORIZ
:
357 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
361 case TBL_DATA_NHORIZ
:
364 case TBL_DATA_DHORIZ
:
366 case TBL_DATA_NDHORIZ
:
372 printf("[\"%s\"", dp
->string
? dp
->string
: "");
374 printf("(%d)", dp
->spans
);
375 if (NULL
== dp
->layout
)
381 printf("(tbl) %d:1\n", sp
->line
);