]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.353 2017/05/05 02:06:19 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2017 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, \
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_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_ll_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_sp_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 termact __termacts
[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_sp_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_ft_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_sp_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 { termp_sp_pre
, NULL
}, /* sp */
248 { NULL
, termp____post
}, /* %U */
249 { NULL
, NULL
}, /* Ta */
250 { termp_ll_pre
, NULL
}, /* ll */
252 static const struct termact
*const termacts
= __termacts
- MDOC_Dd
;
258 terminal_mdoc(void *arg
, const struct roff_man
*mdoc
)
262 size_t save_defindent
;
264 p
= (struct termp
*)arg
;
266 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
267 p
->tabwidth
= term_len(p
, 5);
269 n
= mdoc
->first
->child
;
270 if (p
->synopsisonly
) {
272 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
273 if (n
->child
->next
->child
!= NULL
)
274 print_mdoc_nodelist(p
, NULL
,
276 n
->child
->next
->child
);
283 save_defindent
= p
->defindent
;
284 if (p
->defindent
== 0)
286 term_begin(p
, print_mdoc_head
, print_mdoc_foot
,
288 while (n
!= NULL
&& 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
)
314 struct termpair npair
;
315 size_t offset
, rmargin
;
317 if (n
->flags
& NODE_NOPRT
)
322 rmargin
= p
->rmargin
;
323 n
->flags
&= ~NODE_ENDED
;
324 n
->prev_font
= p
->fonti
;
326 memset(&npair
, 0, sizeof(struct termpair
));
330 * Keeps only work until the end of a line. If a keep was
331 * invoked in a prior line, revert it to PREKEEP.
334 if (p
->flags
& TERMP_KEEP
&& n
->flags
& NODE_LINE
) {
335 p
->flags
&= ~TERMP_KEEP
;
336 p
->flags
|= TERMP_PREKEEP
;
340 * After the keep flags have been set up, we may now
341 * produce output. Note that some pre-handlers do so.
346 if (' ' == *n
->string
&& NODE_LINE
& n
->flags
)
348 if (NODE_DELIMC
& n
->flags
)
349 p
->flags
|= TERMP_NOSPACE
;
350 term_word(p
, n
->string
);
351 if (NODE_DELIMO
& n
->flags
)
352 p
->flags
|= TERMP_NOSPACE
;
355 if ( ! (n
->flags
& NODE_LINE
))
356 p
->flags
|= TERMP_NOSPACE
;
358 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
359 p
->flags
|= TERMP_NOSPACE
;
362 if (p
->tbl
.cols
== NULL
)
364 term_tbl(p
, n
->span
);
367 if (n
->tok
< ROFF_MAX
) {
372 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
373 if (termacts
[n
->tok
].pre
!= NULL
&&
374 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
375 chld
= (*termacts
[n
->tok
].pre
)
376 (p
, &npair
, meta
, n
);
380 if (chld
&& n
->child
)
381 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
384 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
394 if (n
->tok
< ROFF_MAX
||
395 termacts
[n
->tok
].post
== NULL
||
396 n
->flags
& NODE_ENDED
)
398 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
401 * Explicit end tokens not only call the post
402 * handler, but also tell the respective block
403 * that it must not call the post handler again.
405 if (ENDBODY_NOT
!= n
->end
)
406 n
->body
->flags
|= NODE_ENDED
;
410 if (NODE_EOS
& n
->flags
)
411 p
->flags
|= TERMP_SENTENCE
;
413 if (MDOC_ll
!= n
->tok
) {
415 p
->rmargin
= rmargin
;
420 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
424 term_fontrepl(p
, TERMFONT_NONE
);
427 * Output the footer in new-groff style, that is, three columns
428 * with the middle being the manual date and flanking columns
429 * being the operating system:
437 sz
= term_strlen(p
, meta
->date
);
438 p
->rmargin
= p
->maxrmargin
> sz
?
439 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
441 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
443 term_word(p
, meta
->os
);
446 p
->offset
= p
->rmargin
;
447 sz
= term_strlen(p
, meta
->os
);
448 p
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
449 p
->flags
|= TERMP_NOSPACE
;
451 term_word(p
, meta
->date
);
454 p
->offset
= p
->rmargin
;
455 p
->rmargin
= p
->maxrmargin
;
457 p
->flags
&= ~TERMP_NOBREAK
;
458 p
->flags
|= TERMP_NOSPACE
;
460 term_word(p
, meta
->os
);
464 p
->rmargin
= p
->maxrmargin
;
469 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
471 char *volume
, *title
;
472 size_t vollen
, titlen
;
475 * The header is strange. It has three components, which are
476 * really two with the first duplicated. It goes like this:
478 * IDENTIFIER TITLE IDENTIFIER
480 * The IDENTIFIER is NAME(SECTION), which is the command-name
481 * (if given, or "unknown" if not) followed by the manual page
482 * section. These are given in `Dt'. The TITLE is a free-form
483 * string depending on the manual volume. If not specified, it
484 * switches on the manual section.
488 if (NULL
== meta
->arch
)
489 volume
= mandoc_strdup(meta
->vol
);
491 mandoc_asprintf(&volume
, "%s (%s)",
492 meta
->vol
, meta
->arch
);
493 vollen
= term_strlen(p
, volume
);
495 if (NULL
== meta
->msec
)
496 title
= mandoc_strdup(meta
->title
);
498 mandoc_asprintf(&title
, "%s(%s)",
499 meta
->title
, meta
->msec
);
500 titlen
= term_strlen(p
, title
);
502 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
505 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
506 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
507 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
512 p
->flags
|= TERMP_NOSPACE
;
513 p
->offset
= p
->rmargin
;
514 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
515 p
->maxrmargin
- titlen
: p
->maxrmargin
;
517 term_word(p
, volume
);
520 p
->flags
&= ~TERMP_NOBREAK
;
522 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
523 p
->flags
|= TERMP_NOSPACE
;
524 p
->offset
= p
->rmargin
;
525 p
->rmargin
= p
->maxrmargin
;
530 p
->flags
&= ~TERMP_NOSPACE
;
532 p
->rmargin
= p
->maxrmargin
;
538 a2width(const struct termp
*p
, const char *v
)
542 if (a2roffsu(v
, &su
, SCALE_MAX
) < 2) {
543 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
544 su
.scale
/= term_strlen(p
, "0");
546 return term_hspan(p
, &su
) / 24;
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
&& nn
->prev
->flags
& NODE_NOPRT
)
575 while (nn
->prev
== NULL
) {
578 if (nn
->type
== ROFFT_ROOT
)
580 } while (nn
->type
!= ROFFT_BLOCK
);
581 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
583 if (nn
->tok
== MDOC_It
&&
584 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
588 /* A `-column' does not assert vspace within the list. */
590 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
591 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
594 /* A `-diag' without body does not vspace. */
596 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
597 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
598 assert(n
->prev
->body
);
599 if (NULL
== n
->prev
->body
->child
)
608 termp_ll_pre(DECL_ARGS
)
611 term_setwidth(p
, n
->child
!= NULL
? n
->child
->string
: NULL
);
616 termp_it_pre(DECL_ARGS
)
620 const struct roff_node
*bl
, *nn
;
622 int i
, offset
, width
;
625 if (n
->type
== ROFFT_BLOCK
) {
626 print_bvspace(p
, n
->parent
->parent
, n
);
630 bl
= n
->parent
->parent
->parent
;
631 type
= bl
->norm
->Bl
.type
;
634 * Defaults for specific list types.
642 width
= term_len(p
, 2);
646 width
= term_len(p
, 8);
649 width
= term_len(p
, 10);
658 * First calculate width and offset. This is pretty easy unless
659 * we're a -column list, in which case all prior columns must
663 if (bl
->norm
->Bl
.offs
!= NULL
) {
664 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
665 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
667 else if (offset
> SHRT_MAX
)
673 if (n
->type
== ROFFT_HEAD
)
677 * Imitate groff's column handling:
678 * - For each earlier column, add its width.
679 * - For less than 5 columns, add four more blanks per
681 * - For exactly 5 columns, add three more blank per
683 * - For more than 5 columns, add only one column.
685 ncols
= bl
->norm
->Bl
.ncols
;
686 dcol
= ncols
< 5 ? term_len(p
, 4) :
687 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
690 * Calculate the offset by applying all prior ROFFT_BODY,
691 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
694 for (i
= 0, nn
= n
->prev
;
695 nn
->prev
&& i
< (int)ncols
;
696 nn
= nn
->prev
, i
++) {
698 term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
699 su
.scale
/= term_strlen(p
, "0");
700 offset
+= term_hspan(p
, &su
) / 24 + dcol
;
704 * When exceeding the declared number of columns, leave
705 * the remaining widths at 0. This will later be
706 * adjusted to the default width of 10, or, for the last
707 * column, stretched to the right margin.
713 * Use the declared column widths, extended as explained
714 * in the preceding paragraph.
716 SCALE_HS_INIT(&su
, term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
717 su
.scale
/= term_strlen(p
, "0");
718 width
= term_hspan(p
, &su
) / 24 + dcol
;
721 if (NULL
== bl
->norm
->Bl
.width
)
725 * Note: buffer the width by 2, which is groff's magic
726 * number for buffering single arguments. See the above
727 * handling for column for how this changes.
729 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
730 if (width
< 0 && (size_t)(-width
) > p
->offset
)
732 else if (width
> SHRT_MAX
)
738 * Whitespace control. Inset bodies need an initial space,
739 * while diagonal bodies need two.
742 p
->flags
|= TERMP_NOSPACE
;
746 if (n
->type
== ROFFT_BODY
)
747 term_word(p
, "\\ \\ ");
750 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
757 p
->flags
|= TERMP_NOSPACE
;
761 if (n
->type
== ROFFT_HEAD
)
762 term_fontpush(p
, TERMFONT_BOLD
);
769 * Pad and break control. This is the tricky part. These flags
770 * are documented in term_flushln() in term.c. Note that we're
771 * going to unset all of these flags in termp_it_post() when we
781 * Weird special case.
782 * Some very narrow lists actually hang.
784 if (width
<= (int)term_len(p
, 2))
785 p
->flags
|= TERMP_HANG
;
786 if (n
->type
!= ROFFT_HEAD
)
788 p
->flags
|= TERMP_NOBREAK
;
792 if (n
->type
!= ROFFT_HEAD
)
796 * This is ugly. If `-hang' is specified and the body
797 * is a `Bl' or `Bd', then we want basically to nullify
798 * the "overstep" effect in term_flushln() and treat
799 * this as a `-ohang' list instead.
801 if (NULL
!= n
->next
&&
802 NULL
!= n
->next
->child
&&
803 (MDOC_Bl
== n
->next
->child
->tok
||
804 MDOC_Bd
== n
->next
->child
->tok
))
807 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
811 if (n
->type
!= ROFFT_HEAD
)
814 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
817 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
818 p
->flags
|= TERMP_DANGLE
;
821 if (n
->type
== ROFFT_HEAD
)
824 if (NULL
== n
->next
) {
825 p
->flags
&= ~TERMP_NOBREAK
;
828 p
->flags
|= TERMP_NOBREAK
;
834 if (n
->type
!= ROFFT_HEAD
)
836 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
844 * Margin control. Set-head-width lists have their right
845 * margins shortened. The body for these lists has the offset
846 * necessarily lengthened. Everybody gets the offset.
854 * Same stipulation as above, regarding `-hang'. We
855 * don't want to recalculate rmargin and offsets when
856 * using `Bd' or `Bl' within `-hang' overstep lists.
858 if (n
->type
== ROFFT_HEAD
&&
860 NULL
!= n
->next
->child
&&
861 (MDOC_Bl
== n
->next
->child
->tok
||
862 MDOC_Bd
== n
->next
->child
->tok
))
870 if (n
->type
== ROFFT_HEAD
)
871 p
->rmargin
= p
->offset
+ width
;
877 p
->rmargin
= p
->offset
+ width
;
879 * XXX - this behaviour is not documented: the
880 * right-most column is filled to the right margin.
882 if (n
->type
== ROFFT_HEAD
)
884 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
885 p
->rmargin
= p
->maxrmargin
;
892 * The dash, hyphen, bullet and enum lists all have a special
893 * HEAD character (temporarily bold, in some cases).
896 if (n
->type
== ROFFT_HEAD
)
899 term_fontpush(p
, TERMFONT_BOLD
);
900 term_word(p
, "\\[bu]");
905 term_fontpush(p
, TERMFONT_BOLD
);
910 (pair
->ppair
->ppair
->count
)++;
911 (void)snprintf(buf
, sizeof(buf
), "%d.",
912 pair
->ppair
->ppair
->count
);
920 * If we're not going to process our children, indicate so here.
929 if (n
->type
== ROFFT_HEAD
)
933 if (n
->type
== ROFFT_HEAD
)
944 termp_it_post(DECL_ARGS
)
948 if (n
->type
== ROFFT_BLOCK
)
951 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
957 if (n
->type
== ROFFT_BODY
)
961 if (n
->type
== ROFFT_BODY
)
970 * Now that our output is flushed, we can reset our tags. Since
971 * only `It' sets these flags, we're free to assume that nobody
972 * has munged them in the meanwhile.
975 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
|
976 TERMP_DANGLE
| TERMP_HANG
);
981 termp_nm_pre(DECL_ARGS
)
985 if (n
->type
== ROFFT_BLOCK
) {
986 p
->flags
|= TERMP_PREKEEP
;
990 if (n
->type
== ROFFT_BODY
) {
991 if (NULL
== n
->child
)
993 p
->flags
|= TERMP_NOSPACE
;
995 if (n
->prev
->child
!= NULL
)
996 cp
= n
->prev
->child
->string
;
1000 p
->offset
+= term_len(p
, 6);
1002 p
->offset
+= term_len(p
, 1) + term_strlen(p
, cp
);
1006 if (n
->child
== NULL
)
1009 if (n
->type
== ROFFT_HEAD
)
1010 synopsis_pre(p
, n
->parent
);
1012 if (n
->type
== ROFFT_HEAD
&&
1013 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1014 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1016 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1017 if (NULL
== n
->child
) {
1018 p
->rmargin
+= term_strlen(p
, meta
->name
);
1019 } else if (n
->child
->type
== ROFFT_TEXT
) {
1020 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1022 p
->flags
|= TERMP_HANG
;
1024 p
->rmargin
+= term_len(p
, 5);
1025 p
->flags
|= TERMP_HANG
;
1029 term_fontpush(p
, TERMFONT_BOLD
);
1034 termp_nm_post(DECL_ARGS
)
1037 if (n
->type
== ROFFT_BLOCK
) {
1038 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1039 } else if (n
->type
== ROFFT_HEAD
&&
1040 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1042 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1044 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1049 termp_fl_pre(DECL_ARGS
)
1052 termp_tag_pre(p
, pair
, meta
, n
);
1053 term_fontpush(p
, TERMFONT_BOLD
);
1054 term_word(p
, "\\-");
1056 if (!(n
->child
== NULL
&&
1058 n
->next
->type
== ROFFT_TEXT
||
1059 n
->next
->flags
& NODE_LINE
)))
1060 p
->flags
|= TERMP_NOSPACE
;
1066 termp__a_pre(DECL_ARGS
)
1069 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1070 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1071 term_word(p
, "and");
1077 termp_an_pre(DECL_ARGS
)
1080 if (n
->norm
->An
.auth
== AUTH_split
) {
1081 p
->flags
&= ~TERMP_NOSPLIT
;
1082 p
->flags
|= TERMP_SPLIT
;
1085 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1086 p
->flags
&= ~TERMP_SPLIT
;
1087 p
->flags
|= TERMP_NOSPLIT
;
1091 if (p
->flags
& TERMP_SPLIT
)
1094 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1095 p
->flags
|= TERMP_SPLIT
;
1101 termp_ns_pre(DECL_ARGS
)
1104 if ( ! (NODE_LINE
& n
->flags
))
1105 p
->flags
|= TERMP_NOSPACE
;
1110 termp_rs_pre(DECL_ARGS
)
1113 if (SEC_SEE_ALSO
!= n
->sec
)
1115 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1121 termp_ex_pre(DECL_ARGS
)
1128 termp_nd_pre(DECL_ARGS
)
1131 if (n
->type
== ROFFT_BODY
)
1132 term_word(p
, "\\(en");
1137 termp_bl_pre(DECL_ARGS
)
1140 return n
->type
!= ROFFT_HEAD
;
1144 termp_bl_post(DECL_ARGS
)
1147 if (n
->type
== ROFFT_BLOCK
)
1152 termp_xr_pre(DECL_ARGS
)
1155 if (NULL
== (n
= n
->child
))
1158 assert(n
->type
== ROFFT_TEXT
);
1159 term_word(p
, n
->string
);
1161 if (NULL
== (n
= n
->next
))
1164 p
->flags
|= TERMP_NOSPACE
;
1166 p
->flags
|= TERMP_NOSPACE
;
1168 assert(n
->type
== ROFFT_TEXT
);
1169 term_word(p
, n
->string
);
1171 p
->flags
|= TERMP_NOSPACE
;
1178 * This decides how to assert whitespace before any of the SYNOPSIS set
1179 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1183 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1186 * Obviously, if we're not in a SYNOPSIS or no prior macros
1187 * exist, do nothing.
1189 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
1193 * If we're the second in a pair of like elements, emit our
1194 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1195 * case we soldier on.
1197 if (n
->prev
->tok
== n
->tok
&&
1198 MDOC_Ft
!= n
->tok
&&
1199 MDOC_Fo
!= n
->tok
&&
1200 MDOC_Fn
!= n
->tok
) {
1206 * If we're one of the SYNOPSIS set and non-like pair-wise after
1207 * another (or Fn/Fo, which we've let slip through) then assert
1208 * vertical space, else only newline and move on.
1210 switch (n
->prev
->tok
) {
1219 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1231 termp_vt_pre(DECL_ARGS
)
1234 if (n
->type
== ROFFT_ELEM
) {
1236 return termp_under_pre(p
, pair
, meta
, n
);
1237 } else if (n
->type
== ROFFT_BLOCK
) {
1240 } else if (n
->type
== ROFFT_HEAD
)
1243 return termp_under_pre(p
, pair
, meta
, n
);
1247 termp_bold_pre(DECL_ARGS
)
1250 termp_tag_pre(p
, pair
, meta
, n
);
1251 term_fontpush(p
, TERMFONT_BOLD
);
1256 termp_fd_pre(DECL_ARGS
)
1260 return termp_bold_pre(p
, pair
, meta
, n
);
1264 termp_fd_post(DECL_ARGS
)
1271 termp_sh_pre(DECL_ARGS
)
1277 * Vertical space before sections, except
1278 * when the previous section was empty.
1280 if (n
->prev
== NULL
||
1281 n
->prev
->tok
!= MDOC_Sh
||
1282 (n
->prev
->body
!= NULL
&&
1283 n
->prev
->body
->child
!= NULL
))
1287 term_fontpush(p
, TERMFONT_BOLD
);
1290 p
->offset
= term_len(p
, p
->defindent
);
1292 case SEC_DESCRIPTION
:
1296 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1309 termp_sh_post(DECL_ARGS
)
1326 termp_lb_post(DECL_ARGS
)
1329 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
)
1334 termp_d1_pre(DECL_ARGS
)
1337 if (n
->type
!= ROFFT_BLOCK
)
1340 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1345 termp_ft_pre(DECL_ARGS
)
1348 /* NB: NODE_LINE does not effect this! */
1350 term_fontpush(p
, TERMFONT_UNDER
);
1355 termp_fn_pre(DECL_ARGS
)
1360 pretty
= NODE_SYNPRETTY
& n
->flags
;
1364 if (NULL
== (n
= n
->child
))
1368 rmargin
= p
->rmargin
;
1369 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1370 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1373 assert(n
->type
== ROFFT_TEXT
);
1374 term_fontpush(p
, TERMFONT_BOLD
);
1375 term_word(p
, n
->string
);
1378 if (n
->sec
== SEC_DESCRIPTION
|| n
->sec
== SEC_CUSTOM
)
1379 tag_put(n
->string
, ++fn_prio
, p
->line
);
1383 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1384 p
->offset
= p
->rmargin
;
1385 p
->rmargin
= rmargin
;
1388 p
->flags
|= TERMP_NOSPACE
;
1390 p
->flags
|= TERMP_NOSPACE
;
1392 for (n
= n
->next
; n
; n
= n
->next
) {
1393 assert(n
->type
== ROFFT_TEXT
);
1394 term_fontpush(p
, TERMFONT_UNDER
);
1396 p
->flags
|= TERMP_NBRWORD
;
1397 term_word(p
, n
->string
);
1401 p
->flags
|= TERMP_NOSPACE
;
1406 p
->flags
|= TERMP_NOSPACE
;
1410 p
->flags
|= TERMP_NOSPACE
;
1419 termp_fa_pre(DECL_ARGS
)
1421 const struct roff_node
*nn
;
1423 if (n
->parent
->tok
!= MDOC_Fo
) {
1424 term_fontpush(p
, TERMFONT_UNDER
);
1428 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1429 term_fontpush(p
, TERMFONT_UNDER
);
1430 p
->flags
|= TERMP_NBRWORD
;
1431 term_word(p
, nn
->string
);
1434 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1435 p
->flags
|= TERMP_NOSPACE
;
1444 termp_bd_pre(DECL_ARGS
)
1446 size_t tabwidth
, lm
, len
, rm
, rmax
;
1447 struct roff_node
*nn
;
1450 if (n
->type
== ROFFT_BLOCK
) {
1451 print_bvspace(p
, n
, n
);
1453 } else if (n
->type
== ROFFT_HEAD
)
1456 /* Handle the -offset argument. */
1458 if (n
->norm
->Bd
.offs
== NULL
||
1459 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1461 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1462 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1463 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1464 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1466 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1467 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
1469 else if (offset
< SHRT_MAX
)
1470 p
->offset
+= offset
;
1474 * If -ragged or -filled are specified, the block does nothing
1475 * but change the indentation. If -unfilled or -literal are
1476 * specified, text is printed exactly as entered in the display:
1477 * for macro lines, a newline is appended to the line. Blank
1478 * lines are allowed.
1481 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1482 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1483 DISP_centered
!= n
->norm
->Bd
.type
)
1486 tabwidth
= p
->tabwidth
;
1487 if (DISP_literal
== n
->norm
->Bd
.type
)
1488 p
->tabwidth
= term_len(p
, 8);
1492 rmax
= p
->maxrmargin
;
1493 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1495 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1496 if (DISP_centered
== n
->norm
->Bd
.type
) {
1497 if (nn
->type
== ROFFT_TEXT
) {
1498 len
= term_strlen(p
, nn
->string
);
1499 p
->offset
= len
>= rm
? 0 :
1500 lm
+ len
>= rm
? rm
- len
:
1501 (lm
+ rm
- len
) / 2;
1505 print_mdoc_node(p
, pair
, meta
, nn
);
1507 * If the printed node flushes its own line, then we
1508 * needn't do it here as well. This is hacky, but the
1509 * notion of selective eoln whitespace is pretty dumb
1510 * anyway, so don't sweat it.
1525 if (p
->flags
& TERMP_NONEWLINE
||
1526 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1529 p
->flags
|= TERMP_NOSPACE
;
1532 p
->tabwidth
= tabwidth
;
1534 p
->maxrmargin
= rmax
;
1539 termp_bd_post(DECL_ARGS
)
1543 if (n
->type
!= ROFFT_BODY
)
1547 rmax
= p
->maxrmargin
;
1549 if (DISP_literal
== n
->norm
->Bd
.type
||
1550 DISP_unfilled
== n
->norm
->Bd
.type
)
1551 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1553 p
->flags
|= TERMP_NOSPACE
;
1557 p
->maxrmargin
= rmax
;
1561 termp_xx_pre(DECL_ARGS
)
1563 if ((n
->aux
= p
->flags
& TERMP_PREKEEP
) == 0)
1564 p
->flags
|= TERMP_PREKEEP
;
1569 termp_xx_post(DECL_ARGS
)
1572 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1576 termp_pf_post(DECL_ARGS
)
1579 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1580 p
->flags
|= TERMP_NOSPACE
;
1584 termp_ss_pre(DECL_ARGS
)
1586 struct roff_node
*nn
;
1591 for (nn
= n
->prev
; nn
!= NULL
; nn
= nn
->prev
)
1592 if ((nn
->flags
& NODE_NOPRT
) == 0)
1598 term_fontpush(p
, TERMFONT_BOLD
);
1599 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1602 p
->offset
= term_len(p
, p
->defindent
);
1612 termp_ss_post(DECL_ARGS
)
1615 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1620 termp_cd_pre(DECL_ARGS
)
1624 term_fontpush(p
, TERMFONT_BOLD
);
1629 termp_in_pre(DECL_ARGS
)
1634 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
) {
1635 term_fontpush(p
, TERMFONT_BOLD
);
1636 term_word(p
, "#include");
1640 term_fontpush(p
, TERMFONT_UNDER
);
1643 p
->flags
|= TERMP_NOSPACE
;
1648 termp_in_post(DECL_ARGS
)
1651 if (NODE_SYNPRETTY
& n
->flags
)
1652 term_fontpush(p
, TERMFONT_BOLD
);
1654 p
->flags
|= TERMP_NOSPACE
;
1657 if (NODE_SYNPRETTY
& n
->flags
)
1662 termp_sp_pre(DECL_ARGS
)
1670 if ( ! a2roffsu(n
->child
->string
, &su
, SCALE_VS
))
1672 len
= term_vspan(p
, &su
);
1690 for (i
= 0; i
< len
; i
++)
1697 termp_skip_pre(DECL_ARGS
)
1704 termp_quote_pre(DECL_ARGS
)
1707 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1713 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1714 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1730 term_word(p
, "\\(Lq");
1733 if (NULL
== n
->norm
->Es
||
1734 NULL
== n
->norm
->Es
->child
)
1736 term_word(p
, n
->norm
->Es
->child
->string
);
1749 term_word(p
, "\\(oq");
1755 p
->flags
|= TERMP_NOSPACE
;
1760 termp_quote_post(DECL_ARGS
)
1763 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1766 p
->flags
|= TERMP_NOSPACE
;
1771 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1772 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1788 term_word(p
, "\\(Rq");
1791 if (n
->norm
->Es
== NULL
||
1792 n
->norm
->Es
->child
== NULL
||
1793 n
->norm
->Es
->child
->next
== NULL
)
1794 p
->flags
&= ~TERMP_NOSPACE
;
1796 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1809 term_word(p
, "\\(cq");
1817 termp_eo_pre(DECL_ARGS
)
1820 if (n
->type
!= ROFFT_BODY
)
1823 if (n
->end
== ENDBODY_NOT
&&
1824 n
->parent
->head
->child
== NULL
&&
1826 n
->child
->end
!= ENDBODY_NOT
)
1827 term_word(p
, "\\&");
1828 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1829 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1830 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1831 p
->flags
|= TERMP_NOSPACE
;
1837 termp_eo_post(DECL_ARGS
)
1841 if (n
->type
!= ROFFT_BODY
)
1844 if (n
->end
!= ENDBODY_NOT
) {
1845 p
->flags
&= ~TERMP_NOSPACE
;
1849 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1850 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1853 p
->flags
|= TERMP_NOSPACE
;
1854 else if ( ! (body
|| tail
))
1855 term_word(p
, "\\&");
1857 p
->flags
&= ~TERMP_NOSPACE
;
1861 termp_fo_pre(DECL_ARGS
)
1866 pretty
= NODE_SYNPRETTY
& n
->flags
;
1868 if (n
->type
== ROFFT_BLOCK
) {
1871 } else if (n
->type
== ROFFT_BODY
) {
1873 rmargin
= p
->rmargin
;
1874 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1875 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1878 p
->flags
|= TERMP_NOSPACE
;
1880 p
->flags
|= TERMP_NOSPACE
;
1883 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1885 p
->offset
= p
->rmargin
;
1886 p
->rmargin
= rmargin
;
1891 if (NULL
== n
->child
)
1894 /* XXX: we drop non-initial arguments as per groff. */
1896 assert(n
->child
->string
);
1897 term_fontpush(p
, TERMFONT_BOLD
);
1898 term_word(p
, n
->child
->string
);
1903 termp_fo_post(DECL_ARGS
)
1906 if (n
->type
!= ROFFT_BODY
)
1909 p
->flags
|= TERMP_NOSPACE
;
1912 if (NODE_SYNPRETTY
& n
->flags
) {
1913 p
->flags
|= TERMP_NOSPACE
;
1920 termp_bf_pre(DECL_ARGS
)
1923 if (n
->type
== ROFFT_HEAD
)
1925 else if (n
->type
!= ROFFT_BODY
)
1928 if (FONT_Em
== n
->norm
->Bf
.font
)
1929 term_fontpush(p
, TERMFONT_UNDER
);
1930 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1931 term_fontpush(p
, TERMFONT_BOLD
);
1933 term_fontpush(p
, TERMFONT_NONE
);
1939 termp_sm_pre(DECL_ARGS
)
1942 if (NULL
== n
->child
)
1943 p
->flags
^= TERMP_NONOSPACE
;
1944 else if (0 == strcmp("on", n
->child
->string
))
1945 p
->flags
&= ~TERMP_NONOSPACE
;
1947 p
->flags
|= TERMP_NONOSPACE
;
1949 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
1950 p
->flags
&= ~TERMP_NOSPACE
;
1956 termp_ap_pre(DECL_ARGS
)
1959 p
->flags
|= TERMP_NOSPACE
;
1961 p
->flags
|= TERMP_NOSPACE
;
1966 termp____post(DECL_ARGS
)
1970 * Handle lists of authors. In general, print each followed by
1971 * a comma. Don't print the comma if there are only two
1974 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1975 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1976 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1981 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1984 p
->flags
|= TERMP_NOSPACE
;
1985 if (NULL
== n
->next
) {
1987 p
->flags
|= TERMP_SENTENCE
;
1993 termp_li_pre(DECL_ARGS
)
1996 termp_tag_pre(p
, pair
, meta
, n
);
1997 term_fontpush(p
, TERMFONT_NONE
);
2002 termp_lk_pre(DECL_ARGS
)
2004 const struct roff_node
*link
, *descr
;
2007 if ((link
= n
->child
) == NULL
)
2011 if ((descr
= link
->next
) != NULL
&& !(descr
->flags
& NODE_DELIMC
)) {
2012 term_fontpush(p
, TERMFONT_UNDER
);
2013 while (descr
!= NULL
&& !(descr
->flags
& NODE_DELIMC
)) {
2014 term_word(p
, descr
->string
);
2015 descr
= descr
->next
;
2018 p
->flags
|= TERMP_NOSPACE
;
2023 display
= term_strlen(p
, link
->string
) >= 26;
2026 p
->offset
+= term_len(p
, p
->defindent
+ 1);
2028 term_fontpush(p
, TERMFONT_BOLD
);
2029 term_word(p
, link
->string
);
2032 /* Trailing punctuation. */
2033 while (descr
!= NULL
) {
2034 p
->flags
|= TERMP_NOSPACE
;
2035 term_word(p
, descr
->string
);
2036 descr
= descr
->next
;
2044 termp_bk_pre(DECL_ARGS
)
2053 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
2054 p
->flags
|= TERMP_PREKEEP
;
2064 termp_bk_post(DECL_ARGS
)
2067 if (n
->type
== ROFFT_BODY
)
2068 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2072 termp__t_post(DECL_ARGS
)
2076 * If we're in an `Rs' and there's a journal present, then quote
2077 * us instead of underlining us (for disambiguation).
2079 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2080 n
->parent
->norm
->Rs
.quote_T
)
2081 termp_quote_post(p
, pair
, meta
, n
);
2083 termp____post(p
, pair
, meta
, n
);
2087 termp__t_pre(DECL_ARGS
)
2091 * If we're in an `Rs' and there's a journal present, then quote
2092 * us instead of underlining us (for disambiguation).
2094 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2095 n
->parent
->norm
->Rs
.quote_T
)
2096 return termp_quote_pre(p
, pair
, meta
, n
);
2098 term_fontpush(p
, TERMFONT_UNDER
);
2103 termp_under_pre(DECL_ARGS
)
2106 term_fontpush(p
, TERMFONT_UNDER
);
2111 termp_em_pre(DECL_ARGS
)
2113 if (n
->child
!= NULL
&&
2114 n
->child
->type
== ROFFT_TEXT
)
2115 tag_put(n
->child
->string
, 0, p
->line
);
2116 term_fontpush(p
, TERMFONT_UNDER
);
2121 termp_sy_pre(DECL_ARGS
)
2123 if (n
->child
!= NULL
&&
2124 n
->child
->type
== ROFFT_TEXT
)
2125 tag_put(n
->child
->string
, 0, p
->line
);
2126 term_fontpush(p
, TERMFONT_BOLD
);
2131 termp_er_pre(DECL_ARGS
)
2134 if (n
->sec
== SEC_ERRORS
&&
2135 (n
->parent
->tok
== MDOC_It
||
2136 (n
->parent
->tok
== MDOC_Bq
&&
2137 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2138 tag_put(n
->child
->string
, 1, p
->line
);
2143 termp_tag_pre(DECL_ARGS
)
2146 if (n
->child
!= NULL
&&
2147 n
->child
->type
== ROFFT_TEXT
&&
2149 (n
->prev
->type
== ROFFT_TEXT
&&
2150 strcmp(n
->prev
->string
, "|") == 0)) &&
2151 (n
->parent
->tok
== MDOC_It
||
2152 (n
->parent
->tok
== MDOC_Xo
&&
2153 n
->parent
->parent
->prev
== NULL
&&
2154 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2155 tag_put(n
->child
->string
, 1, p
->line
);