1 /* $Id: tree.c,v 1.69 2015/10/12 00:08: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
)
230 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
->line
, n
->pos
+ 1);
254 if (MAN_EOS
& n
->flags
)
260 print_box(n
->eqn
->root
->first
, indent
+ 4);
262 print_man(n
->child
, indent
+
263 (n
->type
== ROFFT_BLOCK
? 2 : 4));
265 print_man(n
->next
, indent
);
269 print_box(const struct eqn_box
*ep
, int indent
)
274 static const char *posnames
[] = {
275 NULL
, "sup", "subsup", "sub",
276 "to", "from", "fromto",
277 "over", "sqrt", NULL
};
281 for (i
= 0; i
< indent
; i
++)
309 printf(" pos=%s", posnames
[ep
->pos
]);
311 printf(" left=\"%s\"", ep
->left
);
313 printf(" right=\"%s\"", ep
->right
);
315 printf(" top=\"%s\"", ep
->top
);
317 printf(" bottom=\"%s\"", ep
->bottom
);
319 printf(" text=\"%s\"", ep
->text
);
321 printf(" font=%d", ep
->font
);
322 if (ep
->size
!= EQN_DEFSIZE
)
323 printf(" size=%d", ep
->size
);
324 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
325 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
327 printf(" args=%zu", ep
->args
);
330 print_box(ep
->first
, indent
+ 4);
331 print_box(ep
->next
, indent
);
335 print_span(const struct tbl_span
*sp
, int indent
)
337 const struct tbl_dat
*dp
;
340 for (i
= 0; i
< indent
; i
++)
347 case TBL_SPAN_DHORIZ
:
354 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
357 case TBL_DATA_NHORIZ
:
360 case TBL_DATA_DHORIZ
:
361 case TBL_DATA_NDHORIZ
:
367 printf("[\"%s\"", dp
->string
? dp
->string
: "");
369 printf("(%d)", dp
->spans
);
370 if (NULL
== dp
->layout
)
376 printf("(tbl) %d:1\n", sp
->line
);