]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.28 2009/02/28 19:15:28 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.
31 * Performs actions on nodes of the abstract syntax tree. Both pre- and
32 * post-fix operations are defined here.
35 /* FIXME: indent/tab. */
36 /* FIXME: macro arguments can be escaped. */
39 #define TTYPE_CMD_FLAG 1
40 #define TTYPE_CMD_ARG 2
41 #define TTYPE_SECTION 3
42 #define TTYPE_FUNC_DECL 4
43 #define TTYPE_VAR_DECL 5
44 #define TTYPE_FUNC_TYPE 6
45 #define TTYPE_FUNC_NAME 7
46 #define TTYPE_FUNC_ARG 8
48 #define TTYPE_SSECTION 10
51 #define TTYPE_CONFIG 13
53 #define TTYPE_INCLUDE 15
55 #define TTYPE_SYMBOL 17
59 * These define "styles" for element types, like command arguments or
60 * executable names. This is useful when multiple macros must decorate
61 * the same thing (like .Ex -std cmd and .Nm cmd).
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 */
85 static int arg_hasattr(int, size_t,
86 const struct mdoc_arg
*);
87 static int arg_getattr(int, size_t,
88 const struct mdoc_arg
*);
89 static size_t arg_offset(const struct mdoc_arg
*);
90 static size_t arg_width(const struct mdoc_arg
*);
93 * What follows describes prefix and postfix operations for the abstract
94 * syntax tree descent.
99 struct termpair *pair, \
100 const struct mdoc_meta *meta, \
101 const struct mdoc_node *node
103 #define DECL_PRE(name) \
104 static int name##_pre(DECL_ARGS)
105 #define DECL_POST(name) \
106 static void name##_post(DECL_ARGS)
107 #define DECL_PREPOST(name) \
111 DECL_PREPOST(termp__t
);
112 DECL_PREPOST(termp_aq
);
113 DECL_PREPOST(termp_bd
);
114 DECL_PREPOST(termp_bq
);
115 DECL_PREPOST(termp_d1
);
116 DECL_PREPOST(termp_dq
);
117 DECL_PREPOST(termp_fd
);
118 DECL_PREPOST(termp_fn
);
119 DECL_PREPOST(termp_fo
);
120 DECL_PREPOST(termp_ft
);
121 DECL_PREPOST(termp_it
);
122 DECL_PREPOST(termp_op
);
123 DECL_PREPOST(termp_pf
);
124 DECL_PREPOST(termp_pq
);
125 DECL_PREPOST(termp_qq
);
126 DECL_PREPOST(termp_sh
);
127 DECL_PREPOST(termp_ss
);
128 DECL_PREPOST(termp_sq
);
129 DECL_PREPOST(termp_vt
);
168 const struct termact __termacts
[MDOC_MAX
] = {
169 { NULL
, NULL
}, /* \" */
170 { NULL
, NULL
}, /* Dd */
171 { NULL
, NULL
}, /* Dt */
172 { NULL
, NULL
}, /* Os */
173 { termp_sh_pre
, termp_sh_post
}, /* Sh */
174 { termp_ss_pre
, termp_ss_post
}, /* Ss */
175 { termp_pp_pre
, NULL
}, /* Pp */
176 { termp_d1_pre
, termp_d1_post
}, /* D1 */
177 { NULL
, NULL
}, /* Dl */
178 { termp_bd_pre
, termp_bd_post
}, /* Bd */
179 { NULL
, NULL
}, /* Ed */
180 { NULL
, termp_bl_post
}, /* Bl */
181 { NULL
, NULL
}, /* El */
182 { termp_it_pre
, termp_it_post
}, /* It */
183 { NULL
, NULL
}, /* Ad */
184 { NULL
, NULL
}, /* An */
185 { termp_ar_pre
, NULL
}, /* Ar */
186 { termp_cd_pre
, NULL
}, /* Cd */
187 { termp_cm_pre
, NULL
}, /* Cm */
188 { NULL
, NULL
}, /* Dv */
189 { NULL
, NULL
}, /* Er */
190 { NULL
, NULL
}, /* Ev */
191 { termp_ex_pre
, NULL
}, /* Ex */
192 { termp_fa_pre
, NULL
}, /* Fa */
193 { termp_fd_pre
, termp_fd_post
}, /* Fd */
194 { termp_fl_pre
, NULL
}, /* Fl */
195 { termp_fn_pre
, termp_fn_post
}, /* Fn */
196 { termp_ft_pre
, termp_ft_post
}, /* Ft */
197 { termp_ic_pre
, NULL
}, /* Ic */
198 { termp_in_pre
, NULL
}, /* In */
199 { NULL
, NULL
}, /* Li */
200 { termp_nd_pre
, NULL
}, /* Nd */
201 { termp_nm_pre
, NULL
}, /* Nm */
202 { termp_op_pre
, termp_op_post
}, /* Op */
203 { NULL
, NULL
}, /* Ot */
204 { termp_pa_pre
, NULL
}, /* Pa */
205 { termp_rv_pre
, NULL
}, /* Rv */
206 { termp_st_pre
, NULL
}, /* St */
207 { termp_va_pre
, NULL
}, /* Va */
208 { termp_vt_pre
, termp_vt_post
}, /* Vt */
209 { termp_xr_pre
, NULL
}, /* Xr */
210 { NULL
, termp____post
}, /* %A */
211 { NULL
, NULL
}, /* %B */
212 { NULL
, termp____post
}, /* %D */
213 { NULL
, NULL
}, /* %I */
214 { NULL
, termp____post
}, /* %J */
215 { NULL
, NULL
}, /* %N */
216 { NULL
, NULL
}, /* %O */
217 { NULL
, NULL
}, /* %P */
218 { NULL
, NULL
}, /* %R */
219 { termp__t_pre
, termp__t_post
}, /* %T */
220 { NULL
, NULL
}, /* %V */
221 { NULL
, NULL
}, /* Ac */
222 { termp_aq_pre
, termp_aq_post
}, /* Ao */
223 { termp_aq_pre
, termp_aq_post
}, /* Aq */
224 { termp_at_pre
, NULL
}, /* At */
225 { NULL
, NULL
}, /* Bc */
226 { termp_bf_pre
, NULL
}, /* Bf */
227 { termp_bq_pre
, termp_bq_post
}, /* Bo */
228 { termp_bq_pre
, termp_bq_post
}, /* Bq */
229 { termp_bsx_pre
, NULL
}, /* Bsx */
230 { termp_bx_pre
, NULL
}, /* Bx */
231 { NULL
, NULL
}, /* Db */
232 { NULL
, NULL
}, /* Dc */
233 { termp_dq_pre
, termp_dq_post
}, /* Do */
234 { termp_dq_pre
, termp_dq_post
}, /* Dq */
235 { NULL
, NULL
}, /* Ec */
236 { NULL
, NULL
}, /* Ef */
237 { termp_em_pre
, NULL
}, /* Em */
238 { NULL
, NULL
}, /* Eo */
239 { termp_fx_pre
, NULL
}, /* Fx */
240 { termp_ms_pre
, NULL
}, /* Ms */
241 { NULL
, NULL
}, /* No */
242 { termp_ns_pre
, NULL
}, /* Ns */
243 { termp_nx_pre
, NULL
}, /* Nx */
244 { termp_ox_pre
, NULL
}, /* Ox */
245 { NULL
, NULL
}, /* Pc */
246 { termp_pf_pre
, termp_pf_post
}, /* Pf */
247 { termp_pq_pre
, termp_pq_post
}, /* Po */
248 { termp_pq_pre
, termp_pq_post
}, /* Pq */
249 { NULL
, NULL
}, /* Qc */
250 { termp_sq_pre
, termp_sq_post
}, /* Ql */
251 { termp_qq_pre
, termp_qq_post
}, /* Qo */
252 { termp_qq_pre
, termp_qq_post
}, /* Qq */
253 { NULL
, NULL
}, /* Re */
254 { termp_rs_pre
, NULL
}, /* Rs */
255 { NULL
, NULL
}, /* Sc */
256 { termp_sq_pre
, termp_sq_post
}, /* So */
257 { termp_sq_pre
, termp_sq_post
}, /* Sq */
258 { termp_sm_pre
, NULL
}, /* Sm */
259 { termp_sx_pre
, NULL
}, /* Sx */
260 { termp_sy_pre
, NULL
}, /* Sy */
261 { NULL
, NULL
}, /* Tn */
262 { termp_ux_pre
, NULL
}, /* Ux */
263 { NULL
, NULL
}, /* Xc */
264 { NULL
, NULL
}, /* Xo */
265 { termp_fo_pre
, termp_fo_post
}, /* Fo */
266 { NULL
, NULL
}, /* Fc */
267 { termp_op_pre
, termp_op_post
}, /* Oo */
268 { NULL
, NULL
}, /* Oc */
269 { NULL
, NULL
}, /* Bk */
270 { NULL
, NULL
}, /* Ek */
271 { termp_bt_pre
, NULL
}, /* Bt */
272 { NULL
, NULL
}, /* Hf */
273 { NULL
, NULL
}, /* Fr */
274 { termp_ud_pre
, NULL
}, /* Ud */
277 const struct termact
*termacts
= __termacts
;
281 arg_width(const struct mdoc_arg
*arg
)
287 if (0 == strcmp(*arg
->value
, "indent"))
289 if (0 == strcmp(*arg
->value
, "indent-two"))
292 len
= (int)strlen(*arg
->value
);
295 for (i
= 0; i
< len
- 1; i
++)
296 if ( ! isdigit((int)(*arg
->value
)[i
]))
300 if ('n' == (*arg
->value
)[len
- 1]) {
301 v
= (size_t)atoi(*arg
->value
);
306 return(strlen(*arg
->value
) + 1);
311 arg_offset(const struct mdoc_arg
*arg
)
316 if (0 == strcmp(*arg
->value
, "indent"))
318 if (0 == strcmp(*arg
->value
, "indent-two"))
320 return(strlen(*arg
->value
));
325 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
328 return(-1 != arg_getattr(arg
, argc
, argv
));
333 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
337 for (i
= 0; i
< (int)argc
; i
++)
338 if (argv
[i
].arg
== arg
)
346 termp_dq_pre(DECL_ARGS
)
349 if (MDOC_BODY
!= node
->type
)
353 p
->flags
|= TERMP_NOSPACE
;
360 termp_dq_post(DECL_ARGS
)
363 if (MDOC_BODY
!= node
->type
)
366 p
->flags
|= TERMP_NOSPACE
;
373 termp_it_pre(DECL_ARGS
)
375 const struct mdoc_node
*n
, *it
;
376 const struct mdoc_block
*bl
;
379 size_t width
, offset
;
381 switch (node
->type
) {
394 n
= it
->parent
->parent
;
397 if (MDOC_BLOCK
== node
->type
) {
398 if (arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
405 /* Get our list type. */
407 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++)
408 switch (bl
->argv
[i
].arg
) {
420 type
= bl
->argv
[i
].arg
;
424 errx(1, "list type not supported");
430 /* Save our existing (inherited) margin and offset. */
432 pair
->offset
= p
->offset
;
433 pair
->rmargin
= p
->rmargin
;
435 /* Get list width and offset. */
437 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
438 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
440 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
441 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
443 /* Override the width. */
453 width
= width
> 6 ? width
: 6;
456 /* FIXME: auto-size. */
458 errx(1, "need non-zero -width");
464 /* Word-wrap control. */
466 p
->flags
|= TERMP_NOSPACE
;
478 if (MDOC_HEAD
== node
->type
)
479 p
->flags
|= TERMP_NOBREAK
;
480 else if (MDOC_BODY
== node
->type
)
481 p
->flags
|= TERMP_NOLPAD
;
488 * Get a token to use as the HEAD lead-in. If NULL, we use the
494 if (MDOC_HEAD
== node
->type
) {
495 if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
))
497 if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
))
499 if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
500 (pair
->ppair
->ppair
->count
)++;
501 (void)snprintf(buf
, sizeof(buf
), "%d.",
502 pair
->ppair
->ppair
->count
);
505 if (arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
))
509 /* Margin control. */
523 if (MDOC_HEAD
== node
->type
)
524 p
->rmargin
= p
->offset
+ width
;
525 else if (MDOC_BODY
== node
->type
)
542 termp_it_post(DECL_ARGS
)
545 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
550 p
->offset
= pair
->offset
;
551 p
->rmargin
= pair
->rmargin
;
553 if (MDOC_HEAD
== node
->type
) {
554 p
->flags
&= ~TERMP_NOBREAK
;
555 p
->flags
&= ~TERMP_NORPAD
;
556 } else if (MDOC_BODY
== node
->type
)
557 p
->flags
&= ~TERMP_NOLPAD
;
563 termp_nm_pre(DECL_ARGS
)
566 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_PROG
]);
567 if (NULL
== node
->child
)
575 termp_fl_pre(DECL_ARGS
)
578 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
580 p
->flags
|= TERMP_NOSPACE
;
587 termp_ar_pre(DECL_ARGS
)
590 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_ARG
]);
591 if (NULL
== node
->child
)
599 termp_ns_pre(DECL_ARGS
)
602 p
->flags
|= TERMP_NOSPACE
;
609 termp_pp_pre(DECL_ARGS
)
619 termp_st_pre(DECL_ARGS
)
623 assert(1 == node
->data
.elem
.argc
);
625 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
634 termp_rs_pre(DECL_ARGS
)
637 if (MDOC_BLOCK
== node
->type
)
645 termp_rv_pre(DECL_ARGS
)
649 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
650 node
->data
.elem
.argv
);
656 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
657 word(p
, *node
->data
.elem
.argv
[i
].value
);
658 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
660 word(p
, "() function returns the value 0 if successful;");
661 word(p
, "otherwise the value -1 is returned and the");
662 word(p
, "global variable");
664 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
666 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
668 word(p
, "is set to indicate the error.");
676 termp_ex_pre(DECL_ARGS
)
680 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
681 node
->data
.elem
.argv
);
685 p
->flags
|= ttypes
[TTYPE_PROG
];
686 word(p
, *node
->data
.elem
.argv
[i
].value
);
687 p
->flags
&= ~ttypes
[TTYPE_PROG
];
688 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
696 termp_nd_pre(DECL_ARGS
)
706 termp_bl_post(DECL_ARGS
)
709 if (MDOC_BLOCK
== node
->type
)
716 termp_op_post(DECL_ARGS
)
719 if (MDOC_BODY
!= node
->type
)
721 p
->flags
|= TERMP_NOSPACE
;
728 termp_xr_pre(DECL_ARGS
)
730 const struct mdoc_node
*n
;
735 assert(MDOC_TEXT
== n
->type
);
736 word(p
, n
->data
.text
.string
);
738 if (NULL
== (n
= n
->next
))
741 assert(MDOC_TEXT
== n
->type
);
742 p
->flags
|= TERMP_NOSPACE
;
744 p
->flags
|= TERMP_NOSPACE
;
745 word(p
, n
->data
.text
.string
);
746 p
->flags
|= TERMP_NOSPACE
;
755 termp_vt_pre(DECL_ARGS
)
758 /* FIXME: this can be "type name". */
759 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
766 termp_vt_post(DECL_ARGS
)
769 if (node
->sec
== SEC_SYNOPSIS
)
776 termp_fd_pre(DECL_ARGS
)
780 * FIXME: this naming is bad. This value is used, in general,
781 * for the #include header or other preprocessor statement.
783 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_DECL
]);
790 termp_fd_post(DECL_ARGS
)
793 if (node
->sec
== SEC_SYNOPSIS
)
800 termp_sh_pre(DECL_ARGS
)
803 switch (node
->type
) {
806 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SECTION
]);
820 termp_sh_post(DECL_ARGS
)
823 switch (node
->type
) {
839 termp_op_pre(DECL_ARGS
)
842 switch (node
->type
) {
845 p
->flags
|= TERMP_NOSPACE
;
856 termp_bt_pre(DECL_ARGS
)
859 word(p
, "is currently in beta test.");
866 termp_ud_pre(DECL_ARGS
)
869 word(p
, "currently under development.");
876 termp_d1_pre(DECL_ARGS
)
879 if (MDOC_BODY
!= node
->type
)
882 p
->offset
+= (pair
->offset
= INDENT
);
889 termp_d1_post(DECL_ARGS
)
892 if (MDOC_BODY
!= node
->type
)
895 p
->offset
-= pair
->offset
;
901 termp_aq_pre(DECL_ARGS
)
904 if (MDOC_BODY
!= node
->type
)
907 p
->flags
|= TERMP_NOSPACE
;
914 termp_aq_post(DECL_ARGS
)
917 if (MDOC_BODY
!= node
->type
)
919 p
->flags
|= TERMP_NOSPACE
;
926 termp_ft_pre(DECL_ARGS
)
929 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_TYPE
]);
936 termp_ft_post(DECL_ARGS
)
939 if (node
->sec
== SEC_SYNOPSIS
)
946 termp_fn_pre(DECL_ARGS
)
948 const struct mdoc_node
*n
;
951 assert(MDOC_TEXT
== node
->child
->type
);
953 /* FIXME: can be "type funcname" "type varname"... */
955 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
956 word(p
, node
->child
->data
.text
.string
);
957 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
961 p
->flags
|= TERMP_NOSPACE
;
962 for (n
= node
->child
->next
; n
; n
= n
->next
) {
963 assert(MDOC_TEXT
== n
->type
);
964 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
965 word(p
, n
->data
.text
.string
);
966 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
973 if (SEC_SYNOPSIS
== node
->sec
)
982 termp_fn_post(DECL_ARGS
)
985 if (node
->sec
== SEC_SYNOPSIS
)
993 termp_sx_pre(DECL_ARGS
)
996 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_LINK
]);
1003 termp_fa_pre(DECL_ARGS
)
1005 struct mdoc_node
*n
;
1007 if (node
->parent
->tok
!= MDOC_Fo
) {
1008 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_ARG
]);
1012 for (n
= node
->child
; n
; n
= n
->next
) {
1013 assert(MDOC_TEXT
== n
->type
);
1015 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1016 word(p
, n
->data
.text
.string
);
1017 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1023 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1032 termp_va_pre(DECL_ARGS
)
1035 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
1042 termp_bd_pre(DECL_ARGS
)
1044 const struct mdoc_block
*bl
;
1045 const struct mdoc_node
*n
;
1048 if (MDOC_BLOCK
== node
->type
) {
1051 } else if (MDOC_BODY
!= node
->type
)
1054 assert(MDOC_BLOCK
== node
->parent
->type
);
1055 pair
->offset
= p
->offset
;
1057 bl
= &node
->parent
->data
.block
;
1060 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1062 assert(1 == bl
->argv
[i
].sz
);
1063 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1066 if ( ! arg_hasattr(MDOC_Literal
, bl
->argc
, bl
->argv
))
1069 p
->flags
|= TERMP_LITERAL
;
1071 for (n
= node
->child
; n
; n
= n
->next
) {
1072 assert(MDOC_TEXT
== n
->type
); /* FIXME */
1073 if ((*n
->data
.text
.string
)) {
1074 word(p
, n
->data
.text
.string
);
1081 p
->flags
&= ~TERMP_LITERAL
;
1088 termp_bd_post(DECL_ARGS
)
1091 if (MDOC_BODY
!= node
->type
)
1094 p
->offset
= pair
->offset
;
1100 termp_qq_pre(DECL_ARGS
)
1103 if (MDOC_BODY
!= node
->type
)
1106 p
->flags
|= TERMP_NOSPACE
;
1113 termp_qq_post(DECL_ARGS
)
1116 if (MDOC_BODY
!= node
->type
)
1118 p
->flags
|= TERMP_NOSPACE
;
1125 termp_bsx_pre(DECL_ARGS
)
1128 word(p
, "BSDI BSD/OS");
1135 termp_bx_pre(DECL_ARGS
)
1145 termp_ox_pre(DECL_ARGS
)
1155 termp_ux_pre(DECL_ARGS
)
1165 termp_fx_pre(DECL_ARGS
)
1175 termp_nx_pre(DECL_ARGS
)
1185 termp_sq_pre(DECL_ARGS
)
1188 if (MDOC_BODY
!= node
->type
)
1191 p
->flags
|= TERMP_NOSPACE
;
1198 termp_sq_post(DECL_ARGS
)
1201 if (MDOC_BODY
!= node
->type
)
1203 p
->flags
|= TERMP_NOSPACE
;
1210 termp_pf_pre(DECL_ARGS
)
1213 p
->flags
|= TERMP_IGNDELIM
;
1220 termp_pf_post(DECL_ARGS
)
1223 p
->flags
&= ~TERMP_IGNDELIM
;
1224 p
->flags
|= TERMP_NOSPACE
;
1230 termp_ss_pre(DECL_ARGS
)
1233 switch (node
->type
) {
1236 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SSECTION
]);
1237 p
->offset
= INDENT
/ 2;
1249 termp_ss_post(DECL_ARGS
)
1252 switch (node
->type
) {
1265 termp_pa_pre(DECL_ARGS
)
1268 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FILE
]);
1275 termp_em_pre(DECL_ARGS
)
1278 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1285 termp_cd_pre(DECL_ARGS
)
1288 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CONFIG
]);
1295 termp_cm_pre(DECL_ARGS
)
1298 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
1305 termp_ic_pre(DECL_ARGS
)
1308 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD
]);
1315 termp_in_pre(DECL_ARGS
)
1318 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_INCLUDE
]);
1325 termp_at_pre(DECL_ARGS
)
1331 assert(MDOC_TEXT
== node
->child
->type
);
1332 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1335 word(p
, mdoc_att2a(c
));
1342 termp_bq_pre(DECL_ARGS
)
1345 if (MDOC_BODY
!= node
->type
)
1348 p
->flags
|= TERMP_NOSPACE
;
1355 termp_bq_post(DECL_ARGS
)
1358 if (MDOC_BODY
!= node
->type
)
1366 termp_pq_pre(DECL_ARGS
)
1369 if (MDOC_BODY
!= node
->type
)
1372 p
->flags
|= TERMP_NOSPACE
;
1379 termp_pq_post(DECL_ARGS
)
1382 if (MDOC_BODY
!= node
->type
)
1390 termp_fo_pre(DECL_ARGS
)
1392 const struct mdoc_node
*n
;
1394 if (MDOC_BODY
== node
->type
) {
1396 p
->flags
|= TERMP_NOSPACE
;
1398 } else if (MDOC_HEAD
!= node
->type
)
1401 /* XXX - groff shows only first parameter */
1403 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1404 for (n
= node
->child
; n
; n
= n
->next
) {
1405 assert(MDOC_TEXT
== n
->type
);
1406 word(p
, n
->data
.text
.string
);
1408 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1416 termp_fo_post(DECL_ARGS
)
1419 if (MDOC_BODY
!= node
->type
)
1429 termp_bf_pre(DECL_ARGS
)
1431 const struct mdoc_node
*n
;
1432 const struct mdoc_block
*b
;
1434 /* XXX - we skip over possible trailing HEAD tokens. */
1436 if (MDOC_HEAD
== node
->type
)
1438 else if (MDOC_BLOCK
!= node
->type
)
1441 b
= &node
->data
.block
;
1443 if (NULL
== (n
= b
->head
->child
)) {
1444 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1445 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1446 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1447 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1452 assert(MDOC_TEXT
== n
->type
);
1454 if (0 == strcmp("Em", n
->data
.text
.string
))
1455 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1456 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1457 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1465 termp_sy_pre(DECL_ARGS
)
1468 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1475 termp_ms_pre(DECL_ARGS
)
1478 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMBOL
]);
1486 termp_sm_pre(DECL_ARGS
)
1490 assert(node
->child
);
1491 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1492 p
->flags
&= ~TERMP_NONOSPACE
;
1493 p
->flags
&= ~TERMP_NOSPACE
;
1495 p
->flags
|= TERMP_NONOSPACE
;
1496 p
->flags
|= TERMP_NOSPACE
;
1506 termp__t_pre(DECL_ARGS
)
1510 p
->flags
|= TERMP_NOSPACE
;
1517 termp__t_post(DECL_ARGS
)
1520 p
->flags
|= TERMP_NOSPACE
;
1522 word(p
, node
->next
? "," : ".");
1528 termp____post(DECL_ARGS
)
1531 p
->flags
|= TERMP_NOSPACE
;
1532 word(p
, node
->next
? "," : ".");