]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.23 2009/02/25 23:18:50 kristaps Exp $ */
3 * Copyright (c) 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
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
30 * Performs actions on nodes of the abstract syntax tree. Both pre- and
31 * post-fix operations are defined here.
34 /* FIXME: indent/tab. */
35 /* FIXME: macro arguments can be escaped. */
38 #define TTYPE_CMD_FLAG 1
39 #define TTYPE_CMD_ARG 2
40 #define TTYPE_SECTION 3
41 #define TTYPE_FUNC_DECL 4
42 #define TTYPE_VAR_DECL 5
43 #define TTYPE_FUNC_TYPE 6
44 #define TTYPE_FUNC_NAME 7
45 #define TTYPE_FUNC_ARG 8
47 #define TTYPE_SSECTION 10
50 #define TTYPE_CONFIG 13
52 #define TTYPE_INCLUDE 15
54 #define TTYPE_SYMBOL 17
58 * These define "styles" for element types, like command arguments or
59 * executable names. This is useful when multiple macros must decorate
60 * the same thing (like .Ex -std cmd and .Nm cmd).
63 const int ttypes
[TTYPE_NMAX
] = {
64 TERMP_BOLD
, /* TTYPE_PROG */
65 TERMP_BOLD
, /* TTYPE_CMD_FLAG */
66 TERMP_UNDERLINE
, /* TTYPE_CMD_ARG */
67 TERMP_BOLD
, /* TTYPE_SECTION */
68 TERMP_BOLD
, /* TTYPE_FUNC_DECL */
69 TERMP_UNDERLINE
, /* TTYPE_VAR_DECL */
70 TERMP_UNDERLINE
, /* TTYPE_FUNC_TYPE */
71 TERMP_BOLD
, /* TTYPE_FUNC_NAME */
72 TERMP_UNDERLINE
, /* TTYPE_FUNC_ARG */
73 TERMP_UNDERLINE
, /* TTYPE_LINK */
74 TERMP_BOLD
, /* TTYPE_SSECTION */
75 TERMP_UNDERLINE
, /* TTYPE_FILE */
76 TERMP_UNDERLINE
, /* TTYPE_EMPH */
77 TERMP_BOLD
, /* TTYPE_CONFIG */
78 TERMP_BOLD
, /* TTYPE_CMD */
79 TERMP_BOLD
, /* TTYPE_INCLUDE */
80 TERMP_BOLD
, /* TTYPE_SYMB */
81 TERMP_BOLD
/* TTYPE_SYMBOL */
84 static int arg_hasattr(int, size_t,
85 const struct mdoc_arg
*);
86 static int arg_getattr(int, size_t,
87 const struct mdoc_arg
*);
88 static size_t arg_offset(const struct mdoc_arg
*);
89 static size_t arg_width(const struct mdoc_arg
*);
92 * What follows describes prefix and postfix operations for the abstract
93 * syntax tree descent.
98 struct termpair *pair, \
99 const struct mdoc_meta *meta, \
100 const struct mdoc_node *node
102 #define DECL_PRE(name) \
103 static int name##_pre(DECL_ARGS)
104 #define DECL_POST(name) \
105 static void name##_post(DECL_ARGS)
106 #define DECL_PREPOST(name) \
110 DECL_PREPOST(termp_aq
);
111 DECL_PREPOST(termp_bd
);
112 DECL_PREPOST(termp_bq
);
113 DECL_PREPOST(termp_d1
);
114 DECL_PREPOST(termp_dq
);
115 DECL_PREPOST(termp_fd
);
116 DECL_PREPOST(termp_fn
);
117 DECL_PREPOST(termp_fo
);
118 DECL_PREPOST(termp_ft
);
119 DECL_PREPOST(termp_it
);
120 DECL_PREPOST(termp_op
);
121 DECL_PREPOST(termp_pf
);
122 DECL_PREPOST(termp_pq
);
123 DECL_PREPOST(termp_qq
);
124 DECL_PREPOST(termp_sh
);
125 DECL_PREPOST(termp_ss
);
126 DECL_PREPOST(termp_sq
);
127 DECL_PREPOST(termp_vt
);
164 const struct termact __termacts
[MDOC_MAX
] = {
165 { NULL
, NULL
}, /* \" */
166 { NULL
, NULL
}, /* Dd */
167 { NULL
, NULL
}, /* Dt */
168 { NULL
, NULL
}, /* Os */
169 { termp_sh_pre
, termp_sh_post
}, /* Sh */
170 { termp_ss_pre
, termp_ss_post
}, /* Ss */
171 { termp_pp_pre
, NULL
}, /* Pp */
172 { termp_d1_pre
, termp_d1_post
}, /* D1 */
173 { NULL
, NULL
}, /* Dl */
174 { termp_bd_pre
, termp_bd_post
}, /* Bd */
175 { NULL
, NULL
}, /* Ed */
176 { NULL
, termp_bl_post
}, /* Bl */
177 { NULL
, NULL
}, /* El */
178 { termp_it_pre
, termp_it_post
}, /* It */
179 { NULL
, NULL
}, /* Ad */
180 { NULL
, NULL
}, /* An */
181 { termp_ar_pre
, NULL
}, /* Ar */
182 { termp_cd_pre
, NULL
}, /* Cd */
183 { termp_cm_pre
, NULL
}, /* Cm */
184 { NULL
, NULL
}, /* Dv */
185 { NULL
, NULL
}, /* Er */
186 { NULL
, NULL
}, /* Ev */
187 { termp_ex_pre
, NULL
}, /* Ex */
188 { termp_fa_pre
, NULL
}, /* Fa */
189 { termp_fd_pre
, termp_fd_post
}, /* Fd */
190 { termp_fl_pre
, NULL
}, /* Fl */
191 { termp_fn_pre
, termp_fn_post
}, /* Fn */
192 { termp_ft_pre
, termp_ft_post
}, /* Ft */
193 { termp_ic_pre
, NULL
}, /* Ic */
194 { termp_in_pre
, NULL
}, /* In */
195 { NULL
, NULL
}, /* Li */
196 { termp_nd_pre
, NULL
}, /* Nd */
197 { termp_nm_pre
, NULL
}, /* Nm */
198 { termp_op_pre
, termp_op_post
}, /* Op */
199 { NULL
, NULL
}, /* Ot */
200 { termp_pa_pre
, NULL
}, /* Pa */
201 { termp_rv_pre
, NULL
}, /* Rv */
202 { termp_st_pre
, NULL
}, /* St */
203 { termp_va_pre
, NULL
}, /* Va */
204 { termp_vt_pre
, termp_vt_post
}, /* Vt */
205 { termp_xr_pre
, NULL
}, /* Xr */
206 { NULL
, NULL
}, /* %A */
207 { NULL
, NULL
}, /* %B */
208 { NULL
, NULL
}, /* %D */
209 { NULL
, NULL
}, /* %I */
210 { NULL
, NULL
}, /* %J */
211 { NULL
, NULL
}, /* %N */
212 { NULL
, NULL
}, /* %O */
213 { NULL
, NULL
}, /* %P */
214 { NULL
, NULL
}, /* %R */
215 { NULL
, NULL
}, /* %T */
216 { NULL
, NULL
}, /* %V */
217 { NULL
, NULL
}, /* Ac */
218 { termp_aq_pre
, termp_aq_post
}, /* Ao */
219 { termp_aq_pre
, termp_aq_post
}, /* Aq */
220 { termp_at_pre
, NULL
}, /* At */
221 { NULL
, NULL
}, /* Bc */
222 { termp_bf_pre
, NULL
}, /* Bf */
223 { termp_bq_pre
, termp_bq_post
}, /* Bo */
224 { termp_bq_pre
, termp_bq_post
}, /* Bq */
225 { termp_bsx_pre
, NULL
}, /* Bsx */
226 { termp_bx_pre
, NULL
}, /* Bx */
227 { NULL
, NULL
}, /* Db */
228 { NULL
, NULL
}, /* Dc */
229 { termp_dq_pre
, termp_dq_post
}, /* Do */
230 { termp_dq_pre
, termp_dq_post
}, /* Dq */
231 { NULL
, NULL
}, /* Ec */
232 { NULL
, NULL
}, /* Ef */
233 { termp_em_pre
, NULL
}, /* Em */
234 { NULL
, NULL
}, /* Eo */
235 { termp_fx_pre
, NULL
}, /* Fx */
236 { termp_ms_pre
, NULL
}, /* Ms */
237 { NULL
, NULL
}, /* No */
238 { termp_ns_pre
, NULL
}, /* Ns */
239 { termp_nx_pre
, NULL
}, /* Nx */
240 { termp_ox_pre
, NULL
}, /* Ox */
241 { NULL
, NULL
}, /* Pc */
242 { termp_pf_pre
, termp_pf_post
}, /* Pf */
243 { termp_pq_pre
, termp_pq_post
}, /* Po */
244 { termp_pq_pre
, termp_pq_post
}, /* Pq */
245 { NULL
, NULL
}, /* Qc */
246 { termp_sq_pre
, termp_sq_post
}, /* Ql */
247 { termp_qq_pre
, termp_qq_post
}, /* Qo */
248 { termp_qq_pre
, termp_qq_post
}, /* Qq */
249 { NULL
, NULL
}, /* Re */
250 { NULL
, NULL
}, /* Rs */
251 { NULL
, NULL
}, /* Sc */
252 { termp_sq_pre
, termp_sq_post
}, /* So */
253 { termp_sq_pre
, termp_sq_post
}, /* Sq */
254 { termp_sm_pre
, NULL
}, /* Sm */
255 { termp_sx_pre
, NULL
}, /* Sx */
256 { termp_sy_pre
, NULL
}, /* Sy */
257 { NULL
, NULL
}, /* Tn */
258 { termp_ux_pre
, NULL
}, /* Ux */
259 { NULL
, NULL
}, /* Xc */
260 { NULL
, NULL
}, /* Xo */
261 { termp_fo_pre
, termp_fo_post
}, /* Fo */
262 { NULL
, NULL
}, /* Fc */
263 { termp_op_pre
, termp_op_post
}, /* Oo */
264 { NULL
, NULL
}, /* Oc */
265 { NULL
, NULL
}, /* Bk */
266 { NULL
, NULL
}, /* Ek */
267 { termp_bt_pre
, NULL
}, /* Bt */
268 { NULL
, NULL
}, /* Hf */
269 { NULL
, NULL
}, /* Fr */
270 { termp_ud_pre
, NULL
}, /* Ud */
273 const struct termact
*termacts
= __termacts
;
277 arg_width(const struct mdoc_arg
*arg
)
282 return(strlen(*arg
->value
));
287 arg_offset(const struct mdoc_arg
*arg
)
292 if (0 == strcmp(*arg
->value
, "indent"))
294 if (0 == strcmp(*arg
->value
, "indent-two"))
297 return(strlen(*arg
->value
));
302 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
305 return(-1 != arg_getattr(arg
, argc
, argv
));
310 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
314 for (i
= 0; i
< (int)argc
; i
++)
315 if (argv
[i
].arg
== arg
)
323 termp_dq_pre(DECL_ARGS
)
326 if (MDOC_BODY
!= node
->type
)
330 p
->flags
|= TERMP_NOSPACE
;
337 termp_dq_post(DECL_ARGS
)
340 if (MDOC_BODY
!= node
->type
)
343 p
->flags
|= TERMP_NOSPACE
;
350 termp_it_pre(DECL_ARGS
)
352 const struct mdoc_node
*n
, *it
;
353 const struct mdoc_block
*bl
;
356 size_t width
, offset
;
358 switch (node
->type
) {
371 n
= it
->parent
->parent
;
374 if (MDOC_BLOCK
== node
->type
) {
375 if (arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
382 /* Get our list type. */
384 for (i
= 0; i
< (int)bl
->argc
; i
++)
385 switch (bl
->argv
[i
].arg
) {
399 type
= bl
->argv
[i
].arg
;
409 errx(1, "list type not supported");
415 /* Save our existing (inherited) margin and offset. */
417 pair
->offset
= p
->offset
;
418 pair
->rmargin
= p
->rmargin
;
420 /* Get list width and offset. */
422 /* FIXME: auto-size. */
423 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
424 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
426 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
427 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
429 /* Override the width. */
439 width
= width
> 6 ? width
: 6;
443 errx(1, "need non-zero -width");
449 /* Word-wrap control. */
451 p
->flags
|= TERMP_NOSPACE
;
463 if (MDOC_HEAD
== node
->type
)
464 p
->flags
|= TERMP_NOBREAK
;
465 else if (MDOC_BODY
== node
->type
)
466 p
->flags
|= TERMP_NOLPAD
;
473 * Get a token to use as the HEAD lead-in. If NULL, we use the
478 if (MDOC_HEAD
== node
->type
) {
479 if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
))
481 if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
))
483 if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
484 (pair
->ppair
->ppair
->count
)++;
485 (void)snprintf(buf
, sizeof(buf
), "%d.",
486 pair
->ppair
->ppair
->count
);
489 if (arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
))
491 if (arg_hasattr(MDOC_Item
, bl
->argc
, bl
->argv
))
495 /* Margin control. */
511 if (MDOC_HEAD
== node
->type
)
512 p
->rmargin
= p
->offset
+ width
;
513 else if (MDOC_BODY
== node
->type
)
523 /* XXX - ignoring children. */
532 termp_it_post(DECL_ARGS
)
535 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
540 p
->offset
= pair
->offset
;
541 p
->rmargin
= pair
->rmargin
;
543 if (MDOC_HEAD
== node
->type
) {
544 p
->flags
&= ~TERMP_NOBREAK
;
545 p
->flags
&= ~TERMP_NORPAD
;
546 } else if (MDOC_BODY
== node
->type
)
547 p
->flags
&= ~TERMP_NOLPAD
;
553 termp_nm_pre(DECL_ARGS
)
556 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_PROG
]);
557 if (NULL
== node
->child
)
565 termp_fl_pre(DECL_ARGS
)
568 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
570 p
->flags
|= TERMP_NOSPACE
;
577 termp_ar_pre(DECL_ARGS
)
580 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_ARG
]);
581 if (NULL
== node
->child
)
589 termp_ns_pre(DECL_ARGS
)
592 p
->flags
|= TERMP_NOSPACE
;
599 termp_pp_pre(DECL_ARGS
)
609 termp_st_pre(DECL_ARGS
)
613 assert(1 == node
->data
.elem
.argc
);
615 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
624 termp_rv_pre(DECL_ARGS
)
628 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
629 node
->data
.elem
.argv
);
635 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
636 word(p
, *node
->data
.elem
.argv
[i
].value
);
637 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
639 word(p
, "() function returns the value 0 if successful;");
640 word(p
, "otherwise the value -1 is returned and the");
641 word(p
, "global variable");
643 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
645 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
647 word(p
, "is set to indicate the error.");
655 termp_ex_pre(DECL_ARGS
)
659 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
660 node
->data
.elem
.argv
);
664 p
->flags
|= ttypes
[TTYPE_PROG
];
665 word(p
, *node
->data
.elem
.argv
[i
].value
);
666 p
->flags
&= ~ttypes
[TTYPE_PROG
];
667 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
675 termp_nd_pre(DECL_ARGS
)
685 termp_bl_post(DECL_ARGS
)
688 if (MDOC_BLOCK
== node
->type
)
695 termp_op_post(DECL_ARGS
)
698 if (MDOC_BODY
!= node
->type
)
700 p
->flags
|= TERMP_NOSPACE
;
707 termp_xr_pre(DECL_ARGS
)
709 const struct mdoc_node
*n
;
714 assert(MDOC_TEXT
== n
->type
);
715 word(p
, n
->data
.text
.string
);
717 if (NULL
== (n
= n
->next
))
720 assert(MDOC_TEXT
== n
->type
);
721 p
->flags
|= TERMP_NOSPACE
;
723 p
->flags
|= TERMP_NOSPACE
;
724 word(p
, n
->data
.text
.string
);
725 p
->flags
|= TERMP_NOSPACE
;
734 termp_vt_pre(DECL_ARGS
)
737 /* FIXME: this can be "type name". */
738 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
745 termp_vt_post(DECL_ARGS
)
748 if (node
->sec
== SEC_SYNOPSIS
)
755 termp_fd_pre(DECL_ARGS
)
759 * FIXME: this naming is bad. This value is used, in general,
760 * for the #include header or other preprocessor statement.
762 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_DECL
]);
769 termp_fd_post(DECL_ARGS
)
772 if (node
->sec
== SEC_SYNOPSIS
)
779 termp_sh_pre(DECL_ARGS
)
782 switch (node
->type
) {
785 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SECTION
]);
799 termp_sh_post(DECL_ARGS
)
802 switch (node
->type
) {
818 termp_op_pre(DECL_ARGS
)
821 switch (node
->type
) {
824 p
->flags
|= TERMP_NOSPACE
;
835 termp_bt_pre(DECL_ARGS
)
838 word(p
, "is currently in beta test.");
845 termp_ud_pre(DECL_ARGS
)
848 word(p
, "currently under development.");
855 termp_d1_pre(DECL_ARGS
)
858 if (MDOC_BODY
!= node
->type
)
861 p
->offset
+= (pair
->offset
= INDENT
);
868 termp_d1_post(DECL_ARGS
)
871 if (MDOC_BODY
!= node
->type
)
874 p
->offset
-= pair
->offset
;
880 termp_aq_pre(DECL_ARGS
)
883 if (MDOC_BODY
!= node
->type
)
886 p
->flags
|= TERMP_NOSPACE
;
893 termp_aq_post(DECL_ARGS
)
896 if (MDOC_BODY
!= node
->type
)
898 p
->flags
|= TERMP_NOSPACE
;
905 termp_ft_pre(DECL_ARGS
)
908 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_TYPE
]);
915 termp_ft_post(DECL_ARGS
)
918 if (node
->sec
== SEC_SYNOPSIS
)
925 termp_fn_pre(DECL_ARGS
)
927 const struct mdoc_node
*n
;
930 assert(MDOC_TEXT
== node
->child
->type
);
932 /* FIXME: can be "type funcname" "type varname"... */
934 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
935 word(p
, node
->child
->data
.text
.string
);
936 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
940 p
->flags
|= TERMP_NOSPACE
;
941 for (n
= node
->child
->next
; n
; n
= n
->next
) {
942 assert(MDOC_TEXT
== n
->type
);
943 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
944 word(p
, n
->data
.text
.string
);
945 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
952 if (SEC_SYNOPSIS
== node
->sec
)
961 termp_fn_post(DECL_ARGS
)
964 if (node
->sec
== SEC_SYNOPSIS
)
972 termp_sx_pre(DECL_ARGS
)
975 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_LINK
]);
982 termp_fa_pre(DECL_ARGS
)
986 if (node
->parent
->tok
!= MDOC_Fo
) {
987 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_ARG
]);
991 for (n
= node
->child
; n
; n
= n
->next
) {
992 assert(MDOC_TEXT
== n
->type
);
994 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
995 word(p
, n
->data
.text
.string
);
996 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1002 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1011 termp_va_pre(DECL_ARGS
)
1014 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
1021 termp_bd_pre(DECL_ARGS
)
1023 const struct mdoc_block
*bl
;
1024 const struct mdoc_node
*n
;
1027 if (MDOC_BLOCK
== node
->type
) {
1030 } else if (MDOC_BODY
!= node
->type
)
1033 assert(MDOC_BLOCK
== node
->parent
->type
);
1034 pair
->offset
= p
->offset
;
1036 bl
= &node
->parent
->data
.block
;
1039 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1041 assert(1 == bl
->argv
[i
].sz
);
1042 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1045 if ( ! arg_hasattr(MDOC_Literal
, bl
->argc
, bl
->argv
))
1048 p
->flags
|= TERMP_LITERAL
;
1050 for (n
= node
->child
; n
; n
= n
->next
) {
1051 assert(MDOC_TEXT
== n
->type
); /* FIXME */
1052 if ((*n
->data
.text
.string
)) {
1053 word(p
, n
->data
.text
.string
);
1060 p
->flags
&= ~TERMP_LITERAL
;
1067 termp_bd_post(DECL_ARGS
)
1070 if (MDOC_BODY
!= node
->type
)
1073 p
->offset
= pair
->offset
;
1079 termp_qq_pre(DECL_ARGS
)
1082 if (MDOC_BODY
!= node
->type
)
1085 p
->flags
|= TERMP_NOSPACE
;
1092 termp_qq_post(DECL_ARGS
)
1095 if (MDOC_BODY
!= node
->type
)
1097 p
->flags
|= TERMP_NOSPACE
;
1104 termp_bsx_pre(DECL_ARGS
)
1107 word(p
, "BSDI BSD/OS");
1114 termp_bx_pre(DECL_ARGS
)
1124 termp_ox_pre(DECL_ARGS
)
1134 termp_ux_pre(DECL_ARGS
)
1144 termp_fx_pre(DECL_ARGS
)
1154 termp_nx_pre(DECL_ARGS
)
1164 termp_sq_pre(DECL_ARGS
)
1167 if (MDOC_BODY
!= node
->type
)
1170 p
->flags
|= TERMP_NOSPACE
;
1177 termp_sq_post(DECL_ARGS
)
1180 if (MDOC_BODY
!= node
->type
)
1182 p
->flags
|= TERMP_NOSPACE
;
1189 termp_pf_pre(DECL_ARGS
)
1192 p
->flags
|= TERMP_IGNDELIM
;
1199 termp_pf_post(DECL_ARGS
)
1202 p
->flags
&= ~TERMP_IGNDELIM
;
1203 p
->flags
|= TERMP_NOSPACE
;
1209 termp_ss_pre(DECL_ARGS
)
1212 switch (node
->type
) {
1215 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SSECTION
]);
1216 p
->offset
= INDENT
/ 2;
1228 termp_ss_post(DECL_ARGS
)
1231 switch (node
->type
) {
1244 termp_pa_pre(DECL_ARGS
)
1247 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FILE
]);
1254 termp_em_pre(DECL_ARGS
)
1257 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1264 termp_cd_pre(DECL_ARGS
)
1267 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CONFIG
]);
1274 termp_cm_pre(DECL_ARGS
)
1277 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
1284 termp_ic_pre(DECL_ARGS
)
1287 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD
]);
1294 termp_in_pre(DECL_ARGS
)
1297 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_INCLUDE
]);
1304 termp_at_pre(DECL_ARGS
)
1310 assert(MDOC_TEXT
== node
->child
->type
);
1311 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1314 word(p
, mdoc_att2a(c
));
1321 termp_bq_pre(DECL_ARGS
)
1324 if (MDOC_BODY
!= node
->type
)
1327 p
->flags
|= TERMP_NOSPACE
;
1334 termp_bq_post(DECL_ARGS
)
1337 if (MDOC_BODY
!= node
->type
)
1345 termp_pq_pre(DECL_ARGS
)
1348 if (MDOC_BODY
!= node
->type
)
1351 p
->flags
|= TERMP_NOSPACE
;
1358 termp_pq_post(DECL_ARGS
)
1361 if (MDOC_BODY
!= node
->type
)
1369 termp_fo_pre(DECL_ARGS
)
1371 const struct mdoc_node
*n
;
1373 if (MDOC_BODY
== node
->type
) {
1375 p
->flags
|= TERMP_NOSPACE
;
1377 } else if (MDOC_HEAD
!= node
->type
)
1380 /* XXX - groff shows only first parameter */
1382 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1383 for (n
= node
->child
; n
; n
= n
->next
) {
1384 assert(MDOC_TEXT
== n
->type
);
1385 word(p
, n
->data
.text
.string
);
1387 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1395 termp_fo_post(DECL_ARGS
)
1398 if (MDOC_BODY
!= node
->type
)
1408 termp_bf_pre(DECL_ARGS
)
1410 const struct mdoc_node
*n
;
1411 const struct mdoc_block
*b
;
1413 /* XXX - we skip over possible trailing HEAD tokens. */
1415 if (MDOC_HEAD
== node
->type
)
1417 else if (MDOC_BLOCK
!= node
->type
)
1420 b
= &node
->data
.block
;
1422 if (NULL
== (n
= b
->head
->child
)) {
1423 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1424 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1425 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1426 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1431 assert(MDOC_TEXT
== n
->type
);
1433 if (0 == strcmp("Em", n
->data
.text
.string
))
1434 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1435 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1436 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1444 termp_sy_pre(DECL_ARGS
)
1447 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1454 termp_ms_pre(DECL_ARGS
)
1457 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMBOL
]);
1465 termp_sm_pre(DECL_ARGS
)
1469 assert(node
->child
);
1470 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1471 p
->flags
&= ~TERMP_NONOSPACE
;
1472 p
->flags
&= ~TERMP_NOSPACE
;
1474 p
->flags
|= TERMP_NONOSPACE
;
1475 p
->flags
|= TERMP_NOSPACE
;