]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.72 2017/01/12 17:29:33 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013, 2014, 2015, 2017 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_meta(const struct roff_meta
*);
37 static void print_mdoc(const struct roff_node
*, int);
38 static void print_span(const struct tbl_span
*, int);
42 tree_mdoc(void *arg
, const struct roff_man
*mdoc
)
44 print_meta(&mdoc
->meta
);
46 print_mdoc(mdoc
->first
->child
, 0);
50 tree_man(void *arg
, const struct roff_man
*man
)
52 print_meta(&man
->meta
);
53 if (man
->meta
.hasbody
== 0)
56 print_man(man
->first
->child
, 0);
60 print_meta(const struct roff_meta
*meta
)
62 if (meta
->title
!= NULL
)
63 printf("title = \"%s\"\n", meta
->title
);
64 if (meta
->name
!= NULL
)
65 printf("name = \"%s\"\n", meta
->name
);
66 if (meta
->msec
!= NULL
)
67 printf("sec = \"%s\"\n", meta
->msec
);
68 if (meta
->vol
!= NULL
)
69 printf("vol = \"%s\"\n", meta
->vol
);
70 if (meta
->arch
!= NULL
)
71 printf("arch = \"%s\"\n", meta
->arch
);
73 printf("os = \"%s\"\n", meta
->os
);
74 if (meta
->date
!= NULL
)
75 printf("date = \"%s\"\n", meta
->date
);
79 print_mdoc(const struct roff_node
*n
, int indent
)
84 struct mdoc_argv
*argv
;
132 p
= mdoc_macronames
[n
->tok
];
135 p
= mdoc_macronames
[n
->tok
];
138 p
= mdoc_macronames
[n
->tok
];
141 p
= mdoc_macronames
[n
->tok
];
143 argv
= n
->args
->argv
;
144 argc
= n
->args
->argc
;
148 p
= mdoc_macronames
[n
->tok
];
150 argv
= n
->args
->argv
;
151 argc
= n
->args
->argc
;
167 assert(NULL
== p
&& NULL
== t
);
168 print_span(n
->span
, indent
);
170 for (i
= 0; i
< indent
; i
++)
173 printf("%s (%s)", p
, t
);
175 for (i
= 0; i
< (int)argc
; i
++) {
176 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
179 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
180 printf(" [%s]", argv
[i
].value
[j
]);
186 if (NODE_DELIMO
& n
->flags
)
188 if (NODE_LINE
& n
->flags
)
190 printf("%d:%d", n
->line
, n
->pos
+ 1);
191 if (NODE_DELIMC
& n
->flags
)
193 if (NODE_EOS
& n
->flags
)
195 if (NODE_NOSRC
& n
->flags
)
197 if (NODE_NOPRT
& n
->flags
)
203 print_box(n
->eqn
->root
->first
, indent
+ 4);
205 print_mdoc(n
->child
, indent
+
206 (n
->type
== ROFFT_BLOCK
? 2 : 4));
208 print_mdoc(n
->next
, indent
);
212 print_man(const struct roff_node
*n
, int indent
)
258 p
= man_macronames
[n
->tok
];
273 assert(NULL
== p
&& NULL
== t
);
274 print_span(n
->span
, indent
);
276 for (i
= 0; i
< indent
; i
++)
278 printf("%s (%s) ", p
, t
);
279 if (NODE_LINE
& n
->flags
)
281 printf("%d:%d", n
->line
, n
->pos
+ 1);
282 if (NODE_EOS
& n
->flags
)
288 print_box(n
->eqn
->root
->first
, indent
+ 4);
290 print_man(n
->child
, indent
+
291 (n
->type
== ROFFT_BLOCK
? 2 : 4));
293 print_man(n
->next
, indent
);
297 print_box(const struct eqn_box
*ep
, int indent
)
302 static const char *posnames
[] = {
303 NULL
, "sup", "subsup", "sub",
304 "to", "from", "fromto",
305 "over", "sqrt", NULL
};
309 for (i
= 0; i
< indent
; i
++)
337 printf(" pos=%s", posnames
[ep
->pos
]);
339 printf(" left=\"%s\"", ep
->left
);
341 printf(" right=\"%s\"", ep
->right
);
343 printf(" top=\"%s\"", ep
->top
);
345 printf(" bottom=\"%s\"", ep
->bottom
);
347 printf(" text=\"%s\"", ep
->text
);
349 printf(" font=%d", ep
->font
);
350 if (ep
->size
!= EQN_DEFSIZE
)
351 printf(" size=%d", ep
->size
);
352 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
353 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
355 printf(" args=%zu", ep
->args
);
358 print_box(ep
->first
, indent
+ 4);
359 print_box(ep
->next
, indent
);
363 print_span(const struct tbl_span
*sp
, int indent
)
365 const struct tbl_dat
*dp
;
368 for (i
= 0; i
< indent
; i
++)
375 case TBL_SPAN_DHORIZ
:
382 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
385 case TBL_DATA_NHORIZ
:
388 case TBL_DATA_DHORIZ
:
389 case TBL_DATA_NDHORIZ
:
395 printf("[\"%s\"", dp
->string
? dp
->string
: "");
397 printf("(%d)", dp
->spans
);
398 if (NULL
== dp
->layout
)
404 printf("(tbl) %d:1\n", sp
->line
);