]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_man.c
1 /* $Id: mdoc_man.c,v 1.46 2012/11/19 02:14:45 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 *meta, \
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_Bk_susp (1 << 8) /* suspend this (after a macro) */
255 #define MMAN_An_split (1 << 9) /* author mode is "split" */
256 #define MMAN_An_nosplit (1 << 10) /* author mode is "nosplit" */
257 #define MMAN_PD (1 << 11) /* inter-paragraph spacing disabled */
259 #define BL_STACK_MAX 32
261 static size_t Bl_stack
[BL_STACK_MAX
]; /* offsets [chars] */
262 static int Bl_stack_post
[BL_STACK_MAX
]; /* add final .RE */
263 static int Bl_stack_len
; /* number of nested Bl blocks */
264 static int TPremain
; /* characters before tag is full */
273 font_push(char newfont
)
276 if (fontqueue
.head
+ fontqueue
.size
<= ++fontqueue
.tail
) {
278 fontqueue
.head
= mandoc_realloc(fontqueue
.head
,
281 *fontqueue
.tail
= newfont
;
285 outflags
&= ~MMAN_spc
;
292 if (fontqueue
.tail
> fontqueue
.head
)
294 outflags
&= ~MMAN_spc
;
297 putchar(*fontqueue
.tail
);
301 print_word(const char *s
)
304 if ((MMAN_PP
| MMAN_sp
| MMAN_br
| MMAN_nl
) & outflags
) {
306 * If we need a newline, print it now and start afresh.
308 if (MMAN_PP
& outflags
) {
309 if (MMAN_sp
& outflags
) {
310 if (MMAN_PD
& outflags
) {
312 outflags
&= ~MMAN_PD
;
314 } else if ( ! (MMAN_PD
& outflags
)) {
319 } else if (MMAN_sp
& outflags
)
321 else if (MMAN_br
& outflags
)
323 else if (MMAN_nl
& outflags
)
325 outflags
&= ~(MMAN_PP
|MMAN_sp
|MMAN_br
|MMAN_nl
|MMAN_spc
);
329 } else if (MMAN_spc
& outflags
) {
331 * If we need a space, only print it if
332 * (1) it is forced by `No' or
333 * (2) what follows is not terminating punctuation or
334 * (3) what follows is longer than one character.
336 if (MMAN_spc_force
& outflags
|| '\0' == s
[0] ||
337 NULL
== strchr(".,:;)]?!", s
[0]) || '\0' != s
[1]) {
338 if (MMAN_Bk
& outflags
&&
339 ! (MMAN_Bk_susp
& outflags
))
348 * Reassign needing space if we're not following opening
351 if (MMAN_Sm
& outflags
&& ('\0' == s
[0] ||
352 (('(' != s
[0] && '[' != s
[0]) || '\0' != s
[1])))
353 outflags
|= MMAN_spc
;
355 outflags
&= ~MMAN_spc
;
356 outflags
&= ~(MMAN_spc_force
| MMAN_Bk_susp
);
367 putchar((unsigned char)*s
);
376 print_line(const char *s
, int newflags
)
379 outflags
&= ~MMAN_br
;
382 outflags
|= newflags
;
386 print_block(const char *s
, int newflags
)
389 outflags
&= ~MMAN_PP
;
390 if (MMAN_sp
& outflags
) {
391 outflags
&= ~(MMAN_sp
| MMAN_br
);
392 if (MMAN_PD
& outflags
) {
393 print_line(".PD", 0);
394 outflags
&= ~MMAN_PD
;
396 } else if (! (MMAN_PD
& outflags
))
397 print_line(".PD 0", MMAN_PD
);
400 outflags
|= MMAN_Bk_susp
| newflags
;
404 print_offs(const char *v
)
410 /* Convert v into a number (of characters). */
411 if (NULL
== v
|| '\0' == *v
|| 0 == strcmp(v
, "left"))
413 else if (0 == strcmp(v
, "indent"))
415 else if (0 == strcmp(v
, "indent-two"))
417 else if (a2roffsu(v
, &su
, SCALE_MAX
)) {
418 if (SCALE_EN
== su
.unit
)
423 * If we are inside an enclosing list,
424 * there is no easy way to add the two
425 * indentations because they are provided
426 * in terms of different units.
435 * We are inside an enclosing list.
436 * Add the two indentations.
439 sz
+= Bl_stack
[Bl_stack_len
- 1];
441 snprintf(buf
, sizeof(buf
), "%ldn", sz
);
446 print_width(const char *v
, const struct mdoc_node
*child
, size_t defsz
)
456 /* Convert v into a number (of characters). */
459 else if (a2roffsu(v
, &su
, SCALE_MAX
)) {
460 if (SCALE_EN
== su
.unit
)
469 /* XXX Rough estimation, might have multiple parts. */
470 chsz
= (NULL
!= child
&& MDOC_TEXT
== child
->type
) ?
471 strlen(child
->string
) : 0;
474 * If we are inside an enclosing list,
475 * preserve its indentation.
477 if (Bl_stack_len
&& Bl_stack
[Bl_stack_len
- 1]) {
478 print_line(".RS", MMAN_Bk_susp
);
479 snprintf(buf
, sizeof(buf
), "%ldn",
480 Bl_stack
[Bl_stack_len
- 1]);
485 * Save our own indentation,
486 * such that child lists can use it.
488 Bl_stack
[Bl_stack_len
++] = sz
+ 2;
490 /* Set up the current list. */
491 if (defsz
&& chsz
> sz
)
492 print_block(".HP", 0);
494 print_block(".TP", 0);
498 snprintf(buf
, sizeof(buf
), "%ldn", sz
+ 2);
506 print_count(int *count
)
510 snprintf(buf
, sizeof(buf
), "%d.", ++*count
);
515 man_man(void *arg
, const struct man
*man
)
519 * Dump the keep buffer.
520 * We're guaranteed by now that this exists (is non-NULL).
521 * Flush stdout afterward, just in case.
523 fputs(mparse_getkeep(man_mparse(man
)), stdout
);
528 man_mdoc(void *arg
, const struct mdoc
*mdoc
)
530 const struct mdoc_meta
*meta
;
531 const struct mdoc_node
*n
;
533 meta
= mdoc_meta(mdoc
);
536 printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
537 meta
->title
, meta
->msec
, meta
->date
,
538 meta
->os
, meta
->vol
);
540 /* Disable hyphenation and if nroff, disable justification. */
541 printf(".nh\n.if n .ad l");
543 outflags
= MMAN_nl
| MMAN_Sm
;
544 if (0 == fontqueue
.size
) {
546 fontqueue
.head
= fontqueue
.tail
= mandoc_malloc(8);
547 *fontqueue
.tail
= 'R';
554 print_node(DECL_ARGS
)
556 const struct mdoc_node
*prev
, *sub
;
557 const struct manact
*act
;
561 * Break the line if we were parsed subsequent the current node.
562 * This makes the page structure be more consistent.
564 prev
= n
->prev
? n
->prev
: n
->parent
;
565 if (MMAN_spc
& outflags
&& prev
&& prev
->line
< n
->line
)
572 if (MDOC_TEXT
== n
->type
) {
574 * Make sure that we don't happen to start with a
575 * control character at the start of a line.
577 if (MMAN_nl
& outflags
&& ('.' == *n
->string
||
578 '\'' == *n
->string
)) {
581 outflags
&= ~MMAN_spc
;
583 print_word(n
->string
);
586 * Conditionally run the pre-node action handler for a
589 act
= manacts
+ n
->tok
;
590 cond
= NULL
== act
->cond
|| (*act
->cond
)(meta
, n
);
591 if (cond
&& act
->pre
)
592 do_sub
= (*act
->pre
)(meta
, n
);
596 * Conditionally run all child nodes.
597 * Note that this iterates over children instead of using
598 * recursion. This prevents unnecessary depth in the stack.
601 for (sub
= n
->child
; sub
; sub
= sub
->next
)
602 print_node(meta
, sub
);
605 * Lastly, conditionally run the post-node handler.
607 if (cond
&& act
->post
)
608 (*act
->post
)(meta
, n
);
615 return(MDOC_HEAD
== n
->type
);
622 return(MDOC_BODY
== n
->type
);
630 prefix
= manacts
[n
->tok
].prefix
;
634 outflags
&= ~MMAN_spc
;
643 suffix
= manacts
[n
->tok
].suffix
;
646 outflags
&= ~MMAN_spc
;
658 post_percent(DECL_ARGS
)
661 if (pre_em
== manacts
[n
->tok
].pre
)
665 if (n
->prev
&& n
->prev
->tok
== n
->tok
&&
666 n
->next
->tok
== n
->tok
)
678 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
679 n
->parent
->norm
->Rs
.quote_T
) {
682 outflags
&= ~MMAN_spc
;
692 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
693 n
->parent
->norm
->Rs
.quote_T
) {
694 outflags
&= ~MMAN_spc
;
699 post_percent(meta
, n
);
703 * Print before a section header.
712 print_block(manacts
[n
->tok
].prefix
, 0);
715 outflags
&= ~MMAN_spc
;
718 if (MDOC_Sh
== n
->tok
) {
719 if (MDOC_SYNPRETTY
& n
->flags
)
722 outflags
&= ~MMAN_Bk
;
732 * Print subsequent a section header.
738 if (MDOC_HEAD
!= n
->type
)
740 outflags
&= ~MMAN_spc
;
744 if (MDOC_Sh
== n
->tok
&& SEC_AUTHORS
== n
->sec
)
745 outflags
&= ~(MMAN_An_split
| MMAN_An_nosplit
);
748 /* See mdoc_term.c, synopsis_pre() for comments. */
750 pre_syn(const struct mdoc_node
*n
)
753 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
756 if (n
->prev
->tok
== n
->tok
&&
764 switch (n
->prev
->tok
) {
777 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
792 switch (n
->norm
->An
.auth
) {
794 outflags
&= ~MMAN_An_nosplit
;
795 outflags
|= MMAN_An_split
;
798 outflags
&= ~MMAN_An_split
;
799 outflags
|= MMAN_An_nosplit
;
802 if (MMAN_An_split
& outflags
)
804 else if (SEC_AUTHORS
== n
->sec
&&
805 ! (MMAN_An_nosplit
& outflags
))
806 outflags
|= MMAN_An_split
;
815 outflags
&= ~MMAN_spc
;
817 outflags
&= ~MMAN_spc
;
825 outflags
&= ~(MMAN_PP
| MMAN_sp
| MMAN_br
);
827 if (DISP_unfilled
== n
->norm
->Bd
.type
||
828 DISP_literal
== n
->norm
->Bd
.type
)
829 print_line(".nf", 0);
830 if (0 == n
->norm
->Bd
.comp
&& NULL
!= n
->parent
->prev
)
832 print_line(".RS", MMAN_Bk_susp
);
833 print_offs(n
->norm
->Bd
.offs
);
843 /* Close out this display. */
844 print_line(".RE", MMAN_nl
);
845 if (DISP_unfilled
== n
->norm
->Bd
.type
||
846 DISP_literal
== n
->norm
->Bd
.type
)
847 print_line(".fi", MMAN_nl
);
850 * If we are inside an enclosing list and the current
851 * list item is not yet finished, restore the correct
852 * indentation for what remains of that item.
854 if (NULL
!= n
->parent
->next
&&
855 Bl_stack_len
&& Bl_stack
[Bl_stack_len
- 1]) {
856 print_line(".RS", MMAN_Bk_susp
);
857 snprintf(buf
, sizeof(buf
), "%ldn",
858 Bl_stack
[Bl_stack_len
- 1]);
860 /* Remeber to close out this .RS block later. */
861 Bl_stack_post
[Bl_stack_len
- 1] = 1;
877 switch (n
->norm
->Bf
.font
) {
895 if (MDOC_BODY
== n
->type
)
918 if (MDOC_BODY
== n
->type
)
919 outflags
&= ~MMAN_Bk
;
927 switch (n
->norm
->Bl
.type
) {
929 n
->norm
->Bl
.count
= 0;
937 print_line(".TS", MMAN_nl
);
938 for (icol
= 0; icol
< n
->norm
->Bl
.ncols
; icol
++)
949 switch (n
->norm
->Bl
.type
) {
951 print_line(".TE", 0);
954 n
->norm
->Bl
.count
= 0;
959 outflags
|= MMAN_PP
| MMAN_nl
;
960 outflags
&= ~(MMAN_sp
| MMAN_br
);
977 print_word(n
->string
);
978 outflags
&= ~MMAN_spc
;
984 outflags
&= ~MMAN_spc
;
986 outflags
&= ~MMAN_spc
;
987 print_word(n
->string
);
995 print_line(".RS 6n", MMAN_nl
);
1003 print_line(".RE", MMAN_nl
);
1018 if (MDOC_HEAD
== n
->type
|| MDOC_BODY
== n
->type
)
1019 outflags
&= ~MMAN_spc
;
1026 if (MDOC_Fa
== n
->tok
)
1031 print_node(meta
, n
);
1033 if (NULL
!= (n
= n
->next
))
1043 if (NULL
!= n
->next
&& MDOC_Fa
== n
->next
->tok
)
1061 outflags
|= MMAN_br
;
1070 outflags
&= ~MMAN_spc
;
1079 if (0 == n
->nchild
&& NULL
!= n
->next
&&
1080 n
->next
->line
== n
->line
)
1081 outflags
&= ~MMAN_spc
;
1095 print_node(meta
, n
);
1097 outflags
&= ~MMAN_spc
;
1099 outflags
&= ~MMAN_spc
;
1112 if (MDOC_SYNPRETTY
& n
->flags
) {
1114 outflags
|= MMAN_br
;
1130 outflags
&= ~MMAN_spc
;
1132 outflags
&= ~MMAN_spc
;
1169 if (MDOC_SYNPRETTY
& n
->flags
) {
1172 print_word("#include <");
1173 outflags
&= ~MMAN_spc
;
1176 outflags
&= ~MMAN_spc
;
1186 if (MDOC_SYNPRETTY
& n
->flags
) {
1187 outflags
&= ~MMAN_spc
;
1190 outflags
|= MMAN_br
;
1193 outflags
&= ~MMAN_spc
;
1201 const struct mdoc_node
*bln
;
1205 outflags
|= MMAN_PP
| MMAN_nl
;
1206 bln
= n
->parent
->parent
;
1207 if (0 == bln
->norm
->Bl
.comp
||
1208 (NULL
== n
->parent
->prev
&&
1209 NULL
== bln
->parent
->prev
))
1210 outflags
|= MMAN_sp
;
1211 outflags
&= ~MMAN_br
;
1212 switch (bln
->norm
->Bl
.type
) {
1220 if (bln
->norm
->Bl
.type
== LIST_diag
)
1221 print_line(".B \"", 0);
1223 print_line(".R \"", 0);
1224 outflags
&= ~MMAN_spc
;
1231 print_width(bln
->norm
->Bl
.width
, NULL
, 0);
1233 outflags
|= MMAN_nl
;
1235 if (LIST_bullet
== bln
->norm
->Bl
.type
)
1242 print_width(bln
->norm
->Bl
.width
, NULL
, 0);
1244 outflags
|= MMAN_nl
;
1245 print_count(&bln
->norm
->Bl
.count
);
1248 print_width(bln
->norm
->Bl
.width
, n
->child
, 6);
1252 print_width(bln
->norm
->Bl
.width
, n
->child
, 0);
1254 outflags
&= ~MMAN_spc
;
1259 outflags
|= MMAN_nl
;
1269 const struct mdoc_node
*bln
;
1271 bln
= n
->parent
->parent
;
1275 switch (bln
->norm
->Bl
.type
) {
1277 outflags
&= ~MMAN_spc
;
1281 outflags
|= MMAN_br
;
1288 switch (bln
->norm
->Bl
.type
) {
1300 assert(Bl_stack_len
);
1301 Bl_stack
[--Bl_stack_len
] = 0;
1304 * Our indentation had to be restored
1305 * after a child display.
1306 * Close out that indentation block now.
1308 if (Bl_stack_post
[Bl_stack_len
]) {
1309 print_line(".RE", MMAN_nl
);
1310 Bl_stack_post
[Bl_stack_len
] = 0;
1314 * We are inside an enclosing list.
1315 * Restore the indentation of that list.
1317 if (Bl_stack_len
&& Bl_stack
[Bl_stack_len
- 1])
1318 print_line(".RE", MMAN_nl
);
1321 if (NULL
!= n
->next
) {
1323 outflags
&= ~MMAN_spc
;
1339 if (SEC_LIBRARY
== n
->sec
)
1340 outflags
|= MMAN_br
;
1346 const struct mdoc_node
*link
, *descr
;
1348 if (NULL
== (link
= n
->child
))
1351 if (NULL
!= (descr
= link
->next
)) {
1353 while (NULL
!= descr
) {
1354 print_word(descr
->string
);
1355 descr
= descr
->next
;
1362 print_word(link
->string
);
1380 if (MDOC_BLOCK
== n
->type
)
1382 if (MDOC_ELEM
!= n
->type
&& MDOC_HEAD
!= n
->type
)
1384 name
= n
->child
? n
->child
->string
: meta
->name
;
1387 if (MDOC_HEAD
== n
->type
) {
1388 if (NULL
== n
->parent
->prev
)
1389 outflags
|= MMAN_sp
;
1390 print_block(".HP", 0);
1391 printf(" %ldn", strlen(name
) + 1);
1392 outflags
|= MMAN_nl
;
1395 if (NULL
== n
->child
)
1396 print_word(meta
->name
);
1404 if (MDOC_ELEM
!= n
->type
&& MDOC_HEAD
!= n
->type
)
1413 outflags
|= MMAN_spc_force
;
1421 outflags
&= ~MMAN_spc
;
1429 outflags
&= ~MMAN_spc
;
1436 if (MDOC_It
!= n
->parent
->tok
)
1437 outflags
|= MMAN_PP
;
1438 outflags
|= MMAN_sp
| MMAN_nl
;
1439 outflags
&= ~MMAN_br
;
1447 if (SEC_SEE_ALSO
== n
->sec
) {
1448 outflags
|= MMAN_PP
| MMAN_sp
| MMAN_nl
;
1449 outflags
&= ~MMAN_br
;
1458 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1459 if (0 == strcmp("on", n
->child
->string
))
1460 outflags
|= MMAN_Sm
| MMAN_spc
;
1462 outflags
&= ~MMAN_Sm
;
1470 if (MMAN_PP
& outflags
) {
1471 outflags
&= ~MMAN_PP
;
1472 print_line(".PP", 0);
1474 print_line(".sp", 0);
1482 outflags
|= MMAN_nl
;
1497 if (MDOC_SYNPRETTY
& n
->flags
) {
1516 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_BODY
!= n
->type
)
1528 print_node(meta
, n
);
1532 outflags
&= ~MMAN_spc
;
1534 print_node(meta
, n
);
1543 print_word(manacts
[n
->tok
].prefix
);
1544 if (NULL
== n
->child
)
1546 outflags
&= ~MMAN_spc
;
1548 outflags
&= ~MMAN_spc
;