]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.104 2010/01/01 13:35:30 kristaps Exp $ */
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/types.h>
35 struct termpair
*ppair
;
40 #define DECL_ARGS struct termp *p, \
41 struct termpair *pair, \
42 const struct mdoc_meta *m, \
43 const struct mdoc_node *n
46 int (*pre
)(DECL_ARGS
);
47 void (*post
)(DECL_ARGS
);
50 static size_t a2width(const struct mdoc_argv
*, int);
51 static size_t a2height(const struct mdoc_node
*);
52 static size_t a2offs(const struct mdoc_argv
*);
54 static int arg_hasattr(int, const struct mdoc_node
*);
55 static int arg_getattrs(const int *, int *, size_t,
56 const struct mdoc_node
*);
57 static int arg_getattr(int, const struct mdoc_node
*);
58 static int arg_listtype(const struct mdoc_node
*);
59 static void print_bvspace(struct termp
*,
60 const struct mdoc_node
*,
61 const struct mdoc_node
*);
62 static void print_mdoc_node(DECL_ARGS
);
63 static void print_mdoc_head(DECL_ARGS
);
64 static void print_mdoc_nodelist(DECL_ARGS
);
65 static void print_foot(DECL_ARGS
);
68 extern size_t strlcpy(char *, const char *, size_t);
69 extern size_t strlcat(char *, const char *, size_t);
72 static void termp____post(DECL_ARGS
);
73 static void termp_an_post(DECL_ARGS
);
74 static void termp_aq_post(DECL_ARGS
);
75 static void termp_bd_post(DECL_ARGS
);
76 static void termp_bl_post(DECL_ARGS
);
77 static void termp_bq_post(DECL_ARGS
);
78 static void termp_brq_post(DECL_ARGS
);
79 static void termp_bx_post(DECL_ARGS
);
80 static void termp_d1_post(DECL_ARGS
);
81 static void termp_dq_post(DECL_ARGS
);
82 static void termp_fd_post(DECL_ARGS
);
83 static void termp_fn_post(DECL_ARGS
);
84 static void termp_fo_post(DECL_ARGS
);
85 static void termp_ft_post(DECL_ARGS
);
86 static void termp_in_post(DECL_ARGS
);
87 static void termp_it_post(DECL_ARGS
);
88 static void termp_lb_post(DECL_ARGS
);
89 static void termp_op_post(DECL_ARGS
);
90 static void termp_pf_post(DECL_ARGS
);
91 static void termp_pq_post(DECL_ARGS
);
92 static void termp_qq_post(DECL_ARGS
);
93 static void termp_sh_post(DECL_ARGS
);
94 static void termp_sq_post(DECL_ARGS
);
95 static void termp_ss_post(DECL_ARGS
);
96 static void termp_vt_post(DECL_ARGS
);
98 static int termp__t_pre(DECL_ARGS
);
99 static int termp_an_pre(DECL_ARGS
);
100 static int termp_ap_pre(DECL_ARGS
);
101 static int termp_aq_pre(DECL_ARGS
);
102 static int termp_bd_pre(DECL_ARGS
);
103 static int termp_bf_pre(DECL_ARGS
);
104 static int termp_bold_pre(DECL_ARGS
);
105 static int termp_bq_pre(DECL_ARGS
);
106 static int termp_brq_pre(DECL_ARGS
);
107 static int termp_bt_pre(DECL_ARGS
);
108 static int termp_cd_pre(DECL_ARGS
);
109 static int termp_d1_pre(DECL_ARGS
);
110 static int termp_dq_pre(DECL_ARGS
);
111 static int termp_ex_pre(DECL_ARGS
);
112 static int termp_fa_pre(DECL_ARGS
);
113 static int termp_fl_pre(DECL_ARGS
);
114 static int termp_fn_pre(DECL_ARGS
);
115 static int termp_fo_pre(DECL_ARGS
);
116 static int termp_ft_pre(DECL_ARGS
);
117 static int termp_in_pre(DECL_ARGS
);
118 static int termp_it_pre(DECL_ARGS
);
119 static int termp_li_pre(DECL_ARGS
);
120 static int termp_lk_pre(DECL_ARGS
);
121 static int termp_nd_pre(DECL_ARGS
);
122 static int termp_nm_pre(DECL_ARGS
);
123 static int termp_ns_pre(DECL_ARGS
);
124 static int termp_op_pre(DECL_ARGS
);
125 static int termp_pf_pre(DECL_ARGS
);
126 static int termp_pq_pre(DECL_ARGS
);
127 static int termp_qq_pre(DECL_ARGS
);
128 static int termp_rs_pre(DECL_ARGS
);
129 static int termp_rv_pre(DECL_ARGS
);
130 static int termp_sh_pre(DECL_ARGS
);
131 static int termp_sm_pre(DECL_ARGS
);
132 static int termp_sp_pre(DECL_ARGS
);
133 static int termp_sq_pre(DECL_ARGS
);
134 static int termp_ss_pre(DECL_ARGS
);
135 static int termp_under_pre(DECL_ARGS
);
136 static int termp_ud_pre(DECL_ARGS
);
137 static int termp_xr_pre(DECL_ARGS
);
138 static int termp_xx_pre(DECL_ARGS
);
140 static const struct termact termacts
[MDOC_MAX
] = {
141 { termp_ap_pre
, NULL
}, /* Ap */
142 { NULL
, NULL
}, /* Dd */
143 { NULL
, NULL
}, /* Dt */
144 { NULL
, NULL
}, /* Os */
145 { termp_sh_pre
, termp_sh_post
}, /* Sh */
146 { termp_ss_pre
, termp_ss_post
}, /* Ss */
147 { termp_sp_pre
, NULL
}, /* Pp */
148 { termp_d1_pre
, termp_d1_post
}, /* D1 */
149 { termp_d1_pre
, termp_d1_post
}, /* Dl */
150 { termp_bd_pre
, termp_bd_post
}, /* Bd */
151 { NULL
, NULL
}, /* Ed */
152 { NULL
, termp_bl_post
}, /* Bl */
153 { NULL
, NULL
}, /* El */
154 { termp_it_pre
, termp_it_post
}, /* It */
155 { NULL
, NULL
}, /* Ad */
156 { termp_an_pre
, termp_an_post
}, /* An */
157 { termp_under_pre
, NULL
}, /* Ar */
158 { termp_cd_pre
, NULL
}, /* Cd */
159 { termp_bold_pre
, NULL
}, /* Cm */
160 { NULL
, NULL
}, /* Dv */
161 { NULL
, NULL
}, /* Er */
162 { NULL
, NULL
}, /* Ev */
163 { termp_ex_pre
, NULL
}, /* Ex */
164 { termp_fa_pre
, NULL
}, /* Fa */
165 { termp_bold_pre
, termp_fd_post
}, /* Fd */
166 { termp_fl_pre
, NULL
}, /* Fl */
167 { termp_fn_pre
, termp_fn_post
}, /* Fn */
168 { termp_ft_pre
, termp_ft_post
}, /* Ft */
169 { termp_bold_pre
, NULL
}, /* Ic */
170 { termp_in_pre
, termp_in_post
}, /* In */
171 { termp_li_pre
, NULL
}, /* Li */
172 { termp_nd_pre
, NULL
}, /* Nd */
173 { termp_nm_pre
, NULL
}, /* Nm */
174 { termp_op_pre
, termp_op_post
}, /* Op */
175 { NULL
, NULL
}, /* Ot */
176 { termp_under_pre
, NULL
}, /* Pa */
177 { termp_rv_pre
, NULL
}, /* Rv */
178 { NULL
, NULL
}, /* St */
179 { termp_under_pre
, NULL
}, /* Va */
180 { termp_under_pre
, termp_vt_post
}, /* Vt */
181 { termp_xr_pre
, NULL
}, /* Xr */
182 { NULL
, termp____post
}, /* %A */
183 { termp_under_pre
, termp____post
}, /* %B */
184 { NULL
, termp____post
}, /* %D */
185 { termp_under_pre
, termp____post
}, /* %I */
186 { termp_under_pre
, termp____post
}, /* %J */
187 { NULL
, termp____post
}, /* %N */
188 { NULL
, termp____post
}, /* %O */
189 { NULL
, termp____post
}, /* %P */
190 { NULL
, termp____post
}, /* %R */
191 { termp__t_pre
, termp____post
}, /* %T */
192 { NULL
, termp____post
}, /* %V */
193 { NULL
, NULL
}, /* Ac */
194 { termp_aq_pre
, termp_aq_post
}, /* Ao */
195 { termp_aq_pre
, termp_aq_post
}, /* Aq */
196 { NULL
, NULL
}, /* At */
197 { NULL
, NULL
}, /* Bc */
198 { termp_bf_pre
, NULL
}, /* Bf */
199 { termp_bq_pre
, termp_bq_post
}, /* Bo */
200 { termp_bq_pre
, termp_bq_post
}, /* Bq */
201 { termp_xx_pre
, NULL
}, /* Bsx */
202 { NULL
, termp_bx_post
}, /* Bx */
203 { NULL
, NULL
}, /* Db */
204 { NULL
, NULL
}, /* Dc */
205 { termp_dq_pre
, termp_dq_post
}, /* Do */
206 { termp_dq_pre
, termp_dq_post
}, /* Dq */
207 { NULL
, NULL
}, /* Ec */
208 { NULL
, NULL
}, /* Ef */
209 { termp_under_pre
, NULL
}, /* Em */
210 { NULL
, NULL
}, /* Eo */
211 { termp_xx_pre
, NULL
}, /* Fx */
212 { termp_bold_pre
, NULL
}, /* Ms */ /* FIXME: convert to symbol? */
213 { NULL
, NULL
}, /* No */
214 { termp_ns_pre
, NULL
}, /* Ns */
215 { termp_xx_pre
, NULL
}, /* Nx */
216 { termp_xx_pre
, NULL
}, /* Ox */
217 { NULL
, NULL
}, /* Pc */
218 { termp_pf_pre
, termp_pf_post
}, /* Pf */
219 { termp_pq_pre
, termp_pq_post
}, /* Po */
220 { termp_pq_pre
, termp_pq_post
}, /* Pq */
221 { NULL
, NULL
}, /* Qc */
222 { termp_sq_pre
, termp_sq_post
}, /* Ql */
223 { termp_qq_pre
, termp_qq_post
}, /* Qo */
224 { termp_qq_pre
, termp_qq_post
}, /* Qq */
225 { NULL
, NULL
}, /* Re */
226 { termp_rs_pre
, NULL
}, /* Rs */
227 { NULL
, NULL
}, /* Sc */
228 { termp_sq_pre
, termp_sq_post
}, /* So */
229 { termp_sq_pre
, termp_sq_post
}, /* Sq */
230 { termp_sm_pre
, NULL
}, /* Sm */
231 { termp_under_pre
, NULL
}, /* Sx */
232 { termp_bold_pre
, NULL
}, /* Sy */
233 { NULL
, NULL
}, /* Tn */
234 { termp_xx_pre
, NULL
}, /* Ux */
235 { NULL
, NULL
}, /* Xc */
236 { NULL
, NULL
}, /* Xo */
237 { termp_fo_pre
, termp_fo_post
}, /* Fo */
238 { NULL
, NULL
}, /* Fc */
239 { termp_op_pre
, termp_op_post
}, /* Oo */
240 { NULL
, NULL
}, /* Oc */
241 { NULL
, NULL
}, /* Bk */
242 { NULL
, NULL
}, /* Ek */
243 { termp_bt_pre
, NULL
}, /* Bt */
244 { NULL
, NULL
}, /* Hf */
245 { NULL
, NULL
}, /* Fr */
246 { termp_ud_pre
, NULL
}, /* Ud */
247 { NULL
, termp_lb_post
}, /* Lb */
248 { termp_sp_pre
, NULL
}, /* Lp */
249 { termp_lk_pre
, NULL
}, /* Lk */
250 { termp_under_pre
, NULL
}, /* Mt */
251 { termp_brq_pre
, termp_brq_post
}, /* Brq */
252 { termp_brq_pre
, termp_brq_post
}, /* Bro */
253 { NULL
, NULL
}, /* Brc */
254 { NULL
, termp____post
}, /* %C */
255 { NULL
, NULL
}, /* Es */ /* TODO */
256 { NULL
, NULL
}, /* En */ /* TODO */
257 { termp_xx_pre
, NULL
}, /* Dx */
258 { NULL
, termp____post
}, /* %Q */
259 { termp_sp_pre
, NULL
}, /* br */
260 { termp_sp_pre
, NULL
}, /* sp */
261 { termp_under_pre
, termp____post
}, /* %U */
266 terminal_mdoc(void *arg
, const struct mdoc
*mdoc
)
268 const struct mdoc_node
*n
;
269 const struct mdoc_meta
*m
;
272 p
= (struct termp
*)arg
;
274 if (NULL
== p
->symtab
)
276 case (TERMENC_ASCII
):
277 p
->symtab
= chars_init(CHARS_ASCII
);
287 print_mdoc_head(p
, NULL
, m
, n
);
289 print_mdoc_nodelist(p
, NULL
, m
, n
->child
);
290 print_foot(p
, NULL
, m
, n
);
295 print_mdoc_nodelist(DECL_ARGS
)
298 print_mdoc_node(p
, pair
, m
, n
);
300 print_mdoc_nodelist(p
, pair
, m
, n
->next
);
306 print_mdoc_node(DECL_ARGS
)
310 struct termpair npair
;
311 size_t offset
, rmargin
;
315 rmargin
= p
->rmargin
;
316 font
= term_fontq(p
);
318 memset(&npair
, 0, sizeof(struct termpair
));
321 if (MDOC_TEXT
!= n
->type
) {
322 if (termacts
[n
->tok
].pre
)
323 chld
= (*termacts
[n
->tok
].pre
)(p
, &npair
, m
, n
);
325 term_word(p
, n
->string
);
327 if (chld
&& n
->child
)
328 print_mdoc_nodelist(p
, &npair
, m
, n
->child
);
330 term_fontpopq(p
, font
);
332 if (MDOC_TEXT
!= n
->type
)
333 if (termacts
[n
->tok
].post
)
334 (*termacts
[n
->tok
].post
)(p
, &npair
, m
, n
);
337 p
->rmargin
= rmargin
;
343 print_foot(DECL_ARGS
)
345 char buf
[DATESIZ
], os
[BUFSIZ
];
347 term_fontrepl(p
, TERMFONT_NONE
);
350 * Output the footer in new-groff style, that is, three columns
351 * with the middle being the manual date and flanking columns
352 * being the operating system:
357 time2a(m
->date
, buf
, DATESIZ
);
358 strlcpy(os
, m
->os
, BUFSIZ
);
363 p
->rmargin
= (p
->maxrmargin
- strlen(buf
) + 1) / 2;
364 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
369 p
->offset
= p
->rmargin
;
370 p
->rmargin
= p
->maxrmargin
- strlen(os
);
371 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
376 p
->offset
= p
->rmargin
;
377 p
->rmargin
= p
->maxrmargin
;
378 p
->flags
&= ~TERMP_NOBREAK
;
379 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
385 p
->rmargin
= p
->maxrmargin
;
392 print_mdoc_head(DECL_ARGS
)
394 char buf
[BUFSIZ
], title
[BUFSIZ
];
396 p
->rmargin
= p
->maxrmargin
;
400 * The header is strange. It has three components, which are
401 * really two with the first duplicated. It goes like this:
403 * IDENTIFIER TITLE IDENTIFIER
405 * The IDENTIFIER is NAME(SECTION), which is the command-name
406 * (if given, or "unknown" if not) followed by the manual page
407 * section. These are given in `Dt'. The TITLE is a free-form
408 * string depending on the manual volume. If not specified, it
409 * switches on the manual section.
413 strlcpy(buf
, m
->vol
, BUFSIZ
);
416 strlcat(buf
, " (", BUFSIZ
);
417 strlcat(buf
, m
->arch
, BUFSIZ
);
418 strlcat(buf
, ")", BUFSIZ
);
421 snprintf(title
, BUFSIZ
, "%s(%d)", m
->title
, m
->msec
);
424 p
->rmargin
= (p
->maxrmargin
- strlen(buf
) + 1) / 2;
425 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
430 p
->offset
= p
->rmargin
;
431 p
->rmargin
= p
->maxrmargin
- strlen(title
);
432 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
437 p
->offset
= p
->rmargin
;
438 p
->rmargin
= p
->maxrmargin
;
439 p
->flags
&= ~TERMP_NOBREAK
;
440 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
446 p
->rmargin
= p
->maxrmargin
;
447 p
->flags
&= ~TERMP_NOSPACE
;
452 a2height(const struct mdoc_node
*n
)
456 assert(MDOC_TEXT
== n
->type
);
458 if ( ! a2roffsu(n
->string
, &su
, SCALE_VS
))
459 SCALE_VS_INIT(&su
, strlen(n
->string
));
461 return(term_vspan(&su
));
466 a2width(const struct mdoc_argv
*arg
, int pos
)
470 assert(arg
->value
[pos
]);
471 if ( ! a2roffsu(arg
->value
[pos
], &su
, SCALE_MAX
))
472 SCALE_HS_INIT(&su
, strlen(arg
->value
[pos
]));
475 return(term_hspan(&su
) + 2);
480 arg_listtype(const struct mdoc_node
*n
)
484 assert(MDOC_BLOCK
== n
->type
);
486 len
= (int)(n
->args
? n
->args
->argc
: 0);
488 for (i
= 0; i
< len
; i
++)
489 switch (n
->args
->argv
[i
].arg
) {
511 return(n
->args
->argv
[i
].arg
);
521 a2offs(const struct mdoc_argv
*arg
)
525 if ('\0' == arg
->value
[0][0])
527 else if (0 == strcmp(arg
->value
[0], "left"))
529 else if (0 == strcmp(arg
->value
[0], "indent"))
531 else if (0 == strcmp(arg
->value
[0], "indent-two"))
532 return((INDENT
+ 1) * 2);
533 else if ( ! a2roffsu(arg
->value
[0], &su
, SCALE_MAX
))
534 SCALE_HS_INIT(&su
, strlen(arg
->value
[0]));
536 return(term_hspan(&su
));
541 arg_hasattr(int arg
, const struct mdoc_node
*n
)
544 return(-1 != arg_getattr(arg
, n
));
549 arg_getattr(int v
, const struct mdoc_node
*n
)
553 return(arg_getattrs(&v
, &val
, 1, n
) ? val
: -1);
558 arg_getattrs(const int *keys
, int *vals
,
559 size_t sz
, const struct mdoc_node
*n
)
566 for (k
= i
= 0; i
< (int)n
->args
->argc
; i
++)
567 for (j
= 0; j
< (int)sz
; j
++)
568 if (n
->args
->argv
[i
].arg
== keys
[j
]) {
577 print_bvspace(struct termp
*p
,
578 const struct mdoc_node
*bl
,
579 const struct mdoc_node
*n
)
581 const struct mdoc_node
*nn
;
584 if (arg_hasattr(MDOC_Compact
, bl
))
587 /* Do not vspace directly after Ss/Sh. */
589 for (nn
= n
; nn
; nn
= nn
->parent
) {
590 if (MDOC_BLOCK
!= nn
->type
)
592 if (MDOC_Ss
== nn
->tok
)
594 if (MDOC_Sh
== nn
->tok
)
596 if (NULL
== nn
->prev
)
601 /* A `-column' does not assert vspace within the list. */
603 if (MDOC_Bl
== bl
->tok
&& arg_hasattr(MDOC_Column
, bl
))
604 if (n
->prev
&& MDOC_It
== n
->prev
->tok
)
607 /* A `-diag' without body does not vspace. */
609 if (MDOC_Bl
== bl
->tok
&& arg_hasattr(MDOC_Diag
, bl
))
610 if (n
->prev
&& MDOC_It
== n
->prev
->tok
) {
611 assert(n
->prev
->body
);
612 if (NULL
== n
->prev
->body
->child
)
622 termp_dq_pre(DECL_ARGS
)
625 if (MDOC_BODY
!= n
->type
)
628 term_word(p
, "\\(lq");
629 p
->flags
|= TERMP_NOSPACE
;
636 termp_dq_post(DECL_ARGS
)
639 if (MDOC_BODY
!= n
->type
)
642 p
->flags
|= TERMP_NOSPACE
;
643 term_word(p
, "\\(rq");
649 termp_it_pre(DECL_ARGS
)
651 const struct mdoc_node
*bl
, *nn
;
653 int i
, type
, keys
[3], vals
[3];
654 size_t width
, offset
;
656 if (MDOC_BLOCK
== n
->type
) {
657 print_bvspace(p
, n
->parent
->parent
, n
);
661 bl
= n
->parent
->parent
->parent
;
663 /* Save parent attributes. */
665 pair
->flag
= p
->flags
;
667 /* Get list width and offset. */
669 keys
[0] = MDOC_Width
;
670 keys
[1] = MDOC_Offset
;
671 keys
[2] = MDOC_Column
;
673 vals
[0] = vals
[1] = vals
[2] = -1;
677 (void)arg_getattrs(keys
, vals
, 3, bl
);
679 type
= arg_listtype(bl
);
682 /* Calculate real width and offset. */
686 if (MDOC_BODY
== n
->type
)
689 * Work around groff's column handling. The offset is
690 * equal to the sum of all widths leading to the current
691 * column (plus the -offset value). If this column
692 * exceeds the stated number of columns, the width is
693 * set as 0, else it's the stated column width (later
694 * the 0 will be adjusted to default 10 or, if in the
695 * last column case, set to stretch to the margin).
697 for (i
= 0, nn
= n
->prev
; nn
&&
698 i
< (int)bl
->args
->argv
[vals
[2]].sz
;
701 (&bl
->args
->argv
[vals
[2]], i
);
703 /* Whether exceeds maximum column. */
704 if (i
< (int)bl
->args
->argv
[vals
[2]].sz
)
705 width
= a2width(&bl
->args
->argv
[vals
[2]], i
);
710 offset
+= a2offs(&bl
->args
->argv
[vals
[1]]);
714 width
= a2width(&bl
->args
->argv
[vals
[0]], 0);
716 offset
+= a2offs(&bl
->args
->argv
[vals
[1]]);
721 * List-type can override the width in the case of fixed-head
722 * values (bullet, dash/hyphen, enum). Tags need a non-zero
754 * Whitespace control. Inset bodies need an initial space,
755 * while diagonal bodies need two.
758 p
->flags
|= TERMP_NOSPACE
;
762 if (MDOC_BODY
== n
->type
)
763 term_word(p
, "\\ \\ ");
766 if (MDOC_BODY
== n
->type
)
773 p
->flags
|= TERMP_NOSPACE
;
777 if (MDOC_HEAD
== n
->type
)
778 term_fontpush(p
, TERMFONT_BOLD
);
785 * Pad and break control. This is the tricker part. Lists with
786 * set right-margins for the head get TERMP_NOBREAK because, if
787 * they overrun the margin, they wrap to the new margin.
788 * Correspondingly, the body for these types don't left-pad, as
789 * the head will pad out to to the right.
800 if (MDOC_HEAD
== n
->type
)
801 p
->flags
|= TERMP_NOBREAK
;
803 p
->flags
|= TERMP_NOLPAD
;
806 if (MDOC_HEAD
== n
->type
)
807 p
->flags
|= TERMP_NOBREAK
;
809 p
->flags
|= TERMP_NOLPAD
;
811 if (MDOC_HEAD
!= n
->type
)
815 * This is ugly. If `-hang' is specified and the body
816 * is a `Bl' or `Bd', then we want basically to nullify
817 * the "overstep" effect in term_flushln() and treat
818 * this as a `-ohang' list instead.
820 if (n
->next
->child
&&
821 (MDOC_Bl
== n
->next
->child
->tok
||
822 MDOC_Bd
== n
->next
->child
->tok
)) {
823 p
->flags
&= ~TERMP_NOBREAK
;
824 p
->flags
&= ~TERMP_NOLPAD
;
826 p
->flags
|= TERMP_HANG
;
829 if (MDOC_HEAD
== n
->type
)
830 p
->flags
|= TERMP_NOBREAK
| TERMP_TWOSPACE
;
832 p
->flags
|= TERMP_NOLPAD
;
834 if (MDOC_HEAD
!= n
->type
)
836 if (NULL
== n
->next
|| NULL
== n
->next
->child
)
837 p
->flags
|= TERMP_DANGLE
;
840 if (MDOC_HEAD
== n
->type
) {
842 if (MDOC_BODY
== n
->next
->type
)
843 p
->flags
&= ~TERMP_NOBREAK
;
845 p
->flags
|= TERMP_NOBREAK
;
847 p
->flags
|= TERMP_NOLPAD
;
851 if (MDOC_HEAD
== n
->type
)
852 p
->flags
|= TERMP_NOBREAK
;
859 * Margin control. Set-head-width lists have their right
860 * margins shortened. The body for these lists has the offset
861 * necessarily lengthened. Everybody gets the offset.
869 * Same stipulation as above, regarding `-hang'. We
870 * don't want to recalculate rmargin and offsets when
871 * using `Bd' or `Bl' within `-hang' overstep lists.
873 if (MDOC_HEAD
== n
->type
&& n
->next
->child
&&
874 (MDOC_Bl
== n
->next
->child
->tok
||
875 MDOC_Bd
== n
->next
->child
->tok
))
888 if (MDOC_HEAD
== n
->type
)
889 p
->rmargin
= p
->offset
+ width
;
895 p
->rmargin
= p
->offset
+ width
;
897 * XXX - this behaviour is not documented: the
898 * right-most column is filled to the right margin.
900 if (MDOC_HEAD
== n
->type
&&
901 MDOC_BODY
== n
->next
->type
)
902 p
->rmargin
= p
->maxrmargin
;
909 * The dash, hyphen, bullet and enum lists all have a special
910 * HEAD character (temporarily bold, in some cases).
913 if (MDOC_HEAD
== n
->type
)
916 term_fontpush(p
, TERMFONT_BOLD
);
917 term_word(p
, "\\[bu]");
923 term_fontpush(p
, TERMFONT_BOLD
);
924 term_word(p
, "\\(hy");
928 (pair
->ppair
->ppair
->count
)++;
929 (void)snprintf(buf
, sizeof(buf
), "%d.",
930 pair
->ppair
->ppair
->count
);
938 * If we're not going to process our children, indicate so here.
951 if (MDOC_HEAD
== n
->type
)
955 if (MDOC_BODY
== n
->type
)
968 termp_it_post(DECL_ARGS
)
972 if (MDOC_BODY
!= n
->type
&& MDOC_HEAD
!= n
->type
)
975 type
= arg_listtype(n
->parent
->parent
->parent
);
984 if (MDOC_BODY
== n
->type
)
988 if (MDOC_HEAD
== n
->type
)
996 p
->flags
= pair
->flag
;
1002 termp_nm_pre(DECL_ARGS
)
1005 if (SEC_SYNOPSIS
== n
->sec
)
1008 term_fontpush(p
, TERMFONT_BOLD
);
1010 if (NULL
== n
->child
)
1011 term_word(p
, m
->name
);
1018 termp_fl_pre(DECL_ARGS
)
1021 term_fontpush(p
, TERMFONT_BOLD
);
1022 term_word(p
, "\\-");
1024 /* A blank `Fl' should incur a subsequent space. */
1027 p
->flags
|= TERMP_NOSPACE
;
1035 termp_an_pre(DECL_ARGS
)
1038 if (NULL
== n
->child
)
1042 * If not in the AUTHORS section, `An -split' will cause
1043 * newlines to occur before the author name. If in the AUTHORS
1044 * section, by default, the first `An' invocation is nosplit,
1045 * then all subsequent ones, regardless of whether interspersed
1046 * with other macros/text, are split. -split, in this case,
1047 * will override the condition of the implied first -nosplit.
1050 if (n
->sec
== SEC_AUTHORS
) {
1051 if ( ! (TERMP_ANPREC
& p
->flags
)) {
1052 if (TERMP_SPLIT
& p
->flags
)
1056 if (TERMP_NOSPLIT
& p
->flags
)
1062 if (TERMP_SPLIT
& p
->flags
)
1071 termp_an_post(DECL_ARGS
)
1075 if (SEC_AUTHORS
== n
->sec
)
1076 p
->flags
|= TERMP_ANPREC
;
1080 if (arg_getattr(MDOC_Split
, n
) > -1) {
1081 p
->flags
&= ~TERMP_NOSPLIT
;
1082 p
->flags
|= TERMP_SPLIT
;
1084 p
->flags
&= ~TERMP_SPLIT
;
1085 p
->flags
|= TERMP_NOSPLIT
;
1093 termp_ns_pre(DECL_ARGS
)
1096 p
->flags
|= TERMP_NOSPACE
;
1103 termp_rs_pre(DECL_ARGS
)
1106 if (SEC_SEE_ALSO
!= n
->sec
)
1108 if (MDOC_BLOCK
== n
->type
&& n
->prev
)
1116 termp_rv_pre(DECL_ARGS
)
1118 const struct mdoc_node
*nn
;
1121 term_word(p
, "The");
1123 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1124 term_fontpush(p
, TERMFONT_BOLD
);
1125 term_word(p
, nn
->string
);
1127 p
->flags
|= TERMP_NOSPACE
;
1128 if (nn
->next
&& NULL
== nn
->next
->next
)
1129 term_word(p
, "(), and");
1131 term_word(p
, "(),");
1137 term_word(p
, "functions return");
1139 term_word(p
, "function returns");
1141 term_word(p
, "the value 0 if successful; otherwise the value "
1142 "-1 is returned and the global variable");
1144 term_fontpush(p
, TERMFONT_UNDER
);
1145 term_word(p
, "errno");
1148 term_word(p
, "is set to indicate the error.");
1156 termp_ex_pre(DECL_ARGS
)
1158 const struct mdoc_node
*nn
;
1160 term_word(p
, "The");
1162 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1163 term_fontpush(p
, TERMFONT_BOLD
);
1164 term_word(p
, nn
->string
);
1166 p
->flags
|= TERMP_NOSPACE
;
1167 if (nn
->next
&& NULL
== nn
->next
->next
)
1168 term_word(p
, ", and");
1172 p
->flags
&= ~TERMP_NOSPACE
;
1176 term_word(p
, "utilities exit");
1178 term_word(p
, "utility exits");
1180 term_word(p
, "0 on success, and >0 if an error occurs.");
1188 termp_nd_pre(DECL_ARGS
)
1191 if (MDOC_BODY
!= n
->type
)
1194 #if defined(__OpenBSD__) || defined(__linux__)
1195 term_word(p
, "\\(en");
1197 term_word(p
, "\\(em");
1205 termp_bl_post(DECL_ARGS
)
1208 if (MDOC_BLOCK
== n
->type
)
1215 termp_op_post(DECL_ARGS
)
1218 if (MDOC_BODY
!= n
->type
)
1220 p
->flags
|= TERMP_NOSPACE
;
1221 term_word(p
, "\\(rB");
1227 termp_xr_pre(DECL_ARGS
)
1229 const struct mdoc_node
*nn
;
1231 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1234 term_word(p
, nn
->string
);
1235 if (NULL
== (nn
= nn
->next
))
1237 p
->flags
|= TERMP_NOSPACE
;
1239 p
->flags
|= TERMP_NOSPACE
;
1240 term_word(p
, nn
->string
);
1241 p
->flags
|= TERMP_NOSPACE
;
1250 termp_vt_post(DECL_ARGS
)
1253 if (n
->sec
!= SEC_SYNOPSIS
)
1255 if (n
->next
&& MDOC_Vt
== n
->next
->tok
)
1264 termp_bold_pre(DECL_ARGS
)
1267 term_fontpush(p
, TERMFONT_BOLD
);
1274 termp_fd_post(DECL_ARGS
)
1277 if (n
->sec
!= SEC_SYNOPSIS
)
1281 if (n
->next
&& MDOC_Fd
!= n
->next
->tok
)
1288 termp_sh_pre(DECL_ARGS
)
1291 /* No vspace between consecutive `Sh' calls. */
1295 if (n
->prev
&& MDOC_Sh
== n
->prev
->tok
)
1296 if (NULL
== n
->prev
->body
->child
)
1301 term_fontpush(p
, TERMFONT_BOLD
);
1315 termp_sh_post(DECL_ARGS
)
1334 termp_op_pre(DECL_ARGS
)
1339 term_word(p
, "\\(lB");
1340 p
->flags
|= TERMP_NOSPACE
;
1351 termp_bt_pre(DECL_ARGS
)
1354 term_word(p
, "is currently in beta test.");
1361 termp_lb_post(DECL_ARGS
)
1364 if (SEC_LIBRARY
== n
->sec
)
1371 termp_ud_pre(DECL_ARGS
)
1374 term_word(p
, "currently under development.");
1381 termp_d1_pre(DECL_ARGS
)
1384 if (MDOC_BLOCK
!= n
->type
)
1387 p
->offset
+= (INDENT
+ 1);
1394 termp_d1_post(DECL_ARGS
)
1397 if (MDOC_BLOCK
!= n
->type
)
1405 termp_aq_pre(DECL_ARGS
)
1408 if (MDOC_BODY
!= n
->type
)
1410 term_word(p
, "\\(la");
1411 p
->flags
|= TERMP_NOSPACE
;
1418 termp_aq_post(DECL_ARGS
)
1421 if (MDOC_BODY
!= n
->type
)
1423 p
->flags
|= TERMP_NOSPACE
;
1424 term_word(p
, "\\(ra");
1430 termp_ft_pre(DECL_ARGS
)
1433 if (SEC_SYNOPSIS
== n
->sec
)
1434 if (n
->prev
&& MDOC_Fo
== n
->prev
->tok
)
1437 term_fontpush(p
, TERMFONT_UNDER
);
1444 termp_ft_post(DECL_ARGS
)
1447 if (SEC_SYNOPSIS
== n
->sec
)
1454 termp_fn_pre(DECL_ARGS
)
1456 const struct mdoc_node
*nn
;
1458 term_fontpush(p
, TERMFONT_BOLD
);
1459 term_word(p
, n
->child
->string
);
1462 p
->flags
|= TERMP_NOSPACE
;
1465 for (nn
= n
->child
->next
; nn
; nn
= nn
->next
) {
1466 term_fontpush(p
, TERMFONT_UNDER
);
1467 term_word(p
, nn
->string
);
1476 if (SEC_SYNOPSIS
== n
->sec
)
1485 termp_fn_post(DECL_ARGS
)
1488 if (n
->sec
== SEC_SYNOPSIS
&& n
->next
)
1495 termp_fa_pre(DECL_ARGS
)
1497 const struct mdoc_node
*nn
;
1499 if (n
->parent
->tok
!= MDOC_Fo
) {
1500 term_fontpush(p
, TERMFONT_UNDER
);
1504 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1505 term_fontpush(p
, TERMFONT_UNDER
);
1506 term_word(p
, nn
->string
);
1513 if (n
->child
&& n
->next
&& n
->next
->tok
== MDOC_Fa
)
1522 termp_bd_pre(DECL_ARGS
)
1525 const struct mdoc_node
*nn
;
1527 if (MDOC_BLOCK
== n
->type
) {
1528 print_bvspace(p
, n
, n
);
1530 } else if (MDOC_BODY
!= n
->type
)
1535 for (type
= -1, i
= 0; i
< (int)nn
->args
->argc
; i
++) {
1536 switch (nn
->args
->argv
[i
].arg
) {
1537 case (MDOC_Centred
):
1543 case (MDOC_Unfilled
):
1545 case (MDOC_Literal
):
1546 type
= nn
->args
->argv
[i
].arg
;
1549 p
->offset
+= a2offs(&nn
->args
->argv
[i
]);
1557 * If -ragged or -filled are specified, the block does nothing
1558 * but change the indentation. If -unfilled or -literal are
1559 * specified, text is printed exactly as entered in the display:
1560 * for macro lines, a newline is appended to the line. Blank
1561 * lines are allowed.
1565 if (MDOC_Literal
!= type
&& MDOC_Unfilled
!= type
)
1568 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1569 p
->flags
|= TERMP_NOSPACE
;
1570 print_mdoc_node(p
, pair
, m
, nn
);
1571 if (NULL
== nn
->next
)
1573 if (nn
->prev
&& nn
->prev
->line
< nn
->line
)
1575 else if (NULL
== nn
->prev
)
1585 termp_bd_post(DECL_ARGS
)
1588 if (MDOC_BODY
!= n
->type
)
1590 p
->flags
|= TERMP_NOSPACE
;
1597 termp_qq_pre(DECL_ARGS
)
1600 if (MDOC_BODY
!= n
->type
)
1603 p
->flags
|= TERMP_NOSPACE
;
1610 termp_qq_post(DECL_ARGS
)
1613 if (MDOC_BODY
!= n
->type
)
1615 p
->flags
|= TERMP_NOSPACE
;
1622 termp_bx_post(DECL_ARGS
)
1626 p
->flags
|= TERMP_NOSPACE
;
1627 term_word(p
, "BSD");
1633 termp_xx_pre(DECL_ARGS
)
1669 termp_sq_pre(DECL_ARGS
)
1672 if (MDOC_BODY
!= n
->type
)
1674 term_word(p
, "\\(oq");
1675 p
->flags
|= TERMP_NOSPACE
;
1682 termp_sq_post(DECL_ARGS
)
1685 if (MDOC_BODY
!= n
->type
)
1687 p
->flags
|= TERMP_NOSPACE
;
1688 term_word(p
, "\\(aq");
1694 termp_pf_pre(DECL_ARGS
)
1697 p
->flags
|= TERMP_IGNDELIM
;
1704 termp_pf_post(DECL_ARGS
)
1707 p
->flags
&= ~TERMP_IGNDELIM
;
1708 p
->flags
|= TERMP_NOSPACE
;
1714 termp_ss_pre(DECL_ARGS
)
1724 term_fontpush(p
, TERMFONT_BOLD
);
1725 p
->offset
= HALFINDENT
;
1737 termp_ss_post(DECL_ARGS
)
1740 if (MDOC_HEAD
== n
->type
)
1747 termp_cd_pre(DECL_ARGS
)
1750 term_fontpush(p
, TERMFONT_BOLD
);
1758 termp_in_pre(DECL_ARGS
)
1761 term_fontpush(p
, TERMFONT_BOLD
);
1762 if (SEC_SYNOPSIS
== n
->sec
)
1763 term_word(p
, "#include");
1766 p
->flags
|= TERMP_NOSPACE
;
1773 termp_in_post(DECL_ARGS
)
1776 term_fontpush(p
, TERMFONT_BOLD
);
1777 p
->flags
|= TERMP_NOSPACE
;
1781 if (SEC_SYNOPSIS
!= n
->sec
)
1786 * XXX Not entirely correct. If `.In foo bar' is specified in
1787 * the SYNOPSIS section, then it produces a single break after
1788 * the <foo>; mandoc asserts a vertical space. Since this
1789 * construction is rarely used, I think it's fine.
1791 if (n
->next
&& MDOC_In
!= n
->next
->tok
)
1798 termp_sp_pre(DECL_ARGS
)
1804 len
= n
->child
? a2height(n
->child
) : 1;
1816 for (i
= 0; i
< len
; i
++)
1825 termp_brq_pre(DECL_ARGS
)
1828 if (MDOC_BODY
!= n
->type
)
1830 term_word(p
, "\\(lC");
1831 p
->flags
|= TERMP_NOSPACE
;
1838 termp_brq_post(DECL_ARGS
)
1841 if (MDOC_BODY
!= n
->type
)
1843 p
->flags
|= TERMP_NOSPACE
;
1844 term_word(p
, "\\(rC");
1850 termp_bq_pre(DECL_ARGS
)
1853 if (MDOC_BODY
!= n
->type
)
1855 term_word(p
, "\\(lB");
1856 p
->flags
|= TERMP_NOSPACE
;
1863 termp_bq_post(DECL_ARGS
)
1866 if (MDOC_BODY
!= n
->type
)
1868 p
->flags
|= TERMP_NOSPACE
;
1869 term_word(p
, "\\(rB");
1875 termp_pq_pre(DECL_ARGS
)
1878 if (MDOC_BODY
!= n
->type
)
1880 term_word(p
, "\\&(");
1881 p
->flags
|= TERMP_NOSPACE
;
1888 termp_pq_post(DECL_ARGS
)
1891 if (MDOC_BODY
!= n
->type
)
1899 termp_fo_pre(DECL_ARGS
)
1901 const struct mdoc_node
*nn
;
1903 if (MDOC_BODY
== n
->type
) {
1904 p
->flags
|= TERMP_NOSPACE
;
1906 p
->flags
|= TERMP_NOSPACE
;
1908 } else if (MDOC_HEAD
!= n
->type
)
1911 term_fontpush(p
, TERMFONT_BOLD
);
1912 for (nn
= n
->child
; nn
; nn
= nn
->next
) {
1913 assert(MDOC_TEXT
== nn
->type
);
1914 term_word(p
, nn
->string
);
1924 termp_fo_post(DECL_ARGS
)
1927 if (MDOC_BODY
!= n
->type
)
1929 p
->flags
|= TERMP_NOSPACE
;
1931 p
->flags
|= TERMP_NOSPACE
;
1939 termp_bf_pre(DECL_ARGS
)
1941 const struct mdoc_node
*nn
;
1943 if (MDOC_HEAD
== n
->type
)
1945 else if (MDOC_BLOCK
!= n
->type
)
1948 if (NULL
== (nn
= n
->head
->child
)) {
1949 if (arg_hasattr(MDOC_Emphasis
, n
))
1950 term_fontpush(p
, TERMFONT_UNDER
);
1951 else if (arg_hasattr(MDOC_Symbolic
, n
))
1952 term_fontpush(p
, TERMFONT_BOLD
);
1954 term_fontpush(p
, TERMFONT_NONE
);
1959 assert(MDOC_TEXT
== nn
->type
);
1960 if (0 == strcmp("Em", nn
->string
))
1961 term_fontpush(p
, TERMFONT_UNDER
);
1962 else if (0 == strcmp("Sy", nn
->string
))
1963 term_fontpush(p
, TERMFONT_BOLD
);
1965 term_fontpush(p
, TERMFONT_NONE
);
1973 termp_sm_pre(DECL_ARGS
)
1976 assert(n
->child
&& MDOC_TEXT
== n
->child
->type
);
1977 if (0 == strcmp("on", n
->child
->string
)) {
1978 p
->flags
&= ~TERMP_NONOSPACE
;
1979 p
->flags
&= ~TERMP_NOSPACE
;
1981 p
->flags
|= TERMP_NONOSPACE
;
1989 termp_ap_pre(DECL_ARGS
)
1992 p
->flags
|= TERMP_NOSPACE
;
1993 term_word(p
, "\\(aq");
1994 p
->flags
|= TERMP_NOSPACE
;
2001 termp____post(DECL_ARGS
)
2006 p
->flags
|= TERMP_NOSPACE
;
2009 term_word(p
, "\\(rq");
2010 p
->flags
|= TERMP_NOSPACE
;
2015 term_word(p
, n
->next
? "," : ".");
2021 termp_li_pre(DECL_ARGS
)
2024 term_fontpush(p
, TERMFONT_NONE
);
2031 termp_lk_pre(DECL_ARGS
)
2033 const struct mdoc_node
*nn
;
2035 term_fontpush(p
, TERMFONT_UNDER
);
2038 if (NULL
== nn
->next
)
2041 term_word(p
, nn
->string
);
2044 p
->flags
|= TERMP_NOSPACE
;
2047 term_fontpush(p
, TERMFONT_BOLD
);
2048 for (nn
= nn
->next
; nn
; nn
= nn
->next
)
2049 term_word(p
, nn
->string
);
2058 termp_under_pre(DECL_ARGS
)
2061 term_fontpush(p
, TERMFONT_UNDER
);
2068 termp__t_pre(DECL_ARGS
)
2071 term_word(p
, "\\(lq");
2072 p
->flags
|= TERMP_NOSPACE
;