]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.37 2009/03/03 22:17:19 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.
29 * Performs actions on nodes of the abstract syntax tree. Both pre- and
30 * post-fix operations are defined here.
33 /* FIXME: macro arguments can be escaped. */
36 #define TTYPE_CMD_FLAG 1
37 #define TTYPE_CMD_ARG 2
38 #define TTYPE_SECTION 3
39 #define TTYPE_FUNC_DECL 4
40 #define TTYPE_VAR_DECL 5
41 #define TTYPE_FUNC_TYPE 6
42 #define TTYPE_FUNC_NAME 7
43 #define TTYPE_FUNC_ARG 8
45 #define TTYPE_SSECTION 10
48 #define TTYPE_CONFIG 13
50 #define TTYPE_INCLUDE 15
52 #define TTYPE_SYMBOL 17
57 * These define "styles" for element types, like command arguments or
58 * executable names. This is useful when multiple macros must decorate
59 * the same thing (like .Ex -std cmd and .Nm cmd).
62 /* TODO: abstract this into mdocterm.c. */
64 const int ttypes
[TTYPE_NMAX
] = {
65 TERMP_BOLD
, /* TTYPE_PROG */
66 TERMP_BOLD
, /* TTYPE_CMD_FLAG */
67 TERMP_UNDERLINE
, /* TTYPE_CMD_ARG */
68 TERMP_BOLD
, /* TTYPE_SECTION */
69 TERMP_BOLD
, /* TTYPE_FUNC_DECL */
70 TERMP_UNDERLINE
, /* TTYPE_VAR_DECL */
71 TERMP_UNDERLINE
, /* TTYPE_FUNC_TYPE */
72 TERMP_BOLD
, /* TTYPE_FUNC_NAME */
73 TERMP_UNDERLINE
, /* TTYPE_FUNC_ARG */
74 TERMP_UNDERLINE
, /* TTYPE_LINK */
75 TERMP_BOLD
, /* TTYPE_SSECTION */
76 TERMP_UNDERLINE
, /* TTYPE_FILE */
77 TERMP_UNDERLINE
, /* TTYPE_EMPH */
78 TERMP_BOLD
, /* TTYPE_CONFIG */
79 TERMP_BOLD
, /* TTYPE_CMD */
80 TERMP_BOLD
, /* TTYPE_INCLUDE */
81 TERMP_BOLD
, /* TTYPE_SYMB */
82 TERMP_BOLD
, /* TTYPE_SYMBOL */
83 TERMP_BOLD
/* TTYPE_DIAG */
86 static int arg_hasattr(int, size_t,
87 const struct mdoc_arg
*);
88 static int arg_getattr(int, size_t,
89 const struct mdoc_arg
*);
90 static size_t arg_offset(const struct mdoc_arg
*);
91 static size_t arg_width(const struct mdoc_arg
*);
94 * What follows describes prefix and postfix operations for the abstract
95 * syntax tree descent.
100 struct termpair *pair, \
101 const struct mdoc_meta *meta, \
102 const struct mdoc_node *node
104 #define DECL_PRE(name) \
105 static int name##_pre(DECL_ARGS)
106 #define DECL_POST(name) \
107 static void name##_post(DECL_ARGS)
108 #define DECL_PREPOST(name) \
112 DECL_PREPOST(termp__t
);
113 DECL_PREPOST(termp_aq
);
114 DECL_PREPOST(termp_bd
);
115 DECL_PREPOST(termp_bq
);
116 DECL_PREPOST(termp_d1
);
117 DECL_PREPOST(termp_dq
);
118 DECL_PREPOST(termp_fd
);
119 DECL_PREPOST(termp_fn
);
120 DECL_PREPOST(termp_fo
);
121 DECL_PREPOST(termp_ft
);
122 DECL_PREPOST(termp_in
);
123 DECL_PREPOST(termp_it
);
124 DECL_PREPOST(termp_op
);
125 DECL_PREPOST(termp_pf
);
126 DECL_PREPOST(termp_pq
);
127 DECL_PREPOST(termp_qq
);
128 DECL_PREPOST(termp_sh
);
129 DECL_PREPOST(termp_ss
);
130 DECL_PREPOST(termp_sq
);
131 DECL_PREPOST(termp_vt
);
169 const struct termact __termacts
[MDOC_MAX
] = {
170 { NULL
, NULL
}, /* \" */
171 { NULL
, NULL
}, /* Dd */
172 { NULL
, NULL
}, /* Dt */
173 { NULL
, NULL
}, /* Os */
174 { termp_sh_pre
, termp_sh_post
}, /* Sh */
175 { termp_ss_pre
, termp_ss_post
}, /* Ss */
176 { termp_pp_pre
, NULL
}, /* Pp */
177 { termp_d1_pre
, termp_d1_post
}, /* D1 */
178 { termp_d1_pre
, termp_d1_post
}, /* Dl */
179 { termp_bd_pre
, termp_bd_post
}, /* Bd */
180 { NULL
, NULL
}, /* Ed */
181 { NULL
, termp_bl_post
}, /* Bl */
182 { NULL
, NULL
}, /* El */
183 { termp_it_pre
, termp_it_post
}, /* It */
184 { NULL
, NULL
}, /* Ad */
185 { NULL
, NULL
}, /* An */
186 { termp_ar_pre
, NULL
}, /* Ar */
187 { termp_cd_pre
, NULL
}, /* Cd */
188 { termp_cm_pre
, NULL
}, /* Cm */
189 { NULL
, NULL
}, /* Dv */
190 { NULL
, NULL
}, /* Er */
191 { NULL
, NULL
}, /* Ev */
192 { termp_ex_pre
, NULL
}, /* Ex */
193 { termp_fa_pre
, NULL
}, /* Fa */
194 { termp_fd_pre
, termp_fd_post
}, /* Fd */
195 { termp_fl_pre
, NULL
}, /* Fl */
196 { termp_fn_pre
, termp_fn_post
}, /* Fn */
197 { termp_ft_pre
, termp_ft_post
}, /* Ft */
198 { termp_ic_pre
, NULL
}, /* Ic */
199 { termp_in_pre
, termp_in_post
}, /* In */
200 { NULL
, NULL
}, /* Li */
201 { termp_nd_pre
, NULL
}, /* Nd */
202 { termp_nm_pre
, NULL
}, /* Nm */
203 { termp_op_pre
, termp_op_post
}, /* Op */
204 { NULL
, NULL
}, /* Ot */
205 { termp_pa_pre
, NULL
}, /* Pa */
206 { termp_rv_pre
, NULL
}, /* Rv */
207 { termp_st_pre
, NULL
}, /* St */
208 { termp_va_pre
, NULL
}, /* Va */
209 { termp_vt_pre
, termp_vt_post
}, /* Vt */
210 { termp_xr_pre
, NULL
}, /* Xr */
211 { NULL
, termp____post
}, /* %A */
212 { NULL
, termp____post
}, /* %B */
213 { NULL
, termp____post
}, /* %D */
214 { NULL
, termp____post
}, /* %I */
215 { NULL
, termp____post
}, /* %J */
216 { NULL
, termp____post
}, /* %N */
217 { NULL
, termp____post
}, /* %O */
218 { NULL
, termp____post
}, /* %P */
219 { NULL
, termp____post
}, /* %R */
220 { termp__t_pre
, termp__t_post
}, /* %T */
221 { NULL
, termp____post
}, /* %V */
222 { NULL
, NULL
}, /* Ac */
223 { termp_aq_pre
, termp_aq_post
}, /* Ao */
224 { termp_aq_pre
, termp_aq_post
}, /* Aq */
225 { termp_at_pre
, NULL
}, /* At */
226 { NULL
, NULL
}, /* Bc */
227 { termp_bf_pre
, NULL
}, /* Bf */
228 { termp_bq_pre
, termp_bq_post
}, /* Bo */
229 { termp_bq_pre
, termp_bq_post
}, /* Bq */
230 { termp_bsx_pre
, NULL
}, /* Bsx */
231 { NULL
, termp_bx_post
}, /* Bx */
232 { NULL
, NULL
}, /* Db */
233 { NULL
, NULL
}, /* Dc */
234 { termp_dq_pre
, termp_dq_post
}, /* Do */
235 { termp_dq_pre
, termp_dq_post
}, /* Dq */
236 { NULL
, NULL
}, /* Ec */
237 { NULL
, NULL
}, /* Ef */
238 { termp_em_pre
, NULL
}, /* Em */
239 { NULL
, NULL
}, /* Eo */
240 { termp_fx_pre
, NULL
}, /* Fx */
241 { termp_ms_pre
, NULL
}, /* Ms */
242 { NULL
, NULL
}, /* No */
243 { termp_ns_pre
, NULL
}, /* Ns */
244 { termp_nx_pre
, NULL
}, /* Nx */
245 { termp_ox_pre
, NULL
}, /* Ox */
246 { NULL
, NULL
}, /* Pc */
247 { termp_pf_pre
, termp_pf_post
}, /* Pf */
248 { termp_pq_pre
, termp_pq_post
}, /* Po */
249 { termp_pq_pre
, termp_pq_post
}, /* Pq */
250 { NULL
, NULL
}, /* Qc */
251 { termp_sq_pre
, termp_sq_post
}, /* Ql */
252 { termp_qq_pre
, termp_qq_post
}, /* Qo */
253 { termp_qq_pre
, termp_qq_post
}, /* Qq */
254 { NULL
, NULL
}, /* Re */
255 { termp_rs_pre
, NULL
}, /* Rs */
256 { NULL
, NULL
}, /* Sc */
257 { termp_sq_pre
, termp_sq_post
}, /* So */
258 { termp_sq_pre
, termp_sq_post
}, /* Sq */
259 { termp_sm_pre
, NULL
}, /* Sm */
260 { termp_sx_pre
, NULL
}, /* Sx */
261 { termp_sy_pre
, NULL
}, /* Sy */
262 { NULL
, NULL
}, /* Tn */
263 { termp_ux_pre
, NULL
}, /* Ux */
264 { NULL
, NULL
}, /* Xc */
265 { NULL
, NULL
}, /* Xo */
266 { termp_fo_pre
, termp_fo_post
}, /* Fo */
267 { NULL
, NULL
}, /* Fc */
268 { termp_op_pre
, termp_op_post
}, /* Oo */
269 { NULL
, NULL
}, /* Oc */
270 { NULL
, NULL
}, /* Bk */
271 { NULL
, NULL
}, /* Ek */
272 { termp_bt_pre
, NULL
}, /* Bt */
273 { NULL
, NULL
}, /* Hf */
274 { NULL
, NULL
}, /* Fr */
275 { termp_ud_pre
, NULL
}, /* Ud */
278 const struct termact
*termacts
= __termacts
;
282 arg_width(const struct mdoc_arg
*arg
)
288 if (0 == strcmp(*arg
->value
, "indent"))
290 if (0 == strcmp(*arg
->value
, "indent-two"))
293 len
= (int)strlen(*arg
->value
);
296 for (i
= 0; i
< len
- 1; i
++)
297 if ( ! isdigit((int)(*arg
->value
)[i
]))
301 if ('n' == (*arg
->value
)[len
- 1]) {
302 v
= (size_t)atoi(*arg
->value
);
307 return(strlen(*arg
->value
) + 1);
312 arg_offset(const struct mdoc_arg
*arg
)
317 if (0 == strcmp(*arg
->value
, "indent"))
319 if (0 == strcmp(*arg
->value
, "indent-two"))
321 return(strlen(*arg
->value
));
326 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
329 return(-1 != arg_getattr(arg
, argc
, argv
));
334 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
338 for (i
= 0; i
< (int)argc
; i
++)
339 if (argv
[i
].arg
== arg
)
347 termp_dq_pre(DECL_ARGS
)
350 if (MDOC_BODY
!= node
->type
)
354 p
->flags
|= TERMP_NOSPACE
;
361 termp_dq_post(DECL_ARGS
)
364 if (MDOC_BODY
!= node
->type
)
367 p
->flags
|= TERMP_NOSPACE
;
374 termp_it_pre(DECL_ARGS
)
376 const struct mdoc_node
*n
, *it
;
377 const struct mdoc_block
*bl
;
380 size_t width
, offset
;
382 switch (node
->type
) {
395 n
= it
->parent
->parent
;
398 if (MDOC_BLOCK
== node
->type
) {
400 if ( ! arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
401 if (node
->prev
|| n
->prev
)
406 /* Get our list type. */
408 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++)
409 switch (bl
->argv
[i
].arg
) {
425 type
= bl
->argv
[i
].arg
;
429 errx(1, "list type not supported");
435 /* Save our existing (inherited) margin and offset. */
437 pair
->offset
= p
->offset
;
438 pair
->rmargin
= p
->rmargin
;
440 /* Get list width and offset. */
442 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
443 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
445 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
446 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
448 /* Override the width. */
458 width
= width
> 6 ? width
: 6;
462 errx(1, "need non-zero -width");
468 /* Word-wrap control. */
472 if (MDOC_HEAD
== node
->type
)
473 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_DIAG
]);
476 if (MDOC_HEAD
== node
->type
)
477 p
->flags
|= TERMP_NOSPACE
;
488 p
->flags
|= TERMP_NOSPACE
;
489 if (MDOC_HEAD
== node
->type
)
490 p
->flags
|= TERMP_NOBREAK
;
491 else if (MDOC_BODY
== node
->type
)
492 p
->flags
|= TERMP_NOLPAD
;
499 * Get a token to use as the HEAD lead-in. If NULL, we use the
505 if (MDOC_HEAD
== node
->type
) {
506 if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
))
508 if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
))
510 if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
511 (pair
->ppair
->ppair
->count
)++;
512 (void)snprintf(buf
, sizeof(buf
), "%d.",
513 pair
->ppair
->ppair
->count
);
516 if (arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
))
520 /* Margin control. */
534 if (MDOC_HEAD
== node
->type
)
535 p
->rmargin
= p
->offset
+ width
;
536 else if (MDOC_BODY
== node
->type
)
553 termp_it_post(DECL_ARGS
)
556 struct mdoc_block
*bl
;
558 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
561 assert(MDOC_BLOCK
== node
->parent
->parent
->parent
->type
);
562 assert(MDOC_Bl
== node
->parent
->parent
->parent
->tok
);
563 bl
= &node
->parent
->parent
->parent
->data
.block
;
565 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++)
566 switch (bl
->argv
[i
].arg
) {
582 type
= bl
->argv
[i
].arg
;
586 errx(1, "list type not supported");
601 p
->offset
= pair
->offset
;
602 p
->rmargin
= pair
->rmargin
;
608 if (MDOC_HEAD
== node
->type
)
609 p
->flags
&= ~TERMP_NOBREAK
;
610 else if (MDOC_BODY
== node
->type
)
611 p
->flags
&= ~TERMP_NOLPAD
;
619 termp_nm_pre(DECL_ARGS
)
622 if (SEC_SYNOPSIS
== node
->sec
)
625 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
626 if (NULL
== node
->child
)
635 termp_fl_pre(DECL_ARGS
)
638 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
640 p
->flags
|= TERMP_NOSPACE
;
647 termp_ar_pre(DECL_ARGS
)
650 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
651 if (NULL
== node
->child
) {
661 termp_ns_pre(DECL_ARGS
)
664 p
->flags
|= TERMP_NOSPACE
;
671 termp_pp_pre(DECL_ARGS
)
681 termp_st_pre(DECL_ARGS
)
685 assert(1 == node
->data
.elem
.argc
);
687 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
696 termp_rs_pre(DECL_ARGS
)
699 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
707 termp_rv_pre(DECL_ARGS
)
711 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
712 node
->data
.elem
.argv
);
718 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
719 word(p
, *node
->data
.elem
.argv
[i
].value
);
720 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
722 word(p
, "() function returns the value 0 if successful;");
723 word(p
, "otherwise the value -1 is returned and the");
724 word(p
, "global variable");
726 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
728 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
730 word(p
, "is set to indicate the error.");
738 termp_ex_pre(DECL_ARGS
)
742 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
743 node
->data
.elem
.argv
);
747 p
->flags
|= ttypes
[TTYPE_PROG
];
748 word(p
, *node
->data
.elem
.argv
[i
].value
);
749 p
->flags
&= ~ttypes
[TTYPE_PROG
];
750 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
758 termp_nd_pre(DECL_ARGS
)
768 termp_bl_post(DECL_ARGS
)
771 if (MDOC_BLOCK
== node
->type
)
778 termp_op_post(DECL_ARGS
)
781 if (MDOC_BODY
!= node
->type
)
783 p
->flags
|= TERMP_NOSPACE
;
790 termp_xr_pre(DECL_ARGS
)
792 const struct mdoc_node
*n
;
797 assert(MDOC_TEXT
== n
->type
);
798 word(p
, n
->data
.text
.string
);
800 if (NULL
== (n
= n
->next
))
803 assert(MDOC_TEXT
== n
->type
);
804 p
->flags
|= TERMP_NOSPACE
;
806 p
->flags
|= TERMP_NOSPACE
;
807 word(p
, n
->data
.text
.string
);
808 p
->flags
|= TERMP_NOSPACE
;
817 termp_vt_pre(DECL_ARGS
)
820 /* FIXME: this can be "type name". */
821 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
828 termp_vt_post(DECL_ARGS
)
831 if (node
->sec
== SEC_SYNOPSIS
)
838 termp_fd_pre(DECL_ARGS
)
842 * FIXME: this naming is bad. This value is used, in general,
843 * for the #include header or other preprocessor statement.
845 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
852 termp_fd_post(DECL_ARGS
)
855 if (node
->sec
!= SEC_SYNOPSIS
)
858 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
865 termp_sh_pre(DECL_ARGS
)
868 switch (node
->type
) {
871 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
885 termp_sh_post(DECL_ARGS
)
888 switch (node
->type
) {
904 termp_op_pre(DECL_ARGS
)
907 switch (node
->type
) {
910 p
->flags
|= TERMP_NOSPACE
;
921 termp_bt_pre(DECL_ARGS
)
924 word(p
, "is currently in beta test.");
931 termp_ud_pre(DECL_ARGS
)
934 word(p
, "currently under development.");
941 termp_d1_pre(DECL_ARGS
)
944 if (MDOC_BODY
!= node
->type
)
947 p
->offset
+= (pair
->offset
= INDENT
);
954 termp_d1_post(DECL_ARGS
)
957 if (MDOC_BODY
!= node
->type
)
960 p
->offset
-= pair
->offset
;
966 termp_aq_pre(DECL_ARGS
)
969 if (MDOC_BODY
!= node
->type
)
972 p
->flags
|= TERMP_NOSPACE
;
979 termp_aq_post(DECL_ARGS
)
982 if (MDOC_BODY
!= node
->type
)
984 p
->flags
|= TERMP_NOSPACE
;
991 termp_ft_pre(DECL_ARGS
)
994 if (SEC_SYNOPSIS
== node
->sec
)
995 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
997 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1004 termp_ft_post(DECL_ARGS
)
1007 if (SEC_SYNOPSIS
== node
->sec
)
1014 termp_fn_pre(DECL_ARGS
)
1016 const struct mdoc_node
*n
;
1018 assert(node
->child
);
1019 assert(MDOC_TEXT
== node
->child
->type
);
1021 /* FIXME: can be "type funcname" "type varname"... */
1023 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1024 word(p
, node
->child
->data
.text
.string
);
1025 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1029 p
->flags
|= TERMP_NOSPACE
;
1030 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1031 assert(MDOC_TEXT
== n
->type
);
1032 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1033 word(p
, n
->data
.text
.string
);
1034 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1041 if (SEC_SYNOPSIS
== node
->sec
)
1050 termp_fn_post(DECL_ARGS
)
1053 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1061 termp_sx_pre(DECL_ARGS
)
1064 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1071 termp_fa_pre(DECL_ARGS
)
1073 struct mdoc_node
*n
;
1075 if (node
->parent
->tok
!= MDOC_Fo
) {
1076 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1080 for (n
= node
->child
; n
; n
= n
->next
) {
1081 assert(MDOC_TEXT
== n
->type
);
1083 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1084 word(p
, n
->data
.text
.string
);
1085 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1091 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1100 termp_va_pre(DECL_ARGS
)
1103 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1110 termp_bd_pre(DECL_ARGS
)
1112 const struct mdoc_block
*bl
;
1113 const struct mdoc_node
*n
;
1116 if (MDOC_BLOCK
== node
->type
) {
1120 } else if (MDOC_BODY
!= node
->type
)
1123 pair
->offset
= p
->offset
;
1124 bl
= &node
->parent
->data
.block
;
1126 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++) {
1127 switch (bl
->argv
[i
].arg
) {
1132 case (MDOC_Unfilled
):
1134 case (MDOC_Literal
):
1135 type
= bl
->argv
[i
].arg
;
1139 errx(1, "display type not supported");
1145 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1147 assert(1 == bl
->argv
[i
].sz
);
1148 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1153 case (MDOC_Literal
):
1155 case (MDOC_Unfilled
):
1161 p
->flags
|= TERMP_LITERAL
;
1163 for (n
= node
->child
; n
; n
= n
->next
) {
1164 if (MDOC_TEXT
!= n
->type
) {
1165 warnx("non-text children not yet allowed");
1168 word(p
, n
->data
.text
.string
);
1178 termp_bd_post(DECL_ARGS
)
1181 if (MDOC_BODY
!= node
->type
)
1184 if ( ! (p
->flags
& TERMP_LITERAL
))
1187 p
->flags
&= ~TERMP_LITERAL
;
1188 p
->offset
= pair
->offset
;
1194 termp_qq_pre(DECL_ARGS
)
1197 if (MDOC_BODY
!= node
->type
)
1200 p
->flags
|= TERMP_NOSPACE
;
1207 termp_qq_post(DECL_ARGS
)
1210 if (MDOC_BODY
!= node
->type
)
1212 p
->flags
|= TERMP_NOSPACE
;
1219 termp_bsx_pre(DECL_ARGS
)
1222 word(p
, "BSDI BSD/OS");
1229 termp_bx_post(DECL_ARGS
)
1233 p
->flags
|= TERMP_NOSPACE
;
1240 termp_ox_pre(DECL_ARGS
)
1250 termp_ux_pre(DECL_ARGS
)
1260 termp_fx_pre(DECL_ARGS
)
1270 termp_nx_pre(DECL_ARGS
)
1280 termp_sq_pre(DECL_ARGS
)
1283 if (MDOC_BODY
!= node
->type
)
1286 p
->flags
|= TERMP_NOSPACE
;
1293 termp_sq_post(DECL_ARGS
)
1296 if (MDOC_BODY
!= node
->type
)
1298 p
->flags
|= TERMP_NOSPACE
;
1305 termp_pf_pre(DECL_ARGS
)
1308 p
->flags
|= TERMP_IGNDELIM
;
1315 termp_pf_post(DECL_ARGS
)
1318 p
->flags
&= ~TERMP_IGNDELIM
;
1319 p
->flags
|= TERMP_NOSPACE
;
1325 termp_ss_pre(DECL_ARGS
)
1328 switch (node
->type
) {
1331 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1332 p
->offset
= INDENT
/ 2;
1344 termp_ss_post(DECL_ARGS
)
1347 switch (node
->type
) {
1360 termp_pa_pre(DECL_ARGS
)
1363 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1370 termp_em_pre(DECL_ARGS
)
1373 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1380 termp_cd_pre(DECL_ARGS
)
1383 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1391 termp_cm_pre(DECL_ARGS
)
1394 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1401 termp_ic_pre(DECL_ARGS
)
1404 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1411 termp_in_pre(DECL_ARGS
)
1414 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1415 word(p
, "#include");
1417 p
->flags
|= TERMP_NOSPACE
;
1424 termp_in_post(DECL_ARGS
)
1427 p
->flags
|= TERMP_NOSPACE
;
1431 if (SEC_SYNOPSIS
!= node
->sec
)
1433 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1440 termp_at_pre(DECL_ARGS
)
1446 assert(MDOC_TEXT
== node
->child
->type
);
1447 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1450 word(p
, mdoc_att2a(c
));
1457 termp_bq_pre(DECL_ARGS
)
1460 if (MDOC_BODY
!= node
->type
)
1463 p
->flags
|= TERMP_NOSPACE
;
1470 termp_bq_post(DECL_ARGS
)
1473 if (MDOC_BODY
!= node
->type
)
1481 termp_pq_pre(DECL_ARGS
)
1484 if (MDOC_BODY
!= node
->type
)
1487 p
->flags
|= TERMP_NOSPACE
;
1494 termp_pq_post(DECL_ARGS
)
1497 if (MDOC_BODY
!= node
->type
)
1505 termp_fo_pre(DECL_ARGS
)
1507 const struct mdoc_node
*n
;
1509 if (MDOC_BODY
== node
->type
) {
1511 p
->flags
|= TERMP_NOSPACE
;
1513 } else if (MDOC_HEAD
!= node
->type
)
1516 /* XXX - groff shows only first parameter */
1518 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1519 for (n
= node
->child
; n
; n
= n
->next
) {
1520 assert(MDOC_TEXT
== n
->type
);
1521 word(p
, n
->data
.text
.string
);
1523 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1531 termp_fo_post(DECL_ARGS
)
1534 if (MDOC_BODY
!= node
->type
)
1544 termp_bf_pre(DECL_ARGS
)
1546 const struct mdoc_node
*n
;
1547 const struct mdoc_block
*b
;
1549 /* XXX - we skip over possible trailing HEAD tokens. */
1551 if (MDOC_HEAD
== node
->type
)
1553 else if (MDOC_BLOCK
!= node
->type
)
1556 b
= &node
->data
.block
;
1558 if (NULL
== (n
= b
->head
->child
)) {
1559 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1560 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1561 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1562 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1567 assert(MDOC_TEXT
== n
->type
);
1569 if (0 == strcmp("Em", n
->data
.text
.string
))
1570 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1571 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1572 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1580 termp_sy_pre(DECL_ARGS
)
1583 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1590 termp_ms_pre(DECL_ARGS
)
1593 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1601 termp_sm_pre(DECL_ARGS
)
1605 assert(node
->child
);
1606 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1607 p
->flags
&= ~TERMP_NONOSPACE
;
1608 p
->flags
&= ~TERMP_NOSPACE
;
1610 p
->flags
|= TERMP_NONOSPACE
;
1611 p
->flags
|= TERMP_NOSPACE
;
1621 termp__t_pre(DECL_ARGS
)
1625 p
->flags
|= TERMP_NOSPACE
;
1632 termp__t_post(DECL_ARGS
)
1635 p
->flags
|= TERMP_NOSPACE
;
1637 word(p
, node
->next
? "," : ".");
1643 termp____post(DECL_ARGS
)
1646 p
->flags
|= TERMP_NOSPACE
;
1647 word(p
, node
->next
? "," : ".");