]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.85 2020/01/11 16:03:42 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013-2015, 2017-2020 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_cellt(enum tbl_cellt
);
38 static void print_man(const struct roff_node
*, int);
39 static void print_meta(const struct roff_meta
*);
40 static void print_mdoc(const struct roff_node
*, int);
41 static void print_span(const struct tbl_span
*, int);
45 tree_mdoc(void *arg
, const struct roff_meta
*mdoc
)
49 print_mdoc(mdoc
->first
->child
, 0);
53 tree_man(void *arg
, const struct roff_meta
*man
)
56 if (man
->hasbody
== 0)
59 print_man(man
->first
->child
, 0);
63 print_meta(const struct roff_meta
*meta
)
65 if (meta
->title
!= NULL
)
66 printf("title = \"%s\"\n", meta
->title
);
67 if (meta
->name
!= NULL
)
68 printf("name = \"%s\"\n", meta
->name
);
69 if (meta
->msec
!= NULL
)
70 printf("sec = \"%s\"\n", meta
->msec
);
71 if (meta
->vol
!= NULL
)
72 printf("vol = \"%s\"\n", meta
->vol
);
73 if (meta
->arch
!= NULL
)
74 printf("arch = \"%s\"\n", meta
->arch
);
76 printf("os = \"%s\"\n", meta
->os
);
77 if (meta
->date
!= NULL
)
78 printf("date = \"%s\"\n", meta
->date
);
82 print_mdoc(const struct roff_node
*n
, int indent
)
87 struct mdoc_argv
*argv
;
139 p
= roff_name
[n
->tok
];
142 p
= roff_name
[n
->tok
];
145 p
= roff_name
[n
->tok
];
148 p
= roff_name
[n
->tok
];
150 argv
= n
->args
->argv
;
151 argc
= n
->args
->argc
;
155 p
= roff_name
[n
->tok
];
157 argv
= n
->args
->argv
;
158 argc
= n
->args
->argc
;
174 assert(NULL
== p
&& NULL
== t
);
175 print_span(n
->span
, indent
);
177 for (i
= 0; i
< indent
; i
++)
180 printf("%s (%s)", p
, t
);
182 for (i
= 0; i
< (int)argc
; i
++) {
183 printf(" -%s", mdoc_argnames
[argv
[i
].arg
]);
186 for (j
= 0; j
< (int)argv
[i
].sz
; j
++)
187 printf(" [%s]", argv
[i
].value
[j
]);
193 if (n
->flags
& NODE_DELIMO
)
195 if (n
->flags
& NODE_LINE
)
197 printf("%d:%d", n
->line
, n
->pos
+ 1);
198 if (n
->flags
& NODE_DELIMC
)
200 if (n
->flags
& NODE_EOS
)
202 if (n
->flags
& NODE_BROKEN
)
204 if (n
->flags
& NODE_NOFILL
)
206 if (n
->flags
& NODE_NOSRC
)
208 if (n
->flags
& NODE_NOPRT
)
214 print_box(n
->eqn
->first
, indent
+ 4);
216 print_mdoc(n
->child
, indent
+
217 (n
->type
== ROFFT_BLOCK
? 2 : 4));
219 print_mdoc(n
->next
, indent
);
223 print_man(const struct roff_node
*n
, int indent
)
273 p
= roff_name
[n
->tok
];
288 assert(NULL
== p
&& NULL
== t
);
289 print_span(n
->span
, indent
);
291 for (i
= 0; i
< indent
; i
++)
293 printf("%s (%s) ", p
, t
);
294 if (n
->flags
& NODE_LINE
)
296 printf("%d:%d", n
->line
, n
->pos
+ 1);
297 if (n
->flags
& NODE_DELIMC
)
299 if (n
->flags
& NODE_EOS
)
301 if (n
->flags
& NODE_NOFILL
)
307 print_box(n
->eqn
->first
, indent
+ 4);
309 print_man(n
->child
, indent
+
310 (n
->type
== ROFFT_BLOCK
? 2 : 4));
312 print_man(n
->next
, indent
);
316 print_box(const struct eqn_box
*ep
, int indent
)
321 static const char *posnames
[] = {
322 NULL
, "sup", "subsup", "sub",
323 "to", "from", "fromto",
324 "over", "sqrt", NULL
};
328 for (i
= 0; i
< indent
; i
++)
352 printf(" pos=%s", posnames
[ep
->pos
]);
354 printf(" left=\"%s\"", ep
->left
);
356 printf(" right=\"%s\"", ep
->right
);
358 printf(" top=\"%s\"", ep
->top
);
360 printf(" bottom=\"%s\"", ep
->bottom
);
362 printf(" text=\"%s\"", ep
->text
);
364 printf(" font=%d", ep
->font
);
365 if (ep
->size
!= EQN_DEFSIZE
)
366 printf(" size=%d", ep
->size
);
367 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
368 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
370 printf(" args=%zu", ep
->args
);
373 print_box(ep
->first
, indent
+ 4);
374 print_box(ep
->next
, indent
);
378 print_cellt(enum tbl_cellt pos
)
387 case TBL_CELL_CENTRE
:
393 case TBL_CELL_NUMBER
:
405 case TBL_CELL_DHORIZ
:
415 print_span(const struct tbl_span
*sp
, int indent
)
417 const struct tbl_dat
*dp
;
418 const struct tbl_cell
*cp
;
421 if (sp
->prev
== NULL
) {
422 for (i
= 0; i
< indent
; i
++)
424 printf("%d", sp
->opts
->cols
);
425 if (sp
->opts
->opts
& TBL_OPT_CENTRE
)
426 fputs(" center", stdout
);
427 if (sp
->opts
->opts
& TBL_OPT_EXPAND
)
428 fputs(" expand", stdout
);
429 if (sp
->opts
->opts
& TBL_OPT_ALLBOX
)
430 fputs(" allbox", stdout
);
431 if (sp
->opts
->opts
& TBL_OPT_BOX
)
432 fputs(" box", stdout
);
433 if (sp
->opts
->opts
& TBL_OPT_DBOX
)
434 fputs(" doublebox", stdout
);
435 if (sp
->opts
->opts
& TBL_OPT_NOKEEP
)
436 fputs(" nokeep", stdout
);
437 if (sp
->opts
->opts
& TBL_OPT_NOSPACE
)
438 fputs(" nospaces", stdout
);
439 if (sp
->opts
->opts
& TBL_OPT_NOWARN
)
440 fputs(" nowarn", stdout
);
441 printf(" (tbl options) %d:1\n", sp
->line
);
444 for (i
= 0; i
< indent
; i
++)
452 case TBL_SPAN_DHORIZ
:
457 for (cp
= sp
->layout
->first
; cp
!= NULL
; cp
= cp
->next
)
458 print_cellt(cp
->pos
);
460 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
461 if ((cp
= dp
->layout
) == NULL
)
464 printf("%d", cp
->col
);
465 print_cellt(dp
->layout
->pos
);
466 if (cp
->flags
& TBL_CELL_BOLD
)
468 if (cp
->flags
& TBL_CELL_ITALIC
)
470 if (cp
->flags
& TBL_CELL_TALIGN
)
472 if (cp
->flags
& TBL_CELL_UP
)
474 if (cp
->flags
& TBL_CELL_BALIGN
)
476 if (cp
->flags
& TBL_CELL_WIGN
)
478 if (cp
->flags
& TBL_CELL_EQUAL
)
480 if (cp
->flags
& TBL_CELL_WMAX
)
485 case TBL_DATA_NHORIZ
:
488 case TBL_DATA_DHORIZ
:
489 case TBL_DATA_NDHORIZ
:
493 putchar(dp
->block
? '{' : '[');
494 if (dp
->string
!= NULL
)
495 fputs(dp
->string
, stdout
);
496 putchar(dp
->block
? '}' : ']');
500 printf(">%d", dp
->hspans
);
502 printf("v%d", dp
->vspans
);
507 printf("(tbl) %d:1\n", sp
->line
);