]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.296 2014/11/28 16:02:52 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012, 2013, 2014 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>
31 #include "mandoc_aux.h"
38 struct termpair
*ppair
;
42 #define DECL_ARGS struct termp *p, \
43 struct termpair *pair, \
44 const struct mdoc_meta *meta, \
48 int (*pre
)(DECL_ARGS
);
49 void (*post
)(DECL_ARGS
);
52 static size_t a2width(const struct termp
*, const char *);
53 static size_t a2height(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_fd_post(DECL_ARGS
);
71 static void termp_fo_post(DECL_ARGS
);
72 static void termp_in_post(DECL_ARGS
);
73 static void termp_it_post(DECL_ARGS
);
74 static void termp_lb_post(DECL_ARGS
);
75 static void termp_nm_post(DECL_ARGS
);
76 static void termp_pf_post(DECL_ARGS
);
77 static void termp_quote_post(DECL_ARGS
);
78 static void termp_sh_post(DECL_ARGS
);
79 static void termp_ss_post(DECL_ARGS
);
81 static int termp__a_pre(DECL_ARGS
);
82 static int termp__t_pre(DECL_ARGS
);
83 static int termp_an_pre(DECL_ARGS
);
84 static int termp_ap_pre(DECL_ARGS
);
85 static int termp_bd_pre(DECL_ARGS
);
86 static int termp_bf_pre(DECL_ARGS
);
87 static int termp_bk_pre(DECL_ARGS
);
88 static int termp_bl_pre(DECL_ARGS
);
89 static int termp_bold_pre(DECL_ARGS
);
90 static int termp_bt_pre(DECL_ARGS
);
91 static int termp_bx_pre(DECL_ARGS
);
92 static int termp_cd_pre(DECL_ARGS
);
93 static int termp_d1_pre(DECL_ARGS
);
94 static int termp_ex_pre(DECL_ARGS
);
95 static int termp_fa_pre(DECL_ARGS
);
96 static int termp_fd_pre(DECL_ARGS
);
97 static int termp_fl_pre(DECL_ARGS
);
98 static int termp_fn_pre(DECL_ARGS
);
99 static int termp_fo_pre(DECL_ARGS
);
100 static int termp_ft_pre(DECL_ARGS
);
101 static int termp_in_pre(DECL_ARGS
);
102 static int termp_it_pre(DECL_ARGS
);
103 static int termp_li_pre(DECL_ARGS
);
104 static int termp_ll_pre(DECL_ARGS
);
105 static int termp_lk_pre(DECL_ARGS
);
106 static int termp_nd_pre(DECL_ARGS
);
107 static int termp_nm_pre(DECL_ARGS
);
108 static int termp_ns_pre(DECL_ARGS
);
109 static int termp_quote_pre(DECL_ARGS
);
110 static int termp_rs_pre(DECL_ARGS
);
111 static int termp_rv_pre(DECL_ARGS
);
112 static int termp_sh_pre(DECL_ARGS
);
113 static int termp_skip_pre(DECL_ARGS
);
114 static int termp_sm_pre(DECL_ARGS
);
115 static int termp_sp_pre(DECL_ARGS
);
116 static int termp_ss_pre(DECL_ARGS
);
117 static int termp_under_pre(DECL_ARGS
);
118 static int termp_ud_pre(DECL_ARGS
);
119 static int termp_vt_pre(DECL_ARGS
);
120 static int termp_xr_pre(DECL_ARGS
);
121 static int termp_xx_pre(DECL_ARGS
);
123 static const struct termact termacts
[MDOC_MAX
] = {
124 { termp_ap_pre
, NULL
}, /* Ap */
125 { NULL
, NULL
}, /* Dd */
126 { NULL
, NULL
}, /* Dt */
127 { NULL
, NULL
}, /* Os */
128 { termp_sh_pre
, termp_sh_post
}, /* Sh */
129 { termp_ss_pre
, termp_ss_post
}, /* Ss */
130 { termp_sp_pre
, NULL
}, /* Pp */
131 { termp_d1_pre
, termp_bl_post
}, /* D1 */
132 { termp_d1_pre
, termp_bl_post
}, /* Dl */
133 { termp_bd_pre
, termp_bd_post
}, /* Bd */
134 { NULL
, NULL
}, /* Ed */
135 { termp_bl_pre
, termp_bl_post
}, /* Bl */
136 { NULL
, NULL
}, /* El */
137 { termp_it_pre
, termp_it_post
}, /* It */
138 { termp_under_pre
, NULL
}, /* Ad */
139 { termp_an_pre
, NULL
}, /* An */
140 { termp_under_pre
, NULL
}, /* Ar */
141 { termp_cd_pre
, NULL
}, /* Cd */
142 { termp_bold_pre
, NULL
}, /* Cm */
143 { NULL
, NULL
}, /* Dv */
144 { NULL
, NULL
}, /* Er */
145 { NULL
, NULL
}, /* Ev */
146 { termp_ex_pre
, NULL
}, /* Ex */
147 { termp_fa_pre
, NULL
}, /* Fa */
148 { termp_fd_pre
, termp_fd_post
}, /* Fd */
149 { termp_fl_pre
, NULL
}, /* Fl */
150 { termp_fn_pre
, NULL
}, /* Fn */
151 { termp_ft_pre
, NULL
}, /* Ft */
152 { termp_bold_pre
, NULL
}, /* Ic */
153 { termp_in_pre
, termp_in_post
}, /* In */
154 { termp_li_pre
, NULL
}, /* Li */
155 { termp_nd_pre
, NULL
}, /* Nd */
156 { termp_nm_pre
, termp_nm_post
}, /* Nm */
157 { termp_quote_pre
, termp_quote_post
}, /* Op */
158 { termp_ft_pre
, NULL
}, /* Ot */
159 { termp_under_pre
, NULL
}, /* Pa */
160 { termp_rv_pre
, NULL
}, /* Rv */
161 { NULL
, NULL
}, /* St */
162 { termp_under_pre
, NULL
}, /* Va */
163 { termp_vt_pre
, NULL
}, /* Vt */
164 { termp_xr_pre
, NULL
}, /* Xr */
165 { termp__a_pre
, termp____post
}, /* %A */
166 { termp_under_pre
, termp____post
}, /* %B */
167 { NULL
, termp____post
}, /* %D */
168 { termp_under_pre
, termp____post
}, /* %I */
169 { termp_under_pre
, termp____post
}, /* %J */
170 { NULL
, termp____post
}, /* %N */
171 { NULL
, termp____post
}, /* %O */
172 { NULL
, termp____post
}, /* %P */
173 { NULL
, termp____post
}, /* %R */
174 { termp__t_pre
, termp__t_post
}, /* %T */
175 { NULL
, termp____post
}, /* %V */
176 { NULL
, NULL
}, /* Ac */
177 { termp_quote_pre
, termp_quote_post
}, /* Ao */
178 { termp_quote_pre
, termp_quote_post
}, /* Aq */
179 { NULL
, NULL
}, /* At */
180 { NULL
, NULL
}, /* Bc */
181 { termp_bf_pre
, NULL
}, /* Bf */
182 { termp_quote_pre
, termp_quote_post
}, /* Bo */
183 { termp_quote_pre
, termp_quote_post
}, /* Bq */
184 { termp_xx_pre
, NULL
}, /* Bsx */
185 { termp_bx_pre
, NULL
}, /* Bx */
186 { termp_skip_pre
, NULL
}, /* Db */
187 { NULL
, NULL
}, /* Dc */
188 { termp_quote_pre
, termp_quote_post
}, /* Do */
189 { termp_quote_pre
, termp_quote_post
}, /* Dq */
190 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
191 { NULL
, NULL
}, /* Ef */
192 { termp_under_pre
, NULL
}, /* Em */
193 { termp_quote_pre
, termp_quote_post
}, /* Eo */
194 { termp_xx_pre
, NULL
}, /* Fx */
195 { termp_bold_pre
, NULL
}, /* Ms */
196 { termp_li_pre
, NULL
}, /* No */
197 { termp_ns_pre
, NULL
}, /* Ns */
198 { termp_xx_pre
, NULL
}, /* Nx */
199 { termp_xx_pre
, NULL
}, /* Ox */
200 { NULL
, NULL
}, /* Pc */
201 { NULL
, termp_pf_post
}, /* Pf */
202 { termp_quote_pre
, termp_quote_post
}, /* Po */
203 { termp_quote_pre
, termp_quote_post
}, /* Pq */
204 { NULL
, NULL
}, /* Qc */
205 { termp_quote_pre
, termp_quote_post
}, /* Ql */
206 { termp_quote_pre
, termp_quote_post
}, /* Qo */
207 { termp_quote_pre
, termp_quote_post
}, /* Qq */
208 { NULL
, NULL
}, /* Re */
209 { termp_rs_pre
, NULL
}, /* Rs */
210 { NULL
, NULL
}, /* Sc */
211 { termp_quote_pre
, termp_quote_post
}, /* So */
212 { termp_quote_pre
, termp_quote_post
}, /* Sq */
213 { termp_sm_pre
, NULL
}, /* Sm */
214 { termp_under_pre
, NULL
}, /* Sx */
215 { termp_bold_pre
, NULL
}, /* Sy */
216 { NULL
, NULL
}, /* Tn */
217 { termp_xx_pre
, NULL
}, /* Ux */
218 { NULL
, NULL
}, /* Xc */
219 { NULL
, NULL
}, /* Xo */
220 { termp_fo_pre
, termp_fo_post
}, /* Fo */
221 { NULL
, NULL
}, /* Fc */
222 { termp_quote_pre
, termp_quote_post
}, /* Oo */
223 { NULL
, NULL
}, /* Oc */
224 { termp_bk_pre
, termp_bk_post
}, /* Bk */
225 { NULL
, NULL
}, /* Ek */
226 { termp_bt_pre
, NULL
}, /* Bt */
227 { NULL
, NULL
}, /* Hf */
228 { termp_under_pre
, NULL
}, /* Fr */
229 { termp_ud_pre
, NULL
}, /* Ud */
230 { NULL
, termp_lb_post
}, /* Lb */
231 { termp_sp_pre
, NULL
}, /* Lp */
232 { termp_lk_pre
, NULL
}, /* Lk */
233 { termp_under_pre
, NULL
}, /* Mt */
234 { termp_quote_pre
, termp_quote_post
}, /* Brq */
235 { termp_quote_pre
, termp_quote_post
}, /* Bro */
236 { NULL
, NULL
}, /* Brc */
237 { NULL
, termp____post
}, /* %C */
238 { termp_skip_pre
, NULL
}, /* Es */
239 { termp_quote_pre
, termp_quote_post
}, /* En */
240 { termp_xx_pre
, NULL
}, /* Dx */
241 { NULL
, termp____post
}, /* %Q */
242 { termp_sp_pre
, NULL
}, /* br */
243 { termp_sp_pre
, NULL
}, /* sp */
244 { NULL
, termp____post
}, /* %U */
245 { NULL
, NULL
}, /* Ta */
246 { termp_ll_pre
, NULL
}, /* ll */
251 terminal_mdoc(void *arg
, const struct mdoc
*mdoc
)
253 const struct mdoc_meta
*meta
;
257 p
= (struct termp
*)arg
;
260 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
261 p
->tabwidth
= term_len(p
, 5);
263 n
= mdoc_node(mdoc
)->child
;
264 meta
= mdoc_meta(mdoc
);
266 if (p
->synopsisonly
) {
268 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
269 if (n
->child
->next
->child
!= NULL
)
270 print_mdoc_nodelist(p
, NULL
,
271 meta
, n
->child
->next
->child
);
278 if (p
->defindent
== 0)
280 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, meta
);
282 if (n
->tok
!= MDOC_Sh
)
284 print_mdoc_nodelist(p
, NULL
, meta
, n
);
291 print_mdoc_nodelist(DECL_ARGS
)
294 print_mdoc_node(p
, pair
, meta
, n
);
296 print_mdoc_nodelist(p
, pair
, meta
, n
->next
);
300 print_mdoc_node(DECL_ARGS
)
303 struct termpair npair
;
304 size_t offset
, rmargin
;
308 rmargin
= p
->rmargin
;
309 n
->prev_font
= term_fontq(p
);
311 memset(&npair
, 0, sizeof(struct termpair
));
315 * Keeps only work until the end of a line. If a keep was
316 * invoked in a prior line, revert it to PREKEEP.
319 if (TERMP_KEEP
& p
->flags
) {
320 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
321 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
322 p
->flags
&= ~TERMP_KEEP
;
323 p
->flags
|= TERMP_PREKEEP
;
328 * After the keep flags have been set up, we may now
329 * produce output. Note that some pre-handlers do so.
334 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
336 if (MDOC_DELIMC
& n
->flags
)
337 p
->flags
|= TERMP_NOSPACE
;
338 term_word(p
, n
->string
);
339 if (MDOC_DELIMO
& n
->flags
)
340 p
->flags
|= TERMP_NOSPACE
;
343 if ( ! (n
->flags
& MDOC_LINE
))
344 p
->flags
|= TERMP_NOSPACE
;
346 if (n
->next
!= NULL
&& ! (n
->next
->flags
& MDOC_LINE
))
347 p
->flags
|= TERMP_NOSPACE
;
350 term_tbl(p
, n
->span
);
353 if (termacts
[n
->tok
].pre
&&
354 (n
->end
== ENDBODY_NOT
|| n
->nchild
))
355 chld
= (*termacts
[n
->tok
].pre
)
356 (p
, &npair
, meta
, n
);
360 if (chld
&& n
->child
)
361 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
364 (ENDBODY_NOT
== n
->end
? n
: n
->pending
)->prev_font
);
374 if ( ! termacts
[n
->tok
].post
|| MDOC_ENDED
& n
->flags
)
376 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
379 * Explicit end tokens not only call the post
380 * handler, but also tell the respective block
381 * that it must not call the post handler again.
383 if (ENDBODY_NOT
!= n
->end
)
384 n
->pending
->flags
|= MDOC_ENDED
;
387 * End of line terminating an implicit block
388 * while an explicit block is still open.
389 * Continue the explicit block without spacing.
391 if (ENDBODY_NOSPACE
== n
->end
)
392 p
->flags
|= TERMP_NOSPACE
;
396 if (MDOC_EOS
& n
->flags
)
397 p
->flags
|= TERMP_SENTENCE
;
399 if (MDOC_ll
!= n
->tok
) {
401 p
->rmargin
= rmargin
;
406 print_mdoc_foot(struct termp
*p
, const void *arg
)
408 const struct mdoc_meta
*meta
;
411 meta
= (const struct mdoc_meta
*)arg
;
413 term_fontrepl(p
, TERMFONT_NONE
);
416 * Output the footer in new-groff style, that is, three columns
417 * with the middle being the manual date and flanking columns
418 * being the operating system:
426 sz
= term_strlen(p
, meta
->date
);
427 p
->rmargin
= p
->maxrmargin
> sz
?
428 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
430 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
432 term_word(p
, meta
->os
);
435 p
->offset
= p
->rmargin
;
436 sz
= term_strlen(p
, meta
->os
);
437 p
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
438 p
->flags
|= TERMP_NOSPACE
;
440 term_word(p
, meta
->date
);
443 p
->offset
= p
->rmargin
;
444 p
->rmargin
= p
->maxrmargin
;
446 p
->flags
&= ~TERMP_NOBREAK
;
447 p
->flags
|= TERMP_NOSPACE
;
449 term_word(p
, meta
->os
);
453 p
->rmargin
= p
->maxrmargin
;
458 print_mdoc_head(struct termp
*p
, const void *arg
)
460 const struct mdoc_meta
*meta
;
461 char *volume
, *title
;
462 size_t vollen
, titlen
;
464 meta
= (const struct mdoc_meta
*)arg
;
467 * The header is strange. It has three components, which are
468 * really two with the first duplicated. It goes like this:
470 * IDENTIFIER TITLE IDENTIFIER
472 * The IDENTIFIER is NAME(SECTION), which is the command-name
473 * (if given, or "unknown" if not) followed by the manual page
474 * section. These are given in `Dt'. The TITLE is a free-form
475 * string depending on the manual volume. If not specified, it
476 * switches on the manual section.
480 if (NULL
== meta
->arch
)
481 volume
= mandoc_strdup(meta
->vol
);
483 mandoc_asprintf(&volume
, "%s (%s)",
484 meta
->vol
, meta
->arch
);
485 vollen
= term_strlen(p
, volume
);
487 if (NULL
== meta
->msec
)
488 title
= mandoc_strdup(meta
->title
);
490 mandoc_asprintf(&title
, "%s(%s)",
491 meta
->title
, meta
->msec
);
492 titlen
= term_strlen(p
, title
);
494 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
497 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
498 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
499 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
504 p
->flags
|= TERMP_NOSPACE
;
505 p
->offset
= p
->rmargin
;
506 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
507 p
->maxrmargin
- titlen
: p
->maxrmargin
;
509 term_word(p
, volume
);
512 p
->flags
&= ~TERMP_NOBREAK
;
514 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
515 p
->flags
|= TERMP_NOSPACE
;
516 p
->offset
= p
->rmargin
;
517 p
->rmargin
= p
->maxrmargin
;
522 p
->flags
&= ~TERMP_NOSPACE
;
524 p
->rmargin
= p
->maxrmargin
;
530 a2height(const struct termp
*p
, const char *v
)
536 if ( ! a2roffsu(v
, &su
, SCALE_VS
))
537 SCALE_VS_INIT(&su
, atoi(v
));
539 return(term_vspan(p
, &su
));
543 a2width(const struct termp
*p
, const char *v
)
548 if ( ! a2roffsu(v
, &su
, SCALE_MAX
)) {
549 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
550 su
.scale
/= term_strlen(p
, "0");
553 return(term_hspan(p
, &su
));
557 * Determine how much space to print out before block elements of `It'
558 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
562 print_bvspace(struct termp
*p
,
563 const struct mdoc_node
*bl
,
564 const struct mdoc_node
*n
)
566 const struct mdoc_node
*nn
;
572 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
574 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
577 /* Do not vspace directly after Ss/Sh. */
580 while (nn
->prev
== NULL
) {
583 if (nn
->type
== MDOC_ROOT
)
585 } while (nn
->type
!= MDOC_BLOCK
);
586 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
588 if (nn
->tok
== MDOC_It
&&
589 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
593 /* A `-column' does not assert vspace within the list. */
595 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
596 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
599 /* A `-diag' without body does not vspace. */
601 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
602 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
603 assert(n
->prev
->body
);
604 if (NULL
== n
->prev
->body
->child
)
613 termp_ll_pre(DECL_ARGS
)
616 term_setwidth(p
, n
->nchild
? n
->child
->string
: NULL
);
621 termp_it_pre(DECL_ARGS
)
623 const struct mdoc_node
*bl
, *nn
;
626 size_t width
, offset
, ncols
, dcol
;
629 if (MDOC_BLOCK
== n
->type
) {
630 print_bvspace(p
, n
->parent
->parent
, n
);
634 bl
= n
->parent
->parent
->parent
;
635 type
= bl
->norm
->Bl
.type
;
638 * First calculate width and offset. This is pretty easy unless
639 * we're a -column list, in which case all prior columns must
645 if (bl
->norm
->Bl
.offs
)
646 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
650 if (MDOC_HEAD
== n
->type
)
654 * Imitate groff's column handling:
655 * - For each earlier column, add its width.
656 * - For less than 5 columns, add four more blanks per
658 * - For exactly 5 columns, add three more blank per
660 * - For more than 5 columns, add only one column.
662 ncols
= bl
->norm
->Bl
.ncols
;
663 dcol
= ncols
< 5 ? term_len(p
, 4) :
664 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
667 * Calculate the offset by applying all prior MDOC_BODY,
668 * so we stop at the MDOC_HEAD (NULL == nn->prev).
671 for (i
= 0, nn
= n
->prev
;
672 nn
->prev
&& i
< (int)ncols
;
674 offset
+= dcol
+ a2width(p
,
675 bl
->norm
->Bl
.cols
[i
]);
678 * When exceeding the declared number of columns, leave
679 * the remaining widths at 0. This will later be
680 * adjusted to the default width of 10, or, for the last
681 * column, stretched to the right margin.
687 * Use the declared column widths, extended as explained
688 * in the preceding paragraph.
690 width
= a2width(p
, bl
->norm
->Bl
.cols
[i
]) + dcol
;
693 if (NULL
== bl
->norm
->Bl
.width
)
697 * Note: buffer the width by 2, which is groff's magic
698 * number for buffering single arguments. See the above
699 * handling for column for how this changes.
701 assert(bl
->norm
->Bl
.width
);
702 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
707 * List-type can override the width in the case of fixed-head
708 * values (bullet, dash/hyphen, enum). Tags need a non-zero
720 if (width
< term_len(p
, 2))
721 width
= term_len(p
, 2);
725 width
= term_len(p
, 8);
731 width
= term_len(p
, 10);
738 * Whitespace control. Inset bodies need an initial space,
739 * while diagonal bodies need two.
742 p
->flags
|= TERMP_NOSPACE
;
746 if (MDOC_BODY
== n
->type
)
747 term_word(p
, "\\ \\ ");
750 if (MDOC_BODY
== n
->type
&& n
->parent
->head
->nchild
)
757 p
->flags
|= TERMP_NOSPACE
;
761 if (MDOC_HEAD
== n
->type
)
762 term_fontpush(p
, TERMFONT_BOLD
);
769 * Pad and break control. This is the tricky part. These flags
770 * are documented in term_flushln() in term.c. Note that we're
771 * going to unset all of these flags in termp_it_post() when we
778 * Weird special case.
779 * Very narrow enum lists actually hang.
781 if (width
== term_len(p
, 2))
782 p
->flags
|= TERMP_HANG
;
789 if (MDOC_HEAD
!= n
->type
)
791 p
->flags
|= TERMP_NOBREAK
;
795 if (MDOC_HEAD
!= n
->type
)
799 * This is ugly. If `-hang' is specified and the body
800 * is a `Bl' or `Bd', then we want basically to nullify
801 * the "overstep" effect in term_flushln() and treat
802 * this as a `-ohang' list instead.
804 if (NULL
!= n
->next
&&
805 NULL
!= n
->next
->child
&&
806 (MDOC_Bl
== n
->next
->child
->tok
||
807 MDOC_Bd
== n
->next
->child
->tok
))
810 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
814 if (MDOC_HEAD
!= n
->type
)
817 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
820 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
821 p
->flags
|= TERMP_DANGLE
;
824 if (MDOC_HEAD
== n
->type
)
827 if (NULL
== n
->next
) {
828 p
->flags
&= ~TERMP_NOBREAK
;
831 p
->flags
|= TERMP_NOBREAK
;
837 if (MDOC_HEAD
!= n
->type
)
839 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
847 * Margin control. Set-head-width lists have their right
848 * margins shortened. The body for these lists has the offset
849 * necessarily lengthened. Everybody gets the offset.
857 * Same stipulation as above, regarding `-hang'. We
858 * don't want to recalculate rmargin and offsets when
859 * using `Bd' or `Bl' within `-hang' overstep lists.
861 if (MDOC_HEAD
== n
->type
&&
863 NULL
!= n
->next
->child
&&
864 (MDOC_Bl
== n
->next
->child
->tok
||
865 MDOC_Bd
== n
->next
->child
->tok
))
878 if (MDOC_HEAD
== n
->type
)
879 p
->rmargin
= p
->offset
+ width
;
885 p
->rmargin
= p
->offset
+ width
;
887 * XXX - this behaviour is not documented: the
888 * right-most column is filled to the right margin.
890 if (MDOC_HEAD
== n
->type
)
892 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
893 p
->rmargin
= p
->maxrmargin
;
900 * The dash, hyphen, bullet and enum lists all have a special
901 * HEAD character (temporarily bold, in some cases).
904 if (MDOC_HEAD
== n
->type
)
907 term_fontpush(p
, TERMFONT_BOLD
);
908 term_word(p
, "\\[bu]");
914 term_fontpush(p
, TERMFONT_BOLD
);
915 term_word(p
, "\\(hy");
919 (pair
->ppair
->ppair
->count
)++;
920 (void)snprintf(buf
, sizeof(buf
), "%d.",
921 pair
->ppair
->ppair
->count
);
929 * If we're not going to process our children, indicate so here.
942 if (MDOC_HEAD
== n
->type
)
946 if (MDOC_HEAD
== n
->type
)
957 termp_it_post(DECL_ARGS
)
961 if (MDOC_BLOCK
== n
->type
)
964 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
972 if (MDOC_BODY
== n
->type
)
976 if (MDOC_BODY
== n
->type
)
985 * Now that our output is flushed, we can reset our tags. Since
986 * only `It' sets these flags, we're free to assume that nobody
987 * has munged them in the meanwhile.
990 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
991 TERMP_DANGLE
| TERMP_HANG
);
996 termp_nm_pre(DECL_ARGS
)
1000 if (MDOC_BLOCK
== n
->type
) {
1001 p
->flags
|= TERMP_PREKEEP
;
1005 if (MDOC_BODY
== n
->type
) {
1006 if (NULL
== n
->child
)
1008 p
->flags
|= TERMP_NOSPACE
;
1010 if (n
->prev
->child
!= NULL
)
1011 cp
= n
->prev
->child
->string
;
1015 p
->offset
+= term_len(p
, 6);
1017 p
->offset
+= term_len(p
, 1) + term_strlen(p
, cp
);
1021 if (NULL
== n
->child
&& NULL
== meta
->name
)
1024 if (MDOC_HEAD
== n
->type
)
1025 synopsis_pre(p
, n
->parent
);
1027 if (MDOC_HEAD
== n
->type
&&
1028 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1029 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1031 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1032 if (NULL
== n
->child
) {
1033 p
->rmargin
+= term_strlen(p
, meta
->name
);
1034 } else if (MDOC_TEXT
== n
->child
->type
) {
1035 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1037 p
->flags
|= TERMP_HANG
;
1039 p
->rmargin
+= term_len(p
, 5);
1040 p
->flags
|= TERMP_HANG
;
1044 term_fontpush(p
, TERMFONT_BOLD
);
1045 if (NULL
== n
->child
)
1046 term_word(p
, meta
->name
);
1051 termp_nm_post(DECL_ARGS
)
1054 if (MDOC_BLOCK
== n
->type
) {
1055 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1056 } else if (MDOC_HEAD
== n
->type
&&
1057 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1059 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1061 } else if (MDOC_BODY
== n
->type
&& n
->child
)
1066 termp_fl_pre(DECL_ARGS
)
1069 term_fontpush(p
, TERMFONT_BOLD
);
1070 term_word(p
, "\\-");
1072 if ( ! (n
->nchild
== 0 &&
1074 n
->next
->type
== MDOC_TEXT
||
1075 n
->next
->flags
& MDOC_LINE
)))
1076 p
->flags
|= TERMP_NOSPACE
;
1082 termp__a_pre(DECL_ARGS
)
1085 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1086 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1087 term_word(p
, "and");
1093 termp_an_pre(DECL_ARGS
)
1096 if (n
->norm
->An
.auth
== AUTH_split
) {
1097 p
->flags
&= ~TERMP_NOSPLIT
;
1098 p
->flags
|= TERMP_SPLIT
;
1101 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1102 p
->flags
&= ~TERMP_SPLIT
;
1103 p
->flags
|= TERMP_NOSPLIT
;
1107 if (n
->child
== NULL
)
1110 if (p
->flags
& TERMP_SPLIT
)
1113 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1114 p
->flags
|= TERMP_SPLIT
;
1120 termp_ns_pre(DECL_ARGS
)
1123 if ( ! (MDOC_LINE
& n
->flags
))
1124 p
->flags
|= TERMP_NOSPACE
;
1129 termp_rs_pre(DECL_ARGS
)
1132 if (SEC_SEE_ALSO
!= n
->sec
)
1134 if (MDOC_BLOCK
== n
->type
&& n
->prev
)
1140 termp_rv_pre(DECL_ARGS
)
1148 term_word(p
, "The");
1150 for (n
= n
->child
; n
; n
= n
->next
) {
1151 term_fontpush(p
, TERMFONT_BOLD
);
1152 term_word(p
, n
->string
);
1155 p
->flags
|= TERMP_NOSPACE
;
1158 if (n
->next
== NULL
)
1162 p
->flags
|= TERMP_NOSPACE
;
1165 if (n
->next
->next
== NULL
)
1166 term_word(p
, "and");
1170 term_word(p
, "functions return");
1172 term_word(p
, "function returns");
1174 term_word(p
, "the value\\~0 if successful;");
1176 term_word(p
, "Upon successful completion,"
1177 " the value\\~0 is returned;");
1179 term_word(p
, "otherwise the value\\~\\-1 is returned"
1180 " and the global variable");
1182 term_fontpush(p
, TERMFONT_UNDER
);
1183 term_word(p
, "errno");
1186 term_word(p
, "is set to indicate the error.");
1187 p
->flags
|= TERMP_SENTENCE
;
1193 termp_ex_pre(DECL_ARGS
)
1198 term_word(p
, "The");
1201 for (n
= n
->child
; n
; n
= n
->next
) {
1202 term_fontpush(p
, TERMFONT_BOLD
);
1203 term_word(p
, n
->string
);
1206 if (nchild
> 2 && n
->next
) {
1207 p
->flags
|= TERMP_NOSPACE
;
1211 if (n
->next
&& NULL
== n
->next
->next
)
1212 term_word(p
, "and");
1216 term_word(p
, "utilities exit\\~0");
1218 term_word(p
, "utility exits\\~0");
1220 term_word(p
, "on success, and\\~>0 if an error occurs.");
1222 p
->flags
|= TERMP_SENTENCE
;
1227 termp_nd_pre(DECL_ARGS
)
1230 if (MDOC_BODY
!= n
->type
)
1233 #if defined(__OpenBSD__) || defined(__linux__)
1234 term_word(p
, "\\(en");
1236 term_word(p
, "\\(em");
1242 termp_bl_pre(DECL_ARGS
)
1245 return(MDOC_HEAD
!= n
->type
);
1249 termp_bl_post(DECL_ARGS
)
1252 if (MDOC_BLOCK
== n
->type
)
1257 termp_xr_pre(DECL_ARGS
)
1260 if (NULL
== (n
= n
->child
))
1263 assert(MDOC_TEXT
== n
->type
);
1264 term_word(p
, n
->string
);
1266 if (NULL
== (n
= n
->next
))
1269 p
->flags
|= TERMP_NOSPACE
;
1271 p
->flags
|= TERMP_NOSPACE
;
1273 assert(MDOC_TEXT
== n
->type
);
1274 term_word(p
, n
->string
);
1276 p
->flags
|= TERMP_NOSPACE
;
1283 * This decides how to assert whitespace before any of the SYNOPSIS set
1284 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1288 synopsis_pre(struct termp
*p
, const struct mdoc_node
*n
)
1291 * Obviously, if we're not in a SYNOPSIS or no prior macros
1292 * exist, do nothing.
1294 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1298 * If we're the second in a pair of like elements, emit our
1299 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1300 * case we soldier on.
1302 if (n
->prev
->tok
== n
->tok
&&
1303 MDOC_Ft
!= n
->tok
&&
1304 MDOC_Fo
!= n
->tok
&&
1305 MDOC_Fn
!= n
->tok
) {
1311 * If we're one of the SYNOPSIS set and non-like pair-wise after
1312 * another (or Fn/Fo, which we've let slip through) then assert
1313 * vertical space, else only newline and move on.
1315 switch (n
->prev
->tok
) {
1328 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1340 termp_vt_pre(DECL_ARGS
)
1343 if (MDOC_ELEM
== n
->type
) {
1345 return(termp_under_pre(p
, pair
, meta
, n
));
1346 } else if (MDOC_BLOCK
== n
->type
) {
1349 } else if (MDOC_HEAD
== n
->type
)
1352 return(termp_under_pre(p
, pair
, meta
, n
));
1356 termp_bold_pre(DECL_ARGS
)
1359 term_fontpush(p
, TERMFONT_BOLD
);
1364 termp_fd_pre(DECL_ARGS
)
1368 return(termp_bold_pre(p
, pair
, meta
, n
));
1372 termp_fd_post(DECL_ARGS
)
1379 termp_sh_pre(DECL_ARGS
)
1385 * Vertical space before sections, except
1386 * when the previous section was empty.
1388 if (n
->prev
== NULL
||
1389 MDOC_Sh
!= n
->prev
->tok
||
1390 (n
->prev
->body
!= NULL
&&
1391 n
->prev
->body
->child
!= NULL
))
1395 term_fontpush(p
, TERMFONT_BOLD
);
1398 p
->offset
= term_len(p
, p
->defindent
);
1399 if (SEC_AUTHORS
== n
->sec
)
1400 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1409 termp_sh_post(DECL_ARGS
)
1426 termp_bt_pre(DECL_ARGS
)
1429 term_word(p
, "is currently in beta test.");
1430 p
->flags
|= TERMP_SENTENCE
;
1435 termp_lb_post(DECL_ARGS
)
1438 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1443 termp_ud_pre(DECL_ARGS
)
1446 term_word(p
, "currently under development.");
1447 p
->flags
|= TERMP_SENTENCE
;
1452 termp_d1_pre(DECL_ARGS
)
1455 if (MDOC_BLOCK
!= n
->type
)
1458 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1463 termp_ft_pre(DECL_ARGS
)
1466 /* NB: MDOC_LINE does not effect this! */
1468 term_fontpush(p
, TERMFONT_UNDER
);
1473 termp_fn_pre(DECL_ARGS
)
1478 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1482 if (NULL
== (n
= n
->child
))
1486 rmargin
= p
->rmargin
;
1487 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1488 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1491 assert(MDOC_TEXT
== n
->type
);
1492 term_fontpush(p
, TERMFONT_BOLD
);
1493 term_word(p
, n
->string
);
1498 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1499 p
->offset
= p
->rmargin
;
1500 p
->rmargin
= rmargin
;
1503 p
->flags
|= TERMP_NOSPACE
;
1505 p
->flags
|= TERMP_NOSPACE
;
1507 for (n
= n
->next
; n
; n
= n
->next
) {
1508 assert(MDOC_TEXT
== n
->type
);
1509 term_fontpush(p
, TERMFONT_UNDER
);
1511 p
->flags
|= TERMP_NBRWORD
;
1512 term_word(p
, n
->string
);
1516 p
->flags
|= TERMP_NOSPACE
;
1521 p
->flags
|= TERMP_NOSPACE
;
1525 p
->flags
|= TERMP_NOSPACE
;
1534 termp_fa_pre(DECL_ARGS
)
1536 const struct mdoc_node
*nn
;
1538 if (n
->parent
->tok
!= MDOC_Fo
) {
1539 term_fontpush(p
, TERMFONT_UNDER
);
1543 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1544 term_fontpush(p
, TERMFONT_UNDER
);
1545 p
->flags
|= TERMP_NBRWORD
;
1546 term_word(p
, nn
->string
);
1549 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1550 p
->flags
|= TERMP_NOSPACE
;
1559 termp_bd_pre(DECL_ARGS
)
1561 size_t tabwidth
, lm
, len
, rm
, rmax
;
1562 struct mdoc_node
*nn
;
1564 if (MDOC_BLOCK
== n
->type
) {
1565 print_bvspace(p
, n
, n
);
1567 } else if (MDOC_HEAD
== n
->type
)
1570 /* Handle the -offset argument. */
1572 if (n
->norm
->Bd
.offs
== NULL
||
1573 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1575 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1576 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1577 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1578 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1580 p
->offset
+= a2width(p
, n
->norm
->Bd
.offs
);
1583 * If -ragged or -filled are specified, the block does nothing
1584 * but change the indentation. If -unfilled or -literal are
1585 * specified, text is printed exactly as entered in the display:
1586 * for macro lines, a newline is appended to the line. Blank
1587 * lines are allowed.
1590 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1591 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1592 DISP_centered
!= n
->norm
->Bd
.type
)
1595 tabwidth
= p
->tabwidth
;
1596 if (DISP_literal
== n
->norm
->Bd
.type
)
1597 p
->tabwidth
= term_len(p
, 8);
1601 rmax
= p
->maxrmargin
;
1602 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1604 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1605 if (DISP_centered
== n
->norm
->Bd
.type
) {
1606 if (MDOC_TEXT
== nn
->type
) {
1607 len
= term_strlen(p
, nn
->string
);
1608 p
->offset
= len
>= rm
? 0 :
1609 lm
+ len
>= rm
? rm
- len
:
1610 (lm
+ rm
- len
) / 2;
1614 print_mdoc_node(p
, pair
, meta
, nn
);
1616 * If the printed node flushes its own line, then we
1617 * needn't do it here as well. This is hacky, but the
1618 * notion of selective eoln whitespace is pretty dumb
1619 * anyway, so don't sweat it.
1641 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1644 p
->flags
|= TERMP_NOSPACE
;
1647 p
->tabwidth
= tabwidth
;
1649 p
->maxrmargin
= rmax
;
1654 termp_bd_post(DECL_ARGS
)
1658 if (MDOC_BODY
!= n
->type
)
1662 rmax
= p
->maxrmargin
;
1664 if (DISP_literal
== n
->norm
->Bd
.type
||
1665 DISP_unfilled
== n
->norm
->Bd
.type
)
1666 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1668 p
->flags
|= TERMP_NOSPACE
;
1672 p
->maxrmargin
= rmax
;
1676 termp_bx_pre(DECL_ARGS
)
1679 if (NULL
!= (n
= n
->child
)) {
1680 term_word(p
, n
->string
);
1681 p
->flags
|= TERMP_NOSPACE
;
1682 term_word(p
, "BSD");
1684 term_word(p
, "BSD");
1688 if (NULL
!= (n
= n
->next
)) {
1689 p
->flags
|= TERMP_NOSPACE
;
1691 p
->flags
|= TERMP_NOSPACE
;
1692 term_word(p
, n
->string
);
1699 termp_xx_pre(DECL_ARGS
)
1732 p
->flags
|= TERMP_KEEP
;
1733 term_word(p
, n
->child
->string
);
1740 termp_pf_post(DECL_ARGS
)
1743 p
->flags
|= TERMP_NOSPACE
;
1747 termp_ss_pre(DECL_ARGS
)
1757 term_fontpush(p
, TERMFONT_BOLD
);
1758 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1761 p
->offset
= term_len(p
, p
->defindent
);
1771 termp_ss_post(DECL_ARGS
)
1774 if (n
->type
== MDOC_HEAD
|| n
->type
== MDOC_BODY
)
1779 termp_cd_pre(DECL_ARGS
)
1783 term_fontpush(p
, TERMFONT_BOLD
);
1788 termp_in_pre(DECL_ARGS
)
1793 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1794 term_fontpush(p
, TERMFONT_BOLD
);
1795 term_word(p
, "#include");
1799 term_fontpush(p
, TERMFONT_UNDER
);
1802 p
->flags
|= TERMP_NOSPACE
;
1807 termp_in_post(DECL_ARGS
)
1810 if (MDOC_SYNPRETTY
& n
->flags
)
1811 term_fontpush(p
, TERMFONT_BOLD
);
1813 p
->flags
|= TERMP_NOSPACE
;
1816 if (MDOC_SYNPRETTY
& n
->flags
)
1821 termp_sp_pre(DECL_ARGS
)
1827 len
= n
->child
? a2height(p
, n
->child
->string
) : 1;
1839 for (i
= 0; i
< len
; i
++)
1846 termp_skip_pre(DECL_ARGS
)
1853 termp_quote_pre(DECL_ARGS
)
1856 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1863 term_word(p
, n
->parent
->prev
!= NULL
&&
1864 n
->parent
->prev
->tok
== MDOC_An
? "<" : "\\(la");
1883 term_word(p
, "\\(lq");
1886 if (NULL
== n
->norm
->Es
||
1887 NULL
== n
->norm
->Es
->child
)
1889 term_word(p
, n
->norm
->Es
->child
->string
);
1910 term_word(p
, "\\(oq");
1917 p
->flags
|= TERMP_NOSPACE
;
1922 termp_quote_post(DECL_ARGS
)
1925 if (n
->type
!= MDOC_BODY
&& n
->type
!= MDOC_ELEM
)
1928 if ( ! (n
->tok
== MDOC_En
||
1929 (n
->tok
== MDOC_Eo
&& n
->end
== ENDBODY_SPACE
)))
1930 p
->flags
|= TERMP_NOSPACE
;
1936 term_word(p
, n
->parent
->prev
!= NULL
&&
1937 n
->parent
->prev
->tok
== MDOC_An
? ">" : "\\(ra");
1956 term_word(p
, "\\(rq");
1959 if (NULL
!= n
->norm
->Es
&&
1960 NULL
!= n
->norm
->Es
->child
&&
1961 NULL
!= n
->norm
->Es
->child
->next
) {
1962 p
->flags
|= TERMP_NOSPACE
;
1963 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1985 term_word(p
, "\\(cq");
1994 termp_fo_pre(DECL_ARGS
)
1999 pretty
= MDOC_SYNPRETTY
& n
->flags
;
2001 if (MDOC_BLOCK
== n
->type
) {
2004 } else if (MDOC_BODY
== n
->type
) {
2006 rmargin
= p
->rmargin
;
2007 p
->rmargin
= p
->offset
+ term_len(p
, 4);
2008 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
2011 p
->flags
|= TERMP_NOSPACE
;
2013 p
->flags
|= TERMP_NOSPACE
;
2016 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2018 p
->offset
= p
->rmargin
;
2019 p
->rmargin
= rmargin
;
2024 if (NULL
== n
->child
)
2027 /* XXX: we drop non-initial arguments as per groff. */
2029 assert(n
->child
->string
);
2030 term_fontpush(p
, TERMFONT_BOLD
);
2031 term_word(p
, n
->child
->string
);
2036 termp_fo_post(DECL_ARGS
)
2039 if (MDOC_BODY
!= n
->type
)
2042 p
->flags
|= TERMP_NOSPACE
;
2045 if (MDOC_SYNPRETTY
& n
->flags
) {
2046 p
->flags
|= TERMP_NOSPACE
;
2053 termp_bf_pre(DECL_ARGS
)
2056 if (MDOC_HEAD
== n
->type
)
2058 else if (MDOC_BODY
!= n
->type
)
2061 if (FONT_Em
== n
->norm
->Bf
.font
)
2062 term_fontpush(p
, TERMFONT_UNDER
);
2063 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2064 term_fontpush(p
, TERMFONT_BOLD
);
2066 term_fontpush(p
, TERMFONT_NONE
);
2072 termp_sm_pre(DECL_ARGS
)
2075 if (NULL
== n
->child
)
2076 p
->flags
^= TERMP_NONOSPACE
;
2077 else if (0 == strcmp("on", n
->child
->string
))
2078 p
->flags
&= ~TERMP_NONOSPACE
;
2080 p
->flags
|= TERMP_NONOSPACE
;
2082 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2083 p
->flags
&= ~TERMP_NOSPACE
;
2089 termp_ap_pre(DECL_ARGS
)
2092 p
->flags
|= TERMP_NOSPACE
;
2094 p
->flags
|= TERMP_NOSPACE
;
2099 termp____post(DECL_ARGS
)
2103 * Handle lists of authors. In general, print each followed by
2104 * a comma. Don't print the comma if there are only two
2107 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2108 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2109 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2114 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2117 p
->flags
|= TERMP_NOSPACE
;
2118 if (NULL
== n
->next
) {
2120 p
->flags
|= TERMP_SENTENCE
;
2126 termp_li_pre(DECL_ARGS
)
2129 term_fontpush(p
, TERMFONT_NONE
);
2134 termp_lk_pre(DECL_ARGS
)
2136 const struct mdoc_node
*link
, *descr
;
2138 if (NULL
== (link
= n
->child
))
2141 if (NULL
!= (descr
= link
->next
)) {
2142 term_fontpush(p
, TERMFONT_UNDER
);
2143 while (NULL
!= descr
) {
2144 term_word(p
, descr
->string
);
2145 descr
= descr
->next
;
2147 p
->flags
|= TERMP_NOSPACE
;
2152 term_fontpush(p
, TERMFONT_BOLD
);
2153 term_word(p
, link
->string
);
2160 termp_bk_pre(DECL_ARGS
)
2169 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2170 p
->flags
|= TERMP_PREKEEP
;
2181 termp_bk_post(DECL_ARGS
)
2184 if (MDOC_BODY
== n
->type
)
2185 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2189 termp__t_post(DECL_ARGS
)
2193 * If we're in an `Rs' and there's a journal present, then quote
2194 * us instead of underlining us (for disambiguation).
2196 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2197 n
->parent
->norm
->Rs
.quote_T
)
2198 termp_quote_post(p
, pair
, meta
, n
);
2200 termp____post(p
, pair
, meta
, n
);
2204 termp__t_pre(DECL_ARGS
)
2208 * If we're in an `Rs' and there's a journal present, then quote
2209 * us instead of underlining us (for disambiguation).
2211 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2212 n
->parent
->norm
->Rs
.quote_T
)
2213 return(termp_quote_pre(p
, pair
, meta
, n
));
2215 term_fontpush(p
, TERMFONT_UNDER
);
2220 termp_under_pre(DECL_ARGS
)
2223 term_fontpush(p
, TERMFONT_UNDER
);