]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_man.c
1 /* $Id: mdoc_man.c,v 1.41 2012/07/16 10:45:41 schwarze Exp $ */
3 * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 #define DECL_ARGS const struct mdoc_meta *m, \
32 const struct mdoc_node *n
35 int (*cond
)(DECL_ARGS
); /* DON'T run actions */
36 int (*pre
)(DECL_ARGS
); /* pre-node action */
37 void (*post
)(DECL_ARGS
); /* post-node action */
38 const char *prefix
; /* pre-node string constant */
39 const char *suffix
; /* post-node string constant */
42 static int cond_body(DECL_ARGS
);
43 static int cond_head(DECL_ARGS
);
44 static void font_push(char);
45 static void font_pop(void);
46 static void post__t(DECL_ARGS
);
47 static void post_bd(DECL_ARGS
);
48 static void post_bf(DECL_ARGS
);
49 static void post_bk(DECL_ARGS
);
50 static void post_bl(DECL_ARGS
);
51 static void post_dl(DECL_ARGS
);
52 static void post_enc(DECL_ARGS
);
53 static void post_eo(DECL_ARGS
);
54 static void post_fa(DECL_ARGS
);
55 static void post_fd(DECL_ARGS
);
56 static void post_fl(DECL_ARGS
);
57 static void post_fn(DECL_ARGS
);
58 static void post_fo(DECL_ARGS
);
59 static void post_font(DECL_ARGS
);
60 static void post_in(DECL_ARGS
);
61 static void post_it(DECL_ARGS
);
62 static void post_lb(DECL_ARGS
);
63 static void post_nm(DECL_ARGS
);
64 static void post_percent(DECL_ARGS
);
65 static void post_pf(DECL_ARGS
);
66 static void post_sect(DECL_ARGS
);
67 static void post_sp(DECL_ARGS
);
68 static void post_vt(DECL_ARGS
);
69 static int pre__t(DECL_ARGS
);
70 static int pre_an(DECL_ARGS
);
71 static int pre_ap(DECL_ARGS
);
72 static int pre_bd(DECL_ARGS
);
73 static int pre_bf(DECL_ARGS
);
74 static int pre_bk(DECL_ARGS
);
75 static int pre_bl(DECL_ARGS
);
76 static int pre_br(DECL_ARGS
);
77 static int pre_bx(DECL_ARGS
);
78 static int pre_dl(DECL_ARGS
);
79 static int pre_enc(DECL_ARGS
);
80 static int pre_em(DECL_ARGS
);
81 static int pre_fa(DECL_ARGS
);
82 static int pre_fd(DECL_ARGS
);
83 static int pre_fl(DECL_ARGS
);
84 static int pre_fn(DECL_ARGS
);
85 static int pre_fo(DECL_ARGS
);
86 static int pre_ft(DECL_ARGS
);
87 static int pre_in(DECL_ARGS
);
88 static int pre_it(DECL_ARGS
);
89 static int pre_lk(DECL_ARGS
);
90 static int pre_li(DECL_ARGS
);
91 static int pre_nm(DECL_ARGS
);
92 static int pre_no(DECL_ARGS
);
93 static int pre_ns(DECL_ARGS
);
94 static int pre_pp(DECL_ARGS
);
95 static int pre_rs(DECL_ARGS
);
96 static int pre_sm(DECL_ARGS
);
97 static int pre_sp(DECL_ARGS
);
98 static int pre_sect(DECL_ARGS
);
99 static int pre_sy(DECL_ARGS
);
100 static void pre_syn(const struct mdoc_node
*);
101 static int pre_vt(DECL_ARGS
);
102 static int pre_ux(DECL_ARGS
);
103 static int pre_xr(DECL_ARGS
);
104 static void print_word(const char *);
105 static void print_line(const char *, int);
106 static void print_block(const char *, int);
107 static void print_offs(const char *);
108 static void print_width(const char *,
109 const struct mdoc_node
*, size_t);
110 static void print_count(int *);
111 static void print_node(DECL_ARGS
);
113 static const struct manact manacts
[MDOC_MAX
+ 1] = {
114 { NULL
, pre_ap
, NULL
, NULL
, NULL
}, /* Ap */
115 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Dd */
116 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Dt */
117 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Os */
118 { NULL
, pre_sect
, post_sect
, ".SH", NULL
}, /* Sh */
119 { NULL
, pre_sect
, post_sect
, ".SS", NULL
}, /* Ss */
120 { NULL
, pre_pp
, NULL
, NULL
, NULL
}, /* Pp */
121 { cond_body
, pre_dl
, post_dl
, NULL
, NULL
}, /* D1 */
122 { cond_body
, pre_dl
, post_dl
, NULL
, NULL
}, /* Dl */
123 { cond_body
, pre_bd
, post_bd
, NULL
, NULL
}, /* Bd */
124 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Ed */
125 { cond_body
, pre_bl
, post_bl
, NULL
, NULL
}, /* Bl */
126 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* El */
127 { NULL
, pre_it
, post_it
, NULL
, NULL
}, /* It */
128 { NULL
, pre_em
, post_font
, NULL
, NULL
}, /* Ad */
129 { NULL
, pre_an
, NULL
, NULL
, NULL
}, /* An */
130 { NULL
, pre_em
, post_font
, NULL
, NULL
}, /* Ar */
131 { NULL
, pre_sy
, post_font
, NULL
, NULL
}, /* Cd */
132 { NULL
, pre_sy
, post_font
, NULL
, NULL
}, /* Cm */
133 { NULL
, pre_li
, post_font
, NULL
, NULL
}, /* Dv */
134 { NULL
, pre_li
, post_font
, NULL
, NULL
}, /* Er */
135 { NULL
, pre_li
, post_font
, NULL
, NULL
}, /* Ev */
136 { NULL
, pre_enc
, post_enc
, "The \\fB",
137 "\\fP\nutility exits 0 on success, and >0 if an error occurs."
139 { NULL
, pre_fa
, post_fa
, NULL
, NULL
}, /* Fa */
140 { NULL
, pre_fd
, post_fd
, NULL
, NULL
}, /* Fd */
141 { NULL
, pre_fl
, post_fl
, NULL
, NULL
}, /* Fl */
142 { NULL
, pre_fn
, post_fn
, NULL
, NULL
}, /* Fn */
143 { NULL
, pre_ft
, post_font
, NULL
, NULL
}, /* Ft */
144 { NULL
, pre_sy
, post_font
, NULL
, NULL
}, /* Ic */
145 { NULL
, pre_in
, post_in
, NULL
, NULL
}, /* In */
146 { NULL
, pre_li
, post_font
, NULL
, NULL
}, /* Li */
147 { cond_head
, pre_enc
, NULL
, "\\- ", NULL
}, /* Nd */
148 { NULL
, pre_nm
, post_nm
, NULL
, NULL
}, /* Nm */
149 { cond_body
, pre_enc
, post_enc
, "[", "]" }, /* Op */
150 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Ot */
151 { NULL
, pre_em
, post_font
, NULL
, NULL
}, /* Pa */
152 { NULL
, pre_enc
, post_enc
, "The \\fB",
153 "\\fP\nfunction returns the value 0 if successful;\n"
154 "otherwise the value -1 is returned and the global\n"
155 "variable \\fIerrno\\fP is set to indicate the error."
157 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* St */
158 { NULL
, pre_em
, post_font
, NULL
, NULL
}, /* Va */
159 { NULL
, pre_vt
, post_vt
, NULL
, NULL
}, /* Vt */
160 { NULL
, pre_xr
, NULL
, NULL
, NULL
}, /* Xr */
161 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %A */
162 { NULL
, pre_em
, post_percent
, NULL
, NULL
}, /* %B */
163 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %D */
164 { NULL
, pre_em
, post_percent
, NULL
, NULL
}, /* %I */
165 { NULL
, pre_em
, post_percent
, NULL
, NULL
}, /* %J */
166 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %N */
167 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %O */
168 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %P */
169 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %R */
170 { NULL
, pre__t
, post__t
, NULL
, NULL
}, /* %T */
171 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %V */
172 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Ac */
173 { cond_body
, pre_enc
, post_enc
, "<", ">" }, /* Ao */
174 { cond_body
, pre_enc
, post_enc
, "<", ">" }, /* Aq */
175 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* At */
176 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Bc */
177 { NULL
, pre_bf
, post_bf
, NULL
, NULL
}, /* Bf */
178 { cond_body
, pre_enc
, post_enc
, "[", "]" }, /* Bo */
179 { cond_body
, pre_enc
, post_enc
, "[", "]" }, /* Bq */
180 { NULL
, pre_ux
, NULL
, "BSD/OS", NULL
}, /* Bsx */
181 { NULL
, pre_bx
, NULL
, NULL
, NULL
}, /* Bx */
182 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Db */
183 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Dc */
184 { cond_body
, pre_enc
, post_enc
, "``", "''" }, /* Do */
185 { cond_body
, pre_enc
, post_enc
, "``", "''" }, /* Dq */
186 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Ec */
187 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Ef */
188 { NULL
, pre_em
, post_font
, NULL
, NULL
}, /* Em */
189 { NULL
, NULL
, post_eo
, NULL
, NULL
}, /* Eo */
190 { NULL
, pre_ux
, NULL
, "FreeBSD", NULL
}, /* Fx */
191 { NULL
, pre_sy
, post_font
, NULL
, NULL
}, /* Ms */
192 { NULL
, pre_no
, NULL
, NULL
, NULL
}, /* No */
193 { NULL
, pre_ns
, NULL
, NULL
, NULL
}, /* Ns */
194 { NULL
, pre_ux
, NULL
, "NetBSD", NULL
}, /* Nx */
195 { NULL
, pre_ux
, NULL
, "OpenBSD", NULL
}, /* Ox */
196 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Pc */
197 { NULL
, NULL
, post_pf
, NULL
, NULL
}, /* Pf */
198 { cond_body
, pre_enc
, post_enc
, "(", ")" }, /* Po */
199 { cond_body
, pre_enc
, post_enc
, "(", ")" }, /* Pq */
200 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Qc */
201 { cond_body
, pre_enc
, post_enc
, "`", "'" }, /* Ql */
202 { cond_body
, pre_enc
, post_enc
, "\"", "\"" }, /* Qo */
203 { cond_body
, pre_enc
, post_enc
, "\"", "\"" }, /* Qq */
204 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Re */
205 { cond_body
, pre_rs
, NULL
, NULL
, NULL
}, /* Rs */
206 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Sc */
207 { cond_body
, pre_enc
, post_enc
, "`", "'" }, /* So */
208 { cond_body
, pre_enc
, post_enc
, "`", "'" }, /* Sq */
209 { NULL
, pre_sm
, NULL
, NULL
, NULL
}, /* Sm */
210 { NULL
, pre_em
, post_font
, NULL
, NULL
}, /* Sx */
211 { NULL
, pre_sy
, post_font
, NULL
, NULL
}, /* Sy */
212 { NULL
, pre_li
, post_font
, NULL
, NULL
}, /* Tn */
213 { NULL
, pre_ux
, NULL
, "UNIX", NULL
}, /* Ux */
214 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Xc */
215 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Xo */
216 { NULL
, pre_fo
, post_fo
, NULL
, NULL
}, /* Fo */
217 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Fc */
218 { cond_body
, pre_enc
, post_enc
, "[", "]" }, /* Oo */
219 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Oc */
220 { NULL
, pre_bk
, post_bk
, NULL
, NULL
}, /* Bk */
221 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Ek */
222 { NULL
, pre_ux
, NULL
, "is currently in beta test.", NULL
}, /* Bt */
223 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Hf */
224 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Fr */
225 { NULL
, pre_ux
, NULL
, "currently under development.", NULL
}, /* Ud */
226 { NULL
, NULL
, post_lb
, NULL
, NULL
}, /* Lb */
227 { NULL
, pre_pp
, NULL
, NULL
, NULL
}, /* Lp */
228 { NULL
, pre_lk
, NULL
, NULL
, NULL
}, /* Lk */
229 { NULL
, pre_em
, post_font
, NULL
, NULL
}, /* Mt */
230 { cond_body
, pre_enc
, post_enc
, "{", "}" }, /* Brq */
231 { cond_body
, pre_enc
, post_enc
, "{", "}" }, /* Bro */
232 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Brc */
233 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %C */
234 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Es */
235 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* En */
236 { NULL
, pre_ux
, NULL
, "DragonFly", NULL
}, /* Dx */
237 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %Q */
238 { NULL
, pre_br
, NULL
, NULL
, NULL
}, /* br */
239 { NULL
, pre_sp
, post_sp
, NULL
, NULL
}, /* sp */
240 { NULL
, NULL
, post_percent
, NULL
, NULL
}, /* %U */
241 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* Ta */
242 { NULL
, NULL
, NULL
, NULL
, NULL
}, /* ROOT */
246 #define MMAN_spc (1 << 0) /* blank character before next word */
247 #define MMAN_spc_force (1 << 1) /* even before trailing punctuation */
248 #define MMAN_nl (1 << 2) /* break man(7) code line */
249 #define MMAN_br (1 << 3) /* break output line */
250 #define MMAN_sp (1 << 4) /* insert a blank output line */
251 #define MMAN_PP (1 << 5) /* reset indentation etc. */
252 #define MMAN_Sm (1 << 6) /* horizontal spacing mode */
253 #define MMAN_Bk (1 << 7) /* word keep mode */
254 #define MMAN_An_split (1 << 8) /* author mode is "split" */
255 #define MMAN_An_nosplit (1 << 9) /* author mode is "nosplit" */
257 static int TPremain
; /* characters before tag is full */
266 font_push(char newfont
)
269 if (fontqueue
.head
+ fontqueue
.size
<= ++fontqueue
.tail
) {
271 fontqueue
.head
= mandoc_realloc(fontqueue
.head
,
274 *fontqueue
.tail
= newfont
;
278 outflags
&= ~MMAN_spc
;
285 if (fontqueue
.tail
> fontqueue
.head
)
287 outflags
&= ~MMAN_spc
;
290 putchar(*fontqueue
.tail
);
294 print_word(const char *s
)
297 if ((MMAN_PP
| MMAN_sp
| MMAN_br
| MMAN_nl
) & outflags
) {
299 * If we need a newline, print it now and start afresh.
301 if (MMAN_PP
& outflags
) {
302 if ( ! (MMAN_sp
& outflags
))
305 } else if (MMAN_sp
& outflags
)
307 else if (MMAN_br
& outflags
)
309 else if (MMAN_nl
& outflags
)
311 outflags
&= ~(MMAN_PP
|MMAN_sp
|MMAN_br
|MMAN_nl
|MMAN_spc
);
315 } else if (MMAN_spc
& outflags
) {
317 * If we need a space, only print it if
318 * (1) it is forced by `No' or
319 * (2) what follows is not terminating punctuation or
320 * (3) what follows is longer than one character.
322 if (MMAN_spc_force
& outflags
|| '\0' == s
[0] ||
323 NULL
== strchr(".,:;)]?!", s
[0]) || '\0' != s
[1]) {
324 if (MMAN_Bk
& outflags
) {
335 * Reassign needing space if we're not following opening
338 if (MMAN_Sm
& outflags
&& ('\0' == s
[0] ||
339 (('(' != s
[0] && '[' != s
[0]) || '\0' != s
[1])))
340 outflags
|= MMAN_spc
;
342 outflags
&= ~MMAN_spc
;
343 outflags
&= ~MMAN_spc_force
;
354 putchar((unsigned char)*s
);
363 print_line(const char *s
, int newflags
)
366 outflags
&= ~MMAN_br
;
369 outflags
|= newflags
;
373 print_block(const char *s
, int newflags
)
376 outflags
&= ~MMAN_PP
;
377 if (MMAN_sp
& outflags
)
378 outflags
&= ~(MMAN_sp
| MMAN_br
);
380 print_line(".sp -1v", 0);
383 outflags
|= newflags
;
387 print_offs(const char *v
)
393 if (NULL
== v
|| '\0' == *v
|| 0 == strcmp(v
, "left"))
395 else if (0 == strcmp(v
, "indent"))
397 else if (0 == strcmp(v
, "indent-two"))
399 else if (a2roffsu(v
, &su
, SCALE_MAX
)) {
405 snprintf(buf
, sizeof(buf
), "%ldn", sz
);
410 print_width(const char *v
, const struct mdoc_node
*child
, size_t defsz
)
421 else if (a2roffsu(v
, &su
, SCALE_MAX
)) {
422 if (SCALE_EN
== su
.unit
)
431 /* XXX Rough estimation, might have multiple parts. */
432 chsz
= (NULL
!= child
&& MDOC_TEXT
== child
->type
) ?
433 strlen(child
->string
) : 0;
435 if (defsz
&& chsz
> sz
)
436 print_block(".HP", 0);
438 print_block(".TP", 0);
442 snprintf(buf
, sizeof(buf
), "%ldn", sz
+ 2);
450 print_count(int *count
)
454 snprintf(buf
, sizeof(buf
), "%d.", ++*count
);
459 man_man(void *arg
, const struct man
*man
)
463 * Dump the keep buffer.
464 * We're guaranteed by now that this exists (is non-NULL).
465 * Flush stdout afterward, just in case.
467 fputs(mparse_getkeep(man_mparse(man
)), stdout
);
472 man_mdoc(void *arg
, const struct mdoc
*mdoc
)
474 const struct mdoc_meta
*m
;
475 const struct mdoc_node
*n
;
480 printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
481 m
->title
, m
->msec
, m
->date
, m
->os
, m
->vol
);
483 outflags
= MMAN_nl
| MMAN_Sm
;
484 if (0 == fontqueue
.size
) {
486 fontqueue
.head
= fontqueue
.tail
= mandoc_malloc(8);
487 *fontqueue
.tail
= 'R';
494 print_node(DECL_ARGS
)
496 const struct mdoc_node
*prev
, *sub
;
497 const struct manact
*act
;
501 * Break the line if we were parsed subsequent the current node.
502 * This makes the page structure be more consistent.
504 prev
= n
->prev
? n
->prev
: n
->parent
;
505 if (MMAN_spc
& outflags
&& prev
&& prev
->line
< n
->line
)
512 if (MDOC_TEXT
== n
->type
) {
514 * Make sure that we don't happen to start with a
515 * control character at the start of a line.
517 if (MMAN_nl
& outflags
&& ('.' == *n
->string
||
518 '\'' == *n
->string
)) {
521 outflags
&= ~MMAN_spc
;
523 print_word(n
->string
);
526 * Conditionally run the pre-node action handler for a
529 act
= manacts
+ n
->tok
;
530 cond
= NULL
== act
->cond
|| (*act
->cond
)(m
, n
);
531 if (cond
&& act
->pre
)
532 do_sub
= (*act
->pre
)(m
, n
);
536 * Conditionally run all child nodes.
537 * Note that this iterates over children instead of using
538 * recursion. This prevents unnecessary depth in the stack.
541 for (sub
= n
->child
; sub
; sub
= sub
->next
)
545 * Lastly, conditionally run the post-node handler.
547 if (cond
&& act
->post
)
555 return(MDOC_HEAD
== n
->type
);
562 return(MDOC_BODY
== n
->type
);
570 prefix
= manacts
[n
->tok
].prefix
;
574 outflags
&= ~MMAN_spc
;
583 suffix
= manacts
[n
->tok
].suffix
;
586 outflags
&= ~MMAN_spc
;
598 post_percent(DECL_ARGS
)
601 if (pre_em
== manacts
[n
->tok
].pre
)
605 if (n
->prev
&& n
->prev
->tok
== n
->tok
&&
606 n
->next
->tok
== n
->tok
)
618 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
619 n
->parent
->norm
->Rs
.quote_T
) {
622 outflags
&= ~MMAN_spc
;
632 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
633 n
->parent
->norm
->Rs
.quote_T
) {
634 outflags
&= ~MMAN_spc
;
643 * Print before a section header.
649 if (MDOC_HEAD
!= n
->type
)
652 print_block(manacts
[n
->tok
].prefix
, 0);
655 outflags
&= ~MMAN_spc
;
660 * Print subsequent a section header.
666 if (MDOC_HEAD
!= n
->type
)
668 outflags
&= ~MMAN_spc
;
672 if (MDOC_Sh
== n
->tok
&& SEC_AUTHORS
== n
->sec
)
673 outflags
&= ~(MMAN_An_split
| MMAN_An_nosplit
);
676 /* See mdoc_term.c, synopsis_pre() for comments. */
678 pre_syn(const struct mdoc_node
*n
)
681 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
684 if (n
->prev
->tok
== n
->tok
&&
692 switch (n
->prev
->tok
) {
705 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
720 switch (n
->norm
->An
.auth
) {
722 outflags
&= ~MMAN_An_nosplit
;
723 outflags
|= MMAN_An_split
;
726 outflags
&= ~MMAN_An_split
;
727 outflags
|= MMAN_An_nosplit
;
730 if (MMAN_An_split
& outflags
)
732 else if (SEC_AUTHORS
== n
->sec
&&
733 ! (MMAN_An_nosplit
& outflags
))
734 outflags
|= MMAN_An_split
;
743 outflags
&= ~MMAN_spc
;
745 outflags
&= ~MMAN_spc
;
753 outflags
&= ~(MMAN_PP
| MMAN_sp
| MMAN_br
);
755 if (DISP_unfilled
== n
->norm
->Bd
.type
||
756 DISP_literal
== n
->norm
->Bd
.type
)
757 print_line(".nf", 0);
758 if (0 == n
->norm
->Bd
.comp
&& NULL
!= n
->parent
->prev
)
760 print_line(".RS", 0);
761 print_offs(n
->norm
->Bd
.offs
);
770 print_line(".RE", MMAN_nl
);
771 if (DISP_unfilled
== n
->norm
->Bd
.type
||
772 DISP_literal
== n
->norm
->Bd
.type
)
773 print_line(".fi", MMAN_nl
);
788 switch (n
->norm
->Bf
.font
) {
806 if (MDOC_BODY
== n
->type
)
829 if (MDOC_BODY
== n
->type
)
830 outflags
&= ~MMAN_Bk
;
838 switch (n
->norm
->Bl
.type
) {
840 n
->norm
->Bl
.count
= 0;
848 print_line(".TS", MMAN_nl
);
849 for (icol
= 0; icol
< n
->norm
->Bl
.ncols
; icol
++)
860 switch (n
->norm
->Bl
.type
) {
862 print_line(".TE", 0);
865 n
->norm
->Bl
.count
= 0;
870 outflags
|= MMAN_PP
| MMAN_nl
;
871 outflags
&= ~(MMAN_sp
| MMAN_br
);
888 print_word(n
->string
);
889 outflags
&= ~MMAN_spc
;
895 outflags
&= ~MMAN_spc
;
897 outflags
&= ~MMAN_spc
;
898 print_word(n
->string
);
906 print_line(".RS 6n", MMAN_nl
);
914 print_line(".RE", MMAN_nl
);
929 if (MDOC_HEAD
== n
->type
|| MDOC_BODY
== n
->type
)
930 outflags
&= ~MMAN_spc
;
937 if (MDOC_Fa
== n
->tok
)
944 if (NULL
!= (n
= n
->next
))
954 if (NULL
!= n
->next
&& MDOC_Fa
== n
->next
->tok
)
981 outflags
&= ~MMAN_spc
;
990 if (0 == n
->nchild
&& NULL
!= n
->next
&&
991 n
->next
->line
== n
->line
)
992 outflags
&= ~MMAN_spc
;
1008 outflags
&= ~MMAN_spc
;
1010 outflags
&= ~MMAN_spc
;
1023 if (MDOC_SYNPRETTY
& n
->flags
) {
1025 outflags
|= MMAN_br
;
1041 outflags
&= ~MMAN_spc
;
1043 outflags
&= ~MMAN_spc
;
1080 if (MDOC_SYNPRETTY
& n
->flags
) {
1083 print_word("#include <");
1084 outflags
&= ~MMAN_spc
;
1087 outflags
&= ~MMAN_spc
;
1097 if (MDOC_SYNPRETTY
& n
->flags
) {
1098 outflags
&= ~MMAN_spc
;
1101 outflags
|= MMAN_br
;
1104 outflags
&= ~MMAN_spc
;
1112 const struct mdoc_node
*bln
;
1116 outflags
|= MMAN_PP
| MMAN_nl
;
1117 bln
= n
->parent
->parent
;
1118 if (0 == bln
->norm
->Bl
.comp
||
1119 (NULL
== n
->parent
->prev
&&
1120 NULL
== bln
->parent
->prev
))
1121 outflags
|= MMAN_sp
;
1122 outflags
&= ~MMAN_br
;
1123 switch (bln
->norm
->Bl
.type
) {
1131 if (bln
->norm
->Bl
.type
== LIST_diag
)
1132 print_line(".B \"", 0);
1134 print_line(".R \"", 0);
1135 outflags
&= ~MMAN_spc
;
1142 print_width(bln
->norm
->Bl
.width
, NULL
, 0);
1144 outflags
|= MMAN_nl
;
1146 if (LIST_bullet
== bln
->norm
->Bl
.type
)
1153 print_width(bln
->norm
->Bl
.width
, NULL
, 0);
1155 outflags
|= MMAN_nl
;
1156 print_count(&bln
->norm
->Bl
.count
);
1159 print_width(bln
->norm
->Bl
.width
, n
->child
, 6);
1163 print_width(bln
->norm
->Bl
.width
, n
->child
, 0);
1165 outflags
&= ~MMAN_spc
;
1170 outflags
|= MMAN_nl
;
1180 const struct mdoc_node
*bln
;
1182 bln
= n
->parent
->parent
;
1186 switch (bln
->norm
->Bl
.type
) {
1188 outflags
&= ~MMAN_spc
;
1192 outflags
|= MMAN_br
;
1199 if (LIST_column
== bln
->norm
->Bl
.type
&&
1202 outflags
&= ~MMAN_spc
;
1214 if (SEC_LIBRARY
== n
->sec
)
1215 outflags
|= MMAN_br
;
1221 const struct mdoc_node
*link
, *descr
;
1223 if (NULL
== (link
= n
->child
))
1226 if (NULL
!= (descr
= link
->next
)) {
1228 while (NULL
!= descr
) {
1229 print_word(descr
->string
);
1230 descr
= descr
->next
;
1237 print_word(link
->string
);
1255 if (MDOC_BLOCK
== n
->type
)
1257 if (MDOC_ELEM
!= n
->type
&& MDOC_HEAD
!= n
->type
)
1259 name
= n
->child
? n
->child
->string
: m
->name
;
1262 if (MDOC_HEAD
== n
->type
) {
1263 if (NULL
== n
->parent
->prev
)
1264 outflags
|= MMAN_sp
;
1265 print_block(".HP", 0);
1266 printf(" %ldn", strlen(name
) + 1);
1267 outflags
|= MMAN_nl
;
1270 if (NULL
== n
->child
)
1271 print_word(m
->name
);
1279 if (MDOC_ELEM
!= n
->type
&& MDOC_HEAD
!= n
->type
)
1288 outflags
|= MMAN_spc_force
;
1296 outflags
&= ~MMAN_spc
;
1304 outflags
&= ~MMAN_spc
;
1311 if (MDOC_It
!= n
->parent
->tok
)
1312 outflags
|= MMAN_PP
;
1313 outflags
|= MMAN_sp
| MMAN_nl
;
1314 outflags
&= ~MMAN_br
;
1322 if (SEC_SEE_ALSO
== n
->sec
) {
1323 outflags
|= MMAN_PP
| MMAN_sp
| MMAN_nl
;
1324 outflags
&= ~MMAN_br
;
1333 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1334 if (0 == strcmp("on", n
->child
->string
))
1335 outflags
|= MMAN_Sm
| MMAN_spc
;
1337 outflags
&= ~MMAN_Sm
;
1345 if (MMAN_PP
& outflags
) {
1346 outflags
&= ~MMAN_PP
;
1347 print_line(".PP", 0);
1349 print_line(".sp", 0);
1357 outflags
|= MMAN_nl
;
1372 if (MDOC_SYNPRETTY
& n
->flags
) {
1391 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_BODY
!= n
->type
)
1407 outflags
&= ~MMAN_spc
;
1418 print_word(manacts
[n
->tok
].prefix
);
1419 if (NULL
== n
->child
)
1421 outflags
&= ~MMAN_spc
;
1423 outflags
&= ~MMAN_spc
;