]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.336 2016/11/08 16:38:21 schwarze Exp $ */
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2016 Ingo Schwarze <schwarze@openbsd.org>
5 * Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <sys/types.h>
31 #include "mandoc_aux.h"
41 struct termpair
*ppair
;
45 #define DECL_ARGS struct termp *p, \
46 struct termpair *pair, \
47 const struct roff_meta *meta, \
51 int (*pre
)(DECL_ARGS
);
52 void (*post
)(DECL_ARGS
);
55 static int a2width(const struct termp
*, const char *);
57 static void print_bvspace(struct termp
*,
58 const struct roff_node
*,
59 const struct roff_node
*);
60 static void print_mdoc_node(DECL_ARGS
);
61 static void print_mdoc_nodelist(DECL_ARGS
);
62 static void print_mdoc_head(struct termp
*, const struct roff_meta
*);
63 static void print_mdoc_foot(struct termp
*, const struct roff_meta
*);
64 static void synopsis_pre(struct termp
*,
65 const struct roff_node
*);
67 static void termp____post(DECL_ARGS
);
68 static void termp__t_post(DECL_ARGS
);
69 static void termp_bd_post(DECL_ARGS
);
70 static void termp_bk_post(DECL_ARGS
);
71 static void termp_bl_post(DECL_ARGS
);
72 static void termp_eo_post(DECL_ARGS
);
73 static void termp_fd_post(DECL_ARGS
);
74 static void termp_fo_post(DECL_ARGS
);
75 static void termp_in_post(DECL_ARGS
);
76 static void termp_it_post(DECL_ARGS
);
77 static void termp_lb_post(DECL_ARGS
);
78 static void termp_nm_post(DECL_ARGS
);
79 static void termp_pf_post(DECL_ARGS
);
80 static void termp_quote_post(DECL_ARGS
);
81 static void termp_sh_post(DECL_ARGS
);
82 static void termp_ss_post(DECL_ARGS
);
84 static int termp__a_pre(DECL_ARGS
);
85 static int termp__t_pre(DECL_ARGS
);
86 static int termp_an_pre(DECL_ARGS
);
87 static int termp_ap_pre(DECL_ARGS
);
88 static int termp_bd_pre(DECL_ARGS
);
89 static int termp_bf_pre(DECL_ARGS
);
90 static int termp_bk_pre(DECL_ARGS
);
91 static int termp_bl_pre(DECL_ARGS
);
92 static int termp_bold_pre(DECL_ARGS
);
93 static int termp_bt_pre(DECL_ARGS
);
94 static int termp_bx_pre(DECL_ARGS
);
95 static int termp_cd_pre(DECL_ARGS
);
96 static int termp_d1_pre(DECL_ARGS
);
97 static int termp_eo_pre(DECL_ARGS
);
98 static int termp_em_pre(DECL_ARGS
);
99 static int termp_er_pre(DECL_ARGS
);
100 static int termp_ex_pre(DECL_ARGS
);
101 static int termp_fa_pre(DECL_ARGS
);
102 static int termp_fd_pre(DECL_ARGS
);
103 static int termp_fl_pre(DECL_ARGS
);
104 static int termp_fn_pre(DECL_ARGS
);
105 static int termp_fo_pre(DECL_ARGS
);
106 static int termp_ft_pre(DECL_ARGS
);
107 static int termp_in_pre(DECL_ARGS
);
108 static int termp_it_pre(DECL_ARGS
);
109 static int termp_li_pre(DECL_ARGS
);
110 static int termp_ll_pre(DECL_ARGS
);
111 static int termp_lk_pre(DECL_ARGS
);
112 static int termp_nd_pre(DECL_ARGS
);
113 static int termp_nm_pre(DECL_ARGS
);
114 static int termp_ns_pre(DECL_ARGS
);
115 static int termp_quote_pre(DECL_ARGS
);
116 static int termp_rs_pre(DECL_ARGS
);
117 static int termp_rv_pre(DECL_ARGS
);
118 static int termp_sh_pre(DECL_ARGS
);
119 static int termp_skip_pre(DECL_ARGS
);
120 static int termp_sm_pre(DECL_ARGS
);
121 static int termp_sp_pre(DECL_ARGS
);
122 static int termp_ss_pre(DECL_ARGS
);
123 static int termp_sy_pre(DECL_ARGS
);
124 static int termp_tag_pre(DECL_ARGS
);
125 static int termp_under_pre(DECL_ARGS
);
126 static int termp_ud_pre(DECL_ARGS
);
127 static int termp_vt_pre(DECL_ARGS
);
128 static int termp_xr_pre(DECL_ARGS
);
129 static int termp_xx_pre(DECL_ARGS
);
131 static const struct termact termacts
[MDOC_MAX
] = {
132 { termp_ap_pre
, NULL
}, /* Ap */
133 { NULL
, NULL
}, /* Dd */
134 { NULL
, NULL
}, /* Dt */
135 { NULL
, NULL
}, /* Os */
136 { termp_sh_pre
, termp_sh_post
}, /* Sh */
137 { termp_ss_pre
, termp_ss_post
}, /* Ss */
138 { termp_sp_pre
, NULL
}, /* Pp */
139 { termp_d1_pre
, termp_bl_post
}, /* D1 */
140 { termp_d1_pre
, termp_bl_post
}, /* Dl */
141 { termp_bd_pre
, termp_bd_post
}, /* Bd */
142 { NULL
, NULL
}, /* Ed */
143 { termp_bl_pre
, termp_bl_post
}, /* Bl */
144 { NULL
, NULL
}, /* El */
145 { termp_it_pre
, termp_it_post
}, /* It */
146 { termp_under_pre
, NULL
}, /* Ad */
147 { termp_an_pre
, NULL
}, /* An */
148 { termp_under_pre
, NULL
}, /* Ar */
149 { termp_cd_pre
, NULL
}, /* Cd */
150 { termp_bold_pre
, NULL
}, /* Cm */
151 { termp_li_pre
, NULL
}, /* Dv */
152 { termp_er_pre
, NULL
}, /* Er */
153 { termp_tag_pre
, NULL
}, /* Ev */
154 { termp_ex_pre
, NULL
}, /* Ex */
155 { termp_fa_pre
, NULL
}, /* Fa */
156 { termp_fd_pre
, termp_fd_post
}, /* Fd */
157 { termp_fl_pre
, NULL
}, /* Fl */
158 { termp_fn_pre
, NULL
}, /* Fn */
159 { termp_ft_pre
, NULL
}, /* Ft */
160 { termp_bold_pre
, NULL
}, /* Ic */
161 { termp_in_pre
, termp_in_post
}, /* In */
162 { termp_li_pre
, NULL
}, /* Li */
163 { termp_nd_pre
, NULL
}, /* Nd */
164 { termp_nm_pre
, termp_nm_post
}, /* Nm */
165 { termp_quote_pre
, termp_quote_post
}, /* Op */
166 { termp_ft_pre
, NULL
}, /* Ot */
167 { termp_under_pre
, NULL
}, /* Pa */
168 { termp_rv_pre
, NULL
}, /* Rv */
169 { NULL
, NULL
}, /* St */
170 { termp_under_pre
, NULL
}, /* Va */
171 { termp_vt_pre
, NULL
}, /* Vt */
172 { termp_xr_pre
, NULL
}, /* Xr */
173 { termp__a_pre
, termp____post
}, /* %A */
174 { termp_under_pre
, termp____post
}, /* %B */
175 { NULL
, termp____post
}, /* %D */
176 { termp_under_pre
, termp____post
}, /* %I */
177 { termp_under_pre
, termp____post
}, /* %J */
178 { NULL
, termp____post
}, /* %N */
179 { NULL
, termp____post
}, /* %O */
180 { NULL
, termp____post
}, /* %P */
181 { NULL
, termp____post
}, /* %R */
182 { termp__t_pre
, termp__t_post
}, /* %T */
183 { NULL
, termp____post
}, /* %V */
184 { NULL
, NULL
}, /* Ac */
185 { termp_quote_pre
, termp_quote_post
}, /* Ao */
186 { termp_quote_pre
, termp_quote_post
}, /* Aq */
187 { NULL
, NULL
}, /* At */
188 { NULL
, NULL
}, /* Bc */
189 { termp_bf_pre
, NULL
}, /* Bf */
190 { termp_quote_pre
, termp_quote_post
}, /* Bo */
191 { termp_quote_pre
, termp_quote_post
}, /* Bq */
192 { termp_xx_pre
, NULL
}, /* Bsx */
193 { termp_bx_pre
, NULL
}, /* Bx */
194 { termp_skip_pre
, NULL
}, /* Db */
195 { NULL
, NULL
}, /* Dc */
196 { termp_quote_pre
, termp_quote_post
}, /* Do */
197 { termp_quote_pre
, termp_quote_post
}, /* Dq */
198 { NULL
, NULL
}, /* Ec */ /* FIXME: no space */
199 { NULL
, NULL
}, /* Ef */
200 { termp_em_pre
, NULL
}, /* Em */
201 { termp_eo_pre
, termp_eo_post
}, /* Eo */
202 { termp_xx_pre
, NULL
}, /* Fx */
203 { termp_bold_pre
, NULL
}, /* Ms */
204 { termp_li_pre
, NULL
}, /* No */
205 { termp_ns_pre
, NULL
}, /* Ns */
206 { termp_xx_pre
, NULL
}, /* Nx */
207 { termp_xx_pre
, NULL
}, /* Ox */
208 { NULL
, NULL
}, /* Pc */
209 { NULL
, termp_pf_post
}, /* Pf */
210 { termp_quote_pre
, termp_quote_post
}, /* Po */
211 { termp_quote_pre
, termp_quote_post
}, /* Pq */
212 { NULL
, NULL
}, /* Qc */
213 { termp_quote_pre
, termp_quote_post
}, /* Ql */
214 { termp_quote_pre
, termp_quote_post
}, /* Qo */
215 { termp_quote_pre
, termp_quote_post
}, /* Qq */
216 { NULL
, NULL
}, /* Re */
217 { termp_rs_pre
, NULL
}, /* Rs */
218 { NULL
, NULL
}, /* Sc */
219 { termp_quote_pre
, termp_quote_post
}, /* So */
220 { termp_quote_pre
, termp_quote_post
}, /* Sq */
221 { termp_sm_pre
, NULL
}, /* Sm */
222 { termp_under_pre
, NULL
}, /* Sx */
223 { termp_sy_pre
, NULL
}, /* Sy */
224 { NULL
, NULL
}, /* Tn */
225 { termp_xx_pre
, NULL
}, /* Ux */
226 { NULL
, NULL
}, /* Xc */
227 { NULL
, NULL
}, /* Xo */
228 { termp_fo_pre
, termp_fo_post
}, /* Fo */
229 { NULL
, NULL
}, /* Fc */
230 { termp_quote_pre
, termp_quote_post
}, /* Oo */
231 { NULL
, NULL
}, /* Oc */
232 { termp_bk_pre
, termp_bk_post
}, /* Bk */
233 { NULL
, NULL
}, /* Ek */
234 { termp_bt_pre
, NULL
}, /* Bt */
235 { NULL
, NULL
}, /* Hf */
236 { termp_under_pre
, NULL
}, /* Fr */
237 { termp_ud_pre
, NULL
}, /* Ud */
238 { NULL
, termp_lb_post
}, /* Lb */
239 { termp_sp_pre
, NULL
}, /* Lp */
240 { termp_lk_pre
, NULL
}, /* Lk */
241 { termp_under_pre
, NULL
}, /* Mt */
242 { termp_quote_pre
, termp_quote_post
}, /* Brq */
243 { termp_quote_pre
, termp_quote_post
}, /* Bro */
244 { NULL
, NULL
}, /* Brc */
245 { NULL
, termp____post
}, /* %C */
246 { termp_skip_pre
, NULL
}, /* Es */
247 { termp_quote_pre
, termp_quote_post
}, /* En */
248 { termp_xx_pre
, NULL
}, /* Dx */
249 { NULL
, termp____post
}, /* %Q */
250 { termp_sp_pre
, NULL
}, /* br */
251 { termp_sp_pre
, NULL
}, /* sp */
252 { NULL
, termp____post
}, /* %U */
253 { NULL
, NULL
}, /* Ta */
254 { termp_ll_pre
, NULL
}, /* ll */
260 terminal_mdoc(void *arg
, const struct roff_man
*mdoc
)
265 p
= (struct termp
*)arg
;
267 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
268 p
->tabwidth
= term_len(p
, 5);
270 n
= mdoc
->first
->child
;
271 if (p
->synopsisonly
) {
273 if (n
->tok
== MDOC_Sh
&& n
->sec
== SEC_SYNOPSIS
) {
274 if (n
->child
->next
->child
!= NULL
)
275 print_mdoc_nodelist(p
, NULL
,
277 n
->child
->next
->child
);
284 if (p
->defindent
== 0)
286 term_begin(p
, print_mdoc_head
, print_mdoc_foot
,
289 if (n
->tok
!= MDOC_Sh
)
291 print_mdoc_nodelist(p
, NULL
, &mdoc
->meta
, n
);
298 print_mdoc_nodelist(DECL_ARGS
)
302 print_mdoc_node(p
, pair
, meta
, n
);
308 print_mdoc_node(DECL_ARGS
)
311 struct termpair npair
;
312 size_t offset
, rmargin
;
316 rmargin
= p
->rmargin
;
317 n
->flags
&= ~MDOC_ENDED
;
318 n
->prev_font
= p
->fonti
;
320 memset(&npair
, 0, sizeof(struct termpair
));
324 * Keeps only work until the end of a line. If a keep was
325 * invoked in a prior line, revert it to PREKEEP.
328 if (p
->flags
& TERMP_KEEP
&& n
->flags
& MDOC_LINE
) {
329 p
->flags
&= ~TERMP_KEEP
;
330 p
->flags
|= TERMP_PREKEEP
;
334 * After the keep flags have been set up, we may now
335 * produce output. Note that some pre-handlers do so.
340 if (' ' == *n
->string
&& MDOC_LINE
& n
->flags
)
342 if (MDOC_DELIMC
& n
->flags
)
343 p
->flags
|= TERMP_NOSPACE
;
344 term_word(p
, n
->string
);
345 if (MDOC_DELIMO
& n
->flags
)
346 p
->flags
|= TERMP_NOSPACE
;
349 if ( ! (n
->flags
& MDOC_LINE
))
350 p
->flags
|= TERMP_NOSPACE
;
352 if (n
->next
!= NULL
&& ! (n
->next
->flags
& MDOC_LINE
))
353 p
->flags
|= TERMP_NOSPACE
;
356 if (p
->tbl
.cols
== NULL
)
358 term_tbl(p
, n
->span
);
361 if (termacts
[n
->tok
].pre
&&
362 (n
->end
== ENDBODY_NOT
|| n
->child
!= NULL
))
363 chld
= (*termacts
[n
->tok
].pre
)
364 (p
, &npair
, meta
, n
);
368 if (chld
&& n
->child
)
369 print_mdoc_nodelist(p
, &npair
, meta
, n
->child
);
372 (ENDBODY_NOT
== n
->end
? n
: n
->body
)->prev_font
);
382 if ( ! termacts
[n
->tok
].post
|| MDOC_ENDED
& n
->flags
)
384 (void)(*termacts
[n
->tok
].post
)(p
, &npair
, meta
, n
);
387 * Explicit end tokens not only call the post
388 * handler, but also tell the respective block
389 * that it must not call the post handler again.
391 if (ENDBODY_NOT
!= n
->end
)
392 n
->body
->flags
|= MDOC_ENDED
;
395 * End of line terminating an implicit block
396 * while an explicit block is still open.
397 * Continue the explicit block without spacing.
399 if (ENDBODY_NOSPACE
== n
->end
)
400 p
->flags
|= TERMP_NOSPACE
;
404 if (MDOC_EOS
& n
->flags
)
405 p
->flags
|= TERMP_SENTENCE
;
407 if (MDOC_ll
!= n
->tok
) {
409 p
->rmargin
= rmargin
;
414 print_mdoc_foot(struct termp
*p
, const struct roff_meta
*meta
)
418 term_fontrepl(p
, TERMFONT_NONE
);
421 * Output the footer in new-groff style, that is, three columns
422 * with the middle being the manual date and flanking columns
423 * being the operating system:
431 sz
= term_strlen(p
, meta
->date
);
432 p
->rmargin
= p
->maxrmargin
> sz
?
433 (p
->maxrmargin
+ term_len(p
, 1) - sz
) / 2 : 0;
435 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
437 term_word(p
, meta
->os
);
440 p
->offset
= p
->rmargin
;
441 sz
= term_strlen(p
, meta
->os
);
442 p
->rmargin
= p
->maxrmargin
> sz
? p
->maxrmargin
- sz
: 0;
443 p
->flags
|= TERMP_NOSPACE
;
445 term_word(p
, meta
->date
);
448 p
->offset
= p
->rmargin
;
449 p
->rmargin
= p
->maxrmargin
;
451 p
->flags
&= ~TERMP_NOBREAK
;
452 p
->flags
|= TERMP_NOSPACE
;
454 term_word(p
, meta
->os
);
458 p
->rmargin
= p
->maxrmargin
;
463 print_mdoc_head(struct termp
*p
, const struct roff_meta
*meta
)
465 char *volume
, *title
;
466 size_t vollen
, titlen
;
469 * The header is strange. It has three components, which are
470 * really two with the first duplicated. It goes like this:
472 * IDENTIFIER TITLE IDENTIFIER
474 * The IDENTIFIER is NAME(SECTION), which is the command-name
475 * (if given, or "unknown" if not) followed by the manual page
476 * section. These are given in `Dt'. The TITLE is a free-form
477 * string depending on the manual volume. If not specified, it
478 * switches on the manual section.
482 if (NULL
== meta
->arch
)
483 volume
= mandoc_strdup(meta
->vol
);
485 mandoc_asprintf(&volume
, "%s (%s)",
486 meta
->vol
, meta
->arch
);
487 vollen
= term_strlen(p
, volume
);
489 if (NULL
== meta
->msec
)
490 title
= mandoc_strdup(meta
->title
);
492 mandoc_asprintf(&title
, "%s(%s)",
493 meta
->title
, meta
->msec
);
494 titlen
= term_strlen(p
, title
);
496 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
499 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
500 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
501 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
506 p
->flags
|= TERMP_NOSPACE
;
507 p
->offset
= p
->rmargin
;
508 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
509 p
->maxrmargin
- titlen
: p
->maxrmargin
;
511 term_word(p
, volume
);
514 p
->flags
&= ~TERMP_NOBREAK
;
516 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
517 p
->flags
|= TERMP_NOSPACE
;
518 p
->offset
= p
->rmargin
;
519 p
->rmargin
= p
->maxrmargin
;
524 p
->flags
&= ~TERMP_NOSPACE
;
526 p
->rmargin
= p
->maxrmargin
;
532 a2width(const struct termp
*p
, const char *v
)
536 if (a2roffsu(v
, &su
, SCALE_MAX
) < 2) {
537 SCALE_HS_INIT(&su
, term_strlen(p
, v
));
538 su
.scale
/= term_strlen(p
, "0");
540 return term_hspan(p
, &su
) / 24;
544 * Determine how much space to print out before block elements of `It'
545 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
549 print_bvspace(struct termp
*p
,
550 const struct roff_node
*bl
,
551 const struct roff_node
*n
)
553 const struct roff_node
*nn
;
559 if (MDOC_Bd
== bl
->tok
&& bl
->norm
->Bd
.comp
)
561 if (MDOC_Bl
== bl
->tok
&& bl
->norm
->Bl
.comp
)
564 /* Do not vspace directly after Ss/Sh. */
567 while (nn
->prev
== NULL
) {
570 if (nn
->type
== ROFFT_ROOT
)
572 } while (nn
->type
!= ROFFT_BLOCK
);
573 if (nn
->tok
== MDOC_Sh
|| nn
->tok
== MDOC_Ss
)
575 if (nn
->tok
== MDOC_It
&&
576 nn
->parent
->parent
->norm
->Bl
.type
!= LIST_item
)
580 /* A `-column' does not assert vspace within the list. */
582 if (MDOC_Bl
== bl
->tok
&& LIST_column
== bl
->norm
->Bl
.type
)
583 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
586 /* A `-diag' without body does not vspace. */
588 if (MDOC_Bl
== bl
->tok
&& LIST_diag
== bl
->norm
->Bl
.type
)
589 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
590 assert(n
->prev
->body
);
591 if (NULL
== n
->prev
->body
->child
)
600 termp_ll_pre(DECL_ARGS
)
603 term_setwidth(p
, n
->child
!= NULL
? n
->child
->string
: NULL
);
608 termp_it_pre(DECL_ARGS
)
611 const struct roff_node
*bl
, *nn
;
613 int i
, offset
, width
;
616 if (n
->type
== ROFFT_BLOCK
) {
617 print_bvspace(p
, n
->parent
->parent
, n
);
621 bl
= n
->parent
->parent
->parent
;
622 type
= bl
->norm
->Bl
.type
;
625 * Defaults for specific list types.
633 width
= term_len(p
, 2);
637 width
= term_len(p
, 8);
640 width
= term_len(p
, 10);
649 * First calculate width and offset. This is pretty easy unless
650 * we're a -column list, in which case all prior columns must
654 if (bl
->norm
->Bl
.offs
!= NULL
) {
655 offset
= a2width(p
, bl
->norm
->Bl
.offs
);
656 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
658 else if (offset
> SHRT_MAX
)
664 if (n
->type
== ROFFT_HEAD
)
668 * Imitate groff's column handling:
669 * - For each earlier column, add its width.
670 * - For less than 5 columns, add four more blanks per
672 * - For exactly 5 columns, add three more blank per
674 * - For more than 5 columns, add only one column.
676 ncols
= bl
->norm
->Bl
.ncols
;
677 dcol
= ncols
< 5 ? term_len(p
, 4) :
678 ncols
== 5 ? term_len(p
, 3) : term_len(p
, 1);
681 * Calculate the offset by applying all prior ROFFT_BODY,
682 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
685 for (i
= 0, nn
= n
->prev
;
686 nn
->prev
&& i
< (int)ncols
;
688 offset
+= dcol
+ a2width(p
,
689 bl
->norm
->Bl
.cols
[i
]);
692 * When exceeding the declared number of columns, leave
693 * the remaining widths at 0. This will later be
694 * adjusted to the default width of 10, or, for the last
695 * column, stretched to the right margin.
701 * Use the declared column widths, extended as explained
702 * in the preceding paragraph.
704 width
= a2width(p
, bl
->norm
->Bl
.cols
[i
]) + dcol
;
707 if (NULL
== bl
->norm
->Bl
.width
)
711 * Note: buffer the width by 2, which is groff's magic
712 * number for buffering single arguments. See the above
713 * handling for column for how this changes.
715 width
= a2width(p
, bl
->norm
->Bl
.width
) + term_len(p
, 2);
716 if (width
< 0 && (size_t)(-width
) > p
->offset
)
718 else if (width
> SHRT_MAX
)
724 * Whitespace control. Inset bodies need an initial space,
725 * while diagonal bodies need two.
728 p
->flags
|= TERMP_NOSPACE
;
732 if (n
->type
== ROFFT_BODY
)
733 term_word(p
, "\\ \\ ");
736 if (n
->type
== ROFFT_BODY
&& n
->parent
->head
->child
!= NULL
)
743 p
->flags
|= TERMP_NOSPACE
;
747 if (n
->type
== ROFFT_HEAD
)
748 term_fontpush(p
, TERMFONT_BOLD
);
755 * Pad and break control. This is the tricky part. These flags
756 * are documented in term_flushln() in term.c. Note that we're
757 * going to unset all of these flags in termp_it_post() when we
767 * Weird special case.
768 * Some very narrow lists actually hang.
770 if (width
<= (int)term_len(p
, 2))
771 p
->flags
|= TERMP_HANG
;
772 if (n
->type
!= ROFFT_HEAD
)
774 p
->flags
|= TERMP_NOBREAK
;
778 if (n
->type
!= ROFFT_HEAD
)
782 * This is ugly. If `-hang' is specified and the body
783 * is a `Bl' or `Bd', then we want basically to nullify
784 * the "overstep" effect in term_flushln() and treat
785 * this as a `-ohang' list instead.
787 if (NULL
!= n
->next
&&
788 NULL
!= n
->next
->child
&&
789 (MDOC_Bl
== n
->next
->child
->tok
||
790 MDOC_Bd
== n
->next
->child
->tok
))
793 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
797 if (n
->type
!= ROFFT_HEAD
)
800 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
;
803 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
804 p
->flags
|= TERMP_DANGLE
;
807 if (n
->type
== ROFFT_HEAD
)
810 if (NULL
== n
->next
) {
811 p
->flags
&= ~TERMP_NOBREAK
;
814 p
->flags
|= TERMP_NOBREAK
;
820 if (n
->type
!= ROFFT_HEAD
)
822 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
830 * Margin control. Set-head-width lists have their right
831 * margins shortened. The body for these lists has the offset
832 * necessarily lengthened. Everybody gets the offset.
840 * Same stipulation as above, regarding `-hang'. We
841 * don't want to recalculate rmargin and offsets when
842 * using `Bd' or `Bl' within `-hang' overstep lists.
844 if (n
->type
== ROFFT_HEAD
&&
846 NULL
!= n
->next
->child
&&
847 (MDOC_Bl
== n
->next
->child
->tok
||
848 MDOC_Bd
== n
->next
->child
->tok
))
856 if (n
->type
== ROFFT_HEAD
)
857 p
->rmargin
= p
->offset
+ width
;
863 p
->rmargin
= p
->offset
+ width
;
865 * XXX - this behaviour is not documented: the
866 * right-most column is filled to the right margin.
868 if (n
->type
== ROFFT_HEAD
)
870 if (NULL
== n
->next
&& p
->rmargin
< p
->maxrmargin
)
871 p
->rmargin
= p
->maxrmargin
;
878 * The dash, hyphen, bullet and enum lists all have a special
879 * HEAD character (temporarily bold, in some cases).
882 if (n
->type
== ROFFT_HEAD
)
885 term_fontpush(p
, TERMFONT_BOLD
);
886 term_word(p
, "\\[bu]");
891 term_fontpush(p
, TERMFONT_BOLD
);
896 (pair
->ppair
->ppair
->count
)++;
897 (void)snprintf(buf
, sizeof(buf
), "%d.",
898 pair
->ppair
->ppair
->count
);
906 * If we're not going to process our children, indicate so here.
915 if (n
->type
== ROFFT_HEAD
)
919 if (n
->type
== ROFFT_HEAD
)
930 termp_it_post(DECL_ARGS
)
934 if (n
->type
== ROFFT_BLOCK
)
937 type
= n
->parent
->parent
->parent
->norm
->Bl
.type
;
943 if (n
->type
== ROFFT_BODY
)
947 if (n
->type
== ROFFT_BODY
)
956 * Now that our output is flushed, we can reset our tags. Since
957 * only `It' sets these flags, we're free to assume that nobody
958 * has munged them in the meanwhile.
961 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
| TERMP_BRIND
|
962 TERMP_DANGLE
| TERMP_HANG
);
967 termp_nm_pre(DECL_ARGS
)
971 if (n
->type
== ROFFT_BLOCK
) {
972 p
->flags
|= TERMP_PREKEEP
;
976 if (n
->type
== ROFFT_BODY
) {
977 if (NULL
== n
->child
)
979 p
->flags
|= TERMP_NOSPACE
;
981 if (n
->prev
->child
!= NULL
)
982 cp
= n
->prev
->child
->string
;
986 p
->offset
+= term_len(p
, 6);
988 p
->offset
+= term_len(p
, 1) + term_strlen(p
, cp
);
992 if (NULL
== n
->child
&& NULL
== meta
->name
)
995 if (n
->type
== ROFFT_HEAD
)
996 synopsis_pre(p
, n
->parent
);
998 if (n
->type
== ROFFT_HEAD
&&
999 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1000 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
| TERMP_BRIND
;
1002 p
->rmargin
= p
->offset
+ term_len(p
, 1);
1003 if (NULL
== n
->child
) {
1004 p
->rmargin
+= term_strlen(p
, meta
->name
);
1005 } else if (n
->child
->type
== ROFFT_TEXT
) {
1006 p
->rmargin
+= term_strlen(p
, n
->child
->string
);
1008 p
->flags
|= TERMP_HANG
;
1010 p
->rmargin
+= term_len(p
, 5);
1011 p
->flags
|= TERMP_HANG
;
1015 term_fontpush(p
, TERMFONT_BOLD
);
1016 if (NULL
== n
->child
)
1017 term_word(p
, meta
->name
);
1022 termp_nm_post(DECL_ARGS
)
1025 if (n
->type
== ROFFT_BLOCK
) {
1026 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
1027 } else if (n
->type
== ROFFT_HEAD
&&
1028 NULL
!= n
->next
&& NULL
!= n
->next
->child
) {
1030 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1032 } else if (n
->type
== ROFFT_BODY
&& n
->child
!= NULL
)
1037 termp_fl_pre(DECL_ARGS
)
1040 termp_tag_pre(p
, pair
, meta
, n
);
1041 term_fontpush(p
, TERMFONT_BOLD
);
1042 term_word(p
, "\\-");
1044 if (!(n
->child
== NULL
&&
1046 n
->next
->type
== ROFFT_TEXT
||
1047 n
->next
->flags
& MDOC_LINE
)))
1048 p
->flags
|= TERMP_NOSPACE
;
1054 termp__a_pre(DECL_ARGS
)
1057 if (n
->prev
&& MDOC__A
== n
->prev
->tok
)
1058 if (NULL
== n
->next
|| MDOC__A
!= n
->next
->tok
)
1059 term_word(p
, "and");
1065 termp_an_pre(DECL_ARGS
)
1068 if (n
->norm
->An
.auth
== AUTH_split
) {
1069 p
->flags
&= ~TERMP_NOSPLIT
;
1070 p
->flags
|= TERMP_SPLIT
;
1073 if (n
->norm
->An
.auth
== AUTH_nosplit
) {
1074 p
->flags
&= ~TERMP_SPLIT
;
1075 p
->flags
|= TERMP_NOSPLIT
;
1079 if (p
->flags
& TERMP_SPLIT
)
1082 if (n
->sec
== SEC_AUTHORS
&& ! (p
->flags
& TERMP_NOSPLIT
))
1083 p
->flags
|= TERMP_SPLIT
;
1089 termp_ns_pre(DECL_ARGS
)
1092 if ( ! (MDOC_LINE
& n
->flags
))
1093 p
->flags
|= TERMP_NOSPACE
;
1098 termp_rs_pre(DECL_ARGS
)
1101 if (SEC_SEE_ALSO
!= n
->sec
)
1103 if (n
->type
== ROFFT_BLOCK
&& n
->prev
!= NULL
)
1109 termp_rv_pre(DECL_ARGS
)
1111 struct roff_node
*nch
;
1115 if (n
->child
!= NULL
) {
1116 term_word(p
, "The");
1118 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
) {
1119 term_fontpush(p
, TERMFONT_BOLD
);
1120 term_word(p
, nch
->string
);
1123 p
->flags
|= TERMP_NOSPACE
;
1126 if (nch
->next
== NULL
)
1129 if (nch
->prev
!= NULL
|| nch
->next
->next
!= NULL
) {
1130 p
->flags
|= TERMP_NOSPACE
;
1133 if (nch
->next
->next
== NULL
)
1134 term_word(p
, "and");
1137 if (n
->child
!= NULL
&& n
->child
->next
!= NULL
)
1138 term_word(p
, "functions return");
1140 term_word(p
, "function returns");
1142 term_word(p
, "the value\\~0 if successful;");
1144 term_word(p
, "Upon successful completion,"
1145 " the value\\~0 is returned;");
1147 term_word(p
, "otherwise the value\\~\\-1 is returned"
1148 " and the global variable");
1150 term_fontpush(p
, TERMFONT_UNDER
);
1151 term_word(p
, "errno");
1154 term_word(p
, "is set to indicate the error.");
1155 p
->flags
|= TERMP_SENTENCE
;
1161 termp_ex_pre(DECL_ARGS
)
1163 struct roff_node
*nch
;
1166 term_word(p
, "The");
1168 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
) {
1169 term_fontpush(p
, TERMFONT_BOLD
);
1170 term_word(p
, nch
->string
);
1173 if (nch
->next
== NULL
)
1176 if (nch
->prev
!= NULL
|| nch
->next
->next
!= NULL
) {
1177 p
->flags
|= TERMP_NOSPACE
;
1181 if (nch
->next
->next
== NULL
)
1182 term_word(p
, "and");
1185 if (n
->child
!= NULL
&& n
->child
->next
!= NULL
)
1186 term_word(p
, "utilities exit\\~0");
1188 term_word(p
, "utility exits\\~0");
1190 term_word(p
, "on success, and\\~>0 if an error occurs.");
1192 p
->flags
|= TERMP_SENTENCE
;
1197 termp_nd_pre(DECL_ARGS
)
1200 if (n
->type
== ROFFT_BODY
)
1201 term_word(p
, "\\(en");
1206 termp_bl_pre(DECL_ARGS
)
1209 return n
->type
!= ROFFT_HEAD
;
1213 termp_bl_post(DECL_ARGS
)
1216 if (n
->type
== ROFFT_BLOCK
)
1221 termp_xr_pre(DECL_ARGS
)
1224 if (NULL
== (n
= n
->child
))
1227 assert(n
->type
== ROFFT_TEXT
);
1228 term_word(p
, n
->string
);
1230 if (NULL
== (n
= n
->next
))
1233 p
->flags
|= TERMP_NOSPACE
;
1235 p
->flags
|= TERMP_NOSPACE
;
1237 assert(n
->type
== ROFFT_TEXT
);
1238 term_word(p
, n
->string
);
1240 p
->flags
|= TERMP_NOSPACE
;
1247 * This decides how to assert whitespace before any of the SYNOPSIS set
1248 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1252 synopsis_pre(struct termp
*p
, const struct roff_node
*n
)
1255 * Obviously, if we're not in a SYNOPSIS or no prior macros
1256 * exist, do nothing.
1258 if (NULL
== n
->prev
|| ! (MDOC_SYNPRETTY
& n
->flags
))
1262 * If we're the second in a pair of like elements, emit our
1263 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1264 * case we soldier on.
1266 if (n
->prev
->tok
== n
->tok
&&
1267 MDOC_Ft
!= n
->tok
&&
1268 MDOC_Fo
!= n
->tok
&&
1269 MDOC_Fn
!= n
->tok
) {
1275 * If we're one of the SYNOPSIS set and non-like pair-wise after
1276 * another (or Fn/Fo, which we've let slip through) then assert
1277 * vertical space, else only newline and move on.
1279 switch (n
->prev
->tok
) {
1288 if (MDOC_Fn
!= n
->tok
&& MDOC_Fo
!= n
->tok
) {
1300 termp_vt_pre(DECL_ARGS
)
1303 if (n
->type
== ROFFT_ELEM
) {
1305 return termp_under_pre(p
, pair
, meta
, n
);
1306 } else if (n
->type
== ROFFT_BLOCK
) {
1309 } else if (n
->type
== ROFFT_HEAD
)
1312 return termp_under_pre(p
, pair
, meta
, n
);
1316 termp_bold_pre(DECL_ARGS
)
1319 termp_tag_pre(p
, pair
, meta
, n
);
1320 term_fontpush(p
, TERMFONT_BOLD
);
1325 termp_fd_pre(DECL_ARGS
)
1329 return termp_bold_pre(p
, pair
, meta
, n
);
1333 termp_fd_post(DECL_ARGS
)
1340 termp_sh_pre(DECL_ARGS
)
1346 * Vertical space before sections, except
1347 * when the previous section was empty.
1349 if (n
->prev
== NULL
||
1350 n
->prev
->tok
!= MDOC_Sh
||
1351 (n
->prev
->body
!= NULL
&&
1352 n
->prev
->body
->child
!= NULL
))
1356 term_fontpush(p
, TERMFONT_BOLD
);
1359 p
->offset
= term_len(p
, p
->defindent
);
1361 case SEC_DESCRIPTION
:
1365 p
->flags
&= ~(TERMP_SPLIT
|TERMP_NOSPLIT
);
1378 termp_sh_post(DECL_ARGS
)
1395 termp_bt_pre(DECL_ARGS
)
1398 term_word(p
, "is currently in beta test.");
1399 p
->flags
|= TERMP_SENTENCE
;
1404 termp_lb_post(DECL_ARGS
)
1407 if (SEC_LIBRARY
== n
->sec
&& MDOC_LINE
& n
->flags
)
1412 termp_ud_pre(DECL_ARGS
)
1415 term_word(p
, "currently under development.");
1416 p
->flags
|= TERMP_SENTENCE
;
1421 termp_d1_pre(DECL_ARGS
)
1424 if (n
->type
!= ROFFT_BLOCK
)
1427 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1432 termp_ft_pre(DECL_ARGS
)
1435 /* NB: MDOC_LINE does not effect this! */
1437 term_fontpush(p
, TERMFONT_UNDER
);
1442 termp_fn_pre(DECL_ARGS
)
1447 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1451 if (NULL
== (n
= n
->child
))
1455 rmargin
= p
->rmargin
;
1456 p
->rmargin
= p
->offset
+ term_len(p
, 4);
1457 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
;
1460 assert(n
->type
== ROFFT_TEXT
);
1461 term_fontpush(p
, TERMFONT_BOLD
);
1462 term_word(p
, n
->string
);
1465 if (n
->sec
== SEC_DESCRIPTION
|| n
->sec
== SEC_CUSTOM
)
1466 tag_put(n
->string
, ++fn_prio
, p
->line
);
1470 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
| TERMP_HANG
);
1471 p
->offset
= p
->rmargin
;
1472 p
->rmargin
= rmargin
;
1475 p
->flags
|= TERMP_NOSPACE
;
1477 p
->flags
|= TERMP_NOSPACE
;
1479 for (n
= n
->next
; n
; n
= n
->next
) {
1480 assert(n
->type
== ROFFT_TEXT
);
1481 term_fontpush(p
, TERMFONT_UNDER
);
1483 p
->flags
|= TERMP_NBRWORD
;
1484 term_word(p
, n
->string
);
1488 p
->flags
|= TERMP_NOSPACE
;
1493 p
->flags
|= TERMP_NOSPACE
;
1497 p
->flags
|= TERMP_NOSPACE
;
1506 termp_fa_pre(DECL_ARGS
)
1508 const struct roff_node
*nn
;
1510 if (n
->parent
->tok
!= MDOC_Fo
) {
1511 term_fontpush(p
, TERMFONT_UNDER
);
1515 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1516 term_fontpush(p
, TERMFONT_UNDER
);
1517 p
->flags
|= TERMP_NBRWORD
;
1518 term_word(p
, nn
->string
);
1521 if (nn
->next
|| (n
->next
&& n
->next
->tok
== MDOC_Fa
)) {
1522 p
->flags
|= TERMP_NOSPACE
;
1531 termp_bd_pre(DECL_ARGS
)
1533 size_t tabwidth
, lm
, len
, rm
, rmax
;
1534 struct roff_node
*nn
;
1537 if (n
->type
== ROFFT_BLOCK
) {
1538 print_bvspace(p
, n
, n
);
1540 } else if (n
->type
== ROFFT_HEAD
)
1543 /* Handle the -offset argument. */
1545 if (n
->norm
->Bd
.offs
== NULL
||
1546 ! strcmp(n
->norm
->Bd
.offs
, "left"))
1548 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent"))
1549 p
->offset
+= term_len(p
, p
->defindent
+ 1);
1550 else if ( ! strcmp(n
->norm
->Bd
.offs
, "indent-two"))
1551 p
->offset
+= term_len(p
, (p
->defindent
+ 1) * 2);
1553 offset
= a2width(p
, n
->norm
->Bd
.offs
);
1554 if (offset
< 0 && (size_t)(-offset
) > p
->offset
)
1556 else if (offset
< SHRT_MAX
)
1557 p
->offset
+= offset
;
1561 * If -ragged or -filled are specified, the block does nothing
1562 * but change the indentation. If -unfilled or -literal are
1563 * specified, text is printed exactly as entered in the display:
1564 * for macro lines, a newline is appended to the line. Blank
1565 * lines are allowed.
1568 if (DISP_literal
!= n
->norm
->Bd
.type
&&
1569 DISP_unfilled
!= n
->norm
->Bd
.type
&&
1570 DISP_centered
!= n
->norm
->Bd
.type
)
1573 tabwidth
= p
->tabwidth
;
1574 if (DISP_literal
== n
->norm
->Bd
.type
)
1575 p
->tabwidth
= term_len(p
, 8);
1579 rmax
= p
->maxrmargin
;
1580 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1582 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1583 if (DISP_centered
== n
->norm
->Bd
.type
) {
1584 if (nn
->type
== ROFFT_TEXT
) {
1585 len
= term_strlen(p
, nn
->string
);
1586 p
->offset
= len
>= rm
? 0 :
1587 lm
+ len
>= rm
? rm
- len
:
1588 (lm
+ rm
- len
) / 2;
1592 print_mdoc_node(p
, pair
, meta
, nn
);
1594 * If the printed node flushes its own line, then we
1595 * needn't do it here as well. This is hacky, but the
1596 * notion of selective eoln whitespace is pretty dumb
1597 * anyway, so don't sweat it.
1612 if (p
->flags
& TERMP_NONEWLINE
||
1613 (nn
->next
&& ! (nn
->next
->flags
& MDOC_LINE
)))
1616 p
->flags
|= TERMP_NOSPACE
;
1619 p
->tabwidth
= tabwidth
;
1621 p
->maxrmargin
= rmax
;
1626 termp_bd_post(DECL_ARGS
)
1630 if (n
->type
!= ROFFT_BODY
)
1634 rmax
= p
->maxrmargin
;
1636 if (DISP_literal
== n
->norm
->Bd
.type
||
1637 DISP_unfilled
== n
->norm
->Bd
.type
)
1638 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1640 p
->flags
|= TERMP_NOSPACE
;
1644 p
->maxrmargin
= rmax
;
1648 termp_bx_pre(DECL_ARGS
)
1651 if (NULL
!= (n
= n
->child
)) {
1652 term_word(p
, n
->string
);
1653 p
->flags
|= TERMP_NOSPACE
;
1654 term_word(p
, "BSD");
1656 term_word(p
, "BSD");
1660 if (NULL
!= (n
= n
->next
)) {
1661 p
->flags
|= TERMP_NOSPACE
;
1663 p
->flags
|= TERMP_NOSPACE
;
1664 term_word(p
, n
->string
);
1671 termp_xx_pre(DECL_ARGS
)
1703 p
->flags
|= TERMP_KEEP
;
1704 term_word(p
, n
->child
->string
);
1711 termp_pf_post(DECL_ARGS
)
1714 if ( ! (n
->next
== NULL
|| n
->next
->flags
& MDOC_LINE
))
1715 p
->flags
|= TERMP_NOSPACE
;
1719 termp_ss_pre(DECL_ARGS
)
1729 term_fontpush(p
, TERMFONT_BOLD
);
1730 p
->offset
= term_len(p
, (p
->defindent
+1)/2);
1733 p
->offset
= term_len(p
, p
->defindent
);
1743 termp_ss_post(DECL_ARGS
)
1746 if (n
->type
== ROFFT_HEAD
|| n
->type
== ROFFT_BODY
)
1751 termp_cd_pre(DECL_ARGS
)
1755 term_fontpush(p
, TERMFONT_BOLD
);
1760 termp_in_pre(DECL_ARGS
)
1765 if (MDOC_SYNPRETTY
& n
->flags
&& MDOC_LINE
& n
->flags
) {
1766 term_fontpush(p
, TERMFONT_BOLD
);
1767 term_word(p
, "#include");
1771 term_fontpush(p
, TERMFONT_UNDER
);
1774 p
->flags
|= TERMP_NOSPACE
;
1779 termp_in_post(DECL_ARGS
)
1782 if (MDOC_SYNPRETTY
& n
->flags
)
1783 term_fontpush(p
, TERMFONT_BOLD
);
1785 p
->flags
|= TERMP_NOSPACE
;
1788 if (MDOC_SYNPRETTY
& n
->flags
)
1793 termp_sp_pre(DECL_ARGS
)
1801 if ( ! a2roffsu(n
->child
->string
, &su
, SCALE_VS
))
1803 len
= term_vspan(p
, &su
);
1821 for (i
= 0; i
< len
; i
++)
1828 termp_skip_pre(DECL_ARGS
)
1835 termp_quote_pre(DECL_ARGS
)
1838 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1844 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1845 n
->child
->tok
== MDOC_Mt
? "<" : "\\(la");
1859 term_word(p
, "\\(Lq");
1862 if (NULL
== n
->norm
->Es
||
1863 NULL
== n
->norm
->Es
->child
)
1865 term_word(p
, n
->norm
->Es
->child
->string
);
1879 term_word(p
, "\\(oq");
1885 p
->flags
|= TERMP_NOSPACE
;
1890 termp_quote_post(DECL_ARGS
)
1893 if (n
->type
!= ROFFT_BODY
&& n
->type
!= ROFFT_ELEM
)
1896 p
->flags
|= TERMP_NOSPACE
;
1901 term_word(p
, n
->child
!= NULL
&& n
->child
->next
== NULL
&&
1902 n
->child
->tok
== MDOC_Mt
? ">" : "\\(ra");
1916 term_word(p
, "\\(Rq");
1919 if (n
->norm
->Es
== NULL
||
1920 n
->norm
->Es
->child
== NULL
||
1921 n
->norm
->Es
->child
->next
== NULL
)
1922 p
->flags
&= ~TERMP_NOSPACE
;
1924 term_word(p
, n
->norm
->Es
->child
->next
->string
);
1938 term_word(p
, "\\(cq");
1946 termp_eo_pre(DECL_ARGS
)
1949 if (n
->type
!= ROFFT_BODY
)
1952 if (n
->end
== ENDBODY_NOT
&&
1953 n
->parent
->head
->child
== NULL
&&
1955 n
->child
->end
!= ENDBODY_NOT
)
1956 term_word(p
, "\\&");
1957 else if (n
->end
!= ENDBODY_NOT
? n
->child
!= NULL
:
1958 n
->parent
->head
->child
!= NULL
&& (n
->child
!= NULL
||
1959 (n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
)))
1960 p
->flags
|= TERMP_NOSPACE
;
1966 termp_eo_post(DECL_ARGS
)
1970 if (n
->type
!= ROFFT_BODY
)
1973 if (n
->end
!= ENDBODY_NOT
) {
1974 p
->flags
&= ~TERMP_NOSPACE
;
1978 body
= n
->child
!= NULL
|| n
->parent
->head
->child
!= NULL
;
1979 tail
= n
->parent
->tail
!= NULL
&& n
->parent
->tail
->child
!= NULL
;
1982 p
->flags
|= TERMP_NOSPACE
;
1983 else if ( ! (body
|| tail
))
1984 term_word(p
, "\\&");
1986 p
->flags
&= ~TERMP_NOSPACE
;
1990 termp_fo_pre(DECL_ARGS
)
1995 pretty
= MDOC_SYNPRETTY
& n
->flags
;
1997 if (n
->type
== ROFFT_BLOCK
) {
2000 } else if (n
->type
== ROFFT_BODY
) {
2002 rmargin
= p
->rmargin
;
2003 p
->rmargin
= p
->offset
+ term_len(p
, 4);
2004 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
|
2007 p
->flags
|= TERMP_NOSPACE
;
2009 p
->flags
|= TERMP_NOSPACE
;
2012 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
|
2014 p
->offset
= p
->rmargin
;
2015 p
->rmargin
= rmargin
;
2020 if (NULL
== n
->child
)
2023 /* XXX: we drop non-initial arguments as per groff. */
2025 assert(n
->child
->string
);
2026 term_fontpush(p
, TERMFONT_BOLD
);
2027 term_word(p
, n
->child
->string
);
2032 termp_fo_post(DECL_ARGS
)
2035 if (n
->type
!= ROFFT_BODY
)
2038 p
->flags
|= TERMP_NOSPACE
;
2041 if (MDOC_SYNPRETTY
& n
->flags
) {
2042 p
->flags
|= TERMP_NOSPACE
;
2049 termp_bf_pre(DECL_ARGS
)
2052 if (n
->type
== ROFFT_HEAD
)
2054 else if (n
->type
!= ROFFT_BODY
)
2057 if (FONT_Em
== n
->norm
->Bf
.font
)
2058 term_fontpush(p
, TERMFONT_UNDER
);
2059 else if (FONT_Sy
== n
->norm
->Bf
.font
)
2060 term_fontpush(p
, TERMFONT_BOLD
);
2062 term_fontpush(p
, TERMFONT_NONE
);
2068 termp_sm_pre(DECL_ARGS
)
2071 if (NULL
== n
->child
)
2072 p
->flags
^= TERMP_NONOSPACE
;
2073 else if (0 == strcmp("on", n
->child
->string
))
2074 p
->flags
&= ~TERMP_NONOSPACE
;
2076 p
->flags
|= TERMP_NONOSPACE
;
2078 if (p
->col
&& ! (TERMP_NONOSPACE
& p
->flags
))
2079 p
->flags
&= ~TERMP_NOSPACE
;
2085 termp_ap_pre(DECL_ARGS
)
2088 p
->flags
|= TERMP_NOSPACE
;
2090 p
->flags
|= TERMP_NOSPACE
;
2095 termp____post(DECL_ARGS
)
2099 * Handle lists of authors. In general, print each followed by
2100 * a comma. Don't print the comma if there are only two
2103 if (MDOC__A
== n
->tok
&& n
->next
&& MDOC__A
== n
->next
->tok
)
2104 if (NULL
== n
->next
->next
|| MDOC__A
!= n
->next
->next
->tok
)
2105 if (NULL
== n
->prev
|| MDOC__A
!= n
->prev
->tok
)
2110 if (NULL
== n
->parent
|| MDOC_Rs
!= n
->parent
->tok
)
2113 p
->flags
|= TERMP_NOSPACE
;
2114 if (NULL
== n
->next
) {
2116 p
->flags
|= TERMP_SENTENCE
;
2122 termp_li_pre(DECL_ARGS
)
2125 termp_tag_pre(p
, pair
, meta
, n
);
2126 term_fontpush(p
, TERMFONT_NONE
);
2131 termp_lk_pre(DECL_ARGS
)
2133 const struct roff_node
*link
, *descr
;
2135 if (NULL
== (link
= n
->child
))
2138 if (NULL
!= (descr
= link
->next
)) {
2139 term_fontpush(p
, TERMFONT_UNDER
);
2140 while (NULL
!= descr
) {
2141 term_word(p
, descr
->string
);
2142 descr
= descr
->next
;
2144 p
->flags
|= TERMP_NOSPACE
;
2149 term_fontpush(p
, TERMFONT_BOLD
);
2150 term_word(p
, link
->string
);
2157 termp_bk_pre(DECL_ARGS
)
2166 if (n
->parent
->args
!= NULL
|| n
->prev
->child
== NULL
)
2167 p
->flags
|= TERMP_PREKEEP
;
2177 termp_bk_post(DECL_ARGS
)
2180 if (n
->type
== ROFFT_BODY
)
2181 p
->flags
&= ~(TERMP_KEEP
| TERMP_PREKEEP
);
2185 termp__t_post(DECL_ARGS
)
2189 * If we're in an `Rs' and there's a journal present, then quote
2190 * us instead of underlining us (for disambiguation).
2192 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2193 n
->parent
->norm
->Rs
.quote_T
)
2194 termp_quote_post(p
, pair
, meta
, n
);
2196 termp____post(p
, pair
, meta
, n
);
2200 termp__t_pre(DECL_ARGS
)
2204 * If we're in an `Rs' and there's a journal present, then quote
2205 * us instead of underlining us (for disambiguation).
2207 if (n
->parent
&& MDOC_Rs
== n
->parent
->tok
&&
2208 n
->parent
->norm
->Rs
.quote_T
)
2209 return termp_quote_pre(p
, pair
, meta
, n
);
2211 term_fontpush(p
, TERMFONT_UNDER
);
2216 termp_under_pre(DECL_ARGS
)
2219 term_fontpush(p
, TERMFONT_UNDER
);
2224 termp_em_pre(DECL_ARGS
)
2226 if (n
->child
!= NULL
&&
2227 n
->child
->type
== ROFFT_TEXT
)
2228 tag_put(n
->child
->string
, 0, p
->line
);
2229 term_fontpush(p
, TERMFONT_UNDER
);
2234 termp_sy_pre(DECL_ARGS
)
2236 if (n
->child
!= NULL
&&
2237 n
->child
->type
== ROFFT_TEXT
)
2238 tag_put(n
->child
->string
, 0, p
->line
);
2239 term_fontpush(p
, TERMFONT_BOLD
);
2244 termp_er_pre(DECL_ARGS
)
2247 if (n
->sec
== SEC_ERRORS
&&
2248 (n
->parent
->tok
== MDOC_It
||
2249 (n
->parent
->tok
== MDOC_Bq
&&
2250 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2251 tag_put(n
->child
->string
, 1, p
->line
);
2256 termp_tag_pre(DECL_ARGS
)
2259 if (n
->child
!= NULL
&&
2260 n
->child
->type
== ROFFT_TEXT
&&
2262 (n
->prev
->type
== ROFFT_TEXT
&&
2263 strcmp(n
->prev
->string
, "|") == 0)) &&
2264 (n
->parent
->tok
== MDOC_It
||
2265 (n
->parent
->tok
== MDOC_Xo
&&
2266 n
->parent
->parent
->prev
== NULL
&&
2267 n
->parent
->parent
->parent
->tok
== MDOC_It
)))
2268 tag_put(n
->child
->string
, 1, p
->line
);