1 /* $Id: mdoc_term.c,v 1.371 2018/12/30 00:49:55 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"
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
)
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
) {
269 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
270 if (n
->child
->next
->child
!= NULL
)
271 print_mdoc_nodelist(p
, NULL
,
272 mdoc
, n
->child
->next
->child
);
279 save_defindent
= p
->defindent
;
280 if (p
->defindent
== 0)
282 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, mdoc
);
284 (n
->type
== ROFFT_COMMENT
||
285 n
->flags
& NODE_NOPRT
))
288 if (n
->tok
!= MDOC_Sh
)
290 print_mdoc_nodelist(p
, NULL
, mdoc
, n
);
293 p
->defindent
= save_defindent
;
298 print_mdoc_nodelist(DECL_ARGS
)
302 print_mdoc_node(p
, pair
, meta
, n
);
308 print_mdoc_node(DECL_ARGS
)
310 const struct mdoc_term_act
*act
;
311 struct termpair npair
;
312 size_t offset
, rmargin
;
315 if (n
->type
== ROFFT_COMMENT
|| n
->flags
& NODE_NOPRT
)
319 offset
= p
->tcol
->offset
;
320 rmargin
= p
->tcol
->rmargin
;
321 n
->flags
&= ~NODE_ENDED
;
322 n
->prev_font
= p
->fonti
;
324 memset(&npair
, 0, sizeof(struct termpair
));
328 * Keeps only work until the end of a line. If a keep was
329 * invoked in a prior line, revert it to PREKEEP.
332 if (p
->flags
& TERMP_KEEP
&& n
->flags
& NODE_LINE
) {
333 p
->flags
&= ~TERMP_KEEP
;
334 p
->flags
|= TERMP_PREKEEP
;
338 * After the keep flags have been set up, we may now
339 * produce output. Note that some pre-handlers do so.
344 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
345 (p
->flags
& TERMP_NONEWLINE
) == 0)
347 if (NODE_DELIMC
& n
->flags
)
348 p
->flags
|= TERMP_NOSPACE
;
349 term_word(p
, n
->string
);
350 if (NODE_DELIMO
& n
->flags
)
351 p
->flags
|= TERMP_NOSPACE
;
354 if ( ! (n
->flags
& NODE_LINE
))
355 p
->flags
|= TERMP_NOSPACE
;
357 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
358 p
->flags
|= TERMP_NOSPACE
;
361 if (p
->tbl
.cols
== NULL
)
363 term_tbl(p
, n
->span
);
366 if (n
->tok
< ROFF_MAX
) {
370 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
371 act
= mdoc_term_acts
+ (n
->tok
- MDOC_Dd
);
372 if (act
->pre
!= NULL
&&
373 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
374 chld
= (*act
->pre
)(p
, &npair
, meta
, n
);
378 if (chld
&& n
->child
)
379 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
382 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
392 if (act
->post
== NULL
|| n
->flags
& NODE_ENDED
)
394 (void)(*act
->post
)(p
, &npair
, meta
, n
);
397 * Explicit end tokens not only call the post
398 * handler, but also tell the respective block
399 * that it must not call the post handler again.
401 if (ENDBODY_NOT
!= n
->end
)
402 n
->body
->flags
|= NODE_ENDED
;
406 if (NODE_EOS
& n
->flags
)
407 p
->flags
|= TERMP_SENTENCE
;
409 if (n
->type
!= ROFFT_TEXT
)
410 p
->tcol
->offset
= offset
;
411 p
->tcol
->rmargin
= rmargin
;
415 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
419 term_fontrepl(p
, TERMFONT_NONE
);
422 * Output the footer in new-groff style, that is, three columns
423 * with the middle being the manual date and flanking columns
424 * being the operating system:
432 sz
= term_strlen(p
, meta
->date
);
433 p
->tcol
->rmargin
= p
->maxrmargin
> sz
?
434 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
436 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
438 term_word(p
, meta
->os
);
441 p
->tcol
->offset
= p
->tcol
->rmargin
;
442 sz
= term_strlen(p
, meta
->os
);
443 p
->tcol
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
444 p
->flags
|= TERMP_NOSPACE
;
446 term_word(p
, meta
->date
);
449 p
->tcol
->offset
= p
->tcol
->rmargin
;
450 p
->tcol
->rmargin
= p
->maxrmargin
;
452 p
->flags
&= ~TERMP_NOBREAK
;
453 p
->flags
|= TERMP_NOSPACE
;
455 term_word(p
, meta
->os
);
459 p
->tcol
->rmargin
= p
->maxrmargin
;
464 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
466 char *volume
, *title
;
467 size_t vollen
, titlen
;
470 * The header is strange. It has three components, which are
471 * really two with the first duplicated. It goes like this:
473 * IDENTIFIER TITLE IDENTIFIER
475 * The IDENTIFIER is NAME(SECTION), which is the command-name
476 * (if given, or "unknown" if not) followed by the manual page
477 * section. These are given in `Dt'. The TITLE is a free-form
478 * string depending on the manual volume. If not specified, it
479 * switches on the manual section.
483 if (NULL
== meta
->arch
)
484 volume
= mandoc_strdup(meta
->vol
);
486 mandoc_asprintf(&volume
, "%s (%s)",
487 meta
->vol
, meta
->arch
);
488 vollen
= term_strlen(p
, volume
);
490 if (NULL
== meta
->msec
)
491 title
= mandoc_strdup(meta
->title
);
493 mandoc_asprintf(&title
, "%s(%s)",
494 meta
->title
, meta
->msec
);
495 titlen
= term_strlen(p
, title
);
497 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
500 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
501 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
502 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
507 p
->flags
|= TERMP_NOSPACE
;
508 p
->tcol
->offset
= p
->tcol
->rmargin
;
509 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
510 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
512 term_word(p
, volume
);
515 p
->flags
&= ~TERMP_NOBREAK
;
517 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
518 p
->flags
|= TERMP_NOSPACE
;
519 p
->tcol
->offset
= p
->tcol
->rmargin
;
520 p
->tcol
->rmargin
= p
->maxrmargin
;
525 p
->flags
&= ~TERMP_NOSPACE
;
527 p
->tcol
->rmargin
= p
->maxrmargin
;
533 a2width(const struct termp
*p
, const char *v
)
538 end
= a2roffsu(v
, &su
, SCALE_MAX
);
539 if (end
== NULL
|| *end
!= '\0') {
540 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
541 su
.scale
/= term_strlen(p
, "0");
543 return term_hen(p
, &su
);
547 * Determine how much space to print out before block elements of `It'
548 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
552 print_bvspace(struct termp
*p
,
553 const struct roff_node
*bl
,
554 const struct roff_node
*n
)
556 const struct roff_node
*nn
;
562 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
564 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
567 /* Do not vspace directly after Ss/Sh. */
570 while (nn
->prev
!= NULL
&&
571 (nn
->prev
->type
== ROFFT_COMMENT
||
572 nn
->prev
->flags
& NODE_NOPRT
))
574 while (nn
->prev
== NULL
) {
577 if (nn
->type
== ROFFT_ROOT
)
579 } while (nn
->type
!= ROFFT_BLOCK
);
580 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
582 if (nn
->tok
== MDOC_It
&&
583 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
587 /* A `-column' does not assert vspace within the list. */
589 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
590 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
593 /* A `-diag' without body does not vspace. */
595 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
596 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
597 assert(n
->prev
->body
);
598 if (NULL
== n
->prev
->body
->child
)
607 termp_it_pre(DECL_ARGS
)
611 const struct roff_node
*bl
, *nn
;
613 int i
, offset
, width
;
616 if (n
->type
== ROFFT_BLOCK
) {
617 print_bvspace(p
, n
->parent
->parent
, n
);
621 bl
= n
->parent
->parent
->parent
;
622 type
= bl
->norm
->Bl
.type
;
625 * Defaults for specific list types.
633 width
= term_len(p
, 2);
637 width
= term_len(p
, 8);
640 width
= term_len(p
, 10);
649 * First calculate width and offset. This is pretty easy unless
650 * we're a -column list, in which case all prior columns must
654 if (bl
->norm
->Bl
.offs
!= NULL
) {
655 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
656 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
657 offset
= -p
->tcol
->offset
;
658 else if (offset
> SHRT_MAX
)
664 if (n
->type
== ROFFT_HEAD
)
668 * Imitate groff's column handling:
669 * - For each earlier column, add its width.
670 * - For less than 5 columns, add four more blanks per
672 * - For exactly 5 columns, add three more blank per
674 * - For more than 5 columns, add only one column.
676 ncols
= bl
->norm
->Bl
.ncols
;
677 dcol
= ncols
< 5 ? term_len(p
, 4) :
678 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
681 * Calculate the offset by applying all prior ROFFT_BODY,
682 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
685 for (i
= 0, nn
= n
->prev
;
686 nn
->prev
&& i
< (int)ncols
;
687 nn
= nn
->prev
, i
++) {
689 term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
690 su
.scale
/= term_strlen(p
, "0");
691 offset
+= term_hen(p
, &su
) + dcol
;
695 * When exceeding the declared number of columns, leave
696 * the remaining widths at 0. This will later be
697 * adjusted to the default width of 10, or, for the last
698 * column, stretched to the right margin.
704 * Use the declared column widths, extended as explained
705 * in the preceding paragraph.
707 SCALE_HS_INIT(&su
, term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
708 su
.scale
/= term_strlen(p
, "0");
709 width
= term_hen(p
, &su
) + dcol
;
712 if (NULL
== bl
->norm
->Bl
.width
)
716 * Note: buffer the width by 2, which is groff's magic
717 * number for buffering single arguments. See the above
718 * handling for column for how this changes.
720 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
721 if (width
< 0 && (size_t)(-width
) > p
->tcol
->offset
)
722 width
= -p
->tcol
->offset
;
723 else if (width
> SHRT_MAX
)
729 * Whitespace control. Inset bodies need an initial space,
730 * while diagonal bodies need two.
733 p
->flags
|= TERMP_NOSPACE
;
737 if (n
->type
== ROFFT_BODY
)
738 term_word(p
, "\\ \\ ");
741 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
748 p
->flags
|= TERMP_NOSPACE
;
752 if (n
->type
== ROFFT_HEAD
)
753 term_fontpush(p
, TERMFONT_BOLD
);
760 * Pad and break control. This is the tricky part. These flags
761 * are documented in term_flushln() in term.c. Note that we're
762 * going to unset all of these flags in termp_it_post() when we
771 if (n
->type
== ROFFT_HEAD
) {
772 p
->flags
|= TERMP_NOBREAK
| TERMP_HANG
;
774 } else if (width
<= (int)term_len(p
, 2))
775 p
->flags
|= TERMP_NOPAD
;
778 if (n
->type
!= ROFFT_HEAD
)
780 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
784 if (n
->type
!= ROFFT_HEAD
)
787 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
790 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
791 p
->flags
|= TERMP_HANG
;
794 if (n
->type
== ROFFT_HEAD
)
797 if (NULL
== n
->next
) {
798 p
->flags
&= ~TERMP_NOBREAK
;
801 p
->flags
|= TERMP_NOBREAK
;
807 if (n
->type
!= ROFFT_HEAD
)
809 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
817 * Margin control. Set-head-width lists have their right
818 * margins shortened. The body for these lists has the offset
819 * necessarily lengthened. Everybody gets the offset.
822 p
->tcol
->offset
+= offset
;
831 if (n
->type
== ROFFT_HEAD
)
832 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
834 p
->tcol
->offset
+= width
;
838 p
->tcol
->rmargin
= p
->tcol
->offset
+ width
;
840 * XXX - this behaviour is not documented: the
841 * right-most column is filled to the right margin.
843 if (n
->type
== ROFFT_HEAD
)
845 if (n
->next
== NULL
&& p
->tcol
->rmargin
< p
->maxrmargin
)
846 p
->tcol
->rmargin
= p
->maxrmargin
;
853 * The dash, hyphen, bullet and enum lists all have a special
854 * HEAD character (temporarily bold, in some cases).
857 if (n
->type
== ROFFT_HEAD
)
860 term_fontpush(p
, TERMFONT_BOLD
);
861 term_word(p
, "\\[bu]");
866 term_fontpush(p
, TERMFONT_BOLD
);
871 (pair
->ppair
->ppair
->count
)++;
872 (void)snprintf(buf
, sizeof(buf
), "%d.",
873 pair
->ppair
->ppair
->count
);
881 * If we're not going to process our children, indicate so here.
890 if (n
->type
== ROFFT_HEAD
)
894 if (n
->type
== ROFFT_HEAD
)
906 termp_it_post(DECL_ARGS
)
910 if (n
->type
== ROFFT_BLOCK
)
913 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
919 if (n
->type
== ROFFT_BODY
)
923 if (n
->type
== ROFFT_BODY
)
932 * Now that our output is flushed, we can reset our tags. Since
933 * only `It' sets these flags, we're free to assume that nobody
934 * has munged them in the meanwhile.
937 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
| TERMP_HANG
);
942 termp_nm_pre(DECL_ARGS
)
946 if (n
->type
== ROFFT_BLOCK
) {
947 p
->flags
|= TERMP_PREKEEP
;
951 if (n
->type
== ROFFT_BODY
) {
952 if (n
->child
== NULL
)
954 p
->flags
|= TERMP_NOSPACE
;
956 if (n
->prev
->child
!= NULL
)
957 cp
= n
->prev
->child
->string
;
961 p
->tcol
->offset
+= term_len(p
, 6);
963 p
->tcol
->offset
+= term_len(p
, 1) +
968 if (n
->child
== NULL
)
971 if (n
->type
== ROFFT_HEAD
)
972 synopsis_pre(p
, n
->parent
);
974 if (n
->type
== ROFFT_HEAD
&&
975 n
->next
!= NULL
&& n
->next
->child
!= NULL
) {
976 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
978 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 1);
979 if (n
->child
== NULL
)
980 p
->tcol
->rmargin
+= term_strlen(p
, meta
->name
);
981 else if (n
->child
->type
== ROFFT_TEXT
) {
982 p
->tcol
->rmargin
+= term_strlen(p
, n
->child
->string
);
983 if (n
->child
->next
!= NULL
)
984 p
->flags
|= TERMP_HANG
;
986 p
->tcol
->rmargin
+= term_len(p
, 5);
987 p
->flags
|= TERMP_HANG
;
991 term_fontpush(p
, TERMFONT_BOLD
);
996 termp_nm_post(DECL_ARGS
)
999 if (n
->type
== ROFFT_BLOCK
) {
1000 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1001 } else if (n
->type
== ROFFT_HEAD
&&
1002 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1004 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1006 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1011 termp_fl_pre(DECL_ARGS
)
1014 termp_tag_pre(p
, pair
, meta
, n
);
1015 term_fontpush(p
, TERMFONT_BOLD
);
1016 term_word(p
, "\\-");
1018 if (!(n
->child
== NULL
&&
1020 n
->next
->type
== ROFFT_TEXT
||
1021 n
->next
->flags
& NODE_LINE
)))
1022 p
->flags
|= TERMP_NOSPACE
;
1028 termp__a_pre(DECL_ARGS
)
1031 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1032 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1033 term_word(p
, "and");
1039 termp_an_pre(DECL_ARGS
)
1042 if (n
->norm
->An
.auth
== AUTH_split
) {
1043 p
->flags
&= ~TERMP_NOSPLIT
;
1044 p
->flags
|= TERMP_SPLIT
;
1047 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1048 p
->flags
&= ~TERMP_SPLIT
;
1049 p
->flags
|= TERMP_NOSPLIT
;
1053 if (p
->flags
& TERMP_SPLIT
)
1056 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1057 p
->flags
|= TERMP_SPLIT
;
1063 termp_ns_pre(DECL_ARGS
)
1066 if ( ! (NODE_LINE
& n
->flags
))
1067 p
->flags
|= TERMP_NOSPACE
;
1072 termp_rs_pre(DECL_ARGS
)
1075 if (SEC_SEE_ALSO
!= n
->sec
)
1077 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1083 termp_ex_pre(DECL_ARGS
)
1090 termp_nd_pre(DECL_ARGS
)
1093 if (n
->type
== ROFFT_BODY
)
1094 term_word(p
, "\\(en");
1099 termp_bl_pre(DECL_ARGS
)
1102 return n
->type
!= ROFFT_HEAD
;
1106 termp_bl_post(DECL_ARGS
)
1109 if (n
->type
!= ROFFT_BLOCK
)
1112 if (n
->tok
!= MDOC_Bl
|| n
->norm
->Bl
.type
!= LIST_column
)
1114 term_tab_set(p
, NULL
);
1115 term_tab_set(p
, "T");
1116 term_tab_set(p
, ".5i");
1120 termp_xr_pre(DECL_ARGS
)
1123 if (NULL
== (n
= n
->child
))
1126 assert(n
->type
== ROFFT_TEXT
);
1127 term_word(p
, n
->string
);
1129 if (NULL
== (n
= n
->next
))
1132 p
->flags
|= TERMP_NOSPACE
;
1134 p
->flags
|= TERMP_NOSPACE
;
1136 assert(n
->type
== ROFFT_TEXT
);
1137 term_word(p
, n
->string
);
1139 p
->flags
|= TERMP_NOSPACE
;
1146 * This decides how to assert whitespace before any of the SYNOPSIS set
1147 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1151 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1154 * Obviously, if we're not in a SYNOPSIS or no prior macros
1155 * exist, do nothing.
1157 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
1161 * If we're the second in a pair of like elements, emit our
1162 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1163 * case we soldier on.
1165 if (n
->prev
->tok
== n
->tok
&&
1166 MDOC_Ft
!= n
->tok
&&
1167 MDOC_Fo
!= n
->tok
&&
1168 MDOC_Fn
!= n
->tok
) {
1174 * If we're one of the SYNOPSIS set and non-like pair-wise after
1175 * another (or Fn/Fo, which we've let slip through) then assert
1176 * vertical space, else only newline and move on.
1178 switch (n
->prev
->tok
) {
1187 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1199 termp_vt_pre(DECL_ARGS
)
1202 if (n
->type
== ROFFT_ELEM
) {
1204 return termp_under_pre(p
, pair
, meta
, n
);
1205 } else if (n
->type
== ROFFT_BLOCK
) {
1208 } else if (n
->type
== ROFFT_HEAD
)
1211 return termp_under_pre(p
, pair
, meta
, n
);
1215 termp_bold_pre(DECL_ARGS
)
1218 termp_tag_pre(p
, pair
, meta
, n
);
1219 term_fontpush(p
, TERMFONT_BOLD
);
1224 termp_fd_pre(DECL_ARGS
)
1228 return termp_bold_pre(p
, pair
, meta
, n
);
1232 termp_fd_post(DECL_ARGS
)
1239 termp_sh_pre(DECL_ARGS
)
1245 * Vertical space before sections, except
1246 * when the previous section was empty.
1248 if (n
->prev
== NULL
||
1249 n
->prev
->tok
!= MDOC_Sh
||
1250 (n
->prev
->body
!= NULL
&&
1251 n
->prev
->body
->child
!= NULL
))
1255 term_fontpush(p
, TERMFONT_BOLD
);
1258 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1259 term_tab_set(p
, NULL
);
1260 term_tab_set(p
, "T");
1261 term_tab_set(p
, ".5i");
1263 case SEC_DESCRIPTION
:
1267 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1280 termp_sh_post(DECL_ARGS
)
1289 p
->tcol
->offset
= 0;
1297 termp_lb_post(DECL_ARGS
)
1300 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
)
1305 termp_d1_pre(DECL_ARGS
)
1308 if (n
->type
!= ROFFT_BLOCK
)
1311 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1312 term_tab_set(p
, NULL
);
1313 term_tab_set(p
, "T");
1314 term_tab_set(p
, ".5i");
1319 termp_ft_pre(DECL_ARGS
)
1322 /* NB: NODE_LINE does not effect this! */
1324 term_fontpush(p
, TERMFONT_UNDER
);
1329 termp_fn_pre(DECL_ARGS
)
1334 pretty
= NODE_SYNPRETTY
& n
->flags
;
1338 if (NULL
== (n
= n
->child
))
1342 rmargin
= p
->tcol
->rmargin
;
1343 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1344 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1347 assert(n
->type
== ROFFT_TEXT
);
1348 term_fontpush(p
, TERMFONT_BOLD
);
1349 term_word(p
, n
->string
);
1352 if (n
->sec
== SEC_DESCRIPTION
|| n
->sec
== SEC_CUSTOM
)
1353 tag_put(n
->string
, ++fn_prio
, p
->line
);
1357 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1358 p
->flags
|= TERMP_NOPAD
;
1359 p
->tcol
->offset
= p
->tcol
->rmargin
;
1360 p
->tcol
->rmargin
= rmargin
;
1363 p
->flags
|= TERMP_NOSPACE
;
1365 p
->flags
|= TERMP_NOSPACE
;
1367 for (n
= n
->next
; n
; n
= n
->next
) {
1368 assert(n
->type
== ROFFT_TEXT
);
1369 term_fontpush(p
, TERMFONT_UNDER
);
1371 p
->flags
|= TERMP_NBRWORD
;
1372 term_word(p
, n
->string
);
1376 p
->flags
|= TERMP_NOSPACE
;
1381 p
->flags
|= TERMP_NOSPACE
;
1385 p
->flags
|= TERMP_NOSPACE
;
1394 termp_fa_pre(DECL_ARGS
)
1396 const struct roff_node
*nn
;
1398 if (n
->parent
->tok
!= MDOC_Fo
) {
1399 term_fontpush(p
, TERMFONT_UNDER
);
1403 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1404 term_fontpush(p
, TERMFONT_UNDER
);
1405 p
->flags
|= TERMP_NBRWORD
;
1406 term_word(p
, nn
->string
);
1409 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1410 p
->flags
|= TERMP_NOSPACE
;
1419 termp_bd_pre(DECL_ARGS
)
1422 struct roff_node
*nn
;
1425 if (n
->type
== ROFFT_BLOCK
) {
1426 print_bvspace(p
, n
, n
);
1428 } else if (n
->type
== ROFFT_HEAD
)
1431 /* Handle the -offset argument. */
1433 if (n
->norm
->Bd
.offs
== NULL
||
1434 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1436 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1437 p
->tcol
->offset
+= term_len(p
, p
->defindent
+ 1);
1438 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1439 p
->tcol
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1441 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1442 if (offset
< 0 && (size_t)(-offset
) > p
->tcol
->offset
)
1443 p
->tcol
->offset
= 0;
1444 else if (offset
< SHRT_MAX
)
1445 p
->tcol
->offset
+= offset
;
1449 * If -ragged or -filled are specified, the block does nothing
1450 * but change the indentation. If -unfilled or -literal are
1451 * specified, text is printed exactly as entered in the display:
1452 * for macro lines, a newline is appended to the line. Blank
1453 * lines are allowed.
1456 if (n
->norm
->Bd
.type
!= DISP_literal
&&
1457 n
->norm
->Bd
.type
!= DISP_unfilled
&&
1458 n
->norm
->Bd
.type
!= DISP_centered
)
1461 if (n
->norm
->Bd
.type
== DISP_literal
) {
1462 term_tab_set(p
, NULL
);
1463 term_tab_set(p
, "T");
1464 term_tab_set(p
, "8n");
1467 lm
= p
->tcol
->offset
;
1468 p
->flags
|= TERMP_BRNEVER
;
1469 for (nn
= n
->child
; nn
!= NULL
; nn
= nn
->next
) {
1470 if (n
->norm
->Bd
.type
== DISP_centered
) {
1471 if (nn
->type
== ROFFT_TEXT
) {
1472 len
= term_strlen(p
, nn
->string
);
1473 p
->tcol
->offset
= len
>= p
->tcol
->rmargin
?
1474 0 : lm
+ len
>= p
->tcol
->rmargin
?
1475 p
->tcol
->rmargin
- len
:
1476 (lm
+ p
->tcol
->rmargin
- len
) / 2;
1478 p
->tcol
->offset
= lm
;
1480 print_mdoc_node(p
, pair
, meta
, nn
);
1482 * If the printed node flushes its own line, then we
1483 * needn't do it here as well. This is hacky, but the
1484 * notion of selective eoln whitespace is pretty dumb
1485 * anyway, so don't sweat it.
1487 if (nn
->tok
< ROFF_MAX
)
1499 if (p
->flags
& TERMP_NONEWLINE
||
1500 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1503 p
->flags
|= TERMP_NOSPACE
;
1505 p
->flags
&= ~TERMP_BRNEVER
;
1510 termp_bd_post(DECL_ARGS
)
1512 if (n
->type
!= ROFFT_BODY
)
1514 if (DISP_literal
== n
->norm
->Bd
.type
||
1515 DISP_unfilled
== n
->norm
->Bd
.type
)
1516 p
->flags
|= TERMP_BRNEVER
;
1517 p
->flags
|= TERMP_NOSPACE
;
1519 p
->flags
&= ~TERMP_BRNEVER
;
1523 termp_xx_pre(DECL_ARGS
)
1525 if ((n
->aux
= p
->flags
& TERMP_PREKEEP
) == 0)
1526 p
->flags
|= TERMP_PREKEEP
;
1531 termp_xx_post(DECL_ARGS
)
1534 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1538 termp_pf_post(DECL_ARGS
)
1541 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1542 p
->flags
|= TERMP_NOSPACE
;
1546 termp_ss_pre(DECL_ARGS
)
1548 struct roff_node
*nn
;
1553 for (nn
= n
->prev
; nn
!= NULL
; nn
= nn
->prev
)
1554 if (nn
->type
!= ROFFT_COMMENT
&&
1555 (nn
->flags
& NODE_NOPRT
) == 0)
1561 term_fontpush(p
, TERMFONT_BOLD
);
1562 p
->tcol
->offset
= term_len(p
, (p
->defindent
+1)/2);
1565 p
->tcol
->offset
= term_len(p
, p
->defindent
);
1566 term_tab_set(p
, NULL
);
1567 term_tab_set(p
, "T");
1568 term_tab_set(p
, ".5i");
1578 termp_ss_post(DECL_ARGS
)
1581 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1586 termp_cd_pre(DECL_ARGS
)
1590 term_fontpush(p
, TERMFONT_BOLD
);
1595 termp_in_pre(DECL_ARGS
)
1600 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
) {
1601 term_fontpush(p
, TERMFONT_BOLD
);
1602 term_word(p
, "#include");
1606 term_fontpush(p
, TERMFONT_UNDER
);
1609 p
->flags
|= TERMP_NOSPACE
;
1614 termp_in_post(DECL_ARGS
)
1617 if (NODE_SYNPRETTY
& n
->flags
)
1618 term_fontpush(p
, TERMFONT_BOLD
);
1620 p
->flags
|= TERMP_NOSPACE
;
1623 if (NODE_SYNPRETTY
& n
->flags
)
1628 termp_pp_pre(DECL_ARGS
)
1636 termp_skip_pre(DECL_ARGS
)
1643 termp_quote_pre(DECL_ARGS
)
1646 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1652 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1653 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1669 term_word(p
, "\\(lq");
1672 if (NULL
== n
->norm
->Es
||
1673 NULL
== n
->norm
->Es
->child
)
1675 term_word(p
, n
->norm
->Es
->child
->string
);
1688 term_word(p
, "\\(oq");
1694 p
->flags
|= TERMP_NOSPACE
;
1699 termp_quote_post(DECL_ARGS
)
1702 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1705 p
->flags
|= TERMP_NOSPACE
;
1710 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1711 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1727 term_word(p
, "\\(rq");
1730 if (n
->norm
->Es
== NULL
||
1731 n
->norm
->Es
->child
== NULL
||
1732 n
->norm
->Es
->child
->next
== NULL
)
1733 p
->flags
&= ~TERMP_NOSPACE
;
1735 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1748 term_word(p
, "\\(cq");
1756 termp_eo_pre(DECL_ARGS
)
1759 if (n
->type
!= ROFFT_BODY
)
1762 if (n
->end
== ENDBODY_NOT
&&
1763 n
->parent
->head
->child
== NULL
&&
1765 n
->child
->end
!= ENDBODY_NOT
)
1766 term_word(p
, "\\&");
1767 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1768 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1769 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1770 p
->flags
|= TERMP_NOSPACE
;
1776 termp_eo_post(DECL_ARGS
)
1780 if (n
->type
!= ROFFT_BODY
)
1783 if (n
->end
!= ENDBODY_NOT
) {
1784 p
->flags
&= ~TERMP_NOSPACE
;
1788 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1789 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1792 p
->flags
|= TERMP_NOSPACE
;
1793 else if ( ! (body
|| tail
))
1794 term_word(p
, "\\&");
1796 p
->flags
&= ~TERMP_NOSPACE
;
1800 termp_fo_pre(DECL_ARGS
)
1805 pretty
= NODE_SYNPRETTY
& n
->flags
;
1807 if (n
->type
== ROFFT_BLOCK
) {
1810 } else if (n
->type
== ROFFT_BODY
) {
1812 rmargin
= p
->tcol
->rmargin
;
1813 p
->tcol
->rmargin
= p
->tcol
->offset
+ term_len(p
, 4);
1814 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1817 p
->flags
|= TERMP_NOSPACE
;
1819 p
->flags
|= TERMP_NOSPACE
;
1822 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1824 p
->flags
|= TERMP_NOPAD
;
1825 p
->tcol
->offset
= p
->tcol
->rmargin
;
1826 p
->tcol
->rmargin
= rmargin
;
1831 if (NULL
== n
->child
)
1834 /* XXX: we drop non-initial arguments as per groff. */
1836 assert(n
->child
->string
);
1837 term_fontpush(p
, TERMFONT_BOLD
);
1838 term_word(p
, n
->child
->string
);
1843 termp_fo_post(DECL_ARGS
)
1846 if (n
->type
!= ROFFT_BODY
)
1849 p
->flags
|= TERMP_NOSPACE
;
1852 if (NODE_SYNPRETTY
& n
->flags
) {
1853 p
->flags
|= TERMP_NOSPACE
;
1860 termp_bf_pre(DECL_ARGS
)
1863 if (n
->type
== ROFFT_HEAD
)
1865 else if (n
->type
!= ROFFT_BODY
)
1868 if (FONT_Em
== n
->norm
->Bf
.font
)
1869 term_fontpush(p
, TERMFONT_UNDER
);
1870 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1871 term_fontpush(p
, TERMFONT_BOLD
);
1873 term_fontpush(p
, TERMFONT_NONE
);
1879 termp_sm_pre(DECL_ARGS
)
1882 if (NULL
== n
->child
)
1883 p
->flags
^= TERMP_NONOSPACE
;
1884 else if (0 == strcmp("on", n
->child
->string
))
1885 p
->flags
&= ~TERMP_NONOSPACE
;
1887 p
->flags
|= TERMP_NONOSPACE
;
1889 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
1890 p
->flags
&= ~TERMP_NOSPACE
;
1896 termp_ap_pre(DECL_ARGS
)
1899 p
->flags
|= TERMP_NOSPACE
;
1901 p
->flags
|= TERMP_NOSPACE
;
1906 termp____post(DECL_ARGS
)
1910 * Handle lists of authors. In general, print each followed by
1911 * a comma. Don't print the comma if there are only two
1914 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1915 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1916 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1921 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1924 p
->flags
|= TERMP_NOSPACE
;
1925 if (NULL
== n
->next
) {
1927 p
->flags
|= TERMP_SENTENCE
;
1933 termp_li_pre(DECL_ARGS
)
1936 termp_tag_pre(p
, pair
, meta
, n
);
1937 term_fontpush(p
, TERMFONT_NONE
);
1942 termp_lk_pre(DECL_ARGS
)
1944 const struct roff_node
*link
, *descr
, *punct
;
1946 if ((link
= n
->child
) == NULL
)
1949 /* Find beginning of trailing punctuation. */
1951 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1952 punct
= punct
->prev
;
1953 punct
= punct
->next
;
1956 if ((descr
= link
->next
) != NULL
&& descr
!= punct
) {
1957 term_fontpush(p
, TERMFONT_UNDER
);
1958 while (descr
!= punct
) {
1959 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1960 p
->flags
|= TERMP_NOSPACE
;
1961 term_word(p
, descr
->string
);
1962 descr
= descr
->next
;
1965 p
->flags
|= TERMP_NOSPACE
;
1970 term_fontpush(p
, TERMFONT_BOLD
);
1971 term_word(p
, link
->string
);
1974 /* Trailing punctuation. */
1975 while (punct
!= NULL
) {
1976 p
->flags
|= TERMP_NOSPACE
;
1977 term_word(p
, punct
->string
);
1978 punct
= punct
->next
;
1984 termp_bk_pre(DECL_ARGS
)
1993 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
1994 p
->flags
|= TERMP_PREKEEP
;
2004 termp_bk_post(DECL_ARGS
)
2007 if (n
->type
== ROFFT_BODY
)
2008 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2012 termp__t_post(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 termp_quote_post(p
, pair
, meta
, n
);
2023 termp____post(p
, pair
, meta
, n
);
2027 termp__t_pre(DECL_ARGS
)
2031 * If we're in an `Rs' and there's a journal present, then quote
2032 * us instead of underlining us (for disambiguation).
2034 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2035 n
->parent
->norm
->Rs
.quote_T
)
2036 return termp_quote_pre(p
, pair
, meta
, n
);
2038 term_fontpush(p
, TERMFONT_UNDER
);
2043 termp_under_pre(DECL_ARGS
)
2046 term_fontpush(p
, TERMFONT_UNDER
);
2051 termp_em_pre(DECL_ARGS
)
2053 if (n
->child
!= NULL
&&
2054 n
->child
->type
== ROFFT_TEXT
)
2055 tag_put(n
->child
->string
, 0, p
->line
);
2056 term_fontpush(p
, TERMFONT_UNDER
);
2061 termp_sy_pre(DECL_ARGS
)
2063 if (n
->child
!= NULL
&&
2064 n
->child
->type
== ROFFT_TEXT
)
2065 tag_put(n
->child
->string
, 0, p
->line
);
2066 term_fontpush(p
, TERMFONT_BOLD
);
2071 termp_er_pre(DECL_ARGS
)
2074 if (n
->sec
== SEC_ERRORS
&&
2075 (n
->parent
->tok
== MDOC_It
||
2076 (n
->parent
->tok
== MDOC_Bq
&&
2077 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2078 tag_put(n
->child
->string
, 1, p
->line
);
2083 termp_tag_pre(DECL_ARGS
)
2086 if (n
->child
!= NULL
&&
2087 n
->child
->type
== ROFFT_TEXT
&&
2089 (n
->prev
->type
== ROFFT_TEXT
&&
2090 strcmp(n
->prev
->string
, "|") == 0)) &&
2091 (n
->parent
->tok
== MDOC_It
||
2092 (n
->parent
->tok
== MDOC_Xo
&&
2093 n
->parent
->parent
->prev
== NULL
&&
2094 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2095 tag_put(n
->child
->string
, 1, p
->line
);
2100 termp_abort_pre(DECL_ARGS
)