]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.289 2014/11/10 21:56:43 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
5 * Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
31 #include "mandoc_aux.h"
38 struct termpair
*ppair
;
42 #define DECL_ARGS struct termp *p, \
43 struct termpair *pair, \
44 const struct mdoc_meta *meta, \
48 int (*pre
)(DECL_ARGS
);
49 void (*post
)(DECL_ARGS
);
52 static size_t a2width(const struct termp
*, const char *);
53 static size_t a2height(const struct termp
*, const char *);
55 static void print_bvspace(struct termp
*,
56 const struct mdoc_node
*,
57 const struct mdoc_node
*);
58 static void print_mdoc_node(DECL_ARGS
);
59 static void print_mdoc_nodelist(DECL_ARGS
);
60 static void print_mdoc_head(struct termp
*, const void *);
61 static void print_mdoc_foot(struct termp
*, const void *);
62 static void synopsis_pre(struct termp
*,
63 const struct mdoc_node
*);
65 static void termp____post(DECL_ARGS
);
66 static void termp__t_post(DECL_ARGS
);
67 static void termp_bd_post(DECL_ARGS
);
68 static void termp_bk_post(DECL_ARGS
);
69 static void termp_bl_post(DECL_ARGS
);
70 static void termp_fd_post(DECL_ARGS
);
71 static void termp_fo_post(DECL_ARGS
);
72 static void termp_in_post(DECL_ARGS
);
73 static void termp_it_post(DECL_ARGS
);
74 static void termp_lb_post(DECL_ARGS
);
75 static void termp_nm_post(DECL_ARGS
);
76 static void termp_pf_post(DECL_ARGS
);
77 static void termp_quote_post(DECL_ARGS
);
78 static void termp_sh_post(DECL_ARGS
);
79 static void termp_ss_post(DECL_ARGS
);
81 static int termp__a_pre(DECL_ARGS
);
82 static int termp__t_pre(DECL_ARGS
);
83 static int termp_an_pre(DECL_ARGS
);
84 static int termp_ap_pre(DECL_ARGS
);
85 static int termp_bd_pre(DECL_ARGS
);
86 static int termp_bf_pre(DECL_ARGS
);
87 static int termp_bk_pre(DECL_ARGS
);
88 static int termp_bl_pre(DECL_ARGS
);
89 static int termp_bold_pre(DECL_ARGS
);
90 static int termp_bt_pre(DECL_ARGS
);
91 static int termp_bx_pre(DECL_ARGS
);
92 static int termp_cd_pre(DECL_ARGS
);
93 static int termp_d1_pre(DECL_ARGS
);
94 static int termp_es_pre(DECL_ARGS
);
95 static int termp_ex_pre(DECL_ARGS
);
96 static int termp_fa_pre(DECL_ARGS
);
97 static int termp_fd_pre(DECL_ARGS
);
98 static int termp_fl_pre(DECL_ARGS
);
99 static int termp_fn_pre(DECL_ARGS
);
100 static int termp_fo_pre(DECL_ARGS
);
101 static int termp_ft_pre(DECL_ARGS
);
102 static int termp_in_pre(DECL_ARGS
);
103 static int termp_it_pre(DECL_ARGS
);
104 static int termp_li_pre(DECL_ARGS
);
105 static int termp_ll_pre(DECL_ARGS
);
106 static int termp_lk_pre(DECL_ARGS
);
107 static int termp_nd_pre(DECL_ARGS
);
108 static int termp_nm_pre(DECL_ARGS
);
109 static int termp_ns_pre(DECL_ARGS
);
110 static int termp_quote_pre(DECL_ARGS
);
111 static int termp_rs_pre(DECL_ARGS
);
112 static int termp_rv_pre(DECL_ARGS
);
113 static int termp_sh_pre(DECL_ARGS
);
114 static int termp_sm_pre(DECL_ARGS
);
115 static int termp_sp_pre(DECL_ARGS
);
116 static int termp_ss_pre(DECL_ARGS
);
117 static int termp_under_pre(DECL_ARGS
);
118 static int termp_ud_pre(DECL_ARGS
);
119 static int termp_vt_pre(DECL_ARGS
);
120 static int termp_xr_pre(DECL_ARGS
);
121 static int termp_xx_pre(DECL_ARGS
);
123 static const struct termact termacts
[MDOC_MAX
] = {
124 { termp_ap_pre
, NULL
}, /* Ap */
125 { NULL
, NULL
}, /* Dd */
126 { NULL
, NULL
}, /* Dt */
127 { NULL
, NULL
}, /* Os */
128 { termp_sh_pre
, termp_sh_post
}, /* Sh */
129 { termp_ss_pre
, termp_ss_post
}, /* Ss */
130 { termp_sp_pre
, NULL
}, /* Pp */
131 { termp_d1_pre
, termp_bl_post
}, /* D1 */
132 { termp_d1_pre
, termp_bl_post
}, /* Dl */
133 { termp_bd_pre
, termp_bd_post
}, /* Bd */
134 { NULL
, NULL
}, /* Ed */
135 { termp_bl_pre
, termp_bl_post
}, /* Bl */
136 { NULL
, NULL
}, /* El */
137 { termp_it_pre
, termp_it_post
}, /* It */
138 { termp_under_pre
, NULL
}, /* Ad */
139 { termp_an_pre
, NULL
}, /* An */
140 { termp_under_pre
, NULL
}, /* Ar */
141 { termp_cd_pre
, NULL
}, /* Cd */
142 { termp_bold_pre
, NULL
}, /* Cm */
143 { NULL
, NULL
}, /* Dv */
144 { NULL
, NULL
}, /* Er */
145 { NULL
, NULL
}, /* Ev */
146 { termp_ex_pre
, NULL
}, /* Ex */
147 { termp_fa_pre
, NULL
}, /* Fa */
148 { termp_fd_pre
, termp_fd_post
}, /* Fd */
149 { termp_fl_pre
, NULL
}, /* Fl */
150 { termp_fn_pre
, NULL
}, /* Fn */
151 { termp_ft_pre
, NULL
}, /* Ft */
152 { termp_bold_pre
, NULL
}, /* Ic */
153 { termp_in_pre
, termp_in_post
}, /* In */
154 { termp_li_pre
, NULL
}, /* Li */
155 { termp_nd_pre
, NULL
}, /* Nd */
156 { termp_nm_pre
, termp_nm_post
}, /* Nm */
157 { termp_quote_pre
, termp_quote_post
}, /* Op */
158 { termp_ft_pre
, NULL
}, /* Ot */
159 { termp_under_pre
, NULL
}, /* Pa */
160 { termp_rv_pre
, NULL
}, /* Rv */
161 { NULL
, NULL
}, /* St */
162 { termp_under_pre
, NULL
}, /* Va */
163 { termp_vt_pre
, NULL
}, /* Vt */
164 { termp_xr_pre
, NULL
}, /* Xr */
165 { termp__a_pre
, termp____post
}, /* %A */
166 { termp_under_pre
, termp____post
}, /* %B */
167 { NULL
, termp____post
}, /* %D */
168 { termp_under_pre
, termp____post
}, /* %I */
169 { termp_under_pre
, termp____post
}, /* %J */
170 { NULL
, termp____post
}, /* %N */
171 { NULL
, termp____post
}, /* %O */
172 { NULL
, termp____post
}, /* %P */
173 { NULL
, termp____post
}, /* %R */
174 { termp__t_pre
, termp__t_post
}, /* %T */
175 { NULL
, termp____post
}, /* %V */
176 { NULL
, NULL
}, /* Ac */
177 { termp_quote_pre
, termp_quote_post
}, /* Ao */
178 { termp_quote_pre
, termp_quote_post
}, /* Aq */
179 { NULL
, NULL
}, /* At */
180 { NULL
, NULL
}, /* Bc */
181 { termp_bf_pre
, NULL
}, /* Bf */
182 { termp_quote_pre
, termp_quote_post
}, /* Bo */
183 { termp_quote_pre
, termp_quote_post
}, /* Bq */
184 { termp_xx_pre
, NULL
}, /* Bsx */
185 { termp_bx_pre
, NULL
}, /* Bx */
186 { NULL
, NULL
}, /* Db */
187 { NULL
, NULL
}, /* Dc */
188 { termp_quote_pre
, termp_quote_post
}, /* Do */
189 { termp_quote_pre
, termp_quote_post
}, /* Dq */
190 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
191 { NULL
, NULL
}, /* Ef */
192 { termp_under_pre
, NULL
}, /* Em */
193 { termp_quote_pre
, termp_quote_post
}, /* Eo */
194 { termp_xx_pre
, NULL
}, /* Fx */
195 { termp_bold_pre
, NULL
}, /* Ms */
196 { NULL
, NULL
}, /* No */
197 { termp_ns_pre
, NULL
}, /* Ns */
198 { termp_xx_pre
, NULL
}, /* Nx */
199 { termp_xx_pre
, NULL
}, /* Ox */
200 { NULL
, NULL
}, /* Pc */
201 { NULL
, termp_pf_post
}, /* Pf */
202 { termp_quote_pre
, termp_quote_post
}, /* Po */
203 { termp_quote_pre
, termp_quote_post
}, /* Pq */
204 { NULL
, NULL
}, /* Qc */
205 { termp_quote_pre
, termp_quote_post
}, /* Ql */
206 { termp_quote_pre
, termp_quote_post
}, /* Qo */
207 { termp_quote_pre
, termp_quote_post
}, /* Qq */
208 { NULL
, NULL
}, /* Re */
209 { termp_rs_pre
, NULL
}, /* Rs */
210 { NULL
, NULL
}, /* Sc */
211 { termp_quote_pre
, termp_quote_post
}, /* So */
212 { termp_quote_pre
, termp_quote_post
}, /* Sq */
213 { termp_sm_pre
, NULL
}, /* Sm */
214 { termp_under_pre
, NULL
}, /* Sx */
215 { termp_bold_pre
, NULL
}, /* Sy */
216 { NULL
, NULL
}, /* Tn */
217 { termp_xx_pre
, NULL
}, /* Ux */
218 { NULL
, NULL
}, /* Xc */
219 { NULL
, NULL
}, /* Xo */
220 { termp_fo_pre
, termp_fo_post
}, /* Fo */
221 { NULL
, NULL
}, /* Fc */
222 { termp_quote_pre
, termp_quote_post
}, /* Oo */
223 { NULL
, NULL
}, /* Oc */
224 { termp_bk_pre
, termp_bk_post
}, /* Bk */
225 { NULL
, NULL
}, /* Ek */
226 { termp_bt_pre
, NULL
}, /* Bt */
227 { NULL
, NULL
}, /* Hf */
228 { termp_under_pre
, NULL
}, /* Fr */
229 { termp_ud_pre
, NULL
}, /* Ud */
230 { NULL
, termp_lb_post
}, /* Lb */
231 { termp_sp_pre
, NULL
}, /* Lp */
232 { termp_lk_pre
, NULL
}, /* Lk */
233 { termp_under_pre
, NULL
}, /* Mt */
234 { termp_quote_pre
, termp_quote_post
}, /* Brq */
235 { termp_quote_pre
, termp_quote_post
}, /* Bro */
236 { NULL
, NULL
}, /* Brc */
237 { NULL
, termp____post
}, /* %C */
238 { termp_es_pre
, NULL
}, /* Es */
239 { termp_quote_pre
, termp_quote_post
}, /* En */
240 { termp_xx_pre
, NULL
}, /* Dx */
241 { NULL
, termp____post
}, /* %Q */
242 { termp_sp_pre
, NULL
}, /* br */
243 { termp_sp_pre
, NULL
}, /* sp */
244 { NULL
, termp____post
}, /* %U */
245 { NULL
, NULL
}, /* Ta */
246 { termp_ll_pre
, NULL
}, /* ll */
251 terminal_mdoc(void *arg
, const struct mdoc
*mdoc
)
253 const struct mdoc_meta
*meta
;
257 p
= (struct termp
*)arg
;
260 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
261 p
->tabwidth
= term_len(p
, 5);
263 n
= mdoc_node(mdoc
)->child
;
264 meta
= mdoc_meta(mdoc
);
266 if (p
->synopsisonly
) {
268 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
269 if (n
->child
->next
->child
!= NULL
)
270 print_mdoc_nodelist(p
, NULL
,
271 meta
, n
->child
->next
->child
);
278 if (p
->defindent
== 0)
280 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, meta
);
282 if (n
->tok
!= MDOC_Sh
)
284 print_mdoc_nodelist(p
, NULL
, meta
, n
);
291 print_mdoc_nodelist(DECL_ARGS
)
294 print_mdoc_node(p
, pair
, meta
, n
);
296 print_mdoc_nodelist(p
, pair
, meta
, n
->next
);
300 print_mdoc_node(DECL_ARGS
)
303 struct termpair npair
;
304 size_t offset
, rmargin
;
308 rmargin
= p
->rmargin
;
309 n
->prev_font
= term_fontq(p
);
311 memset(&npair
, 0, sizeof(struct termpair
));
315 * Keeps only work until the end of a line. If a keep was
316 * invoked in a prior line, revert it to PREKEEP.
319 if (TERMP_KEEP
& p
->flags
) {
320 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
321 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
322 p
->flags
&= ~TERMP_KEEP
;
323 p
->flags
|= TERMP_PREKEEP
;
328 * After the keep flags have been set up, we may now
329 * produce output. Note that some pre-handlers do so.
334 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
336 if (MDOC_DELIMC
& n
->flags
)
337 p
->flags
|= TERMP_NOSPACE
;
338 term_word(p
, n
->string
);
339 if (MDOC_DELIMO
& n
->flags
)
340 p
->flags
|= TERMP_NOSPACE
;
343 if ( ! (n
->flags
& MDOC_LINE
))
344 p
->flags
|= TERMP_NOSPACE
;
346 if (n
->next
!= NULL
&& ! (n
->next
->flags
& MDOC_LINE
))
347 p
->flags
|= TERMP_NOSPACE
;
350 term_tbl(p
, n
->span
);
353 if (termacts
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
354 chld
= (*termacts
[n
->tok
].pre
)
355 (p
, &npair
, meta
, n
);
359 if (chld
&& n
->child
)
360 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
363 (ENDBODY_NOT
== n
->end
? n
: n
->pending
)->prev_font
);
373 if ( ! termacts
[n
->tok
].post
|| MDOC_ENDED
& n
->flags
)
375 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
378 * Explicit end tokens not only call the post
379 * handler, but also tell the respective block
380 * that it must not call the post handler again.
382 if (ENDBODY_NOT
!= n
->end
)
383 n
->pending
->flags
|= MDOC_ENDED
;
386 * End of line terminating an implicit block
387 * while an explicit block is still open.
388 * Continue the explicit block without spacing.
390 if (ENDBODY_NOSPACE
== n
->end
)
391 p
->flags
|= TERMP_NOSPACE
;
395 if (MDOC_EOS
& n
->flags
)
396 p
->flags
|= TERMP_SENTENCE
;
398 if (MDOC_ll
!= n
->tok
) {
400 p
->rmargin
= rmargin
;
405 print_mdoc_foot(struct termp
*p
, const void *arg
)
407 const struct mdoc_meta
*meta
;
409 meta
= (const struct mdoc_meta
*)arg
;
411 term_fontrepl(p
, TERMFONT_NONE
);
414 * Output the footer in new-groff style, that is, three columns
415 * with the middle being the manual date and flanking columns
416 * being the operating system:
424 p
->rmargin
= (p
->maxrmargin
-
425 term_strlen(p
, meta
->date
) + term_len(p
, 1)) / 2;
427 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
429 term_word(p
, meta
->os
);
432 p
->offset
= p
->rmargin
;
433 p
->rmargin
= p
->maxrmargin
- term_strlen(p
, meta
->os
);
434 p
->flags
|= TERMP_NOSPACE
;
436 term_word(p
, meta
->date
);
439 p
->offset
= p
->rmargin
;
440 p
->rmargin
= p
->maxrmargin
;
442 p
->flags
&= ~TERMP_NOBREAK
;
443 p
->flags
|= TERMP_NOSPACE
;
445 term_word(p
, meta
->os
);
449 p
->rmargin
= p
->maxrmargin
;
454 print_mdoc_head(struct termp
*p
, const void *arg
)
456 const struct mdoc_meta
*meta
;
457 char *volume
, *title
;
458 size_t vollen
, titlen
;
460 meta
= (const struct mdoc_meta
*)arg
;
463 * The header is strange. It has three components, which are
464 * really two with the first duplicated. It goes like this:
466 * IDENTIFIER TITLE IDENTIFIER
468 * The IDENTIFIER is NAME(SECTION), which is the command-name
469 * (if given, or "unknown" if not) followed by the manual page
470 * section. These are given in `Dt'. The TITLE is a free-form
471 * string depending on the manual volume. If not specified, it
472 * switches on the manual section.
476 if (NULL
== meta
->arch
)
477 volume
= mandoc_strdup(meta
->vol
);
479 mandoc_asprintf(&volume
, "%s (%s)",
480 meta
->vol
, meta
->arch
);
481 vollen
= term_strlen(p
, volume
);
483 if (NULL
== meta
->msec
)
484 title
= mandoc_strdup(meta
->title
);
486 mandoc_asprintf(&title
, "%s(%s)",
487 meta
->title
, meta
->msec
);
488 titlen
= term_strlen(p
, title
);
490 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
493 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
494 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
495 p
->maxrmargin
- vollen
;
500 p
->flags
|= TERMP_NOSPACE
;
501 p
->offset
= p
->rmargin
;
502 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
503 p
->maxrmargin
- titlen
: p
->maxrmargin
;
505 term_word(p
, volume
);
508 p
->flags
&= ~TERMP_NOBREAK
;
510 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
511 p
->flags
|= TERMP_NOSPACE
;
512 p
->offset
= p
->rmargin
;
513 p
->rmargin
= p
->maxrmargin
;
518 p
->flags
&= ~TERMP_NOSPACE
;
520 p
->rmargin
= p
->maxrmargin
;
526 a2height(const struct termp
*p
, const char *v
)
532 if ( ! a2roffsu(v
, &su
, SCALE_VS
))
533 SCALE_VS_INIT(&su
, atoi(v
));
535 return(term_vspan(p
, &su
));
539 a2width(const struct termp
*p
, const char *v
)
544 if ( ! a2roffsu(v
, &su
, SCALE_MAX
)) {
545 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
546 su
.scale
/= term_strlen(p
, "0");
549 return(term_hspan(p
, &su
));
553 * Determine how much space to print out before block elements of `It'
554 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
558 print_bvspace(struct termp
*p
,
559 const struct mdoc_node
*bl
,
560 const struct mdoc_node
*n
)
562 const struct mdoc_node
*nn
;
568 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
570 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
573 /* Do not vspace directly after Ss/Sh. */
576 while (nn
->prev
== NULL
) {
579 if (nn
->type
== MDOC_ROOT
)
581 } while (nn
->type
!= MDOC_BLOCK
);
582 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
584 if (nn
->tok
== MDOC_It
&&
585 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
589 /* A `-column' does not assert vspace within the list. */
591 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
592 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
595 /* A `-diag' without body does not vspace. */
597 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
598 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
599 assert(n
->prev
->body
);
600 if (NULL
== n
->prev
->body
->child
)
609 termp_ll_pre(DECL_ARGS
)
612 term_setwidth(p
, n
->nchild
? n
->child
->string
: NULL
);
617 termp_it_pre(DECL_ARGS
)
619 const struct mdoc_node
*bl
, *nn
;
622 size_t width
, offset
, ncols
, dcol
;
625 if (MDOC_BLOCK
== n
->type
) {
626 print_bvspace(p
, n
->parent
->parent
, n
);
630 bl
= n
->parent
->parent
->parent
;
631 type
= bl
->norm
->Bl
.type
;
634 * First calculate width and offset. This is pretty easy unless
635 * we're a -column list, in which case all prior columns must
641 if (bl
->norm
->Bl
.offs
)
642 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
646 if (MDOC_HEAD
== n
->type
)
650 * Imitate groff's column handling:
651 * - For each earlier column, add its width.
652 * - For less than 5 columns, add four more blanks per
654 * - For exactly 5 columns, add three more blank per
656 * - For more than 5 columns, add only one column.
658 ncols
= bl
->norm
->Bl
.ncols
;
659 dcol
= ncols
< 5 ? term_len(p
, 4) :
660 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
663 * Calculate the offset by applying all prior MDOC_BODY,
664 * so we stop at the MDOC_HEAD (NULL == nn->prev).
667 for (i
= 0, nn
= n
->prev
;
668 nn
->prev
&& i
< (int)ncols
;
670 offset
+= dcol
+ a2width(p
,
671 bl
->norm
->Bl
.cols
[i
]);
674 * When exceeding the declared number of columns, leave
675 * the remaining widths at 0. This will later be
676 * adjusted to the default width of 10, or, for the last
677 * column, stretched to the right margin.
683 * Use the declared column widths, extended as explained
684 * in the preceding paragraph.
686 width
= a2width(p
, bl
->norm
->Bl
.cols
[i
]) + dcol
;
689 if (NULL
== bl
->norm
->Bl
.width
)
693 * Note: buffer the width by 2, which is groff's magic
694 * number for buffering single arguments. See the above
695 * handling for column for how this changes.
697 assert(bl
->norm
->Bl
.width
);
698 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
703 * List-type can override the width in the case of fixed-head
704 * values (bullet, dash/hyphen, enum). Tags need a non-zero
716 if (width
< term_len(p
, 2))
717 width
= term_len(p
, 2);
721 width
= term_len(p
, 8);
727 width
= term_len(p
, 10);
734 * Whitespace control. Inset bodies need an initial space,
735 * while diagonal bodies need two.
738 p
->flags
|= TERMP_NOSPACE
;
742 if (MDOC_BODY
== n
->type
)
743 term_word(p
, "\\ \\ ");
746 if (MDOC_BODY
== n
->type
&& n
->parent
->head
->nchild
)
753 p
->flags
|= TERMP_NOSPACE
;
757 if (MDOC_HEAD
== n
->type
)
758 term_fontpush(p
, TERMFONT_BOLD
);
765 * Pad and break control. This is the tricky part. These flags
766 * are documented in term_flushln() in term.c. Note that we're
767 * going to unset all of these flags in termp_it_post() when we
774 * Weird special case.
775 * Very narrow enum lists actually hang.
777 if (width
== term_len(p
, 2))
778 p
->flags
|= TERMP_HANG
;
785 if (MDOC_HEAD
!= n
->type
)
787 p
->flags
|= TERMP_NOBREAK
;
791 if (MDOC_HEAD
!= n
->type
)
795 * This is ugly. If `-hang' is specified and the body
796 * is a `Bl' or `Bd', then we want basically to nullify
797 * the "overstep" effect in term_flushln() and treat
798 * this as a `-ohang' list instead.
800 if (NULL
!= n
->next
&&
801 NULL
!= n
->next
->child
&&
802 (MDOC_Bl
== n
->next
->child
->tok
||
803 MDOC_Bd
== n
->next
->child
->tok
))
806 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
810 if (MDOC_HEAD
!= n
->type
)
813 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
816 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
817 p
->flags
|= TERMP_DANGLE
;
820 if (MDOC_HEAD
== n
->type
)
823 if (NULL
== n
->next
) {
824 p
->flags
&= ~TERMP_NOBREAK
;
827 p
->flags
|= TERMP_NOBREAK
;
833 if (MDOC_HEAD
!= n
->type
)
835 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
843 * Margin control. Set-head-width lists have their right
844 * margins shortened. The body for these lists has the offset
845 * necessarily lengthened. Everybody gets the offset.
853 * Same stipulation as above, regarding `-hang'. We
854 * don't want to recalculate rmargin and offsets when
855 * using `Bd' or `Bl' within `-hang' overstep lists.
857 if (MDOC_HEAD
== n
->type
&&
859 NULL
!= n
->next
->child
&&
860 (MDOC_Bl
== n
->next
->child
->tok
||
861 MDOC_Bd
== n
->next
->child
->tok
))
874 if (MDOC_HEAD
== n
->type
)
875 p
->rmargin
= p
->offset
+ width
;
878 if (p
->rmargin
< p
->offset
)
879 p
->rmargin
= p
->offset
;
884 p
->rmargin
= p
->offset
+ width
;
886 * XXX - this behaviour is not documented: the
887 * right-most column is filled to the right margin.
889 if (MDOC_HEAD
== n
->type
)
891 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
892 p
->rmargin
= p
->maxrmargin
;
899 * The dash, hyphen, bullet and enum lists all have a special
900 * HEAD character (temporarily bold, in some cases).
903 if (MDOC_HEAD
== n
->type
)
906 term_fontpush(p
, TERMFONT_BOLD
);
907 term_word(p
, "\\[bu]");
913 term_fontpush(p
, TERMFONT_BOLD
);
914 term_word(p
, "\\(hy");
918 (pair
->ppair
->ppair
->count
)++;
919 (void)snprintf(buf
, sizeof(buf
), "%d.",
920 pair
->ppair
->ppair
->count
);
928 * If we're not going to process our children, indicate so here.
941 if (MDOC_HEAD
== n
->type
)
945 if (MDOC_HEAD
== n
->type
)
956 termp_it_post(DECL_ARGS
)
960 if (MDOC_BLOCK
== n
->type
)
963 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
971 if (MDOC_BODY
== n
->type
)
975 if (MDOC_BODY
== n
->type
)
984 * Now that our output is flushed, we can reset our tags. Since
985 * only `It' sets these flags, we're free to assume that nobody
986 * has munged them in the meanwhile.
989 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
990 TERMP_DANGLE
| TERMP_HANG
);
995 termp_nm_pre(DECL_ARGS
)
998 if (MDOC_BLOCK
== n
->type
) {
999 p
->flags
|= TERMP_PREKEEP
;
1003 if (MDOC_BODY
== n
->type
) {
1004 if (NULL
== n
->child
)
1006 p
->flags
|= TERMP_NOSPACE
;
1007 p
->offset
+= term_len(p
, 1) +
1008 (NULL
== n
->prev
->child
?
1009 term_strlen(p
, meta
->name
) :
1010 MDOC_TEXT
== n
->prev
->child
->type
?
1011 term_strlen(p
, n
->prev
->child
->string
) :
1013 if (p
->rmargin
< p
->offset
)
1014 p
->rmargin
= p
->offset
;
1018 if (NULL
== n
->child
&& NULL
== meta
->name
)
1021 if (MDOC_HEAD
== n
->type
)
1022 synopsis_pre(p
, n
->parent
);
1024 if (MDOC_HEAD
== n
->type
&&
1025 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1026 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1028 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1029 if (NULL
== n
->child
) {
1030 p
->rmargin
+= term_strlen(p
, meta
->name
);
1031 } else if (MDOC_TEXT
== n
->child
->type
) {
1032 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1034 p
->flags
|= TERMP_HANG
;
1036 p
->rmargin
+= term_len(p
, 5);
1037 p
->flags
|= TERMP_HANG
;
1041 term_fontpush(p
, TERMFONT_BOLD
);
1042 if (NULL
== n
->child
)
1043 term_word(p
, meta
->name
);
1048 termp_nm_post(DECL_ARGS
)
1051 if (MDOC_BLOCK
== n
->type
) {
1052 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1053 } else if (MDOC_HEAD
== n
->type
&&
1054 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1056 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1058 } else if (MDOC_BODY
== n
->type
&& n
->child
)
1063 termp_fl_pre(DECL_ARGS
)
1066 term_fontpush(p
, TERMFONT_BOLD
);
1067 term_word(p
, "\\-");
1069 if ( ! (n
->nchild
== 0 &&
1071 n
->next
->type
== MDOC_TEXT
||
1072 n
->next
->flags
& MDOC_LINE
)))
1073 p
->flags
|= TERMP_NOSPACE
;
1079 termp__a_pre(DECL_ARGS
)
1082 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1083 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1084 term_word(p
, "and");
1090 termp_an_pre(DECL_ARGS
)
1093 if (n
->norm
->An
.auth
== AUTH_split
) {
1094 p
->flags
&= ~TERMP_NOSPLIT
;
1095 p
->flags
|= TERMP_SPLIT
;
1098 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1099 p
->flags
&= ~TERMP_SPLIT
;
1100 p
->flags
|= TERMP_NOSPLIT
;
1104 if (n
->child
== NULL
)
1107 if (p
->flags
& TERMP_SPLIT
)
1110 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1111 p
->flags
|= TERMP_SPLIT
;
1117 termp_ns_pre(DECL_ARGS
)
1120 if ( ! (MDOC_LINE
& n
->flags
))
1121 p
->flags
|= TERMP_NOSPACE
;
1126 termp_rs_pre(DECL_ARGS
)
1129 if (SEC_SEE_ALSO
!= n
->sec
)
1131 if (MDOC_BLOCK
== n
->type
&& n
->prev
)
1137 termp_rv_pre(DECL_ARGS
)
1145 term_word(p
, "The");
1147 for (n
= n
->child
; n
; n
= n
->next
) {
1148 term_fontpush(p
, TERMFONT_BOLD
);
1149 term_word(p
, n
->string
);
1152 p
->flags
|= TERMP_NOSPACE
;
1155 if (n
->next
== NULL
)
1159 p
->flags
|= TERMP_NOSPACE
;
1162 if (n
->next
->next
== NULL
)
1163 term_word(p
, "and");
1167 term_word(p
, "functions return");
1169 term_word(p
, "function returns");
1171 term_word(p
, "the value\\~0 if successful;");
1173 term_word(p
, "Upon successful completion,"
1174 " the value\\~0 is returned;");
1176 term_word(p
, "otherwise the value\\~\\-1 is returned"
1177 " and the global variable");
1179 term_fontpush(p
, TERMFONT_UNDER
);
1180 term_word(p
, "errno");
1183 term_word(p
, "is set to indicate the error.");
1184 p
->flags
|= TERMP_SENTENCE
;
1190 termp_ex_pre(DECL_ARGS
)
1195 term_word(p
, "The");
1198 for (n
= n
->child
; n
; n
= n
->next
) {
1199 term_fontpush(p
, TERMFONT_BOLD
);
1200 term_word(p
, n
->string
);
1203 if (nchild
> 2 && n
->next
) {
1204 p
->flags
|= TERMP_NOSPACE
;
1208 if (n
->next
&& NULL
== n
->next
->next
)
1209 term_word(p
, "and");
1213 term_word(p
, "utilities exit\\~0");
1215 term_word(p
, "utility exits\\~0");
1217 term_word(p
, "on success, and\\~>0 if an error occurs.");
1219 p
->flags
|= TERMP_SENTENCE
;
1224 termp_nd_pre(DECL_ARGS
)
1227 if (MDOC_BODY
!= n
->type
)
1230 #if defined(__OpenBSD__) || defined(__linux__)
1231 term_word(p
, "\\(en");
1233 term_word(p
, "\\(em");
1239 termp_bl_pre(DECL_ARGS
)
1242 return(MDOC_HEAD
!= n
->type
);
1246 termp_bl_post(DECL_ARGS
)
1249 if (MDOC_BLOCK
== n
->type
)
1254 termp_xr_pre(DECL_ARGS
)
1257 if (NULL
== (n
= n
->child
))
1260 assert(MDOC_TEXT
== n
->type
);
1261 term_word(p
, n
->string
);
1263 if (NULL
== (n
= n
->next
))
1266 p
->flags
|= TERMP_NOSPACE
;
1268 p
->flags
|= TERMP_NOSPACE
;
1270 assert(MDOC_TEXT
== n
->type
);
1271 term_word(p
, n
->string
);
1273 p
->flags
|= TERMP_NOSPACE
;
1280 * This decides how to assert whitespace before any of the SYNOPSIS set
1281 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1285 synopsis_pre(struct termp
*p
, const struct mdoc_node
*n
)
1288 * Obviously, if we're not in a SYNOPSIS or no prior macros
1289 * exist, do nothing.
1291 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1295 * If we're the second in a pair of like elements, emit our
1296 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1297 * case we soldier on.
1299 if (n
->prev
->tok
== n
->tok
&&
1300 MDOC_Ft
!= n
->tok
&&
1301 MDOC_Fo
!= n
->tok
&&
1302 MDOC_Fn
!= n
->tok
) {
1308 * If we're one of the SYNOPSIS set and non-like pair-wise after
1309 * another (or Fn/Fo, which we've let slip through) then assert
1310 * vertical space, else only newline and move on.
1312 switch (n
->prev
->tok
) {
1325 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1337 termp_vt_pre(DECL_ARGS
)
1340 if (MDOC_ELEM
== n
->type
) {
1342 return(termp_under_pre(p
, pair
, meta
, n
));
1343 } else if (MDOC_BLOCK
== n
->type
) {
1346 } else if (MDOC_HEAD
== n
->type
)
1349 return(termp_under_pre(p
, pair
, meta
, n
));
1353 termp_bold_pre(DECL_ARGS
)
1356 term_fontpush(p
, TERMFONT_BOLD
);
1361 termp_fd_pre(DECL_ARGS
)
1365 return(termp_bold_pre(p
, pair
, meta
, n
));
1369 termp_fd_post(DECL_ARGS
)
1376 termp_sh_pre(DECL_ARGS
)
1379 /* No vspace between consecutive `Sh' calls. */
1383 if (n
->prev
&& MDOC_Sh
== n
->prev
->tok
)
1384 if (NULL
== n
->prev
->body
->child
)
1389 term_fontpush(p
, TERMFONT_BOLD
);
1392 p
->offset
= term_len(p
, p
->defindent
);
1393 if (SEC_AUTHORS
== n
->sec
)
1394 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1403 termp_sh_post(DECL_ARGS
)
1420 termp_bt_pre(DECL_ARGS
)
1423 term_word(p
, "is currently in beta test.");
1424 p
->flags
|= TERMP_SENTENCE
;
1429 termp_lb_post(DECL_ARGS
)
1432 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1437 termp_ud_pre(DECL_ARGS
)
1440 term_word(p
, "currently under development.");
1441 p
->flags
|= TERMP_SENTENCE
;
1446 termp_d1_pre(DECL_ARGS
)
1449 if (MDOC_BLOCK
!= n
->type
)
1452 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1457 termp_ft_pre(DECL_ARGS
)
1460 /* NB: MDOC_LINE does not effect this! */
1462 term_fontpush(p
, TERMFONT_UNDER
);
1467 termp_fn_pre(DECL_ARGS
)
1472 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1476 if (NULL
== (n
= n
->child
))
1480 rmargin
= p
->rmargin
;
1481 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1482 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1485 assert(MDOC_TEXT
== n
->type
);
1486 term_fontpush(p
, TERMFONT_BOLD
);
1487 term_word(p
, n
->string
);
1492 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1493 p
->offset
= p
->rmargin
;
1494 p
->rmargin
= rmargin
;
1497 p
->flags
|= TERMP_NOSPACE
;
1499 p
->flags
|= TERMP_NOSPACE
;
1501 for (n
= n
->next
; n
; n
= n
->next
) {
1502 assert(MDOC_TEXT
== n
->type
);
1503 term_fontpush(p
, TERMFONT_UNDER
);
1505 p
->flags
|= TERMP_NBRWORD
;
1506 term_word(p
, n
->string
);
1510 p
->flags
|= TERMP_NOSPACE
;
1515 p
->flags
|= TERMP_NOSPACE
;
1519 p
->flags
|= TERMP_NOSPACE
;
1528 termp_fa_pre(DECL_ARGS
)
1530 const struct mdoc_node
*nn
;
1532 if (n
->parent
->tok
!= MDOC_Fo
) {
1533 term_fontpush(p
, TERMFONT_UNDER
);
1537 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1538 term_fontpush(p
, TERMFONT_UNDER
);
1539 p
->flags
|= TERMP_NBRWORD
;
1540 term_word(p
, nn
->string
);
1543 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1544 p
->flags
|= TERMP_NOSPACE
;
1553 termp_bd_pre(DECL_ARGS
)
1555 size_t tabwidth
, lm
, len
, rm
, rmax
;
1556 struct mdoc_node
*nn
;
1558 if (MDOC_BLOCK
== n
->type
) {
1559 print_bvspace(p
, n
, n
);
1561 } else if (MDOC_HEAD
== n
->type
)
1564 /* Handle the -offset argument. */
1566 if (n
->norm
->Bd
.offs
== NULL
||
1567 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1569 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1570 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1571 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1572 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1574 p
->offset
+= a2width(p
, n
->norm
->Bd
.offs
);
1577 * If -ragged or -filled are specified, the block does nothing
1578 * but change the indentation. If -unfilled or -literal are
1579 * specified, text is printed exactly as entered in the display:
1580 * for macro lines, a newline is appended to the line. Blank
1581 * lines are allowed.
1584 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1585 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1586 DISP_centered
!= n
->norm
->Bd
.type
)
1589 tabwidth
= p
->tabwidth
;
1590 if (DISP_literal
== n
->norm
->Bd
.type
)
1591 p
->tabwidth
= term_len(p
, 8);
1595 rmax
= p
->maxrmargin
;
1596 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1598 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1599 if (DISP_centered
== n
->norm
->Bd
.type
) {
1600 if (MDOC_TEXT
== nn
->type
) {
1601 len
= term_strlen(p
, nn
->string
);
1602 p
->offset
= len
>= rm
? 0 :
1603 lm
+ len
>= rm
? rm
- len
:
1604 (lm
+ rm
- len
) / 2;
1608 print_mdoc_node(p
, pair
, meta
, nn
);
1610 * If the printed node flushes its own line, then we
1611 * needn't do it here as well. This is hacky, but the
1612 * notion of selective eoln whitespace is pretty dumb
1613 * anyway, so don't sweat it.
1635 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1638 p
->flags
|= TERMP_NOSPACE
;
1641 p
->tabwidth
= tabwidth
;
1643 p
->maxrmargin
= rmax
;
1648 termp_bd_post(DECL_ARGS
)
1652 if (MDOC_BODY
!= n
->type
)
1656 rmax
= p
->maxrmargin
;
1658 if (DISP_literal
== n
->norm
->Bd
.type
||
1659 DISP_unfilled
== n
->norm
->Bd
.type
)
1660 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1662 p
->flags
|= TERMP_NOSPACE
;
1666 p
->maxrmargin
= rmax
;
1670 termp_bx_pre(DECL_ARGS
)
1673 if (NULL
!= (n
= n
->child
)) {
1674 term_word(p
, n
->string
);
1675 p
->flags
|= TERMP_NOSPACE
;
1676 term_word(p
, "BSD");
1678 term_word(p
, "BSD");
1682 if (NULL
!= (n
= n
->next
)) {
1683 p
->flags
|= TERMP_NOSPACE
;
1685 p
->flags
|= TERMP_NOSPACE
;
1686 term_word(p
, n
->string
);
1693 termp_xx_pre(DECL_ARGS
)
1726 p
->flags
|= TERMP_KEEP
;
1727 term_word(p
, n
->child
->string
);
1734 termp_pf_post(DECL_ARGS
)
1737 p
->flags
|= TERMP_NOSPACE
;
1741 termp_ss_pre(DECL_ARGS
)
1751 term_fontpush(p
, TERMFONT_BOLD
);
1752 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1755 p
->offset
= term_len(p
, p
->defindent
);
1765 termp_ss_post(DECL_ARGS
)
1768 if (n
->type
== MDOC_HEAD
|| n
->type
== MDOC_BODY
)
1773 termp_cd_pre(DECL_ARGS
)
1777 term_fontpush(p
, TERMFONT_BOLD
);
1782 termp_in_pre(DECL_ARGS
)
1787 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1788 term_fontpush(p
, TERMFONT_BOLD
);
1789 term_word(p
, "#include");
1793 term_fontpush(p
, TERMFONT_UNDER
);
1796 p
->flags
|= TERMP_NOSPACE
;
1801 termp_in_post(DECL_ARGS
)
1804 if (MDOC_SYNPRETTY
& n
->flags
)
1805 term_fontpush(p
, TERMFONT_BOLD
);
1807 p
->flags
|= TERMP_NOSPACE
;
1810 if (MDOC_SYNPRETTY
& n
->flags
)
1815 termp_sp_pre(DECL_ARGS
)
1821 len
= n
->child
? a2height(p
, n
->child
->string
) : 1;
1833 for (i
= 0; i
< len
; i
++)
1840 termp_es_pre(DECL_ARGS
)
1847 termp_quote_pre(DECL_ARGS
)
1850 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1876 term_word(p
, "\\(lq");
1879 if (NULL
== n
->norm
->Es
||
1880 NULL
== n
->norm
->Es
->child
)
1882 term_word(p
, n
->norm
->Es
->child
->string
);
1903 term_word(p
, "\\(oq");
1910 p
->flags
|= TERMP_NOSPACE
;
1915 termp_quote_post(DECL_ARGS
)
1918 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1921 if (MDOC_En
!= n
->tok
)
1922 p
->flags
|= TERMP_NOSPACE
;
1947 term_word(p
, "\\(rq");
1950 if (NULL
!= n
->norm
->Es
&&
1951 NULL
!= n
->norm
->Es
->child
&&
1952 NULL
!= n
->norm
->Es
->child
->next
) {
1953 p
->flags
|= TERMP_NOSPACE
;
1954 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1976 term_word(p
, "\\(cq");
1985 termp_fo_pre(DECL_ARGS
)
1990 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1992 if (MDOC_BLOCK
== n
->type
) {
1995 } else if (MDOC_BODY
== n
->type
) {
1997 rmargin
= p
->rmargin
;
1998 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1999 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
2002 p
->flags
|= TERMP_NOSPACE
;
2004 p
->flags
|= TERMP_NOSPACE
;
2007 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2009 p
->offset
= p
->rmargin
;
2010 p
->rmargin
= rmargin
;
2015 if (NULL
== n
->child
)
2018 /* XXX: we drop non-initial arguments as per groff. */
2020 assert(n
->child
->string
);
2021 term_fontpush(p
, TERMFONT_BOLD
);
2022 term_word(p
, n
->child
->string
);
2027 termp_fo_post(DECL_ARGS
)
2030 if (MDOC_BODY
!= n
->type
)
2033 p
->flags
|= TERMP_NOSPACE
;
2036 if (MDOC_SYNPRETTY
& n
->flags
) {
2037 p
->flags
|= TERMP_NOSPACE
;
2044 termp_bf_pre(DECL_ARGS
)
2047 if (MDOC_HEAD
== n
->type
)
2049 else if (MDOC_BODY
!= n
->type
)
2052 if (FONT_Em
== n
->norm
->Bf
.font
)
2053 term_fontpush(p
, TERMFONT_UNDER
);
2054 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2055 term_fontpush(p
, TERMFONT_BOLD
);
2057 term_fontpush(p
, TERMFONT_NONE
);
2063 termp_sm_pre(DECL_ARGS
)
2066 if (NULL
== n
->child
)
2067 p
->flags
^= TERMP_NONOSPACE
;
2068 else if (0 == strcmp("on", n
->child
->string
))
2069 p
->flags
&= ~TERMP_NONOSPACE
;
2071 p
->flags
|= TERMP_NONOSPACE
;
2073 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2074 p
->flags
&= ~TERMP_NOSPACE
;
2080 termp_ap_pre(DECL_ARGS
)
2083 p
->flags
|= TERMP_NOSPACE
;
2085 p
->flags
|= TERMP_NOSPACE
;
2090 termp____post(DECL_ARGS
)
2094 * Handle lists of authors. In general, print each followed by
2095 * a comma. Don't print the comma if there are only two
2098 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2099 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2100 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2105 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2108 p
->flags
|= TERMP_NOSPACE
;
2109 if (NULL
== n
->next
) {
2111 p
->flags
|= TERMP_SENTENCE
;
2117 termp_li_pre(DECL_ARGS
)
2120 term_fontpush(p
, TERMFONT_NONE
);
2125 termp_lk_pre(DECL_ARGS
)
2127 const struct mdoc_node
*link
, *descr
;
2129 if (NULL
== (link
= n
->child
))
2132 if (NULL
!= (descr
= link
->next
)) {
2133 term_fontpush(p
, TERMFONT_UNDER
);
2134 while (NULL
!= descr
) {
2135 term_word(p
, descr
->string
);
2136 descr
= descr
->next
;
2138 p
->flags
|= TERMP_NOSPACE
;
2143 term_fontpush(p
, TERMFONT_BOLD
);
2144 term_word(p
, link
->string
);
2151 termp_bk_pre(DECL_ARGS
)
2160 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2161 p
->flags
|= TERMP_PREKEEP
;
2172 termp_bk_post(DECL_ARGS
)
2175 if (MDOC_BODY
== n
->type
)
2176 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2180 termp__t_post(DECL_ARGS
)
2184 * If we're in an `Rs' and there's a journal present, then quote
2185 * us instead of underlining us (for disambiguation).
2187 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2188 n
->parent
->norm
->Rs
.quote_T
)
2189 termp_quote_post(p
, pair
, meta
, n
);
2191 termp____post(p
, pair
, meta
, n
);
2195 termp__t_pre(DECL_ARGS
)
2199 * If we're in an `Rs' and there's a journal present, then quote
2200 * us instead of underlining us (for disambiguation).
2202 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2203 n
->parent
->norm
->Rs
.quote_T
)
2204 return(termp_quote_pre(p
, pair
, meta
, n
));
2206 term_fontpush(p
, TERMFONT_UNDER
);
2211 termp_under_pre(DECL_ARGS
)
2214 term_fontpush(p
, TERMFONT_UNDER
);