]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.286 2014/10/20 15:50:24 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 *);
54 static size_t a2offs(const struct termp
*, const char *);
56 static void print_bvspace(struct termp
*,
57 const struct mdoc_node
*,
58 const struct mdoc_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 void *);
62 static void print_mdoc_foot(struct termp
*, const void *);
63 static void synopsis_pre(struct termp
*,
64 const struct mdoc_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_fd_post(DECL_ARGS
);
72 static void termp_fo_post(DECL_ARGS
);
73 static void termp_in_post(DECL_ARGS
);
74 static void termp_it_post(DECL_ARGS
);
75 static void termp_lb_post(DECL_ARGS
);
76 static void termp_nm_post(DECL_ARGS
);
77 static void termp_pf_post(DECL_ARGS
);
78 static void termp_quote_post(DECL_ARGS
);
79 static void termp_sh_post(DECL_ARGS
);
80 static void termp_ss_post(DECL_ARGS
);
82 static int termp__a_pre(DECL_ARGS
);
83 static int termp__t_pre(DECL_ARGS
);
84 static int termp_an_pre(DECL_ARGS
);
85 static int termp_ap_pre(DECL_ARGS
);
86 static int termp_bd_pre(DECL_ARGS
);
87 static int termp_bf_pre(DECL_ARGS
);
88 static int termp_bk_pre(DECL_ARGS
);
89 static int termp_bl_pre(DECL_ARGS
);
90 static int termp_bold_pre(DECL_ARGS
);
91 static int termp_bt_pre(DECL_ARGS
);
92 static int termp_bx_pre(DECL_ARGS
);
93 static int termp_cd_pre(DECL_ARGS
);
94 static int termp_d1_pre(DECL_ARGS
);
95 static int termp_es_pre(DECL_ARGS
);
96 static int termp_ex_pre(DECL_ARGS
);
97 static int termp_fa_pre(DECL_ARGS
);
98 static int termp_fd_pre(DECL_ARGS
);
99 static int termp_fl_pre(DECL_ARGS
);
100 static int termp_fn_pre(DECL_ARGS
);
101 static int termp_fo_pre(DECL_ARGS
);
102 static int termp_ft_pre(DECL_ARGS
);
103 static int termp_in_pre(DECL_ARGS
);
104 static int termp_it_pre(DECL_ARGS
);
105 static int termp_li_pre(DECL_ARGS
);
106 static int termp_ll_pre(DECL_ARGS
);
107 static int termp_lk_pre(DECL_ARGS
);
108 static int termp_nd_pre(DECL_ARGS
);
109 static int termp_nm_pre(DECL_ARGS
);
110 static int termp_ns_pre(DECL_ARGS
);
111 static int termp_quote_pre(DECL_ARGS
);
112 static int termp_rs_pre(DECL_ARGS
);
113 static int termp_rv_pre(DECL_ARGS
);
114 static int termp_sh_pre(DECL_ARGS
);
115 static int termp_sm_pre(DECL_ARGS
);
116 static int termp_sp_pre(DECL_ARGS
);
117 static int termp_ss_pre(DECL_ARGS
);
118 static int termp_under_pre(DECL_ARGS
);
119 static int termp_ud_pre(DECL_ARGS
);
120 static int termp_vt_pre(DECL_ARGS
);
121 static int termp_xr_pre(DECL_ARGS
);
122 static int termp_xx_pre(DECL_ARGS
);
124 static const struct termact termacts
[MDOC_MAX
] = {
125 { termp_ap_pre
, NULL
}, /* Ap */
126 { NULL
, NULL
}, /* Dd */
127 { NULL
, NULL
}, /* Dt */
128 { NULL
, NULL
}, /* Os */
129 { termp_sh_pre
, termp_sh_post
}, /* Sh */
130 { termp_ss_pre
, termp_ss_post
}, /* Ss */
131 { termp_sp_pre
, NULL
}, /* Pp */
132 { termp_d1_pre
, termp_bl_post
}, /* D1 */
133 { termp_d1_pre
, termp_bl_post
}, /* Dl */
134 { termp_bd_pre
, termp_bd_post
}, /* Bd */
135 { NULL
, NULL
}, /* Ed */
136 { termp_bl_pre
, termp_bl_post
}, /* Bl */
137 { NULL
, NULL
}, /* El */
138 { termp_it_pre
, termp_it_post
}, /* It */
139 { termp_under_pre
, NULL
}, /* Ad */
140 { termp_an_pre
, NULL
}, /* An */
141 { termp_under_pre
, NULL
}, /* Ar */
142 { termp_cd_pre
, NULL
}, /* Cd */
143 { termp_bold_pre
, NULL
}, /* Cm */
144 { NULL
, NULL
}, /* Dv */
145 { NULL
, NULL
}, /* Er */
146 { NULL
, NULL
}, /* Ev */
147 { termp_ex_pre
, NULL
}, /* Ex */
148 { termp_fa_pre
, NULL
}, /* Fa */
149 { termp_fd_pre
, termp_fd_post
}, /* Fd */
150 { termp_fl_pre
, NULL
}, /* Fl */
151 { termp_fn_pre
, NULL
}, /* Fn */
152 { termp_ft_pre
, NULL
}, /* Ft */
153 { termp_bold_pre
, NULL
}, /* Ic */
154 { termp_in_pre
, termp_in_post
}, /* In */
155 { termp_li_pre
, NULL
}, /* Li */
156 { termp_nd_pre
, NULL
}, /* Nd */
157 { termp_nm_pre
, termp_nm_post
}, /* Nm */
158 { termp_quote_pre
, termp_quote_post
}, /* Op */
159 { termp_ft_pre
, NULL
}, /* Ot */
160 { termp_under_pre
, NULL
}, /* Pa */
161 { termp_rv_pre
, NULL
}, /* Rv */
162 { NULL
, NULL
}, /* St */
163 { termp_under_pre
, NULL
}, /* Va */
164 { termp_vt_pre
, NULL
}, /* Vt */
165 { termp_xr_pre
, NULL
}, /* Xr */
166 { termp__a_pre
, termp____post
}, /* %A */
167 { termp_under_pre
, termp____post
}, /* %B */
168 { NULL
, termp____post
}, /* %D */
169 { termp_under_pre
, termp____post
}, /* %I */
170 { termp_under_pre
, termp____post
}, /* %J */
171 { NULL
, termp____post
}, /* %N */
172 { NULL
, termp____post
}, /* %O */
173 { NULL
, termp____post
}, /* %P */
174 { NULL
, termp____post
}, /* %R */
175 { termp__t_pre
, termp__t_post
}, /* %T */
176 { NULL
, termp____post
}, /* %V */
177 { NULL
, NULL
}, /* Ac */
178 { termp_quote_pre
, termp_quote_post
}, /* Ao */
179 { termp_quote_pre
, termp_quote_post
}, /* Aq */
180 { NULL
, NULL
}, /* At */
181 { NULL
, NULL
}, /* Bc */
182 { termp_bf_pre
, NULL
}, /* Bf */
183 { termp_quote_pre
, termp_quote_post
}, /* Bo */
184 { termp_quote_pre
, termp_quote_post
}, /* Bq */
185 { termp_xx_pre
, NULL
}, /* Bsx */
186 { termp_bx_pre
, NULL
}, /* Bx */
187 { NULL
, NULL
}, /* Db */
188 { NULL
, NULL
}, /* Dc */
189 { termp_quote_pre
, termp_quote_post
}, /* Do */
190 { termp_quote_pre
, termp_quote_post
}, /* Dq */
191 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
192 { NULL
, NULL
}, /* Ef */
193 { termp_under_pre
, NULL
}, /* Em */
194 { termp_quote_pre
, termp_quote_post
}, /* Eo */
195 { termp_xx_pre
, NULL
}, /* Fx */
196 { termp_bold_pre
, NULL
}, /* Ms */
197 { NULL
, NULL
}, /* No */
198 { termp_ns_pre
, NULL
}, /* Ns */
199 { termp_xx_pre
, NULL
}, /* Nx */
200 { termp_xx_pre
, NULL
}, /* Ox */
201 { NULL
, NULL
}, /* Pc */
202 { NULL
, termp_pf_post
}, /* Pf */
203 { termp_quote_pre
, termp_quote_post
}, /* Po */
204 { termp_quote_pre
, termp_quote_post
}, /* Pq */
205 { NULL
, NULL
}, /* Qc */
206 { termp_quote_pre
, termp_quote_post
}, /* Ql */
207 { termp_quote_pre
, termp_quote_post
}, /* Qo */
208 { termp_quote_pre
, termp_quote_post
}, /* Qq */
209 { NULL
, NULL
}, /* Re */
210 { termp_rs_pre
, NULL
}, /* Rs */
211 { NULL
, NULL
}, /* Sc */
212 { termp_quote_pre
, termp_quote_post
}, /* So */
213 { termp_quote_pre
, termp_quote_post
}, /* Sq */
214 { termp_sm_pre
, NULL
}, /* Sm */
215 { termp_under_pre
, NULL
}, /* Sx */
216 { termp_bold_pre
, NULL
}, /* Sy */
217 { NULL
, NULL
}, /* Tn */
218 { termp_xx_pre
, NULL
}, /* Ux */
219 { NULL
, NULL
}, /* Xc */
220 { NULL
, NULL
}, /* Xo */
221 { termp_fo_pre
, termp_fo_post
}, /* Fo */
222 { NULL
, NULL
}, /* Fc */
223 { termp_quote_pre
, termp_quote_post
}, /* Oo */
224 { NULL
, NULL
}, /* Oc */
225 { termp_bk_pre
, termp_bk_post
}, /* Bk */
226 { NULL
, NULL
}, /* Ek */
227 { termp_bt_pre
, NULL
}, /* Bt */
228 { NULL
, NULL
}, /* Hf */
229 { termp_under_pre
, NULL
}, /* Fr */
230 { termp_ud_pre
, NULL
}, /* Ud */
231 { NULL
, termp_lb_post
}, /* Lb */
232 { termp_sp_pre
, NULL
}, /* Lp */
233 { termp_lk_pre
, NULL
}, /* Lk */
234 { termp_under_pre
, NULL
}, /* Mt */
235 { termp_quote_pre
, termp_quote_post
}, /* Brq */
236 { termp_quote_pre
, termp_quote_post
}, /* Bro */
237 { NULL
, NULL
}, /* Brc */
238 { NULL
, termp____post
}, /* %C */
239 { termp_es_pre
, NULL
}, /* Es */
240 { termp_quote_pre
, termp_quote_post
}, /* En */
241 { termp_xx_pre
, NULL
}, /* Dx */
242 { NULL
, termp____post
}, /* %Q */
243 { termp_sp_pre
, NULL
}, /* br */
244 { termp_sp_pre
, NULL
}, /* sp */
245 { NULL
, termp____post
}, /* %U */
246 { NULL
, NULL
}, /* Ta */
247 { termp_ll_pre
, NULL
}, /* ll */
252 terminal_mdoc(void *arg
, const struct mdoc
*mdoc
)
254 const struct mdoc_meta
*meta
;
258 p
= (struct termp
*)arg
;
261 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
262 p
->tabwidth
= term_len(p
, 5);
264 if (NULL
== p
->symtab
)
265 p
->symtab
= mchars_alloc();
267 n
= mdoc_node(mdoc
)->child
;
268 meta
= mdoc_meta(mdoc
);
270 if (p
->synopsisonly
) {
272 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
273 if (n
->child
->next
->child
!= NULL
)
274 print_mdoc_nodelist(p
, NULL
,
275 meta
, n
->child
->next
->child
);
282 if (p
->defindent
== 0)
284 term_begin(p
, print_mdoc_head
, print_mdoc_foot
, meta
);
286 if (n
->tok
!= MDOC_Sh
)
288 print_mdoc_nodelist(p
, NULL
, meta
, n
);
295 print_mdoc_nodelist(DECL_ARGS
)
298 print_mdoc_node(p
, pair
, meta
, n
);
300 print_mdoc_nodelist(p
, pair
, meta
, n
->next
);
304 print_mdoc_node(DECL_ARGS
)
307 struct termpair npair
;
308 size_t offset
, rmargin
;
312 rmargin
= p
->rmargin
;
313 n
->prev_font
= term_fontq(p
);
315 memset(&npair
, 0, sizeof(struct termpair
));
319 * Keeps only work until the end of a line. If a keep was
320 * invoked in a prior line, revert it to PREKEEP.
323 if (TERMP_KEEP
& p
->flags
) {
324 if (n
->prev
? (n
->prev
->lastline
!= n
->line
) :
325 (n
->parent
&& n
->parent
->line
!= n
->line
)) {
326 p
->flags
&= ~TERMP_KEEP
;
327 p
->flags
|= TERMP_PREKEEP
;
332 * After the keep flags have been set up, we may now
333 * produce output. Note that some pre-handlers do so.
338 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
340 if (MDOC_DELIMC
& n
->flags
)
341 p
->flags
|= TERMP_NOSPACE
;
342 term_word(p
, n
->string
);
343 if (MDOC_DELIMO
& n
->flags
)
344 p
->flags
|= TERMP_NOSPACE
;
347 if ( ! (n
->flags
& MDOC_LINE
))
348 p
->flags
|= TERMP_NOSPACE
;
350 if (n
->next
!= NULL
&& ! (n
->next
->flags
& MDOC_LINE
))
351 p
->flags
|= TERMP_NOSPACE
;
354 term_tbl(p
, n
->span
);
357 if (termacts
[n
->tok
].pre
&& ENDBODY_NOT
== n
->end
)
358 chld
= (*termacts
[n
->tok
].pre
)
359 (p
, &npair
, meta
, n
);
363 if (chld
&& n
->child
)
364 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
367 (ENDBODY_NOT
== n
->end
? n
: n
->pending
)->prev_font
);
377 if ( ! termacts
[n
->tok
].post
|| MDOC_ENDED
& n
->flags
)
379 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
382 * Explicit end tokens not only call the post
383 * handler, but also tell the respective block
384 * that it must not call the post handler again.
386 if (ENDBODY_NOT
!= n
->end
)
387 n
->pending
->flags
|= MDOC_ENDED
;
390 * End of line terminating an implicit block
391 * while an explicit block is still open.
392 * Continue the explicit block without spacing.
394 if (ENDBODY_NOSPACE
== n
->end
)
395 p
->flags
|= TERMP_NOSPACE
;
399 if (MDOC_EOS
& n
->flags
)
400 p
->flags
|= TERMP_SENTENCE
;
402 if (MDOC_ll
!= n
->tok
) {
404 p
->rmargin
= rmargin
;
409 print_mdoc_foot(struct termp
*p
, const void *arg
)
411 const struct mdoc_meta
*meta
;
413 meta
= (const struct mdoc_meta
*)arg
;
415 term_fontrepl(p
, TERMFONT_NONE
);
418 * Output the footer in new-groff style, that is, three columns
419 * with the middle being the manual date and flanking columns
420 * being the operating system:
428 p
->rmargin
= (p
->maxrmargin
-
429 term_strlen(p
, meta
->date
) + term_len(p
, 1)) / 2;
431 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
433 term_word(p
, meta
->os
);
436 p
->offset
= p
->rmargin
;
437 p
->rmargin
= p
->maxrmargin
- term_strlen(p
, meta
->os
);
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 p
->maxrmargin
- vollen
;
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 a2offs(const struct termp
*p
, const char *v
)
563 else if (0 == strcmp(v
, "left"))
565 else if (0 == strcmp(v
, "indent"))
566 return(term_len(p
, p
->defindent
+ 1));
567 else if (0 == strcmp(v
, "indent-two"))
568 return(term_len(p
, (p
->defindent
+ 1) * 2));
569 else if ( ! a2roffsu(v
, &su
, SCALE_MAX
)) {
570 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
571 su
.scale
/= term_strlen(p
, "0");
574 return(term_hspan(p
, &su
));
578 * Determine how much space to print out before block elements of `It'
579 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
583 print_bvspace(struct termp
*p
,
584 const struct mdoc_node
*bl
,
585 const struct mdoc_node
*n
)
587 const struct mdoc_node
*nn
;
593 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
595 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
598 /* Do not vspace directly after Ss/Sh. */
600 for (nn
= n
; nn
; nn
= nn
->parent
) {
601 if (MDOC_BLOCK
!= nn
->type
)
603 if (MDOC_Ss
== nn
->tok
)
605 if (MDOC_Sh
== nn
->tok
)
607 if (NULL
== nn
->prev
)
612 /* A `-column' does not assert vspace within the list. */
614 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
615 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
618 /* A `-diag' without body does not vspace. */
620 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
621 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
622 assert(n
->prev
->body
);
623 if (NULL
== n
->prev
->body
->child
)
632 termp_ll_pre(DECL_ARGS
)
635 term_setwidth(p
, n
->nchild
? n
->child
->string
: NULL
);
640 termp_it_pre(DECL_ARGS
)
642 const struct mdoc_node
*bl
, *nn
;
645 size_t width
, offset
, ncols
, dcol
;
648 if (MDOC_BLOCK
== n
->type
) {
649 print_bvspace(p
, n
->parent
->parent
, n
);
653 bl
= n
->parent
->parent
->parent
;
654 type
= bl
->norm
->Bl
.type
;
657 * First calculate width and offset. This is pretty easy unless
658 * we're a -column list, in which case all prior columns must
664 if (bl
->norm
->Bl
.offs
)
665 offset
= a2offs(p
, bl
->norm
->Bl
.offs
);
669 if (MDOC_HEAD
== n
->type
)
673 * Imitate groff's column handling:
674 * - For each earlier column, add its width.
675 * - For less than 5 columns, add four more blanks per
677 * - For exactly 5 columns, add three more blank per
679 * - For more than 5 columns, add only one column.
681 ncols
= bl
->norm
->Bl
.ncols
;
682 dcol
= ncols
< 5 ? term_len(p
, 4) :
683 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
686 * Calculate the offset by applying all prior MDOC_BODY,
687 * so we stop at the MDOC_HEAD (NULL == nn->prev).
690 for (i
= 0, nn
= n
->prev
;
691 nn
->prev
&& i
< (int)ncols
;
693 offset
+= dcol
+ a2width(p
,
694 bl
->norm
->Bl
.cols
[i
]);
697 * When exceeding the declared number of columns, leave
698 * the remaining widths at 0. This will later be
699 * adjusted to the default width of 10, or, for the last
700 * column, stretched to the right margin.
706 * Use the declared column widths, extended as explained
707 * in the preceding paragraph.
709 width
= a2width(p
, bl
->norm
->Bl
.cols
[i
]) + dcol
;
712 if (NULL
== bl
->norm
->Bl
.width
)
716 * Note: buffer the width by 2, which is groff's magic
717 * number for buffering single arguments. See the above
718 * handling for column for how this changes.
720 assert(bl
->norm
->Bl
.width
);
721 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
726 * List-type can override the width in the case of fixed-head
727 * values (bullet, dash/hyphen, enum). Tags need a non-zero
739 if (width
< term_len(p
, 2))
740 width
= term_len(p
, 2);
744 width
= term_len(p
, 8);
750 width
= term_len(p
, 10);
757 * Whitespace control. Inset bodies need an initial space,
758 * while diagonal bodies need two.
761 p
->flags
|= TERMP_NOSPACE
;
765 if (MDOC_BODY
== n
->type
)
766 term_word(p
, "\\ \\ ");
769 if (MDOC_BODY
== n
->type
&& n
->parent
->head
->nchild
)
776 p
->flags
|= TERMP_NOSPACE
;
780 if (MDOC_HEAD
== n
->type
)
781 term_fontpush(p
, TERMFONT_BOLD
);
788 * Pad and break control. This is the tricky part. These flags
789 * are documented in term_flushln() in term.c. Note that we're
790 * going to unset all of these flags in termp_it_post() when we
797 * Weird special case.
798 * Very narrow enum lists actually hang.
800 if (width
== term_len(p
, 2))
801 p
->flags
|= TERMP_HANG
;
808 if (MDOC_HEAD
!= n
->type
)
810 p
->flags
|= TERMP_NOBREAK
;
814 if (MDOC_HEAD
!= n
->type
)
818 * This is ugly. If `-hang' is specified and the body
819 * is a `Bl' or `Bd', then we want basically to nullify
820 * the "overstep" effect in term_flushln() and treat
821 * this as a `-ohang' list instead.
823 if (NULL
!= n
->next
&&
824 NULL
!= n
->next
->child
&&
825 (MDOC_Bl
== n
->next
->child
->tok
||
826 MDOC_Bd
== n
->next
->child
->tok
))
829 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
833 if (MDOC_HEAD
!= n
->type
)
836 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
839 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
840 p
->flags
|= TERMP_DANGLE
;
843 if (MDOC_HEAD
== n
->type
)
846 if (NULL
== n
->next
) {
847 p
->flags
&= ~TERMP_NOBREAK
;
850 p
->flags
|= TERMP_NOBREAK
;
856 if (MDOC_HEAD
!= n
->type
)
858 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
866 * Margin control. Set-head-width lists have their right
867 * margins shortened. The body for these lists has the offset
868 * necessarily lengthened. Everybody gets the offset.
876 * Same stipulation as above, regarding `-hang'. We
877 * don't want to recalculate rmargin and offsets when
878 * using `Bd' or `Bl' within `-hang' overstep lists.
880 if (MDOC_HEAD
== n
->type
&&
882 NULL
!= n
->next
->child
&&
883 (MDOC_Bl
== n
->next
->child
->tok
||
884 MDOC_Bd
== n
->next
->child
->tok
))
897 if (MDOC_HEAD
== n
->type
)
898 p
->rmargin
= p
->offset
+ width
;
901 if (p
->rmargin
< p
->offset
)
902 p
->rmargin
= p
->offset
;
907 p
->rmargin
= p
->offset
+ width
;
909 * XXX - this behaviour is not documented: the
910 * right-most column is filled to the right margin.
912 if (MDOC_HEAD
== n
->type
)
914 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
915 p
->rmargin
= p
->maxrmargin
;
922 * The dash, hyphen, bullet and enum lists all have a special
923 * HEAD character (temporarily bold, in some cases).
926 if (MDOC_HEAD
== n
->type
)
929 term_fontpush(p
, TERMFONT_BOLD
);
930 term_word(p
, "\\[bu]");
936 term_fontpush(p
, TERMFONT_BOLD
);
937 term_word(p
, "\\(hy");
941 (pair
->ppair
->ppair
->count
)++;
942 (void)snprintf(buf
, sizeof(buf
), "%d.",
943 pair
->ppair
->ppair
->count
);
951 * If we're not going to process our children, indicate so here.
964 if (MDOC_HEAD
== n
->type
)
968 if (MDOC_HEAD
== n
->type
)
979 termp_it_post(DECL_ARGS
)
983 if (MDOC_BLOCK
== n
->type
)
986 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
994 if (MDOC_BODY
== n
->type
)
998 if (MDOC_BODY
== n
->type
)
1007 * Now that our output is flushed, we can reset our tags. Since
1008 * only `It' sets these flags, we're free to assume that nobody
1009 * has munged them in the meanwhile.
1012 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
1013 TERMP_DANGLE
| TERMP_HANG
);
1018 termp_nm_pre(DECL_ARGS
)
1021 if (MDOC_BLOCK
== n
->type
) {
1022 p
->flags
|= TERMP_PREKEEP
;
1026 if (MDOC_BODY
== n
->type
) {
1027 if (NULL
== n
->child
)
1029 p
->flags
|= TERMP_NOSPACE
;
1030 p
->offset
+= term_len(p
, 1) +
1031 (NULL
== n
->prev
->child
?
1032 term_strlen(p
, meta
->name
) :
1033 MDOC_TEXT
== n
->prev
->child
->type
?
1034 term_strlen(p
, n
->prev
->child
->string
) :
1036 if (p
->rmargin
< p
->offset
)
1037 p
->rmargin
= p
->offset
;
1041 if (NULL
== n
->child
&& NULL
== meta
->name
)
1044 if (MDOC_HEAD
== n
->type
)
1045 synopsis_pre(p
, n
->parent
);
1047 if (MDOC_HEAD
== n
->type
&&
1048 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1049 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1051 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1052 if (NULL
== n
->child
) {
1053 p
->rmargin
+= term_strlen(p
, meta
->name
);
1054 } else if (MDOC_TEXT
== n
->child
->type
) {
1055 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1057 p
->flags
|= TERMP_HANG
;
1059 p
->rmargin
+= term_len(p
, 5);
1060 p
->flags
|= TERMP_HANG
;
1064 term_fontpush(p
, TERMFONT_BOLD
);
1065 if (NULL
== n
->child
)
1066 term_word(p
, meta
->name
);
1071 termp_nm_post(DECL_ARGS
)
1074 if (MDOC_BLOCK
== n
->type
) {
1075 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1076 } else if (MDOC_HEAD
== n
->type
&&
1077 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1079 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1081 } else if (MDOC_BODY
== n
->type
&& n
->child
)
1086 termp_fl_pre(DECL_ARGS
)
1089 term_fontpush(p
, TERMFONT_BOLD
);
1090 term_word(p
, "\\-");
1092 if ( ! (n
->nchild
== 0 &&
1094 n
->next
->type
== MDOC_TEXT
||
1095 n
->next
->flags
& MDOC_LINE
)))
1096 p
->flags
|= TERMP_NOSPACE
;
1102 termp__a_pre(DECL_ARGS
)
1105 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1106 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1107 term_word(p
, "and");
1113 termp_an_pre(DECL_ARGS
)
1116 if (n
->norm
->An
.auth
== AUTH_split
) {
1117 p
->flags
&= ~TERMP_NOSPLIT
;
1118 p
->flags
|= TERMP_SPLIT
;
1121 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1122 p
->flags
&= ~TERMP_SPLIT
;
1123 p
->flags
|= TERMP_NOSPLIT
;
1127 if (n
->child
== NULL
)
1130 if (p
->flags
& TERMP_SPLIT
)
1133 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1134 p
->flags
|= TERMP_SPLIT
;
1140 termp_ns_pre(DECL_ARGS
)
1143 if ( ! (MDOC_LINE
& n
->flags
))
1144 p
->flags
|= TERMP_NOSPACE
;
1149 termp_rs_pre(DECL_ARGS
)
1152 if (SEC_SEE_ALSO
!= n
->sec
)
1154 if (MDOC_BLOCK
== n
->type
&& n
->prev
)
1160 termp_rv_pre(DECL_ARGS
)
1168 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 (n
->next
== NULL
)
1182 p
->flags
|= TERMP_NOSPACE
;
1185 if (n
->next
->next
== NULL
)
1186 term_word(p
, "and");
1190 term_word(p
, "functions return");
1192 term_word(p
, "function returns");
1194 term_word(p
, "the value\\~0 if successful;");
1196 term_word(p
, "Upon successful completion,"
1197 " the value\\~0 is returned;");
1199 term_word(p
, "otherwise the value\\~\\-1 is returned"
1200 " and the global variable");
1202 term_fontpush(p
, TERMFONT_UNDER
);
1203 term_word(p
, "errno");
1206 term_word(p
, "is set to indicate the error.");
1207 p
->flags
|= TERMP_SENTENCE
;
1213 termp_ex_pre(DECL_ARGS
)
1218 term_word(p
, "The");
1221 for (n
= n
->child
; n
; n
= n
->next
) {
1222 term_fontpush(p
, TERMFONT_BOLD
);
1223 term_word(p
, n
->string
);
1226 if (nchild
> 2 && n
->next
) {
1227 p
->flags
|= TERMP_NOSPACE
;
1231 if (n
->next
&& NULL
== n
->next
->next
)
1232 term_word(p
, "and");
1236 term_word(p
, "utilities exit\\~0");
1238 term_word(p
, "utility exits\\~0");
1240 term_word(p
, "on success, and\\~>0 if an error occurs.");
1242 p
->flags
|= TERMP_SENTENCE
;
1247 termp_nd_pre(DECL_ARGS
)
1250 if (MDOC_BODY
!= n
->type
)
1253 #if defined(__OpenBSD__) || defined(__linux__)
1254 term_word(p
, "\\(en");
1256 term_word(p
, "\\(em");
1262 termp_bl_pre(DECL_ARGS
)
1265 return(MDOC_HEAD
!= n
->type
);
1269 termp_bl_post(DECL_ARGS
)
1272 if (MDOC_BLOCK
== n
->type
)
1277 termp_xr_pre(DECL_ARGS
)
1280 if (NULL
== (n
= n
->child
))
1283 assert(MDOC_TEXT
== n
->type
);
1284 term_word(p
, n
->string
);
1286 if (NULL
== (n
= n
->next
))
1289 p
->flags
|= TERMP_NOSPACE
;
1291 p
->flags
|= TERMP_NOSPACE
;
1293 assert(MDOC_TEXT
== n
->type
);
1294 term_word(p
, n
->string
);
1296 p
->flags
|= TERMP_NOSPACE
;
1303 * This decides how to assert whitespace before any of the SYNOPSIS set
1304 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1308 synopsis_pre(struct termp
*p
, const struct mdoc_node
*n
)
1311 * Obviously, if we're not in a SYNOPSIS or no prior macros
1312 * exist, do nothing.
1314 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1318 * If we're the second in a pair of like elements, emit our
1319 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1320 * case we soldier on.
1322 if (n
->prev
->tok
== n
->tok
&&
1323 MDOC_Ft
!= n
->tok
&&
1324 MDOC_Fo
!= n
->tok
&&
1325 MDOC_Fn
!= n
->tok
) {
1331 * If we're one of the SYNOPSIS set and non-like pair-wise after
1332 * another (or Fn/Fo, which we've let slip through) then assert
1333 * vertical space, else only newline and move on.
1335 switch (n
->prev
->tok
) {
1348 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1360 termp_vt_pre(DECL_ARGS
)
1363 if (MDOC_ELEM
== n
->type
) {
1365 return(termp_under_pre(p
, pair
, meta
, n
));
1366 } else if (MDOC_BLOCK
== n
->type
) {
1369 } else if (MDOC_HEAD
== n
->type
)
1372 return(termp_under_pre(p
, pair
, meta
, n
));
1376 termp_bold_pre(DECL_ARGS
)
1379 term_fontpush(p
, TERMFONT_BOLD
);
1384 termp_fd_pre(DECL_ARGS
)
1388 return(termp_bold_pre(p
, pair
, meta
, n
));
1392 termp_fd_post(DECL_ARGS
)
1399 termp_sh_pre(DECL_ARGS
)
1402 /* No vspace between consecutive `Sh' calls. */
1406 if (n
->prev
&& MDOC_Sh
== n
->prev
->tok
)
1407 if (NULL
== n
->prev
->body
->child
)
1412 term_fontpush(p
, TERMFONT_BOLD
);
1415 p
->offset
= term_len(p
, p
->defindent
);
1416 if (SEC_AUTHORS
== n
->sec
)
1417 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1426 termp_sh_post(DECL_ARGS
)
1443 termp_bt_pre(DECL_ARGS
)
1446 term_word(p
, "is currently in beta test.");
1447 p
->flags
|= TERMP_SENTENCE
;
1452 termp_lb_post(DECL_ARGS
)
1455 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1460 termp_ud_pre(DECL_ARGS
)
1463 term_word(p
, "currently under development.");
1464 p
->flags
|= TERMP_SENTENCE
;
1469 termp_d1_pre(DECL_ARGS
)
1472 if (MDOC_BLOCK
!= n
->type
)
1475 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1480 termp_ft_pre(DECL_ARGS
)
1483 /* NB: MDOC_LINE does not effect this! */
1485 term_fontpush(p
, TERMFONT_UNDER
);
1490 termp_fn_pre(DECL_ARGS
)
1495 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1499 if (NULL
== (n
= n
->child
))
1503 rmargin
= p
->rmargin
;
1504 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1505 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1508 assert(MDOC_TEXT
== n
->type
);
1509 term_fontpush(p
, TERMFONT_BOLD
);
1510 term_word(p
, n
->string
);
1515 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1516 p
->offset
= p
->rmargin
;
1517 p
->rmargin
= rmargin
;
1520 p
->flags
|= TERMP_NOSPACE
;
1522 p
->flags
|= TERMP_NOSPACE
;
1524 for (n
= n
->next
; n
; n
= n
->next
) {
1525 assert(MDOC_TEXT
== n
->type
);
1526 term_fontpush(p
, TERMFONT_UNDER
);
1528 p
->flags
|= TERMP_NBRWORD
;
1529 term_word(p
, n
->string
);
1533 p
->flags
|= TERMP_NOSPACE
;
1538 p
->flags
|= TERMP_NOSPACE
;
1542 p
->flags
|= TERMP_NOSPACE
;
1551 termp_fa_pre(DECL_ARGS
)
1553 const struct mdoc_node
*nn
;
1555 if (n
->parent
->tok
!= MDOC_Fo
) {
1556 term_fontpush(p
, TERMFONT_UNDER
);
1560 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1561 term_fontpush(p
, TERMFONT_UNDER
);
1562 p
->flags
|= TERMP_NBRWORD
;
1563 term_word(p
, nn
->string
);
1566 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1567 p
->flags
|= TERMP_NOSPACE
;
1576 termp_bd_pre(DECL_ARGS
)
1578 size_t tabwidth
, lm
, len
, rm
, rmax
;
1579 struct mdoc_node
*nn
;
1581 if (MDOC_BLOCK
== n
->type
) {
1582 print_bvspace(p
, n
, n
);
1584 } else if (MDOC_HEAD
== n
->type
)
1587 if (n
->norm
->Bd
.offs
)
1588 p
->offset
+= a2offs(p
, n
->norm
->Bd
.offs
);
1591 * If -ragged or -filled are specified, the block does nothing
1592 * but change the indentation. If -unfilled or -literal are
1593 * specified, text is printed exactly as entered in the display:
1594 * for macro lines, a newline is appended to the line. Blank
1595 * lines are allowed.
1598 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1599 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1600 DISP_centered
!= n
->norm
->Bd
.type
)
1603 tabwidth
= p
->tabwidth
;
1604 if (DISP_literal
== n
->norm
->Bd
.type
)
1605 p
->tabwidth
= term_len(p
, 8);
1609 rmax
= p
->maxrmargin
;
1610 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1612 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1613 if (DISP_centered
== n
->norm
->Bd
.type
) {
1614 if (MDOC_TEXT
== nn
->type
) {
1615 len
= term_strlen(p
, nn
->string
);
1616 p
->offset
= len
>= rm
? 0 :
1617 lm
+ len
>= rm
? rm
- len
:
1618 (lm
+ rm
- len
) / 2;
1622 print_mdoc_node(p
, pair
, meta
, nn
);
1624 * If the printed node flushes its own line, then we
1625 * needn't do it here as well. This is hacky, but the
1626 * notion of selective eoln whitespace is pretty dumb
1627 * anyway, so don't sweat it.
1649 if (nn
->next
&& nn
->next
->line
== nn
->line
)
1652 p
->flags
|= TERMP_NOSPACE
;
1655 p
->tabwidth
= tabwidth
;
1657 p
->maxrmargin
= rmax
;
1662 termp_bd_post(DECL_ARGS
)
1666 if (MDOC_BODY
!= n
->type
)
1670 rmax
= p
->maxrmargin
;
1672 if (DISP_literal
== n
->norm
->Bd
.type
||
1673 DISP_unfilled
== n
->norm
->Bd
.type
)
1674 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1676 p
->flags
|= TERMP_NOSPACE
;
1680 p
->maxrmargin
= rmax
;
1684 termp_bx_pre(DECL_ARGS
)
1687 if (NULL
!= (n
= n
->child
)) {
1688 term_word(p
, n
->string
);
1689 p
->flags
|= TERMP_NOSPACE
;
1690 term_word(p
, "BSD");
1692 term_word(p
, "BSD");
1696 if (NULL
!= (n
= n
->next
)) {
1697 p
->flags
|= TERMP_NOSPACE
;
1699 p
->flags
|= TERMP_NOSPACE
;
1700 term_word(p
, n
->string
);
1707 termp_xx_pre(DECL_ARGS
)
1740 p
->flags
|= TERMP_KEEP
;
1741 term_word(p
, n
->child
->string
);
1748 termp_pf_post(DECL_ARGS
)
1751 p
->flags
|= TERMP_NOSPACE
;
1755 termp_ss_pre(DECL_ARGS
)
1765 term_fontpush(p
, TERMFONT_BOLD
);
1766 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1769 p
->offset
= term_len(p
, p
->defindent
);
1779 termp_ss_post(DECL_ARGS
)
1782 if (n
->type
== MDOC_HEAD
|| n
->type
== MDOC_BODY
)
1787 termp_cd_pre(DECL_ARGS
)
1791 term_fontpush(p
, TERMFONT_BOLD
);
1796 termp_in_pre(DECL_ARGS
)
1801 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1802 term_fontpush(p
, TERMFONT_BOLD
);
1803 term_word(p
, "#include");
1807 term_fontpush(p
, TERMFONT_UNDER
);
1810 p
->flags
|= TERMP_NOSPACE
;
1815 termp_in_post(DECL_ARGS
)
1818 if (MDOC_SYNPRETTY
& n
->flags
)
1819 term_fontpush(p
, TERMFONT_BOLD
);
1821 p
->flags
|= TERMP_NOSPACE
;
1824 if (MDOC_SYNPRETTY
& n
->flags
)
1829 termp_sp_pre(DECL_ARGS
)
1835 len
= n
->child
? a2height(p
, n
->child
->string
) : 1;
1847 for (i
= 0; i
< len
; i
++)
1854 termp_es_pre(DECL_ARGS
)
1861 termp_quote_pre(DECL_ARGS
)
1864 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1890 term_word(p
, "\\(lq");
1893 if (NULL
== n
->norm
->Es
||
1894 NULL
== n
->norm
->Es
->child
)
1896 term_word(p
, n
->norm
->Es
->child
->string
);
1917 term_word(p
, "\\(oq");
1924 p
->flags
|= TERMP_NOSPACE
;
1929 termp_quote_post(DECL_ARGS
)
1932 if (MDOC_BODY
!= n
->type
&& MDOC_ELEM
!= n
->type
)
1935 if (MDOC_En
!= n
->tok
)
1936 p
->flags
|= TERMP_NOSPACE
;
1961 term_word(p
, "\\(rq");
1964 if (NULL
!= n
->norm
->Es
&&
1965 NULL
!= n
->norm
->Es
->child
&&
1966 NULL
!= n
->norm
->Es
->child
->next
) {
1967 p
->flags
|= TERMP_NOSPACE
;
1968 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1990 term_word(p
, "\\(cq");
1999 termp_fo_pre(DECL_ARGS
)
2004 pretty
= MDOC_SYNPRETTY
& n
->flags
;
2006 if (MDOC_BLOCK
== n
->type
) {
2009 } else if (MDOC_BODY
== n
->type
) {
2011 rmargin
= p
->rmargin
;
2012 p
->rmargin
= p
->offset
+ term_len(p
, 4);
2013 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
2016 p
->flags
|= TERMP_NOSPACE
;
2018 p
->flags
|= TERMP_NOSPACE
;
2021 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2023 p
->offset
= p
->rmargin
;
2024 p
->rmargin
= rmargin
;
2029 if (NULL
== n
->child
)
2032 /* XXX: we drop non-initial arguments as per groff. */
2034 assert(n
->child
->string
);
2035 term_fontpush(p
, TERMFONT_BOLD
);
2036 term_word(p
, n
->child
->string
);
2041 termp_fo_post(DECL_ARGS
)
2044 if (MDOC_BODY
!= n
->type
)
2047 p
->flags
|= TERMP_NOSPACE
;
2050 if (MDOC_SYNPRETTY
& n
->flags
) {
2051 p
->flags
|= TERMP_NOSPACE
;
2058 termp_bf_pre(DECL_ARGS
)
2061 if (MDOC_HEAD
== n
->type
)
2063 else if (MDOC_BODY
!= n
->type
)
2066 if (FONT_Em
== n
->norm
->Bf
.font
)
2067 term_fontpush(p
, TERMFONT_UNDER
);
2068 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2069 term_fontpush(p
, TERMFONT_BOLD
);
2071 term_fontpush(p
, TERMFONT_NONE
);
2077 termp_sm_pre(DECL_ARGS
)
2080 if (NULL
== n
->child
)
2081 p
->flags
^= TERMP_NONOSPACE
;
2082 else if (0 == strcmp("on", n
->child
->string
))
2083 p
->flags
&= ~TERMP_NONOSPACE
;
2085 p
->flags
|= TERMP_NONOSPACE
;
2087 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2088 p
->flags
&= ~TERMP_NOSPACE
;
2094 termp_ap_pre(DECL_ARGS
)
2097 p
->flags
|= TERMP_NOSPACE
;
2099 p
->flags
|= TERMP_NOSPACE
;
2104 termp____post(DECL_ARGS
)
2108 * Handle lists of authors. In general, print each followed by
2109 * a comma. Don't print the comma if there are only two
2112 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2113 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2114 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2119 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2122 p
->flags
|= TERMP_NOSPACE
;
2123 if (NULL
== n
->next
) {
2125 p
->flags
|= TERMP_SENTENCE
;
2131 termp_li_pre(DECL_ARGS
)
2134 term_fontpush(p
, TERMFONT_NONE
);
2139 termp_lk_pre(DECL_ARGS
)
2141 const struct mdoc_node
*link
, *descr
;
2143 if (NULL
== (link
= n
->child
))
2146 if (NULL
!= (descr
= link
->next
)) {
2147 term_fontpush(p
, TERMFONT_UNDER
);
2148 while (NULL
!= descr
) {
2149 term_word(p
, descr
->string
);
2150 descr
= descr
->next
;
2152 p
->flags
|= TERMP_NOSPACE
;
2157 term_fontpush(p
, TERMFONT_BOLD
);
2158 term_word(p
, link
->string
);
2165 termp_bk_pre(DECL_ARGS
)
2174 if (n
->parent
->args
|| 0 == n
->prev
->nchild
)
2175 p
->flags
|= TERMP_PREKEEP
;
2186 termp_bk_post(DECL_ARGS
)
2189 if (MDOC_BODY
== n
->type
)
2190 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2194 termp__t_post(DECL_ARGS
)
2198 * If we're in an `Rs' and there's a journal present, then quote
2199 * us instead of underlining us (for disambiguation).
2201 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2202 n
->parent
->norm
->Rs
.quote_T
)
2203 termp_quote_post(p
, pair
, meta
, n
);
2205 termp____post(p
, pair
, meta
, n
);
2209 termp__t_pre(DECL_ARGS
)
2213 * If we're in an `Rs' and there's a journal present, then quote
2214 * us instead of underlining us (for disambiguation).
2216 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2217 n
->parent
->norm
->Rs
.quote_T
)
2218 return(termp_quote_pre(p
, pair
, meta
, n
));
2220 term_fontpush(p
, TERMFONT_UNDER
);
2225 termp_under_pre(DECL_ARGS
)
2228 term_fontpush(p
, TERMFONT_UNDER
);