]>
git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
2bd7cd2f3027be0ce252749125f34d51d398086a
1 /* $Id: mdoc_term.c,v 1.68 2009/08/20 13:22:48 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>
33 #define TTYPE_CMD_FLAG 1
34 #define TTYPE_CMD_ARG 2
35 #define TTYPE_SECTION 3
36 #define TTYPE_FUNC_DECL 4
37 #define TTYPE_VAR_DECL 5
38 #define TTYPE_FUNC_TYPE 6
39 #define TTYPE_FUNC_NAME 7
40 #define TTYPE_FUNC_ARG 8
42 #define TTYPE_SSECTION 10
45 #define TTYPE_CONFIG 13
47 #define TTYPE_INCLUDE 15
49 #define TTYPE_SYMBOL 17
51 #define TTYPE_LINK_ANCHOR 19
52 #define TTYPE_LINK_TEXT 20
53 #define TTYPE_REF_JOURNAL 21
54 #define TTYPE_REF_TITLE 22
58 const int ttypes
[TTYPE_NMAX
] = {
59 TERMP_BOLD
, /* TTYPE_PROG */
60 TERMP_BOLD
, /* TTYPE_CMD_FLAG */
61 TERMP_UNDER
, /* TTYPE_CMD_ARG */
62 TERMP_BOLD
, /* TTYPE_SECTION */
63 TERMP_BOLD
, /* TTYPE_FUNC_DECL */
64 TERMP_UNDER
, /* TTYPE_VAR_DECL */
65 TERMP_UNDER
, /* TTYPE_FUNC_TYPE */
66 TERMP_BOLD
, /* TTYPE_FUNC_NAME */
67 TERMP_UNDER
, /* TTYPE_FUNC_ARG */
68 TERMP_UNDER
, /* TTYPE_LINK */
69 TERMP_BOLD
, /* TTYPE_SSECTION */
70 TERMP_UNDER
, /* TTYPE_FILE */
71 TERMP_UNDER
, /* TTYPE_EMPH */
72 TERMP_BOLD
, /* TTYPE_CONFIG */
73 TERMP_BOLD
, /* TTYPE_CMD */
74 TERMP_BOLD
, /* TTYPE_INCLUDE */
75 TERMP_BOLD
, /* TTYPE_SYMB */
76 TERMP_BOLD
, /* TTYPE_SYMBOL */
77 TERMP_BOLD
, /* TTYPE_DIAG */
78 TERMP_UNDER
, /* TTYPE_LINK_ANCHOR */
79 TERMP_BOLD
, /* TTYPE_LINK_TEXT */
80 TERMP_UNDER
, /* TTYPE_REF_JOURNAL */
81 TERMP_UNDER
, /* TTYPE_REF_TITLE */
82 TERMP_BOLD
/* TTYPE_LIST */
86 struct termpair
*ppair
;
91 #define DECL_ARGS struct termp *p, \
92 struct termpair *pair, \
93 const struct mdoc_meta *meta, \
94 const struct mdoc_node *node
97 int (*pre
)(DECL_ARGS
);
98 void (*post
)(DECL_ARGS
);
101 static void termp____post(DECL_ARGS
);
102 static void termp_an_post(DECL_ARGS
);
103 static void termp_aq_post(DECL_ARGS
);
104 static void termp_bd_post(DECL_ARGS
);
105 static void termp_bl_post(DECL_ARGS
);
106 static void termp_bq_post(DECL_ARGS
);
107 static void termp_brq_post(DECL_ARGS
);
108 static void termp_bx_post(DECL_ARGS
);
109 static void termp_d1_post(DECL_ARGS
);
110 static void termp_dq_post(DECL_ARGS
);
111 static void termp_fd_post(DECL_ARGS
);
112 static void termp_fn_post(DECL_ARGS
);
113 static void termp_fo_post(DECL_ARGS
);
114 static void termp_ft_post(DECL_ARGS
);
115 static void termp_in_post(DECL_ARGS
);
116 static void termp_it_post(DECL_ARGS
);
117 static void termp_lb_post(DECL_ARGS
);
118 static void termp_op_post(DECL_ARGS
);
119 static void termp_pf_post(DECL_ARGS
);
120 static void termp_pq_post(DECL_ARGS
);
121 static void termp_qq_post(DECL_ARGS
);
122 static void termp_sh_post(DECL_ARGS
);
123 static void termp_sq_post(DECL_ARGS
);
124 static void termp_ss_post(DECL_ARGS
);
125 static void termp_vt_post(DECL_ARGS
);
127 static int termp__j_pre(DECL_ARGS
);
128 static int termp__t_pre(DECL_ARGS
);
129 static int termp_an_pre(DECL_ARGS
);
130 static int termp_ap_pre(DECL_ARGS
);
131 static int termp_aq_pre(DECL_ARGS
);
132 static int termp_ar_pre(DECL_ARGS
);
133 static int termp_bd_pre(DECL_ARGS
);
134 static int termp_bf_pre(DECL_ARGS
);
135 static int termp_bq_pre(DECL_ARGS
);
136 static int termp_br_pre(DECL_ARGS
);
137 static int termp_brq_pre(DECL_ARGS
);
138 static int termp_bt_pre(DECL_ARGS
);
139 static int termp_cd_pre(DECL_ARGS
);
140 static int termp_cm_pre(DECL_ARGS
);
141 static int termp_d1_pre(DECL_ARGS
);
142 static int termp_dq_pre(DECL_ARGS
);
143 static int termp_em_pre(DECL_ARGS
);
144 static int termp_ex_pre(DECL_ARGS
);
145 static int termp_fa_pre(DECL_ARGS
);
146 static int termp_fd_pre(DECL_ARGS
);
147 static int termp_fl_pre(DECL_ARGS
);
148 static int termp_fn_pre(DECL_ARGS
);
149 static int termp_fo_pre(DECL_ARGS
);
150 static int termp_ft_pre(DECL_ARGS
);
151 static int termp_ic_pre(DECL_ARGS
);
152 static int termp_in_pre(DECL_ARGS
);
153 static int termp_it_pre(DECL_ARGS
);
154 static int termp_lk_pre(DECL_ARGS
);
155 static int termp_ms_pre(DECL_ARGS
);
156 static int termp_mt_pre(DECL_ARGS
);
157 static int termp_nd_pre(DECL_ARGS
);
158 static int termp_nm_pre(DECL_ARGS
);
159 static int termp_ns_pre(DECL_ARGS
);
160 static int termp_op_pre(DECL_ARGS
);
161 static int termp_pa_pre(DECL_ARGS
);
162 static int termp_pf_pre(DECL_ARGS
);
163 static int termp_pp_pre(DECL_ARGS
);
164 static int termp_pq_pre(DECL_ARGS
);
165 static int termp_qq_pre(DECL_ARGS
);
166 static int termp_rs_pre(DECL_ARGS
);
167 static int termp_rv_pre(DECL_ARGS
);
168 static int termp_sh_pre(DECL_ARGS
);
169 static int termp_sm_pre(DECL_ARGS
);
170 static int termp_sp_pre(DECL_ARGS
);
171 static int termp_sq_pre(DECL_ARGS
);
172 static int termp_ss_pre(DECL_ARGS
);
173 static int termp_sx_pre(DECL_ARGS
);
174 static int termp_sy_pre(DECL_ARGS
);
175 static int termp_ud_pre(DECL_ARGS
);
176 static int termp_va_pre(DECL_ARGS
);
177 static int termp_vt_pre(DECL_ARGS
);
178 static int termp_xr_pre(DECL_ARGS
);
179 static int termp_xx_pre(DECL_ARGS
);
181 static const struct termact termacts
[MDOC_MAX
] = {
182 { termp_ap_pre
, NULL
}, /* Ap */
183 { NULL
, NULL
}, /* Dd */
184 { NULL
, NULL
}, /* Dt */
185 { NULL
, NULL
}, /* Os */
186 { termp_sh_pre
, termp_sh_post
}, /* Sh */
187 { termp_ss_pre
, termp_ss_post
}, /* Ss */
188 { termp_pp_pre
, NULL
}, /* Pp */
189 { termp_d1_pre
, termp_d1_post
}, /* D1 */
190 { termp_d1_pre
, termp_d1_post
}, /* Dl */
191 { termp_bd_pre
, termp_bd_post
}, /* Bd */
192 { NULL
, NULL
}, /* Ed */
193 { NULL
, termp_bl_post
}, /* Bl */
194 { NULL
, NULL
}, /* El */
195 { termp_it_pre
, termp_it_post
}, /* It */
196 { NULL
, NULL
}, /* Ad */
197 { termp_an_pre
, termp_an_post
}, /* An */
198 { termp_ar_pre
, NULL
}, /* Ar */
199 { termp_cd_pre
, NULL
}, /* Cd */
200 { termp_cm_pre
, NULL
}, /* Cm */
201 { NULL
, NULL
}, /* Dv */
202 { NULL
, NULL
}, /* Er */
203 { NULL
, NULL
}, /* Ev */
204 { termp_ex_pre
, NULL
}, /* Ex */
205 { termp_fa_pre
, NULL
}, /* Fa */
206 { termp_fd_pre
, termp_fd_post
}, /* Fd */
207 { termp_fl_pre
, NULL
}, /* Fl */
208 { termp_fn_pre
, termp_fn_post
}, /* Fn */
209 { termp_ft_pre
, termp_ft_post
}, /* Ft */
210 { termp_ic_pre
, NULL
}, /* Ic */
211 { termp_in_pre
, termp_in_post
}, /* In */
212 { NULL
, NULL
}, /* Li */
213 { termp_nd_pre
, NULL
}, /* Nd */
214 { termp_nm_pre
, NULL
}, /* Nm */
215 { termp_op_pre
, termp_op_post
}, /* Op */
216 { NULL
, NULL
}, /* Ot */
217 { termp_pa_pre
, NULL
}, /* Pa */
218 { termp_rv_pre
, NULL
}, /* Rv */
219 { NULL
, NULL
}, /* St */
220 { termp_va_pre
, NULL
}, /* Va */
221 { termp_vt_pre
, termp_vt_post
}, /* Vt */
222 { termp_xr_pre
, NULL
}, /* Xr */
223 { NULL
, termp____post
}, /* %A */
224 { NULL
, termp____post
}, /* %B */
225 { NULL
, termp____post
}, /* %D */
226 { NULL
, termp____post
}, /* %I */
227 { termp__j_pre
, termp____post
}, /* %J */
228 { NULL
, termp____post
}, /* %N */
229 { NULL
, termp____post
}, /* %O */
230 { NULL
, termp____post
}, /* %P */
231 { NULL
, termp____post
}, /* %R */
232 { termp__t_pre
, termp____post
}, /* %T */
233 { NULL
, termp____post
}, /* %V */
234 { NULL
, NULL
}, /* Ac */
235 { termp_aq_pre
, termp_aq_post
}, /* Ao */
236 { termp_aq_pre
, termp_aq_post
}, /* Aq */
237 { NULL
, NULL
}, /* At */
238 { NULL
, NULL
}, /* Bc */
239 { termp_bf_pre
, NULL
}, /* Bf */
240 { termp_bq_pre
, termp_bq_post
}, /* Bo */
241 { termp_bq_pre
, termp_bq_post
}, /* Bq */
242 { termp_xx_pre
, NULL
}, /* Bsx */
243 { NULL
, termp_bx_post
}, /* Bx */
244 { NULL
, NULL
}, /* Db */
245 { NULL
, NULL
}, /* Dc */
246 { termp_dq_pre
, termp_dq_post
}, /* Do */
247 { termp_dq_pre
, termp_dq_post
}, /* Dq */
248 { NULL
, NULL
}, /* Ec */
249 { NULL
, NULL
}, /* Ef */
250 { termp_em_pre
, NULL
}, /* Em */
251 { NULL
, NULL
}, /* Eo */
252 { termp_xx_pre
, NULL
}, /* Fx */
253 { termp_ms_pre
, NULL
}, /* Ms */
254 { NULL
, NULL
}, /* No */
255 { termp_ns_pre
, NULL
}, /* Ns */
256 { termp_xx_pre
, NULL
}, /* Nx */
257 { termp_xx_pre
, NULL
}, /* Ox */
258 { NULL
, NULL
}, /* Pc */
259 { termp_pf_pre
, termp_pf_post
}, /* Pf */
260 { termp_pq_pre
, termp_pq_post
}, /* Po */
261 { termp_pq_pre
, termp_pq_post
}, /* Pq */
262 { NULL
, NULL
}, /* Qc */
263 { termp_sq_pre
, termp_sq_post
}, /* Ql */
264 { termp_qq_pre
, termp_qq_post
}, /* Qo */
265 { termp_qq_pre
, termp_qq_post
}, /* Qq */
266 { NULL
, NULL
}, /* Re */
267 { termp_rs_pre
, NULL
}, /* Rs */
268 { NULL
, NULL
}, /* Sc */
269 { termp_sq_pre
, termp_sq_post
}, /* So */
270 { termp_sq_pre
, termp_sq_post
}, /* Sq */
271 { termp_sm_pre
, NULL
}, /* Sm */
272 { termp_sx_pre
, NULL
}, /* Sx */
273 { termp_sy_pre
, NULL
}, /* Sy */
274 { NULL
, NULL
}, /* Tn */
275 { termp_xx_pre
, NULL
}, /* Ux */
276 { NULL
, NULL
}, /* Xc */
277 { NULL
, NULL
}, /* Xo */
278 { termp_fo_pre
, termp_fo_post
}, /* Fo */
279 { NULL
, NULL
}, /* Fc */
280 { termp_op_pre
, termp_op_post
}, /* Oo */
281 { NULL
, NULL
}, /* Oc */
282 { NULL
, NULL
}, /* Bk */
283 { NULL
, NULL
}, /* Ek */
284 { termp_bt_pre
, NULL
}, /* Bt */
285 { NULL
, NULL
}, /* Hf */
286 { NULL
, NULL
}, /* Fr */
287 { termp_ud_pre
, NULL
}, /* Ud */
288 { NULL
, termp_lb_post
}, /* Lb */
289 { termp_pp_pre
, NULL
}, /* Lp */
290 { termp_lk_pre
, NULL
}, /* Lk */
291 { termp_mt_pre
, NULL
}, /* Mt */
292 { termp_brq_pre
, termp_brq_post
}, /* Brq */
293 { termp_brq_pre
, termp_brq_post
}, /* Bro */
294 { NULL
, NULL
}, /* Brc */
295 { NULL
, NULL
}, /* %C */
296 { NULL
, NULL
}, /* Es */
297 { NULL
, NULL
}, /* En */
298 { termp_xx_pre
, NULL
}, /* Dx */
299 { NULL
, NULL
}, /* %Q */
300 { termp_br_pre
, NULL
}, /* br */
301 { termp_sp_pre
, NULL
}, /* sp */
305 extern size_t strlcpy(char *, const char *, size_t);
306 extern size_t strlcat(char *, const char *, size_t);
309 static int arg_hasattr(int, const struct mdoc_node
*);
310 static int arg_getattrs(const int *, int *, size_t,
311 const struct mdoc_node
*);
312 static int arg_getattr(int, const struct mdoc_node
*);
313 static size_t arg_offset(const struct mdoc_argv
*);
314 static size_t arg_width(const struct mdoc_argv
*, int);
315 static int arg_listtype(const struct mdoc_node
*);
316 static void fmt_block_vspace(struct termp
*,
317 const struct mdoc_node
*,
318 const struct mdoc_node
*);
319 static void print_node(DECL_ARGS
);
320 static void print_head(struct termp
*,
321 const struct mdoc_meta
*);
322 static void print_body(DECL_ARGS
);
323 static void print_foot(struct termp
*,
324 const struct mdoc_meta
*);
328 mdoc_run(struct termp
*p
, const struct mdoc
*m
)
331 * Main output function. When this is called, assume that the
332 * tree is properly formed.
334 print_head(p
, mdoc_meta(m
));
335 assert(mdoc_node(m
));
336 assert(MDOC_ROOT
== mdoc_node(m
)->type
);
337 if (mdoc_node(m
)->child
)
338 print_body(p
, NULL
, mdoc_meta(m
), mdoc_node(m
)->child
);
339 print_foot(p
, mdoc_meta(m
));
345 print_body(DECL_ARGS
)
348 print_node(p
, pair
, meta
, node
);
351 print_body(p
, pair
, meta
, node
->next
);
356 print_node(DECL_ARGS
)
359 struct termpair npair
;
360 size_t offset
, rmargin
;
364 rmargin
= p
->rmargin
;
371 * Note on termpair. This allows a pre function to set a termp
372 * flag that is automatically unset after the body, but before
373 * the post function. Thus, if a pre uses a termpair flag, it
374 * must be reapplied in the post for use.
377 if (MDOC_TEXT
!= node
->type
) {
378 if (termacts
[node
->tok
].pre
)
379 if ( ! (*termacts
[node
->tok
].pre
)(p
, &npair
, meta
, node
))
381 } else /* MDOC_TEXT == node->type */
382 term_word(p
, node
->string
);
386 p
->flags
|= npair
.flag
;
388 if (dochild
&& node
->child
)
389 print_body(p
, &npair
, meta
, node
->child
);
391 p
->flags
&= ~npair
.flag
;
393 /* Post-processing. */
395 if (MDOC_TEXT
!= node
->type
)
396 if (termacts
[node
->tok
].post
)
397 (*termacts
[node
->tok
].post
)(p
, &npair
, meta
, node
);
400 p
->rmargin
= rmargin
;
405 print_foot(struct termp
*p
, const struct mdoc_meta
*meta
)
411 * Output the footer in new-groff style, that is, three columns
412 * with the middle being the manual date and flanking columns
413 * being the operating system:
418 if (NULL
== (buf
= malloc(p
->rmargin
)))
420 if (NULL
== (os
= malloc(p
->rmargin
)))
423 tm
= localtime(&meta
->date
);
425 if (0 == strftime(buf
, p
->rmargin
, "%B %e, %Y", tm
))
428 (void)strlcpy(os
, meta
->os
, p
->rmargin
);
433 p
->rmargin
= (p
->maxrmargin
- strlen(buf
) + 1) / 2;
434 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
439 p
->offset
= p
->rmargin
;
440 p
->rmargin
= p
->maxrmargin
- strlen(os
);
441 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
446 p
->offset
= p
->rmargin
;
447 p
->rmargin
= p
->maxrmargin
;
448 p
->flags
&= ~TERMP_NOBREAK
;
449 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
455 p
->rmargin
= p
->maxrmargin
;
464 print_head(struct termp
*p
, const struct mdoc_meta
*meta
)
468 p
->rmargin
= p
->maxrmargin
;
471 if (NULL
== (buf
= malloc(p
->rmargin
)))
473 if (NULL
== (title
= malloc(p
->rmargin
)))
477 * The header is strange. It has three components, which are
478 * really two with the first duplicated. It goes like this:
480 * IDENTIFIER TITLE IDENTIFIER
482 * The IDENTIFIER is NAME(SECTION), which is the command-name
483 * (if given, or "unknown" if not) followed by the manual page
484 * section. These are given in `Dt'. The TITLE is a free-form
485 * string depending on the manual volume. If not specified, it
486 * switches on the manual section.
490 (void)strlcpy(buf
, meta
->vol
, p
->rmargin
);
493 (void)strlcat(buf
, " (", p
->rmargin
);
494 (void)strlcat(buf
, meta
->arch
, p
->rmargin
);
495 (void)strlcat(buf
, ")", p
->rmargin
);
498 (void)snprintf(title
, p
->rmargin
, "%s(%d)",
499 meta
->title
, meta
->msec
);
502 p
->rmargin
= (p
->maxrmargin
- strlen(buf
) + 1) / 2;
503 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
508 p
->offset
= p
->rmargin
;
509 p
->rmargin
= p
->maxrmargin
- strlen(title
);
510 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
515 p
->offset
= p
->rmargin
;
516 p
->rmargin
= p
->maxrmargin
;
517 p
->flags
&= ~TERMP_NOBREAK
;
518 p
->flags
|= TERMP_NOLPAD
| TERMP_NOSPACE
;
524 p
->rmargin
= p
->maxrmargin
;
525 p
->flags
&= ~TERMP_NOSPACE
;
533 arg_width(const struct mdoc_argv
*arg
, int pos
)
538 assert(pos
< (int)arg
->sz
&& pos
>= 0);
539 assert(arg
->value
[pos
]);
543 if (0 == (len
= (int)strlen(p
)))
546 for (i
= 0; i
< len
- 1; i
++)
547 if ( ! isdigit((u_char
)p
[i
]))
551 if ('n' == p
[len
- 1] || 'm' == p
[len
- 1])
552 return((size_t)atoi(p
) + 2);
554 return((size_t)len
+ 2);
559 arg_listtype(const struct mdoc_node
*n
)
563 assert(MDOC_BLOCK
== n
->type
);
565 len
= (int)(n
->args
? n
->args
->argc
: 0);
567 for (i
= 0; i
< len
; i
++)
568 switch (n
->args
->argv
[i
].arg
) {
590 return(n
->args
->argv
[i
].arg
);
600 arg_offset(const struct mdoc_argv
*arg
)
608 if (0 == strcmp(p
, "left"))
610 if (0 == strcmp(p
, "indent"))
612 if (0 == strcmp(p
, "indent-two"))
613 return((INDENT
+ 1) * 2);
615 if (0 == (len
= (int)strlen(p
)))
618 for (i
= 0; i
< len
- 1; i
++)
619 if ( ! isdigit((u_char
)p
[i
]))
623 if ('n' == p
[len
- 1] || 'm' == p
[len
- 1])
624 return((size_t)atoi(p
));
631 arg_hasattr(int arg
, const struct mdoc_node
*n
)
634 return(-1 != arg_getattr(arg
, n
));
639 arg_getattr(int v
, const struct mdoc_node
*n
)
643 return(arg_getattrs(&v
, &val
, 1, n
) ? val
: -1);
648 arg_getattrs(const int *keys
, int *vals
,
649 size_t sz
, const struct mdoc_node
*n
)
656 for (k
= i
= 0; i
< (int)n
->args
->argc
; i
++)
657 for (j
= 0; j
< (int)sz
; j
++)
658 if (n
->args
->argv
[i
].arg
== keys
[j
]) {
668 fmt_block_vspace(struct termp
*p
,
669 const struct mdoc_node
*bl
,
670 const struct mdoc_node
*node
)
672 const struct mdoc_node
*n
;
676 if (MDOC_Bl
== bl
->tok
&& arg_hasattr(MDOC_Compact
, bl
))
681 * Search through our prior nodes. If we follow a `Ss' or `Sh',
685 for (n
= node
; n
; n
= n
->parent
) {
686 if (MDOC_BLOCK
!= n
->type
)
688 if (MDOC_Ss
== n
->tok
)
690 if (MDOC_Sh
== n
->tok
)
698 * XXX - not documented: a `-column' does not ever assert vspace
702 if (MDOC_Bl
== bl
->tok
&& arg_hasattr(MDOC_Column
, bl
))
703 if (node
->prev
&& MDOC_It
== node
->prev
->tok
)
707 * XXX - not documented: a `-diag' without a body does not
708 * assert a vspace prior to the next element.
710 if (MDOC_Bl
== bl
->tok
&& arg_hasattr(MDOC_Diag
, bl
))
711 if (node
->prev
&& MDOC_It
== node
->prev
->tok
) {
712 assert(node
->prev
->body
);
713 if (NULL
== node
->prev
->body
->child
)
723 termp_dq_pre(DECL_ARGS
)
726 if (MDOC_BODY
!= node
->type
)
729 term_word(p
, "\\(lq");
730 p
->flags
|= TERMP_NOSPACE
;
737 termp_dq_post(DECL_ARGS
)
740 if (MDOC_BODY
!= node
->type
)
743 p
->flags
|= TERMP_NOSPACE
;
744 term_word(p
, "\\(rq");
750 termp_it_pre(DECL_ARGS
)
752 const struct mdoc_node
*bl
, *n
;
754 int i
, type
, keys
[3], vals
[3];
755 size_t width
, offset
;
757 if (MDOC_BLOCK
== node
->type
) {
758 fmt_block_vspace(p
, node
->parent
->parent
, node
);
762 bl
= node
->parent
->parent
->parent
;
764 /* Save parent attributes. */
766 pair
->flag
= p
->flags
;
768 /* Get list width and offset. */
770 keys
[0] = MDOC_Width
;
771 keys
[1] = MDOC_Offset
;
772 keys
[2] = MDOC_Column
;
774 vals
[0] = vals
[1] = vals
[2] = -1;
778 (void)arg_getattrs(keys
, vals
, 3, bl
);
780 type
= arg_listtype(bl
);
783 /* Calculate real width and offset. */
787 if (MDOC_BODY
== node
->type
)
790 * Work around groff's column handling. The offset is
791 * equal to the sum of all widths leading to the current
792 * column (plus the -offset value). If this column
793 * exceeds the stated number of columns, the width is
794 * set as 0, else it's the stated column width (later
795 * the 0 will be adjusted to default 10 or, if in the
796 * last column case, set to stretch to the margin).
798 for (i
= 0, n
= node
->prev
; n
&& n
&&
799 i
< (int)bl
->args
[vals
[2]].argv
->sz
;
802 (&bl
->args
->argv
[vals
[2]], i
);
804 /* Whether exceeds maximum column. */
805 if (i
< (int)bl
->args
[vals
[2]].argv
->sz
)
806 width
= arg_width(&bl
->args
->argv
[vals
[2]], i
);
811 offset
+= arg_offset(&bl
->args
->argv
[vals
[1]]);
815 width
= arg_width(&bl
->args
->argv
[vals
[0]], 0);
817 offset
+= arg_offset(&bl
->args
->argv
[vals
[1]]);
822 * List-type can override the width in the case of fixed-head
823 * values (bullet, dash/hyphen, enum). Tags need a non-zero
855 * Whitespace control. Inset bodies need an initial space,
856 * while diagonal bodies need two.
859 p
->flags
|= TERMP_NOSPACE
;
863 if (MDOC_BODY
== node
->type
)
864 term_word(p
, "\\ \\ ");
867 if (MDOC_BODY
== node
->type
)
874 p
->flags
|= TERMP_NOSPACE
;
877 * Style flags. Diagnostic heads need TTYPE_DIAG.
882 if (MDOC_HEAD
== node
->type
)
883 p
->flags
|= ttypes
[TTYPE_DIAG
];
890 * Pad and break control. This is the tricker part. Lists with
891 * set right-margins for the head get TERMP_NOBREAK because, if
892 * they overrun the margin, they wrap to the new margin.
893 * Correspondingly, the body for these types don't left-pad, as
894 * the head will pad out to to the right.
905 if (MDOC_HEAD
== node
->type
)
906 p
->flags
|= TERMP_NOBREAK
;
908 p
->flags
|= TERMP_NOLPAD
;
911 if (MDOC_HEAD
== node
->type
)
912 p
->flags
|= TERMP_NOBREAK
;
914 p
->flags
|= TERMP_NOLPAD
;
916 if (MDOC_HEAD
!= node
->type
)
920 * This is ugly. If `-hang' is specified and the body
921 * is a `Bl' or `Bd', then we want basically to nullify
922 * the "overstep" effect in term_flushln() and treat
923 * this as a `-ohang' list instead.
925 if (node
->next
->child
&&
926 (MDOC_Bl
== node
->next
->child
->tok
||
927 MDOC_Bd
== node
->next
->child
->tok
)) {
928 p
->flags
&= ~TERMP_NOBREAK
;
929 p
->flags
&= ~TERMP_NOLPAD
;
931 p
->flags
|= TERMP_HANG
;
934 if (MDOC_HEAD
== node
->type
)
935 p
->flags
|= TERMP_NOBREAK
| TERMP_TWOSPACE
;
937 p
->flags
|= TERMP_NOLPAD
;
939 if (MDOC_HEAD
!= node
->type
)
941 if (NULL
== node
->next
|| NULL
== node
->next
->child
)
942 p
->flags
|= TERMP_DANGLE
;
945 if (MDOC_HEAD
== node
->type
) {
947 if (MDOC_BODY
== node
->next
->type
)
948 p
->flags
&= ~TERMP_NOBREAK
;
950 p
->flags
|= TERMP_NOBREAK
;
952 p
->flags
|= TERMP_NOLPAD
;
956 if (MDOC_HEAD
== node
->type
)
957 p
->flags
|= TERMP_NOBREAK
;
964 * Margin control. Set-head-width lists have their right
965 * margins shortened. The body for these lists has the offset
966 * necessarily lengthened. Everybody gets the offset.
974 * Same stipulation as above, regarding `-hang'. We
975 * don't want to recalculate rmargin and offsets when
976 * using `Bd' or `Bl' within `-hang' overstep lists.
978 if (MDOC_HEAD
== node
->type
&& node
->next
->child
&&
979 (MDOC_Bl
== node
->next
->child
->tok
||
980 MDOC_Bd
== node
->next
->child
->tok
))
993 if (MDOC_HEAD
== node
->type
)
994 p
->rmargin
= p
->offset
+ width
;
1000 p
->rmargin
= p
->offset
+ width
;
1002 * XXX - this behaviour is not documented: the
1003 * right-most column is filled to the right margin.
1005 if (MDOC_HEAD
== node
->type
&&
1006 MDOC_BODY
== node
->next
->type
)
1007 p
->rmargin
= p
->maxrmargin
;
1014 * The dash, hyphen, bullet and enum lists all have a special
1015 * HEAD character (temporarily bold, in some cases).
1018 if (MDOC_HEAD
== node
->type
)
1021 p
->flags
|= TERMP_BOLD
;
1022 term_word(p
, "\\[bu]");
1023 p
->flags
&= ~TERMP_BOLD
;
1028 p
->flags
|= TERMP_BOLD
;
1029 term_word(p
, "\\(hy");
1030 p
->flags
&= ~TERMP_BOLD
;
1033 (pair
->ppair
->ppair
->count
)++;
1034 (void)snprintf(buf
, sizeof(buf
), "%d.",
1035 pair
->ppair
->ppair
->count
);
1043 * If we're not going to process our children, indicate so here.
1056 if (MDOC_HEAD
== node
->type
)
1060 if (MDOC_BODY
== node
->type
)
1073 termp_it_post(DECL_ARGS
)
1077 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
1080 type
= arg_listtype(node
->parent
->parent
->parent
);
1089 if (MDOC_BODY
== node
->type
)
1093 if (MDOC_HEAD
== node
->type
)
1101 p
->flags
= pair
->flag
;
1107 termp_nm_pre(DECL_ARGS
)
1110 if (SEC_SYNOPSIS
== node
->sec
)
1113 pair
->flag
|= ttypes
[TTYPE_PROG
];
1114 p
->flags
|= ttypes
[TTYPE_PROG
];
1116 if (NULL
== node
->child
)
1117 term_word(p
, meta
->name
);
1125 termp_fl_pre(DECL_ARGS
)
1128 pair
->flag
|= ttypes
[TTYPE_CMD_FLAG
];
1129 p
->flags
|= ttypes
[TTYPE_CMD_FLAG
];
1130 term_word(p
, "\\-");
1131 p
->flags
|= TERMP_NOSPACE
;
1138 termp_an_pre(DECL_ARGS
)
1141 if (NULL
== node
->child
)
1145 * XXX: this is poorly documented. If not in the AUTHORS
1146 * section, `An -split' will cause newlines to occur before the
1147 * author name. If in the AUTHORS section, by default, the
1148 * first `An' invocation is nosplit, then all subsequent ones,
1149 * regardless of whether interspersed with other macros/text,
1150 * are split. -split, in this case, will override the condition
1151 * of the implied first -nosplit.
1154 if (node
->sec
== SEC_AUTHORS
) {
1155 if ( ! (TERMP_ANPREC
& p
->flags
)) {
1156 if (TERMP_SPLIT
& p
->flags
)
1160 if (TERMP_NOSPLIT
& p
->flags
)
1166 if (TERMP_SPLIT
& p
->flags
)
1175 termp_an_post(DECL_ARGS
)
1179 if (SEC_AUTHORS
== node
->sec
)
1180 p
->flags
|= TERMP_ANPREC
;
1184 if (arg_getattr(MDOC_Split
, node
) > -1) {
1185 p
->flags
&= ~TERMP_NOSPLIT
;
1186 p
->flags
|= TERMP_SPLIT
;
1188 p
->flags
&= ~TERMP_SPLIT
;
1189 p
->flags
|= TERMP_NOSPLIT
;
1197 termp_ar_pre(DECL_ARGS
)
1200 pair
->flag
|= ttypes
[TTYPE_CMD_ARG
];
1207 termp_ns_pre(DECL_ARGS
)
1210 p
->flags
|= TERMP_NOSPACE
;
1217 termp_pp_pre(DECL_ARGS
)
1227 termp_rs_pre(DECL_ARGS
)
1230 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
1238 termp_rv_pre(DECL_ARGS
)
1240 const struct mdoc_node
*nn
;
1243 term_word(p
, "The");
1247 for ( ; nn
; nn
= nn
->next
) {
1248 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1249 term_word(p
, nn
->string
);
1250 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1251 p
->flags
|= TERMP_NOSPACE
;
1252 if (nn
->next
&& NULL
== nn
->next
->next
)
1253 term_word(p
, "(), and");
1255 term_word(p
, "(),");
1260 if (node
->child
->next
)
1261 term_word(p
, "functions return");
1263 term_word(p
, "function returns");
1265 term_word(p
, "the value 0 if successful; otherwise the value "
1266 "-1 is returned and the global variable");
1268 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
1269 term_word(p
, "errno");
1270 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
1272 term_word(p
, "is set to indicate the error.");
1280 termp_ex_pre(DECL_ARGS
)
1282 const struct mdoc_node
*nn
;
1284 term_word(p
, "The");
1288 for ( ; nn
; nn
= nn
->next
) {
1289 p
->flags
|= ttypes
[TTYPE_PROG
];
1290 term_word(p
, nn
->string
);
1291 p
->flags
&= ~ttypes
[TTYPE_PROG
];
1292 p
->flags
|= TERMP_NOSPACE
;
1293 if (nn
->next
&& NULL
== nn
->next
->next
)
1294 term_word(p
, ", and");
1298 p
->flags
&= ~TERMP_NOSPACE
;
1301 if (node
->child
->next
)
1302 term_word(p
, "utilities exit");
1304 term_word(p
, "utility exits");
1306 term_word(p
, "0 on success, and >0 if an error occurs.");
1314 termp_nd_pre(DECL_ARGS
)
1317 if (MDOC_BODY
!= node
->type
)
1320 #if defined(__OpenBSD__) || defined(__linux__)
1321 term_word(p
, "\\(en");
1323 term_word(p
, "\\(em");
1331 termp_bl_post(DECL_ARGS
)
1334 if (MDOC_BLOCK
== node
->type
)
1341 termp_op_post(DECL_ARGS
)
1344 if (MDOC_BODY
!= node
->type
)
1346 p
->flags
|= TERMP_NOSPACE
;
1347 term_word(p
, "\\(rB");
1353 termp_xr_pre(DECL_ARGS
)
1355 const struct mdoc_node
*n
;
1357 assert(node
->child
&& MDOC_TEXT
== node
->child
->type
);
1360 term_word(p
, n
->string
);
1361 if (NULL
== (n
= n
->next
))
1363 p
->flags
|= TERMP_NOSPACE
;
1365 p
->flags
|= TERMP_NOSPACE
;
1366 term_word(p
, n
->string
);
1367 p
->flags
|= TERMP_NOSPACE
;
1375 termp_vt_pre(DECL_ARGS
)
1378 /* FIXME: this can be "type name". */
1379 pair
->flag
|= ttypes
[TTYPE_VAR_DECL
];
1386 termp_vt_post(DECL_ARGS
)
1389 if (node
->sec
!= SEC_SYNOPSIS
)
1391 if (node
->next
&& MDOC_Vt
== node
->next
->tok
)
1393 else if (node
->next
)
1400 termp_fd_pre(DECL_ARGS
)
1403 pair
->flag
|= ttypes
[TTYPE_FUNC_DECL
];
1410 termp_fd_post(DECL_ARGS
)
1413 if (node
->sec
!= SEC_SYNOPSIS
)
1417 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
1424 termp_sh_pre(DECL_ARGS
)
1427 * XXX: undocumented: using two `Sh' macros in sequence has no
1428 * vspace between calls, only a newline.
1430 switch (node
->type
) {
1432 if (node
->prev
&& MDOC_Sh
== node
->prev
->tok
)
1433 if (NULL
== node
->prev
->body
->child
)
1438 pair
->flag
|= ttypes
[TTYPE_SECTION
];
1452 termp_sh_post(DECL_ARGS
)
1455 switch (node
->type
) {
1471 termp_op_pre(DECL_ARGS
)
1474 switch (node
->type
) {
1476 term_word(p
, "\\(lB");
1477 p
->flags
|= TERMP_NOSPACE
;
1488 termp_bt_pre(DECL_ARGS
)
1491 term_word(p
, "is currently in beta test.");
1498 termp_lb_post(DECL_ARGS
)
1507 termp_ud_pre(DECL_ARGS
)
1510 term_word(p
, "currently under development.");
1517 termp_d1_pre(DECL_ARGS
)
1520 if (MDOC_BLOCK
!= node
->type
)
1523 p
->offset
+= (INDENT
+ 1);
1530 termp_d1_post(DECL_ARGS
)
1533 if (MDOC_BLOCK
!= node
->type
)
1541 termp_aq_pre(DECL_ARGS
)
1544 if (MDOC_BODY
!= node
->type
)
1546 term_word(p
, "\\(la");
1547 p
->flags
|= TERMP_NOSPACE
;
1554 termp_aq_post(DECL_ARGS
)
1557 if (MDOC_BODY
!= node
->type
)
1559 p
->flags
|= TERMP_NOSPACE
;
1560 term_word(p
, "\\(ra");
1566 termp_ft_pre(DECL_ARGS
)
1569 if (SEC_SYNOPSIS
== node
->sec
)
1570 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1572 pair
->flag
|= ttypes
[TTYPE_FUNC_TYPE
];
1579 termp_ft_post(DECL_ARGS
)
1582 if (SEC_SYNOPSIS
== node
->sec
)
1589 termp_fn_pre(DECL_ARGS
)
1591 const struct mdoc_node
*n
;
1593 assert(node
->child
&& MDOC_TEXT
== node
->child
->type
);
1595 /* FIXME: can be "type funcname" "type varname"... */
1597 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1598 term_word(p
, node
->child
->string
);
1599 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1601 p
->flags
|= TERMP_NOSPACE
;
1604 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1605 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1606 term_word(p
, n
->string
);
1607 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1614 if (SEC_SYNOPSIS
== node
->sec
)
1623 termp_fn_post(DECL_ARGS
)
1626 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1633 termp_sx_pre(DECL_ARGS
)
1636 pair
->flag
|= ttypes
[TTYPE_LINK
];
1643 termp_fa_pre(DECL_ARGS
)
1645 struct mdoc_node
*n
;
1647 if (node
->parent
->tok
!= MDOC_Fo
) {
1648 pair
->flag
|= ttypes
[TTYPE_FUNC_ARG
];
1652 for (n
= node
->child
; n
; n
= n
->next
) {
1653 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1654 term_word(p
, n
->string
);
1655 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1660 if (node
->child
&& node
->next
&& node
->next
->tok
== MDOC_Fa
)
1669 termp_va_pre(DECL_ARGS
)
1672 pair
->flag
|= ttypes
[TTYPE_VAR_DECL
];
1679 termp_bd_pre(DECL_ARGS
)
1684 * This is fairly tricky due primarily to crappy documentation.
1685 * If -ragged or -filled are specified, the block does nothing
1686 * but change the indentation.
1688 * If, on the other hand, -unfilled or -literal are specified,
1689 * then the game changes. Text is printed exactly as entered in
1690 * the display: if a macro line, a newline is appended to the
1691 * line. Blank lines are allowed.
1694 if (MDOC_BLOCK
== node
->type
) {
1695 fmt_block_vspace(p
, node
, node
);
1697 } else if (MDOC_BODY
!= node
->type
)
1700 assert(node
->parent
->args
);
1702 for (type
= -1, i
= 0; -1 == type
&&
1703 i
< (int)node
->parent
->args
->argc
; i
++) {
1704 switch (node
->parent
->args
->argv
[i
].arg
) {
1709 case (MDOC_Unfilled
):
1711 case (MDOC_Literal
):
1712 type
= node
->parent
->args
->argv
[i
].arg
;
1721 i
= arg_getattr(MDOC_Offset
, node
->parent
);
1723 p
->offset
+= arg_offset(&node
->parent
->args
->argv
[i
]);
1726 case (MDOC_Literal
):
1728 case (MDOC_Unfilled
):
1734 for (node
= node
->child
; node
; node
= node
->next
) {
1735 p
->flags
|= TERMP_NOSPACE
;
1736 print_node(p
, pair
, meta
, node
);
1747 termp_bd_post(DECL_ARGS
)
1750 if (MDOC_BODY
!= node
->type
)
1752 p
->flags
|= TERMP_NOSPACE
;
1759 termp_qq_pre(DECL_ARGS
)
1762 if (MDOC_BODY
!= node
->type
)
1765 p
->flags
|= TERMP_NOSPACE
;
1772 termp_qq_post(DECL_ARGS
)
1775 if (MDOC_BODY
!= node
->type
)
1777 p
->flags
|= TERMP_NOSPACE
;
1784 termp_bx_post(DECL_ARGS
)
1788 p
->flags
|= TERMP_NOSPACE
;
1789 term_word(p
, "BSD");
1795 termp_xx_pre(DECL_ARGS
)
1800 switch (node
->tok
) {
1805 pp
= "DragonFlyBSD";
1831 termp_sq_pre(DECL_ARGS
)
1834 if (MDOC_BODY
!= node
->type
)
1836 term_word(p
, "\\(oq");
1837 p
->flags
|= TERMP_NOSPACE
;
1844 termp_sq_post(DECL_ARGS
)
1847 if (MDOC_BODY
!= node
->type
)
1849 p
->flags
|= TERMP_NOSPACE
;
1850 term_word(p
, "\\(aq");
1856 termp_pa_pre(DECL_ARGS
)
1859 pair
->flag
|= ttypes
[TTYPE_FILE
];
1866 termp_pf_pre(DECL_ARGS
)
1869 p
->flags
|= TERMP_IGNDELIM
;
1876 termp_pf_post(DECL_ARGS
)
1879 p
->flags
&= ~TERMP_IGNDELIM
;
1880 p
->flags
|= TERMP_NOSPACE
;
1886 termp_ss_pre(DECL_ARGS
)
1889 switch (node
->type
) {
1896 pair
->flag
|= ttypes
[TTYPE_SSECTION
];
1897 p
->offset
= HALFINDENT
;
1909 termp_ss_post(DECL_ARGS
)
1912 if (MDOC_HEAD
== node
->type
)
1919 termp_em_pre(DECL_ARGS
)
1922 pair
->flag
|= ttypes
[TTYPE_EMPH
];
1929 termp_cd_pre(DECL_ARGS
)
1932 pair
->flag
|= ttypes
[TTYPE_CONFIG
];
1940 termp_cm_pre(DECL_ARGS
)
1943 pair
->flag
|= ttypes
[TTYPE_CMD_FLAG
];
1950 termp_ic_pre(DECL_ARGS
)
1953 pair
->flag
|= ttypes
[TTYPE_CMD
];
1960 termp_in_pre(DECL_ARGS
)
1963 pair
->flag
|= ttypes
[TTYPE_INCLUDE
];
1964 p
->flags
|= ttypes
[TTYPE_INCLUDE
];
1966 if (SEC_SYNOPSIS
== node
->sec
)
1967 term_word(p
, "#include");
1970 p
->flags
|= TERMP_NOSPACE
;
1977 termp_in_post(DECL_ARGS
)
1980 p
->flags
|= TERMP_NOSPACE
| ttypes
[TTYPE_INCLUDE
];
1982 p
->flags
&= ~ttypes
[TTYPE_INCLUDE
];
1984 if (SEC_SYNOPSIS
!= node
->sec
)
1989 * XXX Not entirely correct. If `.In foo bar' is specified in
1990 * the SYNOPSIS section, then it produces a single break after
1991 * the <foo>; mandoc asserts a vertical space. Since this
1992 * construction is rarely used, I think it's fine.
1994 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
2001 termp_sp_pre(DECL_ARGS
)
2005 if (NULL
== node
->child
) {
2010 len
= atoi(node
->child
->string
);
2013 for (i
= 0; i
< len
; i
++)
2022 termp_br_pre(DECL_ARGS
)
2032 termp_brq_pre(DECL_ARGS
)
2035 if (MDOC_BODY
!= node
->type
)
2037 term_word(p
, "\\(lC");
2038 p
->flags
|= TERMP_NOSPACE
;
2045 termp_brq_post(DECL_ARGS
)
2048 if (MDOC_BODY
!= node
->type
)
2050 p
->flags
|= TERMP_NOSPACE
;
2051 term_word(p
, "\\(rC");
2057 termp_bq_pre(DECL_ARGS
)
2060 if (MDOC_BODY
!= node
->type
)
2062 term_word(p
, "\\(lB");
2063 p
->flags
|= TERMP_NOSPACE
;
2070 termp_bq_post(DECL_ARGS
)
2073 if (MDOC_BODY
!= node
->type
)
2075 p
->flags
|= TERMP_NOSPACE
;
2076 term_word(p
, "\\(rB");
2082 termp_pq_pre(DECL_ARGS
)
2085 if (MDOC_BODY
!= node
->type
)
2087 term_word(p
, "\\&(");
2088 p
->flags
|= TERMP_NOSPACE
;
2095 termp_pq_post(DECL_ARGS
)
2098 if (MDOC_BODY
!= node
->type
)
2106 termp_fo_pre(DECL_ARGS
)
2108 const struct mdoc_node
*n
;
2110 if (MDOC_BODY
== node
->type
) {
2111 p
->flags
|= TERMP_NOSPACE
;
2113 p
->flags
|= TERMP_NOSPACE
;
2115 } else if (MDOC_HEAD
!= node
->type
)
2118 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
2119 for (n
= node
->child
; n
; n
= n
->next
) {
2120 assert(MDOC_TEXT
== n
->type
);
2121 term_word(p
, n
->string
);
2123 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
2131 termp_fo_post(DECL_ARGS
)
2134 if (MDOC_BODY
!= node
->type
)
2136 p
->flags
|= TERMP_NOSPACE
;
2138 p
->flags
|= TERMP_NOSPACE
;
2146 termp_bf_pre(DECL_ARGS
)
2148 const struct mdoc_node
*n
;
2150 if (MDOC_HEAD
== node
->type
)
2152 else if (MDOC_BLOCK
!= node
->type
)
2155 if (NULL
== (n
= node
->head
->child
)) {
2156 if (arg_hasattr(MDOC_Emphasis
, node
))
2157 pair
->flag
|= ttypes
[TTYPE_EMPH
];
2158 else if (arg_hasattr(MDOC_Symbolic
, node
))
2159 pair
->flag
|= ttypes
[TTYPE_SYMB
];
2164 assert(MDOC_TEXT
== n
->type
);
2165 if (0 == strcmp("Em", n
->string
))
2166 pair
->flag
|= ttypes
[TTYPE_EMPH
];
2167 else if (0 == strcmp("Sy", n
->string
))
2168 pair
->flag
|= ttypes
[TTYPE_SYMB
];
2176 termp_sy_pre(DECL_ARGS
)
2179 pair
->flag
|= ttypes
[TTYPE_SYMB
];
2186 termp_ms_pre(DECL_ARGS
)
2189 pair
->flag
|= ttypes
[TTYPE_SYMBOL
];
2197 termp_sm_pre(DECL_ARGS
)
2200 assert(node
->child
&& MDOC_TEXT
== node
->child
->type
);
2201 if (0 == strcmp("on", node
->child
->string
)) {
2202 p
->flags
&= ~TERMP_NONOSPACE
;
2203 p
->flags
&= ~TERMP_NOSPACE
;
2205 p
->flags
|= TERMP_NONOSPACE
;
2213 termp_ap_pre(DECL_ARGS
)
2216 p
->flags
|= TERMP_NOSPACE
;
2217 term_word(p
, "\\(aq");
2218 p
->flags
|= TERMP_NOSPACE
;
2225 termp__j_pre(DECL_ARGS
)
2228 pair
->flag
|= ttypes
[TTYPE_REF_JOURNAL
];
2235 termp__t_pre(DECL_ARGS
)
2238 pair
->flag
|= ttypes
[TTYPE_REF_TITLE
];
2245 termp____post(DECL_ARGS
)
2248 p
->flags
|= TERMP_NOSPACE
;
2249 term_word(p
, node
->next
? "," : ".");
2255 termp_lk_pre(DECL_ARGS
)
2257 const struct mdoc_node
*n
;
2259 assert(node
->child
);
2262 if (NULL
== n
->next
) {
2263 pair
->flag
|= ttypes
[TTYPE_LINK_ANCHOR
];
2267 p
->flags
|= ttypes
[TTYPE_LINK_ANCHOR
];
2268 term_word(p
, n
->string
);
2269 p
->flags
|= TERMP_NOSPACE
;
2271 p
->flags
&= ~ttypes
[TTYPE_LINK_ANCHOR
];
2273 p
->flags
|= ttypes
[TTYPE_LINK_TEXT
];
2274 for (n
= n
->next
; n
; n
= n
->next
)
2275 term_word(p
, n
->string
);
2277 p
->flags
&= ~ttypes
[TTYPE_LINK_TEXT
];
2284 termp_mt_pre(DECL_ARGS
)
2287 pair
->flag
|= ttypes
[TTYPE_LINK_ANCHOR
];