]>
git.cameronkatri.com Git - mandoc.git/blob - tree.c
1 /* $Id: tree.c,v 1.82 2018/12/13 05:23:38 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>
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_man
*mdoc
)
46 print_meta(&mdoc
->meta
);
48 print_mdoc(mdoc
->first
->child
, 0);
52 tree_man(void *arg
, const struct roff_man
*man
)
54 print_meta(&man
->meta
);
55 if (man
->meta
.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 (NODE_DELIMO
& n
->flags
)
194 if (NODE_LINE
& n
->flags
)
196 printf("%d:%d", n
->line
, n
->pos
+ 1);
197 if (NODE_DELIMC
& n
->flags
)
199 if (NODE_EOS
& n
->flags
)
201 if (NODE_BROKEN
& n
->flags
)
203 if (NODE_NOSRC
& n
->flags
)
205 if (NODE_NOPRT
& n
->flags
)
211 print_box(n
->eqn
->first
, indent
+ 4);
213 print_mdoc(n
->child
, indent
+
214 (n
->type
== ROFFT_BLOCK
? 2 : 4));
216 print_mdoc(n
->next
, indent
);
220 print_man(const struct roff_node
*n
, int indent
)
270 p
= roff_name
[n
->tok
];
285 assert(NULL
== p
&& NULL
== t
);
286 print_span(n
->span
, indent
);
288 for (i
= 0; i
< indent
; i
++)
290 printf("%s (%s) ", p
, t
);
291 if (NODE_LINE
& n
->flags
)
293 printf("%d:%d", n
->line
, n
->pos
+ 1);
294 if (NODE_DELIMC
& n
->flags
)
296 if (NODE_EOS
& n
->flags
)
302 print_box(n
->eqn
->first
, indent
+ 4);
304 print_man(n
->child
, indent
+
305 (n
->type
== ROFFT_BLOCK
? 2 : 4));
307 print_man(n
->next
, indent
);
311 print_box(const struct eqn_box
*ep
, int indent
)
316 static const char *posnames
[] = {
317 NULL
, "sup", "subsup", "sub",
318 "to", "from", "fromto",
319 "over", "sqrt", NULL
};
323 for (i
= 0; i
< indent
; i
++)
347 printf(" pos=%s", posnames
[ep
->pos
]);
349 printf(" left=\"%s\"", ep
->left
);
351 printf(" right=\"%s\"", ep
->right
);
353 printf(" top=\"%s\"", ep
->top
);
355 printf(" bottom=\"%s\"", ep
->bottom
);
357 printf(" text=\"%s\"", ep
->text
);
359 printf(" font=%d", ep
->font
);
360 if (ep
->size
!= EQN_DEFSIZE
)
361 printf(" size=%d", ep
->size
);
362 if (ep
->expectargs
!= UINT_MAX
&& ep
->expectargs
!= ep
->args
)
363 printf(" badargs=%zu(%zu)", ep
->args
, ep
->expectargs
);
365 printf(" args=%zu", ep
->args
);
368 print_box(ep
->first
, indent
+ 4);
369 print_box(ep
->next
, indent
);
373 print_span(const struct tbl_span
*sp
, int indent
)
375 const struct tbl_dat
*dp
;
378 for (i
= 0; i
< indent
; i
++)
386 case TBL_SPAN_DHORIZ
:
391 for (dp
= sp
->first
; dp
; dp
= dp
->next
) {
394 case TBL_DATA_NHORIZ
:
398 case TBL_DATA_DHORIZ
:
399 case TBL_DATA_NDHORIZ
:
406 printf("[\"%s\"", dp
->string
? dp
->string
: "");
408 printf(">%d", dp
->hspans
);
410 printf("v%d", dp
->vspans
);
411 if (dp
->layout
== NULL
)
413 else if (dp
->layout
->pos
== TBL_CELL_DOWN
)
420 printf("(tbl) %d:1\n", sp
->line
);