]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.358 2017/05/30 16:31:29 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
;
411 p
->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
->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
->offset
= p
->rmargin
;
442 sz
= term_strlen(p
, meta
->os
);
443 p
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
444 p
->flags
|= TERMP_NOSPACE
;
446 term_word(p
, meta
->date
);
449 p
->offset
= p
->rmargin
;
450 p
->rmargin
= p
->maxrmargin
;
452 p
->flags
&= ~TERMP_NOBREAK
;
453 p
->flags
|= TERMP_NOSPACE
;
455 term_word(p
, meta
->os
);
459 p
->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
->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
->offset
= p
->rmargin
;
509 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
510 p
->maxrmargin
- titlen
: p
->maxrmargin
;
512 term_word(p
, volume
);
515 p
->flags
&= ~TERMP_NOBREAK
;
517 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
518 p
->flags
|= TERMP_NOSPACE
;
519 p
->offset
= p
->rmargin
;
520 p
->rmargin
= p
->maxrmargin
;
525 p
->flags
&= ~TERMP_NOSPACE
;
527 p
->rmargin
= p
->maxrmargin
;
533 a2width(const struct termp
*p
, const char *v
)
537 if (a2roffsu(v
, &su
, SCALE_MAX
) < 2) {
538 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
539 su
.scale
/= term_strlen(p
, "0");
541 return term_hspan(p
, &su
) / 24;
545 * Determine how much space to print out before block elements of `It'
546 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
550 print_bvspace(struct termp
*p
,
551 const struct roff_node
*bl
,
552 const struct roff_node
*n
)
554 const struct roff_node
*nn
;
560 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
562 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
565 /* Do not vspace directly after Ss/Sh. */
568 while (nn
->prev
!= NULL
&& nn
->prev
->flags
& NODE_NOPRT
)
570 while (nn
->prev
== NULL
) {
573 if (nn
->type
== ROFFT_ROOT
)
575 } while (nn
->type
!= ROFFT_BLOCK
);
576 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
578 if (nn
->tok
== MDOC_It
&&
579 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
583 /* A `-column' does not assert vspace within the list. */
585 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
586 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
589 /* A `-diag' without body does not vspace. */
591 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
592 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
593 assert(n
->prev
->body
);
594 if (NULL
== n
->prev
->body
->child
)
603 termp_it_pre(DECL_ARGS
)
607 const struct roff_node
*bl
, *nn
;
609 int i
, offset
, width
;
612 if (n
->type
== ROFFT_BLOCK
) {
613 print_bvspace(p
, n
->parent
->parent
, n
);
617 bl
= n
->parent
->parent
->parent
;
618 type
= bl
->norm
->Bl
.type
;
621 * Defaults for specific list types.
629 width
= term_len(p
, 2);
633 width
= term_len(p
, 8);
636 width
= term_len(p
, 10);
645 * First calculate width and offset. This is pretty easy unless
646 * we're a -column list, in which case all prior columns must
650 if (bl
->norm
->Bl
.offs
!= NULL
) {
651 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
652 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
654 else if (offset
> SHRT_MAX
)
660 if (n
->type
== ROFFT_HEAD
)
664 * Imitate groff's column handling:
665 * - For each earlier column, add its width.
666 * - For less than 5 columns, add four more blanks per
668 * - For exactly 5 columns, add three more blank per
670 * - For more than 5 columns, add only one column.
672 ncols
= bl
->norm
->Bl
.ncols
;
673 dcol
= ncols
< 5 ? term_len(p
, 4) :
674 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
677 * Calculate the offset by applying all prior ROFFT_BODY,
678 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
681 for (i
= 0, nn
= n
->prev
;
682 nn
->prev
&& i
< (int)ncols
;
683 nn
= nn
->prev
, i
++) {
685 term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
686 su
.scale
/= term_strlen(p
, "0");
687 offset
+= term_hspan(p
, &su
) / 24 + dcol
;
691 * When exceeding the declared number of columns, leave
692 * the remaining widths at 0. This will later be
693 * adjusted to the default width of 10, or, for the last
694 * column, stretched to the right margin.
700 * Use the declared column widths, extended as explained
701 * in the preceding paragraph.
703 SCALE_HS_INIT(&su
, term_strlen(p
, bl
->norm
->Bl
.cols
[i
]));
704 su
.scale
/= term_strlen(p
, "0");
705 width
= term_hspan(p
, &su
) / 24 + dcol
;
708 if (NULL
== bl
->norm
->Bl
.width
)
712 * Note: buffer the width by 2, which is groff's magic
713 * number for buffering single arguments. See the above
714 * handling for column for how this changes.
716 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
717 if (width
< 0 && (size_t)(-width
) > p
->offset
)
719 else if (width
> SHRT_MAX
)
725 * Whitespace control. Inset bodies need an initial space,
726 * while diagonal bodies need two.
729 p
->flags
|= TERMP_NOSPACE
;
733 if (n
->type
== ROFFT_BODY
)
734 term_word(p
, "\\ \\ ");
737 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
744 p
->flags
|= TERMP_NOSPACE
;
748 if (n
->type
== ROFFT_HEAD
)
749 term_fontpush(p
, TERMFONT_BOLD
);
756 * Pad and break control. This is the tricky part. These flags
757 * are documented in term_flushln() in term.c. Note that we're
758 * going to unset all of these flags in termp_it_post() when we
768 * Weird special case.
769 * Some very narrow lists actually hang.
771 if (width
<= (int)term_len(p
, 2))
772 p
->flags
|= TERMP_HANG
;
773 if (n
->type
!= ROFFT_HEAD
)
775 p
->flags
|= TERMP_NOBREAK
;
779 if (n
->type
!= ROFFT_HEAD
)
783 * This is ugly. If `-hang' is specified and the body
784 * is a `Bl' or `Bd', then we want basically to nullify
785 * the "overstep" effect in term_flushln() and treat
786 * this as a `-ohang' list instead.
788 if (NULL
!= n
->next
&&
789 NULL
!= n
->next
->child
&&
790 (MDOC_Bl
== n
->next
->child
->tok
||
791 MDOC_Bd
== n
->next
->child
->tok
))
794 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
798 if (n
->type
!= ROFFT_HEAD
)
801 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
804 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
805 p
->flags
|= TERMP_DANGLE
;
808 if (n
->type
== ROFFT_HEAD
)
811 if (NULL
== n
->next
) {
812 p
->flags
&= ~TERMP_NOBREAK
;
815 p
->flags
|= TERMP_NOBREAK
;
821 if (n
->type
!= ROFFT_HEAD
)
823 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
831 * Margin control. Set-head-width lists have their right
832 * margins shortened. The body for these lists has the offset
833 * necessarily lengthened. Everybody gets the offset.
841 * Same stipulation as above, regarding `-hang'. We
842 * don't want to recalculate rmargin and offsets when
843 * using `Bd' or `Bl' within `-hang' overstep lists.
845 if (n
->type
== ROFFT_HEAD
&&
847 NULL
!= n
->next
->child
&&
848 (MDOC_Bl
== n
->next
->child
->tok
||
849 MDOC_Bd
== n
->next
->child
->tok
))
857 if (n
->type
== ROFFT_HEAD
)
858 p
->rmargin
= p
->offset
+ width
;
864 p
->rmargin
= p
->offset
+ width
;
866 * XXX - this behaviour is not documented: the
867 * right-most column is filled to the right margin.
869 if (n
->type
== ROFFT_HEAD
)
871 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
872 p
->rmargin
= p
->maxrmargin
;
879 * The dash, hyphen, bullet and enum lists all have a special
880 * HEAD character (temporarily bold, in some cases).
883 if (n
->type
== ROFFT_HEAD
)
886 term_fontpush(p
, TERMFONT_BOLD
);
887 term_word(p
, "\\[bu]");
892 term_fontpush(p
, TERMFONT_BOLD
);
897 (pair
->ppair
->ppair
->count
)++;
898 (void)snprintf(buf
, sizeof(buf
), "%d.",
899 pair
->ppair
->ppair
->count
);
907 * If we're not going to process our children, indicate so here.
916 if (n
->type
== ROFFT_HEAD
)
920 if (n
->type
== ROFFT_HEAD
)
931 termp_it_post(DECL_ARGS
)
935 if (n
->type
== ROFFT_BLOCK
)
938 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
944 if (n
->type
== ROFFT_BODY
)
948 if (n
->type
== ROFFT_BODY
)
957 * Now that our output is flushed, we can reset our tags. Since
958 * only `It' sets these flags, we're free to assume that nobody
959 * has munged them in the meanwhile.
962 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
|
963 TERMP_DANGLE
| TERMP_HANG
);
968 termp_nm_pre(DECL_ARGS
)
972 if (n
->type
== ROFFT_BLOCK
) {
973 p
->flags
|= TERMP_PREKEEP
;
977 if (n
->type
== ROFFT_BODY
) {
978 if (NULL
== n
->child
)
980 p
->flags
|= TERMP_NOSPACE
;
982 if (n
->prev
->child
!= NULL
)
983 cp
= n
->prev
->child
->string
;
987 p
->offset
+= term_len(p
, 6);
989 p
->offset
+= term_len(p
, 1) + term_strlen(p
, cp
);
993 if (n
->child
== NULL
)
996 if (n
->type
== ROFFT_HEAD
)
997 synopsis_pre(p
, n
->parent
);
999 if (n
->type
== ROFFT_HEAD
&&
1000 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1001 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1003 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1004 if (NULL
== n
->child
) {
1005 p
->rmargin
+= term_strlen(p
, meta
->name
);
1006 } else if (n
->child
->type
== ROFFT_TEXT
) {
1007 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1009 p
->flags
|= TERMP_HANG
;
1011 p
->rmargin
+= term_len(p
, 5);
1012 p
->flags
|= TERMP_HANG
;
1016 term_fontpush(p
, TERMFONT_BOLD
);
1021 termp_nm_post(DECL_ARGS
)
1024 if (n
->type
== ROFFT_BLOCK
) {
1025 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1026 } else if (n
->type
== ROFFT_HEAD
&&
1027 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1029 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1031 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1036 termp_fl_pre(DECL_ARGS
)
1039 termp_tag_pre(p
, pair
, meta
, n
);
1040 term_fontpush(p
, TERMFONT_BOLD
);
1041 term_word(p
, "\\-");
1043 if (!(n
->child
== NULL
&&
1045 n
->next
->type
== ROFFT_TEXT
||
1046 n
->next
->flags
& NODE_LINE
)))
1047 p
->flags
|= TERMP_NOSPACE
;
1053 termp__a_pre(DECL_ARGS
)
1056 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1057 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1058 term_word(p
, "and");
1064 termp_an_pre(DECL_ARGS
)
1067 if (n
->norm
->An
.auth
== AUTH_split
) {
1068 p
->flags
&= ~TERMP_NOSPLIT
;
1069 p
->flags
|= TERMP_SPLIT
;
1072 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1073 p
->flags
&= ~TERMP_SPLIT
;
1074 p
->flags
|= TERMP_NOSPLIT
;
1078 if (p
->flags
& TERMP_SPLIT
)
1081 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1082 p
->flags
|= TERMP_SPLIT
;
1088 termp_ns_pre(DECL_ARGS
)
1091 if ( ! (NODE_LINE
& n
->flags
))
1092 p
->flags
|= TERMP_NOSPACE
;
1097 termp_rs_pre(DECL_ARGS
)
1100 if (SEC_SEE_ALSO
!= n
->sec
)
1102 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1108 termp_ex_pre(DECL_ARGS
)
1115 termp_nd_pre(DECL_ARGS
)
1118 if (n
->type
== ROFFT_BODY
)
1119 term_word(p
, "\\(en");
1124 termp_bl_pre(DECL_ARGS
)
1127 return n
->type
!= ROFFT_HEAD
;
1131 termp_bl_post(DECL_ARGS
)
1134 if (n
->type
!= ROFFT_BLOCK
)
1137 if (n
->tok
!= MDOC_Bl
|| n
->norm
->Bl
.type
!= LIST_column
)
1139 term_tab_set(p
, NULL
);
1140 term_tab_set(p
, "T");
1141 term_tab_set(p
, ".5i");
1145 termp_xr_pre(DECL_ARGS
)
1148 if (NULL
== (n
= n
->child
))
1151 assert(n
->type
== ROFFT_TEXT
);
1152 term_word(p
, n
->string
);
1154 if (NULL
== (n
= n
->next
))
1157 p
->flags
|= TERMP_NOSPACE
;
1159 p
->flags
|= TERMP_NOSPACE
;
1161 assert(n
->type
== ROFFT_TEXT
);
1162 term_word(p
, n
->string
);
1164 p
->flags
|= TERMP_NOSPACE
;
1171 * This decides how to assert whitespace before any of the SYNOPSIS set
1172 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1176 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1179 * Obviously, if we're not in a SYNOPSIS or no prior macros
1180 * exist, do nothing.
1182 if (NULL
== n
->prev
|| ! (NODE_SYNPRETTY
& n
->flags
))
1186 * If we're the second in a pair of like elements, emit our
1187 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1188 * case we soldier on.
1190 if (n
->prev
->tok
== n
->tok
&&
1191 MDOC_Ft
!= n
->tok
&&
1192 MDOC_Fo
!= n
->tok
&&
1193 MDOC_Fn
!= n
->tok
) {
1199 * If we're one of the SYNOPSIS set and non-like pair-wise after
1200 * another (or Fn/Fo, which we've let slip through) then assert
1201 * vertical space, else only newline and move on.
1203 switch (n
->prev
->tok
) {
1212 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1224 termp_vt_pre(DECL_ARGS
)
1227 if (n
->type
== ROFFT_ELEM
) {
1229 return termp_under_pre(p
, pair
, meta
, n
);
1230 } else if (n
->type
== ROFFT_BLOCK
) {
1233 } else if (n
->type
== ROFFT_HEAD
)
1236 return termp_under_pre(p
, pair
, meta
, n
);
1240 termp_bold_pre(DECL_ARGS
)
1243 termp_tag_pre(p
, pair
, meta
, n
);
1244 term_fontpush(p
, TERMFONT_BOLD
);
1249 termp_fd_pre(DECL_ARGS
)
1253 return termp_bold_pre(p
, pair
, meta
, n
);
1257 termp_fd_post(DECL_ARGS
)
1264 termp_sh_pre(DECL_ARGS
)
1270 * Vertical space before sections, except
1271 * when the previous section was empty.
1273 if (n
->prev
== NULL
||
1274 n
->prev
->tok
!= MDOC_Sh
||
1275 (n
->prev
->body
!= NULL
&&
1276 n
->prev
->body
->child
!= NULL
))
1280 term_fontpush(p
, TERMFONT_BOLD
);
1283 p
->offset
= term_len(p
, p
->defindent
);
1284 term_tab_set(p
, NULL
);
1285 term_tab_set(p
, "T");
1286 term_tab_set(p
, ".5i");
1288 case SEC_DESCRIPTION
:
1292 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1305 termp_sh_post(DECL_ARGS
)
1322 termp_lb_post(DECL_ARGS
)
1325 if (SEC_LIBRARY
== n
->sec
&& NODE_LINE
& n
->flags
)
1330 termp_d1_pre(DECL_ARGS
)
1333 if (n
->type
!= ROFFT_BLOCK
)
1336 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1337 term_tab_set(p
, NULL
);
1338 term_tab_set(p
, "T");
1339 term_tab_set(p
, ".5i");
1344 termp_ft_pre(DECL_ARGS
)
1347 /* NB: NODE_LINE does not effect this! */
1349 term_fontpush(p
, TERMFONT_UNDER
);
1354 termp_fn_pre(DECL_ARGS
)
1359 pretty
= NODE_SYNPRETTY
& n
->flags
;
1363 if (NULL
== (n
= n
->child
))
1367 rmargin
= p
->rmargin
;
1368 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1369 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1372 assert(n
->type
== ROFFT_TEXT
);
1373 term_fontpush(p
, TERMFONT_BOLD
);
1374 term_word(p
, n
->string
);
1377 if (n
->sec
== SEC_DESCRIPTION
|| n
->sec
== SEC_CUSTOM
)
1378 tag_put(n
->string
, ++fn_prio
, p
->line
);
1382 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1383 p
->offset
= p
->rmargin
;
1384 p
->rmargin
= rmargin
;
1387 p
->flags
|= TERMP_NOSPACE
;
1389 p
->flags
|= TERMP_NOSPACE
;
1391 for (n
= n
->next
; n
; n
= n
->next
) {
1392 assert(n
->type
== ROFFT_TEXT
);
1393 term_fontpush(p
, TERMFONT_UNDER
);
1395 p
->flags
|= TERMP_NBRWORD
;
1396 term_word(p
, n
->string
);
1400 p
->flags
|= TERMP_NOSPACE
;
1405 p
->flags
|= TERMP_NOSPACE
;
1409 p
->flags
|= TERMP_NOSPACE
;
1418 termp_fa_pre(DECL_ARGS
)
1420 const struct roff_node
*nn
;
1422 if (n
->parent
->tok
!= MDOC_Fo
) {
1423 term_fontpush(p
, TERMFONT_UNDER
);
1427 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1428 term_fontpush(p
, TERMFONT_UNDER
);
1429 p
->flags
|= TERMP_NBRWORD
;
1430 term_word(p
, nn
->string
);
1433 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1434 p
->flags
|= TERMP_NOSPACE
;
1443 termp_bd_pre(DECL_ARGS
)
1445 size_t lm
, len
, rm
, rmax
;
1446 struct roff_node
*nn
;
1449 if (n
->type
== ROFFT_BLOCK
) {
1450 print_bvspace(p
, n
, n
);
1452 } else if (n
->type
== ROFFT_HEAD
)
1455 /* Handle the -offset argument. */
1457 if (n
->norm
->Bd
.offs
== NULL
||
1458 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1460 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1461 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1462 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1463 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1465 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1466 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
1468 else if (offset
< SHRT_MAX
)
1469 p
->offset
+= offset
;
1473 * If -ragged or -filled are specified, the block does nothing
1474 * but change the indentation. If -unfilled or -literal are
1475 * specified, text is printed exactly as entered in the display:
1476 * for macro lines, a newline is appended to the line. Blank
1477 * lines are allowed.
1480 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1481 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1482 DISP_centered
!= n
->norm
->Bd
.type
)
1485 if (n
->norm
->Bd
.type
== DISP_literal
) {
1486 term_tab_set(p
, NULL
);
1487 term_tab_set(p
, "T");
1488 term_tab_set(p
, "8n");
1493 rmax
= p
->maxrmargin
;
1494 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1496 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1497 if (DISP_centered
== n
->norm
->Bd
.type
) {
1498 if (nn
->type
== ROFFT_TEXT
) {
1499 len
= term_strlen(p
, nn
->string
);
1500 p
->offset
= len
>= rm
? 0 :
1501 lm
+ len
>= rm
? rm
- len
:
1502 (lm
+ rm
- len
) / 2;
1506 print_mdoc_node(p
, pair
, meta
, nn
);
1508 * If the printed node flushes its own line, then we
1509 * needn't do it here as well. This is hacky, but the
1510 * notion of selective eoln whitespace is pretty dumb
1511 * anyway, so don't sweat it.
1513 if (nn
->tok
< ROFF_MAX
)
1526 if (p
->flags
& TERMP_NONEWLINE
||
1527 (nn
->next
&& ! (nn
->next
->flags
& NODE_LINE
)))
1530 p
->flags
|= TERMP_NOSPACE
;
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
);
1603 term_tab_set(p
, NULL
);
1604 term_tab_set(p
, "T");
1605 term_tab_set(p
, ".5i");
1615 termp_ss_post(DECL_ARGS
)
1618 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1623 termp_cd_pre(DECL_ARGS
)
1627 term_fontpush(p
, TERMFONT_BOLD
);
1632 termp_in_pre(DECL_ARGS
)
1637 if (NODE_SYNPRETTY
& n
->flags
&& NODE_LINE
& n
->flags
) {
1638 term_fontpush(p
, TERMFONT_BOLD
);
1639 term_word(p
, "#include");
1643 term_fontpush(p
, TERMFONT_UNDER
);
1646 p
->flags
|= TERMP_NOSPACE
;
1651 termp_in_post(DECL_ARGS
)
1654 if (NODE_SYNPRETTY
& n
->flags
)
1655 term_fontpush(p
, TERMFONT_BOLD
);
1657 p
->flags
|= TERMP_NOSPACE
;
1660 if (NODE_SYNPRETTY
& n
->flags
)
1665 termp_pp_pre(DECL_ARGS
)
1673 termp_skip_pre(DECL_ARGS
)
1680 termp_quote_pre(DECL_ARGS
)
1683 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1689 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1690 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1706 term_word(p
, "\\(Lq");
1709 if (NULL
== n
->norm
->Es
||
1710 NULL
== n
->norm
->Es
->child
)
1712 term_word(p
, n
->norm
->Es
->child
->string
);
1725 term_word(p
, "\\(oq");
1731 p
->flags
|= TERMP_NOSPACE
;
1736 termp_quote_post(DECL_ARGS
)
1739 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1742 p
->flags
|= TERMP_NOSPACE
;
1747 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1748 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1764 term_word(p
, "\\(Rq");
1767 if (n
->norm
->Es
== NULL
||
1768 n
->norm
->Es
->child
== NULL
||
1769 n
->norm
->Es
->child
->next
== NULL
)
1770 p
->flags
&= ~TERMP_NOSPACE
;
1772 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1785 term_word(p
, "\\(cq");
1793 termp_eo_pre(DECL_ARGS
)
1796 if (n
->type
!= ROFFT_BODY
)
1799 if (n
->end
== ENDBODY_NOT
&&
1800 n
->parent
->head
->child
== NULL
&&
1802 n
->child
->end
!= ENDBODY_NOT
)
1803 term_word(p
, "\\&");
1804 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1805 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1806 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1807 p
->flags
|= TERMP_NOSPACE
;
1813 termp_eo_post(DECL_ARGS
)
1817 if (n
->type
!= ROFFT_BODY
)
1820 if (n
->end
!= ENDBODY_NOT
) {
1821 p
->flags
&= ~TERMP_NOSPACE
;
1825 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1826 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1829 p
->flags
|= TERMP_NOSPACE
;
1830 else if ( ! (body
|| tail
))
1831 term_word(p
, "\\&");
1833 p
->flags
&= ~TERMP_NOSPACE
;
1837 termp_fo_pre(DECL_ARGS
)
1842 pretty
= NODE_SYNPRETTY
& n
->flags
;
1844 if (n
->type
== ROFFT_BLOCK
) {
1847 } else if (n
->type
== ROFFT_BODY
) {
1849 rmargin
= p
->rmargin
;
1850 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1851 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1854 p
->flags
|= TERMP_NOSPACE
;
1856 p
->flags
|= TERMP_NOSPACE
;
1859 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1861 p
->offset
= p
->rmargin
;
1862 p
->rmargin
= rmargin
;
1867 if (NULL
== n
->child
)
1870 /* XXX: we drop non-initial arguments as per groff. */
1872 assert(n
->child
->string
);
1873 term_fontpush(p
, TERMFONT_BOLD
);
1874 term_word(p
, n
->child
->string
);
1879 termp_fo_post(DECL_ARGS
)
1882 if (n
->type
!= ROFFT_BODY
)
1885 p
->flags
|= TERMP_NOSPACE
;
1888 if (NODE_SYNPRETTY
& n
->flags
) {
1889 p
->flags
|= TERMP_NOSPACE
;
1896 termp_bf_pre(DECL_ARGS
)
1899 if (n
->type
== ROFFT_HEAD
)
1901 else if (n
->type
!= ROFFT_BODY
)
1904 if (FONT_Em
== n
->norm
->Bf
.font
)
1905 term_fontpush(p
, TERMFONT_UNDER
);
1906 else if (FONT_Sy
== n
->norm
->Bf
.font
)
1907 term_fontpush(p
, TERMFONT_BOLD
);
1909 term_fontpush(p
, TERMFONT_NONE
);
1915 termp_sm_pre(DECL_ARGS
)
1918 if (NULL
== n
->child
)
1919 p
->flags
^= TERMP_NONOSPACE
;
1920 else if (0 == strcmp("on", n
->child
->string
))
1921 p
->flags
&= ~TERMP_NONOSPACE
;
1923 p
->flags
|= TERMP_NONOSPACE
;
1925 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
1926 p
->flags
&= ~TERMP_NOSPACE
;
1932 termp_ap_pre(DECL_ARGS
)
1935 p
->flags
|= TERMP_NOSPACE
;
1937 p
->flags
|= TERMP_NOSPACE
;
1942 termp____post(DECL_ARGS
)
1946 * Handle lists of authors. In general, print each followed by
1947 * a comma. Don't print the comma if there are only two
1950 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
1951 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
1952 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
1957 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
1960 p
->flags
|= TERMP_NOSPACE
;
1961 if (NULL
== n
->next
) {
1963 p
->flags
|= TERMP_SENTENCE
;
1969 termp_li_pre(DECL_ARGS
)
1972 termp_tag_pre(p
, pair
, meta
, n
);
1973 term_fontpush(p
, TERMFONT_NONE
);
1978 termp_lk_pre(DECL_ARGS
)
1980 const struct roff_node
*link
, *descr
, *punct
;
1983 if ((link
= n
->child
) == NULL
)
1986 /* Find beginning of trailing punctuation. */
1988 while (punct
!= link
&& punct
->flags
& NODE_DELIMC
)
1989 punct
= punct
->prev
;
1990 punct
= punct
->next
;
1993 if ((descr
= link
->next
) != NULL
&& descr
!= punct
) {
1994 term_fontpush(p
, TERMFONT_UNDER
);
1995 while (descr
!= punct
) {
1996 if (descr
->flags
& (NODE_DELIMC
| NODE_DELIMO
))
1997 p
->flags
|= TERMP_NOSPACE
;
1998 term_word(p
, descr
->string
);
1999 descr
= descr
->next
;
2002 p
->flags
|= TERMP_NOSPACE
;
2007 display
= term_strlen(p
, link
->string
) >= 26;
2010 p
->offset
+= term_len(p
, p
->defindent
+ 1);
2012 term_fontpush(p
, TERMFONT_BOLD
);
2013 term_word(p
, link
->string
);
2016 /* Trailing punctuation. */
2017 while (punct
!= NULL
) {
2018 p
->flags
|= TERMP_NOSPACE
;
2019 term_word(p
, punct
->string
);
2020 punct
= punct
->next
;
2028 termp_bk_pre(DECL_ARGS
)
2037 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
2038 p
->flags
|= TERMP_PREKEEP
;
2048 termp_bk_post(DECL_ARGS
)
2051 if (n
->type
== ROFFT_BODY
)
2052 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2056 termp__t_post(DECL_ARGS
)
2060 * If we're in an `Rs' and there's a journal present, then quote
2061 * us instead of underlining us (for disambiguation).
2063 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2064 n
->parent
->norm
->Rs
.quote_T
)
2065 termp_quote_post(p
, pair
, meta
, n
);
2067 termp____post(p
, pair
, meta
, n
);
2071 termp__t_pre(DECL_ARGS
)
2075 * If we're in an `Rs' and there's a journal present, then quote
2076 * us instead of underlining us (for disambiguation).
2078 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2079 n
->parent
->norm
->Rs
.quote_T
)
2080 return termp_quote_pre(p
, pair
, meta
, n
);
2082 term_fontpush(p
, TERMFONT_UNDER
);
2087 termp_under_pre(DECL_ARGS
)
2090 term_fontpush(p
, TERMFONT_UNDER
);
2095 termp_em_pre(DECL_ARGS
)
2097 if (n
->child
!= NULL
&&
2098 n
->child
->type
== ROFFT_TEXT
)
2099 tag_put(n
->child
->string
, 0, p
->line
);
2100 term_fontpush(p
, TERMFONT_UNDER
);
2105 termp_sy_pre(DECL_ARGS
)
2107 if (n
->child
!= NULL
&&
2108 n
->child
->type
== ROFFT_TEXT
)
2109 tag_put(n
->child
->string
, 0, p
->line
);
2110 term_fontpush(p
, TERMFONT_BOLD
);
2115 termp_er_pre(DECL_ARGS
)
2118 if (n
->sec
== SEC_ERRORS
&&
2119 (n
->parent
->tok
== MDOC_It
||
2120 (n
->parent
->tok
== MDOC_Bq
&&
2121 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2122 tag_put(n
->child
->string
, 1, p
->line
);
2127 termp_tag_pre(DECL_ARGS
)
2130 if (n
->child
!= NULL
&&
2131 n
->child
->type
== ROFFT_TEXT
&&
2133 (n
->prev
->type
== ROFFT_TEXT
&&
2134 strcmp(n
->prev
->string
, "|") == 0)) &&
2135 (n
->parent
->tok
== MDOC_It
||
2136 (n
->parent
->tok
== MDOC_Xo
&&
2137 n
->parent
->parent
->prev
== NULL
&&
2138 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2139 tag_put(n
->child
->string
, 1, p
->line
);