1 /* $Id: mdoc_term.c,v 1.379 2020/03/13 15:32:28 schwarze Exp $ */
3 * Copyright (c) 2010, 2012-2020 Ingo Schwarze <schwarze@openbsd.org>
4 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
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 AUTHORS DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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.
19 * Plain text formatter for mdoc(7), used by mandoc(1)
20 * for ASCII, UTF-8, PostScript, and PDF output.
24 #include <sys/types.h>
34 #include "mandoc_aux.h"
43 struct termpair
*ppair
;
47 #define DECL_ARGS struct termp *p, \
48 struct termpair *pair, \
49 const struct roff_meta *meta, \
52 struct mdoc_term_act
{
53 int (*pre
)(DECL_ARGS
);
54 void (*post
)(DECL_ARGS
);
57 static int a2width(const struct termp
*, const char *);
59 static void print_bvspace(struct termp
*,
60 struct roff_node
*, struct roff_node
*);
61 static void print_mdoc_node(DECL_ARGS
);
62 static void print_mdoc_nodelist(DECL_ARGS
);
63 static void print_mdoc_head(struct termp
*, const struct roff_meta
*);
64 static void print_mdoc_foot(struct termp
*, const struct roff_meta
*);
65 static void synopsis_pre(struct termp
*, struct roff_node
*);
67 static void termp____post(DECL_ARGS
);
68 static void termp__t_post(DECL_ARGS
);
69 static void termp_bd_post(DECL_ARGS
);
70 static void termp_bk_post(DECL_ARGS
);
71 static void termp_bl_post(DECL_ARGS
);
72 static void termp_eo_post(DECL_ARGS
);
73 static void termp_fd_post(DECL_ARGS
);
74 static void termp_fo_post(DECL_ARGS
);
75 static void termp_in_post(DECL_ARGS
);
76 static void termp_it_post(DECL_ARGS
);
77 static void termp_lb_post(DECL_ARGS
);
78 static void termp_nm_post(DECL_ARGS
);
79 static void termp_pf_post(DECL_ARGS
);
80 static void termp_quote_post(DECL_ARGS
);
81 static void termp_sh_post(DECL_ARGS
);
82 static void termp_ss_post(DECL_ARGS
);
83 static void termp_xx_post(DECL_ARGS
);
85 static int termp__a_pre(DECL_ARGS
);
86 static int termp__t_pre(DECL_ARGS
);
87 static int termp_abort_pre(DECL_ARGS
);
88 static int termp_an_pre(DECL_ARGS
);
89 static int termp_ap_pre(DECL_ARGS
);
90 static int termp_bd_pre(DECL_ARGS
);
91 static int termp_bf_pre(DECL_ARGS
);
92 static int termp_bk_pre(DECL_ARGS
);
93 static int termp_bl_pre(DECL_ARGS
);
94 static int termp_bold_pre(DECL_ARGS
);
95 static int termp_d1_pre(DECL_ARGS
);
96 static int termp_eo_pre(DECL_ARGS
);
97 static int termp_ex_pre(DECL_ARGS
);
98 static int termp_fa_pre(DECL_ARGS
);
99 static int termp_fd_pre(DECL_ARGS
);
100 static int termp_fl_pre(DECL_ARGS
);
101 static int termp_fn_pre(DECL_ARGS
);
102 static int termp_fo_pre(DECL_ARGS
);
103 static int termp_ft_pre(DECL_ARGS
);
104 static int termp_in_pre(DECL_ARGS
);
105 static int termp_it_pre(DECL_ARGS
);
106 static int termp_li_pre(DECL_ARGS
);
107 static int termp_lk_pre(DECL_ARGS
);
108 static int termp_nd_pre(DECL_ARGS
);
109 static int termp_nm_pre(DECL_ARGS
);
110 static int termp_ns_pre(DECL_ARGS
);
111 static int termp_quote_pre(DECL_ARGS
);
112 static int termp_rs_pre(DECL_ARGS
);
113 static int termp_sh_pre(DECL_ARGS
);
114 static int termp_skip_pre(DECL_ARGS
);
115 static int termp_sm_pre(DECL_ARGS
);
116 static int termp_pp_pre(DECL_ARGS
);
117 static int termp_ss_pre(DECL_ARGS
);
118 static int termp_under_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 mdoc_term_act mdoc_term_acts
[MDOC_MAX
- MDOC_Dd
] = {
124 { NULL
, NULL
}, /* Dd */
125 { NULL
, NULL
}, /* Dt */
126 { NULL
, NULL
}, /* Os */
127 { termp_sh_pre
, termp_sh_post
}, /* Sh */
128 { termp_ss_pre
, termp_ss_post
}, /* Ss */
129 { termp_pp_pre
, NULL
}, /* Pp */
130 { termp_d1_pre
, termp_bl_post
}, /* D1 */
131 { termp_d1_pre
, termp_bl_post
}, /* Dl */
132 { termp_bd_pre
, termp_bd_post
}, /* Bd */
133 { NULL
, NULL
}, /* Ed */
134 { termp_bl_pre
, termp_bl_post
}, /* Bl */
135 { NULL
, NULL
}, /* El */
136 { termp_it_pre
, termp_it_post
}, /* It */
137 { termp_under_pre
, NULL
}, /* Ad */
138 { termp_an_pre
, NULL
}, /* An */
139 { termp_ap_pre
, NULL
}, /* Ap */
140 { termp_under_pre
, NULL
}, /* Ar */
141 { termp_fd_pre
, NULL
}, /* Cd */
142 { termp_bold_pre
, NULL
}, /* Cm */
143 { termp_li_pre
, 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_abort_pre
, NULL
}, /* Ot */
159 { termp_under_pre
, NULL
}, /* Pa */
160 { termp_ex_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
, termp_xx_post
}, /* Bsx */
185 { NULL
, NULL
}, /* Bx */
186 { termp_skip_pre
, 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_eo_pre
, termp_eo_post
}, /* Eo */
194 { termp_xx_pre
, termp_xx_post
}, /* Fx */
195 { termp_bold_pre
, NULL
}, /* Ms */
196 { termp_li_pre
, NULL
}, /* No */
197 { termp_ns_pre
, NULL
}, /* Ns */
198 { termp_xx_pre
, termp_xx_post
}, /* Nx */
199 { termp_xx_pre
, termp_xx_post
}, /* 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
, termp_xx_post
}, /* 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 { NULL
, NULL
}, /* Bt */
227 { NULL
, NULL
}, /* Hf */
228 { termp_under_pre
, NULL
}, /* Fr */
229 { NULL
, NULL
}, /* Ud */
230 { NULL
, termp_lb_post
}, /* Lb */
231 { termp_abort_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_skip_pre
, NULL
}, /* Es */
239 { termp_quote_pre
, termp_quote_post
}, /* En */
240 { termp_xx_pre
, termp_xx_post
}, /* Dx */
241 { NULL
, termp____post
}, /* %Q */
242 { NULL
, termp____post
}, /* %U */
243 { NULL
, NULL
}, /* Ta */
244 { termp_skip_pre
, NULL
}, /* Tg */
249 terminal_mdoc(void *arg
, const struct roff_meta
*mdoc
)
251 struct roff_node
*n
, *nn
;
253 size_t save_defindent
;
255 p
= (struct termp
*)arg
;
256 p
->tcol
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
257 term_tab_set(p
, NULL
);
258 term_tab_set(p
, "T");
259 term_tab_set(p
, ".5i");
261 n
= mdoc
->first
->child
;
262 if (p
->synopsisonly
) {
263 for (nn
= NULL
; n
!= NULL
; n
= n
->next
) {
264 if (n
->tok
!= MDOC_Sh
)
266 if (n
->sec
== SEC_SYNOPSIS
)
268 if (nn
== NULL
&& n
->sec
== SEC_NAME
)
273 p
->flags
|= TERMP_NOSPACE
;
274 if (n
!= NULL
&& (n
= n
->child
->next
->child
) != NULL
)
275 print_mdoc_nodelist(p
, NULL
, mdoc
, n
);
278 save_defindent
= p
->defindent
;
279 if (p
->defindent
== 0)
281 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, mdoc
);
283 (n
->type
== ROFFT_COMMENT
||
284 n
->flags
& NODE_NOPRT
))
287 if (n
->tok
!= MDOC_Sh
)
289 print_mdoc_nodelist(p
, NULL
, mdoc
, n
);
292 p
->defindent
= save_defindent
;
297 print_mdoc_nodelist(DECL_ARGS
)
300 print_mdoc_node(p
, pair
, meta
, n
);
306 print_mdoc_node(DECL_ARGS
)
308 const struct mdoc_term_act
*act
;
309 struct termpair npair
;
310 size_t offset
, rmargin
;
314 * In no-fill mode, break the output line at the beginning
315 * of new input lines except after \c, and nowhere else.
318 if (n
->flags
& NODE_NOFILL
) {
319 if (n
->flags
& NODE_LINE
&&
320 (p
->flags
& TERMP_NONEWLINE
) == 0)
322 p
->flags
|= TERMP_BRNEVER
;
324 p
->flags
&= ~TERMP_BRNEVER
;
326 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
330 offset
= p
->tcol
->offset
;
331 rmargin
= p
->tcol
->rmargin
;
332 n
->flags
&= ~NODE_ENDED
;
333 n
->prev_font
= p
->fonti
;
335 memset(&npair
, 0, sizeof(struct termpair
));
338 if (n
->flags
& NODE_ID
)
339 term_tag_write(n
, p
->line
);
342 * Keeps only work until the end of a line. If a keep was
343 * invoked in a prior line, revert it to PREKEEP.
346 if (p
->flags
& TERMP_KEEP
&& n
->flags
& NODE_LINE
) {
347 p
->flags
&= ~TERMP_KEEP
;
348 p
->flags
|= TERMP_PREKEEP
;
352 * After the keep flags have been set up, we may now
353 * produce output. Note that some pre-handlers do so.
359 if (n
->flags
& NODE_LINE
) {
360 switch (*n
->string
) {
362 if (p
->flags
& TERMP_NONEWLINE
)
368 if ((p
->flags
& TERMP_NONEWLINE
) == 0)
375 if (NODE_DELIMC
& n
->flags
)
376 p
->flags
|= TERMP_NOSPACE
;
377 term_word(p
, n
->string
);
378 if (NODE_DELIMO
& n
->flags
)
379 p
->flags
|= TERMP_NOSPACE
;
382 if ( ! (n
->flags
& NODE_LINE
))
383 p
->flags
|= TERMP_NOSPACE
;
385 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
386 p
->flags
|= TERMP_NOSPACE
;
389 if (p
->tbl
.cols
== NULL
)
391 term_tbl(p
, n
->span
);
394 if (n
->tok
< ROFF_MAX
) {
398 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
399 act
= mdoc_term_acts
+ (n
->tok
- MDOC_Dd
);
400 if (act
->pre
!= NULL
&&
401 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
402 chld
= (*act
->pre
)(p
, &npair
, meta
, n
);
406 if (chld
&& n
->child
)
407 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
410 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
420 if (act
->post
== NULL
|| n
->flags
& NODE_ENDED
)
422 (void)(*act
->post
)(p
, &npair
, meta
, n
);
425 * Explicit end tokens not only call the post
426 * handler, but also tell the respective block
427 * that it must not call the post handler again.
429 if (ENDBODY_NOT
!= n
->end
)
430 n
->body
->flags
|= NODE_ENDED
;
434 if (NODE_EOS
& n
->flags
)
435 p
->flags
|= TERMP_SENTENCE
;
437 if (n
->type
!= ROFFT_TEXT
)
438 p
->tcol
->offset
= offset
;
439 p
->tcol
->rmargin
= rmargin
;
443 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
447 term_fontrepl(p
, TERMFONT_NONE
);
450 * Output the footer in new-groff style, that is, three columns
451 * with the middle being the manual date and flanking columns
452 * being the operating system:
460 sz
= term_strlen(p
, meta
->date
);
461 p
->tcol
->rmargin
= p
->maxrmargin
> sz
?
462 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
464 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
466 term_word(p
, meta
->os
);
469 p
->tcol
->offset
= p
->tcol
->rmargin
;
470 sz
= term_strlen(p
, meta
->os
);
471 p
->tcol
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
472 p
->flags
|= TERMP_NOSPACE
;
474 term_word(p
, meta
->date
);
477 p
->tcol
->offset
= p
->tcol
->rmargin
;
478 p
->tcol
->rmargin
= p
->maxrmargin
;
480 p
->flags
&= ~TERMP_NOBREAK
;
481 p
->flags
|= TERMP_NOSPACE
;
483 term_word(p
, meta
->os
);
487 p
->tcol
->rmargin
= p
->maxrmargin
;
492 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
494 char *volume
, *title
;
495 size_t vollen
, titlen
;
498 * The header is strange. It has three components, which are
499 * really two with the first duplicated. It goes like this:
501 * IDENTIFIER TITLE IDENTIFIER
503 * The IDENTIFIER is NAME(SECTION), which is the command-name
504 * (if given, or "unknown" if not) followed by the manual page
505 * section. These are given in `Dt'. The TITLE is a free-form
506 * string depending on the manual volume. If not specified, it
507 * switches on the manual section.
511 if (NULL
== meta
->arch
)
512 volume
= mandoc_strdup(meta
->vol
);
514 mandoc_asprintf(&volume
, "%s (%s)",
515 meta
->vol
, meta
->arch
);
516 vollen
= term_strlen(p
, volume
);
518 if (NULL
== meta
->msec
)
519 title
= mandoc_strdup(meta
->title
);
521 mandoc_asprintf(&title
, "%s(%s)",
522 meta
->title
, meta
->msec
);
523 titlen
= term_strlen(p
, title
);
525 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
528 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
529 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
530 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
535 p
->flags
|= TERMP_NOSPACE
;
536 p
->tcol
->offset
= p
->tcol
->rmargin
;
537 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
538 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
540 term_word(p
, volume
);
543 p
->flags
&= ~TERMP_NOBREAK
;
545 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
546 p
->flags
|= TERMP_NOSPACE
;
547 p
->tcol
->offset
= p
->tcol
->rmargin
;
548 p
->tcol
->rmargin
= p
->maxrmargin
;
553 p
->flags
&= ~TERMP_NOSPACE
;
555 p
->tcol
->rmargin
= p
->maxrmargin
;
561 a2width(const struct termp
*p
, const char *v
)
566 end
= a2roffsu(v
, &su
, SCALE_MAX
);
567 if (end
== NULL
|| *end
!= '\0') {
568 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
569 su
.scale
/= term_strlen(p
, "0");
571 return term_hen(p
, &su
);
575 * Determine how much space to print out before block elements of `It'
576 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
580 print_bvspace(struct termp
*p
, struct roff_node
*bl
, struct roff_node
*n
)
582 struct roff_node
*nn
;
586 if ((bl
->tok
== MDOC_Bd
&& bl
->norm
->Bd
.comp
) ||
587 (bl
->tok
== MDOC_Bl
&& bl
->norm
->Bl
.comp
))
590 /* Do not vspace directly after Ss/Sh. */
593 while (roff_node_prev(nn
) == NULL
) {
596 if (nn
->type
== ROFFT_ROOT
)
598 } while (nn
->type
!= ROFFT_BLOCK
);
599 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
601 if (nn
->tok
== MDOC_It
&&
602 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
607 * No vertical space after:
608 * items in .Bl -column
609 * items without a body in .Bl -diag
612 if (bl
->tok
!= MDOC_Bl
||
613 n
->prev
== NULL
|| n
->prev
->tok
!= MDOC_It
||
614 (bl
->norm
->Bl
.type
!= LIST_column
&&
615 (bl
->norm
->Bl
.type
!= LIST_diag
||
616 n
->prev
->body
->child
!= NULL
)))
622 termp_it_pre(DECL_ARGS
)
626 const struct roff_node
*bl
, *nn
;
628 int i
, offset
, width
;
631 if (n
->type
== ROFFT_BLOCK
) {
632 print_bvspace(p
, n
->parent
->parent
, n
);
636 bl
= n
->parent
->parent
->parent
;
637 type
= bl
->norm
->Bl
.type
;
640 * Defaults for specific list types.
648 width
= term_len(p
, 2);
652 width
= term_len(p
, 8);
655 width
= term_len(p
, 10);
664 * First calculate width and offset. This is pretty easy unless
665 * we're a -column list, in which case all prior columns must
669 if (bl
->norm
->Bl
.offs
!= NULL
) {
670 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
671 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
672 offset
= -p
->tcol
->offset
;
673 else if (offset
> SHRT_MAX
)
679 if (n
->type
== ROFFT_HEAD
)
683 * Imitate groff's column handling:
684 * - For each earlier column, add its width.
685 * - For less than 5 columns, add four more blanks per
687 * - For exactly 5 columns, add three more blank per
689 * - For more than 5 columns, add only one column.
691 ncols
= bl
->norm
->Bl
.ncols
;
692 dcol
= ncols
< 5 ? term_len(p
, 4) :
693 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
696 * Calculate the offset by applying all prior ROFFT_BODY,
697 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
700 for (i
= 0, nn
= n
->prev
;
701 nn
->prev
&& i
< (int)ncols
;
702 nn
= nn
->prev
, i
++) {
704 term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
705 su
.scale
/= term_strlen(p
, "0");
706 offset
+= term_hen(p
, &su
) + dcol
;
710 * When exceeding the declared number of columns, leave
711 * the remaining widths at 0. This will later be
712 * adjusted to the default width of 10, or, for the last
713 * column, stretched to the right margin.
719 * Use the declared column widths, extended as explained
720 * in the preceding paragraph.
722 SCALE_HS_INIT(&su
, term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
723 su
.scale
/= term_strlen(p
, "0");
724 width
= term_hen(p
, &su
) + dcol
;
727 if (NULL
== bl
->norm
->Bl
.width
)
731 * Note: buffer the width by 2, which is groff's magic
732 * number for buffering single arguments. See the above
733 * handling for column for how this changes.
735 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
736 if (width
< 0 && (size_t)(-width
) > p
->tcol
->offset
)
737 width
= -p
->tcol
->offset
;
738 else if (width
> SHRT_MAX
)
744 * Whitespace control. Inset bodies need an initial space,
745 * while diagonal bodies need two.
748 p
->flags
|= TERMP_NOSPACE
;
752 if (n
->type
== ROFFT_BODY
)
753 term_word(p
, "\\ \\ ");
756 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
763 p
->flags
|= TERMP_NOSPACE
;
767 if (n
->type
== ROFFT_HEAD
)
768 term_fontpush(p
, TERMFONT_BOLD
);
775 * Pad and break control. This is the tricky part. These flags
776 * are documented in term_flushln() in term.c. Note that we're
777 * going to unset all of these flags in termp_it_post() when we
786 if (n
->type
== ROFFT_HEAD
) {
787 p
->flags
|= TERMP_NOBREAK
| TERMP_HANG
;
789 } else if (width
<= (int)term_len(p
, 2))
790 p
->flags
|= TERMP_NOPAD
;
793 if (n
->type
!= ROFFT_HEAD
)
795 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
799 if (n
->type
!= ROFFT_HEAD
)
802 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
805 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
806 p
->flags
|= TERMP_HANG
;
809 if (n
->type
== ROFFT_HEAD
)
812 if (NULL
== n
->next
) {
813 p
->flags
&= ~TERMP_NOBREAK
;
816 p
->flags
|= TERMP_NOBREAK
;
822 if (n
->type
!= ROFFT_HEAD
)
824 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
832 * Margin control. Set-head-width lists have their right
833 * margins shortened. The body for these lists has the offset
834 * necessarily lengthened. Everybody gets the offset.
837 p
->tcol
->offset
+= offset
;
846 if (n
->type
== ROFFT_HEAD
)
847 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
849 p
->tcol
->offset
+= width
;
853 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
855 * XXX - this behaviour is not documented: the
856 * right-most column is filled to the right margin.
858 if (n
->type
== ROFFT_HEAD
)
860 if (n
->next
== NULL
&& p
->tcol
->rmargin
< p
->maxrmargin
)
861 p
->tcol
->rmargin
= p
->maxrmargin
;
868 * The dash, hyphen, bullet and enum lists all have a special
869 * HEAD character (temporarily bold, in some cases).
872 if (n
->type
== ROFFT_HEAD
)
875 term_fontpush(p
, TERMFONT_BOLD
);
876 term_word(p
, "\\[bu]");
881 term_fontpush(p
, TERMFONT_BOLD
);
886 (pair
->ppair
->ppair
->count
)++;
887 (void)snprintf(buf
, sizeof(buf
), "%d.",
888 pair
->ppair
->ppair
->count
);
896 * If we're not going to process our children, indicate so here.
905 if (n
->type
== ROFFT_HEAD
)
909 if (n
->type
== ROFFT_HEAD
)
921 termp_it_post(DECL_ARGS
)
925 if (n
->type
== ROFFT_BLOCK
)
928 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
934 if (n
->type
== ROFFT_BODY
)
938 if (n
->type
== ROFFT_BODY
)
947 * Now that our output is flushed, we can reset our tags. Since
948 * only `It' sets these flags, we're free to assume that nobody
949 * has munged them in the meanwhile.
952 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
| TERMP_HANG
);
957 termp_nm_pre(DECL_ARGS
)
961 if (n
->type
== ROFFT_BLOCK
) {
962 p
->flags
|= TERMP_PREKEEP
;
966 if (n
->type
== ROFFT_BODY
) {
967 if (n
->child
== NULL
)
969 p
->flags
|= TERMP_NOSPACE
;
971 if (n
->prev
->child
!= NULL
)
972 cp
= n
->prev
->child
->string
;
976 p
->tcol
->offset
+= term_len(p
, 6);
978 p
->tcol
->offset
+= term_len(p
, 1) +
983 if (n
->child
== NULL
)
986 if (n
->type
== ROFFT_HEAD
)
987 synopsis_pre(p
, n
->parent
);
989 if (n
->type
== ROFFT_HEAD
&&
990 n
->next
!= NULL
&& n
->next
->child
!= NULL
) {
991 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
993 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 1);
994 if (n
->child
== NULL
)
995 p
->tcol
->rmargin
+= term_strlen(p
, meta
->name
);
996 else if (n
->child
->type
== ROFFT_TEXT
) {
997 p
->tcol
->rmargin
+= term_strlen(p
, n
->child
->string
);
998 if (n
->child
->next
!= NULL
)
999 p
->flags
|= TERMP_HANG
;
1001 p
->tcol
->rmargin
+= term_len(p
, 5);
1002 p
->flags
|= TERMP_HANG
;
1005 return termp_bold_pre(p
, pair
, meta
, n
);
1009 termp_nm_post(DECL_ARGS
)
1013 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1016 if (n
->next
== NULL
|| n
->next
->child
== NULL
)
1019 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1023 if (n
->child
!= NULL
)
1032 termp_fl_pre(DECL_ARGS
)
1034 struct roff_node
*nn
;
1036 term_fontpush(p
, TERMFONT_BOLD
);
1037 term_word(p
, "\\-");
1039 if (n
->child
!= NULL
||
1040 ((nn
= roff_node_next(n
)) != NULL
&&
1041 nn
->type
!= ROFFT_TEXT
&&
1042 (nn
->flags
& NODE_LINE
) == 0))
1043 p
->flags
|= TERMP_NOSPACE
;
1049 termp__a_pre(DECL_ARGS
)
1051 struct roff_node
*nn
;
1053 if ((nn
= roff_node_prev(n
)) != NULL
&& nn
->tok
== MDOC__A
&&
1054 ((nn
= roff_node_next(n
)) == NULL
|| nn
->tok
!= MDOC__A
))
1055 term_word(p
, "and");
1061 termp_an_pre(DECL_ARGS
)
1064 if (n
->norm
->An
.auth
== AUTH_split
) {
1065 p
->flags
&= ~TERMP_NOSPLIT
;
1066 p
->flags
|= TERMP_SPLIT
;
1069 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1070 p
->flags
&= ~TERMP_SPLIT
;
1071 p
->flags
|= TERMP_NOSPLIT
;
1075 if (p
->flags
& TERMP_SPLIT
)
1078 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1079 p
->flags
|= TERMP_SPLIT
;
1085 termp_ns_pre(DECL_ARGS
)
1088 if ( ! (NODE_LINE
& n
->flags
))
1089 p
->flags
|= TERMP_NOSPACE
;
1094 termp_rs_pre(DECL_ARGS
)
1096 if (SEC_SEE_ALSO
!= n
->sec
)
1098 if (n
->type
== ROFFT_BLOCK
&& roff_node_prev(n
) != NULL
)
1104 termp_ex_pre(DECL_ARGS
)
1111 termp_nd_pre(DECL_ARGS
)
1114 if (n
->type
== ROFFT_BODY
)
1115 term_word(p
, "\\(en");
1120 termp_bl_pre(DECL_ARGS
)
1123 return n
->type
!= ROFFT_HEAD
;
1127 termp_bl_post(DECL_ARGS
)
1130 if (n
->type
!= ROFFT_BLOCK
)
1133 if (n
->tok
!= MDOC_Bl
|| n
->norm
->Bl
.type
!= LIST_column
)
1135 term_tab_set(p
, NULL
);
1136 term_tab_set(p
, "T");
1137 term_tab_set(p
, ".5i");
1141 termp_xr_pre(DECL_ARGS
)
1144 if (NULL
== (n
= n
->child
))
1147 assert(n
->type
== ROFFT_TEXT
);
1148 term_word(p
, n
->string
);
1150 if (NULL
== (n
= n
->next
))
1153 p
->flags
|= TERMP_NOSPACE
;
1155 p
->flags
|= TERMP_NOSPACE
;
1157 assert(n
->type
== ROFFT_TEXT
);
1158 term_word(p
, n
->string
);
1160 p
->flags
|= TERMP_NOSPACE
;
1167 * This decides how to assert whitespace before any of the SYNOPSIS set
1168 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1172 synopsis_pre(struct termp
*p
, struct roff_node
*n
)
1174 struct roff_node
*np
;
1176 if ((n
->flags
& NODE_SYNPRETTY
) == 0 ||
1177 (np
= roff_node_prev(n
)) == NULL
)
1181 * If we're the second in a pair of like elements, emit our
1182 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1183 * case we soldier on.
1185 if (np
->tok
== n
->tok
&&
1186 MDOC_Ft
!= n
->tok
&&
1187 MDOC_Fo
!= n
->tok
&&
1188 MDOC_Fn
!= n
->tok
) {
1194 * If we're one of the SYNOPSIS set and non-like pair-wise after
1195 * another (or Fn/Fo, which we've let slip through) then assert
1196 * vertical space, else only newline and move on.
1207 if (n
->tok
!= MDOC_Fn
&& n
->tok
!= MDOC_Fo
) {
1219 termp_vt_pre(DECL_ARGS
)
1223 return termp_ft_pre(p
, pair
, meta
, n
);
1230 return termp_under_pre(p
, pair
, meta
, n
);
1235 termp_bold_pre(DECL_ARGS
)
1237 term_fontpush(p
, TERMFONT_BOLD
);
1242 termp_fd_pre(DECL_ARGS
)
1245 return termp_bold_pre(p
, pair
, meta
, n
);
1249 termp_fd_post(DECL_ARGS
)
1255 termp_sh_pre(DECL_ARGS
)
1257 struct roff_node
*np
;
1262 * Vertical space before sections, except
1263 * when the previous section was empty.
1265 if ((np
= roff_node_prev(n
)) == NULL
||
1266 np
->tok
!= MDOC_Sh
||
1267 (np
->body
!= NULL
&& np
->body
->child
!= NULL
))
1271 return termp_bold_pre(p
, pair
, meta
, n
);
1273 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1274 term_tab_set(p
, NULL
);
1275 term_tab_set(p
, "T");
1276 term_tab_set(p
, ".5i");
1277 if (n
->sec
== SEC_AUTHORS
)
1278 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1287 termp_sh_post(DECL_ARGS
)
1295 p
->tcol
->offset
= 0;
1303 termp_lb_post(DECL_ARGS
)
1305 if (n
->sec
== SEC_LIBRARY
&& n
->flags
& NODE_LINE
)
1310 termp_d1_pre(DECL_ARGS
)
1312 if (n
->type
!= ROFFT_BLOCK
)
1315 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1316 term_tab_set(p
, NULL
);
1317 term_tab_set(p
, "T");
1318 term_tab_set(p
, ".5i");
1323 termp_ft_pre(DECL_ARGS
)
1326 return termp_under_pre(p
, pair
, meta
, n
);
1330 termp_fn_pre(DECL_ARGS
)
1336 pretty
= n
->flags
& NODE_SYNPRETTY
;
1337 if ((n
= n
->child
) == NULL
)
1341 rmargin
= p
->tcol
->rmargin
;
1342 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1343 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1346 assert(n
->type
== ROFFT_TEXT
);
1347 term_fontpush(p
, TERMFONT_BOLD
);
1348 term_word(p
, n
->string
);
1353 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1354 p
->flags
|= TERMP_NOPAD
;
1355 p
->tcol
->offset
= p
->tcol
->rmargin
;
1356 p
->tcol
->rmargin
= rmargin
;
1359 p
->flags
|= TERMP_NOSPACE
;
1361 p
->flags
|= TERMP_NOSPACE
;
1363 for (n
= n
->next
; n
; n
= n
->next
) {
1364 assert(n
->type
== ROFFT_TEXT
);
1365 term_fontpush(p
, TERMFONT_UNDER
);
1367 p
->flags
|= TERMP_NBRWORD
;
1368 term_word(p
, n
->string
);
1372 p
->flags
|= TERMP_NOSPACE
;
1377 p
->flags
|= TERMP_NOSPACE
;
1381 p
->flags
|= TERMP_NOSPACE
;
1389 termp_fa_pre(DECL_ARGS
)
1391 const struct roff_node
*nn
;
1393 if (n
->parent
->tok
!= MDOC_Fo
)
1394 return termp_under_pre(p
, pair
, meta
, n
);
1396 for (nn
= n
->child
; nn
!= NULL
; nn
= nn
->next
) {
1397 term_fontpush(p
, TERMFONT_UNDER
);
1398 p
->flags
|= TERMP_NBRWORD
;
1399 term_word(p
, nn
->string
);
1401 if (nn
->next
!= NULL
) {
1402 p
->flags
|= TERMP_NOSPACE
;
1406 if (n
->child
!= NULL
&&
1407 (nn
= roff_node_next(n
)) != NULL
&&
1408 nn
->tok
== MDOC_Fa
) {
1409 p
->flags
|= TERMP_NOSPACE
;
1416 termp_bd_pre(DECL_ARGS
)
1420 if (n
->type
== ROFFT_BLOCK
) {
1421 print_bvspace(p
, n
, n
);
1423 } else if (n
->type
== ROFFT_HEAD
)
1426 /* Handle the -offset argument. */
1428 if (n
->norm
->Bd
.offs
== NULL
||
1429 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1431 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1432 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1433 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1434 p
->tcol
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1436 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1437 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
1438 p
->tcol
->offset
= 0;
1439 else if (offset
< SHRT_MAX
)
1440 p
->tcol
->offset
+= offset
;
1443 switch (n
->norm
->Bd
.type
) {
1445 term_tab_set(p
, NULL
);
1446 term_tab_set(p
, "T");
1447 term_tab_set(p
, "8n");
1450 p
->flags
|= TERMP_CENTER
;
1459 termp_bd_post(DECL_ARGS
)
1461 if (n
->type
!= ROFFT_BODY
)
1463 if (n
->norm
->Bd
.type
== DISP_unfilled
||
1464 n
->norm
->Bd
.type
== DISP_literal
)
1465 p
->flags
|= TERMP_BRNEVER
;
1466 p
->flags
|= TERMP_NOSPACE
;
1468 p
->flags
&= ~TERMP_BRNEVER
;
1469 if (n
->norm
->Bd
.type
== DISP_centered
)
1470 p
->flags
&= ~TERMP_CENTER
;
1474 termp_xx_pre(DECL_ARGS
)
1476 if ((n
->aux
= p
->flags
& TERMP_PREKEEP
) == 0)
1477 p
->flags
|= TERMP_PREKEEP
;
1482 termp_xx_post(DECL_ARGS
)
1485 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1489 termp_pf_post(DECL_ARGS
)
1491 if (n
->next
!= NULL
&& (n
->next
->flags
& NODE_LINE
) == 0)
1492 p
->flags
|= TERMP_NOSPACE
;
1496 termp_ss_pre(DECL_ARGS
)
1500 if (roff_node_prev(n
) == NULL
)
1506 p
->tcol
->offset
= term_len(p
, (p
->defindent
+1)/2);
1507 return termp_bold_pre(p
, pair
, meta
, n
);
1509 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1510 term_tab_set(p
, NULL
);
1511 term_tab_set(p
, "T");
1512 term_tab_set(p
, ".5i");
1521 termp_ss_post(DECL_ARGS
)
1523 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1528 termp_in_pre(DECL_ARGS
)
1531 if (n
->flags
& NODE_SYNPRETTY
&& n
->flags
& NODE_LINE
) {
1532 term_fontpush(p
, TERMFONT_BOLD
);
1533 term_word(p
, "#include");
1537 term_fontpush(p
, TERMFONT_UNDER
);
1539 p
->flags
|= TERMP_NOSPACE
;
1544 termp_in_post(DECL_ARGS
)
1546 if (n
->flags
& NODE_SYNPRETTY
)
1547 term_fontpush(p
, TERMFONT_BOLD
);
1548 p
->flags
|= TERMP_NOSPACE
;
1550 if (n
->flags
& NODE_SYNPRETTY
)
1555 termp_pp_pre(DECL_ARGS
)
1562 termp_skip_pre(DECL_ARGS
)
1568 termp_quote_pre(DECL_ARGS
)
1570 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1576 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1577 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1593 term_word(p
, "\\(lq");
1596 if (NULL
== n
->norm
->Es
||
1597 NULL
== n
->norm
->Es
->child
)
1599 term_word(p
, n
->norm
->Es
->child
->string
);
1612 term_word(p
, "\\(oq");
1618 p
->flags
|= TERMP_NOSPACE
;
1623 termp_quote_post(DECL_ARGS
)
1626 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1629 p
->flags
|= TERMP_NOSPACE
;
1634 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1635 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1651 term_word(p
, "\\(rq");
1654 if (n
->norm
->Es
== NULL
||
1655 n
->norm
->Es
->child
== NULL
||
1656 n
->norm
->Es
->child
->next
== NULL
)
1657 p
->flags
&= ~TERMP_NOSPACE
;
1659 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1672 term_word(p
, "\\(cq");
1680 termp_eo_pre(DECL_ARGS
)
1683 if (n
->type
!= ROFFT_BODY
)
1686 if (n
->end
== ENDBODY_NOT
&&
1687 n
->parent
->head
->child
== NULL
&&
1689 n
->child
->end
!= ENDBODY_NOT
)
1690 term_word(p
, "\\&");
1691 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1692 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1693 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1694 p
->flags
|= TERMP_NOSPACE
;
1700 termp_eo_post(DECL_ARGS
)
1704 if (n
->type
!= ROFFT_BODY
)
1707 if (n
->end
!= ENDBODY_NOT
) {
1708 p
->flags
&= ~TERMP_NOSPACE
;
1712 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1713 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1716 p
->flags
|= TERMP_NOSPACE
;
1717 else if ( ! (body
|| tail
))
1718 term_word(p
, "\\&");
1720 p
->flags
&= ~TERMP_NOSPACE
;
1724 termp_fo_pre(DECL_ARGS
)
1733 rmargin
= p
->tcol
->rmargin
;
1734 if (n
->flags
& NODE_SYNPRETTY
) {
1735 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1736 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1739 p
->flags
|= TERMP_NOSPACE
;
1741 p
->flags
|= TERMP_NOSPACE
;
1742 if (n
->flags
& NODE_SYNPRETTY
) {
1744 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1746 p
->flags
|= TERMP_NOPAD
;
1747 p
->tcol
->offset
= p
->tcol
->rmargin
;
1748 p
->tcol
->rmargin
= rmargin
;
1752 return termp_bold_pre(p
, pair
, meta
, n
);
1757 termp_fo_post(DECL_ARGS
)
1759 if (n
->type
!= ROFFT_BODY
)
1762 p
->flags
|= TERMP_NOSPACE
;
1765 if (n
->flags
& NODE_SYNPRETTY
) {
1766 p
->flags
|= TERMP_NOSPACE
;
1773 termp_bf_pre(DECL_ARGS
)
1783 switch (n
->norm
->Bf
.font
) {
1785 return termp_under_pre(p
, pair
, meta
, n
);
1787 return termp_bold_pre(p
, pair
, meta
, n
);
1789 return termp_li_pre(p
, pair
, meta
, n
);
1794 termp_sm_pre(DECL_ARGS
)
1796 if (n
->child
== NULL
)
1797 p
->flags
^= TERMP_NONOSPACE
;
1798 else if (strcmp(n
->child
->string
, "on") == 0)
1799 p
->flags
&= ~TERMP_NONOSPACE
;
1801 p
->flags
|= TERMP_NONOSPACE
;
1803 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
1804 p
->flags
&= ~TERMP_NOSPACE
;
1810 termp_ap_pre(DECL_ARGS
)
1812 p
->flags
|= TERMP_NOSPACE
;
1814 p
->flags
|= TERMP_NOSPACE
;
1819 termp____post(DECL_ARGS
)
1821 struct roff_node
*nn
;
1824 * Handle lists of authors. In general, print each followed by
1825 * a comma. Don't print the comma if there are only two
1828 if (n
->tok
== MDOC__A
&&
1829 (nn
= roff_node_next(n
)) != NULL
&& nn
->tok
== MDOC__A
&&
1830 ((nn
= roff_node_next(nn
)) == NULL
|| nn
->tok
!= MDOC__A
) &&
1831 ((nn
= roff_node_prev(n
)) == NULL
|| nn
->tok
!= MDOC__A
))
1836 if (n
->parent
== NULL
|| n
->parent
->tok
!= MDOC_Rs
)
1839 p
->flags
|= TERMP_NOSPACE
;
1840 if (roff_node_next(n
) == NULL
) {
1842 p
->flags
|= TERMP_SENTENCE
;
1848 termp_li_pre(DECL_ARGS
)
1850 term_fontpush(p
, TERMFONT_NONE
);
1855 termp_lk_pre(DECL_ARGS
)
1857 const struct roff_node
*link
, *descr
, *punct
;
1859 if ((link
= n
->child
) == NULL
)
1862 /* Find beginning of trailing punctuation. */
1864 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1865 punct
= punct
->prev
;
1866 punct
= punct
->next
;
1869 if ((descr
= link
->next
) != NULL
&& descr
!= punct
) {
1870 term_fontpush(p
, TERMFONT_UNDER
);
1871 while (descr
!= punct
) {
1872 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1873 p
->flags
|= TERMP_NOSPACE
;
1874 term_word(p
, descr
->string
);
1875 descr
= descr
->next
;
1878 p
->flags
|= TERMP_NOSPACE
;
1883 term_fontpush(p
, TERMFONT_BOLD
);
1884 term_word(p
, link
->string
);
1887 /* Trailing punctuation. */
1888 while (punct
!= NULL
) {
1889 p
->flags
|= TERMP_NOSPACE
;
1890 term_word(p
, punct
->string
);
1891 punct
= punct
->next
;
1897 termp_bk_pre(DECL_ARGS
)
1905 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1906 p
->flags
|= TERMP_PREKEEP
;
1915 termp_bk_post(DECL_ARGS
)
1917 if (n
->type
== ROFFT_BODY
)
1918 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1922 * If we are in an `Rs' and there is a journal present,
1923 * then quote us instead of underlining us (for disambiguation).
1926 termp__t_post(DECL_ARGS
)
1928 if (n
->parent
!= NULL
&& n
->parent
->tok
== MDOC_Rs
&&
1929 n
->parent
->norm
->Rs
.quote_T
)
1930 termp_quote_post(p
, pair
, meta
, n
);
1931 termp____post(p
, pair
, meta
, n
);
1935 termp__t_pre(DECL_ARGS
)
1937 if (n
->parent
!= NULL
&& n
->parent
->tok
== MDOC_Rs
&&
1938 n
->parent
->norm
->Rs
.quote_T
)
1939 return termp_quote_pre(p
, pair
, meta
, n
);
1941 return termp_under_pre(p
, pair
, meta
, n
);
1945 termp_under_pre(DECL_ARGS
)
1947 term_fontpush(p
, TERMFONT_UNDER
);
1952 termp_abort_pre(DECL_ARGS
)