]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.359 2017/06/01 19:05:37 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_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 termact __termacts
[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_ft_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_pp_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 */
249 static const struct termact
*const termacts
= __termacts
- MDOC_Dd
;
255 terminal_mdoc(void *arg
, const struct roff_man
*mdoc
)
259 size_t save_defindent
;
261 p
= (struct termp
*)arg
;
263 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
264 term_tab_set(p
, NULL
);
265 term_tab_set(p
, "T");
266 term_tab_set(p
, ".5i");
268 n
= mdoc
->first
->child
;
269 if (p
->synopsisonly
) {
271 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
272 if (n
->child
->next
->child
!= NULL
)
273 print_mdoc_nodelist(p
, NULL
,
275 n
->child
->next
->child
);
282 save_defindent
= p
->defindent
;
283 if (p
->defindent
== 0)
285 term_begin(p
, print_mdoc_head
, print_mdoc_foot
,
287 while (n
!= NULL
&& n
->flags
& NODE_NOPRT
)
290 if (n
->tok
!= MDOC_Sh
)
292 print_mdoc_nodelist(p
, NULL
, &mdoc
->meta
, n
);
295 p
->defindent
= save_defindent
;
300 print_mdoc_nodelist(DECL_ARGS
)
304 print_mdoc_node(p
, pair
, meta
, n
);
310 print_mdoc_node(DECL_ARGS
)
313 struct termpair npair
;
314 size_t offset
, rmargin
;
316 if (n
->flags
& NODE_NOPRT
)
321 rmargin
= p
->rmargin
;
322 n
->flags
&= ~NODE_ENDED
;
323 n
->prev_font
= p
->fonti
;
325 memset(&npair
, 0, sizeof(struct termpair
));
329 * Keeps only work until the end of a line. If a keep was
330 * invoked in a prior line, revert it to PREKEEP.
333 if (p
->flags
& TERMP_KEEP
&& n
->flags
& NODE_LINE
) {
334 p
->flags
&= ~TERMP_KEEP
;
335 p
->flags
|= TERMP_PREKEEP
;
339 * After the keep flags have been set up, we may now
340 * produce output. Note that some pre-handlers do so.
345 if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
346 (p
->flags
& TERMP_NONEWLINE
) == 0)
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
) {
371 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
372 if (termacts
[n
->tok
].pre
!= NULL
&&
373 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
374 chld
= (*termacts
[n
->tok
].pre
)
375 (p
, &npair
, meta
, n
);
379 if (chld
&& n
->child
)
380 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
383 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
393 if (termacts
[n
->tok
].post
== NULL
|| n
->flags
& NODE_ENDED
)
395 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
398 * Explicit end tokens not only call the post
399 * handler, but also tell the respective block
400 * that it must not call the post handler again.
402 if (ENDBODY_NOT
!= n
->end
)
403 n
->body
->flags
|= NODE_ENDED
;
407 if (NODE_EOS
& n
->flags
)
408 p
->flags
|= TERMP_SENTENCE
;
410 if (n
->type
!= ROFFT_TEXT
)
412 p
->rmargin
= rmargin
;
416 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
420 term_fontrepl(p
, TERMFONT_NONE
);
423 * Output the footer in new-groff style, that is, three columns
424 * with the middle being the manual date and flanking columns
425 * being the operating system:
433 sz
= term_strlen(p
, meta
->date
);
434 p
->rmargin
= p
->maxrmargin
> sz
?
435 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
437 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
439 term_word(p
, meta
->os
);
442 p
->offset
= p
->rmargin
;
443 sz
= term_strlen(p
, meta
->os
);
444 p
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
445 p
->flags
|= TERMP_NOSPACE
;
447 term_word(p
, meta
->date
);
450 p
->offset
= p
->rmargin
;
451 p
->rmargin
= p
->maxrmargin
;
453 p
->flags
&= ~TERMP_NOBREAK
;
454 p
->flags
|= TERMP_NOSPACE
;
456 term_word(p
, meta
->os
);
460 p
->rmargin
= p
->maxrmargin
;
465 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
467 char *volume
, *title
;
468 size_t vollen
, titlen
;
471 * The header is strange. It has three components, which are
472 * really two with the first duplicated. It goes like this:
474 * IDENTIFIER TITLE IDENTIFIER
476 * The IDENTIFIER is NAME(SECTION), which is the command-name
477 * (if given, or "unknown" if not) followed by the manual page
478 * section. These are given in `Dt'. The TITLE is a free-form
479 * string depending on the manual volume. If not specified, it
480 * switches on the manual section.
484 if (NULL
== meta
->arch
)
485 volume
= mandoc_strdup(meta
->vol
);
487 mandoc_asprintf(&volume
, "%s (%s)",
488 meta
->vol
, meta
->arch
);
489 vollen
= term_strlen(p
, volume
);
491 if (NULL
== meta
->msec
)
492 title
= mandoc_strdup(meta
->title
);
494 mandoc_asprintf(&title
, "%s(%s)",
495 meta
->title
, meta
->msec
);
496 titlen
= term_strlen(p
, title
);
498 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
501 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
502 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
503 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
508 p
->flags
|= TERMP_NOSPACE
;
509 p
->offset
= p
->rmargin
;
510 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
511 p
->maxrmargin
- titlen
: p
->maxrmargin
;
513 term_word(p
, volume
);
516 p
->flags
&= ~TERMP_NOBREAK
;
518 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
519 p
->flags
|= TERMP_NOSPACE
;
520 p
->offset
= p
->rmargin
;
521 p
->rmargin
= p
->maxrmargin
;
526 p
->flags
&= ~TERMP_NOSPACE
;
528 p
->rmargin
= p
->maxrmargin
;
534 a2width(const struct termp
*p
, const char *v
)
538 if (a2roffsu(v
, &su
, SCALE_MAX
) < 2) {
539 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
540 su
.scale
/= term_strlen(p
, "0");
542 return term_hspan(p
, &su
) / 24;
546 * Determine how much space to print out before block elements of `It'
547 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
551 print_bvspace(struct termp
*p
,
552 const struct roff_node
*bl
,
553 const struct roff_node
*n
)
555 const struct roff_node
*nn
;
561 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
563 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
566 /* Do not vspace directly after Ss/Sh. */
569 while (nn
->prev
!= NULL
&& nn
->prev
->flags
& NODE_NOPRT
)
571 while (nn
->prev
== NULL
) {
574 if (nn
->type
== ROFFT_ROOT
)
576 } while (nn
->type
!= ROFFT_BLOCK
);
577 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
579 if (nn
->tok
== MDOC_It
&&
580 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
584 /* A `-column' does not assert vspace within the list. */
586 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
587 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
590 /* A `-diag' without body does not vspace. */
592 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
593 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
594 assert(n
->prev
->body
);
595 if (NULL
== n
->prev
->body
->child
)
604 termp_it_pre(DECL_ARGS
)
608 const struct roff_node
*bl
, *nn
;
610 int i
, offset
, width
;
613 if (n
->type
== ROFFT_BLOCK
) {
614 print_bvspace(p
, n
->parent
->parent
, n
);
618 bl
= n
->parent
->parent
->parent
;
619 type
= bl
->norm
->Bl
.type
;
622 * Defaults for specific list types.
630 width
= term_len(p
, 2);
634 width
= term_len(p
, 8);
637 width
= term_len(p
, 10);
646 * First calculate width and offset. This is pretty easy unless
647 * we're a -column list, in which case all prior columns must
651 if (bl
->norm
->Bl
.offs
!= NULL
) {
652 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
653 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
655 else if (offset
> SHRT_MAX
)
661 if (n
->type
== ROFFT_HEAD
)
665 * Imitate groff's column handling:
666 * - For each earlier column, add its width.
667 * - For less than 5 columns, add four more blanks per
669 * - For exactly 5 columns, add three more blank per
671 * - For more than 5 columns, add only one column.
673 ncols
= bl
->norm
->Bl
.ncols
;
674 dcol
= ncols
< 5 ? term_len(p
, 4) :
675 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
678 * Calculate the offset by applying all prior ROFFT_BODY,
679 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
682 for (i
= 0, nn
= n
->prev
;
683 nn
->prev
&& i
< (int)ncols
;
684 nn
= nn
->prev
, i
++) {
686 term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
687 su
.scale
/= term_strlen(p
, "0");
688 offset
+= term_hspan(p
, &su
) / 24 + dcol
;
692 * When exceeding the declared number of columns, leave
693 * the remaining widths at 0. This will later be
694 * adjusted to the default width of 10, or, for the last
695 * column, stretched to the right margin.
701 * Use the declared column widths, extended as explained
702 * in the preceding paragraph.
704 SCALE_HS_INIT(&su
, term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
705 su
.scale
/= term_strlen(p
, "0");
706 width
= term_hspan(p
, &su
) / 24 + dcol
;
709 if (NULL
== bl
->norm
->Bl
.width
)
713 * Note: buffer the width by 2, which is groff's magic
714 * number for buffering single arguments. See the above
715 * handling for column for how this changes.
717 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
718 if (width
< 0 && (size_t)(-width
) > p
->offset
)
720 else if (width
> SHRT_MAX
)
726 * Whitespace control. Inset bodies need an initial space,
727 * while diagonal bodies need two.
730 p
->flags
|= TERMP_NOSPACE
;
734 if (n
->type
== ROFFT_BODY
)
735 term_word(p
, "\\ \\ ");
738 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
745 p
->flags
|= TERMP_NOSPACE
;
749 if (n
->type
== ROFFT_HEAD
)
750 term_fontpush(p
, TERMFONT_BOLD
);
757 * Pad and break control. This is the tricky part. These flags
758 * are documented in term_flushln() in term.c. Note that we're
759 * going to unset all of these flags in termp_it_post() when we
769 * Weird special case.
770 * Some very narrow lists actually hang.
772 if (width
<= (int)term_len(p
, 2))
773 p
->flags
|= TERMP_HANG
;
774 if (n
->type
!= ROFFT_HEAD
)
776 p
->flags
|= TERMP_NOBREAK
;
780 if (n
->type
!= ROFFT_HEAD
)
784 * This is ugly. If `-hang' is specified and the body
785 * is a `Bl' or `Bd', then we want basically to nullify
786 * the "overstep" effect in term_flushln() and treat
787 * this as a `-ohang' list instead.
789 if (NULL
!= n
->next
&&
790 NULL
!= n
->next
->child
&&
791 (MDOC_Bl
== n
->next
->child
->tok
||
792 MDOC_Bd
== n
->next
->child
->tok
))
795 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
799 if (n
->type
!= ROFFT_HEAD
)
802 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
805 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
806 p
->flags
|= TERMP_DANGLE
;
809 if (n
->type
== ROFFT_HEAD
)
812 if (NULL
== n
->next
) {
813 p
->flags
&= ~TERMP_NOBREAK
;
816 p
->flags
|= TERMP_NOBREAK
;
822 if (n
->type
!= ROFFT_HEAD
)
824 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
832 * Margin control. Set-head-width lists have their right
833 * margins shortened. The body for these lists has the offset
834 * necessarily lengthened. Everybody gets the offset.
842 * Same stipulation as above, regarding `-hang'. We
843 * don't want to recalculate rmargin and offsets when
844 * using `Bd' or `Bl' within `-hang' overstep lists.
846 if (n
->type
== ROFFT_HEAD
&&
848 NULL
!= n
->next
->child
&&
849 (MDOC_Bl
== n
->next
->child
->tok
||
850 MDOC_Bd
== n
->next
->child
->tok
))
858 if (n
->type
== ROFFT_HEAD
)
859 p
->rmargin
= p
->offset
+ width
;
865 p
->rmargin
= p
->offset
+ width
;
867 * XXX - this behaviour is not documented: the
868 * right-most column is filled to the right margin.
870 if (n
->type
== ROFFT_HEAD
)
872 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
873 p
->rmargin
= p
->maxrmargin
;
880 * The dash, hyphen, bullet and enum lists all have a special
881 * HEAD character (temporarily bold, in some cases).
884 if (n
->type
== ROFFT_HEAD
)
887 term_fontpush(p
, TERMFONT_BOLD
);
888 term_word(p
, "\\[bu]");
893 term_fontpush(p
, TERMFONT_BOLD
);
898 (pair
->ppair
->ppair
->count
)++;
899 (void)snprintf(buf
, sizeof(buf
), "%d.",
900 pair
->ppair
->ppair
->count
);
908 * If we're not going to process our children, indicate so here.
917 if (n
->type
== ROFFT_HEAD
)
921 if (n
->type
== ROFFT_HEAD
)
932 termp_it_post(DECL_ARGS
)
936 if (n
->type
== ROFFT_BLOCK
)
939 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
945 if (n
->type
== ROFFT_BODY
)
949 if (n
->type
== ROFFT_BODY
)
958 * Now that our output is flushed, we can reset our tags. Since
959 * only `It' sets these flags, we're free to assume that nobody
960 * has munged them in the meanwhile.
963 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
|
964 TERMP_DANGLE
| TERMP_HANG
);
969 termp_nm_pre(DECL_ARGS
)
973 if (n
->type
== ROFFT_BLOCK
) {
974 p
->flags
|= TERMP_PREKEEP
;
978 if (n
->type
== ROFFT_BODY
) {
979 if (NULL
== n
->child
)
981 p
->flags
|= TERMP_NOSPACE
;
983 if (n
->prev
->child
!= NULL
)
984 cp
= n
->prev
->child
->string
;
988 p
->offset
+= term_len(p
, 6);
990 p
->offset
+= term_len(p
, 1) + term_strlen(p
, cp
);
994 if (n
->child
== NULL
)
997 if (n
->type
== ROFFT_HEAD
)
998 synopsis_pre(p
, n
->parent
);
1000 if (n
->type
== ROFFT_HEAD
&&
1001 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1002 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1004 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1005 if (NULL
== n
->child
) {
1006 p
->rmargin
+= term_strlen(p
, meta
->name
);
1007 } else if (n
->child
->type
== ROFFT_TEXT
) {
1008 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1010 p
->flags
|= TERMP_HANG
;
1012 p
->rmargin
+= term_len(p
, 5);
1013 p
->flags
|= TERMP_HANG
;
1017 term_fontpush(p
, TERMFONT_BOLD
);
1022 termp_nm_post(DECL_ARGS
)
1025 if (n
->type
== ROFFT_BLOCK
) {
1026 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1027 } else if (n
->type
== ROFFT_HEAD
&&
1028 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1030 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1032 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1037 termp_fl_pre(DECL_ARGS
)
1040 termp_tag_pre(p
, pair
, meta
, n
);
1041 term_fontpush(p
, TERMFONT_BOLD
);
1042 term_word(p
, "\\-");
1044 if (!(n
->child
== NULL
&&
1046 n
->next
->type
== ROFFT_TEXT
||
1047 n
->next
->flags
& NODE_LINE
)))
1048 p
->flags
|= TERMP_NOSPACE
;
1054 termp__a_pre(DECL_ARGS
)
1057 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1058 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1059 term_word(p
, "and");
1065 termp_an_pre(DECL_ARGS
)
1068 if (n
->norm
->An
.auth
== AUTH_split
) {
1069 p
->flags
&= ~TERMP_NOSPLIT
;
1070 p
->flags
|= TERMP_SPLIT
;
1073 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1074 p
->flags
&= ~TERMP_SPLIT
;
1075 p
->flags
|= TERMP_NOSPLIT
;
1079 if (p
->flags
& TERMP_SPLIT
)
1082 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1083 p
->flags
|= TERMP_SPLIT
;
1089 termp_ns_pre(DECL_ARGS
)
1092 if ( ! (NODE_LINE
& n
->flags
))
1093 p
->flags
|= TERMP_NOSPACE
;
1098 termp_rs_pre(DECL_ARGS
)
1101 if (SEC_SEE_ALSO
!= n
->sec
)
1103 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1109 termp_ex_pre(DECL_ARGS
)
1116 termp_nd_pre(DECL_ARGS
)
1119 if (n
->type
== ROFFT_BODY
)
1120 term_word(p
, "\\(en");
1125 termp_bl_pre(DECL_ARGS
)
1128 return n
->type
!= ROFFT_HEAD
;
1132 termp_bl_post(DECL_ARGS
)
1135 if (n
->type
!= ROFFT_BLOCK
)
1138 if (n
->tok
!= MDOC_Bl
|| n
->norm
->Bl
.type
!= LIST_column
)
1140 term_tab_set(p
, NULL
);
1141 term_tab_set(p
, "T");
1142 term_tab_set(p
, ".5i");
1146 termp_xr_pre(DECL_ARGS
)
1149 if (NULL
== (n
= n
->child
))
1152 assert(n
->type
== ROFFT_TEXT
);
1153 term_word(p
, n
->string
);
1155 if (NULL
== (n
= n
->next
))
1158 p
->flags
|= TERMP_NOSPACE
;
1160 p
->flags
|= TERMP_NOSPACE
;
1162 assert(n
->type
== ROFFT_TEXT
);
1163 term_word(p
, n
->string
);
1165 p
->flags
|= TERMP_NOSPACE
;
1172 * This decides how to assert whitespace before any of the SYNOPSIS set
1173 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1177 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1180 * Obviously, if we're not in a SYNOPSIS or no prior macros
1181 * exist, do nothing.
1183 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
1187 * If we're the second in a pair of like elements, emit our
1188 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1189 * case we soldier on.
1191 if (n
->prev
->tok
== n
->tok
&&
1192 MDOC_Ft
!= n
->tok
&&
1193 MDOC_Fo
!= n
->tok
&&
1194 MDOC_Fn
!= n
->tok
) {
1200 * If we're one of the SYNOPSIS set and non-like pair-wise after
1201 * another (or Fn/Fo, which we've let slip through) then assert
1202 * vertical space, else only newline and move on.
1204 switch (n
->prev
->tok
) {
1213 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1225 termp_vt_pre(DECL_ARGS
)
1228 if (n
->type
== ROFFT_ELEM
) {
1230 return termp_under_pre(p
, pair
, meta
, n
);
1231 } else if (n
->type
== ROFFT_BLOCK
) {
1234 } else if (n
->type
== ROFFT_HEAD
)
1237 return termp_under_pre(p
, pair
, meta
, n
);
1241 termp_bold_pre(DECL_ARGS
)
1244 termp_tag_pre(p
, pair
, meta
, n
);
1245 term_fontpush(p
, TERMFONT_BOLD
);
1250 termp_fd_pre(DECL_ARGS
)
1254 return termp_bold_pre(p
, pair
, meta
, n
);
1258 termp_fd_post(DECL_ARGS
)
1265 termp_sh_pre(DECL_ARGS
)
1271 * Vertical space before sections, except
1272 * when the previous section was empty.
1274 if (n
->prev
== NULL
||
1275 n
->prev
->tok
!= MDOC_Sh
||
1276 (n
->prev
->body
!= NULL
&&
1277 n
->prev
->body
->child
!= NULL
))
1281 term_fontpush(p
, TERMFONT_BOLD
);
1284 p
->offset
= term_len(p
, p
->defindent
);
1285 term_tab_set(p
, NULL
);
1286 term_tab_set(p
, "T");
1287 term_tab_set(p
, ".5i");
1289 case SEC_DESCRIPTION
:
1293 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1306 termp_sh_post(DECL_ARGS
)
1323 termp_lb_post(DECL_ARGS
)
1326 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
)
1331 termp_d1_pre(DECL_ARGS
)
1334 if (n
->type
!= ROFFT_BLOCK
)
1337 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1338 term_tab_set(p
, NULL
);
1339 term_tab_set(p
, "T");
1340 term_tab_set(p
, ".5i");
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 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 if (n
->norm
->Bd
.type
== DISP_literal
) {
1487 term_tab_set(p
, NULL
);
1488 term_tab_set(p
, "T");
1489 term_tab_set(p
, "8n");
1494 rmax
= p
->maxrmargin
;
1495 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1497 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1498 if (DISP_centered
== n
->norm
->Bd
.type
) {
1499 if (nn
->type
== ROFFT_TEXT
) {
1500 len
= term_strlen(p
, nn
->string
);
1501 p
->offset
= len
>= rm
? 0 :
1502 lm
+ len
>= rm
? rm
- len
:
1503 (lm
+ rm
- len
) / 2;
1507 print_mdoc_node(p
, pair
, meta
, nn
);
1509 * If the printed node flushes its own line, then we
1510 * needn't do it here as well. This is hacky, but the
1511 * notion of selective eoln whitespace is pretty dumb
1512 * anyway, so don't sweat it.
1514 if (nn
->tok
< ROFF_MAX
)
1527 if (p
->flags
& TERMP_NONEWLINE
||
1528 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1531 p
->flags
|= TERMP_NOSPACE
;
1535 p
->maxrmargin
= rmax
;
1540 termp_bd_post(DECL_ARGS
)
1544 if (n
->type
!= ROFFT_BODY
)
1548 rmax
= p
->maxrmargin
;
1550 if (DISP_literal
== n
->norm
->Bd
.type
||
1551 DISP_unfilled
== n
->norm
->Bd
.type
)
1552 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1554 p
->flags
|= TERMP_NOSPACE
;
1558 p
->maxrmargin
= rmax
;
1562 termp_xx_pre(DECL_ARGS
)
1564 if ((n
->aux
= p
->flags
& TERMP_PREKEEP
) == 0)
1565 p
->flags
|= TERMP_PREKEEP
;
1570 termp_xx_post(DECL_ARGS
)
1573 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1577 termp_pf_post(DECL_ARGS
)
1580 if ( ! (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
))
1581 p
->flags
|= TERMP_NOSPACE
;
1585 termp_ss_pre(DECL_ARGS
)
1587 struct roff_node
*nn
;
1592 for (nn
= n
->prev
; nn
!= NULL
; nn
= nn
->prev
)
1593 if ((nn
->flags
& NODE_NOPRT
) == 0)
1599 term_fontpush(p
, TERMFONT_BOLD
);
1600 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1603 p
->offset
= term_len(p
, p
->defindent
);
1604 term_tab_set(p
, NULL
);
1605 term_tab_set(p
, "T");
1606 term_tab_set(p
, ".5i");
1616 termp_ss_post(DECL_ARGS
)
1619 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1624 termp_cd_pre(DECL_ARGS
)
1628 term_fontpush(p
, TERMFONT_BOLD
);
1633 termp_in_pre(DECL_ARGS
)
1638 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
) {
1639 term_fontpush(p
, TERMFONT_BOLD
);
1640 term_word(p
, "#include");
1644 term_fontpush(p
, TERMFONT_UNDER
);
1647 p
->flags
|= TERMP_NOSPACE
;
1652 termp_in_post(DECL_ARGS
)
1655 if (NODE_SYNPRETTY
& n
->flags
)
1656 term_fontpush(p
, TERMFONT_BOLD
);
1658 p
->flags
|= TERMP_NOSPACE
;
1661 if (NODE_SYNPRETTY
& n
->flags
)
1666 termp_pp_pre(DECL_ARGS
)
1674 termp_skip_pre(DECL_ARGS
)
1681 termp_quote_pre(DECL_ARGS
)
1684 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1690 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1691 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1707 term_word(p
, "\\(Lq");
1710 if (NULL
== n
->norm
->Es
||
1711 NULL
== n
->norm
->Es
->child
)
1713 term_word(p
, n
->norm
->Es
->child
->string
);
1726 term_word(p
, "\\(oq");
1732 p
->flags
|= TERMP_NOSPACE
;
1737 termp_quote_post(DECL_ARGS
)
1740 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1743 p
->flags
|= TERMP_NOSPACE
;
1748 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1749 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1765 term_word(p
, "\\(Rq");
1768 if (n
->norm
->Es
== NULL
||
1769 n
->norm
->Es
->child
== NULL
||
1770 n
->norm
->Es
->child
->next
== NULL
)
1771 p
->flags
&= ~TERMP_NOSPACE
;
1773 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1786 term_word(p
, "\\(cq");
1794 termp_eo_pre(DECL_ARGS
)
1797 if (n
->type
!= ROFFT_BODY
)
1800 if (n
->end
== ENDBODY_NOT
&&
1801 n
->parent
->head
->child
== NULL
&&
1803 n
->child
->end
!= ENDBODY_NOT
)
1804 term_word(p
, "\\&");
1805 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1806 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1807 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1808 p
->flags
|= TERMP_NOSPACE
;
1814 termp_eo_post(DECL_ARGS
)
1818 if (n
->type
!= ROFFT_BODY
)
1821 if (n
->end
!= ENDBODY_NOT
) {
1822 p
->flags
&= ~TERMP_NOSPACE
;
1826 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1827 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1830 p
->flags
|= TERMP_NOSPACE
;
1831 else if ( ! (body
|| tail
))
1832 term_word(p
, "\\&");
1834 p
->flags
&= ~TERMP_NOSPACE
;
1838 termp_fo_pre(DECL_ARGS
)
1843 pretty
= NODE_SYNPRETTY
& n
->flags
;
1845 if (n
->type
== ROFFT_BLOCK
) {
1848 } else if (n
->type
== ROFFT_BODY
) {
1850 rmargin
= p
->rmargin
;
1851 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1852 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1855 p
->flags
|= TERMP_NOSPACE
;
1857 p
->flags
|= TERMP_NOSPACE
;
1860 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1862 p
->offset
= p
->rmargin
;
1863 p
->rmargin
= rmargin
;
1868 if (NULL
== n
->child
)
1871 /* XXX: we drop non-initial arguments as per groff. */
1873 assert(n
->child
->string
);
1874 term_fontpush(p
, TERMFONT_BOLD
);
1875 term_word(p
, n
->child
->string
);
1880 termp_fo_post(DECL_ARGS
)
1883 if (n
->type
!= ROFFT_BODY
)
1886 p
->flags
|= TERMP_NOSPACE
;
1889 if (NODE_SYNPRETTY
& n
->flags
) {
1890 p
->flags
|= TERMP_NOSPACE
;
1897 termp_bf_pre(DECL_ARGS
)
1900 if (n
->type
== ROFFT_HEAD
)
1902 else if (n
->type
!= ROFFT_BODY
)
1905 if (FONT_Em
== n
->norm
->Bf
.font
)
1906 term_fontpush(p
, TERMFONT_UNDER
);
1907 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1908 term_fontpush(p
, TERMFONT_BOLD
);
1910 term_fontpush(p
, TERMFONT_NONE
);
1916 termp_sm_pre(DECL_ARGS
)
1919 if (NULL
== n
->child
)
1920 p
->flags
^= TERMP_NONOSPACE
;
1921 else if (0 == strcmp("on", n
->child
->string
))
1922 p
->flags
&= ~TERMP_NONOSPACE
;
1924 p
->flags
|= TERMP_NONOSPACE
;
1926 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
1927 p
->flags
&= ~TERMP_NOSPACE
;
1933 termp_ap_pre(DECL_ARGS
)
1936 p
->flags
|= TERMP_NOSPACE
;
1938 p
->flags
|= TERMP_NOSPACE
;
1943 termp____post(DECL_ARGS
)
1947 * Handle lists of authors. In general, print each followed by
1948 * a comma. Don't print the comma if there are only two
1951 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1952 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1953 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1958 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1961 p
->flags
|= TERMP_NOSPACE
;
1962 if (NULL
== n
->next
) {
1964 p
->flags
|= TERMP_SENTENCE
;
1970 termp_li_pre(DECL_ARGS
)
1973 termp_tag_pre(p
, pair
, meta
, n
);
1974 term_fontpush(p
, TERMFONT_NONE
);
1979 termp_lk_pre(DECL_ARGS
)
1981 const struct roff_node
*link
, *descr
, *punct
;
1984 if ((link
= n
->child
) == NULL
)
1987 /* Find beginning of trailing punctuation. */
1989 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1990 punct
= punct
->prev
;
1991 punct
= punct
->next
;
1994 if ((descr
= link
->next
) != NULL
&& descr
!= punct
) {
1995 term_fontpush(p
, TERMFONT_UNDER
);
1996 while (descr
!= punct
) {
1997 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1998 p
->flags
|= TERMP_NOSPACE
;
1999 term_word(p
, descr
->string
);
2000 descr
= descr
->next
;
2003 p
->flags
|= TERMP_NOSPACE
;
2008 display
= term_strlen(p
, link
->string
) >= 26;
2011 p
->offset
+= term_len(p
, p
->defindent
+ 1);
2013 term_fontpush(p
, TERMFONT_BOLD
);
2014 term_word(p
, link
->string
);
2017 /* Trailing punctuation. */
2018 while (punct
!= NULL
) {
2019 p
->flags
|= TERMP_NOSPACE
;
2020 term_word(p
, punct
->string
);
2021 punct
= punct
->next
;
2029 termp_bk_pre(DECL_ARGS
)
2038 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
2039 p
->flags
|= TERMP_PREKEEP
;
2049 termp_bk_post(DECL_ARGS
)
2052 if (n
->type
== ROFFT_BODY
)
2053 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2057 termp__t_post(DECL_ARGS
)
2061 * If we're in an `Rs' and there's a journal present, then quote
2062 * us instead of underlining us (for disambiguation).
2064 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2065 n
->parent
->norm
->Rs
.quote_T
)
2066 termp_quote_post(p
, pair
, meta
, n
);
2068 termp____post(p
, pair
, meta
, n
);
2072 termp__t_pre(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 return termp_quote_pre(p
, pair
, meta
, n
);
2083 term_fontpush(p
, TERMFONT_UNDER
);
2088 termp_under_pre(DECL_ARGS
)
2091 term_fontpush(p
, TERMFONT_UNDER
);
2096 termp_em_pre(DECL_ARGS
)
2098 if (n
->child
!= NULL
&&
2099 n
->child
->type
== ROFFT_TEXT
)
2100 tag_put(n
->child
->string
, 0, p
->line
);
2101 term_fontpush(p
, TERMFONT_UNDER
);
2106 termp_sy_pre(DECL_ARGS
)
2108 if (n
->child
!= NULL
&&
2109 n
->child
->type
== ROFFT_TEXT
)
2110 tag_put(n
->child
->string
, 0, p
->line
);
2111 term_fontpush(p
, TERMFONT_BOLD
);
2116 termp_er_pre(DECL_ARGS
)
2119 if (n
->sec
== SEC_ERRORS
&&
2120 (n
->parent
->tok
== MDOC_It
||
2121 (n
->parent
->tok
== MDOC_Bq
&&
2122 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2123 tag_put(n
->child
->string
, 1, p
->line
);
2128 termp_tag_pre(DECL_ARGS
)
2131 if (n
->child
!= NULL
&&
2132 n
->child
->type
== ROFFT_TEXT
&&
2134 (n
->prev
->type
== ROFFT_TEXT
&&
2135 strcmp(n
->prev
->string
, "|") == 0)) &&
2136 (n
->parent
->tok
== MDOC_It
||
2137 (n
->parent
->tok
== MDOC_Xo
&&
2138 n
->parent
->parent
->prev
== NULL
&&
2139 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2140 tag_put(n
->child
->string
, 1, p
->line
);