]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
5181f9b0018a69a230a811f9a1fd45f8f60f65ef
1 /* $Id: term.c,v 1.36 2009/03/02 17:29:16 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
56 * These define "styles" for element types, like command arguments or
57 * executable names. This is useful when multiple macros must decorate
58 * the same thing (like .Ex -std cmd and .Nm cmd).
61 /* TODO: abstract this into mdocterm.c. */
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__t
);
111 DECL_PREPOST(termp_aq
);
112 DECL_PREPOST(termp_bd
);
113 DECL_PREPOST(termp_bq
);
114 DECL_PREPOST(termp_d1
);
115 DECL_PREPOST(termp_dq
);
116 DECL_PREPOST(termp_fd
);
117 DECL_PREPOST(termp_fn
);
118 DECL_PREPOST(termp_fo
);
119 DECL_PREPOST(termp_ft
);
120 DECL_PREPOST(termp_in
);
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
);
167 const struct termact __termacts
[MDOC_MAX
] = {
168 { NULL
, NULL
}, /* \" */
169 { NULL
, NULL
}, /* Dd */
170 { NULL
, NULL
}, /* Dt */
171 { NULL
, NULL
}, /* Os */
172 { termp_sh_pre
, termp_sh_post
}, /* Sh */
173 { termp_ss_pre
, termp_ss_post
}, /* Ss */
174 { termp_pp_pre
, NULL
}, /* Pp */
175 { termp_d1_pre
, termp_d1_post
}, /* D1 */
176 { termp_d1_pre
, termp_d1_post
}, /* Dl */
177 { termp_bd_pre
, termp_bd_post
}, /* Bd */
178 { NULL
, NULL
}, /* Ed */
179 { NULL
, termp_bl_post
}, /* Bl */
180 { NULL
, NULL
}, /* El */
181 { termp_it_pre
, termp_it_post
}, /* It */
182 { NULL
, NULL
}, /* Ad */
183 { NULL
, NULL
}, /* An */
184 { termp_ar_pre
, NULL
}, /* Ar */
185 { termp_cd_pre
, NULL
}, /* Cd */
186 { termp_cm_pre
, NULL
}, /* Cm */
187 { NULL
, NULL
}, /* Dv */
188 { NULL
, NULL
}, /* Er */
189 { NULL
, NULL
}, /* Ev */
190 { termp_ex_pre
, NULL
}, /* Ex */
191 { termp_fa_pre
, NULL
}, /* Fa */
192 { termp_fd_pre
, termp_fd_post
}, /* Fd */
193 { termp_fl_pre
, NULL
}, /* Fl */
194 { termp_fn_pre
, termp_fn_post
}, /* Fn */
195 { termp_ft_pre
, termp_ft_post
}, /* Ft */
196 { termp_ic_pre
, NULL
}, /* Ic */
197 { termp_in_pre
, termp_in_post
}, /* In */
198 { NULL
, NULL
}, /* Li */
199 { termp_nd_pre
, NULL
}, /* Nd */
200 { termp_nm_pre
, NULL
}, /* Nm */
201 { termp_op_pre
, termp_op_post
}, /* Op */
202 { NULL
, NULL
}, /* Ot */
203 { termp_pa_pre
, NULL
}, /* Pa */
204 { termp_rv_pre
, NULL
}, /* Rv */
205 { termp_st_pre
, NULL
}, /* St */
206 { termp_va_pre
, NULL
}, /* Va */
207 { termp_vt_pre
, termp_vt_post
}, /* Vt */
208 { termp_xr_pre
, NULL
}, /* Xr */
209 { NULL
, termp____post
}, /* %A */
210 { NULL
, termp____post
}, /* %B */
211 { NULL
, termp____post
}, /* %D */
212 { NULL
, termp____post
}, /* %I */
213 { NULL
, termp____post
}, /* %J */
214 { NULL
, termp____post
}, /* %N */
215 { NULL
, termp____post
}, /* %O */
216 { NULL
, termp____post
}, /* %P */
217 { NULL
, termp____post
}, /* %R */
218 { termp__t_pre
, termp__t_post
}, /* %T */
219 { NULL
, termp____post
}, /* %V */
220 { NULL
, NULL
}, /* Ac */
221 { termp_aq_pre
, termp_aq_post
}, /* Ao */
222 { termp_aq_pre
, termp_aq_post
}, /* Aq */
223 { termp_at_pre
, NULL
}, /* At */
224 { NULL
, NULL
}, /* Bc */
225 { termp_bf_pre
, NULL
}, /* Bf */
226 { termp_bq_pre
, termp_bq_post
}, /* Bo */
227 { termp_bq_pre
, termp_bq_post
}, /* Bq */
228 { termp_bsx_pre
, NULL
}, /* Bsx */
229 { NULL
, termp_bx_post
}, /* Bx */
230 { NULL
, NULL
}, /* Db */
231 { NULL
, NULL
}, /* Dc */
232 { termp_dq_pre
, termp_dq_post
}, /* Do */
233 { termp_dq_pre
, termp_dq_post
}, /* Dq */
234 { NULL
, NULL
}, /* Ec */
235 { NULL
, NULL
}, /* Ef */
236 { termp_em_pre
, NULL
}, /* Em */
237 { NULL
, NULL
}, /* Eo */
238 { termp_fx_pre
, NULL
}, /* Fx */
239 { termp_ms_pre
, NULL
}, /* Ms */
240 { NULL
, NULL
}, /* No */
241 { termp_ns_pre
, NULL
}, /* Ns */
242 { termp_nx_pre
, NULL
}, /* Nx */
243 { termp_ox_pre
, NULL
}, /* Ox */
244 { NULL
, NULL
}, /* Pc */
245 { termp_pf_pre
, termp_pf_post
}, /* Pf */
246 { termp_pq_pre
, termp_pq_post
}, /* Po */
247 { termp_pq_pre
, termp_pq_post
}, /* Pq */
248 { NULL
, NULL
}, /* Qc */
249 { termp_sq_pre
, termp_sq_post
}, /* Ql */
250 { termp_qq_pre
, termp_qq_post
}, /* Qo */
251 { termp_qq_pre
, termp_qq_post
}, /* Qq */
252 { NULL
, NULL
}, /* Re */
253 { termp_rs_pre
, NULL
}, /* Rs */
254 { NULL
, NULL
}, /* Sc */
255 { termp_sq_pre
, termp_sq_post
}, /* So */
256 { termp_sq_pre
, termp_sq_post
}, /* Sq */
257 { termp_sm_pre
, NULL
}, /* Sm */
258 { termp_sx_pre
, NULL
}, /* Sx */
259 { termp_sy_pre
, NULL
}, /* Sy */
260 { NULL
, NULL
}, /* Tn */
261 { termp_ux_pre
, NULL
}, /* Ux */
262 { NULL
, NULL
}, /* Xc */
263 { NULL
, NULL
}, /* Xo */
264 { termp_fo_pre
, termp_fo_post
}, /* Fo */
265 { NULL
, NULL
}, /* Fc */
266 { termp_op_pre
, termp_op_post
}, /* Oo */
267 { NULL
, NULL
}, /* Oc */
268 { NULL
, NULL
}, /* Bk */
269 { NULL
, NULL
}, /* Ek */
270 { termp_bt_pre
, NULL
}, /* Bt */
271 { NULL
, NULL
}, /* Hf */
272 { NULL
, NULL
}, /* Fr */
273 { termp_ud_pre
, NULL
}, /* Ud */
276 const struct termact
*termacts
= __termacts
;
280 arg_width(const struct mdoc_arg
*arg
)
286 if (0 == strcmp(*arg
->value
, "indent"))
288 if (0 == strcmp(*arg
->value
, "indent-two"))
291 len
= (int)strlen(*arg
->value
);
294 for (i
= 0; i
< len
- 1; i
++)
295 if ( ! isdigit((int)(*arg
->value
)[i
]))
299 if ('n' == (*arg
->value
)[len
- 1]) {
300 v
= (size_t)atoi(*arg
->value
);
305 return(strlen(*arg
->value
) + 1);
310 arg_offset(const struct mdoc_arg
*arg
)
315 if (0 == strcmp(*arg
->value
, "indent"))
317 if (0 == strcmp(*arg
->value
, "indent-two"))
319 return(strlen(*arg
->value
));
324 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
327 return(-1 != arg_getattr(arg
, argc
, argv
));
332 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
336 for (i
= 0; i
< (int)argc
; i
++)
337 if (argv
[i
].arg
== arg
)
345 termp_dq_pre(DECL_ARGS
)
348 if (MDOC_BODY
!= node
->type
)
352 p
->flags
|= TERMP_NOSPACE
;
359 termp_dq_post(DECL_ARGS
)
362 if (MDOC_BODY
!= node
->type
)
365 p
->flags
|= TERMP_NOSPACE
;
372 termp_it_pre(DECL_ARGS
)
374 const struct mdoc_node
*n
, *it
;
375 const struct mdoc_block
*bl
;
378 size_t width
, offset
;
380 switch (node
->type
) {
393 n
= it
->parent
->parent
;
396 if (MDOC_BLOCK
== node
->type
) {
398 if ( ! arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
399 if (node
->prev
|| n
->prev
)
404 /* Get our list type. */
406 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++)
407 switch (bl
->argv
[i
].arg
) {
419 type
= bl
->argv
[i
].arg
;
423 errx(1, "list type not supported");
429 /* Save our existing (inherited) margin and offset. */
431 pair
->offset
= p
->offset
;
432 pair
->rmargin
= p
->rmargin
;
434 /* Get list width and offset. */
436 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
437 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
439 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
440 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
442 /* Override the width. */
452 width
= width
> 6 ? width
: 6;
455 /* FIXME: auto-size. */
457 errx(1, "need non-zero -width");
463 /* Word-wrap control. */
465 p
->flags
|= TERMP_NOSPACE
;
477 if (MDOC_HEAD
== node
->type
)
478 p
->flags
|= TERMP_NOBREAK
;
479 else if (MDOC_BODY
== node
->type
)
480 p
->flags
|= TERMP_NOLPAD
;
487 * Get a token to use as the HEAD lead-in. If NULL, we use the
493 if (MDOC_HEAD
== node
->type
) {
494 if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
))
496 if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
))
498 if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
499 (pair
->ppair
->ppair
->count
)++;
500 (void)snprintf(buf
, sizeof(buf
), "%d.",
501 pair
->ppair
->ppair
->count
);
504 if (arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
))
508 /* Margin control. */
522 if (MDOC_HEAD
== node
->type
)
523 p
->rmargin
= p
->offset
+ width
;
524 else if (MDOC_BODY
== node
->type
)
541 termp_it_post(DECL_ARGS
)
544 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
549 p
->offset
= pair
->offset
;
550 p
->rmargin
= pair
->rmargin
;
552 if (MDOC_HEAD
== node
->type
)
553 p
->flags
&= ~TERMP_NOBREAK
;
554 else if (MDOC_BODY
== node
->type
)
555 p
->flags
&= ~TERMP_NOLPAD
;
561 termp_nm_pre(DECL_ARGS
)
564 if (SEC_SYNOPSIS
== node
->sec
)
567 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
568 if (NULL
== node
->child
)
577 termp_fl_pre(DECL_ARGS
)
580 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
582 p
->flags
|= TERMP_NOSPACE
;
589 termp_ar_pre(DECL_ARGS
)
592 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
593 if (NULL
== node
->child
) {
603 termp_ns_pre(DECL_ARGS
)
606 p
->flags
|= TERMP_NOSPACE
;
613 termp_pp_pre(DECL_ARGS
)
623 termp_st_pre(DECL_ARGS
)
627 assert(1 == node
->data
.elem
.argc
);
629 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
638 termp_rs_pre(DECL_ARGS
)
641 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
649 termp_rv_pre(DECL_ARGS
)
653 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
654 node
->data
.elem
.argv
);
660 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
661 word(p
, *node
->data
.elem
.argv
[i
].value
);
662 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
664 word(p
, "() function returns the value 0 if successful;");
665 word(p
, "otherwise the value -1 is returned and the");
666 word(p
, "global variable");
668 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
670 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
672 word(p
, "is set to indicate the error.");
680 termp_ex_pre(DECL_ARGS
)
684 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
685 node
->data
.elem
.argv
);
689 p
->flags
|= ttypes
[TTYPE_PROG
];
690 word(p
, *node
->data
.elem
.argv
[i
].value
);
691 p
->flags
&= ~ttypes
[TTYPE_PROG
];
692 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
700 termp_nd_pre(DECL_ARGS
)
710 termp_bl_post(DECL_ARGS
)
713 if (MDOC_BLOCK
== node
->type
)
720 termp_op_post(DECL_ARGS
)
723 if (MDOC_BODY
!= node
->type
)
725 p
->flags
|= TERMP_NOSPACE
;
732 termp_xr_pre(DECL_ARGS
)
734 const struct mdoc_node
*n
;
739 assert(MDOC_TEXT
== n
->type
);
740 word(p
, n
->data
.text
.string
);
742 if (NULL
== (n
= n
->next
))
745 assert(MDOC_TEXT
== n
->type
);
746 p
->flags
|= TERMP_NOSPACE
;
748 p
->flags
|= TERMP_NOSPACE
;
749 word(p
, n
->data
.text
.string
);
750 p
->flags
|= TERMP_NOSPACE
;
759 termp_vt_pre(DECL_ARGS
)
762 /* FIXME: this can be "type name". */
763 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
770 termp_vt_post(DECL_ARGS
)
773 if (node
->sec
== SEC_SYNOPSIS
)
780 termp_fd_pre(DECL_ARGS
)
784 * FIXME: this naming is bad. This value is used, in general,
785 * for the #include header or other preprocessor statement.
787 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
794 termp_fd_post(DECL_ARGS
)
797 if (node
->sec
!= SEC_SYNOPSIS
)
800 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
807 termp_sh_pre(DECL_ARGS
)
810 switch (node
->type
) {
813 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
827 termp_sh_post(DECL_ARGS
)
830 switch (node
->type
) {
846 termp_op_pre(DECL_ARGS
)
849 switch (node
->type
) {
852 p
->flags
|= TERMP_NOSPACE
;
863 termp_bt_pre(DECL_ARGS
)
866 word(p
, "is currently in beta test.");
873 termp_ud_pre(DECL_ARGS
)
876 word(p
, "currently under development.");
883 termp_d1_pre(DECL_ARGS
)
886 if (MDOC_BODY
!= node
->type
)
889 p
->offset
+= (pair
->offset
= INDENT
);
896 termp_d1_post(DECL_ARGS
)
899 if (MDOC_BODY
!= node
->type
)
902 p
->offset
-= pair
->offset
;
908 termp_aq_pre(DECL_ARGS
)
911 if (MDOC_BODY
!= node
->type
)
914 p
->flags
|= TERMP_NOSPACE
;
921 termp_aq_post(DECL_ARGS
)
924 if (MDOC_BODY
!= node
->type
)
926 p
->flags
|= TERMP_NOSPACE
;
933 termp_ft_pre(DECL_ARGS
)
936 if (SEC_SYNOPSIS
== node
->sec
)
937 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
939 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
946 termp_ft_post(DECL_ARGS
)
949 if (SEC_SYNOPSIS
== node
->sec
)
956 termp_fn_pre(DECL_ARGS
)
958 const struct mdoc_node
*n
;
961 assert(MDOC_TEXT
== node
->child
->type
);
963 /* FIXME: can be "type funcname" "type varname"... */
965 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
966 word(p
, node
->child
->data
.text
.string
);
967 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
971 p
->flags
|= TERMP_NOSPACE
;
972 for (n
= node
->child
->next
; n
; n
= n
->next
) {
973 assert(MDOC_TEXT
== n
->type
);
974 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
975 word(p
, n
->data
.text
.string
);
976 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
983 if (SEC_SYNOPSIS
== node
->sec
)
992 termp_fn_post(DECL_ARGS
)
995 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1003 termp_sx_pre(DECL_ARGS
)
1006 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1013 termp_fa_pre(DECL_ARGS
)
1015 struct mdoc_node
*n
;
1017 if (node
->parent
->tok
!= MDOC_Fo
) {
1018 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1022 for (n
= node
->child
; n
; n
= n
->next
) {
1023 assert(MDOC_TEXT
== n
->type
);
1025 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1026 word(p
, n
->data
.text
.string
);
1027 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1033 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1042 termp_va_pre(DECL_ARGS
)
1045 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1052 termp_bd_pre(DECL_ARGS
)
1054 const struct mdoc_block
*bl
;
1055 const struct mdoc_node
*n
;
1058 if (MDOC_BLOCK
== node
->type
) {
1062 } else if (MDOC_BODY
!= node
->type
)
1065 pair
->offset
= p
->offset
;
1066 bl
= &node
->parent
->data
.block
;
1068 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++) {
1069 switch (bl
->argv
[i
].arg
) {
1074 case (MDOC_Unfilled
):
1076 case (MDOC_Literal
):
1077 type
= bl
->argv
[i
].arg
;
1081 errx(1, "display type not supported");
1087 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1089 assert(1 == bl
->argv
[i
].sz
);
1090 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1095 case (MDOC_Literal
):
1097 case (MDOC_Unfilled
):
1103 p
->flags
|= TERMP_LITERAL
;
1105 for (n
= node
->child
; n
; n
= n
->next
) {
1106 if (MDOC_TEXT
!= n
->type
) {
1107 warnx("non-text children not yet allowed");
1110 word(p
, n
->data
.text
.string
);
1120 termp_bd_post(DECL_ARGS
)
1123 if (MDOC_BODY
!= node
->type
)
1126 if ( ! (p
->flags
& TERMP_LITERAL
))
1129 p
->flags
&= ~TERMP_LITERAL
;
1130 p
->offset
= pair
->offset
;
1136 termp_qq_pre(DECL_ARGS
)
1139 if (MDOC_BODY
!= node
->type
)
1142 p
->flags
|= TERMP_NOSPACE
;
1149 termp_qq_post(DECL_ARGS
)
1152 if (MDOC_BODY
!= node
->type
)
1154 p
->flags
|= TERMP_NOSPACE
;
1161 termp_bsx_pre(DECL_ARGS
)
1164 word(p
, "BSDI BSD/OS");
1171 termp_bx_post(DECL_ARGS
)
1175 p
->flags
|= TERMP_NOSPACE
;
1182 termp_ox_pre(DECL_ARGS
)
1192 termp_ux_pre(DECL_ARGS
)
1202 termp_fx_pre(DECL_ARGS
)
1212 termp_nx_pre(DECL_ARGS
)
1222 termp_sq_pre(DECL_ARGS
)
1225 if (MDOC_BODY
!= node
->type
)
1228 p
->flags
|= TERMP_NOSPACE
;
1235 termp_sq_post(DECL_ARGS
)
1238 if (MDOC_BODY
!= node
->type
)
1240 p
->flags
|= TERMP_NOSPACE
;
1247 termp_pf_pre(DECL_ARGS
)
1250 p
->flags
|= TERMP_IGNDELIM
;
1257 termp_pf_post(DECL_ARGS
)
1260 p
->flags
&= ~TERMP_IGNDELIM
;
1261 p
->flags
|= TERMP_NOSPACE
;
1267 termp_ss_pre(DECL_ARGS
)
1270 switch (node
->type
) {
1273 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1274 p
->offset
= INDENT
/ 2;
1286 termp_ss_post(DECL_ARGS
)
1289 switch (node
->type
) {
1302 termp_pa_pre(DECL_ARGS
)
1305 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1312 termp_em_pre(DECL_ARGS
)
1315 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1322 termp_cd_pre(DECL_ARGS
)
1325 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1333 termp_cm_pre(DECL_ARGS
)
1336 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1343 termp_ic_pre(DECL_ARGS
)
1346 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1353 termp_in_pre(DECL_ARGS
)
1356 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1357 word(p
, "#include");
1359 p
->flags
|= TERMP_NOSPACE
;
1366 termp_in_post(DECL_ARGS
)
1369 p
->flags
|= TERMP_NOSPACE
;
1373 if (SEC_SYNOPSIS
!= node
->sec
)
1375 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1382 termp_at_pre(DECL_ARGS
)
1388 assert(MDOC_TEXT
== node
->child
->type
);
1389 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1392 word(p
, mdoc_att2a(c
));
1399 termp_bq_pre(DECL_ARGS
)
1402 if (MDOC_BODY
!= node
->type
)
1405 p
->flags
|= TERMP_NOSPACE
;
1412 termp_bq_post(DECL_ARGS
)
1415 if (MDOC_BODY
!= node
->type
)
1423 termp_pq_pre(DECL_ARGS
)
1426 if (MDOC_BODY
!= node
->type
)
1429 p
->flags
|= TERMP_NOSPACE
;
1436 termp_pq_post(DECL_ARGS
)
1439 if (MDOC_BODY
!= node
->type
)
1447 termp_fo_pre(DECL_ARGS
)
1449 const struct mdoc_node
*n
;
1451 if (MDOC_BODY
== node
->type
) {
1453 p
->flags
|= TERMP_NOSPACE
;
1455 } else if (MDOC_HEAD
!= node
->type
)
1458 /* XXX - groff shows only first parameter */
1460 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1461 for (n
= node
->child
; n
; n
= n
->next
) {
1462 assert(MDOC_TEXT
== n
->type
);
1463 word(p
, n
->data
.text
.string
);
1465 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1473 termp_fo_post(DECL_ARGS
)
1476 if (MDOC_BODY
!= node
->type
)
1486 termp_bf_pre(DECL_ARGS
)
1488 const struct mdoc_node
*n
;
1489 const struct mdoc_block
*b
;
1491 /* XXX - we skip over possible trailing HEAD tokens. */
1493 if (MDOC_HEAD
== node
->type
)
1495 else if (MDOC_BLOCK
!= node
->type
)
1498 b
= &node
->data
.block
;
1500 if (NULL
== (n
= b
->head
->child
)) {
1501 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1502 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1503 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1504 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1509 assert(MDOC_TEXT
== n
->type
);
1511 if (0 == strcmp("Em", n
->data
.text
.string
))
1512 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1513 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1514 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1522 termp_sy_pre(DECL_ARGS
)
1525 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1532 termp_ms_pre(DECL_ARGS
)
1535 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1543 termp_sm_pre(DECL_ARGS
)
1547 assert(node
->child
);
1548 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1549 p
->flags
&= ~TERMP_NONOSPACE
;
1550 p
->flags
&= ~TERMP_NOSPACE
;
1552 p
->flags
|= TERMP_NONOSPACE
;
1553 p
->flags
|= TERMP_NOSPACE
;
1563 termp__t_pre(DECL_ARGS
)
1567 p
->flags
|= TERMP_NOSPACE
;
1574 termp__t_post(DECL_ARGS
)
1577 p
->flags
|= TERMP_NOSPACE
;
1579 word(p
, node
->next
? "," : ".");
1585 termp____post(DECL_ARGS
)
1588 p
->flags
|= TERMP_NOSPACE
;
1589 word(p
, node
->next
? "," : ".");