1 /* $Id: mdoc_term.c,v 1.374 2019/06/27 12:20:18 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2019 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 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.
21 #include <sys/types.h>
31 #include "mandoc_aux.h"
40 struct termpair
*ppair
;
44 #define DECL_ARGS struct termp *p, \
45 struct termpair *pair, \
46 const struct roff_meta *meta, \
49 struct mdoc_term_act
{
50 int (*pre
)(DECL_ARGS
);
51 void (*post
)(DECL_ARGS
);
54 static int a2width(const struct termp
*, const char *);
56 static void print_bvspace(struct termp
*,
57 const struct roff_node
*,
58 const struct roff_node
*);
59 static void print_mdoc_node(DECL_ARGS
);
60 static void print_mdoc_nodelist(DECL_ARGS
);
61 static void print_mdoc_head(struct termp
*, const struct roff_meta
*);
62 static void print_mdoc_foot(struct termp
*, const struct roff_meta
*);
63 static void synopsis_pre(struct termp
*,
64 const struct roff_node
*);
66 static void termp____post(DECL_ARGS
);
67 static void termp__t_post(DECL_ARGS
);
68 static void termp_bd_post(DECL_ARGS
);
69 static void termp_bk_post(DECL_ARGS
);
70 static void termp_bl_post(DECL_ARGS
);
71 static void termp_eo_post(DECL_ARGS
);
72 static void termp_fd_post(DECL_ARGS
);
73 static void termp_fo_post(DECL_ARGS
);
74 static void termp_in_post(DECL_ARGS
);
75 static void termp_it_post(DECL_ARGS
);
76 static void termp_lb_post(DECL_ARGS
);
77 static void termp_nm_post(DECL_ARGS
);
78 static void termp_pf_post(DECL_ARGS
);
79 static void termp_quote_post(DECL_ARGS
);
80 static void termp_sh_post(DECL_ARGS
);
81 static void termp_ss_post(DECL_ARGS
);
82 static void termp_xx_post(DECL_ARGS
);
84 static int termp__a_pre(DECL_ARGS
);
85 static int termp__t_pre(DECL_ARGS
);
86 static int termp_abort_pre(DECL_ARGS
);
87 static int termp_an_pre(DECL_ARGS
);
88 static int termp_ap_pre(DECL_ARGS
);
89 static int termp_bd_pre(DECL_ARGS
);
90 static int termp_bf_pre(DECL_ARGS
);
91 static int termp_bk_pre(DECL_ARGS
);
92 static int termp_bl_pre(DECL_ARGS
);
93 static int termp_bold_pre(DECL_ARGS
);
94 static int termp_cd_pre(DECL_ARGS
);
95 static int termp_d1_pre(DECL_ARGS
);
96 static int termp_eo_pre(DECL_ARGS
);
97 static int termp_em_pre(DECL_ARGS
);
98 static int termp_er_pre(DECL_ARGS
);
99 static int termp_ex_pre(DECL_ARGS
);
100 static int termp_fa_pre(DECL_ARGS
);
101 static int termp_fd_pre(DECL_ARGS
);
102 static int termp_fl_pre(DECL_ARGS
);
103 static int termp_fn_pre(DECL_ARGS
);
104 static int termp_fo_pre(DECL_ARGS
);
105 static int termp_ft_pre(DECL_ARGS
);
106 static int termp_in_pre(DECL_ARGS
);
107 static int termp_it_pre(DECL_ARGS
);
108 static int termp_li_pre(DECL_ARGS
);
109 static int termp_lk_pre(DECL_ARGS
);
110 static int termp_nd_pre(DECL_ARGS
);
111 static int termp_nm_pre(DECL_ARGS
);
112 static int termp_ns_pre(DECL_ARGS
);
113 static int termp_quote_pre(DECL_ARGS
);
114 static int termp_rs_pre(DECL_ARGS
);
115 static int termp_sh_pre(DECL_ARGS
);
116 static int termp_skip_pre(DECL_ARGS
);
117 static int termp_sm_pre(DECL_ARGS
);
118 static int termp_pp_pre(DECL_ARGS
);
119 static int termp_ss_pre(DECL_ARGS
);
120 static int termp_sy_pre(DECL_ARGS
);
121 static int termp_tag_pre(DECL_ARGS
);
122 static int termp_under_pre(DECL_ARGS
);
123 static int termp_vt_pre(DECL_ARGS
);
124 static int termp_xr_pre(DECL_ARGS
);
125 static int termp_xx_pre(DECL_ARGS
);
127 static const struct mdoc_term_act mdoc_term_acts
[MDOC_MAX
- MDOC_Dd
] = {
128 { NULL
, NULL
}, /* Dd */
129 { NULL
, NULL
}, /* Dt */
130 { NULL
, NULL
}, /* Os */
131 { termp_sh_pre
, termp_sh_post
}, /* Sh */
132 { termp_ss_pre
, termp_ss_post
}, /* Ss */
133 { termp_pp_pre
, NULL
}, /* Pp */
134 { termp_d1_pre
, termp_bl_post
}, /* D1 */
135 { termp_d1_pre
, termp_bl_post
}, /* Dl */
136 { termp_bd_pre
, termp_bd_post
}, /* Bd */
137 { NULL
, NULL
}, /* Ed */
138 { termp_bl_pre
, termp_bl_post
}, /* Bl */
139 { NULL
, NULL
}, /* El */
140 { termp_it_pre
, termp_it_post
}, /* It */
141 { termp_under_pre
, NULL
}, /* Ad */
142 { termp_an_pre
, NULL
}, /* An */
143 { termp_ap_pre
, NULL
}, /* Ap */
144 { termp_under_pre
, NULL
}, /* Ar */
145 { termp_cd_pre
, NULL
}, /* Cd */
146 { termp_bold_pre
, NULL
}, /* Cm */
147 { termp_li_pre
, NULL
}, /* Dv */
148 { termp_er_pre
, NULL
}, /* Er */
149 { termp_tag_pre
, NULL
}, /* Ev */
150 { termp_ex_pre
, NULL
}, /* Ex */
151 { termp_fa_pre
, NULL
}, /* Fa */
152 { termp_fd_pre
, termp_fd_post
}, /* Fd */
153 { termp_fl_pre
, NULL
}, /* Fl */
154 { termp_fn_pre
, NULL
}, /* Fn */
155 { termp_ft_pre
, NULL
}, /* Ft */
156 { termp_bold_pre
, NULL
}, /* Ic */
157 { termp_in_pre
, termp_in_post
}, /* In */
158 { termp_li_pre
, NULL
}, /* Li */
159 { termp_nd_pre
, NULL
}, /* Nd */
160 { termp_nm_pre
, termp_nm_post
}, /* Nm */
161 { termp_quote_pre
, termp_quote_post
}, /* Op */
162 { termp_abort_pre
, NULL
}, /* Ot */
163 { termp_under_pre
, NULL
}, /* Pa */
164 { termp_ex_pre
, NULL
}, /* Rv */
165 { NULL
, NULL
}, /* St */
166 { termp_under_pre
, NULL
}, /* Va */
167 { termp_vt_pre
, NULL
}, /* Vt */
168 { termp_xr_pre
, NULL
}, /* Xr */
169 { termp__a_pre
, termp____post
}, /* %A */
170 { termp_under_pre
, termp____post
}, /* %B */
171 { NULL
, termp____post
}, /* %D */
172 { termp_under_pre
, termp____post
}, /* %I */
173 { termp_under_pre
, termp____post
}, /* %J */
174 { NULL
, termp____post
}, /* %N */
175 { NULL
, termp____post
}, /* %O */
176 { NULL
, termp____post
}, /* %P */
177 { NULL
, termp____post
}, /* %R */
178 { termp__t_pre
, termp__t_post
}, /* %T */
179 { NULL
, termp____post
}, /* %V */
180 { NULL
, NULL
}, /* Ac */
181 { termp_quote_pre
, termp_quote_post
}, /* Ao */
182 { termp_quote_pre
, termp_quote_post
}, /* Aq */
183 { NULL
, NULL
}, /* At */
184 { NULL
, NULL
}, /* Bc */
185 { termp_bf_pre
, NULL
}, /* Bf */
186 { termp_quote_pre
, termp_quote_post
}, /* Bo */
187 { termp_quote_pre
, termp_quote_post
}, /* Bq */
188 { termp_xx_pre
, termp_xx_post
}, /* Bsx */
189 { NULL
, NULL
}, /* Bx */
190 { termp_skip_pre
, NULL
}, /* Db */
191 { NULL
, NULL
}, /* Dc */
192 { termp_quote_pre
, termp_quote_post
}, /* Do */
193 { termp_quote_pre
, termp_quote_post
}, /* Dq */
194 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
195 { NULL
, NULL
}, /* Ef */
196 { termp_em_pre
, NULL
}, /* Em */
197 { termp_eo_pre
, termp_eo_post
}, /* Eo */
198 { termp_xx_pre
, termp_xx_post
}, /* Fx */
199 { termp_bold_pre
, NULL
}, /* Ms */
200 { termp_li_pre
, NULL
}, /* No */
201 { termp_ns_pre
, NULL
}, /* Ns */
202 { termp_xx_pre
, termp_xx_post
}, /* Nx */
203 { termp_xx_pre
, termp_xx_post
}, /* Ox */
204 { NULL
, NULL
}, /* Pc */
205 { NULL
, termp_pf_post
}, /* Pf */
206 { termp_quote_pre
, termp_quote_post
}, /* Po */
207 { termp_quote_pre
, termp_quote_post
}, /* Pq */
208 { NULL
, NULL
}, /* Qc */
209 { termp_quote_pre
, termp_quote_post
}, /* Ql */
210 { termp_quote_pre
, termp_quote_post
}, /* Qo */
211 { termp_quote_pre
, termp_quote_post
}, /* Qq */
212 { NULL
, NULL
}, /* Re */
213 { termp_rs_pre
, NULL
}, /* Rs */
214 { NULL
, NULL
}, /* Sc */
215 { termp_quote_pre
, termp_quote_post
}, /* So */
216 { termp_quote_pre
, termp_quote_post
}, /* Sq */
217 { termp_sm_pre
, NULL
}, /* Sm */
218 { termp_under_pre
, NULL
}, /* Sx */
219 { termp_sy_pre
, NULL
}, /* Sy */
220 { NULL
, NULL
}, /* Tn */
221 { termp_xx_pre
, termp_xx_post
}, /* Ux */
222 { NULL
, NULL
}, /* Xc */
223 { NULL
, NULL
}, /* Xo */
224 { termp_fo_pre
, termp_fo_post
}, /* Fo */
225 { NULL
, NULL
}, /* Fc */
226 { termp_quote_pre
, termp_quote_post
}, /* Oo */
227 { NULL
, NULL
}, /* Oc */
228 { termp_bk_pre
, termp_bk_post
}, /* Bk */
229 { NULL
, NULL
}, /* Ek */
230 { NULL
, NULL
}, /* Bt */
231 { NULL
, NULL
}, /* Hf */
232 { termp_under_pre
, NULL
}, /* Fr */
233 { NULL
, NULL
}, /* Ud */
234 { NULL
, termp_lb_post
}, /* Lb */
235 { termp_abort_pre
, NULL
}, /* Lp */
236 { termp_lk_pre
, NULL
}, /* Lk */
237 { termp_under_pre
, NULL
}, /* Mt */
238 { termp_quote_pre
, termp_quote_post
}, /* Brq */
239 { termp_quote_pre
, termp_quote_post
}, /* Bro */
240 { NULL
, NULL
}, /* Brc */
241 { NULL
, termp____post
}, /* %C */
242 { termp_skip_pre
, NULL
}, /* Es */
243 { termp_quote_pre
, termp_quote_post
}, /* En */
244 { termp_xx_pre
, termp_xx_post
}, /* Dx */
245 { NULL
, termp____post
}, /* %Q */
246 { NULL
, termp____post
}, /* %U */
247 { NULL
, NULL
}, /* Ta */
254 terminal_mdoc(void *arg
, const struct roff_meta
*mdoc
)
256 struct roff_node
*n
, *nn
;
258 size_t save_defindent
;
260 p
= (struct termp
*)arg
;
261 p
->tcol
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
262 term_tab_set(p
, NULL
);
263 term_tab_set(p
, "T");
264 term_tab_set(p
, ".5i");
266 n
= mdoc
->first
->child
;
267 if (p
->synopsisonly
) {
268 for (nn
= NULL
; n
!= NULL
; n
= n
->next
) {
269 if (n
->tok
!= MDOC_Sh
)
271 if (n
->sec
== SEC_SYNOPSIS
)
273 if (nn
== NULL
&& n
->sec
== SEC_NAME
)
278 p
->flags
|= TERMP_NOSPACE
;
279 if (n
!= NULL
&& (n
= n
->child
->next
->child
) != NULL
)
280 print_mdoc_nodelist(p
, NULL
, mdoc
, n
);
283 save_defindent
= p
->defindent
;
284 if (p
->defindent
== 0)
286 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, mdoc
);
288 (n
->type
== ROFFT_COMMENT
||
289 n
->flags
& NODE_NOPRT
))
292 if (n
->tok
!= MDOC_Sh
)
294 print_mdoc_nodelist(p
, NULL
, mdoc
, n
);
297 p
->defindent
= save_defindent
;
302 print_mdoc_nodelist(DECL_ARGS
)
306 print_mdoc_node(p
, pair
, meta
, n
);
312 print_mdoc_node(DECL_ARGS
)
314 const struct mdoc_term_act
*act
;
315 struct termpair npair
;
316 size_t offset
, rmargin
;
320 * In no-fill mode, break the output line at the beginning
321 * of new input lines except after \c, and nowhere else.
324 if (n
->flags
& NODE_NOFILL
) {
325 if (n
->flags
& NODE_LINE
&&
326 (p
->flags
& TERMP_NONEWLINE
) == 0)
328 p
->flags
|= TERMP_BRNEVER
;
330 p
->flags
&= ~TERMP_BRNEVER
;
332 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
336 offset
= p
->tcol
->offset
;
337 rmargin
= p
->tcol
->rmargin
;
338 n
->flags
&= ~NODE_ENDED
;
339 n
->prev_font
= p
->fonti
;
341 memset(&npair
, 0, sizeof(struct termpair
));
345 * Keeps only work until the end of a line. If a keep was
346 * invoked in a prior line, revert it to PREKEEP.
349 if (p
->flags
& TERMP_KEEP
&& n
->flags
& NODE_LINE
) {
350 p
->flags
&= ~TERMP_KEEP
;
351 p
->flags
|= TERMP_PREKEEP
;
355 * After the keep flags have been set up, we may now
356 * produce output. Note that some pre-handlers do so.
362 if (n
->flags
& NODE_LINE
) {
363 switch (*n
->string
) {
365 if (p
->flags
& TERMP_NONEWLINE
)
371 if ((p
->flags
& TERMP_NONEWLINE
) == 0)
378 if (NODE_DELIMC
& n
->flags
)
379 p
->flags
|= TERMP_NOSPACE
;
380 term_word(p
, n
->string
);
381 if (NODE_DELIMO
& n
->flags
)
382 p
->flags
|= TERMP_NOSPACE
;
385 if ( ! (n
->flags
& NODE_LINE
))
386 p
->flags
|= TERMP_NOSPACE
;
388 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
389 p
->flags
|= TERMP_NOSPACE
;
392 if (p
->tbl
.cols
== NULL
)
394 term_tbl(p
, n
->span
);
397 if (n
->tok
< ROFF_MAX
) {
401 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
402 act
= mdoc_term_acts
+ (n
->tok
- MDOC_Dd
);
403 if (act
->pre
!= NULL
&&
404 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
405 chld
= (*act
->pre
)(p
, &npair
, meta
, n
);
409 if (chld
&& n
->child
)
410 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
413 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
423 if (act
->post
== NULL
|| n
->flags
& NODE_ENDED
)
425 (void)(*act
->post
)(p
, &npair
, meta
, n
);
428 * Explicit end tokens not only call the post
429 * handler, but also tell the respective block
430 * that it must not call the post handler again.
432 if (ENDBODY_NOT
!= n
->end
)
433 n
->body
->flags
|= NODE_ENDED
;
437 if (NODE_EOS
& n
->flags
)
438 p
->flags
|= TERMP_SENTENCE
;
440 if (n
->type
!= ROFFT_TEXT
)
441 p
->tcol
->offset
= offset
;
442 p
->tcol
->rmargin
= rmargin
;
446 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
450 term_fontrepl(p
, TERMFONT_NONE
);
453 * Output the footer in new-groff style, that is, three columns
454 * with the middle being the manual date and flanking columns
455 * being the operating system:
463 sz
= term_strlen(p
, meta
->date
);
464 p
->tcol
->rmargin
= p
->maxrmargin
> sz
?
465 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
467 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
469 term_word(p
, meta
->os
);
472 p
->tcol
->offset
= p
->tcol
->rmargin
;
473 sz
= term_strlen(p
, meta
->os
);
474 p
->tcol
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
475 p
->flags
|= TERMP_NOSPACE
;
477 term_word(p
, meta
->date
);
480 p
->tcol
->offset
= p
->tcol
->rmargin
;
481 p
->tcol
->rmargin
= p
->maxrmargin
;
483 p
->flags
&= ~TERMP_NOBREAK
;
484 p
->flags
|= TERMP_NOSPACE
;
486 term_word(p
, meta
->os
);
490 p
->tcol
->rmargin
= p
->maxrmargin
;
495 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
497 char *volume
, *title
;
498 size_t vollen
, titlen
;
501 * The header is strange. It has three components, which are
502 * really two with the first duplicated. It goes like this:
504 * IDENTIFIER TITLE IDENTIFIER
506 * The IDENTIFIER is NAME(SECTION), which is the command-name
507 * (if given, or "unknown" if not) followed by the manual page
508 * section. These are given in `Dt'. The TITLE is a free-form
509 * string depending on the manual volume. If not specified, it
510 * switches on the manual section.
514 if (NULL
== meta
->arch
)
515 volume
= mandoc_strdup(meta
->vol
);
517 mandoc_asprintf(&volume
, "%s (%s)",
518 meta
->vol
, meta
->arch
);
519 vollen
= term_strlen(p
, volume
);
521 if (NULL
== meta
->msec
)
522 title
= mandoc_strdup(meta
->title
);
524 mandoc_asprintf(&title
, "%s(%s)",
525 meta
->title
, meta
->msec
);
526 titlen
= term_strlen(p
, title
);
528 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
531 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
532 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
533 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
538 p
->flags
|= TERMP_NOSPACE
;
539 p
->tcol
->offset
= p
->tcol
->rmargin
;
540 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
541 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
543 term_word(p
, volume
);
546 p
->flags
&= ~TERMP_NOBREAK
;
548 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
549 p
->flags
|= TERMP_NOSPACE
;
550 p
->tcol
->offset
= p
->tcol
->rmargin
;
551 p
->tcol
->rmargin
= p
->maxrmargin
;
556 p
->flags
&= ~TERMP_NOSPACE
;
558 p
->tcol
->rmargin
= p
->maxrmargin
;
564 a2width(const struct termp
*p
, const char *v
)
569 end
= a2roffsu(v
, &su
, SCALE_MAX
);
570 if (end
== NULL
|| *end
!= '\0') {
571 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
572 su
.scale
/= term_strlen(p
, "0");
574 return term_hen(p
, &su
);
578 * Determine how much space to print out before block elements of `It'
579 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
583 print_bvspace(struct termp
*p
,
584 const struct roff_node
*bl
,
585 const struct roff_node
*n
)
587 const struct roff_node
*nn
;
593 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
595 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
598 /* Do not vspace directly after Ss/Sh. */
601 while (nn
->prev
!= NULL
&&
602 (nn
->prev
->type
== ROFFT_COMMENT
||
603 nn
->prev
->flags
& NODE_NOPRT
))
605 while (nn
->prev
== NULL
) {
608 if (nn
->type
== ROFFT_ROOT
)
610 } while (nn
->type
!= ROFFT_BLOCK
);
611 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
613 if (nn
->tok
== MDOC_It
&&
614 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
618 /* A `-column' does not assert vspace within the list. */
620 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
621 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
624 /* A `-diag' without body does not vspace. */
626 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
627 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
628 assert(n
->prev
->body
);
629 if (NULL
== n
->prev
->body
->child
)
638 termp_it_pre(DECL_ARGS
)
642 const struct roff_node
*bl
, *nn
;
644 int i
, offset
, width
;
647 if (n
->type
== ROFFT_BLOCK
) {
648 print_bvspace(p
, n
->parent
->parent
, n
);
652 bl
= n
->parent
->parent
->parent
;
653 type
= bl
->norm
->Bl
.type
;
656 * Defaults for specific list types.
664 width
= term_len(p
, 2);
668 width
= term_len(p
, 8);
671 width
= term_len(p
, 10);
680 * First calculate width and offset. This is pretty easy unless
681 * we're a -column list, in which case all prior columns must
685 if (bl
->norm
->Bl
.offs
!= NULL
) {
686 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
687 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
688 offset
= -p
->tcol
->offset
;
689 else if (offset
> SHRT_MAX
)
695 if (n
->type
== ROFFT_HEAD
)
699 * Imitate groff's column handling:
700 * - For each earlier column, add its width.
701 * - For less than 5 columns, add four more blanks per
703 * - For exactly 5 columns, add three more blank per
705 * - For more than 5 columns, add only one column.
707 ncols
= bl
->norm
->Bl
.ncols
;
708 dcol
= ncols
< 5 ? term_len(p
, 4) :
709 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
712 * Calculate the offset by applying all prior ROFFT_BODY,
713 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
716 for (i
= 0, nn
= n
->prev
;
717 nn
->prev
&& i
< (int)ncols
;
718 nn
= nn
->prev
, i
++) {
720 term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
721 su
.scale
/= term_strlen(p
, "0");
722 offset
+= term_hen(p
, &su
) + dcol
;
726 * When exceeding the declared number of columns, leave
727 * the remaining widths at 0. This will later be
728 * adjusted to the default width of 10, or, for the last
729 * column, stretched to the right margin.
735 * Use the declared column widths, extended as explained
736 * in the preceding paragraph.
738 SCALE_HS_INIT(&su
, term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
739 su
.scale
/= term_strlen(p
, "0");
740 width
= term_hen(p
, &su
) + dcol
;
743 if (NULL
== bl
->norm
->Bl
.width
)
747 * Note: buffer the width by 2, which is groff's magic
748 * number for buffering single arguments. See the above
749 * handling for column for how this changes.
751 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
752 if (width
< 0 && (size_t)(-width
) > p
->tcol
->offset
)
753 width
= -p
->tcol
->offset
;
754 else if (width
> SHRT_MAX
)
760 * Whitespace control. Inset bodies need an initial space,
761 * while diagonal bodies need two.
764 p
->flags
|= TERMP_NOSPACE
;
768 if (n
->type
== ROFFT_BODY
)
769 term_word(p
, "\\ \\ ");
772 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
779 p
->flags
|= TERMP_NOSPACE
;
783 if (n
->type
== ROFFT_HEAD
)
784 term_fontpush(p
, TERMFONT_BOLD
);
791 * Pad and break control. This is the tricky part. These flags
792 * are documented in term_flushln() in term.c. Note that we're
793 * going to unset all of these flags in termp_it_post() when we
802 if (n
->type
== ROFFT_HEAD
) {
803 p
->flags
|= TERMP_NOBREAK
| TERMP_HANG
;
805 } else if (width
<= (int)term_len(p
, 2))
806 p
->flags
|= TERMP_NOPAD
;
809 if (n
->type
!= ROFFT_HEAD
)
811 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
815 if (n
->type
!= ROFFT_HEAD
)
818 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
821 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
822 p
->flags
|= TERMP_HANG
;
825 if (n
->type
== ROFFT_HEAD
)
828 if (NULL
== n
->next
) {
829 p
->flags
&= ~TERMP_NOBREAK
;
832 p
->flags
|= TERMP_NOBREAK
;
838 if (n
->type
!= ROFFT_HEAD
)
840 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
848 * Margin control. Set-head-width lists have their right
849 * margins shortened. The body for these lists has the offset
850 * necessarily lengthened. Everybody gets the offset.
853 p
->tcol
->offset
+= offset
;
862 if (n
->type
== ROFFT_HEAD
)
863 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
865 p
->tcol
->offset
+= width
;
869 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
871 * XXX - this behaviour is not documented: the
872 * right-most column is filled to the right margin.
874 if (n
->type
== ROFFT_HEAD
)
876 if (n
->next
== NULL
&& p
->tcol
->rmargin
< p
->maxrmargin
)
877 p
->tcol
->rmargin
= p
->maxrmargin
;
884 * The dash, hyphen, bullet and enum lists all have a special
885 * HEAD character (temporarily bold, in some cases).
888 if (n
->type
== ROFFT_HEAD
)
891 term_fontpush(p
, TERMFONT_BOLD
);
892 term_word(p
, "\\[bu]");
897 term_fontpush(p
, TERMFONT_BOLD
);
902 (pair
->ppair
->ppair
->count
)++;
903 (void)snprintf(buf
, sizeof(buf
), "%d.",
904 pair
->ppair
->ppair
->count
);
912 * If we're not going to process our children, indicate so here.
921 if (n
->type
== ROFFT_HEAD
)
925 if (n
->type
== ROFFT_HEAD
)
937 termp_it_post(DECL_ARGS
)
941 if (n
->type
== ROFFT_BLOCK
)
944 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
950 if (n
->type
== ROFFT_BODY
)
954 if (n
->type
== ROFFT_BODY
)
963 * Now that our output is flushed, we can reset our tags. Since
964 * only `It' sets these flags, we're free to assume that nobody
965 * has munged them in the meanwhile.
968 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
| TERMP_HANG
);
973 termp_nm_pre(DECL_ARGS
)
977 if (n
->type
== ROFFT_BLOCK
) {
978 p
->flags
|= TERMP_PREKEEP
;
982 if (n
->type
== ROFFT_BODY
) {
983 if (n
->child
== NULL
)
985 p
->flags
|= TERMP_NOSPACE
;
987 if (n
->prev
->child
!= NULL
)
988 cp
= n
->prev
->child
->string
;
992 p
->tcol
->offset
+= term_len(p
, 6);
994 p
->tcol
->offset
+= term_len(p
, 1) +
999 if (n
->child
== NULL
)
1002 if (n
->type
== ROFFT_HEAD
)
1003 synopsis_pre(p
, n
->parent
);
1005 if (n
->type
== ROFFT_HEAD
&&
1006 n
->next
!= NULL
&& n
->next
->child
!= NULL
) {
1007 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1009 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 1);
1010 if (n
->child
== NULL
)
1011 p
->tcol
->rmargin
+= term_strlen(p
, meta
->name
);
1012 else if (n
->child
->type
== ROFFT_TEXT
) {
1013 p
->tcol
->rmargin
+= term_strlen(p
, n
->child
->string
);
1014 if (n
->child
->next
!= NULL
)
1015 p
->flags
|= TERMP_HANG
;
1017 p
->tcol
->rmargin
+= term_len(p
, 5);
1018 p
->flags
|= TERMP_HANG
;
1022 term_fontpush(p
, TERMFONT_BOLD
);
1027 termp_nm_post(DECL_ARGS
)
1030 if (n
->type
== ROFFT_BLOCK
) {
1031 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1032 } else if (n
->type
== ROFFT_HEAD
&&
1033 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1035 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1037 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1042 termp_fl_pre(DECL_ARGS
)
1045 termp_tag_pre(p
, pair
, meta
, n
);
1046 term_fontpush(p
, TERMFONT_BOLD
);
1047 term_word(p
, "\\-");
1049 if (!(n
->child
== NULL
&&
1051 n
->next
->type
== ROFFT_TEXT
||
1052 n
->next
->flags
& NODE_LINE
)))
1053 p
->flags
|= TERMP_NOSPACE
;
1059 termp__a_pre(DECL_ARGS
)
1062 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1063 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1064 term_word(p
, "and");
1070 termp_an_pre(DECL_ARGS
)
1073 if (n
->norm
->An
.auth
== AUTH_split
) {
1074 p
->flags
&= ~TERMP_NOSPLIT
;
1075 p
->flags
|= TERMP_SPLIT
;
1078 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1079 p
->flags
&= ~TERMP_SPLIT
;
1080 p
->flags
|= TERMP_NOSPLIT
;
1084 if (p
->flags
& TERMP_SPLIT
)
1087 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1088 p
->flags
|= TERMP_SPLIT
;
1094 termp_ns_pre(DECL_ARGS
)
1097 if ( ! (NODE_LINE
& n
->flags
))
1098 p
->flags
|= TERMP_NOSPACE
;
1103 termp_rs_pre(DECL_ARGS
)
1106 if (SEC_SEE_ALSO
!= n
->sec
)
1108 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1114 termp_ex_pre(DECL_ARGS
)
1121 termp_nd_pre(DECL_ARGS
)
1124 if (n
->type
== ROFFT_BODY
)
1125 term_word(p
, "\\(en");
1130 termp_bl_pre(DECL_ARGS
)
1133 return n
->type
!= ROFFT_HEAD
;
1137 termp_bl_post(DECL_ARGS
)
1140 if (n
->type
!= ROFFT_BLOCK
)
1143 if (n
->tok
!= MDOC_Bl
|| n
->norm
->Bl
.type
!= LIST_column
)
1145 term_tab_set(p
, NULL
);
1146 term_tab_set(p
, "T");
1147 term_tab_set(p
, ".5i");
1151 termp_xr_pre(DECL_ARGS
)
1154 if (NULL
== (n
= n
->child
))
1157 assert(n
->type
== ROFFT_TEXT
);
1158 term_word(p
, n
->string
);
1160 if (NULL
== (n
= n
->next
))
1163 p
->flags
|= TERMP_NOSPACE
;
1165 p
->flags
|= TERMP_NOSPACE
;
1167 assert(n
->type
== ROFFT_TEXT
);
1168 term_word(p
, n
->string
);
1170 p
->flags
|= TERMP_NOSPACE
;
1177 * This decides how to assert whitespace before any of the SYNOPSIS set
1178 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1182 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1185 * Obviously, if we're not in a SYNOPSIS or no prior macros
1186 * exist, do nothing.
1188 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
1192 * If we're the second in a pair of like elements, emit our
1193 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1194 * case we soldier on.
1196 if (n
->prev
->tok
== n
->tok
&&
1197 MDOC_Ft
!= n
->tok
&&
1198 MDOC_Fo
!= n
->tok
&&
1199 MDOC_Fn
!= n
->tok
) {
1205 * If we're one of the SYNOPSIS set and non-like pair-wise after
1206 * another (or Fn/Fo, which we've let slip through) then assert
1207 * vertical space, else only newline and move on.
1209 switch (n
->prev
->tok
) {
1218 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1230 termp_vt_pre(DECL_ARGS
)
1233 if (n
->type
== ROFFT_ELEM
) {
1235 return termp_under_pre(p
, pair
, meta
, n
);
1236 } else if (n
->type
== ROFFT_BLOCK
) {
1239 } else if (n
->type
== ROFFT_HEAD
)
1242 return termp_under_pre(p
, pair
, meta
, n
);
1246 termp_bold_pre(DECL_ARGS
)
1249 termp_tag_pre(p
, pair
, meta
, n
);
1250 term_fontpush(p
, TERMFONT_BOLD
);
1255 termp_fd_pre(DECL_ARGS
)
1259 return termp_bold_pre(p
, pair
, meta
, n
);
1263 termp_fd_post(DECL_ARGS
)
1270 termp_sh_pre(DECL_ARGS
)
1276 * Vertical space before sections, except
1277 * when the previous section was empty.
1279 if (n
->prev
== NULL
||
1280 n
->prev
->tok
!= MDOC_Sh
||
1281 (n
->prev
->body
!= NULL
&&
1282 n
->prev
->body
->child
!= NULL
))
1286 term_fontpush(p
, TERMFONT_BOLD
);
1289 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1290 term_tab_set(p
, NULL
);
1291 term_tab_set(p
, "T");
1292 term_tab_set(p
, ".5i");
1294 case SEC_DESCRIPTION
:
1298 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1311 termp_sh_post(DECL_ARGS
)
1320 p
->tcol
->offset
= 0;
1328 termp_lb_post(DECL_ARGS
)
1331 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
)
1336 termp_d1_pre(DECL_ARGS
)
1339 if (n
->type
!= ROFFT_BLOCK
)
1342 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1343 term_tab_set(p
, NULL
);
1344 term_tab_set(p
, "T");
1345 term_tab_set(p
, ".5i");
1350 termp_ft_pre(DECL_ARGS
)
1353 /* NB: NODE_LINE does not effect this! */
1355 term_fontpush(p
, TERMFONT_UNDER
);
1360 termp_fn_pre(DECL_ARGS
)
1365 pretty
= NODE_SYNPRETTY
& n
->flags
;
1369 if (NULL
== (n
= n
->child
))
1373 rmargin
= p
->tcol
->rmargin
;
1374 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1375 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1378 assert(n
->type
== ROFFT_TEXT
);
1379 term_fontpush(p
, TERMFONT_BOLD
);
1380 term_word(p
, n
->string
);
1383 if (n
->sec
== SEC_DESCRIPTION
|| n
->sec
== SEC_CUSTOM
)
1384 tag_put(n
->string
, ++fn_prio
, p
->line
);
1388 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1389 p
->flags
|= TERMP_NOPAD
;
1390 p
->tcol
->offset
= p
->tcol
->rmargin
;
1391 p
->tcol
->rmargin
= rmargin
;
1394 p
->flags
|= TERMP_NOSPACE
;
1396 p
->flags
|= TERMP_NOSPACE
;
1398 for (n
= n
->next
; n
; n
= n
->next
) {
1399 assert(n
->type
== ROFFT_TEXT
);
1400 term_fontpush(p
, TERMFONT_UNDER
);
1402 p
->flags
|= TERMP_NBRWORD
;
1403 term_word(p
, n
->string
);
1407 p
->flags
|= TERMP_NOSPACE
;
1412 p
->flags
|= TERMP_NOSPACE
;
1416 p
->flags
|= TERMP_NOSPACE
;
1425 termp_fa_pre(DECL_ARGS
)
1427 const struct roff_node
*nn
;
1429 if (n
->parent
->tok
!= MDOC_Fo
) {
1430 term_fontpush(p
, TERMFONT_UNDER
);
1434 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1435 term_fontpush(p
, TERMFONT_UNDER
);
1436 p
->flags
|= TERMP_NBRWORD
;
1437 term_word(p
, nn
->string
);
1440 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1441 p
->flags
|= TERMP_NOSPACE
;
1450 termp_bd_pre(DECL_ARGS
)
1454 if (n
->type
== ROFFT_BLOCK
) {
1455 print_bvspace(p
, n
, n
);
1457 } else if (n
->type
== ROFFT_HEAD
)
1460 /* Handle the -offset argument. */
1462 if (n
->norm
->Bd
.offs
== NULL
||
1463 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1465 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1466 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1467 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1468 p
->tcol
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1470 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1471 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
1472 p
->tcol
->offset
= 0;
1473 else if (offset
< SHRT_MAX
)
1474 p
->tcol
->offset
+= offset
;
1477 switch (n
->norm
->Bd
.type
) {
1479 term_tab_set(p
, NULL
);
1480 term_tab_set(p
, "T");
1481 term_tab_set(p
, "8n");
1484 p
->flags
|= TERMP_CENTER
;
1493 termp_bd_post(DECL_ARGS
)
1495 if (n
->type
!= ROFFT_BODY
)
1497 if (n
->norm
->Bd
.type
== DISP_unfilled
||
1498 n
->norm
->Bd
.type
== DISP_literal
)
1499 p
->flags
|= TERMP_BRNEVER
;
1500 p
->flags
|= TERMP_NOSPACE
;
1502 p
->flags
&= ~TERMP_BRNEVER
;
1503 if (n
->norm
->Bd
.type
== DISP_centered
)
1504 p
->flags
&= ~TERMP_CENTER
;
1508 termp_xx_pre(DECL_ARGS
)
1510 if ((n
->aux
= p
->flags
& TERMP_PREKEEP
) == 0)
1511 p
->flags
|= TERMP_PREKEEP
;
1516 termp_xx_post(DECL_ARGS
)
1519 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1523 termp_pf_post(DECL_ARGS
)
1526 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1527 p
->flags
|= TERMP_NOSPACE
;
1531 termp_ss_pre(DECL_ARGS
)
1533 struct roff_node
*nn
;
1538 for (nn
= n
->prev
; nn
!= NULL
; nn
= nn
->prev
)
1539 if (nn
->type
!= ROFFT_COMMENT
&&
1540 (nn
->flags
& NODE_NOPRT
) == 0)
1546 term_fontpush(p
, TERMFONT_BOLD
);
1547 p
->tcol
->offset
= term_len(p
, (p
->defindent
+1)/2);
1550 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1551 term_tab_set(p
, NULL
);
1552 term_tab_set(p
, "T");
1553 term_tab_set(p
, ".5i");
1563 termp_ss_post(DECL_ARGS
)
1566 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1571 termp_cd_pre(DECL_ARGS
)
1575 term_fontpush(p
, TERMFONT_BOLD
);
1580 termp_in_pre(DECL_ARGS
)
1585 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
) {
1586 term_fontpush(p
, TERMFONT_BOLD
);
1587 term_word(p
, "#include");
1591 term_fontpush(p
, TERMFONT_UNDER
);
1594 p
->flags
|= TERMP_NOSPACE
;
1599 termp_in_post(DECL_ARGS
)
1602 if (NODE_SYNPRETTY
& n
->flags
)
1603 term_fontpush(p
, TERMFONT_BOLD
);
1605 p
->flags
|= TERMP_NOSPACE
;
1608 if (NODE_SYNPRETTY
& n
->flags
)
1613 termp_pp_pre(DECL_ARGS
)
1621 termp_skip_pre(DECL_ARGS
)
1628 termp_quote_pre(DECL_ARGS
)
1631 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1637 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1638 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1654 term_word(p
, "\\(lq");
1657 if (NULL
== n
->norm
->Es
||
1658 NULL
== n
->norm
->Es
->child
)
1660 term_word(p
, n
->norm
->Es
->child
->string
);
1673 term_word(p
, "\\(oq");
1679 p
->flags
|= TERMP_NOSPACE
;
1684 termp_quote_post(DECL_ARGS
)
1687 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1690 p
->flags
|= TERMP_NOSPACE
;
1695 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1696 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1712 term_word(p
, "\\(rq");
1715 if (n
->norm
->Es
== NULL
||
1716 n
->norm
->Es
->child
== NULL
||
1717 n
->norm
->Es
->child
->next
== NULL
)
1718 p
->flags
&= ~TERMP_NOSPACE
;
1720 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1733 term_word(p
, "\\(cq");
1741 termp_eo_pre(DECL_ARGS
)
1744 if (n
->type
!= ROFFT_BODY
)
1747 if (n
->end
== ENDBODY_NOT
&&
1748 n
->parent
->head
->child
== NULL
&&
1750 n
->child
->end
!= ENDBODY_NOT
)
1751 term_word(p
, "\\&");
1752 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1753 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1754 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1755 p
->flags
|= TERMP_NOSPACE
;
1761 termp_eo_post(DECL_ARGS
)
1765 if (n
->type
!= ROFFT_BODY
)
1768 if (n
->end
!= ENDBODY_NOT
) {
1769 p
->flags
&= ~TERMP_NOSPACE
;
1773 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1774 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1777 p
->flags
|= TERMP_NOSPACE
;
1778 else if ( ! (body
|| tail
))
1779 term_word(p
, "\\&");
1781 p
->flags
&= ~TERMP_NOSPACE
;
1785 termp_fo_pre(DECL_ARGS
)
1790 pretty
= NODE_SYNPRETTY
& n
->flags
;
1792 if (n
->type
== ROFFT_BLOCK
) {
1795 } else if (n
->type
== ROFFT_BODY
) {
1797 rmargin
= p
->tcol
->rmargin
;
1798 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1799 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1802 p
->flags
|= TERMP_NOSPACE
;
1804 p
->flags
|= TERMP_NOSPACE
;
1807 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1809 p
->flags
|= TERMP_NOPAD
;
1810 p
->tcol
->offset
= p
->tcol
->rmargin
;
1811 p
->tcol
->rmargin
= rmargin
;
1816 if (NULL
== n
->child
)
1819 /* XXX: we drop non-initial arguments as per groff. */
1821 assert(n
->child
->string
);
1822 term_fontpush(p
, TERMFONT_BOLD
);
1823 term_word(p
, n
->child
->string
);
1828 termp_fo_post(DECL_ARGS
)
1831 if (n
->type
!= ROFFT_BODY
)
1834 p
->flags
|= TERMP_NOSPACE
;
1837 if (NODE_SYNPRETTY
& n
->flags
) {
1838 p
->flags
|= TERMP_NOSPACE
;
1845 termp_bf_pre(DECL_ARGS
)
1848 if (n
->type
== ROFFT_HEAD
)
1850 else if (n
->type
!= ROFFT_BODY
)
1853 if (FONT_Em
== n
->norm
->Bf
.font
)
1854 term_fontpush(p
, TERMFONT_UNDER
);
1855 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1856 term_fontpush(p
, TERMFONT_BOLD
);
1858 term_fontpush(p
, TERMFONT_NONE
);
1864 termp_sm_pre(DECL_ARGS
)
1867 if (NULL
== n
->child
)
1868 p
->flags
^= TERMP_NONOSPACE
;
1869 else if (0 == strcmp("on", n
->child
->string
))
1870 p
->flags
&= ~TERMP_NONOSPACE
;
1872 p
->flags
|= TERMP_NONOSPACE
;
1874 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
1875 p
->flags
&= ~TERMP_NOSPACE
;
1881 termp_ap_pre(DECL_ARGS
)
1884 p
->flags
|= TERMP_NOSPACE
;
1886 p
->flags
|= TERMP_NOSPACE
;
1891 termp____post(DECL_ARGS
)
1895 * Handle lists of authors. In general, print each followed by
1896 * a comma. Don't print the comma if there are only two
1899 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1900 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1901 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1906 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1909 p
->flags
|= TERMP_NOSPACE
;
1910 if (NULL
== n
->next
) {
1912 p
->flags
|= TERMP_SENTENCE
;
1918 termp_li_pre(DECL_ARGS
)
1921 termp_tag_pre(p
, pair
, meta
, n
);
1922 term_fontpush(p
, TERMFONT_NONE
);
1927 termp_lk_pre(DECL_ARGS
)
1929 const struct roff_node
*link
, *descr
, *punct
;
1931 if ((link
= n
->child
) == NULL
)
1934 /* Find beginning of trailing punctuation. */
1936 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1937 punct
= punct
->prev
;
1938 punct
= punct
->next
;
1941 if ((descr
= link
->next
) != NULL
&& descr
!= punct
) {
1942 term_fontpush(p
, TERMFONT_UNDER
);
1943 while (descr
!= punct
) {
1944 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1945 p
->flags
|= TERMP_NOSPACE
;
1946 term_word(p
, descr
->string
);
1947 descr
= descr
->next
;
1950 p
->flags
|= TERMP_NOSPACE
;
1955 term_fontpush(p
, TERMFONT_BOLD
);
1956 term_word(p
, link
->string
);
1959 /* Trailing punctuation. */
1960 while (punct
!= NULL
) {
1961 p
->flags
|= TERMP_NOSPACE
;
1962 term_word(p
, punct
->string
);
1963 punct
= punct
->next
;
1969 termp_bk_pre(DECL_ARGS
)
1978 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1979 p
->flags
|= TERMP_PREKEEP
;
1989 termp_bk_post(DECL_ARGS
)
1992 if (n
->type
== ROFFT_BODY
)
1993 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1997 termp__t_post(DECL_ARGS
)
2001 * If we're in an `Rs' and there's a journal present, then quote
2002 * us instead of underlining us (for disambiguation).
2004 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2005 n
->parent
->norm
->Rs
.quote_T
)
2006 termp_quote_post(p
, pair
, meta
, n
);
2008 termp____post(p
, pair
, meta
, n
);
2012 termp__t_pre(DECL_ARGS
)
2016 * If we're in an `Rs' and there's a journal present, then quote
2017 * us instead of underlining us (for disambiguation).
2019 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2020 n
->parent
->norm
->Rs
.quote_T
)
2021 return termp_quote_pre(p
, pair
, meta
, n
);
2023 term_fontpush(p
, TERMFONT_UNDER
);
2028 termp_under_pre(DECL_ARGS
)
2031 term_fontpush(p
, TERMFONT_UNDER
);
2036 termp_em_pre(DECL_ARGS
)
2038 if (n
->child
!= NULL
&&
2039 n
->child
->type
== ROFFT_TEXT
)
2040 tag_put(n
->child
->string
, 0, p
->line
);
2041 term_fontpush(p
, TERMFONT_UNDER
);
2046 termp_sy_pre(DECL_ARGS
)
2048 if (n
->child
!= NULL
&&
2049 n
->child
->type
== ROFFT_TEXT
)
2050 tag_put(n
->child
->string
, 0, p
->line
);
2051 term_fontpush(p
, TERMFONT_BOLD
);
2056 termp_er_pre(DECL_ARGS
)
2059 if (n
->sec
== SEC_ERRORS
&&
2060 (n
->parent
->tok
== MDOC_It
||
2061 (n
->parent
->tok
== MDOC_Bq
&&
2062 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2063 tag_put(n
->child
->string
, 1, p
->line
);
2068 termp_tag_pre(DECL_ARGS
)
2071 if (n
->child
!= NULL
&&
2072 n
->child
->type
== ROFFT_TEXT
&&
2074 (n
->prev
->type
== ROFFT_TEXT
&&
2075 strcmp(n
->prev
->string
, "|") == 0)) &&
2076 (n
->parent
->tok
== MDOC_It
||
2077 (n
->parent
->tok
== MDOC_Xo
&&
2078 n
->parent
->parent
->prev
== NULL
&&
2079 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2080 tag_put(n
->child
->string
, 1, p
->line
);
2085 termp_abort_pre(DECL_ARGS
)