]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.306 2015/02/01 23:10:35 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2015 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 AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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>
32 #include "mandoc_aux.h"
39 struct termpair
*ppair
;
43 #define DECL_ARGS struct termp *p, \
44 struct termpair *pair, \
45 const struct mdoc_meta *meta, \
49 int (*pre
)(DECL_ARGS
);
50 void (*post
)(DECL_ARGS
);
53 static int a2width(const struct termp
*, const char *);
55 static void print_bvspace(struct termp
*,
56 const struct mdoc_node
*,
57 const struct mdoc_node
*);
58 static void print_mdoc_node(DECL_ARGS
);
59 static void print_mdoc_nodelist(DECL_ARGS
);
60 static void print_mdoc_head(struct termp
*, const void *);
61 static void print_mdoc_foot(struct termp
*, const void *);
62 static void synopsis_pre(struct termp
*,
63 const struct mdoc_node
*);
65 static void termp____post(DECL_ARGS
);
66 static void termp__t_post(DECL_ARGS
);
67 static void termp_bd_post(DECL_ARGS
);
68 static void termp_bk_post(DECL_ARGS
);
69 static void termp_bl_post(DECL_ARGS
);
70 static void termp_eo_post(DECL_ARGS
);
71 static void termp_fd_post(DECL_ARGS
);
72 static void termp_fo_post(DECL_ARGS
);
73 static void termp_in_post(DECL_ARGS
);
74 static void termp_it_post(DECL_ARGS
);
75 static void termp_lb_post(DECL_ARGS
);
76 static void termp_nm_post(DECL_ARGS
);
77 static void termp_pf_post(DECL_ARGS
);
78 static void termp_quote_post(DECL_ARGS
);
79 static void termp_sh_post(DECL_ARGS
);
80 static void termp_ss_post(DECL_ARGS
);
82 static int termp__a_pre(DECL_ARGS
);
83 static int termp__t_pre(DECL_ARGS
);
84 static int termp_an_pre(DECL_ARGS
);
85 static int termp_ap_pre(DECL_ARGS
);
86 static int termp_bd_pre(DECL_ARGS
);
87 static int termp_bf_pre(DECL_ARGS
);
88 static int termp_bk_pre(DECL_ARGS
);
89 static int termp_bl_pre(DECL_ARGS
);
90 static int termp_bold_pre(DECL_ARGS
);
91 static int termp_bt_pre(DECL_ARGS
);
92 static int termp_bx_pre(DECL_ARGS
);
93 static int termp_cd_pre(DECL_ARGS
);
94 static int termp_d1_pre(DECL_ARGS
);
95 static int termp_eo_pre(DECL_ARGS
);
96 static int termp_ex_pre(DECL_ARGS
);
97 static int termp_fa_pre(DECL_ARGS
);
98 static int termp_fd_pre(DECL_ARGS
);
99 static int termp_fl_pre(DECL_ARGS
);
100 static int termp_fn_pre(DECL_ARGS
);
101 static int termp_fo_pre(DECL_ARGS
);
102 static int termp_ft_pre(DECL_ARGS
);
103 static int termp_in_pre(DECL_ARGS
);
104 static int termp_it_pre(DECL_ARGS
);
105 static int termp_li_pre(DECL_ARGS
);
106 static int termp_ll_pre(DECL_ARGS
);
107 static int termp_lk_pre(DECL_ARGS
);
108 static int termp_nd_pre(DECL_ARGS
);
109 static int termp_nm_pre(DECL_ARGS
);
110 static int termp_ns_pre(DECL_ARGS
);
111 static int termp_quote_pre(DECL_ARGS
);
112 static int termp_rs_pre(DECL_ARGS
);
113 static int termp_rv_pre(DECL_ARGS
);
114 static int termp_sh_pre(DECL_ARGS
);
115 static int termp_skip_pre(DECL_ARGS
);
116 static int termp_sm_pre(DECL_ARGS
);
117 static int termp_sp_pre(DECL_ARGS
);
118 static int termp_ss_pre(DECL_ARGS
);
119 static int termp_under_pre(DECL_ARGS
);
120 static int termp_ud_pre(DECL_ARGS
);
121 static int termp_vt_pre(DECL_ARGS
);
122 static int termp_xr_pre(DECL_ARGS
);
123 static int termp_xx_pre(DECL_ARGS
);
125 static const struct termact termacts
[MDOC_MAX
] = {
126 { termp_ap_pre
, NULL
}, /* Ap */
127 { NULL
, NULL
}, /* Dd */
128 { NULL
, NULL
}, /* Dt */
129 { NULL
, NULL
}, /* Os */
130 { termp_sh_pre
, termp_sh_post
}, /* Sh */
131 { termp_ss_pre
, termp_ss_post
}, /* Ss */
132 { termp_sp_pre
, NULL
}, /* Pp */
133 { termp_d1_pre
, termp_bl_post
}, /* D1 */
134 { termp_d1_pre
, termp_bl_post
}, /* Dl */
135 { termp_bd_pre
, termp_bd_post
}, /* Bd */
136 { NULL
, NULL
}, /* Ed */
137 { termp_bl_pre
, termp_bl_post
}, /* Bl */
138 { NULL
, NULL
}, /* El */
139 { termp_it_pre
, termp_it_post
}, /* It */
140 { termp_under_pre
, NULL
}, /* Ad */
141 { termp_an_pre
, NULL
}, /* An */
142 { termp_under_pre
, NULL
}, /* Ar */
143 { termp_cd_pre
, NULL
}, /* Cd */
144 { termp_bold_pre
, NULL
}, /* Cm */
145 { NULL
, NULL
}, /* Dv */
146 { NULL
, NULL
}, /* Er */
147 { NULL
, NULL
}, /* Ev */
148 { termp_ex_pre
, NULL
}, /* Ex */
149 { termp_fa_pre
, NULL
}, /* Fa */
150 { termp_fd_pre
, termp_fd_post
}, /* Fd */
151 { termp_fl_pre
, NULL
}, /* Fl */
152 { termp_fn_pre
, NULL
}, /* Fn */
153 { termp_ft_pre
, NULL
}, /* Ft */
154 { termp_bold_pre
, NULL
}, /* Ic */
155 { termp_in_pre
, termp_in_post
}, /* In */
156 { termp_li_pre
, NULL
}, /* Li */
157 { termp_nd_pre
, NULL
}, /* Nd */
158 { termp_nm_pre
, termp_nm_post
}, /* Nm */
159 { termp_quote_pre
, termp_quote_post
}, /* Op */
160 { termp_ft_pre
, NULL
}, /* Ot */
161 { termp_under_pre
, NULL
}, /* Pa */
162 { termp_rv_pre
, NULL
}, /* Rv */
163 { NULL
, NULL
}, /* St */
164 { termp_under_pre
, NULL
}, /* Va */
165 { termp_vt_pre
, NULL
}, /* Vt */
166 { termp_xr_pre
, NULL
}, /* Xr */
167 { termp__a_pre
, termp____post
}, /* %A */
168 { termp_under_pre
, termp____post
}, /* %B */
169 { NULL
, termp____post
}, /* %D */
170 { termp_under_pre
, termp____post
}, /* %I */
171 { termp_under_pre
, termp____post
}, /* %J */
172 { NULL
, termp____post
}, /* %N */
173 { NULL
, termp____post
}, /* %O */
174 { NULL
, termp____post
}, /* %P */
175 { NULL
, termp____post
}, /* %R */
176 { termp__t_pre
, termp__t_post
}, /* %T */
177 { NULL
, termp____post
}, /* %V */
178 { NULL
, NULL
}, /* Ac */
179 { termp_quote_pre
, termp_quote_post
}, /* Ao */
180 { termp_quote_pre
, termp_quote_post
}, /* Aq */
181 { NULL
, NULL
}, /* At */
182 { NULL
, NULL
}, /* Bc */
183 { termp_bf_pre
, NULL
}, /* Bf */
184 { termp_quote_pre
, termp_quote_post
}, /* Bo */
185 { termp_quote_pre
, termp_quote_post
}, /* Bq */
186 { termp_xx_pre
, NULL
}, /* Bsx */
187 { termp_bx_pre
, NULL
}, /* Bx */
188 { termp_skip_pre
, NULL
}, /* Db */
189 { NULL
, NULL
}, /* Dc */
190 { termp_quote_pre
, termp_quote_post
}, /* Do */
191 { termp_quote_pre
, termp_quote_post
}, /* Dq */
192 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
193 { NULL
, NULL
}, /* Ef */
194 { termp_under_pre
, NULL
}, /* Em */
195 { termp_eo_pre
, termp_eo_post
}, /* Eo */
196 { termp_xx_pre
, NULL
}, /* Fx */
197 { termp_bold_pre
, NULL
}, /* Ms */
198 { termp_li_pre
, NULL
}, /* No */
199 { termp_ns_pre
, NULL
}, /* Ns */
200 { termp_xx_pre
, NULL
}, /* Nx */
201 { termp_xx_pre
, NULL
}, /* Ox */
202 { NULL
, NULL
}, /* Pc */
203 { NULL
, termp_pf_post
}, /* Pf */
204 { termp_quote_pre
, termp_quote_post
}, /* Po */
205 { termp_quote_pre
, termp_quote_post
}, /* Pq */
206 { NULL
, NULL
}, /* Qc */
207 { termp_quote_pre
, termp_quote_post
}, /* Ql */
208 { termp_quote_pre
, termp_quote_post
}, /* Qo */
209 { termp_quote_pre
, termp_quote_post
}, /* Qq */
210 { NULL
, NULL
}, /* Re */
211 { termp_rs_pre
, NULL
}, /* Rs */
212 { NULL
, NULL
}, /* Sc */
213 { termp_quote_pre
, termp_quote_post
}, /* So */
214 { termp_quote_pre
, termp_quote_post
}, /* Sq */
215 { termp_sm_pre
, NULL
}, /* Sm */
216 { termp_under_pre
, NULL
}, /* Sx */
217 { termp_bold_pre
, NULL
}, /* Sy */
218 { NULL
, NULL
}, /* Tn */
219 { termp_xx_pre
, NULL
}, /* Ux */
220 { NULL
, NULL
}, /* Xc */
221 { NULL
, NULL
}, /* Xo */
222 { termp_fo_pre
, termp_fo_post
}, /* Fo */
223 { NULL
, NULL
}, /* Fc */
224 { termp_quote_pre
, termp_quote_post
}, /* Oo */
225 { NULL
, NULL
}, /* Oc */
226 { termp_bk_pre
, termp_bk_post
}, /* Bk */
227 { NULL
, NULL
}, /* Ek */
228 { termp_bt_pre
, NULL
}, /* Bt */
229 { NULL
, NULL
}, /* Hf */
230 { termp_under_pre
, NULL
}, /* Fr */
231 { termp_ud_pre
, NULL
}, /* Ud */
232 { NULL
, termp_lb_post
}, /* Lb */
233 { termp_sp_pre
, NULL
}, /* Lp */
234 { termp_lk_pre
, NULL
}, /* Lk */
235 { termp_under_pre
, NULL
}, /* Mt */
236 { termp_quote_pre
, termp_quote_post
}, /* Brq */
237 { termp_quote_pre
, termp_quote_post
}, /* Bro */
238 { NULL
, NULL
}, /* Brc */
239 { NULL
, termp____post
}, /* %C */
240 { termp_skip_pre
, NULL
}, /* Es */
241 { termp_quote_pre
, termp_quote_post
}, /* En */
242 { termp_xx_pre
, NULL
}, /* Dx */
243 { NULL
, termp____post
}, /* %Q */
244 { termp_sp_pre
, NULL
}, /* br */
245 { termp_sp_pre
, NULL
}, /* sp */
246 { NULL
, termp____post
}, /* %U */
247 { NULL
, NULL
}, /* Ta */
248 { termp_ll_pre
, NULL
}, /* ll */
253 terminal_mdoc(void *arg
, const struct mdoc
*mdoc
)
255 const struct mdoc_meta
*meta
;
259 p
= (struct termp
*)arg
;
262 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
263 p
->tabwidth
= term_len(p
, 5);
265 n
= mdoc_node(mdoc
)->child
;
266 meta
= mdoc_meta(mdoc
);
268 if (p
->synopsisonly
) {
270 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
271 if (n
->child
->next
->child
!= NULL
)
272 print_mdoc_nodelist(p
, NULL
,
273 meta
, n
->child
->next
->child
);
280 if (p
->defindent
== 0)
282 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, meta
);
284 if (n
->tok
!= MDOC_Sh
)
286 print_mdoc_nodelist(p
, NULL
, meta
, n
);
293 print_mdoc_nodelist(DECL_ARGS
)
297 print_mdoc_node(p
, pair
, meta
, n
);
303 print_mdoc_node(DECL_ARGS
)
306 struct termpair npair
;
307 size_t offset
, rmargin
;
311 rmargin
= p
->rmargin
;
312 n
->prev_font
= p
->fonti
;
314 memset(&npair
, 0, sizeof(struct termpair
));
318 * Keeps only work until the end of a line. If a keep was
319 * invoked in a prior line, revert it to PREKEEP.
322 if (TERMP_KEEP
& p
->flags
) {
323 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
324 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
325 p
->flags
&= ~TERMP_KEEP
;
326 p
->flags
|= TERMP_PREKEEP
;
331 * After the keep flags have been set up, we may now
332 * produce output. Note that some pre-handlers do so.
337 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
339 if (MDOC_DELIMC
& n
->flags
)
340 p
->flags
|= TERMP_NOSPACE
;
341 term_word(p
, n
->string
);
342 if (MDOC_DELIMO
& n
->flags
)
343 p
->flags
|= TERMP_NOSPACE
;
346 if ( ! (n
->flags
& MDOC_LINE
))
347 p
->flags
|= TERMP_NOSPACE
;
349 if (n
->next
!= NULL
&& ! (n
->next
->flags
& MDOC_LINE
))
350 p
->flags
|= TERMP_NOSPACE
;
353 term_tbl(p
, n
->span
);
356 if (termacts
[n
->tok
].pre
&&
357 (n
->end
== ENDBODY_NOT
|| n
->nchild
))
358 chld
= (*termacts
[n
->tok
].pre
)
359 (p
, &npair
, meta
, n
);
363 if (chld
&& n
->child
)
364 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
367 (ENDBODY_NOT
== n
->end
? n
: n
->pending
)->prev_font
);
377 if ( ! termacts
[n
->tok
].post
|| MDOC_ENDED
& n
->flags
)
379 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
382 * Explicit end tokens not only call the post
383 * handler, but also tell the respective block
384 * that it must not call the post handler again.
386 if (ENDBODY_NOT
!= n
->end
)
387 n
->pending
->flags
|= MDOC_ENDED
;
390 * End of line terminating an implicit block
391 * while an explicit block is still open.
392 * Continue the explicit block without spacing.
394 if (ENDBODY_NOSPACE
== n
->end
)
395 p
->flags
|= TERMP_NOSPACE
;
399 if (MDOC_EOS
& n
->flags
)
400 p
->flags
|= TERMP_SENTENCE
;
402 if (MDOC_ll
!= n
->tok
) {
404 p
->rmargin
= rmargin
;
409 print_mdoc_foot(struct termp
*p
, const void *arg
)
411 const struct mdoc_meta
*meta
;
414 meta
= (const struct mdoc_meta
*)arg
;
416 term_fontrepl(p
, TERMFONT_NONE
);
419 * Output the footer in new-groff style, that is, three columns
420 * with the middle being the manual date and flanking columns
421 * being the operating system:
429 sz
= term_strlen(p
, meta
->date
);
430 p
->rmargin
= p
->maxrmargin
> sz
?
431 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
433 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
435 term_word(p
, meta
->os
);
438 p
->offset
= p
->rmargin
;
439 sz
= term_strlen(p
, meta
->os
);
440 p
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
441 p
->flags
|= TERMP_NOSPACE
;
443 term_word(p
, meta
->date
);
446 p
->offset
= p
->rmargin
;
447 p
->rmargin
= p
->maxrmargin
;
449 p
->flags
&= ~TERMP_NOBREAK
;
450 p
->flags
|= TERMP_NOSPACE
;
452 term_word(p
, meta
->os
);
456 p
->rmargin
= p
->maxrmargin
;
461 print_mdoc_head(struct termp
*p
, const void *arg
)
463 const struct mdoc_meta
*meta
;
464 char *volume
, *title
;
465 size_t vollen
, titlen
;
467 meta
= (const struct mdoc_meta
*)arg
;
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
));
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 mdoc_node
*bl
,
552 const struct mdoc_node
*n
)
554 const struct mdoc_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
) {
571 if (nn
->type
== MDOC_ROOT
)
573 } while (nn
->type
!= MDOC_BLOCK
);
574 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
576 if (nn
->tok
== MDOC_It
&&
577 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
581 /* A `-column' does not assert vspace within the list. */
583 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
584 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
587 /* A `-diag' without body does not vspace. */
589 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
590 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
591 assert(n
->prev
->body
);
592 if (NULL
== n
->prev
->body
->child
)
601 termp_ll_pre(DECL_ARGS
)
604 term_setwidth(p
, n
->nchild
? n
->child
->string
: NULL
);
609 termp_it_pre(DECL_ARGS
)
612 const struct mdoc_node
*bl
, *nn
;
614 int i
, offset
, width
;
617 if (MDOC_BLOCK
== n
->type
) {
618 print_bvspace(p
, n
->parent
->parent
, n
);
622 bl
= n
->parent
->parent
->parent
;
623 type
= bl
->norm
->Bl
.type
;
626 * Defaults for specific list types.
637 width
= term_len(p
, 2);
640 width
= term_len(p
, 8);
645 width
= term_len(p
, 10);
654 * First calculate width and offset. This is pretty easy unless
655 * we're a -column list, in which case all prior columns must
659 if (bl
->norm
->Bl
.offs
!= NULL
) {
660 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
661 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
663 else if (offset
> SHRT_MAX
)
669 if (MDOC_HEAD
== n
->type
)
673 * Imitate groff's column handling:
674 * - For each earlier column, add its width.
675 * - For less than 5 columns, add four more blanks per
677 * - For exactly 5 columns, add three more blank per
679 * - For more than 5 columns, add only one column.
681 ncols
= bl
->norm
->Bl
.ncols
;
682 dcol
= ncols
< 5 ? term_len(p
, 4) :
683 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
686 * Calculate the offset by applying all prior MDOC_BODY,
687 * so we stop at the MDOC_HEAD (NULL == nn->prev).
690 for (i
= 0, nn
= n
->prev
;
691 nn
->prev
&& i
< (int)ncols
;
693 offset
+= dcol
+ a2width(p
,
694 bl
->norm
->Bl
.cols
[i
]);
697 * When exceeding the declared number of columns, leave
698 * the remaining widths at 0. This will later be
699 * adjusted to the default width of 10, or, for the last
700 * column, stretched to the right margin.
706 * Use the declared column widths, extended as explained
707 * in the preceding paragraph.
709 width
= a2width(p
, bl
->norm
->Bl
.cols
[i
]) + dcol
;
712 if (NULL
== bl
->norm
->Bl
.width
)
716 * Note: buffer the width by 2, which is groff's magic
717 * number for buffering single arguments. See the above
718 * handling for column for how this changes.
720 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
721 if (width
< 0 && (size_t)(-width
) > p
->offset
)
723 else if (width
> SHRT_MAX
)
729 * Whitespace control. Inset bodies need an initial space,
730 * while diagonal bodies need two.
733 p
->flags
|= TERMP_NOSPACE
;
737 if (MDOC_BODY
== n
->type
)
738 term_word(p
, "\\ \\ ");
741 if (MDOC_BODY
== n
->type
&& n
->parent
->head
->nchild
)
748 p
->flags
|= TERMP_NOSPACE
;
752 if (MDOC_HEAD
== n
->type
)
753 term_fontpush(p
, TERMFONT_BOLD
);
760 * Pad and break control. This is the tricky part. These flags
761 * are documented in term_flushln() in term.c. Note that we're
762 * going to unset all of these flags in termp_it_post() when we
769 * Weird special case.
770 * Some very narrow lists actually hang.
778 if (width
<= (int)term_len(p
, 2))
779 p
->flags
|= TERMP_HANG
;
780 if (MDOC_HEAD
!= n
->type
)
782 p
->flags
|= TERMP_NOBREAK
;
786 if (MDOC_HEAD
!= n
->type
)
790 * This is ugly. If `-hang' is specified and the body
791 * is a `Bl' or `Bd', then we want basically to nullify
792 * the "overstep" effect in term_flushln() and treat
793 * this as a `-ohang' list instead.
795 if (NULL
!= n
->next
&&
796 NULL
!= n
->next
->child
&&
797 (MDOC_Bl
== n
->next
->child
->tok
||
798 MDOC_Bd
== n
->next
->child
->tok
))
801 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
805 if (MDOC_HEAD
!= n
->type
)
808 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
811 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
812 p
->flags
|= TERMP_DANGLE
;
815 if (MDOC_HEAD
== n
->type
)
818 if (NULL
== n
->next
) {
819 p
->flags
&= ~TERMP_NOBREAK
;
822 p
->flags
|= TERMP_NOBREAK
;
828 if (MDOC_HEAD
!= n
->type
)
830 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
838 * Margin control. Set-head-width lists have their right
839 * margins shortened. The body for these lists has the offset
840 * necessarily lengthened. Everybody gets the offset.
848 * Same stipulation as above, regarding `-hang'. We
849 * don't want to recalculate rmargin and offsets when
850 * using `Bd' or `Bl' within `-hang' overstep lists.
852 if (MDOC_HEAD
== n
->type
&&
854 NULL
!= n
->next
->child
&&
855 (MDOC_Bl
== n
->next
->child
->tok
||
856 MDOC_Bd
== n
->next
->child
->tok
))
868 if (MDOC_HEAD
== n
->type
)
869 p
->rmargin
= p
->offset
+ width
;
875 p
->rmargin
= p
->offset
+ width
;
877 * XXX - this behaviour is not documented: the
878 * right-most column is filled to the right margin.
880 if (MDOC_HEAD
== n
->type
)
882 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
883 p
->rmargin
= p
->maxrmargin
;
890 * The dash, hyphen, bullet and enum lists all have a special
891 * HEAD character (temporarily bold, in some cases).
894 if (MDOC_HEAD
== n
->type
)
897 term_fontpush(p
, TERMFONT_BOLD
);
898 term_word(p
, "\\[bu]");
904 term_fontpush(p
, TERMFONT_BOLD
);
905 term_word(p
, "\\(hy");
909 (pair
->ppair
->ppair
->count
)++;
910 (void)snprintf(buf
, sizeof(buf
), "%d.",
911 pair
->ppair
->ppair
->count
);
919 * If we're not going to process our children, indicate so here.
932 if (MDOC_HEAD
== n
->type
)
936 if (MDOC_HEAD
== n
->type
)
947 termp_it_post(DECL_ARGS
)
951 if (MDOC_BLOCK
== n
->type
)
954 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
962 if (MDOC_BODY
== n
->type
)
966 if (MDOC_BODY
== n
->type
)
975 * Now that our output is flushed, we can reset our tags. Since
976 * only `It' sets these flags, we're free to assume that nobody
977 * has munged them in the meanwhile.
980 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
981 TERMP_DANGLE
| TERMP_HANG
);
986 termp_nm_pre(DECL_ARGS
)
990 if (MDOC_BLOCK
== n
->type
) {
991 p
->flags
|= TERMP_PREKEEP
;
995 if (MDOC_BODY
== n
->type
) {
996 if (NULL
== n
->child
)
998 p
->flags
|= TERMP_NOSPACE
;
1000 if (n
->prev
->child
!= NULL
)
1001 cp
= n
->prev
->child
->string
;
1005 p
->offset
+= term_len(p
, 6);
1007 p
->offset
+= term_len(p
, 1) + term_strlen(p
, cp
);
1011 if (NULL
== n
->child
&& NULL
== meta
->name
)
1014 if (MDOC_HEAD
== n
->type
)
1015 synopsis_pre(p
, n
->parent
);
1017 if (MDOC_HEAD
== n
->type
&&
1018 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1019 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1021 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1022 if (NULL
== n
->child
) {
1023 p
->rmargin
+= term_strlen(p
, meta
->name
);
1024 } else if (MDOC_TEXT
== n
->child
->type
) {
1025 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1027 p
->flags
|= TERMP_HANG
;
1029 p
->rmargin
+= term_len(p
, 5);
1030 p
->flags
|= TERMP_HANG
;
1034 term_fontpush(p
, TERMFONT_BOLD
);
1035 if (NULL
== n
->child
)
1036 term_word(p
, meta
->name
);
1041 termp_nm_post(DECL_ARGS
)
1044 if (MDOC_BLOCK
== n
->type
) {
1045 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1046 } else if (MDOC_HEAD
== n
->type
&&
1047 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1049 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1051 } else if (MDOC_BODY
== n
->type
&& n
->child
)
1056 termp_fl_pre(DECL_ARGS
)
1059 term_fontpush(p
, TERMFONT_BOLD
);
1060 term_word(p
, "\\-");
1062 if ( ! (n
->nchild
== 0 &&
1064 n
->next
->type
== MDOC_TEXT
||
1065 n
->next
->flags
& MDOC_LINE
)))
1066 p
->flags
|= TERMP_NOSPACE
;
1072 termp__a_pre(DECL_ARGS
)
1075 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1076 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1077 term_word(p
, "and");
1083 termp_an_pre(DECL_ARGS
)
1086 if (n
->norm
->An
.auth
== AUTH_split
) {
1087 p
->flags
&= ~TERMP_NOSPLIT
;
1088 p
->flags
|= TERMP_SPLIT
;
1091 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1092 p
->flags
&= ~TERMP_SPLIT
;
1093 p
->flags
|= TERMP_NOSPLIT
;
1097 if (n
->child
== NULL
)
1100 if (p
->flags
& TERMP_SPLIT
)
1103 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1104 p
->flags
|= TERMP_SPLIT
;
1110 termp_ns_pre(DECL_ARGS
)
1113 if ( ! (MDOC_LINE
& n
->flags
))
1114 p
->flags
|= TERMP_NOSPACE
;
1119 termp_rs_pre(DECL_ARGS
)
1122 if (SEC_SEE_ALSO
!= n
->sec
)
1124 if (MDOC_BLOCK
== n
->type
&& n
->prev
)
1130 termp_rv_pre(DECL_ARGS
)
1138 term_word(p
, "The");
1140 for (n
= n
->child
; n
; n
= n
->next
) {
1141 term_fontpush(p
, TERMFONT_BOLD
);
1142 term_word(p
, n
->string
);
1145 p
->flags
|= TERMP_NOSPACE
;
1148 if (n
->next
== NULL
)
1152 p
->flags
|= TERMP_NOSPACE
;
1155 if (n
->next
->next
== NULL
)
1156 term_word(p
, "and");
1160 term_word(p
, "functions return");
1162 term_word(p
, "function returns");
1164 term_word(p
, "the value\\~0 if successful;");
1166 term_word(p
, "Upon successful completion,"
1167 " the value\\~0 is returned;");
1169 term_word(p
, "otherwise the value\\~\\-1 is returned"
1170 " and the global variable");
1172 term_fontpush(p
, TERMFONT_UNDER
);
1173 term_word(p
, "errno");
1176 term_word(p
, "is set to indicate the error.");
1177 p
->flags
|= TERMP_SENTENCE
;
1183 termp_ex_pre(DECL_ARGS
)
1188 term_word(p
, "The");
1191 for (n
= n
->child
; n
; n
= n
->next
) {
1192 term_fontpush(p
, TERMFONT_BOLD
);
1193 term_word(p
, n
->string
);
1196 if (nchild
> 2 && n
->next
) {
1197 p
->flags
|= TERMP_NOSPACE
;
1201 if (n
->next
&& NULL
== n
->next
->next
)
1202 term_word(p
, "and");
1206 term_word(p
, "utilities exit\\~0");
1208 term_word(p
, "utility exits\\~0");
1210 term_word(p
, "on success, and\\~>0 if an error occurs.");
1212 p
->flags
|= TERMP_SENTENCE
;
1217 termp_nd_pre(DECL_ARGS
)
1220 if (n
->type
== MDOC_BODY
)
1221 term_word(p
, "\\(en");
1226 termp_bl_pre(DECL_ARGS
)
1229 return(MDOC_HEAD
!= n
->type
);
1233 termp_bl_post(DECL_ARGS
)
1236 if (MDOC_BLOCK
== n
->type
)
1241 termp_xr_pre(DECL_ARGS
)
1244 if (NULL
== (n
= n
->child
))
1247 assert(MDOC_TEXT
== n
->type
);
1248 term_word(p
, n
->string
);
1250 if (NULL
== (n
= n
->next
))
1253 p
->flags
|= TERMP_NOSPACE
;
1255 p
->flags
|= TERMP_NOSPACE
;
1257 assert(MDOC_TEXT
== n
->type
);
1258 term_word(p
, n
->string
);
1260 p
->flags
|= TERMP_NOSPACE
;
1267 * This decides how to assert whitespace before any of the SYNOPSIS set
1268 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1272 synopsis_pre(struct termp
*p
, const struct mdoc_node
*n
)
1275 * Obviously, if we're not in a SYNOPSIS or no prior macros
1276 * exist, do nothing.
1278 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1282 * If we're the second in a pair of like elements, emit our
1283 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1284 * case we soldier on.
1286 if (n
->prev
->tok
== n
->tok
&&
1287 MDOC_Ft
!= n
->tok
&&
1288 MDOC_Fo
!= n
->tok
&&
1289 MDOC_Fn
!= n
->tok
) {
1295 * If we're one of the SYNOPSIS set and non-like pair-wise after
1296 * another (or Fn/Fo, which we've let slip through) then assert
1297 * vertical space, else only newline and move on.
1299 switch (n
->prev
->tok
) {
1312 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1324 termp_vt_pre(DECL_ARGS
)
1327 if (MDOC_ELEM
== n
->type
) {
1329 return(termp_under_pre(p
, pair
, meta
, n
));
1330 } else if (MDOC_BLOCK
== n
->type
) {
1333 } else if (MDOC_HEAD
== n
->type
)
1336 return(termp_under_pre(p
, pair
, meta
, n
));
1340 termp_bold_pre(DECL_ARGS
)
1343 term_fontpush(p
, TERMFONT_BOLD
);
1348 termp_fd_pre(DECL_ARGS
)
1352 return(termp_bold_pre(p
, pair
, meta
, n
));
1356 termp_fd_post(DECL_ARGS
)
1363 termp_sh_pre(DECL_ARGS
)
1369 * Vertical space before sections, except
1370 * when the previous section was empty.
1372 if (n
->prev
== NULL
||
1373 MDOC_Sh
!= n
->prev
->tok
||
1374 (n
->prev
->body
!= NULL
&&
1375 n
->prev
->body
->child
!= NULL
))
1379 term_fontpush(p
, TERMFONT_BOLD
);
1382 p
->offset
= term_len(p
, p
->defindent
);
1383 if (SEC_AUTHORS
== n
->sec
)
1384 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1393 termp_sh_post(DECL_ARGS
)
1410 termp_bt_pre(DECL_ARGS
)
1413 term_word(p
, "is currently in beta test.");
1414 p
->flags
|= TERMP_SENTENCE
;
1419 termp_lb_post(DECL_ARGS
)
1422 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1427 termp_ud_pre(DECL_ARGS
)
1430 term_word(p
, "currently under development.");
1431 p
->flags
|= TERMP_SENTENCE
;
1436 termp_d1_pre(DECL_ARGS
)
1439 if (MDOC_BLOCK
!= n
->type
)
1442 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1447 termp_ft_pre(DECL_ARGS
)
1450 /* NB: MDOC_LINE does not effect this! */
1452 term_fontpush(p
, TERMFONT_UNDER
);
1457 termp_fn_pre(DECL_ARGS
)
1462 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1466 if (NULL
== (n
= n
->child
))
1470 rmargin
= p
->rmargin
;
1471 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1472 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1475 assert(MDOC_TEXT
== n
->type
);
1476 term_fontpush(p
, TERMFONT_BOLD
);
1477 term_word(p
, n
->string
);
1482 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1483 p
->offset
= p
->rmargin
;
1484 p
->rmargin
= rmargin
;
1487 p
->flags
|= TERMP_NOSPACE
;
1489 p
->flags
|= TERMP_NOSPACE
;
1491 for (n
= n
->next
; n
; n
= n
->next
) {
1492 assert(MDOC_TEXT
== n
->type
);
1493 term_fontpush(p
, TERMFONT_UNDER
);
1495 p
->flags
|= TERMP_NBRWORD
;
1496 term_word(p
, n
->string
);
1500 p
->flags
|= TERMP_NOSPACE
;
1505 p
->flags
|= TERMP_NOSPACE
;
1509 p
->flags
|= TERMP_NOSPACE
;
1518 termp_fa_pre(DECL_ARGS
)
1520 const struct mdoc_node
*nn
;
1522 if (n
->parent
->tok
!= MDOC_Fo
) {
1523 term_fontpush(p
, TERMFONT_UNDER
);
1527 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1528 term_fontpush(p
, TERMFONT_UNDER
);
1529 p
->flags
|= TERMP_NBRWORD
;
1530 term_word(p
, nn
->string
);
1533 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1534 p
->flags
|= TERMP_NOSPACE
;
1543 termp_bd_pre(DECL_ARGS
)
1545 size_t tabwidth
, lm
, len
, rm
, rmax
;
1546 struct mdoc_node
*nn
;
1549 if (MDOC_BLOCK
== n
->type
) {
1550 print_bvspace(p
, n
, n
);
1552 } else if (MDOC_HEAD
== n
->type
)
1555 /* Handle the -offset argument. */
1557 if (n
->norm
->Bd
.offs
== NULL
||
1558 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1560 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1561 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1562 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1563 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1565 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1566 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
1568 else if (offset
< SHRT_MAX
)
1569 p
->offset
+= offset
;
1573 * If -ragged or -filled are specified, the block does nothing
1574 * but change the indentation. If -unfilled or -literal are
1575 * specified, text is printed exactly as entered in the display:
1576 * for macro lines, a newline is appended to the line. Blank
1577 * lines are allowed.
1580 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1581 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1582 DISP_centered
!= n
->norm
->Bd
.type
)
1585 tabwidth
= p
->tabwidth
;
1586 if (DISP_literal
== n
->norm
->Bd
.type
)
1587 p
->tabwidth
= term_len(p
, 8);
1591 rmax
= p
->maxrmargin
;
1592 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1594 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1595 if (DISP_centered
== n
->norm
->Bd
.type
) {
1596 if (MDOC_TEXT
== nn
->type
) {
1597 len
= term_strlen(p
, nn
->string
);
1598 p
->offset
= len
>= rm
? 0 :
1599 lm
+ len
>= rm
? rm
- len
:
1600 (lm
+ rm
- len
) / 2;
1604 print_mdoc_node(p
, pair
, meta
, nn
);
1606 * If the printed node flushes its own line, then we
1607 * needn't do it here as well. This is hacky, but the
1608 * notion of selective eoln whitespace is pretty dumb
1609 * anyway, so don't sweat it.
1631 if (p
->flags
& TERMP_NONEWLINE
||
1632 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1635 p
->flags
|= TERMP_NOSPACE
;
1638 p
->tabwidth
= tabwidth
;
1640 p
->maxrmargin
= rmax
;
1645 termp_bd_post(DECL_ARGS
)
1649 if (MDOC_BODY
!= n
->type
)
1653 rmax
= p
->maxrmargin
;
1655 if (DISP_literal
== n
->norm
->Bd
.type
||
1656 DISP_unfilled
== n
->norm
->Bd
.type
)
1657 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1659 p
->flags
|= TERMP_NOSPACE
;
1663 p
->maxrmargin
= rmax
;
1667 termp_bx_pre(DECL_ARGS
)
1670 if (NULL
!= (n
= n
->child
)) {
1671 term_word(p
, n
->string
);
1672 p
->flags
|= TERMP_NOSPACE
;
1673 term_word(p
, "BSD");
1675 term_word(p
, "BSD");
1679 if (NULL
!= (n
= n
->next
)) {
1680 p
->flags
|= TERMP_NOSPACE
;
1682 p
->flags
|= TERMP_NOSPACE
;
1683 term_word(p
, n
->string
);
1690 termp_xx_pre(DECL_ARGS
)
1723 p
->flags
|= TERMP_KEEP
;
1724 term_word(p
, n
->child
->string
);
1731 termp_pf_post(DECL_ARGS
)
1734 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1735 p
->flags
|= TERMP_NOSPACE
;
1739 termp_ss_pre(DECL_ARGS
)
1749 term_fontpush(p
, TERMFONT_BOLD
);
1750 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1753 p
->offset
= term_len(p
, p
->defindent
);
1763 termp_ss_post(DECL_ARGS
)
1766 if (n
->type
== MDOC_HEAD
|| n
->type
== MDOC_BODY
)
1771 termp_cd_pre(DECL_ARGS
)
1775 term_fontpush(p
, TERMFONT_BOLD
);
1780 termp_in_pre(DECL_ARGS
)
1785 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1786 term_fontpush(p
, TERMFONT_BOLD
);
1787 term_word(p
, "#include");
1791 term_fontpush(p
, TERMFONT_UNDER
);
1794 p
->flags
|= TERMP_NOSPACE
;
1799 termp_in_post(DECL_ARGS
)
1802 if (MDOC_SYNPRETTY
& n
->flags
)
1803 term_fontpush(p
, TERMFONT_BOLD
);
1805 p
->flags
|= TERMP_NOSPACE
;
1808 if (MDOC_SYNPRETTY
& n
->flags
)
1813 termp_sp_pre(DECL_ARGS
)
1821 if ( ! a2roffsu(n
->child
->string
, &su
, SCALE_VS
))
1823 len
= term_vspan(p
, &su
);
1837 for (i
= 0; i
< len
; i
++)
1844 termp_skip_pre(DECL_ARGS
)
1851 termp_quote_pre(DECL_ARGS
)
1854 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1861 term_word(p
, n
->nchild
== 1 &&
1862 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1881 term_word(p
, "\\(lq");
1884 if (NULL
== n
->norm
->Es
||
1885 NULL
== n
->norm
->Es
->child
)
1887 term_word(p
, n
->norm
->Es
->child
->string
);
1906 term_word(p
, "\\(oq");
1913 p
->flags
|= TERMP_NOSPACE
;
1918 termp_quote_post(DECL_ARGS
)
1921 if (n
->type
!= MDOC_BODY
&& n
->type
!= MDOC_ELEM
)
1924 p
->flags
|= TERMP_NOSPACE
;
1930 term_word(p
, n
->nchild
== 1 &&
1931 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1950 term_word(p
, "\\(rq");
1953 if (n
->norm
->Es
== NULL
||
1954 n
->norm
->Es
->child
== NULL
||
1955 n
->norm
->Es
->child
->next
== NULL
)
1956 p
->flags
&= ~TERMP_NOSPACE
;
1958 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1977 term_word(p
, "\\(cq");
1986 termp_eo_pre(DECL_ARGS
)
1989 if (n
->type
!= MDOC_BODY
)
1992 if (n
->end
== ENDBODY_NOT
&&
1993 n
->parent
->head
->child
== NULL
&&
1995 n
->child
->end
!= ENDBODY_NOT
)
1996 term_word(p
, "\\&");
1997 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1998 n
->parent
->head
->child
!= NULL
&&
1999 (n
->parent
->body
->child
!= NULL
||
2000 n
->parent
->tail
->child
!= NULL
))
2001 p
->flags
|= TERMP_NOSPACE
;
2007 termp_eo_post(DECL_ARGS
)
2011 if (n
->type
!= MDOC_BODY
)
2014 if (n
->end
!= ENDBODY_NOT
) {
2015 p
->flags
&= ~TERMP_NOSPACE
;
2019 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2020 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2023 p
->flags
|= TERMP_NOSPACE
;
2024 else if ( ! (body
|| tail
))
2025 term_word(p
, "\\&");
2027 p
->flags
&= ~TERMP_NOSPACE
;
2031 termp_fo_pre(DECL_ARGS
)
2036 pretty
= MDOC_SYNPRETTY
& n
->flags
;
2038 if (MDOC_BLOCK
== n
->type
) {
2041 } else if (MDOC_BODY
== n
->type
) {
2043 rmargin
= p
->rmargin
;
2044 p
->rmargin
= p
->offset
+ term_len(p
, 4);
2045 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
2048 p
->flags
|= TERMP_NOSPACE
;
2050 p
->flags
|= TERMP_NOSPACE
;
2053 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2055 p
->offset
= p
->rmargin
;
2056 p
->rmargin
= rmargin
;
2061 if (NULL
== n
->child
)
2064 /* XXX: we drop non-initial arguments as per groff. */
2066 assert(n
->child
->string
);
2067 term_fontpush(p
, TERMFONT_BOLD
);
2068 term_word(p
, n
->child
->string
);
2073 termp_fo_post(DECL_ARGS
)
2076 if (MDOC_BODY
!= n
->type
)
2079 p
->flags
|= TERMP_NOSPACE
;
2082 if (MDOC_SYNPRETTY
& n
->flags
) {
2083 p
->flags
|= TERMP_NOSPACE
;
2090 termp_bf_pre(DECL_ARGS
)
2093 if (MDOC_HEAD
== n
->type
)
2095 else if (MDOC_BODY
!= n
->type
)
2098 if (FONT_Em
== n
->norm
->Bf
.font
)
2099 term_fontpush(p
, TERMFONT_UNDER
);
2100 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2101 term_fontpush(p
, TERMFONT_BOLD
);
2103 term_fontpush(p
, TERMFONT_NONE
);
2109 termp_sm_pre(DECL_ARGS
)
2112 if (NULL
== n
->child
)
2113 p
->flags
^= TERMP_NONOSPACE
;
2114 else if (0 == strcmp("on", n
->child
->string
))
2115 p
->flags
&= ~TERMP_NONOSPACE
;
2117 p
->flags
|= TERMP_NONOSPACE
;
2119 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2120 p
->flags
&= ~TERMP_NOSPACE
;
2126 termp_ap_pre(DECL_ARGS
)
2129 p
->flags
|= TERMP_NOSPACE
;
2131 p
->flags
|= TERMP_NOSPACE
;
2136 termp____post(DECL_ARGS
)
2140 * Handle lists of authors. In general, print each followed by
2141 * a comma. Don't print the comma if there are only two
2144 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2145 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2146 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2151 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2154 p
->flags
|= TERMP_NOSPACE
;
2155 if (NULL
== n
->next
) {
2157 p
->flags
|= TERMP_SENTENCE
;
2163 termp_li_pre(DECL_ARGS
)
2166 term_fontpush(p
, TERMFONT_NONE
);
2171 termp_lk_pre(DECL_ARGS
)
2173 const struct mdoc_node
*link
, *descr
;
2175 if (NULL
== (link
= n
->child
))
2178 if (NULL
!= (descr
= link
->next
)) {
2179 term_fontpush(p
, TERMFONT_UNDER
);
2180 while (NULL
!= descr
) {
2181 term_word(p
, descr
->string
);
2182 descr
= descr
->next
;
2184 p
->flags
|= TERMP_NOSPACE
;
2189 term_fontpush(p
, TERMFONT_BOLD
);
2190 term_word(p
, link
->string
);
2197 termp_bk_pre(DECL_ARGS
)
2206 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2207 p
->flags
|= TERMP_PREKEEP
;
2218 termp_bk_post(DECL_ARGS
)
2221 if (MDOC_BODY
== n
->type
)
2222 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2226 termp__t_post(DECL_ARGS
)
2230 * If we're in an `Rs' and there's a journal present, then quote
2231 * us instead of underlining us (for disambiguation).
2233 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2234 n
->parent
->norm
->Rs
.quote_T
)
2235 termp_quote_post(p
, pair
, meta
, n
);
2237 termp____post(p
, pair
, meta
, n
);
2241 termp__t_pre(DECL_ARGS
)
2245 * If we're in an `Rs' and there's a journal present, then quote
2246 * us instead of underlining us (for disambiguation).
2248 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2249 n
->parent
->norm
->Rs
.quote_T
)
2250 return(termp_quote_pre(p
, pair
, meta
, n
));
2252 term_fontpush(p
, TERMFONT_UNDER
);
2257 termp_under_pre(DECL_ARGS
)
2260 term_fontpush(p
, TERMFONT_UNDER
);