]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.84 2019/01/01 05:56:34 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013-2015, 2017-2019 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>
36 static void print_box(const struct eqn_box
*, int);
37 static void print_man(const struct roff_node
*, int);
38 static void print_meta(const struct roff_meta
*);
39 static void print_mdoc(const struct roff_node
*, int);
40 static void print_span(const struct tbl_span
*, int);
44 tree_mdoc(void *arg
, const struct roff_meta
*mdoc
)
48 print_mdoc(mdoc
->first
->child
, 0);
52 tree_man(void *arg
, const struct roff_meta
*man
)
55 if (man
->hasbody
== 0)
58 print_man(man
->first
->child
, 0);
62 print_meta(const struct roff_meta
*meta
)
64 if (meta
->title
!= NULL
)
65 printf("title = \"%s\"\n", meta
->title
);
66 if (meta
->name
!= NULL
)
67 printf("name = \"%s\"\n", meta
->name
);
68 if (meta
->msec
!= NULL
)
69 printf("sec = \"%s\"\n", meta
->msec
);
70 if (meta
->vol
!= NULL
)
71 printf("vol = \"%s\"\n", meta
->vol
);
72 if (meta
->arch
!= NULL
)
73 printf("arch = \"%s\"\n", meta
->arch
);
75 printf("os = \"%s\"\n", meta
->os
);
76 if (meta
->date
!= NULL
)
77 printf("date = \"%s\"\n", meta
->date
);
81 print_mdoc(const struct roff_node
*n
, int indent
)
86 struct mdoc_argv
*argv
;
138 p
= roff_name
[n
->tok
];
141 p
= roff_name
[n
->tok
];
144 p
= roff_name
[n
->tok
];
147 p
= roff_name
[n
->tok
];
149 argv
= n
->args
->argv
;
150 argc
= n
->args
->argc
;
154 p
= roff_name
[n
->tok
];
156 argv
= n
->args
->argv
;
157 argc
= n
->args
->argc
;
173 assert(NULL
== p
&& NULL
== t
);
174 print_span(n
->span
, indent
);
176 for (i
= 0; i
< indent
; i
++)
179 printf("%s (%s)", p
, t
);
181 for (i
= 0; i
< (int)argc
; i
++) {
182 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
185 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
186 printf(" [%s]", argv
[i
].value
[j
]);
192 if (n
->flags
& NODE_DELIMO
)
194 if (n
->flags
& NODE_LINE
)
196 printf("%d:%d", n
->line
, n
->pos
+ 1);
197 if (n
->flags
& NODE_DELIMC
)
199 if (n
->flags
& NODE_EOS
)
201 if (n
->flags
& NODE_BROKEN
)
203 if (n
->flags
& NODE_NOFILL
)
205 if (n
->flags
& NODE_NOSRC
)
207 if (n
->flags
& NODE_NOPRT
)
213 print_box(n
->eqn
->first
, indent
+ 4);
215 print_mdoc(n
->child
, indent
+
216 (n
->type
== ROFFT_BLOCK
? 2 : 4));
218 print_mdoc(n
->next
, indent
);
222 print_man(const struct roff_node
*n
, int indent
)
272 p
= roff_name
[n
->tok
];
287 assert(NULL
== p
&& NULL
== t
);
288 print_span(n
->span
, indent
);
290 for (i
= 0; i
< indent
; i
++)
292 printf("%s (%s) ", p
, t
);
293 if (n
->flags
& NODE_LINE
)
295 printf("%d:%d", n
->line
, n
->pos
+ 1);
296 if (n
->flags
& NODE_DELIMC
)
298 if (n
->flags
& NODE_EOS
)
300 if (n
->flags
& NODE_NOFILL
)
306 print_box(n
->eqn
->first
, indent
+ 4);
308 print_man(n
->child
, indent
+
309 (n
->type
== ROFFT_BLOCK
? 2 : 4));
311 print_man(n
->next
, indent
);
315 print_box(const struct eqn_box
*ep
, int indent
)
320 static const char *posnames
[] = {
321 NULL
, "sup", "subsup", "sub",
322 "to", "from", "fromto",
323 "over", "sqrt", NULL
};
327 for (i
= 0; i
< indent
; i
++)
351 printf(" pos=%s", posnames
[ep
->pos
]);
353 printf(" left=\"%s\"", ep
->left
);
355 printf(" right=\"%s\"", ep
->right
);
357 printf(" top=\"%s\"", ep
->top
);
359 printf(" bottom=\"%s\"", ep
->bottom
);
361 printf(" text=\"%s\"", ep
->text
);
363 printf(" font=%d", ep
->font
);
364 if (ep
->size
!= EQN_DEFSIZE
)
365 printf(" size=%d", ep
->size
);
366 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
367 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
369 printf(" args=%zu", ep
->args
);
372 print_box(ep
->first
, indent
+ 4);
373 print_box(ep
->next
, indent
);
377 print_span(const struct tbl_span
*sp
, int indent
)
379 const struct tbl_dat
*dp
;
382 for (i
= 0; i
< indent
; i
++)
390 case TBL_SPAN_DHORIZ
:
395 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
398 case TBL_DATA_NHORIZ
:
402 case TBL_DATA_DHORIZ
:
403 case TBL_DATA_NDHORIZ
:
410 printf("[\"%s\"", dp
->string
? dp
->string
: "");
412 printf(">%d", dp
->hspans
);
414 printf("v%d", dp
->vspans
);
415 if (dp
->layout
== NULL
)
417 else if (dp
->layout
->pos
== TBL_CELL_DOWN
)
424 printf("(tbl) %d:1\n", sp
->line
);