]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.79 2018/08/14 01:27:48 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013,2014,2015,2017,2018 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
;
136 p
= roff_name
[n
->tok
];
139 p
= roff_name
[n
->tok
];
142 p
= roff_name
[n
->tok
];
145 p
= roff_name
[n
->tok
];
147 argv
= n
->args
->argv
;
148 argc
= n
->args
->argc
;
152 p
= roff_name
[n
->tok
];
154 argv
= n
->args
->argv
;
155 argc
= n
->args
->argc
;
171 assert(NULL
== p
&& NULL
== t
);
172 print_span(n
->span
, indent
);
174 for (i
= 0; i
< indent
; i
++)
177 printf("%s (%s)", p
, t
);
179 for (i
= 0; i
< (int)argc
; i
++) {
180 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
183 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
184 printf(" [%s]", argv
[i
].value
[j
]);
190 if (NODE_DELIMO
& n
->flags
)
192 if (NODE_LINE
& n
->flags
)
194 printf("%d:%d", n
->line
, n
->pos
+ 1);
195 if (NODE_DELIMC
& n
->flags
)
197 if (NODE_EOS
& n
->flags
)
199 if (NODE_BROKEN
& n
->flags
)
201 if (NODE_NOSRC
& n
->flags
)
203 if (NODE_NOPRT
& n
->flags
)
209 print_box(n
->eqn
->first
, indent
+ 4);
211 print_mdoc(n
->child
, indent
+
212 (n
->type
== ROFFT_BLOCK
? 2 : 4));
214 print_mdoc(n
->next
, indent
);
218 print_man(const struct roff_node
*n
, int indent
)
268 p
= roff_name
[n
->tok
];
283 assert(NULL
== p
&& NULL
== t
);
284 print_span(n
->span
, indent
);
286 for (i
= 0; i
< indent
; i
++)
288 printf("%s (%s) ", p
, t
);
289 if (NODE_LINE
& n
->flags
)
291 printf("%d:%d", n
->line
, n
->pos
+ 1);
292 if (NODE_DELIMC
& n
->flags
)
294 if (NODE_EOS
& n
->flags
)
300 print_box(n
->eqn
->first
, indent
+ 4);
302 print_man(n
->child
, indent
+
303 (n
->type
== ROFFT_BLOCK
? 2 : 4));
305 print_man(n
->next
, indent
);
309 print_box(const struct eqn_box
*ep
, int indent
)
314 static const char *posnames
[] = {
315 NULL
, "sup", "subsup", "sub",
316 "to", "from", "fromto",
317 "over", "sqrt", NULL
};
321 for (i
= 0; i
< indent
; i
++)
345 printf(" pos=%s", posnames
[ep
->pos
]);
347 printf(" left=\"%s\"", ep
->left
);
349 printf(" right=\"%s\"", ep
->right
);
351 printf(" top=\"%s\"", ep
->top
);
353 printf(" bottom=\"%s\"", ep
->bottom
);
355 printf(" text=\"%s\"", ep
->text
);
357 printf(" font=%d", ep
->font
);
358 if (ep
->size
!= EQN_DEFSIZE
)
359 printf(" size=%d", ep
->size
);
360 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
361 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
363 printf(" args=%zu", ep
->args
);
366 print_box(ep
->first
, indent
+ 4);
367 print_box(ep
->next
, indent
);
371 print_span(const struct tbl_span
*sp
, int indent
)
373 const struct tbl_dat
*dp
;
376 for (i
= 0; i
< indent
; i
++)
383 case TBL_SPAN_DHORIZ
:
390 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
393 case TBL_DATA_NHORIZ
:
396 case TBL_DATA_DHORIZ
:
397 case TBL_DATA_NDHORIZ
:
403 printf("[\"%s\"", dp
->string
? dp
->string
: "");
405 printf("(%d)", dp
->spans
);
406 if (NULL
== dp
->layout
)
412 printf("(tbl) %d:1\n", sp
->line
);