]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.320 2015/07/17 22:38:29 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 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
);
84 static int termp__a_pre(DECL_ARGS
);
85 static int termp__t_pre(DECL_ARGS
);
86 static int termp_an_pre(DECL_ARGS
);
87 static int termp_ap_pre(DECL_ARGS
);
88 static int termp_bd_pre(DECL_ARGS
);
89 static int termp_bf_pre(DECL_ARGS
);
90 static int termp_bk_pre(DECL_ARGS
);
91 static int termp_bl_pre(DECL_ARGS
);
92 static int termp_bold_pre(DECL_ARGS
);
93 static int termp_bt_pre(DECL_ARGS
);
94 static int termp_bx_pre(DECL_ARGS
);
95 static int termp_cd_pre(DECL_ARGS
);
96 static int termp_d1_pre(DECL_ARGS
);
97 static int termp_eo_pre(DECL_ARGS
);
98 static int termp_ex_pre(DECL_ARGS
);
99 static int termp_fa_pre(DECL_ARGS
);
100 static int termp_fd_pre(DECL_ARGS
);
101 static int termp_fl_pre(DECL_ARGS
);
102 static int termp_fn_pre(DECL_ARGS
);
103 static int termp_fo_pre(DECL_ARGS
);
104 static int termp_ft_pre(DECL_ARGS
);
105 static int termp_in_pre(DECL_ARGS
);
106 static int termp_it_pre(DECL_ARGS
);
107 static int termp_li_pre(DECL_ARGS
);
108 static int termp_ll_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_rv_pre(DECL_ARGS
);
116 static int termp_sh_pre(DECL_ARGS
);
117 static int termp_skip_pre(DECL_ARGS
);
118 static int termp_sm_pre(DECL_ARGS
);
119 static int termp_sp_pre(DECL_ARGS
);
120 static int termp_ss_pre(DECL_ARGS
);
121 static int termp_tag_pre(DECL_ARGS
);
122 static int termp_under_pre(DECL_ARGS
);
123 static int termp_ud_pre(DECL_ARGS
);
124 static int termp_vt_pre(DECL_ARGS
);
125 static int termp_xr_pre(DECL_ARGS
);
126 static int termp_xx_pre(DECL_ARGS
);
128 static const struct termact termacts
[MDOC_MAX
] = {
129 { termp_ap_pre
, NULL
}, /* Ap */
130 { NULL
, NULL
}, /* Dd */
131 { NULL
, NULL
}, /* Dt */
132 { NULL
, NULL
}, /* Os */
133 { termp_sh_pre
, termp_sh_post
}, /* Sh */
134 { termp_ss_pre
, termp_ss_post
}, /* Ss */
135 { termp_sp_pre
, NULL
}, /* Pp */
136 { termp_d1_pre
, termp_bl_post
}, /* D1 */
137 { termp_d1_pre
, termp_bl_post
}, /* Dl */
138 { termp_bd_pre
, termp_bd_post
}, /* Bd */
139 { NULL
, NULL
}, /* Ed */
140 { termp_bl_pre
, termp_bl_post
}, /* Bl */
141 { NULL
, NULL
}, /* El */
142 { termp_it_pre
, termp_it_post
}, /* It */
143 { termp_under_pre
, NULL
}, /* Ad */
144 { termp_an_pre
, NULL
}, /* An */
145 { termp_under_pre
, NULL
}, /* Ar */
146 { termp_cd_pre
, NULL
}, /* Cd */
147 { termp_bold_pre
, NULL
}, /* Cm */
148 { NULL
, NULL
}, /* Dv */
149 { NULL
, NULL
}, /* Er */
150 { termp_tag_pre
, NULL
}, /* Ev */
151 { termp_ex_pre
, NULL
}, /* Ex */
152 { termp_fa_pre
, NULL
}, /* Fa */
153 { termp_fd_pre
, termp_fd_post
}, /* Fd */
154 { termp_fl_pre
, NULL
}, /* Fl */
155 { termp_fn_pre
, NULL
}, /* Fn */
156 { termp_ft_pre
, NULL
}, /* Ft */
157 { termp_bold_pre
, NULL
}, /* Ic */
158 { termp_in_pre
, termp_in_post
}, /* In */
159 { termp_li_pre
, NULL
}, /* Li */
160 { termp_nd_pre
, NULL
}, /* Nd */
161 { termp_nm_pre
, termp_nm_post
}, /* Nm */
162 { termp_quote_pre
, termp_quote_post
}, /* Op */
163 { termp_ft_pre
, NULL
}, /* Ot */
164 { termp_under_pre
, NULL
}, /* Pa */
165 { termp_rv_pre
, NULL
}, /* Rv */
166 { NULL
, NULL
}, /* St */
167 { termp_under_pre
, NULL
}, /* Va */
168 { termp_vt_pre
, NULL
}, /* Vt */
169 { termp_xr_pre
, NULL
}, /* Xr */
170 { termp__a_pre
, termp____post
}, /* %A */
171 { termp_under_pre
, termp____post
}, /* %B */
172 { NULL
, termp____post
}, /* %D */
173 { termp_under_pre
, termp____post
}, /* %I */
174 { termp_under_pre
, termp____post
}, /* %J */
175 { NULL
, termp____post
}, /* %N */
176 { NULL
, termp____post
}, /* %O */
177 { NULL
, termp____post
}, /* %P */
178 { NULL
, termp____post
}, /* %R */
179 { termp__t_pre
, termp__t_post
}, /* %T */
180 { NULL
, termp____post
}, /* %V */
181 { NULL
, NULL
}, /* Ac */
182 { termp_quote_pre
, termp_quote_post
}, /* Ao */
183 { termp_quote_pre
, termp_quote_post
}, /* Aq */
184 { NULL
, NULL
}, /* At */
185 { NULL
, NULL
}, /* Bc */
186 { termp_bf_pre
, NULL
}, /* Bf */
187 { termp_quote_pre
, termp_quote_post
}, /* Bo */
188 { termp_quote_pre
, termp_quote_post
}, /* Bq */
189 { termp_xx_pre
, NULL
}, /* Bsx */
190 { termp_bx_pre
, NULL
}, /* Bx */
191 { termp_skip_pre
, NULL
}, /* Db */
192 { NULL
, NULL
}, /* Dc */
193 { termp_quote_pre
, termp_quote_post
}, /* Do */
194 { termp_quote_pre
, termp_quote_post
}, /* Dq */
195 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
196 { NULL
, NULL
}, /* Ef */
197 { termp_under_pre
, NULL
}, /* Em */
198 { termp_eo_pre
, termp_eo_post
}, /* Eo */
199 { termp_xx_pre
, NULL
}, /* Fx */
200 { termp_bold_pre
, NULL
}, /* Ms */
201 { termp_li_pre
, NULL
}, /* No */
202 { termp_ns_pre
, NULL
}, /* Ns */
203 { termp_xx_pre
, NULL
}, /* Nx */
204 { termp_xx_pre
, NULL
}, /* Ox */
205 { NULL
, NULL
}, /* Pc */
206 { NULL
, termp_pf_post
}, /* Pf */
207 { termp_quote_pre
, termp_quote_post
}, /* Po */
208 { termp_quote_pre
, termp_quote_post
}, /* Pq */
209 { NULL
, NULL
}, /* Qc */
210 { termp_quote_pre
, termp_quote_post
}, /* Ql */
211 { termp_quote_pre
, termp_quote_post
}, /* Qo */
212 { termp_quote_pre
, termp_quote_post
}, /* Qq */
213 { NULL
, NULL
}, /* Re */
214 { termp_rs_pre
, NULL
}, /* Rs */
215 { NULL
, NULL
}, /* Sc */
216 { termp_quote_pre
, termp_quote_post
}, /* So */
217 { termp_quote_pre
, termp_quote_post
}, /* Sq */
218 { termp_sm_pre
, NULL
}, /* Sm */
219 { termp_under_pre
, NULL
}, /* Sx */
220 { termp_bold_pre
, NULL
}, /* Sy */
221 { NULL
, NULL
}, /* Tn */
222 { termp_xx_pre
, NULL
}, /* Ux */
223 { NULL
, NULL
}, /* Xc */
224 { NULL
, NULL
}, /* Xo */
225 { termp_fo_pre
, termp_fo_post
}, /* Fo */
226 { NULL
, NULL
}, /* Fc */
227 { termp_quote_pre
, termp_quote_post
}, /* Oo */
228 { NULL
, NULL
}, /* Oc */
229 { termp_bk_pre
, termp_bk_post
}, /* Bk */
230 { NULL
, NULL
}, /* Ek */
231 { termp_bt_pre
, NULL
}, /* Bt */
232 { NULL
, NULL
}, /* Hf */
233 { termp_under_pre
, NULL
}, /* Fr */
234 { termp_ud_pre
, NULL
}, /* Ud */
235 { NULL
, termp_lb_post
}, /* Lb */
236 { termp_sp_pre
, NULL
}, /* Lp */
237 { termp_lk_pre
, NULL
}, /* Lk */
238 { termp_under_pre
, NULL
}, /* Mt */
239 { termp_quote_pre
, termp_quote_post
}, /* Brq */
240 { termp_quote_pre
, termp_quote_post
}, /* Bro */
241 { NULL
, NULL
}, /* Brc */
242 { NULL
, termp____post
}, /* %C */
243 { termp_skip_pre
, NULL
}, /* Es */
244 { termp_quote_pre
, termp_quote_post
}, /* En */
245 { termp_xx_pre
, NULL
}, /* Dx */
246 { NULL
, termp____post
}, /* %Q */
247 { termp_sp_pre
, NULL
}, /* br */
248 { termp_sp_pre
, NULL
}, /* sp */
249 { NULL
, termp____post
}, /* %U */
250 { NULL
, NULL
}, /* Ta */
251 { termp_ll_pre
, NULL
}, /* ll */
256 terminal_mdoc(void *arg
, const struct roff_man
*mdoc
)
261 p
= (struct termp
*)arg
;
263 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
264 p
->tabwidth
= term_len(p
, 5);
266 n
= mdoc
->first
->child
;
267 if (p
->synopsisonly
) {
269 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
270 if (n
->child
->next
->child
!= NULL
)
271 print_mdoc_nodelist(p
, NULL
,
273 n
->child
->next
->child
);
280 if (p
->defindent
== 0)
282 term_begin(p
, print_mdoc_head
, print_mdoc_foot
,
285 if (n
->tok
!= MDOC_Sh
)
287 print_mdoc_nodelist(p
, NULL
, &mdoc
->meta
, n
);
294 print_mdoc_nodelist(DECL_ARGS
)
298 print_mdoc_node(p
, pair
, meta
, n
);
304 print_mdoc_node(DECL_ARGS
)
307 struct termpair npair
;
308 size_t offset
, rmargin
;
312 rmargin
= p
->rmargin
;
313 n
->flags
&= ~MDOC_ENDED
;
314 n
->prev_font
= p
->fonti
;
316 memset(&npair
, 0, sizeof(struct termpair
));
320 * Keeps only work until the end of a line. If a keep was
321 * invoked in a prior line, revert it to PREKEEP.
324 if (p
->flags
& TERMP_KEEP
&& n
->flags
& MDOC_LINE
) {
325 p
->flags
&= ~TERMP_KEEP
;
326 p
->flags
|= TERMP_PREKEEP
;
330 * After the keep flags have been set up, we may now
331 * produce output. Note that some pre-handlers do so.
336 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
338 if (MDOC_DELIMC
& n
->flags
)
339 p
->flags
|= TERMP_NOSPACE
;
340 term_word(p
, n
->string
);
341 if (MDOC_DELIMO
& n
->flags
)
342 p
->flags
|= TERMP_NOSPACE
;
345 if ( ! (n
->flags
& MDOC_LINE
))
346 p
->flags
|= TERMP_NOSPACE
;
348 if (n
->next
!= NULL
&& ! (n
->next
->flags
& MDOC_LINE
))
349 p
->flags
|= TERMP_NOSPACE
;
352 if (p
->tbl
.cols
== NULL
)
354 term_tbl(p
, n
->span
);
357 if (termacts
[n
->tok
].pre
&&
358 (n
->end
== ENDBODY_NOT
|| n
->nchild
))
359 chld
= (*termacts
[n
->tok
].pre
)
360 (p
, &npair
, meta
, n
);
364 if (chld
&& n
->child
)
365 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
368 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
378 if ( ! termacts
[n
->tok
].post
|| MDOC_ENDED
& n
->flags
)
380 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
383 * Explicit end tokens not only call the post
384 * handler, but also tell the respective block
385 * that it must not call the post handler again.
387 if (ENDBODY_NOT
!= n
->end
)
388 n
->body
->flags
|= MDOC_ENDED
;
391 * End of line terminating an implicit block
392 * while an explicit block is still open.
393 * Continue the explicit block without spacing.
395 if (ENDBODY_NOSPACE
== n
->end
)
396 p
->flags
|= TERMP_NOSPACE
;
400 if (MDOC_EOS
& n
->flags
)
401 p
->flags
|= TERMP_SENTENCE
;
403 if (MDOC_ll
!= n
->tok
) {
405 p
->rmargin
= rmargin
;
410 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
414 term_fontrepl(p
, TERMFONT_NONE
);
417 * Output the footer in new-groff style, that is, three columns
418 * with the middle being the manual date and flanking columns
419 * being the operating system:
427 sz
= term_strlen(p
, meta
->date
);
428 p
->rmargin
= p
->maxrmargin
> sz
?
429 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
431 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
433 term_word(p
, meta
->os
);
436 p
->offset
= p
->rmargin
;
437 sz
= term_strlen(p
, meta
->os
);
438 p
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
439 p
->flags
|= TERMP_NOSPACE
;
441 term_word(p
, meta
->date
);
444 p
->offset
= p
->rmargin
;
445 p
->rmargin
= p
->maxrmargin
;
447 p
->flags
&= ~TERMP_NOBREAK
;
448 p
->flags
|= TERMP_NOSPACE
;
450 term_word(p
, meta
->os
);
454 p
->rmargin
= p
->maxrmargin
;
459 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
461 char *volume
, *title
;
462 size_t vollen
, titlen
;
465 * The header is strange. It has three components, which are
466 * really two with the first duplicated. It goes like this:
468 * IDENTIFIER TITLE IDENTIFIER
470 * The IDENTIFIER is NAME(SECTION), which is the command-name
471 * (if given, or "unknown" if not) followed by the manual page
472 * section. These are given in `Dt'. The TITLE is a free-form
473 * string depending on the manual volume. If not specified, it
474 * switches on the manual section.
478 if (NULL
== meta
->arch
)
479 volume
= mandoc_strdup(meta
->vol
);
481 mandoc_asprintf(&volume
, "%s (%s)",
482 meta
->vol
, meta
->arch
);
483 vollen
= term_strlen(p
, volume
);
485 if (NULL
== meta
->msec
)
486 title
= mandoc_strdup(meta
->title
);
488 mandoc_asprintf(&title
, "%s(%s)",
489 meta
->title
, meta
->msec
);
490 titlen
= term_strlen(p
, title
);
492 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
495 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
496 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
497 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
502 p
->flags
|= TERMP_NOSPACE
;
503 p
->offset
= p
->rmargin
;
504 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
505 p
->maxrmargin
- titlen
: p
->maxrmargin
;
507 term_word(p
, volume
);
510 p
->flags
&= ~TERMP_NOBREAK
;
512 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
513 p
->flags
|= TERMP_NOSPACE
;
514 p
->offset
= p
->rmargin
;
515 p
->rmargin
= p
->maxrmargin
;
520 p
->flags
&= ~TERMP_NOSPACE
;
522 p
->rmargin
= p
->maxrmargin
;
528 a2width(const struct termp
*p
, const char *v
)
532 if (a2roffsu(v
, &su
, SCALE_MAX
) < 2) {
533 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
534 su
.scale
/= term_strlen(p
, "0");
536 return(term_hspan(p
, &su
) / 24);
540 * Determine how much space to print out before block elements of `It'
541 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
545 print_bvspace(struct termp
*p
,
546 const struct roff_node
*bl
,
547 const struct roff_node
*n
)
549 const struct roff_node
*nn
;
555 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
557 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
560 /* Do not vspace directly after Ss/Sh. */
563 while (nn
->prev
== NULL
) {
566 if (nn
->type
== ROFFT_ROOT
)
568 } while (nn
->type
!= ROFFT_BLOCK
);
569 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
571 if (nn
->tok
== MDOC_It
&&
572 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
576 /* A `-column' does not assert vspace within the list. */
578 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
579 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
582 /* A `-diag' without body does not vspace. */
584 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
585 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
586 assert(n
->prev
->body
);
587 if (NULL
== n
->prev
->body
->child
)
596 termp_ll_pre(DECL_ARGS
)
599 term_setwidth(p
, n
->nchild
? n
->child
->string
: NULL
);
604 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.
632 width
= term_len(p
, 2);
635 width
= term_len(p
, 8);
640 width
= term_len(p
, 10);
649 * First calculate width and offset. This is pretty easy unless
650 * we're a -column list, in which case all prior columns must
654 if (bl
->norm
->Bl
.offs
!= NULL
) {
655 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
656 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
658 else if (offset
> SHRT_MAX
)
664 if (n
->type
== ROFFT_HEAD
)
668 * Imitate groff's column handling:
669 * - For each earlier column, add its width.
670 * - For less than 5 columns, add four more blanks per
672 * - For exactly 5 columns, add three more blank per
674 * - For more than 5 columns, add only one column.
676 ncols
= bl
->norm
->Bl
.ncols
;
677 dcol
= ncols
< 5 ? term_len(p
, 4) :
678 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
681 * Calculate the offset by applying all prior ROFFT_BODY,
682 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
685 for (i
= 0, nn
= n
->prev
;
686 nn
->prev
&& i
< (int)ncols
;
688 offset
+= dcol
+ a2width(p
,
689 bl
->norm
->Bl
.cols
[i
]);
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 width
= a2width(p
, bl
->norm
->Bl
.cols
[i
]) + dcol
;
707 if (NULL
== bl
->norm
->Bl
.width
)
711 * Note: buffer the width by 2, which is groff's magic
712 * number for buffering single arguments. See the above
713 * handling for column for how this changes.
715 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
716 if (width
< 0 && (size_t)(-width
) > p
->offset
)
718 else if (width
> SHRT_MAX
)
724 * Whitespace control. Inset bodies need an initial space,
725 * while diagonal bodies need two.
728 p
->flags
|= TERMP_NOSPACE
;
732 if (n
->type
== ROFFT_BODY
)
733 term_word(p
, "\\ \\ ");
736 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->nchild
)
743 p
->flags
|= TERMP_NOSPACE
;
747 if (n
->type
== ROFFT_HEAD
)
748 term_fontpush(p
, TERMFONT_BOLD
);
755 * Pad and break control. This is the tricky part. These flags
756 * are documented in term_flushln() in term.c. Note that we're
757 * going to unset all of these flags in termp_it_post() when we
764 * Weird special case.
765 * Some very narrow lists actually hang.
773 if (width
<= (int)term_len(p
, 2))
774 p
->flags
|= TERMP_HANG
;
775 if (n
->type
!= ROFFT_HEAD
)
777 p
->flags
|= TERMP_NOBREAK
;
781 if (n
->type
!= ROFFT_HEAD
)
785 * This is ugly. If `-hang' is specified and the body
786 * is a `Bl' or `Bd', then we want basically to nullify
787 * the "overstep" effect in term_flushln() and treat
788 * this as a `-ohang' list instead.
790 if (NULL
!= n
->next
&&
791 NULL
!= n
->next
->child
&&
792 (MDOC_Bl
== n
->next
->child
->tok
||
793 MDOC_Bd
== n
->next
->child
->tok
))
796 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
800 if (n
->type
!= ROFFT_HEAD
)
803 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
806 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
807 p
->flags
|= TERMP_DANGLE
;
810 if (n
->type
== ROFFT_HEAD
)
813 if (NULL
== n
->next
) {
814 p
->flags
&= ~TERMP_NOBREAK
;
817 p
->flags
|= TERMP_NOBREAK
;
823 if (n
->type
!= ROFFT_HEAD
)
825 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
833 * Margin control. Set-head-width lists have their right
834 * margins shortened. The body for these lists has the offset
835 * necessarily lengthened. Everybody gets the offset.
843 * Same stipulation as above, regarding `-hang'. We
844 * don't want to recalculate rmargin and offsets when
845 * using `Bd' or `Bl' within `-hang' overstep lists.
847 if (n
->type
== ROFFT_HEAD
&&
849 NULL
!= n
->next
->child
&&
850 (MDOC_Bl
== n
->next
->child
->tok
||
851 MDOC_Bd
== n
->next
->child
->tok
))
863 if (n
->type
== ROFFT_HEAD
)
864 p
->rmargin
= p
->offset
+ width
;
870 p
->rmargin
= p
->offset
+ width
;
872 * XXX - this behaviour is not documented: the
873 * right-most column is filled to the right margin.
875 if (n
->type
== ROFFT_HEAD
)
877 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
878 p
->rmargin
= p
->maxrmargin
;
885 * The dash, hyphen, bullet and enum lists all have a special
886 * HEAD character (temporarily bold, in some cases).
889 if (n
->type
== ROFFT_HEAD
)
892 term_fontpush(p
, TERMFONT_BOLD
);
893 term_word(p
, "\\[bu]");
899 term_fontpush(p
, TERMFONT_BOLD
);
900 term_word(p
, "\\(hy");
904 (pair
->ppair
->ppair
->count
)++;
905 (void)snprintf(buf
, sizeof(buf
), "%d.",
906 pair
->ppair
->ppair
->count
);
914 * If we're not going to process our children, indicate so here.
927 if (n
->type
== ROFFT_HEAD
)
931 if (n
->type
== ROFFT_HEAD
)
942 termp_it_post(DECL_ARGS
)
946 if (n
->type
== ROFFT_BLOCK
)
949 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
957 if (n
->type
== ROFFT_BODY
)
961 if (n
->type
== ROFFT_BODY
)
970 * Now that our output is flushed, we can reset our tags. Since
971 * only `It' sets these flags, we're free to assume that nobody
972 * has munged them in the meanwhile.
975 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
976 TERMP_DANGLE
| TERMP_HANG
);
981 termp_nm_pre(DECL_ARGS
)
985 if (n
->type
== ROFFT_BLOCK
) {
986 p
->flags
|= TERMP_PREKEEP
;
990 if (n
->type
== ROFFT_BODY
) {
991 if (NULL
== n
->child
)
993 p
->flags
|= TERMP_NOSPACE
;
995 if (n
->prev
->child
!= NULL
)
996 cp
= n
->prev
->child
->string
;
1000 p
->offset
+= term_len(p
, 6);
1002 p
->offset
+= term_len(p
, 1) + term_strlen(p
, cp
);
1006 if (NULL
== n
->child
&& NULL
== meta
->name
)
1009 if (n
->type
== ROFFT_HEAD
)
1010 synopsis_pre(p
, n
->parent
);
1012 if (n
->type
== ROFFT_HEAD
&&
1013 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1014 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1016 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1017 if (NULL
== n
->child
) {
1018 p
->rmargin
+= term_strlen(p
, meta
->name
);
1019 } else if (n
->child
->type
== ROFFT_TEXT
) {
1020 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1022 p
->flags
|= TERMP_HANG
;
1024 p
->rmargin
+= term_len(p
, 5);
1025 p
->flags
|= TERMP_HANG
;
1029 term_fontpush(p
, TERMFONT_BOLD
);
1030 if (NULL
== n
->child
)
1031 term_word(p
, meta
->name
);
1036 termp_nm_post(DECL_ARGS
)
1039 if (n
->type
== ROFFT_BLOCK
) {
1040 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1041 } else if (n
->type
== ROFFT_HEAD
&&
1042 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1044 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1046 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1051 termp_fl_pre(DECL_ARGS
)
1054 termp_tag_pre(p
, pair
, meta
, n
);
1055 term_fontpush(p
, TERMFONT_BOLD
);
1056 term_word(p
, "\\-");
1058 if ( ! (n
->nchild
== 0 &&
1060 n
->next
->type
== ROFFT_TEXT
||
1061 n
->next
->flags
& MDOC_LINE
)))
1062 p
->flags
|= TERMP_NOSPACE
;
1068 termp__a_pre(DECL_ARGS
)
1071 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1072 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1073 term_word(p
, "and");
1079 termp_an_pre(DECL_ARGS
)
1082 if (n
->norm
->An
.auth
== AUTH_split
) {
1083 p
->flags
&= ~TERMP_NOSPLIT
;
1084 p
->flags
|= TERMP_SPLIT
;
1087 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1088 p
->flags
&= ~TERMP_SPLIT
;
1089 p
->flags
|= TERMP_NOSPLIT
;
1093 if (p
->flags
& TERMP_SPLIT
)
1096 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1097 p
->flags
|= TERMP_SPLIT
;
1103 termp_ns_pre(DECL_ARGS
)
1106 if ( ! (MDOC_LINE
& n
->flags
))
1107 p
->flags
|= TERMP_NOSPACE
;
1112 termp_rs_pre(DECL_ARGS
)
1115 if (SEC_SEE_ALSO
!= n
->sec
)
1117 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1123 termp_rv_pre(DECL_ARGS
)
1131 term_word(p
, "The");
1133 for (n
= n
->child
; n
; n
= n
->next
) {
1134 term_fontpush(p
, TERMFONT_BOLD
);
1135 term_word(p
, n
->string
);
1138 p
->flags
|= TERMP_NOSPACE
;
1141 if (n
->next
== NULL
)
1145 p
->flags
|= TERMP_NOSPACE
;
1148 if (n
->next
->next
== NULL
)
1149 term_word(p
, "and");
1153 term_word(p
, "functions return");
1155 term_word(p
, "function returns");
1157 term_word(p
, "the value\\~0 if successful;");
1159 term_word(p
, "Upon successful completion,"
1160 " the value\\~0 is returned;");
1162 term_word(p
, "otherwise the value\\~\\-1 is returned"
1163 " and the global variable");
1165 term_fontpush(p
, TERMFONT_UNDER
);
1166 term_word(p
, "errno");
1169 term_word(p
, "is set to indicate the error.");
1170 p
->flags
|= TERMP_SENTENCE
;
1176 termp_ex_pre(DECL_ARGS
)
1181 term_word(p
, "The");
1184 for (n
= n
->child
; n
; n
= n
->next
) {
1185 term_fontpush(p
, TERMFONT_BOLD
);
1186 term_word(p
, n
->string
);
1189 if (nchild
> 2 && n
->next
) {
1190 p
->flags
|= TERMP_NOSPACE
;
1194 if (n
->next
&& NULL
== n
->next
->next
)
1195 term_word(p
, "and");
1199 term_word(p
, "utilities exit\\~0");
1201 term_word(p
, "utility exits\\~0");
1203 term_word(p
, "on success, and\\~>0 if an error occurs.");
1205 p
->flags
|= TERMP_SENTENCE
;
1210 termp_nd_pre(DECL_ARGS
)
1213 if (n
->type
== ROFFT_BODY
)
1214 term_word(p
, "\\(en");
1219 termp_bl_pre(DECL_ARGS
)
1222 return(n
->type
!= ROFFT_HEAD
);
1226 termp_bl_post(DECL_ARGS
)
1229 if (n
->type
== ROFFT_BLOCK
)
1234 termp_xr_pre(DECL_ARGS
)
1237 if (NULL
== (n
= n
->child
))
1240 assert(n
->type
== ROFFT_TEXT
);
1241 term_word(p
, n
->string
);
1243 if (NULL
== (n
= n
->next
))
1246 p
->flags
|= TERMP_NOSPACE
;
1248 p
->flags
|= TERMP_NOSPACE
;
1250 assert(n
->type
== ROFFT_TEXT
);
1251 term_word(p
, n
->string
);
1253 p
->flags
|= TERMP_NOSPACE
;
1260 * This decides how to assert whitespace before any of the SYNOPSIS set
1261 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1265 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1268 * Obviously, if we're not in a SYNOPSIS or no prior macros
1269 * exist, do nothing.
1271 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1275 * If we're the second in a pair of like elements, emit our
1276 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1277 * case we soldier on.
1279 if (n
->prev
->tok
== n
->tok
&&
1280 MDOC_Ft
!= n
->tok
&&
1281 MDOC_Fo
!= n
->tok
&&
1282 MDOC_Fn
!= n
->tok
) {
1288 * If we're one of the SYNOPSIS set and non-like pair-wise after
1289 * another (or Fn/Fo, which we've let slip through) then assert
1290 * vertical space, else only newline and move on.
1292 switch (n
->prev
->tok
) {
1305 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1317 termp_vt_pre(DECL_ARGS
)
1320 if (n
->type
== ROFFT_ELEM
) {
1322 return(termp_under_pre(p
, pair
, meta
, n
));
1323 } else if (n
->type
== ROFFT_BLOCK
) {
1326 } else if (n
->type
== ROFFT_HEAD
)
1329 return(termp_under_pre(p
, pair
, meta
, n
));
1333 termp_bold_pre(DECL_ARGS
)
1336 termp_tag_pre(p
, pair
, meta
, n
);
1337 term_fontpush(p
, TERMFONT_BOLD
);
1342 termp_fd_pre(DECL_ARGS
)
1346 return(termp_bold_pre(p
, pair
, meta
, n
));
1350 termp_fd_post(DECL_ARGS
)
1357 termp_sh_pre(DECL_ARGS
)
1363 * Vertical space before sections, except
1364 * when the previous section was empty.
1366 if (n
->prev
== NULL
||
1367 MDOC_Sh
!= n
->prev
->tok
||
1368 (n
->prev
->body
!= NULL
&&
1369 n
->prev
->body
->child
!= NULL
))
1373 term_fontpush(p
, TERMFONT_BOLD
);
1376 p
->offset
= term_len(p
, p
->defindent
);
1377 if (SEC_AUTHORS
== n
->sec
)
1378 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1387 termp_sh_post(DECL_ARGS
)
1404 termp_bt_pre(DECL_ARGS
)
1407 term_word(p
, "is currently in beta test.");
1408 p
->flags
|= TERMP_SENTENCE
;
1413 termp_lb_post(DECL_ARGS
)
1416 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1421 termp_ud_pre(DECL_ARGS
)
1424 term_word(p
, "currently under development.");
1425 p
->flags
|= TERMP_SENTENCE
;
1430 termp_d1_pre(DECL_ARGS
)
1433 if (n
->type
!= ROFFT_BLOCK
)
1436 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1441 termp_ft_pre(DECL_ARGS
)
1444 /* NB: MDOC_LINE does not effect this! */
1446 term_fontpush(p
, TERMFONT_UNDER
);
1451 termp_fn_pre(DECL_ARGS
)
1456 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1460 if (NULL
== (n
= n
->child
))
1464 rmargin
= p
->rmargin
;
1465 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1466 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1469 assert(n
->type
== ROFFT_TEXT
);
1470 term_fontpush(p
, TERMFONT_BOLD
);
1471 term_word(p
, n
->string
);
1476 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1477 p
->offset
= p
->rmargin
;
1478 p
->rmargin
= rmargin
;
1481 p
->flags
|= TERMP_NOSPACE
;
1483 p
->flags
|= TERMP_NOSPACE
;
1485 for (n
= n
->next
; n
; n
= n
->next
) {
1486 assert(n
->type
== ROFFT_TEXT
);
1487 term_fontpush(p
, TERMFONT_UNDER
);
1489 p
->flags
|= TERMP_NBRWORD
;
1490 term_word(p
, n
->string
);
1494 p
->flags
|= TERMP_NOSPACE
;
1499 p
->flags
|= TERMP_NOSPACE
;
1503 p
->flags
|= TERMP_NOSPACE
;
1512 termp_fa_pre(DECL_ARGS
)
1514 const struct roff_node
*nn
;
1516 if (n
->parent
->tok
!= MDOC_Fo
) {
1517 term_fontpush(p
, TERMFONT_UNDER
);
1521 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1522 term_fontpush(p
, TERMFONT_UNDER
);
1523 p
->flags
|= TERMP_NBRWORD
;
1524 term_word(p
, nn
->string
);
1527 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1528 p
->flags
|= TERMP_NOSPACE
;
1537 termp_bd_pre(DECL_ARGS
)
1539 size_t tabwidth
, lm
, len
, rm
, rmax
;
1540 struct roff_node
*nn
;
1543 if (n
->type
== ROFFT_BLOCK
) {
1544 print_bvspace(p
, n
, n
);
1546 } else if (n
->type
== ROFFT_HEAD
)
1549 /* Handle the -offset argument. */
1551 if (n
->norm
->Bd
.offs
== NULL
||
1552 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1554 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1555 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1556 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1557 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1559 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1560 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
1562 else if (offset
< SHRT_MAX
)
1563 p
->offset
+= offset
;
1567 * If -ragged or -filled are specified, the block does nothing
1568 * but change the indentation. If -unfilled or -literal are
1569 * specified, text is printed exactly as entered in the display:
1570 * for macro lines, a newline is appended to the line. Blank
1571 * lines are allowed.
1574 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1575 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1576 DISP_centered
!= n
->norm
->Bd
.type
)
1579 tabwidth
= p
->tabwidth
;
1580 if (DISP_literal
== n
->norm
->Bd
.type
)
1581 p
->tabwidth
= term_len(p
, 8);
1585 rmax
= p
->maxrmargin
;
1586 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1588 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1589 if (DISP_centered
== n
->norm
->Bd
.type
) {
1590 if (nn
->type
== ROFFT_TEXT
) {
1591 len
= term_strlen(p
, nn
->string
);
1592 p
->offset
= len
>= rm
? 0 :
1593 lm
+ len
>= rm
? rm
- len
:
1594 (lm
+ rm
- len
) / 2;
1598 print_mdoc_node(p
, pair
, meta
, nn
);
1600 * If the printed node flushes its own line, then we
1601 * needn't do it here as well. This is hacky, but the
1602 * notion of selective eoln whitespace is pretty dumb
1603 * anyway, so don't sweat it.
1625 if (p
->flags
& TERMP_NONEWLINE
||
1626 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1629 p
->flags
|= TERMP_NOSPACE
;
1632 p
->tabwidth
= tabwidth
;
1634 p
->maxrmargin
= rmax
;
1639 termp_bd_post(DECL_ARGS
)
1643 if (n
->type
!= ROFFT_BODY
)
1647 rmax
= p
->maxrmargin
;
1649 if (DISP_literal
== n
->norm
->Bd
.type
||
1650 DISP_unfilled
== n
->norm
->Bd
.type
)
1651 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1653 p
->flags
|= TERMP_NOSPACE
;
1657 p
->maxrmargin
= rmax
;
1661 termp_bx_pre(DECL_ARGS
)
1664 if (NULL
!= (n
= n
->child
)) {
1665 term_word(p
, n
->string
);
1666 p
->flags
|= TERMP_NOSPACE
;
1667 term_word(p
, "BSD");
1669 term_word(p
, "BSD");
1673 if (NULL
!= (n
= n
->next
)) {
1674 p
->flags
|= TERMP_NOSPACE
;
1676 p
->flags
|= TERMP_NOSPACE
;
1677 term_word(p
, n
->string
);
1684 termp_xx_pre(DECL_ARGS
)
1717 p
->flags
|= TERMP_KEEP
;
1718 term_word(p
, n
->child
->string
);
1725 termp_pf_post(DECL_ARGS
)
1728 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1729 p
->flags
|= TERMP_NOSPACE
;
1733 termp_ss_pre(DECL_ARGS
)
1743 term_fontpush(p
, TERMFONT_BOLD
);
1744 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1747 p
->offset
= term_len(p
, p
->defindent
);
1757 termp_ss_post(DECL_ARGS
)
1760 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1765 termp_cd_pre(DECL_ARGS
)
1769 term_fontpush(p
, TERMFONT_BOLD
);
1774 termp_in_pre(DECL_ARGS
)
1779 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1780 term_fontpush(p
, TERMFONT_BOLD
);
1781 term_word(p
, "#include");
1785 term_fontpush(p
, TERMFONT_UNDER
);
1788 p
->flags
|= TERMP_NOSPACE
;
1793 termp_in_post(DECL_ARGS
)
1796 if (MDOC_SYNPRETTY
& n
->flags
)
1797 term_fontpush(p
, TERMFONT_BOLD
);
1799 p
->flags
|= TERMP_NOSPACE
;
1802 if (MDOC_SYNPRETTY
& n
->flags
)
1807 termp_sp_pre(DECL_ARGS
)
1815 if ( ! a2roffsu(n
->child
->string
, &su
, SCALE_VS
))
1817 len
= term_vspan(p
, &su
);
1834 for (i
= 0; i
< len
; i
++)
1841 termp_skip_pre(DECL_ARGS
)
1848 termp_quote_pre(DECL_ARGS
)
1851 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1858 term_word(p
, n
->nchild
== 1 &&
1859 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1878 term_word(p
, "\\(Lq");
1881 if (NULL
== n
->norm
->Es
||
1882 NULL
== n
->norm
->Es
->child
)
1884 term_word(p
, n
->norm
->Es
->child
->string
);
1903 term_word(p
, "\\(oq");
1910 p
->flags
|= TERMP_NOSPACE
;
1915 termp_quote_post(DECL_ARGS
)
1918 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1921 p
->flags
|= TERMP_NOSPACE
;
1927 term_word(p
, n
->nchild
== 1 &&
1928 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1947 term_word(p
, "\\(Rq");
1950 if (n
->norm
->Es
== NULL
||
1951 n
->norm
->Es
->child
== NULL
||
1952 n
->norm
->Es
->child
->next
== NULL
)
1953 p
->flags
&= ~TERMP_NOSPACE
;
1955 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1974 term_word(p
, "\\(cq");
1983 termp_eo_pre(DECL_ARGS
)
1986 if (n
->type
!= ROFFT_BODY
)
1989 if (n
->end
== ENDBODY_NOT
&&
1990 n
->parent
->head
->child
== NULL
&&
1992 n
->child
->end
!= ENDBODY_NOT
)
1993 term_word(p
, "\\&");
1994 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1995 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1996 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1997 p
->flags
|= TERMP_NOSPACE
;
2003 termp_eo_post(DECL_ARGS
)
2007 if (n
->type
!= ROFFT_BODY
)
2010 if (n
->end
!= ENDBODY_NOT
) {
2011 p
->flags
&= ~TERMP_NOSPACE
;
2015 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2016 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2019 p
->flags
|= TERMP_NOSPACE
;
2020 else if ( ! (body
|| tail
))
2021 term_word(p
, "\\&");
2023 p
->flags
&= ~TERMP_NOSPACE
;
2027 termp_fo_pre(DECL_ARGS
)
2032 pretty
= MDOC_SYNPRETTY
& n
->flags
;
2034 if (n
->type
== ROFFT_BLOCK
) {
2037 } else if (n
->type
== ROFFT_BODY
) {
2039 rmargin
= p
->rmargin
;
2040 p
->rmargin
= p
->offset
+ term_len(p
, 4);
2041 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
2044 p
->flags
|= TERMP_NOSPACE
;
2046 p
->flags
|= TERMP_NOSPACE
;
2049 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2051 p
->offset
= p
->rmargin
;
2052 p
->rmargin
= rmargin
;
2057 if (NULL
== n
->child
)
2060 /* XXX: we drop non-initial arguments as per groff. */
2062 assert(n
->child
->string
);
2063 term_fontpush(p
, TERMFONT_BOLD
);
2064 term_word(p
, n
->child
->string
);
2069 termp_fo_post(DECL_ARGS
)
2072 if (n
->type
!= ROFFT_BODY
)
2075 p
->flags
|= TERMP_NOSPACE
;
2078 if (MDOC_SYNPRETTY
& n
->flags
) {
2079 p
->flags
|= TERMP_NOSPACE
;
2086 termp_bf_pre(DECL_ARGS
)
2089 if (n
->type
== ROFFT_HEAD
)
2091 else if (n
->type
!= ROFFT_BODY
)
2094 if (FONT_Em
== n
->norm
->Bf
.font
)
2095 term_fontpush(p
, TERMFONT_UNDER
);
2096 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2097 term_fontpush(p
, TERMFONT_BOLD
);
2099 term_fontpush(p
, TERMFONT_NONE
);
2105 termp_sm_pre(DECL_ARGS
)
2108 if (NULL
== n
->child
)
2109 p
->flags
^= TERMP_NONOSPACE
;
2110 else if (0 == strcmp("on", n
->child
->string
))
2111 p
->flags
&= ~TERMP_NONOSPACE
;
2113 p
->flags
|= TERMP_NONOSPACE
;
2115 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2116 p
->flags
&= ~TERMP_NOSPACE
;
2122 termp_ap_pre(DECL_ARGS
)
2125 p
->flags
|= TERMP_NOSPACE
;
2127 p
->flags
|= TERMP_NOSPACE
;
2132 termp____post(DECL_ARGS
)
2136 * Handle lists of authors. In general, print each followed by
2137 * a comma. Don't print the comma if there are only two
2140 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2141 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2142 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2147 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2150 p
->flags
|= TERMP_NOSPACE
;
2151 if (NULL
== n
->next
) {
2153 p
->flags
|= TERMP_SENTENCE
;
2159 termp_li_pre(DECL_ARGS
)
2162 term_fontpush(p
, TERMFONT_NONE
);
2167 termp_lk_pre(DECL_ARGS
)
2169 const struct roff_node
*link
, *descr
;
2171 if (NULL
== (link
= n
->child
))
2174 if (NULL
!= (descr
= link
->next
)) {
2175 term_fontpush(p
, TERMFONT_UNDER
);
2176 while (NULL
!= descr
) {
2177 term_word(p
, descr
->string
);
2178 descr
= descr
->next
;
2180 p
->flags
|= TERMP_NOSPACE
;
2185 term_fontpush(p
, TERMFONT_BOLD
);
2186 term_word(p
, link
->string
);
2193 termp_bk_pre(DECL_ARGS
)
2202 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2203 p
->flags
|= TERMP_PREKEEP
;
2214 termp_bk_post(DECL_ARGS
)
2217 if (n
->type
== ROFFT_BODY
)
2218 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2222 termp__t_post(DECL_ARGS
)
2226 * If we're in an `Rs' and there's a journal present, then quote
2227 * us instead of underlining us (for disambiguation).
2229 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2230 n
->parent
->norm
->Rs
.quote_T
)
2231 termp_quote_post(p
, pair
, meta
, n
);
2233 termp____post(p
, pair
, meta
, n
);
2237 termp__t_pre(DECL_ARGS
)
2241 * If we're in an `Rs' and there's a journal present, then quote
2242 * us instead of underlining us (for disambiguation).
2244 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2245 n
->parent
->norm
->Rs
.quote_T
)
2246 return(termp_quote_pre(p
, pair
, meta
, n
));
2248 term_fontpush(p
, TERMFONT_UNDER
);
2253 termp_under_pre(DECL_ARGS
)
2256 term_fontpush(p
, TERMFONT_UNDER
);
2261 termp_tag_pre(DECL_ARGS
)
2264 if (n
->child
!= NULL
&&
2265 n
->child
->type
== ROFFT_TEXT
&&
2267 (n
->parent
->tok
== MDOC_It
||
2268 (n
->parent
->tok
== MDOC_Xo
&&
2269 n
->parent
->parent
->prev
== NULL
&&
2270 n
->parent
->parent
->parent
->tok
== MDOC_It
)) &&
2271 ! tag_get(n
->child
->string
, 0))
2272 tag_put(n
->child
->string
, 0, p
->line
);