]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
7a007e8440c6f97ce77418c94dd1dcc0d7344a46
1 /* $Id: mdoc_term.c,v 1.269 2014/07/02 19:55:10 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.
23 #include <sys/types.h>
33 #include "mandoc_aux.h"
40 struct termpair
*ppair
;
44 #define DECL_ARGS struct termp *p, \
45 struct termpair *pair, \
46 const struct mdoc_meta *meta, \
50 int (*pre
)(DECL_ARGS
);
51 void (*post
)(DECL_ARGS
);
54 static size_t a2width(const struct termp
*, const char *);
55 static size_t a2height(const struct termp
*, const char *);
56 static size_t a2offs(const struct termp
*, const char *);
58 static void print_bvspace(struct termp
*,
59 const struct mdoc_node
*,
60 const struct mdoc_node
*);
61 static void print_mdoc_node(DECL_ARGS
);
62 static void print_mdoc_nodelist(DECL_ARGS
);
63 static void print_mdoc_head(struct termp
*, const void *);
64 static void print_mdoc_foot(struct termp
*, const void *);
65 static void synopsis_pre(struct termp
*,
66 const struct mdoc_node
*);
68 static void termp____post(DECL_ARGS
);
69 static void termp__t_post(DECL_ARGS
);
70 static void termp_an_post(DECL_ARGS
);
71 static void termp_bd_post(DECL_ARGS
);
72 static void termp_bk_post(DECL_ARGS
);
73 static void termp_bl_post(DECL_ARGS
);
74 static void termp_fd_post(DECL_ARGS
);
75 static void termp_fo_post(DECL_ARGS
);
76 static void termp_in_post(DECL_ARGS
);
77 static void termp_it_post(DECL_ARGS
);
78 static void termp_lb_post(DECL_ARGS
);
79 static void termp_nm_post(DECL_ARGS
);
80 static void termp_pf_post(DECL_ARGS
);
81 static void termp_quote_post(DECL_ARGS
);
82 static void termp_sh_post(DECL_ARGS
);
83 static void termp_ss_post(DECL_ARGS
);
85 static int termp__a_pre(DECL_ARGS
);
86 static int termp__t_pre(DECL_ARGS
);
87 static int termp_an_pre(DECL_ARGS
);
88 static int termp_ap_pre(DECL_ARGS
);
89 static int termp_bd_pre(DECL_ARGS
);
90 static int termp_bf_pre(DECL_ARGS
);
91 static int termp_bk_pre(DECL_ARGS
);
92 static int termp_bl_pre(DECL_ARGS
);
93 static int termp_bold_pre(DECL_ARGS
);
94 static int termp_bt_pre(DECL_ARGS
);
95 static int termp_bx_pre(DECL_ARGS
);
96 static int termp_cd_pre(DECL_ARGS
);
97 static int termp_d1_pre(DECL_ARGS
);
98 static int termp_es_pre(DECL_ARGS
);
99 static int termp_ex_pre(DECL_ARGS
);
100 static int termp_fa_pre(DECL_ARGS
);
101 static int termp_fd_pre(DECL_ARGS
);
102 static int termp_fl_pre(DECL_ARGS
);
103 static int termp_fn_pre(DECL_ARGS
);
104 static int termp_fo_pre(DECL_ARGS
);
105 static int termp_ft_pre(DECL_ARGS
);
106 static int termp_in_pre(DECL_ARGS
);
107 static int termp_it_pre(DECL_ARGS
);
108 static int termp_li_pre(DECL_ARGS
);
109 static int termp_ll_pre(DECL_ARGS
);
110 static int termp_lk_pre(DECL_ARGS
);
111 static int termp_nd_pre(DECL_ARGS
);
112 static int termp_nm_pre(DECL_ARGS
);
113 static int termp_ns_pre(DECL_ARGS
);
114 static int termp_quote_pre(DECL_ARGS
);
115 static int termp_rs_pre(DECL_ARGS
);
116 static int termp_rv_pre(DECL_ARGS
);
117 static int termp_sh_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_under_pre(DECL_ARGS
);
122 static int termp_ud_pre(DECL_ARGS
);
123 static int termp_vt_pre(DECL_ARGS
);
124 static int termp_xr_pre(DECL_ARGS
);
125 static int termp_xx_pre(DECL_ARGS
);
127 static const struct termact termacts
[MDOC_MAX
] = {
128 { termp_ap_pre
, NULL
}, /* Ap */
129 { NULL
, NULL
}, /* Dd */
130 { NULL
, NULL
}, /* Dt */
131 { NULL
, NULL
}, /* Os */
132 { termp_sh_pre
, termp_sh_post
}, /* Sh */
133 { termp_ss_pre
, termp_ss_post
}, /* Ss */
134 { termp_sp_pre
, NULL
}, /* Pp */
135 { termp_d1_pre
, termp_bl_post
}, /* D1 */
136 { termp_d1_pre
, termp_bl_post
}, /* Dl */
137 { termp_bd_pre
, termp_bd_post
}, /* Bd */
138 { NULL
, NULL
}, /* Ed */
139 { termp_bl_pre
, termp_bl_post
}, /* Bl */
140 { NULL
, NULL
}, /* El */
141 { termp_it_pre
, termp_it_post
}, /* It */
142 { termp_under_pre
, NULL
}, /* Ad */
143 { termp_an_pre
, termp_an_post
}, /* An */
144 { termp_under_pre
, NULL
}, /* Ar */
145 { termp_cd_pre
, NULL
}, /* Cd */
146 { termp_bold_pre
, NULL
}, /* Cm */
147 { NULL
, NULL
}, /* Dv */
148 { NULL
, NULL
}, /* Er */
149 { NULL
, NULL
}, /* Ev */
150 { termp_ex_pre
, NULL
}, /* Ex */
151 { termp_fa_pre
, NULL
}, /* Fa */
152 { termp_fd_pre
, termp_fd_post
}, /* Fd */
153 { termp_fl_pre
, NULL
}, /* Fl */
154 { termp_fn_pre
, NULL
}, /* Fn */
155 { termp_ft_pre
, NULL
}, /* Ft */
156 { termp_bold_pre
, NULL
}, /* Ic */
157 { termp_in_pre
, termp_in_post
}, /* In */
158 { termp_li_pre
, NULL
}, /* Li */
159 { termp_nd_pre
, NULL
}, /* Nd */
160 { termp_nm_pre
, termp_nm_post
}, /* Nm */
161 { termp_quote_pre
, termp_quote_post
}, /* Op */
162 { termp_ft_pre
, NULL
}, /* Ot */
163 { termp_under_pre
, NULL
}, /* Pa */
164 { termp_rv_pre
, NULL
}, /* Rv */
165 { NULL
, NULL
}, /* St */
166 { termp_under_pre
, NULL
}, /* Va */
167 { termp_vt_pre
, NULL
}, /* Vt */
168 { termp_xr_pre
, NULL
}, /* Xr */
169 { termp__a_pre
, termp____post
}, /* %A */
170 { termp_under_pre
, termp____post
}, /* %B */
171 { NULL
, termp____post
}, /* %D */
172 { termp_under_pre
, termp____post
}, /* %I */
173 { termp_under_pre
, termp____post
}, /* %J */
174 { NULL
, termp____post
}, /* %N */
175 { NULL
, termp____post
}, /* %O */
176 { NULL
, termp____post
}, /* %P */
177 { NULL
, termp____post
}, /* %R */
178 { termp__t_pre
, termp__t_post
}, /* %T */
179 { NULL
, termp____post
}, /* %V */
180 { NULL
, NULL
}, /* Ac */
181 { termp_quote_pre
, termp_quote_post
}, /* Ao */
182 { termp_quote_pre
, termp_quote_post
}, /* Aq */
183 { NULL
, NULL
}, /* At */
184 { NULL
, NULL
}, /* Bc */
185 { termp_bf_pre
, NULL
}, /* Bf */
186 { termp_quote_pre
, termp_quote_post
}, /* Bo */
187 { termp_quote_pre
, termp_quote_post
}, /* Bq */
188 { termp_xx_pre
, NULL
}, /* Bsx */
189 { termp_bx_pre
, NULL
}, /* Bx */
190 { NULL
, NULL
}, /* Db */
191 { NULL
, NULL
}, /* Dc */
192 { termp_quote_pre
, termp_quote_post
}, /* Do */
193 { termp_quote_pre
, termp_quote_post
}, /* Dq */
194 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
195 { NULL
, NULL
}, /* Ef */
196 { termp_under_pre
, NULL
}, /* Em */
197 { termp_quote_pre
, termp_quote_post
}, /* Eo */
198 { termp_xx_pre
, NULL
}, /* Fx */
199 { termp_bold_pre
, NULL
}, /* Ms */
200 { NULL
, NULL
}, /* No */
201 { termp_ns_pre
, NULL
}, /* Ns */
202 { termp_xx_pre
, NULL
}, /* Nx */
203 { termp_xx_pre
, NULL
}, /* Ox */
204 { NULL
, NULL
}, /* Pc */
205 { NULL
, termp_pf_post
}, /* Pf */
206 { termp_quote_pre
, termp_quote_post
}, /* Po */
207 { termp_quote_pre
, termp_quote_post
}, /* Pq */
208 { NULL
, NULL
}, /* Qc */
209 { termp_quote_pre
, termp_quote_post
}, /* Ql */
210 { termp_quote_pre
, termp_quote_post
}, /* Qo */
211 { termp_quote_pre
, termp_quote_post
}, /* Qq */
212 { NULL
, NULL
}, /* Re */
213 { termp_rs_pre
, NULL
}, /* Rs */
214 { NULL
, NULL
}, /* Sc */
215 { termp_quote_pre
, termp_quote_post
}, /* So */
216 { termp_quote_pre
, termp_quote_post
}, /* Sq */
217 { termp_sm_pre
, NULL
}, /* Sm */
218 { termp_under_pre
, NULL
}, /* Sx */
219 { termp_bold_pre
, NULL
}, /* Sy */
220 { NULL
, NULL
}, /* Tn */
221 { termp_xx_pre
, NULL
}, /* Ux */
222 { NULL
, NULL
}, /* Xc */
223 { NULL
, NULL
}, /* Xo */
224 { termp_fo_pre
, termp_fo_post
}, /* Fo */
225 { NULL
, NULL
}, /* Fc */
226 { termp_quote_pre
, termp_quote_post
}, /* Oo */
227 { NULL
, NULL
}, /* Oc */
228 { termp_bk_pre
, termp_bk_post
}, /* Bk */
229 { NULL
, NULL
}, /* Ek */
230 { termp_bt_pre
, NULL
}, /* Bt */
231 { NULL
, NULL
}, /* Hf */
232 { termp_under_pre
, NULL
}, /* Fr */
233 { termp_ud_pre
, NULL
}, /* Ud */
234 { NULL
, termp_lb_post
}, /* Lb */
235 { termp_sp_pre
, NULL
}, /* Lp */
236 { termp_lk_pre
, NULL
}, /* Lk */
237 { termp_under_pre
, NULL
}, /* Mt */
238 { termp_quote_pre
, termp_quote_post
}, /* Brq */
239 { termp_quote_pre
, termp_quote_post
}, /* Bro */
240 { NULL
, NULL
}, /* Brc */
241 { NULL
, termp____post
}, /* %C */
242 { termp_es_pre
, NULL
}, /* Es */
243 { termp_quote_pre
, termp_quote_post
}, /* En */
244 { termp_xx_pre
, NULL
}, /* Dx */
245 { NULL
, termp____post
}, /* %Q */
246 { termp_sp_pre
, NULL
}, /* br */
247 { termp_sp_pre
, NULL
}, /* sp */
248 { NULL
, termp____post
}, /* %U */
249 { NULL
, NULL
}, /* Ta */
250 { termp_ll_pre
, NULL
}, /* ll */
255 terminal_mdoc(void *arg
, const struct mdoc
*mdoc
)
257 const struct mdoc_node
*n
;
258 const struct mdoc_meta
*meta
;
261 p
= (struct termp
*)arg
;
263 if (0 == p
->defindent
)
267 p
->maxrmargin
= p
->defrmargin
;
268 p
->tabwidth
= term_len(p
, 5);
270 if (NULL
== p
->symtab
)
271 p
->symtab
= mchars_alloc();
274 meta
= mdoc_meta(mdoc
);
276 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, meta
);
279 print_mdoc_nodelist(p
, NULL
, meta
, n
->child
);
285 print_mdoc_nodelist(DECL_ARGS
)
288 print_mdoc_node(p
, pair
, meta
, n
);
290 print_mdoc_nodelist(p
, pair
, meta
, n
->next
);
294 print_mdoc_node(DECL_ARGS
)
297 struct termpair npair
;
298 size_t offset
, rmargin
;
302 rmargin
= p
->rmargin
;
303 n
->prev_font
= term_fontq(p
);
305 memset(&npair
, 0, sizeof(struct termpair
));
309 * Keeps only work until the end of a line. If a keep was
310 * invoked in a prior line, revert it to PREKEEP.
313 if (TERMP_KEEP
& p
->flags
) {
314 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
315 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
316 p
->flags
&= ~TERMP_KEEP
;
317 p
->flags
|= TERMP_PREKEEP
;
322 * After the keep flags have been set up, we may now
323 * produce output. Note that some pre-handlers do so.
328 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
330 if (MDOC_DELIMC
& n
->flags
)
331 p
->flags
|= TERMP_NOSPACE
;
332 term_word(p
, n
->string
);
333 if (MDOC_DELIMO
& n
->flags
)
334 p
->flags
|= TERMP_NOSPACE
;
340 term_tbl(p
, n
->span
);
343 if (termacts
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
344 chld
= (*termacts
[n
->tok
].pre
)
345 (p
, &npair
, meta
, n
);
349 if (chld
&& n
->child
)
350 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
353 (ENDBODY_NOT
== n
->end
? n
: n
->pending
)->prev_font
);
363 if ( ! termacts
[n
->tok
].post
|| MDOC_ENDED
& n
->flags
)
365 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
368 * Explicit end tokens not only call the post
369 * handler, but also tell the respective block
370 * that it must not call the post handler again.
372 if (ENDBODY_NOT
!= n
->end
)
373 n
->pending
->flags
|= MDOC_ENDED
;
376 * End of line terminating an implicit block
377 * while an explicit block is still open.
378 * Continue the explicit block without spacing.
380 if (ENDBODY_NOSPACE
== n
->end
)
381 p
->flags
|= TERMP_NOSPACE
;
385 if (MDOC_EOS
& n
->flags
)
386 p
->flags
|= TERMP_SENTENCE
;
388 if (MDOC_ll
!= n
->tok
) {
390 p
->rmargin
= rmargin
;
395 print_mdoc_foot(struct termp
*p
, const void *arg
)
397 const struct mdoc_meta
*meta
;
399 meta
= (const struct mdoc_meta
*)arg
;
401 term_fontrepl(p
, TERMFONT_NONE
);
404 * Output the footer in new-groff style, that is, three columns
405 * with the middle being the manual date and flanking columns
406 * being the operating system:
414 p
->rmargin
= (p
->maxrmargin
-
415 term_strlen(p
, meta
->date
) + term_len(p
, 1)) / 2;
417 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
419 term_word(p
, meta
->os
);
422 p
->offset
= p
->rmargin
;
423 p
->rmargin
= p
->maxrmargin
- term_strlen(p
, meta
->os
);
424 p
->flags
|= TERMP_NOSPACE
;
426 term_word(p
, meta
->date
);
429 p
->offset
= p
->rmargin
;
430 p
->rmargin
= p
->maxrmargin
;
432 p
->flags
&= ~TERMP_NOBREAK
;
433 p
->flags
|= TERMP_NOSPACE
;
435 term_word(p
, meta
->os
);
439 p
->rmargin
= p
->maxrmargin
;
444 print_mdoc_head(struct termp
*p
, const void *arg
)
446 const struct mdoc_meta
*meta
;
447 char *volume
, *title
;
448 size_t vollen
, titlen
;
450 meta
= (const struct mdoc_meta
*)arg
;
453 * The header is strange. It has three components, which are
454 * really two with the first duplicated. It goes like this:
456 * IDENTIFIER TITLE IDENTIFIER
458 * The IDENTIFIER is NAME(SECTION), which is the command-name
459 * (if given, or "unknown" if not) followed by the manual page
460 * section. These are given in `Dt'. The TITLE is a free-form
461 * string depending on the manual volume. If not specified, it
462 * switches on the manual section.
466 p
->rmargin
= p
->maxrmargin
;
469 if (NULL
== meta
->arch
)
470 volume
= mandoc_strdup(meta
->vol
);
472 mandoc_asprintf(&volume
, "%s (%s)",
473 meta
->vol
, meta
->arch
);
474 vollen
= term_strlen(p
, volume
);
476 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
477 titlen
= term_strlen(p
, title
);
479 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
482 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
483 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
484 p
->maxrmargin
- vollen
;
489 p
->flags
|= TERMP_NOSPACE
;
490 p
->offset
= p
->rmargin
;
491 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
492 p
->maxrmargin
- titlen
: p
->maxrmargin
;
494 term_word(p
, volume
);
497 p
->flags
&= ~TERMP_NOBREAK
;
499 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
500 p
->flags
|= TERMP_NOSPACE
;
501 p
->offset
= p
->rmargin
;
502 p
->rmargin
= p
->maxrmargin
;
507 p
->flags
&= ~TERMP_NOSPACE
;
509 p
->rmargin
= p
->maxrmargin
;
515 a2height(const struct termp
*p
, const char *v
)
521 if ( ! a2roffsu(v
, &su
, SCALE_VS
))
522 SCALE_VS_INIT(&su
, atoi(v
));
524 return(term_vspan(p
, &su
));
528 a2width(const struct termp
*p
, const char *v
)
533 if ( ! a2roffsu(v
, &su
, SCALE_MAX
))
534 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
536 return(term_hspan(p
, &su
));
540 a2offs(const struct termp
*p
, const char *v
)
546 else if (0 == strcmp(v
, "left"))
548 else if (0 == strcmp(v
, "indent"))
549 return(term_len(p
, p
->defindent
+ 1));
550 else if (0 == strcmp(v
, "indent-two"))
551 return(term_len(p
, (p
->defindent
+ 1) * 2));
552 else if ( ! a2roffsu(v
, &su
, SCALE_MAX
))
553 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
555 return(term_hspan(p
, &su
));
559 * Determine how much space to print out before block elements of `It'
560 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
564 print_bvspace(struct termp
*p
,
565 const struct mdoc_node
*bl
,
566 const struct mdoc_node
*n
)
568 const struct mdoc_node
*nn
;
574 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
576 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
579 /* Do not vspace directly after Ss/Sh. */
581 for (nn
= n
; nn
; nn
= nn
->parent
) {
582 if (MDOC_BLOCK
!= nn
->type
)
584 if (MDOC_Ss
== nn
->tok
)
586 if (MDOC_Sh
== nn
->tok
)
588 if (NULL
== nn
->prev
)
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
= a2offs(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
)
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 (n
->next
->child
&&
805 (MDOC_Bl
== n
->next
->child
->tok
||
806 MDOC_Bd
== n
->next
->child
->tok
))
809 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
813 if (MDOC_HEAD
!= n
->type
)
816 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
819 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
820 p
->flags
|= TERMP_DANGLE
;
823 if (MDOC_HEAD
== n
->type
)
826 if (NULL
== n
->next
) {
827 p
->flags
&= ~TERMP_NOBREAK
;
830 p
->flags
|= TERMP_NOBREAK
;
836 if (MDOC_HEAD
!= n
->type
)
838 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
846 * Margin control. Set-head-width lists have their right
847 * margins shortened. The body for these lists has the offset
848 * necessarily lengthened. Everybody gets the offset.
856 * Same stipulation as above, regarding `-hang'. We
857 * don't want to recalculate rmargin and offsets when
858 * using `Bd' or `Bl' within `-hang' overstep lists.
860 if (MDOC_HEAD
== n
->type
&& n
->next
->child
&&
861 (MDOC_Bl
== n
->next
->child
->tok
||
862 MDOC_Bd
== n
->next
->child
->tok
))
875 if (MDOC_HEAD
== n
->type
)
876 p
->rmargin
= p
->offset
+ width
;
879 if (p
->rmargin
< p
->offset
)
880 p
->rmargin
= p
->offset
;
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
)
999 if (MDOC_BLOCK
== n
->type
) {
1000 p
->flags
|= TERMP_PREKEEP
;
1004 if (MDOC_BODY
== n
->type
) {
1005 if (NULL
== n
->child
)
1007 p
->flags
|= TERMP_NOSPACE
;
1008 p
->offset
+= term_len(p
, 1) +
1009 (NULL
== n
->prev
->child
?
1010 term_strlen(p
, meta
->name
) :
1011 MDOC_TEXT
== n
->prev
->child
->type
?
1012 term_strlen(p
, n
->prev
->child
->string
) :
1014 if (p
->rmargin
< p
->offset
)
1015 p
->rmargin
= p
->offset
;
1019 if (NULL
== n
->child
&& NULL
== meta
->name
)
1022 if (MDOC_HEAD
== n
->type
)
1023 synopsis_pre(p
, n
->parent
);
1025 if (MDOC_HEAD
== n
->type
&& n
->next
->child
) {
1026 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1028 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1029 if (NULL
== n
->child
) {
1030 p
->rmargin
+= term_strlen(p
, meta
->name
);
1031 } else if (MDOC_TEXT
== n
->child
->type
) {
1032 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1034 p
->flags
|= TERMP_HANG
;
1036 p
->rmargin
+= term_len(p
, 5);
1037 p
->flags
|= TERMP_HANG
;
1041 term_fontpush(p
, TERMFONT_BOLD
);
1042 if (NULL
== n
->child
)
1043 term_word(p
, meta
->name
);
1048 termp_nm_post(DECL_ARGS
)
1051 if (MDOC_BLOCK
== n
->type
) {
1052 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1053 } else if (MDOC_HEAD
== n
->type
&& n
->next
->child
) {
1055 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1057 } else if (MDOC_BODY
== n
->type
&& n
->child
)
1062 termp_fl_pre(DECL_ARGS
)
1065 term_fontpush(p
, TERMFONT_BOLD
);
1066 term_word(p
, "\\-");
1069 p
->flags
|= TERMP_NOSPACE
;
1070 else if (n
->next
&& n
->next
->line
== n
->line
)
1071 p
->flags
|= TERMP_NOSPACE
;
1077 termp__a_pre(DECL_ARGS
)
1080 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1081 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1082 term_word(p
, "and");
1088 termp_an_pre(DECL_ARGS
)
1091 if (NULL
== n
->child
)
1095 * If not in the AUTHORS section, `An -split' will cause
1096 * newlines to occur before the author name. If in the AUTHORS
1097 * section, by default, the first `An' invocation is nosplit,
1098 * then all subsequent ones, regardless of whether interspersed
1099 * with other macros/text, are split. -split, in this case,
1100 * will override the condition of the implied first -nosplit.
1103 if (n
->sec
== SEC_AUTHORS
) {
1104 if ( ! (TERMP_ANPREC
& p
->flags
)) {
1105 if (TERMP_SPLIT
& p
->flags
)
1109 if (TERMP_NOSPLIT
& p
->flags
)
1115 if (TERMP_SPLIT
& p
->flags
)
1122 termp_an_post(DECL_ARGS
)
1126 if (SEC_AUTHORS
== n
->sec
)
1127 p
->flags
|= TERMP_ANPREC
;
1131 if (AUTH_split
== n
->norm
->An
.auth
) {
1132 p
->flags
&= ~TERMP_NOSPLIT
;
1133 p
->flags
|= TERMP_SPLIT
;
1134 } else if (AUTH_nosplit
== n
->norm
->An
.auth
) {
1135 p
->flags
&= ~TERMP_SPLIT
;
1136 p
->flags
|= TERMP_NOSPLIT
;
1142 termp_ns_pre(DECL_ARGS
)
1145 if ( ! (MDOC_LINE
& n
->flags
))
1146 p
->flags
|= TERMP_NOSPACE
;
1151 termp_rs_pre(DECL_ARGS
)
1154 if (SEC_SEE_ALSO
!= n
->sec
)
1156 if (MDOC_BLOCK
== n
->type
&& n
->prev
)
1162 termp_rv_pre(DECL_ARGS
)
1167 term_word(p
, "The");
1170 for (n
= n
->child
; n
; n
= n
->next
) {
1171 term_fontpush(p
, TERMFONT_BOLD
);
1172 term_word(p
, n
->string
);
1175 p
->flags
|= TERMP_NOSPACE
;
1178 if (nchild
> 2 && n
->next
) {
1179 p
->flags
|= TERMP_NOSPACE
;
1183 if (n
->next
&& NULL
== n
->next
->next
)
1184 term_word(p
, "and");
1188 term_word(p
, "functions return");
1190 term_word(p
, "function returns");
1192 term_word(p
, "the value 0 if successful; otherwise the "
1193 "value -1 is returned and the global variable");
1195 term_fontpush(p
, TERMFONT_UNDER
);
1196 term_word(p
, "errno");
1199 term_word(p
, "is set to indicate the error.");
1200 p
->flags
|= TERMP_SENTENCE
;
1206 termp_ex_pre(DECL_ARGS
)
1211 term_word(p
, "The");
1214 for (n
= n
->child
; n
; n
= n
->next
) {
1215 term_fontpush(p
, TERMFONT_BOLD
);
1216 term_word(p
, n
->string
);
1219 if (nchild
> 2 && n
->next
) {
1220 p
->flags
|= TERMP_NOSPACE
;
1224 if (n
->next
&& NULL
== n
->next
->next
)
1225 term_word(p
, "and");
1229 term_word(p
, "utilities exit");
1231 term_word(p
, "utility exits");
1233 term_word(p
, "0 on success, and >0 if an error occurs.");
1235 p
->flags
|= TERMP_SENTENCE
;
1240 termp_nd_pre(DECL_ARGS
)
1243 if (MDOC_BODY
!= n
->type
)
1246 #if defined(__OpenBSD__) || defined(__linux__)
1247 term_word(p
, "\\(en");
1249 term_word(p
, "\\(em");
1255 termp_bl_pre(DECL_ARGS
)
1258 return(MDOC_HEAD
!= n
->type
);
1262 termp_bl_post(DECL_ARGS
)
1265 if (MDOC_BLOCK
== n
->type
)
1270 termp_xr_pre(DECL_ARGS
)
1273 if (NULL
== (n
= n
->child
))
1276 assert(MDOC_TEXT
== n
->type
);
1277 term_word(p
, n
->string
);
1279 if (NULL
== (n
= n
->next
))
1282 p
->flags
|= TERMP_NOSPACE
;
1284 p
->flags
|= TERMP_NOSPACE
;
1286 assert(MDOC_TEXT
== n
->type
);
1287 term_word(p
, n
->string
);
1289 p
->flags
|= TERMP_NOSPACE
;
1296 * This decides how to assert whitespace before any of the SYNOPSIS set
1297 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1301 synopsis_pre(struct termp
*p
, const struct mdoc_node
*n
)
1304 * Obviously, if we're not in a SYNOPSIS or no prior macros
1305 * exist, do nothing.
1307 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1311 * If we're the second in a pair of like elements, emit our
1312 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1313 * case we soldier on.
1315 if (n
->prev
->tok
== n
->tok
&&
1316 MDOC_Ft
!= n
->tok
&&
1317 MDOC_Fo
!= n
->tok
&&
1318 MDOC_Fn
!= n
->tok
) {
1324 * If we're one of the SYNOPSIS set and non-like pair-wise after
1325 * another (or Fn/Fo, which we've let slip through) then assert
1326 * vertical space, else only newline and move on.
1328 switch (n
->prev
->tok
) {
1341 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1353 termp_vt_pre(DECL_ARGS
)
1356 if (MDOC_ELEM
== n
->type
) {
1358 return(termp_under_pre(p
, pair
, meta
, n
));
1359 } else if (MDOC_BLOCK
== n
->type
) {
1362 } else if (MDOC_HEAD
== n
->type
)
1365 return(termp_under_pre(p
, pair
, meta
, n
));
1369 termp_bold_pre(DECL_ARGS
)
1372 term_fontpush(p
, TERMFONT_BOLD
);
1377 termp_fd_pre(DECL_ARGS
)
1381 return(termp_bold_pre(p
, pair
, meta
, n
));
1385 termp_fd_post(DECL_ARGS
)
1392 termp_sh_pre(DECL_ARGS
)
1395 /* No vspace between consecutive `Sh' calls. */
1399 if (n
->prev
&& MDOC_Sh
== n
->prev
->tok
)
1400 if (NULL
== n
->prev
->body
->child
)
1405 term_fontpush(p
, TERMFONT_BOLD
);
1408 p
->offset
= term_len(p
, p
->defindent
);
1409 if (SEC_AUTHORS
== n
->sec
)
1410 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1419 termp_sh_post(DECL_ARGS
)
1436 termp_bt_pre(DECL_ARGS
)
1439 term_word(p
, "is currently in beta test.");
1440 p
->flags
|= TERMP_SENTENCE
;
1445 termp_lb_post(DECL_ARGS
)
1448 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1453 termp_ud_pre(DECL_ARGS
)
1456 term_word(p
, "currently under development.");
1457 p
->flags
|= TERMP_SENTENCE
;
1462 termp_d1_pre(DECL_ARGS
)
1465 if (MDOC_BLOCK
!= n
->type
)
1468 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1473 termp_ft_pre(DECL_ARGS
)
1476 /* NB: MDOC_LINE does not effect this! */
1478 term_fontpush(p
, TERMFONT_UNDER
);
1483 termp_fn_pre(DECL_ARGS
)
1488 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1492 if (NULL
== (n
= n
->child
))
1496 rmargin
= p
->rmargin
;
1497 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1498 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1501 assert(MDOC_TEXT
== n
->type
);
1502 term_fontpush(p
, TERMFONT_BOLD
);
1503 term_word(p
, n
->string
);
1508 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1509 p
->offset
= p
->rmargin
;
1510 p
->rmargin
= rmargin
;
1513 p
->flags
|= TERMP_NOSPACE
;
1515 p
->flags
|= TERMP_NOSPACE
;
1517 for (n
= n
->next
; n
; n
= n
->next
) {
1518 assert(MDOC_TEXT
== n
->type
);
1519 term_fontpush(p
, TERMFONT_UNDER
);
1521 p
->flags
|= TERMP_NBRWORD
;
1522 term_word(p
, n
->string
);
1526 p
->flags
|= TERMP_NOSPACE
;
1531 p
->flags
|= TERMP_NOSPACE
;
1535 p
->flags
|= TERMP_NOSPACE
;
1544 termp_fa_pre(DECL_ARGS
)
1546 const struct mdoc_node
*nn
;
1548 if (n
->parent
->tok
!= MDOC_Fo
) {
1549 term_fontpush(p
, TERMFONT_UNDER
);
1553 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1554 term_fontpush(p
, TERMFONT_UNDER
);
1555 p
->flags
|= TERMP_NBRWORD
;
1556 term_word(p
, nn
->string
);
1559 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1560 p
->flags
|= TERMP_NOSPACE
;
1569 termp_bd_pre(DECL_ARGS
)
1571 size_t tabwidth
, rm
, rmax
;
1572 struct mdoc_node
*nn
;
1574 if (MDOC_BLOCK
== n
->type
) {
1575 print_bvspace(p
, n
, n
);
1577 } else if (MDOC_HEAD
== n
->type
)
1580 if (n
->norm
->Bd
.offs
)
1581 p
->offset
+= a2offs(p
, n
->norm
->Bd
.offs
);
1584 * If -ragged or -filled are specified, the block does nothing
1585 * but change the indentation. If -unfilled or -literal are
1586 * specified, text is printed exactly as entered in the display:
1587 * for macro lines, a newline is appended to the line. Blank
1588 * lines are allowed.
1591 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1592 DISP_unfilled
!= n
->norm
->Bd
.type
)
1595 tabwidth
= p
->tabwidth
;
1596 if (DISP_literal
== n
->norm
->Bd
.type
)
1597 p
->tabwidth
= term_len(p
, 8);
1600 rmax
= p
->maxrmargin
;
1601 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1603 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1604 print_mdoc_node(p
, pair
, meta
, nn
);
1606 * If the printed node flushes its own line, then we
1607 * needn't do it here as well. This is hacky, but the
1608 * notion of selective eoln whitespace is pretty dumb
1609 * anyway, so don't sweat it.
1631 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1634 p
->flags
|= TERMP_NOSPACE
;
1637 p
->tabwidth
= tabwidth
;
1639 p
->maxrmargin
= rmax
;
1644 termp_bd_post(DECL_ARGS
)
1648 if (MDOC_BODY
!= n
->type
)
1652 rmax
= p
->maxrmargin
;
1654 if (DISP_literal
== n
->norm
->Bd
.type
||
1655 DISP_unfilled
== n
->norm
->Bd
.type
)
1656 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1658 p
->flags
|= TERMP_NOSPACE
;
1662 p
->maxrmargin
= rmax
;
1666 termp_bx_pre(DECL_ARGS
)
1669 if (NULL
!= (n
= n
->child
)) {
1670 term_word(p
, n
->string
);
1671 p
->flags
|= TERMP_NOSPACE
;
1672 term_word(p
, "BSD");
1674 term_word(p
, "BSD");
1678 if (NULL
!= (n
= n
->next
)) {
1679 p
->flags
|= TERMP_NOSPACE
;
1681 p
->flags
|= TERMP_NOSPACE
;
1682 term_word(p
, n
->string
);
1689 termp_xx_pre(DECL_ARGS
)
1722 p
->flags
|= TERMP_KEEP
;
1723 term_word(p
, n
->child
->string
);
1730 termp_pf_post(DECL_ARGS
)
1733 p
->flags
|= TERMP_NOSPACE
;
1737 termp_ss_pre(DECL_ARGS
)
1747 term_fontpush(p
, TERMFONT_BOLD
);
1748 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1758 termp_ss_post(DECL_ARGS
)
1761 if (MDOC_HEAD
== n
->type
)
1766 termp_cd_pre(DECL_ARGS
)
1770 term_fontpush(p
, TERMFONT_BOLD
);
1775 termp_in_pre(DECL_ARGS
)
1780 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1781 term_fontpush(p
, TERMFONT_BOLD
);
1782 term_word(p
, "#include");
1786 term_fontpush(p
, TERMFONT_UNDER
);
1789 p
->flags
|= TERMP_NOSPACE
;
1794 termp_in_post(DECL_ARGS
)
1797 if (MDOC_SYNPRETTY
& n
->flags
)
1798 term_fontpush(p
, TERMFONT_BOLD
);
1800 p
->flags
|= TERMP_NOSPACE
;
1803 if (MDOC_SYNPRETTY
& n
->flags
)
1808 termp_sp_pre(DECL_ARGS
)
1814 len
= n
->child
? a2height(p
, n
->child
->string
) : 1;
1826 for (i
= 0; i
< len
; i
++)
1833 termp_es_pre(DECL_ARGS
)
1840 termp_quote_pre(DECL_ARGS
)
1843 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1869 term_word(p
, "\\(lq");
1872 if (NULL
== n
->norm
->Es
||
1873 NULL
== n
->norm
->Es
->child
)
1875 term_word(p
, n
->norm
->Es
->child
->string
);
1896 term_word(p
, "\\(oq");
1903 p
->flags
|= TERMP_NOSPACE
;
1908 termp_quote_post(DECL_ARGS
)
1911 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1914 if (MDOC_En
!= n
->tok
)
1915 p
->flags
|= TERMP_NOSPACE
;
1940 term_word(p
, "\\(rq");
1943 if (NULL
!= n
->norm
->Es
&&
1944 NULL
!= n
->norm
->Es
->child
&&
1945 NULL
!= n
->norm
->Es
->child
->next
) {
1946 p
->flags
|= TERMP_NOSPACE
;
1947 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1969 term_word(p
, "\\(cq");
1978 termp_fo_pre(DECL_ARGS
)
1983 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1985 if (MDOC_BLOCK
== n
->type
) {
1988 } else if (MDOC_BODY
== n
->type
) {
1990 rmargin
= p
->rmargin
;
1991 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1992 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
1995 p
->flags
|= TERMP_NOSPACE
;
1997 p
->flags
|= TERMP_NOSPACE
;
2000 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2002 p
->offset
= p
->rmargin
;
2003 p
->rmargin
= rmargin
;
2008 if (NULL
== n
->child
)
2011 /* XXX: we drop non-initial arguments as per groff. */
2013 assert(n
->child
->string
);
2014 term_fontpush(p
, TERMFONT_BOLD
);
2015 term_word(p
, n
->child
->string
);
2020 termp_fo_post(DECL_ARGS
)
2023 if (MDOC_BODY
!= n
->type
)
2026 p
->flags
|= TERMP_NOSPACE
;
2029 if (MDOC_SYNPRETTY
& n
->flags
) {
2030 p
->flags
|= TERMP_NOSPACE
;
2037 termp_bf_pre(DECL_ARGS
)
2040 if (MDOC_HEAD
== n
->type
)
2042 else if (MDOC_BODY
!= n
->type
)
2045 if (FONT_Em
== n
->norm
->Bf
.font
)
2046 term_fontpush(p
, TERMFONT_UNDER
);
2047 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2048 term_fontpush(p
, TERMFONT_BOLD
);
2050 term_fontpush(p
, TERMFONT_NONE
);
2056 termp_sm_pre(DECL_ARGS
)
2059 if (NULL
== n
->child
)
2060 p
->flags
^= TERMP_NONOSPACE
;
2061 else if (0 == strcmp("on", n
->child
->string
))
2062 p
->flags
&= ~TERMP_NONOSPACE
;
2064 p
->flags
|= TERMP_NONOSPACE
;
2066 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2067 p
->flags
&= ~TERMP_NOSPACE
;
2073 termp_ap_pre(DECL_ARGS
)
2076 p
->flags
|= TERMP_NOSPACE
;
2078 p
->flags
|= TERMP_NOSPACE
;
2083 termp____post(DECL_ARGS
)
2087 * Handle lists of authors. In general, print each followed by
2088 * a comma. Don't print the comma if there are only two
2091 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2092 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2093 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2098 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2101 p
->flags
|= TERMP_NOSPACE
;
2102 if (NULL
== n
->next
) {
2104 p
->flags
|= TERMP_SENTENCE
;
2110 termp_li_pre(DECL_ARGS
)
2113 term_fontpush(p
, TERMFONT_NONE
);
2118 termp_lk_pre(DECL_ARGS
)
2120 const struct mdoc_node
*link
, *descr
;
2122 if (NULL
== (link
= n
->child
))
2125 if (NULL
!= (descr
= link
->next
)) {
2126 term_fontpush(p
, TERMFONT_UNDER
);
2127 while (NULL
!= descr
) {
2128 term_word(p
, descr
->string
);
2129 descr
= descr
->next
;
2131 p
->flags
|= TERMP_NOSPACE
;
2136 term_fontpush(p
, TERMFONT_BOLD
);
2137 term_word(p
, link
->string
);
2144 termp_bk_pre(DECL_ARGS
)
2153 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2154 p
->flags
|= TERMP_PREKEEP
;
2165 termp_bk_post(DECL_ARGS
)
2168 if (MDOC_BODY
== n
->type
)
2169 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2173 termp__t_post(DECL_ARGS
)
2177 * If we're in an `Rs' and there's a journal present, then quote
2178 * us instead of underlining us (for disambiguation).
2180 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2181 n
->parent
->norm
->Rs
.quote_T
)
2182 termp_quote_post(p
, pair
, meta
, n
);
2184 termp____post(p
, pair
, meta
, n
);
2188 termp__t_pre(DECL_ARGS
)
2192 * If we're in an `Rs' and there's a journal present, then quote
2193 * us instead of underlining us (for disambiguation).
2195 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2196 n
->parent
->norm
->Rs
.quote_T
)
2197 return(termp_quote_pre(p
, pair
, meta
, n
));
2199 term_fontpush(p
, TERMFONT_UNDER
);
2204 termp_under_pre(DECL_ARGS
)
2207 term_fontpush(p
, TERMFONT_UNDER
);