]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
76fced1e2553f8d0ae6afc9c7f63479521435b9b
1 /* $Id: term.c,v 1.41 2009/03/04 14:41:40 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
*);
92 static int arg_listtype(const struct mdoc_node
*);
95 * What follows describes prefix and postfix operations for the abstract
96 * syntax tree descent.
101 struct termpair *pair, \
102 const struct mdoc_meta *meta, \
103 const struct mdoc_node *node
105 #define DECL_PRE(name) \
106 static int name##_pre(DECL_ARGS)
107 #define DECL_POST(name) \
108 static void name##_post(DECL_ARGS)
109 #define DECL_PREPOST(name) \
113 DECL_PREPOST(termp__t
);
114 DECL_PREPOST(termp_aq
);
115 DECL_PREPOST(termp_bd
);
116 DECL_PREPOST(termp_bq
);
117 DECL_PREPOST(termp_d1
);
118 DECL_PREPOST(termp_dq
);
119 DECL_PREPOST(termp_fd
);
120 DECL_PREPOST(termp_fn
);
121 DECL_PREPOST(termp_fo
);
122 DECL_PREPOST(termp_ft
);
123 DECL_PREPOST(termp_in
);
124 DECL_PREPOST(termp_it
);
125 DECL_PREPOST(termp_op
);
126 DECL_PREPOST(termp_pf
);
127 DECL_PREPOST(termp_pq
);
128 DECL_PREPOST(termp_qq
);
129 DECL_PREPOST(termp_sh
);
130 DECL_PREPOST(termp_ss
);
131 DECL_PREPOST(termp_sq
);
132 DECL_PREPOST(termp_vt
);
170 const struct termact __termacts
[MDOC_MAX
] = {
171 { NULL
, NULL
}, /* \" */
172 { NULL
, NULL
}, /* Dd */
173 { NULL
, NULL
}, /* Dt */
174 { NULL
, NULL
}, /* Os */
175 { termp_sh_pre
, termp_sh_post
}, /* Sh */
176 { termp_ss_pre
, termp_ss_post
}, /* Ss */
177 { termp_pp_pre
, NULL
}, /* Pp */
178 { termp_d1_pre
, termp_d1_post
}, /* D1 */
179 { termp_d1_pre
, termp_d1_post
}, /* Dl */
180 { termp_bd_pre
, termp_bd_post
}, /* Bd */
181 { NULL
, NULL
}, /* Ed */
182 { NULL
, termp_bl_post
}, /* Bl */
183 { NULL
, NULL
}, /* El */
184 { termp_it_pre
, termp_it_post
}, /* It */
185 { NULL
, NULL
}, /* Ad */
186 { NULL
, NULL
}, /* An */
187 { termp_ar_pre
, NULL
}, /* Ar */
188 { termp_cd_pre
, NULL
}, /* Cd */
189 { termp_cm_pre
, NULL
}, /* Cm */
190 { NULL
, NULL
}, /* Dv */
191 { NULL
, NULL
}, /* Er */
192 { NULL
, NULL
}, /* Ev */
193 { termp_ex_pre
, NULL
}, /* Ex */
194 { termp_fa_pre
, NULL
}, /* Fa */
195 { termp_fd_pre
, termp_fd_post
}, /* Fd */
196 { termp_fl_pre
, NULL
}, /* Fl */
197 { termp_fn_pre
, termp_fn_post
}, /* Fn */
198 { termp_ft_pre
, termp_ft_post
}, /* Ft */
199 { termp_ic_pre
, NULL
}, /* Ic */
200 { termp_in_pre
, termp_in_post
}, /* In */
201 { NULL
, NULL
}, /* Li */
202 { termp_nd_pre
, NULL
}, /* Nd */
203 { termp_nm_pre
, NULL
}, /* Nm */
204 { termp_op_pre
, termp_op_post
}, /* Op */
205 { NULL
, NULL
}, /* Ot */
206 { termp_pa_pre
, NULL
}, /* Pa */
207 { termp_rv_pre
, NULL
}, /* Rv */
208 { termp_st_pre
, NULL
}, /* St */
209 { termp_va_pre
, NULL
}, /* Va */
210 { termp_vt_pre
, termp_vt_post
}, /* Vt */
211 { termp_xr_pre
, NULL
}, /* Xr */
212 { NULL
, termp____post
}, /* %A */
213 { NULL
, termp____post
}, /* %B */
214 { NULL
, termp____post
}, /* %D */
215 { NULL
, termp____post
}, /* %I */
216 { NULL
, termp____post
}, /* %J */
217 { NULL
, termp____post
}, /* %N */
218 { NULL
, termp____post
}, /* %O */
219 { NULL
, termp____post
}, /* %P */
220 { NULL
, termp____post
}, /* %R */
221 { termp__t_pre
, termp__t_post
}, /* %T */
222 { NULL
, termp____post
}, /* %V */
223 { NULL
, NULL
}, /* Ac */
224 { termp_aq_pre
, termp_aq_post
}, /* Ao */
225 { termp_aq_pre
, termp_aq_post
}, /* Aq */
226 { termp_at_pre
, NULL
}, /* At */
227 { NULL
, NULL
}, /* Bc */
228 { termp_bf_pre
, NULL
}, /* Bf */
229 { termp_bq_pre
, termp_bq_post
}, /* Bo */
230 { termp_bq_pre
, termp_bq_post
}, /* Bq */
231 { termp_bsx_pre
, NULL
}, /* Bsx */
232 { NULL
, termp_bx_post
}, /* Bx */
233 { NULL
, NULL
}, /* Db */
234 { NULL
, NULL
}, /* Dc */
235 { termp_dq_pre
, termp_dq_post
}, /* Do */
236 { termp_dq_pre
, termp_dq_post
}, /* Dq */
237 { NULL
, NULL
}, /* Ec */
238 { NULL
, NULL
}, /* Ef */
239 { termp_em_pre
, NULL
}, /* Em */
240 { NULL
, NULL
}, /* Eo */
241 { termp_fx_pre
, NULL
}, /* Fx */
242 { termp_ms_pre
, NULL
}, /* Ms */
243 { NULL
, NULL
}, /* No */
244 { termp_ns_pre
, NULL
}, /* Ns */
245 { termp_nx_pre
, NULL
}, /* Nx */
246 { termp_ox_pre
, NULL
}, /* Ox */
247 { NULL
, NULL
}, /* Pc */
248 { termp_pf_pre
, termp_pf_post
}, /* Pf */
249 { termp_pq_pre
, termp_pq_post
}, /* Po */
250 { termp_pq_pre
, termp_pq_post
}, /* Pq */
251 { NULL
, NULL
}, /* Qc */
252 { termp_sq_pre
, termp_sq_post
}, /* Ql */
253 { termp_qq_pre
, termp_qq_post
}, /* Qo */
254 { termp_qq_pre
, termp_qq_post
}, /* Qq */
255 { NULL
, NULL
}, /* Re */
256 { termp_rs_pre
, NULL
}, /* Rs */
257 { NULL
, NULL
}, /* Sc */
258 { termp_sq_pre
, termp_sq_post
}, /* So */
259 { termp_sq_pre
, termp_sq_post
}, /* Sq */
260 { termp_sm_pre
, NULL
}, /* Sm */
261 { termp_sx_pre
, NULL
}, /* Sx */
262 { termp_sy_pre
, NULL
}, /* Sy */
263 { NULL
, NULL
}, /* Tn */
264 { termp_ux_pre
, NULL
}, /* Ux */
265 { NULL
, NULL
}, /* Xc */
266 { NULL
, NULL
}, /* Xo */
267 { termp_fo_pre
, termp_fo_post
}, /* Fo */
268 { NULL
, NULL
}, /* Fc */
269 { termp_op_pre
, termp_op_post
}, /* Oo */
270 { NULL
, NULL
}, /* Oc */
271 { NULL
, NULL
}, /* Bk */
272 { NULL
, NULL
}, /* Ek */
273 { termp_bt_pre
, NULL
}, /* Bt */
274 { NULL
, NULL
}, /* Hf */
275 { NULL
, NULL
}, /* Fr */
276 { termp_ud_pre
, NULL
}, /* Ud */
279 const struct termact
*termacts
= __termacts
;
283 arg_width(const struct mdoc_arg
*arg
)
289 if (0 == strcmp(*arg
->value
, "indent"))
291 if (0 == strcmp(*arg
->value
, "indent-two"))
294 len
= (int)strlen(*arg
->value
);
297 for (i
= 0; i
< len
- 1; i
++)
298 if ( ! isdigit((int)(*arg
->value
)[i
]))
302 if ('n' == (*arg
->value
)[len
- 1]) {
303 v
= (size_t)atoi(*arg
->value
);
308 return(strlen(*arg
->value
) + 1);
313 arg_listtype(const struct mdoc_node
*n
)
315 const struct mdoc_block
*bl
;
321 for (i
= 0; i
< len
; i
++)
322 switch (bl
->argv
[i
].arg
) {
340 return(bl
->argv
[i
].arg
);
345 errx(1, "list type not supported");
351 arg_offset(const struct mdoc_arg
*arg
)
356 if (0 == strcmp(*arg
->value
, "indent"))
358 if (0 == strcmp(*arg
->value
, "indent-two"))
360 return(strlen(*arg
->value
));
365 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
368 return(-1 != arg_getattr(arg
, argc
, argv
));
373 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
377 for (i
= 0; i
< (int)argc
; i
++)
378 if (argv
[i
].arg
== arg
)
386 termp_dq_pre(DECL_ARGS
)
389 if (MDOC_BODY
!= node
->type
)
393 p
->flags
|= TERMP_NOSPACE
;
400 termp_dq_post(DECL_ARGS
)
403 if (MDOC_BODY
!= node
->type
)
406 p
->flags
|= TERMP_NOSPACE
;
413 termp_it_pre_block(DECL_ARGS
)
415 const struct mdoc_node
*n
;
416 const struct mdoc_block
*bl
;
418 n
= node
->parent
->parent
;
422 if ( ! arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
423 if (node
->prev
|| n
->prev
)
432 termp_it_pre(DECL_ARGS
)
434 const struct mdoc_block
*bl
;
437 size_t width
, offset
;
439 if (MDOC_BLOCK
== node
->type
)
440 return(termp_it_pre_block(p
, pair
, meta
, node
));
442 /* Get ptr to list block, type, etc. */
444 bl
= &node
->parent
->parent
->parent
->data
.block
;
445 type
= arg_listtype(node
->parent
->parent
->parent
);
447 /* Save parent attributes. */
449 pair
->offset
= p
->offset
;
450 pair
->rmargin
= p
->rmargin
;
451 pair
->flag
= p
->flags
;
453 /* Get list width and offset. */
455 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
456 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
458 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
459 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
462 * List-type can override the width in the case of fixed-head
463 * values (bullet, dash/hyphen, enum). Tags need a non-zero
475 width
= width
> 4 ? width
: 4;
480 errx(1, "need non-zero %s for list type",
481 mdoc_argnames
[MDOC_Width
]);
487 * Whitespace control. Inset bodies need an initial space.
494 if (MDOC_BODY
== node
->type
)
495 p
->flags
&= ~TERMP_NOSPACE
;
497 p
->flags
|= TERMP_NOSPACE
;
500 p
->flags
|= TERMP_NOSPACE
;
505 * Style flags. Diagnostic heads need TTYPE_DIAG.
510 if (MDOC_HEAD
== node
->type
)
511 p
->flags
|= ttypes
[TTYPE_DIAG
];
518 * Pad and break control. This is the tricker part. Lists with
519 * set right-margins for the head get TERMP_NOBREAK because, if
520 * they overrun the margin, they wrap to the new margin.
521 * Correspondingly, the body for these types don't left-pad, as
522 * the head will pad out to to the right.
535 if (MDOC_HEAD
== node
->type
)
536 p
->flags
|= TERMP_NOBREAK
;
538 p
->flags
|= TERMP_NOLPAD
;
539 if (MDOC_HEAD
== node
->type
&& MDOC_Tag
== type
)
540 if (NULL
== node
->next
||
541 NULL
== node
->next
->child
)
542 p
->flags
|= TERMP_NONOBREAK
;
545 if (MDOC_HEAD
== node
->type
)
546 p
->flags
|= TERMP_NOBREAK
;
553 * Margin control. Set-head-width lists have their right
554 * margins shortened. The body for these lists has the offset
555 * necessarily lengthened. Everybody gets the offset.
570 if (MDOC_HEAD
== node
->type
)
571 p
->rmargin
= p
->offset
+ width
;
580 * The dash, hyphen, bullet and enum lists all have a special
581 * HEAD character. Print it now.
584 if (MDOC_HEAD
== node
->type
)
595 /* TODO: have a wordfmt or something. */
596 (pair
->ppair
->ppair
->count
)++;
597 (void)snprintf(buf
, sizeof(buf
), "%d.",
598 pair
->ppair
->ppair
->count
);
606 * If we're not going to process our header children, indicate
610 if (MDOC_HEAD
== node
->type
)
632 termp_it_post(DECL_ARGS
)
636 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
639 type
= arg_listtype(node
->parent
->parent
->parent
);
647 if (MDOC_BODY
!= node
->type
)
656 p
->offset
= pair
->offset
;
657 p
->rmargin
= pair
->rmargin
;
658 p
->flags
= pair
->flag
;
664 termp_nm_pre(DECL_ARGS
)
667 if (SEC_SYNOPSIS
== node
->sec
)
670 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
671 if (NULL
== node
->child
)
680 termp_fl_pre(DECL_ARGS
)
683 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
685 p
->flags
|= TERMP_NOSPACE
;
692 termp_ar_pre(DECL_ARGS
)
695 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
696 if (NULL
== node
->child
) {
706 termp_ns_pre(DECL_ARGS
)
709 p
->flags
|= TERMP_NOSPACE
;
716 termp_pp_pre(DECL_ARGS
)
726 termp_st_pre(DECL_ARGS
)
730 assert(1 == node
->data
.elem
.argc
);
732 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
741 termp_rs_pre(DECL_ARGS
)
744 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
752 termp_rv_pre(DECL_ARGS
)
756 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
757 node
->data
.elem
.argv
);
763 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
764 word(p
, *node
->data
.elem
.argv
[i
].value
);
765 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
767 word(p
, "() function returns the value 0 if successful;");
768 word(p
, "otherwise the value -1 is returned and the");
769 word(p
, "global variable");
771 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
773 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
775 word(p
, "is set to indicate the error.");
783 termp_ex_pre(DECL_ARGS
)
787 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
788 node
->data
.elem
.argv
);
792 p
->flags
|= ttypes
[TTYPE_PROG
];
793 word(p
, *node
->data
.elem
.argv
[i
].value
);
794 p
->flags
&= ~ttypes
[TTYPE_PROG
];
795 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
803 termp_nd_pre(DECL_ARGS
)
813 termp_bl_post(DECL_ARGS
)
816 if (MDOC_BLOCK
== node
->type
)
823 termp_op_post(DECL_ARGS
)
826 if (MDOC_BODY
!= node
->type
)
828 p
->flags
|= TERMP_NOSPACE
;
835 termp_xr_pre(DECL_ARGS
)
837 const struct mdoc_node
*n
;
842 assert(MDOC_TEXT
== n
->type
);
843 word(p
, n
->data
.text
.string
);
845 if (NULL
== (n
= n
->next
))
848 assert(MDOC_TEXT
== n
->type
);
849 p
->flags
|= TERMP_NOSPACE
;
851 p
->flags
|= TERMP_NOSPACE
;
852 word(p
, n
->data
.text
.string
);
853 p
->flags
|= TERMP_NOSPACE
;
862 termp_vt_pre(DECL_ARGS
)
865 /* FIXME: this can be "type name". */
866 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
873 termp_vt_post(DECL_ARGS
)
876 if (node
->sec
== SEC_SYNOPSIS
)
883 termp_fd_pre(DECL_ARGS
)
887 * FIXME: this naming is bad. This value is used, in general,
888 * for the #include header or other preprocessor statement.
890 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
897 termp_fd_post(DECL_ARGS
)
900 if (node
->sec
!= SEC_SYNOPSIS
)
903 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
910 termp_sh_pre(DECL_ARGS
)
913 switch (node
->type
) {
916 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
930 termp_sh_post(DECL_ARGS
)
933 switch (node
->type
) {
949 termp_op_pre(DECL_ARGS
)
952 switch (node
->type
) {
955 p
->flags
|= TERMP_NOSPACE
;
966 termp_bt_pre(DECL_ARGS
)
969 word(p
, "is currently in beta test.");
976 termp_ud_pre(DECL_ARGS
)
979 word(p
, "currently under development.");
986 termp_d1_pre(DECL_ARGS
)
989 if (MDOC_BODY
!= node
->type
)
992 p
->offset
+= (pair
->offset
= INDENT
);
999 termp_d1_post(DECL_ARGS
)
1002 if (MDOC_BODY
!= node
->type
)
1005 p
->offset
-= pair
->offset
;
1011 termp_aq_pre(DECL_ARGS
)
1014 if (MDOC_BODY
!= node
->type
)
1017 p
->flags
|= TERMP_NOSPACE
;
1024 termp_aq_post(DECL_ARGS
)
1027 if (MDOC_BODY
!= node
->type
)
1029 p
->flags
|= TERMP_NOSPACE
;
1036 termp_ft_pre(DECL_ARGS
)
1039 if (SEC_SYNOPSIS
== node
->sec
)
1040 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1042 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1049 termp_ft_post(DECL_ARGS
)
1052 if (SEC_SYNOPSIS
== node
->sec
)
1059 termp_fn_pre(DECL_ARGS
)
1061 const struct mdoc_node
*n
;
1063 assert(node
->child
);
1064 assert(MDOC_TEXT
== node
->child
->type
);
1066 /* FIXME: can be "type funcname" "type varname"... */
1068 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1069 word(p
, node
->child
->data
.text
.string
);
1070 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1074 p
->flags
|= TERMP_NOSPACE
;
1075 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1076 assert(MDOC_TEXT
== n
->type
);
1077 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1078 word(p
, n
->data
.text
.string
);
1079 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1086 if (SEC_SYNOPSIS
== node
->sec
)
1095 termp_fn_post(DECL_ARGS
)
1098 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1106 termp_sx_pre(DECL_ARGS
)
1109 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1116 termp_fa_pre(DECL_ARGS
)
1118 struct mdoc_node
*n
;
1120 if (node
->parent
->tok
!= MDOC_Fo
) {
1121 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1125 for (n
= node
->child
; n
; n
= n
->next
) {
1126 assert(MDOC_TEXT
== n
->type
);
1128 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1129 word(p
, n
->data
.text
.string
);
1130 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1136 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1145 termp_va_pre(DECL_ARGS
)
1148 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1155 termp_bd_pre(DECL_ARGS
)
1157 const struct mdoc_block
*bl
;
1158 const struct mdoc_node
*n
;
1161 if (MDOC_BLOCK
== node
->type
) {
1165 } else if (MDOC_BODY
!= node
->type
)
1168 pair
->offset
= p
->offset
;
1169 bl
= &node
->parent
->data
.block
;
1171 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++) {
1172 switch (bl
->argv
[i
].arg
) {
1177 case (MDOC_Unfilled
):
1179 case (MDOC_Literal
):
1180 type
= bl
->argv
[i
].arg
;
1184 errx(1, "display type not supported");
1190 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1192 assert(1 == bl
->argv
[i
].sz
);
1193 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1198 case (MDOC_Literal
):
1200 case (MDOC_Unfilled
):
1206 p
->flags
|= TERMP_LITERAL
;
1208 for (n
= node
->child
; n
; n
= n
->next
) {
1209 if (MDOC_TEXT
!= n
->type
) {
1210 warnx("non-text children not yet allowed");
1213 word(p
, n
->data
.text
.string
);
1223 termp_bd_post(DECL_ARGS
)
1226 if (MDOC_BODY
!= node
->type
)
1229 if ( ! (p
->flags
& TERMP_LITERAL
))
1232 p
->flags
&= ~TERMP_LITERAL
;
1233 p
->offset
= pair
->offset
;
1239 termp_qq_pre(DECL_ARGS
)
1242 if (MDOC_BODY
!= node
->type
)
1245 p
->flags
|= TERMP_NOSPACE
;
1252 termp_qq_post(DECL_ARGS
)
1255 if (MDOC_BODY
!= node
->type
)
1257 p
->flags
|= TERMP_NOSPACE
;
1264 termp_bsx_pre(DECL_ARGS
)
1267 word(p
, "BSDI BSD/OS");
1274 termp_bx_post(DECL_ARGS
)
1278 p
->flags
|= TERMP_NOSPACE
;
1285 termp_ox_pre(DECL_ARGS
)
1295 termp_ux_pre(DECL_ARGS
)
1305 termp_fx_pre(DECL_ARGS
)
1315 termp_nx_pre(DECL_ARGS
)
1325 termp_sq_pre(DECL_ARGS
)
1328 if (MDOC_BODY
!= node
->type
)
1331 p
->flags
|= TERMP_NOSPACE
;
1338 termp_sq_post(DECL_ARGS
)
1341 if (MDOC_BODY
!= node
->type
)
1343 p
->flags
|= TERMP_NOSPACE
;
1350 termp_pf_pre(DECL_ARGS
)
1353 p
->flags
|= TERMP_IGNDELIM
;
1360 termp_pf_post(DECL_ARGS
)
1363 p
->flags
&= ~TERMP_IGNDELIM
;
1364 p
->flags
|= TERMP_NOSPACE
;
1370 termp_ss_pre(DECL_ARGS
)
1373 switch (node
->type
) {
1376 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1377 p
->offset
= INDENT
/ 2;
1389 termp_ss_post(DECL_ARGS
)
1392 switch (node
->type
) {
1405 termp_pa_pre(DECL_ARGS
)
1408 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1415 termp_em_pre(DECL_ARGS
)
1418 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1425 termp_cd_pre(DECL_ARGS
)
1428 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1436 termp_cm_pre(DECL_ARGS
)
1439 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1446 termp_ic_pre(DECL_ARGS
)
1449 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1456 termp_in_pre(DECL_ARGS
)
1459 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1460 word(p
, "#include");
1462 p
->flags
|= TERMP_NOSPACE
;
1469 termp_in_post(DECL_ARGS
)
1472 p
->flags
|= TERMP_NOSPACE
;
1476 if (SEC_SYNOPSIS
!= node
->sec
)
1478 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1485 termp_at_pre(DECL_ARGS
)
1491 assert(MDOC_TEXT
== node
->child
->type
);
1492 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1495 word(p
, mdoc_att2a(c
));
1502 termp_bq_pre(DECL_ARGS
)
1505 if (MDOC_BODY
!= node
->type
)
1508 p
->flags
|= TERMP_NOSPACE
;
1515 termp_bq_post(DECL_ARGS
)
1518 if (MDOC_BODY
!= node
->type
)
1526 termp_pq_pre(DECL_ARGS
)
1529 if (MDOC_BODY
!= node
->type
)
1532 p
->flags
|= TERMP_NOSPACE
;
1539 termp_pq_post(DECL_ARGS
)
1542 if (MDOC_BODY
!= node
->type
)
1550 termp_fo_pre(DECL_ARGS
)
1552 const struct mdoc_node
*n
;
1554 if (MDOC_BODY
== node
->type
) {
1556 p
->flags
|= TERMP_NOSPACE
;
1558 } else if (MDOC_HEAD
!= node
->type
)
1561 /* XXX - groff shows only first parameter */
1563 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1564 for (n
= node
->child
; n
; n
= n
->next
) {
1565 assert(MDOC_TEXT
== n
->type
);
1566 word(p
, n
->data
.text
.string
);
1568 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1576 termp_fo_post(DECL_ARGS
)
1579 if (MDOC_BODY
!= node
->type
)
1589 termp_bf_pre(DECL_ARGS
)
1591 const struct mdoc_node
*n
;
1592 const struct mdoc_block
*b
;
1594 /* XXX - we skip over possible trailing HEAD tokens. */
1596 if (MDOC_HEAD
== node
->type
)
1598 else if (MDOC_BLOCK
!= node
->type
)
1601 b
= &node
->data
.block
;
1603 if (NULL
== (n
= b
->head
->child
)) {
1604 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1605 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1606 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1607 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1612 assert(MDOC_TEXT
== n
->type
);
1614 if (0 == strcmp("Em", n
->data
.text
.string
))
1615 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1616 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1617 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1625 termp_sy_pre(DECL_ARGS
)
1628 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1635 termp_ms_pre(DECL_ARGS
)
1638 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1646 termp_sm_pre(DECL_ARGS
)
1650 assert(node
->child
);
1651 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1652 p
->flags
&= ~TERMP_NONOSPACE
;
1653 p
->flags
&= ~TERMP_NOSPACE
;
1655 p
->flags
|= TERMP_NONOSPACE
;
1656 p
->flags
|= TERMP_NOSPACE
;
1666 termp__t_pre(DECL_ARGS
)
1669 /* FIXME: titles are underlined. */
1671 p
->flags
|= TERMP_NOSPACE
;
1678 termp__t_post(DECL_ARGS
)
1681 p
->flags
|= TERMP_NOSPACE
;
1682 /* FIXME: titles are underlined. */
1684 word(p
, node
->next
? "," : ".");
1690 termp____post(DECL_ARGS
)
1693 p
->flags
|= TERMP_NOSPACE
;
1694 word(p
, node
->next
? "," : ".");