1 /* $Id: mdoc_term.c,v 1.369 2018/12/03 21:00:11 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2018 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"
41 struct termpair
*ppair
;
45 #define DECL_ARGS struct termp *p, \
46 struct termpair *pair, \
47 const struct roff_meta *meta, \
50 struct mdoc_term_act
{
51 int (*pre
)(DECL_ARGS
);
52 void (*post
)(DECL_ARGS
);
55 static int a2width(const struct termp
*, const char *);
57 static void print_bvspace(struct termp
*,
58 const struct roff_node
*,
59 const struct roff_node
*);
60 static void print_mdoc_node(DECL_ARGS
);
61 static void print_mdoc_nodelist(DECL_ARGS
);
62 static void print_mdoc_head(struct termp
*, const struct roff_meta
*);
63 static void print_mdoc_foot(struct termp
*, const struct roff_meta
*);
64 static void synopsis_pre(struct termp
*,
65 const 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_cd_pre(DECL_ARGS
);
96 static int termp_d1_pre(DECL_ARGS
);
97 static int termp_eo_pre(DECL_ARGS
);
98 static int termp_em_pre(DECL_ARGS
);
99 static int termp_er_pre(DECL_ARGS
);
100 static int termp_ex_pre(DECL_ARGS
);
101 static int termp_fa_pre(DECL_ARGS
);
102 static int termp_fd_pre(DECL_ARGS
);
103 static int termp_fl_pre(DECL_ARGS
);
104 static int termp_fn_pre(DECL_ARGS
);
105 static int termp_fo_pre(DECL_ARGS
);
106 static int termp_ft_pre(DECL_ARGS
);
107 static int termp_in_pre(DECL_ARGS
);
108 static int termp_it_pre(DECL_ARGS
);
109 static int termp_li_pre(DECL_ARGS
);
110 static int termp_lk_pre(DECL_ARGS
);
111 static int termp_nd_pre(DECL_ARGS
);
112 static int termp_nm_pre(DECL_ARGS
);
113 static int termp_ns_pre(DECL_ARGS
);
114 static int termp_quote_pre(DECL_ARGS
);
115 static int termp_rs_pre(DECL_ARGS
);
116 static int termp_sh_pre(DECL_ARGS
);
117 static int termp_skip_pre(DECL_ARGS
);
118 static int termp_sm_pre(DECL_ARGS
);
119 static int termp_pp_pre(DECL_ARGS
);
120 static int termp_ss_pre(DECL_ARGS
);
121 static int termp_sy_pre(DECL_ARGS
);
122 static int termp_tag_pre(DECL_ARGS
);
123 static int termp_under_pre(DECL_ARGS
);
124 static int termp_vt_pre(DECL_ARGS
);
125 static int termp_xr_pre(DECL_ARGS
);
126 static int termp_xx_pre(DECL_ARGS
);
128 static const struct mdoc_term_act mdoc_term_acts
[MDOC_MAX
- MDOC_Dd
] = {
129 { NULL
, NULL
}, /* Dd */
130 { NULL
, NULL
}, /* Dt */
131 { NULL
, NULL
}, /* Os */
132 { termp_sh_pre
, termp_sh_post
}, /* Sh */
133 { termp_ss_pre
, termp_ss_post
}, /* Ss */
134 { termp_pp_pre
, NULL
}, /* Pp */
135 { termp_d1_pre
, termp_bl_post
}, /* D1 */
136 { termp_d1_pre
, termp_bl_post
}, /* Dl */
137 { termp_bd_pre
, termp_bd_post
}, /* Bd */
138 { NULL
, NULL
}, /* Ed */
139 { termp_bl_pre
, termp_bl_post
}, /* Bl */
140 { NULL
, NULL
}, /* El */
141 { termp_it_pre
, termp_it_post
}, /* It */
142 { termp_under_pre
, NULL
}, /* Ad */
143 { termp_an_pre
, NULL
}, /* An */
144 { termp_ap_pre
, NULL
}, /* Ap */
145 { termp_under_pre
, NULL
}, /* Ar */
146 { termp_cd_pre
, NULL
}, /* Cd */
147 { termp_bold_pre
, NULL
}, /* Cm */
148 { termp_li_pre
, NULL
}, /* Dv */
149 { termp_er_pre
, NULL
}, /* Er */
150 { termp_tag_pre
, NULL
}, /* Ev */
151 { termp_ex_pre
, NULL
}, /* Ex */
152 { termp_fa_pre
, NULL
}, /* Fa */
153 { termp_fd_pre
, termp_fd_post
}, /* Fd */
154 { termp_fl_pre
, NULL
}, /* Fl */
155 { termp_fn_pre
, NULL
}, /* Fn */
156 { termp_ft_pre
, NULL
}, /* Ft */
157 { termp_bold_pre
, NULL
}, /* Ic */
158 { termp_in_pre
, termp_in_post
}, /* In */
159 { termp_li_pre
, NULL
}, /* Li */
160 { termp_nd_pre
, NULL
}, /* Nd */
161 { termp_nm_pre
, termp_nm_post
}, /* Nm */
162 { termp_quote_pre
, termp_quote_post
}, /* Op */
163 { termp_abort_pre
, NULL
}, /* Ot */
164 { termp_under_pre
, NULL
}, /* Pa */
165 { termp_ex_pre
, NULL
}, /* Rv */
166 { NULL
, NULL
}, /* St */
167 { termp_under_pre
, NULL
}, /* Va */
168 { termp_vt_pre
, NULL
}, /* Vt */
169 { termp_xr_pre
, NULL
}, /* Xr */
170 { termp__a_pre
, termp____post
}, /* %A */
171 { termp_under_pre
, termp____post
}, /* %B */
172 { NULL
, termp____post
}, /* %D */
173 { termp_under_pre
, termp____post
}, /* %I */
174 { termp_under_pre
, termp____post
}, /* %J */
175 { NULL
, termp____post
}, /* %N */
176 { NULL
, termp____post
}, /* %O */
177 { NULL
, termp____post
}, /* %P */
178 { NULL
, termp____post
}, /* %R */
179 { termp__t_pre
, termp__t_post
}, /* %T */
180 { NULL
, termp____post
}, /* %V */
181 { NULL
, NULL
}, /* Ac */
182 { termp_quote_pre
, termp_quote_post
}, /* Ao */
183 { termp_quote_pre
, termp_quote_post
}, /* Aq */
184 { NULL
, NULL
}, /* At */
185 { NULL
, NULL
}, /* Bc */
186 { termp_bf_pre
, NULL
}, /* Bf */
187 { termp_quote_pre
, termp_quote_post
}, /* Bo */
188 { termp_quote_pre
, termp_quote_post
}, /* Bq */
189 { termp_xx_pre
, termp_xx_post
}, /* Bsx */
190 { NULL
, NULL
}, /* Bx */
191 { termp_skip_pre
, NULL
}, /* Db */
192 { NULL
, NULL
}, /* Dc */
193 { termp_quote_pre
, termp_quote_post
}, /* Do */
194 { termp_quote_pre
, termp_quote_post
}, /* Dq */
195 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
196 { NULL
, NULL
}, /* Ef */
197 { termp_em_pre
, NULL
}, /* Em */
198 { termp_eo_pre
, termp_eo_post
}, /* Eo */
199 { termp_xx_pre
, termp_xx_post
}, /* Fx */
200 { termp_bold_pre
, NULL
}, /* Ms */
201 { termp_li_pre
, NULL
}, /* No */
202 { termp_ns_pre
, NULL
}, /* Ns */
203 { termp_xx_pre
, termp_xx_post
}, /* Nx */
204 { termp_xx_pre
, termp_xx_post
}, /* Ox */
205 { NULL
, NULL
}, /* Pc */
206 { NULL
, termp_pf_post
}, /* Pf */
207 { termp_quote_pre
, termp_quote_post
}, /* Po */
208 { termp_quote_pre
, termp_quote_post
}, /* Pq */
209 { NULL
, NULL
}, /* Qc */
210 { termp_quote_pre
, termp_quote_post
}, /* Ql */
211 { termp_quote_pre
, termp_quote_post
}, /* Qo */
212 { termp_quote_pre
, termp_quote_post
}, /* Qq */
213 { NULL
, NULL
}, /* Re */
214 { termp_rs_pre
, NULL
}, /* Rs */
215 { NULL
, NULL
}, /* Sc */
216 { termp_quote_pre
, termp_quote_post
}, /* So */
217 { termp_quote_pre
, termp_quote_post
}, /* Sq */
218 { termp_sm_pre
, NULL
}, /* Sm */
219 { termp_under_pre
, NULL
}, /* Sx */
220 { termp_sy_pre
, NULL
}, /* Sy */
221 { NULL
, NULL
}, /* Tn */
222 { termp_xx_pre
, termp_xx_post
}, /* Ux */
223 { NULL
, NULL
}, /* Xc */
224 { NULL
, NULL
}, /* Xo */
225 { termp_fo_pre
, termp_fo_post
}, /* Fo */
226 { NULL
, NULL
}, /* Fc */
227 { termp_quote_pre
, termp_quote_post
}, /* Oo */
228 { NULL
, NULL
}, /* Oc */
229 { termp_bk_pre
, termp_bk_post
}, /* Bk */
230 { NULL
, NULL
}, /* Ek */
231 { NULL
, NULL
}, /* Bt */
232 { NULL
, NULL
}, /* Hf */
233 { termp_under_pre
, NULL
}, /* Fr */
234 { NULL
, NULL
}, /* Ud */
235 { NULL
, termp_lb_post
}, /* Lb */
236 { termp_abort_pre
, NULL
}, /* Lp */
237 { termp_lk_pre
, NULL
}, /* Lk */
238 { termp_under_pre
, NULL
}, /* Mt */
239 { termp_quote_pre
, termp_quote_post
}, /* Brq */
240 { termp_quote_pre
, termp_quote_post
}, /* Bro */
241 { NULL
, NULL
}, /* Brc */
242 { NULL
, termp____post
}, /* %C */
243 { termp_skip_pre
, NULL
}, /* Es */
244 { termp_quote_pre
, termp_quote_post
}, /* En */
245 { termp_xx_pre
, termp_xx_post
}, /* Dx */
246 { NULL
, termp____post
}, /* %Q */
247 { NULL
, termp____post
}, /* %U */
248 { NULL
, NULL
}, /* Ta */
255 terminal_mdoc(void *arg
, const struct roff_man
*mdoc
)
259 size_t save_defindent
;
261 p
= (struct termp
*)arg
;
262 p
->tcol
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
263 term_tab_set(p
, NULL
);
264 term_tab_set(p
, "T");
265 term_tab_set(p
, ".5i");
267 n
= mdoc
->first
->child
;
268 if (p
->synopsisonly
) {
270 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
271 if (n
->child
->next
->child
!= NULL
)
272 print_mdoc_nodelist(p
, NULL
,
274 n
->child
->next
->child
);
281 save_defindent
= p
->defindent
;
282 if (p
->defindent
== 0)
284 term_begin(p
, print_mdoc_head
, print_mdoc_foot
,
287 (n
->type
== ROFFT_COMMENT
||
288 n
->flags
& NODE_NOPRT
))
291 if (n
->tok
!= MDOC_Sh
)
293 print_mdoc_nodelist(p
, NULL
, &mdoc
->meta
, n
);
296 p
->defindent
= save_defindent
;
301 print_mdoc_nodelist(DECL_ARGS
)
305 print_mdoc_node(p
, pair
, meta
, n
);
311 print_mdoc_node(DECL_ARGS
)
313 const struct mdoc_term_act
*act
;
314 struct termpair npair
;
315 size_t offset
, rmargin
;
318 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
322 offset
= p
->tcol
->offset
;
323 rmargin
= p
->tcol
->rmargin
;
324 n
->flags
&= ~NODE_ENDED
;
325 n
->prev_font
= p
->fonti
;
327 memset(&npair
, 0, sizeof(struct termpair
));
331 * Keeps only work until the end of a line. If a keep was
332 * invoked in a prior line, revert it to PREKEEP.
335 if (p
->flags
& TERMP_KEEP
&& n
->flags
& NODE_LINE
) {
336 p
->flags
&= ~TERMP_KEEP
;
337 p
->flags
|= TERMP_PREKEEP
;
341 * After the keep flags have been set up, we may now
342 * produce output. Note that some pre-handlers do so.
347 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
348 (p
->flags
& TERMP_NONEWLINE
) == 0)
350 if (NODE_DELIMC
& n
->flags
)
351 p
->flags
|= TERMP_NOSPACE
;
352 term_word(p
, n
->string
);
353 if (NODE_DELIMO
& n
->flags
)
354 p
->flags
|= TERMP_NOSPACE
;
357 if ( ! (n
->flags
& NODE_LINE
))
358 p
->flags
|= TERMP_NOSPACE
;
360 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
361 p
->flags
|= TERMP_NOSPACE
;
364 if (p
->tbl
.cols
== NULL
)
366 term_tbl(p
, n
->span
);
369 if (n
->tok
< ROFF_MAX
) {
373 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
374 act
= mdoc_term_acts
+ (n
->tok
- MDOC_Dd
);
375 if (act
->pre
!= NULL
&&
376 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
377 chld
= (*act
->pre
)(p
, &npair
, meta
, n
);
381 if (chld
&& n
->child
)
382 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
385 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
395 if (act
->post
== NULL
|| n
->flags
& NODE_ENDED
)
397 (void)(*act
->post
)(p
, &npair
, meta
, n
);
400 * Explicit end tokens not only call the post
401 * handler, but also tell the respective block
402 * that it must not call the post handler again.
404 if (ENDBODY_NOT
!= n
->end
)
405 n
->body
->flags
|= NODE_ENDED
;
409 if (NODE_EOS
& n
->flags
)
410 p
->flags
|= TERMP_SENTENCE
;
412 if (n
->type
!= ROFFT_TEXT
)
413 p
->tcol
->offset
= offset
;
414 p
->tcol
->rmargin
= rmargin
;
418 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
422 term_fontrepl(p
, TERMFONT_NONE
);
425 * Output the footer in new-groff style, that is, three columns
426 * with the middle being the manual date and flanking columns
427 * being the operating system:
435 sz
= term_strlen(p
, meta
->date
);
436 p
->tcol
->rmargin
= p
->maxrmargin
> sz
?
437 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
439 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
441 term_word(p
, meta
->os
);
444 p
->tcol
->offset
= p
->tcol
->rmargin
;
445 sz
= term_strlen(p
, meta
->os
);
446 p
->tcol
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
447 p
->flags
|= TERMP_NOSPACE
;
449 term_word(p
, meta
->date
);
452 p
->tcol
->offset
= p
->tcol
->rmargin
;
453 p
->tcol
->rmargin
= p
->maxrmargin
;
455 p
->flags
&= ~TERMP_NOBREAK
;
456 p
->flags
|= TERMP_NOSPACE
;
458 term_word(p
, meta
->os
);
462 p
->tcol
->rmargin
= p
->maxrmargin
;
467 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
469 char *volume
, *title
;
470 size_t vollen
, titlen
;
473 * The header is strange. It has three components, which are
474 * really two with the first duplicated. It goes like this:
476 * IDENTIFIER TITLE IDENTIFIER
478 * The IDENTIFIER is NAME(SECTION), which is the command-name
479 * (if given, or "unknown" if not) followed by the manual page
480 * section. These are given in `Dt'. The TITLE is a free-form
481 * string depending on the manual volume. If not specified, it
482 * switches on the manual section.
486 if (NULL
== meta
->arch
)
487 volume
= mandoc_strdup(meta
->vol
);
489 mandoc_asprintf(&volume
, "%s (%s)",
490 meta
->vol
, meta
->arch
);
491 vollen
= term_strlen(p
, volume
);
493 if (NULL
== meta
->msec
)
494 title
= mandoc_strdup(meta
->title
);
496 mandoc_asprintf(&title
, "%s(%s)",
497 meta
->title
, meta
->msec
);
498 titlen
= term_strlen(p
, title
);
500 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
503 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
504 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
505 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
510 p
->flags
|= TERMP_NOSPACE
;
511 p
->tcol
->offset
= p
->tcol
->rmargin
;
512 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
513 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
515 term_word(p
, volume
);
518 p
->flags
&= ~TERMP_NOBREAK
;
520 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
521 p
->flags
|= TERMP_NOSPACE
;
522 p
->tcol
->offset
= p
->tcol
->rmargin
;
523 p
->tcol
->rmargin
= p
->maxrmargin
;
528 p
->flags
&= ~TERMP_NOSPACE
;
530 p
->tcol
->rmargin
= p
->maxrmargin
;
536 a2width(const struct termp
*p
, const char *v
)
541 end
= a2roffsu(v
, &su
, SCALE_MAX
);
542 if (end
== NULL
|| *end
!= '\0') {
543 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
544 su
.scale
/= term_strlen(p
, "0");
546 return term_hen(p
, &su
);
550 * Determine how much space to print out before block elements of `It'
551 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
555 print_bvspace(struct termp
*p
,
556 const struct roff_node
*bl
,
557 const struct roff_node
*n
)
559 const struct roff_node
*nn
;
565 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
567 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
570 /* Do not vspace directly after Ss/Sh. */
573 while (nn
->prev
!= NULL
&&
574 (nn
->prev
->type
== ROFFT_COMMENT
||
575 nn
->prev
->flags
& NODE_NOPRT
))
577 while (nn
->prev
== NULL
) {
580 if (nn
->type
== ROFFT_ROOT
)
582 } while (nn
->type
!= ROFFT_BLOCK
);
583 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
585 if (nn
->tok
== MDOC_It
&&
586 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
590 /* A `-column' does not assert vspace within the list. */
592 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
593 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
596 /* A `-diag' without body does not vspace. */
598 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
599 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
600 assert(n
->prev
->body
);
601 if (NULL
== n
->prev
->body
->child
)
610 termp_it_pre(DECL_ARGS
)
614 const struct roff_node
*bl
, *nn
;
616 int i
, offset
, width
;
619 if (n
->type
== ROFFT_BLOCK
) {
620 print_bvspace(p
, n
->parent
->parent
, n
);
624 bl
= n
->parent
->parent
->parent
;
625 type
= bl
->norm
->Bl
.type
;
628 * Defaults for specific list types.
636 width
= term_len(p
, 2);
640 width
= term_len(p
, 8);
643 width
= term_len(p
, 10);
652 * First calculate width and offset. This is pretty easy unless
653 * we're a -column list, in which case all prior columns must
657 if (bl
->norm
->Bl
.offs
!= NULL
) {
658 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
659 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
660 offset
= -p
->tcol
->offset
;
661 else if (offset
> SHRT_MAX
)
667 if (n
->type
== ROFFT_HEAD
)
671 * Imitate groff's column handling:
672 * - For each earlier column, add its width.
673 * - For less than 5 columns, add four more blanks per
675 * - For exactly 5 columns, add three more blank per
677 * - For more than 5 columns, add only one column.
679 ncols
= bl
->norm
->Bl
.ncols
;
680 dcol
= ncols
< 5 ? term_len(p
, 4) :
681 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
684 * Calculate the offset by applying all prior ROFFT_BODY,
685 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
688 for (i
= 0, nn
= n
->prev
;
689 nn
->prev
&& i
< (int)ncols
;
690 nn
= nn
->prev
, i
++) {
692 term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
693 su
.scale
/= term_strlen(p
, "0");
694 offset
+= term_hen(p
, &su
) + dcol
;
698 * When exceeding the declared number of columns, leave
699 * the remaining widths at 0. This will later be
700 * adjusted to the default width of 10, or, for the last
701 * column, stretched to the right margin.
707 * Use the declared column widths, extended as explained
708 * in the preceding paragraph.
710 SCALE_HS_INIT(&su
, term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
711 su
.scale
/= term_strlen(p
, "0");
712 width
= term_hen(p
, &su
) + dcol
;
715 if (NULL
== bl
->norm
->Bl
.width
)
719 * Note: buffer the width by 2, which is groff's magic
720 * number for buffering single arguments. See the above
721 * handling for column for how this changes.
723 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
724 if (width
< 0 && (size_t)(-width
) > p
->tcol
->offset
)
725 width
= -p
->tcol
->offset
;
726 else if (width
> SHRT_MAX
)
732 * Whitespace control. Inset bodies need an initial space,
733 * while diagonal bodies need two.
736 p
->flags
|= TERMP_NOSPACE
;
740 if (n
->type
== ROFFT_BODY
)
741 term_word(p
, "\\ \\ ");
744 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
751 p
->flags
|= TERMP_NOSPACE
;
755 if (n
->type
== ROFFT_HEAD
)
756 term_fontpush(p
, TERMFONT_BOLD
);
763 * Pad and break control. This is the tricky part. These flags
764 * are documented in term_flushln() in term.c. Note that we're
765 * going to unset all of these flags in termp_it_post() when we
774 if (n
->type
== ROFFT_HEAD
) {
775 p
->flags
|= TERMP_NOBREAK
| TERMP_HANG
;
777 } else if (width
<= (int)term_len(p
, 2))
778 p
->flags
|= TERMP_NOPAD
;
781 if (n
->type
!= ROFFT_HEAD
)
783 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
787 if (n
->type
!= ROFFT_HEAD
)
790 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
793 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
794 p
->flags
|= TERMP_HANG
;
797 if (n
->type
== ROFFT_HEAD
)
800 if (NULL
== n
->next
) {
801 p
->flags
&= ~TERMP_NOBREAK
;
804 p
->flags
|= TERMP_NOBREAK
;
810 if (n
->type
!= ROFFT_HEAD
)
812 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
820 * Margin control. Set-head-width lists have their right
821 * margins shortened. The body for these lists has the offset
822 * necessarily lengthened. Everybody gets the offset.
825 p
->tcol
->offset
+= offset
;
834 if (n
->type
== ROFFT_HEAD
)
835 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
837 p
->tcol
->offset
+= width
;
841 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
843 * XXX - this behaviour is not documented: the
844 * right-most column is filled to the right margin.
846 if (n
->type
== ROFFT_HEAD
)
848 if (n
->next
== NULL
&& p
->tcol
->rmargin
< p
->maxrmargin
)
849 p
->tcol
->rmargin
= p
->maxrmargin
;
856 * The dash, hyphen, bullet and enum lists all have a special
857 * HEAD character (temporarily bold, in some cases).
860 if (n
->type
== ROFFT_HEAD
)
863 term_fontpush(p
, TERMFONT_BOLD
);
864 term_word(p
, "\\[bu]");
869 term_fontpush(p
, TERMFONT_BOLD
);
874 (pair
->ppair
->ppair
->count
)++;
875 (void)snprintf(buf
, sizeof(buf
), "%d.",
876 pair
->ppair
->ppair
->count
);
884 * If we're not going to process our children, indicate so here.
893 if (n
->type
== ROFFT_HEAD
)
897 if (n
->type
== ROFFT_HEAD
)
909 termp_it_post(DECL_ARGS
)
913 if (n
->type
== ROFFT_BLOCK
)
916 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
922 if (n
->type
== ROFFT_BODY
)
926 if (n
->type
== ROFFT_BODY
)
935 * Now that our output is flushed, we can reset our tags. Since
936 * only `It' sets these flags, we're free to assume that nobody
937 * has munged them in the meanwhile.
940 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
| TERMP_HANG
);
945 termp_nm_pre(DECL_ARGS
)
949 if (n
->type
== ROFFT_BLOCK
) {
950 p
->flags
|= TERMP_PREKEEP
;
954 if (n
->type
== ROFFT_BODY
) {
955 if (n
->child
== NULL
)
957 p
->flags
|= TERMP_NOSPACE
;
959 if (n
->prev
->child
!= NULL
)
960 cp
= n
->prev
->child
->string
;
964 p
->tcol
->offset
+= term_len(p
, 6);
966 p
->tcol
->offset
+= term_len(p
, 1) +
971 if (n
->child
== NULL
)
974 if (n
->type
== ROFFT_HEAD
)
975 synopsis_pre(p
, n
->parent
);
977 if (n
->type
== ROFFT_HEAD
&&
978 n
->next
!= NULL
&& n
->next
->child
!= NULL
) {
979 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
981 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 1);
982 if (n
->child
== NULL
)
983 p
->tcol
->rmargin
+= term_strlen(p
, meta
->name
);
984 else if (n
->child
->type
== ROFFT_TEXT
) {
985 p
->tcol
->rmargin
+= term_strlen(p
, n
->child
->string
);
986 if (n
->child
->next
!= NULL
)
987 p
->flags
|= TERMP_HANG
;
989 p
->tcol
->rmargin
+= term_len(p
, 5);
990 p
->flags
|= TERMP_HANG
;
994 term_fontpush(p
, TERMFONT_BOLD
);
999 termp_nm_post(DECL_ARGS
)
1002 if (n
->type
== ROFFT_BLOCK
) {
1003 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1004 } else if (n
->type
== ROFFT_HEAD
&&
1005 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1007 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1009 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1014 termp_fl_pre(DECL_ARGS
)
1017 termp_tag_pre(p
, pair
, meta
, n
);
1018 term_fontpush(p
, TERMFONT_BOLD
);
1019 term_word(p
, "\\-");
1021 if (!(n
->child
== NULL
&&
1023 n
->next
->type
== ROFFT_TEXT
||
1024 n
->next
->flags
& NODE_LINE
)))
1025 p
->flags
|= TERMP_NOSPACE
;
1031 termp__a_pre(DECL_ARGS
)
1034 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1035 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1036 term_word(p
, "and");
1042 termp_an_pre(DECL_ARGS
)
1045 if (n
->norm
->An
.auth
== AUTH_split
) {
1046 p
->flags
&= ~TERMP_NOSPLIT
;
1047 p
->flags
|= TERMP_SPLIT
;
1050 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1051 p
->flags
&= ~TERMP_SPLIT
;
1052 p
->flags
|= TERMP_NOSPLIT
;
1056 if (p
->flags
& TERMP_SPLIT
)
1059 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1060 p
->flags
|= TERMP_SPLIT
;
1066 termp_ns_pre(DECL_ARGS
)
1069 if ( ! (NODE_LINE
& n
->flags
))
1070 p
->flags
|= TERMP_NOSPACE
;
1075 termp_rs_pre(DECL_ARGS
)
1078 if (SEC_SEE_ALSO
!= n
->sec
)
1080 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1086 termp_ex_pre(DECL_ARGS
)
1093 termp_nd_pre(DECL_ARGS
)
1096 if (n
->type
== ROFFT_BODY
)
1097 term_word(p
, "\\(en");
1102 termp_bl_pre(DECL_ARGS
)
1105 return n
->type
!= ROFFT_HEAD
;
1109 termp_bl_post(DECL_ARGS
)
1112 if (n
->type
!= ROFFT_BLOCK
)
1115 if (n
->tok
!= MDOC_Bl
|| n
->norm
->Bl
.type
!= LIST_column
)
1117 term_tab_set(p
, NULL
);
1118 term_tab_set(p
, "T");
1119 term_tab_set(p
, ".5i");
1123 termp_xr_pre(DECL_ARGS
)
1126 if (NULL
== (n
= n
->child
))
1129 assert(n
->type
== ROFFT_TEXT
);
1130 term_word(p
, n
->string
);
1132 if (NULL
== (n
= n
->next
))
1135 p
->flags
|= TERMP_NOSPACE
;
1137 p
->flags
|= TERMP_NOSPACE
;
1139 assert(n
->type
== ROFFT_TEXT
);
1140 term_word(p
, n
->string
);
1142 p
->flags
|= TERMP_NOSPACE
;
1149 * This decides how to assert whitespace before any of the SYNOPSIS set
1150 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1154 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1157 * Obviously, if we're not in a SYNOPSIS or no prior macros
1158 * exist, do nothing.
1160 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
1164 * If we're the second in a pair of like elements, emit our
1165 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1166 * case we soldier on.
1168 if (n
->prev
->tok
== n
->tok
&&
1169 MDOC_Ft
!= n
->tok
&&
1170 MDOC_Fo
!= n
->tok
&&
1171 MDOC_Fn
!= n
->tok
) {
1177 * If we're one of the SYNOPSIS set and non-like pair-wise after
1178 * another (or Fn/Fo, which we've let slip through) then assert
1179 * vertical space, else only newline and move on.
1181 switch (n
->prev
->tok
) {
1190 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1202 termp_vt_pre(DECL_ARGS
)
1205 if (n
->type
== ROFFT_ELEM
) {
1207 return termp_under_pre(p
, pair
, meta
, n
);
1208 } else if (n
->type
== ROFFT_BLOCK
) {
1211 } else if (n
->type
== ROFFT_HEAD
)
1214 return termp_under_pre(p
, pair
, meta
, n
);
1218 termp_bold_pre(DECL_ARGS
)
1221 termp_tag_pre(p
, pair
, meta
, n
);
1222 term_fontpush(p
, TERMFONT_BOLD
);
1227 termp_fd_pre(DECL_ARGS
)
1231 return termp_bold_pre(p
, pair
, meta
, n
);
1235 termp_fd_post(DECL_ARGS
)
1242 termp_sh_pre(DECL_ARGS
)
1248 * Vertical space before sections, except
1249 * when the previous section was empty.
1251 if (n
->prev
== NULL
||
1252 n
->prev
->tok
!= MDOC_Sh
||
1253 (n
->prev
->body
!= NULL
&&
1254 n
->prev
->body
->child
!= NULL
))
1258 term_fontpush(p
, TERMFONT_BOLD
);
1261 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1262 term_tab_set(p
, NULL
);
1263 term_tab_set(p
, "T");
1264 term_tab_set(p
, ".5i");
1266 case SEC_DESCRIPTION
:
1270 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1283 termp_sh_post(DECL_ARGS
)
1292 p
->tcol
->offset
= 0;
1300 termp_lb_post(DECL_ARGS
)
1303 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
)
1308 termp_d1_pre(DECL_ARGS
)
1311 if (n
->type
!= ROFFT_BLOCK
)
1314 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1315 term_tab_set(p
, NULL
);
1316 term_tab_set(p
, "T");
1317 term_tab_set(p
, ".5i");
1322 termp_ft_pre(DECL_ARGS
)
1325 /* NB: NODE_LINE does not effect this! */
1327 term_fontpush(p
, TERMFONT_UNDER
);
1332 termp_fn_pre(DECL_ARGS
)
1337 pretty
= NODE_SYNPRETTY
& n
->flags
;
1341 if (NULL
== (n
= n
->child
))
1345 rmargin
= p
->tcol
->rmargin
;
1346 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1347 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1350 assert(n
->type
== ROFFT_TEXT
);
1351 term_fontpush(p
, TERMFONT_BOLD
);
1352 term_word(p
, n
->string
);
1355 if (n
->sec
== SEC_DESCRIPTION
|| n
->sec
== SEC_CUSTOM
)
1356 tag_put(n
->string
, ++fn_prio
, p
->line
);
1360 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1361 p
->flags
|= TERMP_NOPAD
;
1362 p
->tcol
->offset
= p
->tcol
->rmargin
;
1363 p
->tcol
->rmargin
= rmargin
;
1366 p
->flags
|= TERMP_NOSPACE
;
1368 p
->flags
|= TERMP_NOSPACE
;
1370 for (n
= n
->next
; n
; n
= n
->next
) {
1371 assert(n
->type
== ROFFT_TEXT
);
1372 term_fontpush(p
, TERMFONT_UNDER
);
1374 p
->flags
|= TERMP_NBRWORD
;
1375 term_word(p
, n
->string
);
1379 p
->flags
|= TERMP_NOSPACE
;
1384 p
->flags
|= TERMP_NOSPACE
;
1388 p
->flags
|= TERMP_NOSPACE
;
1397 termp_fa_pre(DECL_ARGS
)
1399 const struct roff_node
*nn
;
1401 if (n
->parent
->tok
!= MDOC_Fo
) {
1402 term_fontpush(p
, TERMFONT_UNDER
);
1406 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1407 term_fontpush(p
, TERMFONT_UNDER
);
1408 p
->flags
|= TERMP_NBRWORD
;
1409 term_word(p
, nn
->string
);
1412 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1413 p
->flags
|= TERMP_NOSPACE
;
1422 termp_bd_pre(DECL_ARGS
)
1425 struct roff_node
*nn
;
1428 if (n
->type
== ROFFT_BLOCK
) {
1429 print_bvspace(p
, n
, n
);
1431 } else if (n
->type
== ROFFT_HEAD
)
1434 /* Handle the -offset argument. */
1436 if (n
->norm
->Bd
.offs
== NULL
||
1437 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1439 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1440 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1441 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1442 p
->tcol
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1444 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1445 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
1446 p
->tcol
->offset
= 0;
1447 else if (offset
< SHRT_MAX
)
1448 p
->tcol
->offset
+= offset
;
1452 * If -ragged or -filled are specified, the block does nothing
1453 * but change the indentation. If -unfilled or -literal are
1454 * specified, text is printed exactly as entered in the display:
1455 * for macro lines, a newline is appended to the line. Blank
1456 * lines are allowed.
1459 if (n
->norm
->Bd
.type
!= DISP_literal
&&
1460 n
->norm
->Bd
.type
!= DISP_unfilled
&&
1461 n
->norm
->Bd
.type
!= DISP_centered
)
1464 if (n
->norm
->Bd
.type
== DISP_literal
) {
1465 term_tab_set(p
, NULL
);
1466 term_tab_set(p
, "T");
1467 term_tab_set(p
, "8n");
1470 lm
= p
->tcol
->offset
;
1471 p
->flags
|= TERMP_BRNEVER
;
1472 for (nn
= n
->child
; nn
!= NULL
; nn
= nn
->next
) {
1473 if (n
->norm
->Bd
.type
== DISP_centered
) {
1474 if (nn
->type
== ROFFT_TEXT
) {
1475 len
= term_strlen(p
, nn
->string
);
1476 p
->tcol
->offset
= len
>= p
->tcol
->rmargin
?
1477 0 : lm
+ len
>= p
->tcol
->rmargin
?
1478 p
->tcol
->rmargin
- len
:
1479 (lm
+ p
->tcol
->rmargin
- len
) / 2;
1481 p
->tcol
->offset
= lm
;
1483 print_mdoc_node(p
, pair
, meta
, nn
);
1485 * If the printed node flushes its own line, then we
1486 * needn't do it here as well. This is hacky, but the
1487 * notion of selective eoln whitespace is pretty dumb
1488 * anyway, so don't sweat it.
1490 if (nn
->tok
< ROFF_MAX
)
1502 if (p
->flags
& TERMP_NONEWLINE
||
1503 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1506 p
->flags
|= TERMP_NOSPACE
;
1508 p
->flags
&= ~TERMP_BRNEVER
;
1513 termp_bd_post(DECL_ARGS
)
1515 if (n
->type
!= ROFFT_BODY
)
1517 if (DISP_literal
== n
->norm
->Bd
.type
||
1518 DISP_unfilled
== n
->norm
->Bd
.type
)
1519 p
->flags
|= TERMP_BRNEVER
;
1520 p
->flags
|= TERMP_NOSPACE
;
1522 p
->flags
&= ~TERMP_BRNEVER
;
1526 termp_xx_pre(DECL_ARGS
)
1528 if ((n
->aux
= p
->flags
& TERMP_PREKEEP
) == 0)
1529 p
->flags
|= TERMP_PREKEEP
;
1534 termp_xx_post(DECL_ARGS
)
1537 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1541 termp_pf_post(DECL_ARGS
)
1544 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1545 p
->flags
|= TERMP_NOSPACE
;
1549 termp_ss_pre(DECL_ARGS
)
1551 struct roff_node
*nn
;
1556 for (nn
= n
->prev
; nn
!= NULL
; nn
= nn
->prev
)
1557 if (nn
->type
!= ROFFT_COMMENT
&&
1558 (nn
->flags
& NODE_NOPRT
) == 0)
1564 term_fontpush(p
, TERMFONT_BOLD
);
1565 p
->tcol
->offset
= term_len(p
, (p
->defindent
+1)/2);
1568 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1569 term_tab_set(p
, NULL
);
1570 term_tab_set(p
, "T");
1571 term_tab_set(p
, ".5i");
1581 termp_ss_post(DECL_ARGS
)
1584 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1589 termp_cd_pre(DECL_ARGS
)
1593 term_fontpush(p
, TERMFONT_BOLD
);
1598 termp_in_pre(DECL_ARGS
)
1603 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
) {
1604 term_fontpush(p
, TERMFONT_BOLD
);
1605 term_word(p
, "#include");
1609 term_fontpush(p
, TERMFONT_UNDER
);
1612 p
->flags
|= TERMP_NOSPACE
;
1617 termp_in_post(DECL_ARGS
)
1620 if (NODE_SYNPRETTY
& n
->flags
)
1621 term_fontpush(p
, TERMFONT_BOLD
);
1623 p
->flags
|= TERMP_NOSPACE
;
1626 if (NODE_SYNPRETTY
& n
->flags
)
1631 termp_pp_pre(DECL_ARGS
)
1639 termp_skip_pre(DECL_ARGS
)
1646 termp_quote_pre(DECL_ARGS
)
1649 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1655 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1656 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1672 term_word(p
, "\\(lq");
1675 if (NULL
== n
->norm
->Es
||
1676 NULL
== n
->norm
->Es
->child
)
1678 term_word(p
, n
->norm
->Es
->child
->string
);
1691 term_word(p
, "\\(oq");
1697 p
->flags
|= TERMP_NOSPACE
;
1702 termp_quote_post(DECL_ARGS
)
1705 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1708 p
->flags
|= TERMP_NOSPACE
;
1713 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1714 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1730 term_word(p
, "\\(rq");
1733 if (n
->norm
->Es
== NULL
||
1734 n
->norm
->Es
->child
== NULL
||
1735 n
->norm
->Es
->child
->next
== NULL
)
1736 p
->flags
&= ~TERMP_NOSPACE
;
1738 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1751 term_word(p
, "\\(cq");
1759 termp_eo_pre(DECL_ARGS
)
1762 if (n
->type
!= ROFFT_BODY
)
1765 if (n
->end
== ENDBODY_NOT
&&
1766 n
->parent
->head
->child
== NULL
&&
1768 n
->child
->end
!= ENDBODY_NOT
)
1769 term_word(p
, "\\&");
1770 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1771 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1772 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1773 p
->flags
|= TERMP_NOSPACE
;
1779 termp_eo_post(DECL_ARGS
)
1783 if (n
->type
!= ROFFT_BODY
)
1786 if (n
->end
!= ENDBODY_NOT
) {
1787 p
->flags
&= ~TERMP_NOSPACE
;
1791 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1792 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1795 p
->flags
|= TERMP_NOSPACE
;
1796 else if ( ! (body
|| tail
))
1797 term_word(p
, "\\&");
1799 p
->flags
&= ~TERMP_NOSPACE
;
1803 termp_fo_pre(DECL_ARGS
)
1808 pretty
= NODE_SYNPRETTY
& n
->flags
;
1810 if (n
->type
== ROFFT_BLOCK
) {
1813 } else if (n
->type
== ROFFT_BODY
) {
1815 rmargin
= p
->tcol
->rmargin
;
1816 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1817 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1820 p
->flags
|= TERMP_NOSPACE
;
1822 p
->flags
|= TERMP_NOSPACE
;
1825 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1827 p
->flags
|= TERMP_NOPAD
;
1828 p
->tcol
->offset
= p
->tcol
->rmargin
;
1829 p
->tcol
->rmargin
= rmargin
;
1834 if (NULL
== n
->child
)
1837 /* XXX: we drop non-initial arguments as per groff. */
1839 assert(n
->child
->string
);
1840 term_fontpush(p
, TERMFONT_BOLD
);
1841 term_word(p
, n
->child
->string
);
1846 termp_fo_post(DECL_ARGS
)
1849 if (n
->type
!= ROFFT_BODY
)
1852 p
->flags
|= TERMP_NOSPACE
;
1855 if (NODE_SYNPRETTY
& n
->flags
) {
1856 p
->flags
|= TERMP_NOSPACE
;
1863 termp_bf_pre(DECL_ARGS
)
1866 if (n
->type
== ROFFT_HEAD
)
1868 else if (n
->type
!= ROFFT_BODY
)
1871 if (FONT_Em
== n
->norm
->Bf
.font
)
1872 term_fontpush(p
, TERMFONT_UNDER
);
1873 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1874 term_fontpush(p
, TERMFONT_BOLD
);
1876 term_fontpush(p
, TERMFONT_NONE
);
1882 termp_sm_pre(DECL_ARGS
)
1885 if (NULL
== n
->child
)
1886 p
->flags
^= TERMP_NONOSPACE
;
1887 else if (0 == strcmp("on", n
->child
->string
))
1888 p
->flags
&= ~TERMP_NONOSPACE
;
1890 p
->flags
|= TERMP_NONOSPACE
;
1892 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
1893 p
->flags
&= ~TERMP_NOSPACE
;
1899 termp_ap_pre(DECL_ARGS
)
1902 p
->flags
|= TERMP_NOSPACE
;
1904 p
->flags
|= TERMP_NOSPACE
;
1909 termp____post(DECL_ARGS
)
1913 * Handle lists of authors. In general, print each followed by
1914 * a comma. Don't print the comma if there are only two
1917 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1918 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1919 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1924 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1927 p
->flags
|= TERMP_NOSPACE
;
1928 if (NULL
== n
->next
) {
1930 p
->flags
|= TERMP_SENTENCE
;
1936 termp_li_pre(DECL_ARGS
)
1939 termp_tag_pre(p
, pair
, meta
, n
);
1940 term_fontpush(p
, TERMFONT_NONE
);
1945 termp_lk_pre(DECL_ARGS
)
1947 const struct roff_node
*link
, *descr
, *punct
;
1949 if ((link
= n
->child
) == NULL
)
1952 /* Find beginning of trailing punctuation. */
1954 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1955 punct
= punct
->prev
;
1956 punct
= punct
->next
;
1959 if ((descr
= link
->next
) != NULL
&& descr
!= punct
) {
1960 term_fontpush(p
, TERMFONT_UNDER
);
1961 while (descr
!= punct
) {
1962 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1963 p
->flags
|= TERMP_NOSPACE
;
1964 term_word(p
, descr
->string
);
1965 descr
= descr
->next
;
1968 p
->flags
|= TERMP_NOSPACE
;
1973 term_fontpush(p
, TERMFONT_BOLD
);
1974 term_word(p
, link
->string
);
1977 /* Trailing punctuation. */
1978 while (punct
!= NULL
) {
1979 p
->flags
|= TERMP_NOSPACE
;
1980 term_word(p
, punct
->string
);
1981 punct
= punct
->next
;
1987 termp_bk_pre(DECL_ARGS
)
1996 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1997 p
->flags
|= TERMP_PREKEEP
;
2007 termp_bk_post(DECL_ARGS
)
2010 if (n
->type
== ROFFT_BODY
)
2011 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2015 termp__t_post(DECL_ARGS
)
2019 * If we're in an `Rs' and there's a journal present, then quote
2020 * us instead of underlining us (for disambiguation).
2022 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2023 n
->parent
->norm
->Rs
.quote_T
)
2024 termp_quote_post(p
, pair
, meta
, n
);
2026 termp____post(p
, pair
, meta
, n
);
2030 termp__t_pre(DECL_ARGS
)
2034 * If we're in an `Rs' and there's a journal present, then quote
2035 * us instead of underlining us (for disambiguation).
2037 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2038 n
->parent
->norm
->Rs
.quote_T
)
2039 return termp_quote_pre(p
, pair
, meta
, n
);
2041 term_fontpush(p
, TERMFONT_UNDER
);
2046 termp_under_pre(DECL_ARGS
)
2049 term_fontpush(p
, TERMFONT_UNDER
);
2054 termp_em_pre(DECL_ARGS
)
2056 if (n
->child
!= NULL
&&
2057 n
->child
->type
== ROFFT_TEXT
)
2058 tag_put(n
->child
->string
, 0, p
->line
);
2059 term_fontpush(p
, TERMFONT_UNDER
);
2064 termp_sy_pre(DECL_ARGS
)
2066 if (n
->child
!= NULL
&&
2067 n
->child
->type
== ROFFT_TEXT
)
2068 tag_put(n
->child
->string
, 0, p
->line
);
2069 term_fontpush(p
, TERMFONT_BOLD
);
2074 termp_er_pre(DECL_ARGS
)
2077 if (n
->sec
== SEC_ERRORS
&&
2078 (n
->parent
->tok
== MDOC_It
||
2079 (n
->parent
->tok
== MDOC_Bq
&&
2080 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2081 tag_put(n
->child
->string
, 1, p
->line
);
2086 termp_tag_pre(DECL_ARGS
)
2089 if (n
->child
!= NULL
&&
2090 n
->child
->type
== ROFFT_TEXT
&&
2092 (n
->prev
->type
== ROFFT_TEXT
&&
2093 strcmp(n
->prev
->string
, "|") == 0)) &&
2094 (n
->parent
->tok
== MDOC_It
||
2095 (n
->parent
->tok
== MDOC_Xo
&&
2096 n
->parent
->parent
->prev
== NULL
&&
2097 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2098 tag_put(n
->child
->string
, 1, p
->line
);
2103 termp_abort_pre(DECL_ARGS
)