]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.316 2015/04/02 23:48:20 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"
40 struct termpair
*ppair
;
44 #define DECL_ARGS struct termp *p, \
45 struct termpair *pair, \
46 const struct roff_meta *meta, \
50 int (*pre
)(DECL_ARGS
);
51 void (*post
)(DECL_ARGS
);
54 static int a2width(const struct termp
*, const char *);
56 static void print_bvspace(struct termp
*,
57 const struct roff_node
*,
58 const struct roff_node
*);
59 static void print_mdoc_node(DECL_ARGS
);
60 static void print_mdoc_nodelist(DECL_ARGS
);
61 static void print_mdoc_head(struct termp
*, const struct roff_meta
*);
62 static void print_mdoc_foot(struct termp
*, const struct roff_meta
*);
63 static void synopsis_pre(struct termp
*,
64 const struct roff_node
*);
66 static void termp____post(DECL_ARGS
);
67 static void termp__t_post(DECL_ARGS
);
68 static void termp_bd_post(DECL_ARGS
);
69 static void termp_bk_post(DECL_ARGS
);
70 static void termp_bl_post(DECL_ARGS
);
71 static void termp_eo_post(DECL_ARGS
);
72 static void termp_fd_post(DECL_ARGS
);
73 static void termp_fo_post(DECL_ARGS
);
74 static void termp_in_post(DECL_ARGS
);
75 static void termp_it_post(DECL_ARGS
);
76 static void termp_lb_post(DECL_ARGS
);
77 static void termp_nm_post(DECL_ARGS
);
78 static void termp_pf_post(DECL_ARGS
);
79 static void termp_quote_post(DECL_ARGS
);
80 static void termp_sh_post(DECL_ARGS
);
81 static void termp_ss_post(DECL_ARGS
);
83 static int termp__a_pre(DECL_ARGS
);
84 static int termp__t_pre(DECL_ARGS
);
85 static int termp_an_pre(DECL_ARGS
);
86 static int termp_ap_pre(DECL_ARGS
);
87 static int termp_bd_pre(DECL_ARGS
);
88 static int termp_bf_pre(DECL_ARGS
);
89 static int termp_bk_pre(DECL_ARGS
);
90 static int termp_bl_pre(DECL_ARGS
);
91 static int termp_bold_pre(DECL_ARGS
);
92 static int termp_bt_pre(DECL_ARGS
);
93 static int termp_bx_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_ex_pre(DECL_ARGS
);
98 static int termp_fa_pre(DECL_ARGS
);
99 static int termp_fd_pre(DECL_ARGS
);
100 static int termp_fl_pre(DECL_ARGS
);
101 static int termp_fn_pre(DECL_ARGS
);
102 static int termp_fo_pre(DECL_ARGS
);
103 static int termp_ft_pre(DECL_ARGS
);
104 static int termp_in_pre(DECL_ARGS
);
105 static int termp_it_pre(DECL_ARGS
);
106 static int termp_li_pre(DECL_ARGS
);
107 static int termp_ll_pre(DECL_ARGS
);
108 static int termp_lk_pre(DECL_ARGS
);
109 static int termp_nd_pre(DECL_ARGS
);
110 static int termp_nm_pre(DECL_ARGS
);
111 static int termp_ns_pre(DECL_ARGS
);
112 static int termp_quote_pre(DECL_ARGS
);
113 static int termp_rs_pre(DECL_ARGS
);
114 static int termp_rv_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_sp_pre(DECL_ARGS
);
119 static int termp_ss_pre(DECL_ARGS
);
120 static int termp_under_pre(DECL_ARGS
);
121 static int termp_ud_pre(DECL_ARGS
);
122 static int termp_vt_pre(DECL_ARGS
);
123 static int termp_xr_pre(DECL_ARGS
);
124 static int termp_xx_pre(DECL_ARGS
);
126 static const struct termact termacts
[MDOC_MAX
] = {
127 { termp_ap_pre
, NULL
}, /* Ap */
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_sp_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_under_pre
, NULL
}, /* Ar */
144 { termp_cd_pre
, NULL
}, /* Cd */
145 { termp_bold_pre
, NULL
}, /* Cm */
146 { NULL
, NULL
}, /* Dv */
147 { NULL
, NULL
}, /* Er */
148 { NULL
, NULL
}, /* Ev */
149 { termp_ex_pre
, NULL
}, /* Ex */
150 { termp_fa_pre
, NULL
}, /* Fa */
151 { termp_fd_pre
, termp_fd_post
}, /* Fd */
152 { termp_fl_pre
, NULL
}, /* Fl */
153 { termp_fn_pre
, NULL
}, /* Fn */
154 { termp_ft_pre
, NULL
}, /* Ft */
155 { termp_bold_pre
, NULL
}, /* Ic */
156 { termp_in_pre
, termp_in_post
}, /* In */
157 { termp_li_pre
, NULL
}, /* Li */
158 { termp_nd_pre
, NULL
}, /* Nd */
159 { termp_nm_pre
, termp_nm_post
}, /* Nm */
160 { termp_quote_pre
, termp_quote_post
}, /* Op */
161 { termp_ft_pre
, NULL
}, /* Ot */
162 { termp_under_pre
, NULL
}, /* Pa */
163 { termp_rv_pre
, NULL
}, /* Rv */
164 { NULL
, NULL
}, /* St */
165 { termp_under_pre
, NULL
}, /* Va */
166 { termp_vt_pre
, NULL
}, /* Vt */
167 { termp_xr_pre
, NULL
}, /* Xr */
168 { termp__a_pre
, termp____post
}, /* %A */
169 { termp_under_pre
, termp____post
}, /* %B */
170 { NULL
, termp____post
}, /* %D */
171 { termp_under_pre
, termp____post
}, /* %I */
172 { termp_under_pre
, termp____post
}, /* %J */
173 { NULL
, termp____post
}, /* %N */
174 { NULL
, termp____post
}, /* %O */
175 { NULL
, termp____post
}, /* %P */
176 { NULL
, termp____post
}, /* %R */
177 { termp__t_pre
, termp__t_post
}, /* %T */
178 { NULL
, termp____post
}, /* %V */
179 { NULL
, NULL
}, /* Ac */
180 { termp_quote_pre
, termp_quote_post
}, /* Ao */
181 { termp_quote_pre
, termp_quote_post
}, /* Aq */
182 { NULL
, NULL
}, /* At */
183 { NULL
, NULL
}, /* Bc */
184 { termp_bf_pre
, NULL
}, /* Bf */
185 { termp_quote_pre
, termp_quote_post
}, /* Bo */
186 { termp_quote_pre
, termp_quote_post
}, /* Bq */
187 { termp_xx_pre
, NULL
}, /* Bsx */
188 { termp_bx_pre
, NULL
}, /* Bx */
189 { termp_skip_pre
, NULL
}, /* Db */
190 { NULL
, NULL
}, /* Dc */
191 { termp_quote_pre
, termp_quote_post
}, /* Do */
192 { termp_quote_pre
, termp_quote_post
}, /* Dq */
193 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
194 { NULL
, NULL
}, /* Ef */
195 { termp_under_pre
, NULL
}, /* Em */
196 { termp_eo_pre
, termp_eo_post
}, /* Eo */
197 { termp_xx_pre
, NULL
}, /* Fx */
198 { termp_bold_pre
, NULL
}, /* Ms */
199 { termp_li_pre
, NULL
}, /* No */
200 { termp_ns_pre
, NULL
}, /* Ns */
201 { termp_xx_pre
, NULL
}, /* Nx */
202 { termp_xx_pre
, NULL
}, /* Ox */
203 { NULL
, NULL
}, /* Pc */
204 { NULL
, termp_pf_post
}, /* Pf */
205 { termp_quote_pre
, termp_quote_post
}, /* Po */
206 { termp_quote_pre
, termp_quote_post
}, /* Pq */
207 { NULL
, NULL
}, /* Qc */
208 { termp_quote_pre
, termp_quote_post
}, /* Ql */
209 { termp_quote_pre
, termp_quote_post
}, /* Qo */
210 { termp_quote_pre
, termp_quote_post
}, /* Qq */
211 { NULL
, NULL
}, /* Re */
212 { termp_rs_pre
, NULL
}, /* Rs */
213 { NULL
, NULL
}, /* Sc */
214 { termp_quote_pre
, termp_quote_post
}, /* So */
215 { termp_quote_pre
, termp_quote_post
}, /* Sq */
216 { termp_sm_pre
, NULL
}, /* Sm */
217 { termp_under_pre
, NULL
}, /* Sx */
218 { termp_bold_pre
, NULL
}, /* Sy */
219 { NULL
, NULL
}, /* Tn */
220 { termp_xx_pre
, NULL
}, /* Ux */
221 { NULL
, NULL
}, /* Xc */
222 { NULL
, NULL
}, /* Xo */
223 { termp_fo_pre
, termp_fo_post
}, /* Fo */
224 { NULL
, NULL
}, /* Fc */
225 { termp_quote_pre
, termp_quote_post
}, /* Oo */
226 { NULL
, NULL
}, /* Oc */
227 { termp_bk_pre
, termp_bk_post
}, /* Bk */
228 { NULL
, NULL
}, /* Ek */
229 { termp_bt_pre
, NULL
}, /* Bt */
230 { NULL
, NULL
}, /* Hf */
231 { termp_under_pre
, NULL
}, /* Fr */
232 { termp_ud_pre
, NULL
}, /* Ud */
233 { NULL
, termp_lb_post
}, /* Lb */
234 { termp_sp_pre
, NULL
}, /* Lp */
235 { termp_lk_pre
, NULL
}, /* Lk */
236 { termp_under_pre
, NULL
}, /* Mt */
237 { termp_quote_pre
, termp_quote_post
}, /* Brq */
238 { termp_quote_pre
, termp_quote_post
}, /* Bro */
239 { NULL
, NULL
}, /* Brc */
240 { NULL
, termp____post
}, /* %C */
241 { termp_skip_pre
, NULL
}, /* Es */
242 { termp_quote_pre
, termp_quote_post
}, /* En */
243 { termp_xx_pre
, NULL
}, /* Dx */
244 { NULL
, termp____post
}, /* %Q */
245 { termp_sp_pre
, NULL
}, /* br */
246 { termp_sp_pre
, NULL
}, /* sp */
247 { NULL
, termp____post
}, /* %U */
248 { NULL
, NULL
}, /* Ta */
249 { termp_ll_pre
, NULL
}, /* ll */
254 terminal_mdoc(void *arg
, const struct mdoc
*mdoc
)
256 const struct roff_meta
*meta
;
260 p
= (struct termp
*)arg
;
263 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
264 p
->tabwidth
= term_len(p
, 5);
266 n
= mdoc_node(mdoc
)->child
;
267 meta
= mdoc_meta(mdoc
);
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
,
274 meta
, n
->child
->next
->child
);
281 if (p
->defindent
== 0)
283 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, meta
);
285 if (n
->tok
!= MDOC_Sh
)
287 print_mdoc_nodelist(p
, NULL
, 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
));
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 term_fontpush(p
, TERMFONT_BOLD
);
1055 term_word(p
, "\\-");
1057 if ( ! (n
->nchild
== 0 &&
1059 n
->next
->type
== ROFFT_TEXT
||
1060 n
->next
->flags
& MDOC_LINE
)))
1061 p
->flags
|= TERMP_NOSPACE
;
1067 termp__a_pre(DECL_ARGS
)
1070 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1071 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1072 term_word(p
, "and");
1078 termp_an_pre(DECL_ARGS
)
1081 if (n
->norm
->An
.auth
== AUTH_split
) {
1082 p
->flags
&= ~TERMP_NOSPLIT
;
1083 p
->flags
|= TERMP_SPLIT
;
1086 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1087 p
->flags
&= ~TERMP_SPLIT
;
1088 p
->flags
|= TERMP_NOSPLIT
;
1092 if (p
->flags
& TERMP_SPLIT
)
1095 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1096 p
->flags
|= TERMP_SPLIT
;
1102 termp_ns_pre(DECL_ARGS
)
1105 if ( ! (MDOC_LINE
& n
->flags
))
1106 p
->flags
|= TERMP_NOSPACE
;
1111 termp_rs_pre(DECL_ARGS
)
1114 if (SEC_SEE_ALSO
!= n
->sec
)
1116 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1122 termp_rv_pre(DECL_ARGS
)
1130 term_word(p
, "The");
1132 for (n
= n
->child
; n
; n
= n
->next
) {
1133 term_fontpush(p
, TERMFONT_BOLD
);
1134 term_word(p
, n
->string
);
1137 p
->flags
|= TERMP_NOSPACE
;
1140 if (n
->next
== NULL
)
1144 p
->flags
|= TERMP_NOSPACE
;
1147 if (n
->next
->next
== NULL
)
1148 term_word(p
, "and");
1152 term_word(p
, "functions return");
1154 term_word(p
, "function returns");
1156 term_word(p
, "the value\\~0 if successful;");
1158 term_word(p
, "Upon successful completion,"
1159 " the value\\~0 is returned;");
1161 term_word(p
, "otherwise the value\\~\\-1 is returned"
1162 " and the global variable");
1164 term_fontpush(p
, TERMFONT_UNDER
);
1165 term_word(p
, "errno");
1168 term_word(p
, "is set to indicate the error.");
1169 p
->flags
|= TERMP_SENTENCE
;
1175 termp_ex_pre(DECL_ARGS
)
1180 term_word(p
, "The");
1183 for (n
= n
->child
; n
; n
= n
->next
) {
1184 term_fontpush(p
, TERMFONT_BOLD
);
1185 term_word(p
, n
->string
);
1188 if (nchild
> 2 && n
->next
) {
1189 p
->flags
|= TERMP_NOSPACE
;
1193 if (n
->next
&& NULL
== n
->next
->next
)
1194 term_word(p
, "and");
1198 term_word(p
, "utilities exit\\~0");
1200 term_word(p
, "utility exits\\~0");
1202 term_word(p
, "on success, and\\~>0 if an error occurs.");
1204 p
->flags
|= TERMP_SENTENCE
;
1209 termp_nd_pre(DECL_ARGS
)
1212 if (n
->type
== ROFFT_BODY
)
1213 term_word(p
, "\\(en");
1218 termp_bl_pre(DECL_ARGS
)
1221 return(n
->type
!= ROFFT_HEAD
);
1225 termp_bl_post(DECL_ARGS
)
1228 if (n
->type
== ROFFT_BLOCK
)
1233 termp_xr_pre(DECL_ARGS
)
1236 if (NULL
== (n
= n
->child
))
1239 assert(n
->type
== ROFFT_TEXT
);
1240 term_word(p
, n
->string
);
1242 if (NULL
== (n
= n
->next
))
1245 p
->flags
|= TERMP_NOSPACE
;
1247 p
->flags
|= TERMP_NOSPACE
;
1249 assert(n
->type
== ROFFT_TEXT
);
1250 term_word(p
, n
->string
);
1252 p
->flags
|= TERMP_NOSPACE
;
1259 * This decides how to assert whitespace before any of the SYNOPSIS set
1260 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1264 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1267 * Obviously, if we're not in a SYNOPSIS or no prior macros
1268 * exist, do nothing.
1270 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1274 * If we're the second in a pair of like elements, emit our
1275 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1276 * case we soldier on.
1278 if (n
->prev
->tok
== n
->tok
&&
1279 MDOC_Ft
!= n
->tok
&&
1280 MDOC_Fo
!= n
->tok
&&
1281 MDOC_Fn
!= n
->tok
) {
1287 * If we're one of the SYNOPSIS set and non-like pair-wise after
1288 * another (or Fn/Fo, which we've let slip through) then assert
1289 * vertical space, else only newline and move on.
1291 switch (n
->prev
->tok
) {
1304 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1316 termp_vt_pre(DECL_ARGS
)
1319 if (n
->type
== ROFFT_ELEM
) {
1321 return(termp_under_pre(p
, pair
, meta
, n
));
1322 } else if (n
->type
== ROFFT_BLOCK
) {
1325 } else if (n
->type
== ROFFT_HEAD
)
1328 return(termp_under_pre(p
, pair
, meta
, n
));
1332 termp_bold_pre(DECL_ARGS
)
1335 term_fontpush(p
, TERMFONT_BOLD
);
1340 termp_fd_pre(DECL_ARGS
)
1344 return(termp_bold_pre(p
, pair
, meta
, n
));
1348 termp_fd_post(DECL_ARGS
)
1355 termp_sh_pre(DECL_ARGS
)
1361 * Vertical space before sections, except
1362 * when the previous section was empty.
1364 if (n
->prev
== NULL
||
1365 MDOC_Sh
!= n
->prev
->tok
||
1366 (n
->prev
->body
!= NULL
&&
1367 n
->prev
->body
->child
!= NULL
))
1371 term_fontpush(p
, TERMFONT_BOLD
);
1374 p
->offset
= term_len(p
, p
->defindent
);
1375 if (SEC_AUTHORS
== n
->sec
)
1376 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1385 termp_sh_post(DECL_ARGS
)
1402 termp_bt_pre(DECL_ARGS
)
1405 term_word(p
, "is currently in beta test.");
1406 p
->flags
|= TERMP_SENTENCE
;
1411 termp_lb_post(DECL_ARGS
)
1414 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1419 termp_ud_pre(DECL_ARGS
)
1422 term_word(p
, "currently under development.");
1423 p
->flags
|= TERMP_SENTENCE
;
1428 termp_d1_pre(DECL_ARGS
)
1431 if (n
->type
!= ROFFT_BLOCK
)
1434 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1439 termp_ft_pre(DECL_ARGS
)
1442 /* NB: MDOC_LINE does not effect this! */
1444 term_fontpush(p
, TERMFONT_UNDER
);
1449 termp_fn_pre(DECL_ARGS
)
1454 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1458 if (NULL
== (n
= n
->child
))
1462 rmargin
= p
->rmargin
;
1463 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1464 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1467 assert(n
->type
== ROFFT_TEXT
);
1468 term_fontpush(p
, TERMFONT_BOLD
);
1469 term_word(p
, n
->string
);
1474 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1475 p
->offset
= p
->rmargin
;
1476 p
->rmargin
= rmargin
;
1479 p
->flags
|= TERMP_NOSPACE
;
1481 p
->flags
|= TERMP_NOSPACE
;
1483 for (n
= n
->next
; n
; n
= n
->next
) {
1484 assert(n
->type
== ROFFT_TEXT
);
1485 term_fontpush(p
, TERMFONT_UNDER
);
1487 p
->flags
|= TERMP_NBRWORD
;
1488 term_word(p
, n
->string
);
1492 p
->flags
|= TERMP_NOSPACE
;
1497 p
->flags
|= TERMP_NOSPACE
;
1501 p
->flags
|= TERMP_NOSPACE
;
1510 termp_fa_pre(DECL_ARGS
)
1512 const struct roff_node
*nn
;
1514 if (n
->parent
->tok
!= MDOC_Fo
) {
1515 term_fontpush(p
, TERMFONT_UNDER
);
1519 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1520 term_fontpush(p
, TERMFONT_UNDER
);
1521 p
->flags
|= TERMP_NBRWORD
;
1522 term_word(p
, nn
->string
);
1525 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1526 p
->flags
|= TERMP_NOSPACE
;
1535 termp_bd_pre(DECL_ARGS
)
1537 size_t tabwidth
, lm
, len
, rm
, rmax
;
1538 struct roff_node
*nn
;
1541 if (n
->type
== ROFFT_BLOCK
) {
1542 print_bvspace(p
, n
, n
);
1544 } else if (n
->type
== ROFFT_HEAD
)
1547 /* Handle the -offset argument. */
1549 if (n
->norm
->Bd
.offs
== NULL
||
1550 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1552 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1553 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1554 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1555 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1557 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1558 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
1560 else if (offset
< SHRT_MAX
)
1561 p
->offset
+= offset
;
1565 * If -ragged or -filled are specified, the block does nothing
1566 * but change the indentation. If -unfilled or -literal are
1567 * specified, text is printed exactly as entered in the display:
1568 * for macro lines, a newline is appended to the line. Blank
1569 * lines are allowed.
1572 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1573 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1574 DISP_centered
!= n
->norm
->Bd
.type
)
1577 tabwidth
= p
->tabwidth
;
1578 if (DISP_literal
== n
->norm
->Bd
.type
)
1579 p
->tabwidth
= term_len(p
, 8);
1583 rmax
= p
->maxrmargin
;
1584 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1586 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1587 if (DISP_centered
== n
->norm
->Bd
.type
) {
1588 if (nn
->type
== ROFFT_TEXT
) {
1589 len
= term_strlen(p
, nn
->string
);
1590 p
->offset
= len
>= rm
? 0 :
1591 lm
+ len
>= rm
? rm
- len
:
1592 (lm
+ rm
- len
) / 2;
1596 print_mdoc_node(p
, pair
, meta
, nn
);
1598 * If the printed node flushes its own line, then we
1599 * needn't do it here as well. This is hacky, but the
1600 * notion of selective eoln whitespace is pretty dumb
1601 * anyway, so don't sweat it.
1623 if (p
->flags
& TERMP_NONEWLINE
||
1624 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1627 p
->flags
|= TERMP_NOSPACE
;
1630 p
->tabwidth
= tabwidth
;
1632 p
->maxrmargin
= rmax
;
1637 termp_bd_post(DECL_ARGS
)
1641 if (n
->type
!= ROFFT_BODY
)
1645 rmax
= p
->maxrmargin
;
1647 if (DISP_literal
== n
->norm
->Bd
.type
||
1648 DISP_unfilled
== n
->norm
->Bd
.type
)
1649 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1651 p
->flags
|= TERMP_NOSPACE
;
1655 p
->maxrmargin
= rmax
;
1659 termp_bx_pre(DECL_ARGS
)
1662 if (NULL
!= (n
= n
->child
)) {
1663 term_word(p
, n
->string
);
1664 p
->flags
|= TERMP_NOSPACE
;
1665 term_word(p
, "BSD");
1667 term_word(p
, "BSD");
1671 if (NULL
!= (n
= n
->next
)) {
1672 p
->flags
|= TERMP_NOSPACE
;
1674 p
->flags
|= TERMP_NOSPACE
;
1675 term_word(p
, n
->string
);
1682 termp_xx_pre(DECL_ARGS
)
1715 p
->flags
|= TERMP_KEEP
;
1716 term_word(p
, n
->child
->string
);
1723 termp_pf_post(DECL_ARGS
)
1726 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1727 p
->flags
|= TERMP_NOSPACE
;
1731 termp_ss_pre(DECL_ARGS
)
1741 term_fontpush(p
, TERMFONT_BOLD
);
1742 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1745 p
->offset
= term_len(p
, p
->defindent
);
1755 termp_ss_post(DECL_ARGS
)
1758 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1763 termp_cd_pre(DECL_ARGS
)
1767 term_fontpush(p
, TERMFONT_BOLD
);
1772 termp_in_pre(DECL_ARGS
)
1777 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1778 term_fontpush(p
, TERMFONT_BOLD
);
1779 term_word(p
, "#include");
1783 term_fontpush(p
, TERMFONT_UNDER
);
1786 p
->flags
|= TERMP_NOSPACE
;
1791 termp_in_post(DECL_ARGS
)
1794 if (MDOC_SYNPRETTY
& n
->flags
)
1795 term_fontpush(p
, TERMFONT_BOLD
);
1797 p
->flags
|= TERMP_NOSPACE
;
1800 if (MDOC_SYNPRETTY
& n
->flags
)
1805 termp_sp_pre(DECL_ARGS
)
1813 if ( ! a2roffsu(n
->child
->string
, &su
, SCALE_VS
))
1815 len
= term_vspan(p
, &su
);
1832 for (i
= 0; i
< len
; i
++)
1839 termp_skip_pre(DECL_ARGS
)
1846 termp_quote_pre(DECL_ARGS
)
1849 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1856 term_word(p
, n
->nchild
== 1 &&
1857 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1876 term_word(p
, "\\(Lq");
1879 if (NULL
== n
->norm
->Es
||
1880 NULL
== n
->norm
->Es
->child
)
1882 term_word(p
, n
->norm
->Es
->child
->string
);
1901 term_word(p
, "\\(oq");
1908 p
->flags
|= TERMP_NOSPACE
;
1913 termp_quote_post(DECL_ARGS
)
1916 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1919 p
->flags
|= TERMP_NOSPACE
;
1925 term_word(p
, n
->nchild
== 1 &&
1926 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1945 term_word(p
, "\\(Rq");
1948 if (n
->norm
->Es
== NULL
||
1949 n
->norm
->Es
->child
== NULL
||
1950 n
->norm
->Es
->child
->next
== NULL
)
1951 p
->flags
&= ~TERMP_NOSPACE
;
1953 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1972 term_word(p
, "\\(cq");
1981 termp_eo_pre(DECL_ARGS
)
1984 if (n
->type
!= ROFFT_BODY
)
1987 if (n
->end
== ENDBODY_NOT
&&
1988 n
->parent
->head
->child
== NULL
&&
1990 n
->child
->end
!= ENDBODY_NOT
)
1991 term_word(p
, "\\&");
1992 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1993 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1994 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1995 p
->flags
|= TERMP_NOSPACE
;
2001 termp_eo_post(DECL_ARGS
)
2005 if (n
->type
!= ROFFT_BODY
)
2008 if (n
->end
!= ENDBODY_NOT
) {
2009 p
->flags
&= ~TERMP_NOSPACE
;
2013 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
2014 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
2017 p
->flags
|= TERMP_NOSPACE
;
2018 else if ( ! (body
|| tail
))
2019 term_word(p
, "\\&");
2021 p
->flags
&= ~TERMP_NOSPACE
;
2025 termp_fo_pre(DECL_ARGS
)
2030 pretty
= MDOC_SYNPRETTY
& n
->flags
;
2032 if (n
->type
== ROFFT_BLOCK
) {
2035 } else if (n
->type
== ROFFT_BODY
) {
2037 rmargin
= p
->rmargin
;
2038 p
->rmargin
= p
->offset
+ term_len(p
, 4);
2039 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
2042 p
->flags
|= TERMP_NOSPACE
;
2044 p
->flags
|= TERMP_NOSPACE
;
2047 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2049 p
->offset
= p
->rmargin
;
2050 p
->rmargin
= rmargin
;
2055 if (NULL
== n
->child
)
2058 /* XXX: we drop non-initial arguments as per groff. */
2060 assert(n
->child
->string
);
2061 term_fontpush(p
, TERMFONT_BOLD
);
2062 term_word(p
, n
->child
->string
);
2067 termp_fo_post(DECL_ARGS
)
2070 if (n
->type
!= ROFFT_BODY
)
2073 p
->flags
|= TERMP_NOSPACE
;
2076 if (MDOC_SYNPRETTY
& n
->flags
) {
2077 p
->flags
|= TERMP_NOSPACE
;
2084 termp_bf_pre(DECL_ARGS
)
2087 if (n
->type
== ROFFT_HEAD
)
2089 else if (n
->type
!= ROFFT_BODY
)
2092 if (FONT_Em
== n
->norm
->Bf
.font
)
2093 term_fontpush(p
, TERMFONT_UNDER
);
2094 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2095 term_fontpush(p
, TERMFONT_BOLD
);
2097 term_fontpush(p
, TERMFONT_NONE
);
2103 termp_sm_pre(DECL_ARGS
)
2106 if (NULL
== n
->child
)
2107 p
->flags
^= TERMP_NONOSPACE
;
2108 else if (0 == strcmp("on", n
->child
->string
))
2109 p
->flags
&= ~TERMP_NONOSPACE
;
2111 p
->flags
|= TERMP_NONOSPACE
;
2113 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2114 p
->flags
&= ~TERMP_NOSPACE
;
2120 termp_ap_pre(DECL_ARGS
)
2123 p
->flags
|= TERMP_NOSPACE
;
2125 p
->flags
|= TERMP_NOSPACE
;
2130 termp____post(DECL_ARGS
)
2134 * Handle lists of authors. In general, print each followed by
2135 * a comma. Don't print the comma if there are only two
2138 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2139 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2140 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2145 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2148 p
->flags
|= TERMP_NOSPACE
;
2149 if (NULL
== n
->next
) {
2151 p
->flags
|= TERMP_SENTENCE
;
2157 termp_li_pre(DECL_ARGS
)
2160 term_fontpush(p
, TERMFONT_NONE
);
2165 termp_lk_pre(DECL_ARGS
)
2167 const struct roff_node
*link
, *descr
;
2169 if (NULL
== (link
= n
->child
))
2172 if (NULL
!= (descr
= link
->next
)) {
2173 term_fontpush(p
, TERMFONT_UNDER
);
2174 while (NULL
!= descr
) {
2175 term_word(p
, descr
->string
);
2176 descr
= descr
->next
;
2178 p
->flags
|= TERMP_NOSPACE
;
2183 term_fontpush(p
, TERMFONT_BOLD
);
2184 term_word(p
, link
->string
);
2191 termp_bk_pre(DECL_ARGS
)
2200 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2201 p
->flags
|= TERMP_PREKEEP
;
2212 termp_bk_post(DECL_ARGS
)
2215 if (n
->type
== ROFFT_BODY
)
2216 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2220 termp__t_post(DECL_ARGS
)
2224 * If we're in an `Rs' and there's a journal present, then quote
2225 * us instead of underlining us (for disambiguation).
2227 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2228 n
->parent
->norm
->Rs
.quote_T
)
2229 termp_quote_post(p
, pair
, meta
, n
);
2231 termp____post(p
, pair
, meta
, n
);
2235 termp__t_pre(DECL_ARGS
)
2239 * If we're in an `Rs' and there's a journal present, then quote
2240 * us instead of underlining us (for disambiguation).
2242 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2243 n
->parent
->norm
->Rs
.quote_T
)
2244 return(termp_quote_pre(p
, pair
, meta
, n
));
2246 term_fontpush(p
, TERMFONT_UNDER
);
2251 termp_under_pre(DECL_ARGS
)
2254 term_fontpush(p
, TERMFONT_UNDER
);