]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
7888980b66f2aa8d14ce41c69f4c04a07af0f3ac
1 /* $Id: term.c,v 1.38 2009/03/03 22:28:21 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
> 4 ? width
: 4;
462 errx(1, "need non-zero -width");
468 /* Word-wrap control. */
472 /* XXX - ignore child macros!? */
473 if (MDOC_HEAD
== node
->type
)
474 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_DIAG
]);
477 if (MDOC_HEAD
== node
->type
)
478 p
->flags
|= TERMP_NOSPACE
;
489 p
->flags
|= TERMP_NOSPACE
;
490 if (MDOC_HEAD
== node
->type
)
491 p
->flags
|= TERMP_NOBREAK
;
492 else if (MDOC_BODY
== node
->type
)
493 p
->flags
|= TERMP_NOLPAD
;
500 * Get a token to use as the HEAD lead-in. If NULL, we use the
506 if (MDOC_HEAD
== node
->type
) {
507 if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
))
509 if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
))
511 if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
512 (pair
->ppair
->ppair
->count
)++;
513 (void)snprintf(buf
, sizeof(buf
), "%d.",
514 pair
->ppair
->ppair
->count
);
517 if (arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
))
521 /* Margin control. */
535 if (MDOC_HEAD
== node
->type
)
536 p
->rmargin
= p
->offset
+ width
;
537 else if (MDOC_BODY
== node
->type
)
554 termp_it_post(DECL_ARGS
)
557 struct mdoc_block
*bl
;
559 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
562 assert(MDOC_BLOCK
== node
->parent
->parent
->parent
->type
);
563 assert(MDOC_Bl
== node
->parent
->parent
->parent
->tok
);
564 bl
= &node
->parent
->parent
->parent
->data
.block
;
566 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++)
567 switch (bl
->argv
[i
].arg
) {
583 type
= bl
->argv
[i
].arg
;
587 errx(1, "list type not supported");
602 p
->offset
= pair
->offset
;
603 p
->rmargin
= pair
->rmargin
;
609 if (MDOC_HEAD
== node
->type
)
610 p
->flags
&= ~TERMP_NOBREAK
;
611 else if (MDOC_BODY
== node
->type
)
612 p
->flags
&= ~TERMP_NOLPAD
;
620 termp_nm_pre(DECL_ARGS
)
623 if (SEC_SYNOPSIS
== node
->sec
)
626 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
627 if (NULL
== node
->child
)
636 termp_fl_pre(DECL_ARGS
)
639 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
641 p
->flags
|= TERMP_NOSPACE
;
648 termp_ar_pre(DECL_ARGS
)
651 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
652 if (NULL
== node
->child
) {
662 termp_ns_pre(DECL_ARGS
)
665 p
->flags
|= TERMP_NOSPACE
;
672 termp_pp_pre(DECL_ARGS
)
682 termp_st_pre(DECL_ARGS
)
686 assert(1 == node
->data
.elem
.argc
);
688 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
697 termp_rs_pre(DECL_ARGS
)
700 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
708 termp_rv_pre(DECL_ARGS
)
712 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
713 node
->data
.elem
.argv
);
719 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
720 word(p
, *node
->data
.elem
.argv
[i
].value
);
721 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
723 word(p
, "() function returns the value 0 if successful;");
724 word(p
, "otherwise the value -1 is returned and the");
725 word(p
, "global variable");
727 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
729 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
731 word(p
, "is set to indicate the error.");
739 termp_ex_pre(DECL_ARGS
)
743 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
744 node
->data
.elem
.argv
);
748 p
->flags
|= ttypes
[TTYPE_PROG
];
749 word(p
, *node
->data
.elem
.argv
[i
].value
);
750 p
->flags
&= ~ttypes
[TTYPE_PROG
];
751 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
759 termp_nd_pre(DECL_ARGS
)
769 termp_bl_post(DECL_ARGS
)
772 if (MDOC_BLOCK
== node
->type
)
779 termp_op_post(DECL_ARGS
)
782 if (MDOC_BODY
!= node
->type
)
784 p
->flags
|= TERMP_NOSPACE
;
791 termp_xr_pre(DECL_ARGS
)
793 const struct mdoc_node
*n
;
798 assert(MDOC_TEXT
== n
->type
);
799 word(p
, n
->data
.text
.string
);
801 if (NULL
== (n
= n
->next
))
804 assert(MDOC_TEXT
== n
->type
);
805 p
->flags
|= TERMP_NOSPACE
;
807 p
->flags
|= TERMP_NOSPACE
;
808 word(p
, n
->data
.text
.string
);
809 p
->flags
|= TERMP_NOSPACE
;
818 termp_vt_pre(DECL_ARGS
)
821 /* FIXME: this can be "type name". */
822 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
829 termp_vt_post(DECL_ARGS
)
832 if (node
->sec
== SEC_SYNOPSIS
)
839 termp_fd_pre(DECL_ARGS
)
843 * FIXME: this naming is bad. This value is used, in general,
844 * for the #include header or other preprocessor statement.
846 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
853 termp_fd_post(DECL_ARGS
)
856 if (node
->sec
!= SEC_SYNOPSIS
)
859 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
866 termp_sh_pre(DECL_ARGS
)
869 switch (node
->type
) {
872 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
886 termp_sh_post(DECL_ARGS
)
889 switch (node
->type
) {
905 termp_op_pre(DECL_ARGS
)
908 switch (node
->type
) {
911 p
->flags
|= TERMP_NOSPACE
;
922 termp_bt_pre(DECL_ARGS
)
925 word(p
, "is currently in beta test.");
932 termp_ud_pre(DECL_ARGS
)
935 word(p
, "currently under development.");
942 termp_d1_pre(DECL_ARGS
)
945 if (MDOC_BODY
!= node
->type
)
948 p
->offset
+= (pair
->offset
= INDENT
);
955 termp_d1_post(DECL_ARGS
)
958 if (MDOC_BODY
!= node
->type
)
961 p
->offset
-= pair
->offset
;
967 termp_aq_pre(DECL_ARGS
)
970 if (MDOC_BODY
!= node
->type
)
973 p
->flags
|= TERMP_NOSPACE
;
980 termp_aq_post(DECL_ARGS
)
983 if (MDOC_BODY
!= node
->type
)
985 p
->flags
|= TERMP_NOSPACE
;
992 termp_ft_pre(DECL_ARGS
)
995 if (SEC_SYNOPSIS
== node
->sec
)
996 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
998 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1005 termp_ft_post(DECL_ARGS
)
1008 if (SEC_SYNOPSIS
== node
->sec
)
1015 termp_fn_pre(DECL_ARGS
)
1017 const struct mdoc_node
*n
;
1019 assert(node
->child
);
1020 assert(MDOC_TEXT
== node
->child
->type
);
1022 /* FIXME: can be "type funcname" "type varname"... */
1024 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1025 word(p
, node
->child
->data
.text
.string
);
1026 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1030 p
->flags
|= TERMP_NOSPACE
;
1031 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1032 assert(MDOC_TEXT
== n
->type
);
1033 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1034 word(p
, n
->data
.text
.string
);
1035 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1042 if (SEC_SYNOPSIS
== node
->sec
)
1051 termp_fn_post(DECL_ARGS
)
1054 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1062 termp_sx_pre(DECL_ARGS
)
1065 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1072 termp_fa_pre(DECL_ARGS
)
1074 struct mdoc_node
*n
;
1076 if (node
->parent
->tok
!= MDOC_Fo
) {
1077 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1081 for (n
= node
->child
; n
; n
= n
->next
) {
1082 assert(MDOC_TEXT
== n
->type
);
1084 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1085 word(p
, n
->data
.text
.string
);
1086 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1092 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1101 termp_va_pre(DECL_ARGS
)
1104 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1111 termp_bd_pre(DECL_ARGS
)
1113 const struct mdoc_block
*bl
;
1114 const struct mdoc_node
*n
;
1117 if (MDOC_BLOCK
== node
->type
) {
1121 } else if (MDOC_BODY
!= node
->type
)
1124 pair
->offset
= p
->offset
;
1125 bl
= &node
->parent
->data
.block
;
1127 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++) {
1128 switch (bl
->argv
[i
].arg
) {
1133 case (MDOC_Unfilled
):
1135 case (MDOC_Literal
):
1136 type
= bl
->argv
[i
].arg
;
1140 errx(1, "display type not supported");
1146 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1148 assert(1 == bl
->argv
[i
].sz
);
1149 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1154 case (MDOC_Literal
):
1156 case (MDOC_Unfilled
):
1162 p
->flags
|= TERMP_LITERAL
;
1164 for (n
= node
->child
; n
; n
= n
->next
) {
1165 if (MDOC_TEXT
!= n
->type
) {
1166 warnx("non-text children not yet allowed");
1169 word(p
, n
->data
.text
.string
);
1179 termp_bd_post(DECL_ARGS
)
1182 if (MDOC_BODY
!= node
->type
)
1185 if ( ! (p
->flags
& TERMP_LITERAL
))
1188 p
->flags
&= ~TERMP_LITERAL
;
1189 p
->offset
= pair
->offset
;
1195 termp_qq_pre(DECL_ARGS
)
1198 if (MDOC_BODY
!= node
->type
)
1201 p
->flags
|= TERMP_NOSPACE
;
1208 termp_qq_post(DECL_ARGS
)
1211 if (MDOC_BODY
!= node
->type
)
1213 p
->flags
|= TERMP_NOSPACE
;
1220 termp_bsx_pre(DECL_ARGS
)
1223 word(p
, "BSDI BSD/OS");
1230 termp_bx_post(DECL_ARGS
)
1234 p
->flags
|= TERMP_NOSPACE
;
1241 termp_ox_pre(DECL_ARGS
)
1251 termp_ux_pre(DECL_ARGS
)
1261 termp_fx_pre(DECL_ARGS
)
1271 termp_nx_pre(DECL_ARGS
)
1281 termp_sq_pre(DECL_ARGS
)
1284 if (MDOC_BODY
!= node
->type
)
1287 p
->flags
|= TERMP_NOSPACE
;
1294 termp_sq_post(DECL_ARGS
)
1297 if (MDOC_BODY
!= node
->type
)
1299 p
->flags
|= TERMP_NOSPACE
;
1306 termp_pf_pre(DECL_ARGS
)
1309 p
->flags
|= TERMP_IGNDELIM
;
1316 termp_pf_post(DECL_ARGS
)
1319 p
->flags
&= ~TERMP_IGNDELIM
;
1320 p
->flags
|= TERMP_NOSPACE
;
1326 termp_ss_pre(DECL_ARGS
)
1329 switch (node
->type
) {
1332 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1333 p
->offset
= INDENT
/ 2;
1345 termp_ss_post(DECL_ARGS
)
1348 switch (node
->type
) {
1361 termp_pa_pre(DECL_ARGS
)
1364 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1371 termp_em_pre(DECL_ARGS
)
1374 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1381 termp_cd_pre(DECL_ARGS
)
1384 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1392 termp_cm_pre(DECL_ARGS
)
1395 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1402 termp_ic_pre(DECL_ARGS
)
1405 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1412 termp_in_pre(DECL_ARGS
)
1415 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1416 word(p
, "#include");
1418 p
->flags
|= TERMP_NOSPACE
;
1425 termp_in_post(DECL_ARGS
)
1428 p
->flags
|= TERMP_NOSPACE
;
1432 if (SEC_SYNOPSIS
!= node
->sec
)
1434 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1441 termp_at_pre(DECL_ARGS
)
1447 assert(MDOC_TEXT
== node
->child
->type
);
1448 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1451 word(p
, mdoc_att2a(c
));
1458 termp_bq_pre(DECL_ARGS
)
1461 if (MDOC_BODY
!= node
->type
)
1464 p
->flags
|= TERMP_NOSPACE
;
1471 termp_bq_post(DECL_ARGS
)
1474 if (MDOC_BODY
!= node
->type
)
1482 termp_pq_pre(DECL_ARGS
)
1485 if (MDOC_BODY
!= node
->type
)
1488 p
->flags
|= TERMP_NOSPACE
;
1495 termp_pq_post(DECL_ARGS
)
1498 if (MDOC_BODY
!= node
->type
)
1506 termp_fo_pre(DECL_ARGS
)
1508 const struct mdoc_node
*n
;
1510 if (MDOC_BODY
== node
->type
) {
1512 p
->flags
|= TERMP_NOSPACE
;
1514 } else if (MDOC_HEAD
!= node
->type
)
1517 /* XXX - groff shows only first parameter */
1519 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1520 for (n
= node
->child
; n
; n
= n
->next
) {
1521 assert(MDOC_TEXT
== n
->type
);
1522 word(p
, n
->data
.text
.string
);
1524 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1532 termp_fo_post(DECL_ARGS
)
1535 if (MDOC_BODY
!= node
->type
)
1545 termp_bf_pre(DECL_ARGS
)
1547 const struct mdoc_node
*n
;
1548 const struct mdoc_block
*b
;
1550 /* XXX - we skip over possible trailing HEAD tokens. */
1552 if (MDOC_HEAD
== node
->type
)
1554 else if (MDOC_BLOCK
!= node
->type
)
1557 b
= &node
->data
.block
;
1559 if (NULL
== (n
= b
->head
->child
)) {
1560 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1561 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1562 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1563 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1568 assert(MDOC_TEXT
== n
->type
);
1570 if (0 == strcmp("Em", n
->data
.text
.string
))
1571 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1572 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1573 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1581 termp_sy_pre(DECL_ARGS
)
1584 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1591 termp_ms_pre(DECL_ARGS
)
1594 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1602 termp_sm_pre(DECL_ARGS
)
1606 assert(node
->child
);
1607 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1608 p
->flags
&= ~TERMP_NONOSPACE
;
1609 p
->flags
&= ~TERMP_NOSPACE
;
1611 p
->flags
|= TERMP_NONOSPACE
;
1612 p
->flags
|= TERMP_NOSPACE
;
1622 termp__t_pre(DECL_ARGS
)
1626 p
->flags
|= TERMP_NOSPACE
;
1633 termp__t_post(DECL_ARGS
)
1636 p
->flags
|= TERMP_NOSPACE
;
1638 word(p
, node
->next
? "," : ".");
1644 termp____post(DECL_ARGS
)
1647 p
->flags
|= TERMP_NOSPACE
;
1648 word(p
, node
->next
? "," : ".");