]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.43 2009/03/06 14:13:47 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
);
171 const struct termact __termacts
[MDOC_MAX
] = {
172 { NULL
, NULL
}, /* \" */
173 { NULL
, NULL
}, /* Dd */
174 { NULL
, NULL
}, /* Dt */
175 { NULL
, NULL
}, /* Os */
176 { termp_sh_pre
, termp_sh_post
}, /* Sh */
177 { termp_ss_pre
, termp_ss_post
}, /* Ss */
178 { termp_pp_pre
, NULL
}, /* Pp */
179 { termp_d1_pre
, termp_d1_post
}, /* D1 */
180 { termp_d1_pre
, termp_d1_post
}, /* Dl */
181 { termp_bd_pre
, termp_bd_post
}, /* Bd */
182 { NULL
, NULL
}, /* Ed */
183 { NULL
, termp_bl_post
}, /* Bl */
184 { NULL
, NULL
}, /* El */
185 { termp_it_pre
, termp_it_post
}, /* It */
186 { NULL
, NULL
}, /* Ad */
187 { NULL
, NULL
}, /* An */
188 { termp_ar_pre
, NULL
}, /* Ar */
189 { termp_cd_pre
, NULL
}, /* Cd */
190 { termp_cm_pre
, NULL
}, /* Cm */
191 { NULL
, NULL
}, /* Dv */
192 { NULL
, NULL
}, /* Er */
193 { NULL
, NULL
}, /* Ev */
194 { termp_ex_pre
, NULL
}, /* Ex */
195 { termp_fa_pre
, NULL
}, /* Fa */
196 { termp_fd_pre
, termp_fd_post
}, /* Fd */
197 { termp_fl_pre
, NULL
}, /* Fl */
198 { termp_fn_pre
, termp_fn_post
}, /* Fn */
199 { termp_ft_pre
, termp_ft_post
}, /* Ft */
200 { termp_ic_pre
, NULL
}, /* Ic */
201 { termp_in_pre
, termp_in_post
}, /* In */
202 { NULL
, NULL
}, /* Li */
203 { termp_nd_pre
, NULL
}, /* Nd */
204 { termp_nm_pre
, NULL
}, /* Nm */
205 { termp_op_pre
, termp_op_post
}, /* Op */
206 { NULL
, NULL
}, /* Ot */
207 { termp_pa_pre
, NULL
}, /* Pa */
208 { termp_rv_pre
, NULL
}, /* Rv */
209 { termp_st_pre
, NULL
}, /* St */
210 { termp_va_pre
, NULL
}, /* Va */
211 { termp_vt_pre
, termp_vt_post
}, /* Vt */
212 { termp_xr_pre
, NULL
}, /* Xr */
213 { NULL
, termp____post
}, /* %A */
214 { NULL
, termp____post
}, /* %B */
215 { NULL
, termp____post
}, /* %D */
216 { NULL
, termp____post
}, /* %I */
217 { NULL
, termp____post
}, /* %J */
218 { NULL
, termp____post
}, /* %N */
219 { NULL
, termp____post
}, /* %O */
220 { NULL
, termp____post
}, /* %P */
221 { NULL
, termp____post
}, /* %R */
222 { termp__t_pre
, termp__t_post
}, /* %T */
223 { NULL
, termp____post
}, /* %V */
224 { NULL
, NULL
}, /* Ac */
225 { termp_aq_pre
, termp_aq_post
}, /* Ao */
226 { termp_aq_pre
, termp_aq_post
}, /* Aq */
227 { termp_at_pre
, NULL
}, /* At */
228 { NULL
, NULL
}, /* Bc */
229 { termp_bf_pre
, NULL
}, /* Bf */
230 { termp_bq_pre
, termp_bq_post
}, /* Bo */
231 { termp_bq_pre
, termp_bq_post
}, /* Bq */
232 { termp_bsx_pre
, NULL
}, /* Bsx */
233 { NULL
, termp_bx_post
}, /* Bx */
234 { NULL
, NULL
}, /* Db */
235 { NULL
, NULL
}, /* Dc */
236 { termp_dq_pre
, termp_dq_post
}, /* Do */
237 { termp_dq_pre
, termp_dq_post
}, /* Dq */
238 { NULL
, NULL
}, /* Ec */
239 { NULL
, NULL
}, /* Ef */
240 { termp_em_pre
, NULL
}, /* Em */
241 { NULL
, NULL
}, /* Eo */
242 { termp_fx_pre
, NULL
}, /* Fx */
243 { termp_ms_pre
, NULL
}, /* Ms */
244 { NULL
, NULL
}, /* No */
245 { termp_ns_pre
, NULL
}, /* Ns */
246 { termp_nx_pre
, NULL
}, /* Nx */
247 { termp_ox_pre
, NULL
}, /* Ox */
248 { NULL
, NULL
}, /* Pc */
249 { termp_pf_pre
, termp_pf_post
}, /* Pf */
250 { termp_pq_pre
, termp_pq_post
}, /* Po */
251 { termp_pq_pre
, termp_pq_post
}, /* Pq */
252 { NULL
, NULL
}, /* Qc */
253 { termp_sq_pre
, termp_sq_post
}, /* Ql */
254 { termp_qq_pre
, termp_qq_post
}, /* Qo */
255 { termp_qq_pre
, termp_qq_post
}, /* Qq */
256 { NULL
, NULL
}, /* Re */
257 { termp_rs_pre
, NULL
}, /* Rs */
258 { NULL
, NULL
}, /* Sc */
259 { termp_sq_pre
, termp_sq_post
}, /* So */
260 { termp_sq_pre
, termp_sq_post
}, /* Sq */
261 { termp_sm_pre
, NULL
}, /* Sm */
262 { termp_sx_pre
, NULL
}, /* Sx */
263 { termp_sy_pre
, NULL
}, /* Sy */
264 { NULL
, NULL
}, /* Tn */
265 { termp_ux_pre
, NULL
}, /* Ux */
266 { NULL
, NULL
}, /* Xc */
267 { NULL
, NULL
}, /* Xo */
268 { termp_fo_pre
, termp_fo_post
}, /* Fo */
269 { NULL
, NULL
}, /* Fc */
270 { termp_op_pre
, termp_op_post
}, /* Oo */
271 { NULL
, NULL
}, /* Oc */
272 { NULL
, NULL
}, /* Bk */
273 { NULL
, NULL
}, /* Ek */
274 { termp_bt_pre
, NULL
}, /* Bt */
275 { NULL
, NULL
}, /* Hf */
276 { NULL
, NULL
}, /* Fr */
277 { termp_ud_pre
, NULL
}, /* Ud */
278 { NULL
, termp_lb_post
}, /* lb */
281 const struct termact
*termacts
= __termacts
;
285 arg_width(const struct mdoc_arg
*arg
)
291 if (0 == strcmp(*arg
->value
, "indent"))
293 if (0 == strcmp(*arg
->value
, "indent-two"))
296 len
= (int)strlen(*arg
->value
);
299 for (i
= 0; i
< len
- 1; i
++)
300 if ( ! isdigit((u_char
)(*arg
->value
)[i
]))
304 if ('n' == (*arg
->value
)[len
- 1]) {
305 v
= (size_t)atoi(*arg
->value
);
310 return(strlen(*arg
->value
) + 1);
315 arg_listtype(const struct mdoc_node
*n
)
317 const struct mdoc_block
*bl
;
323 for (i
= 0; i
< len
; i
++)
324 switch (bl
->argv
[i
].arg
) {
342 return(bl
->argv
[i
].arg
);
347 errx(1, "list type not supported");
353 arg_offset(const struct mdoc_arg
*arg
)
358 if (0 == strcmp(*arg
->value
, "indent"))
360 if (0 == strcmp(*arg
->value
, "indent-two"))
362 return(strlen(*arg
->value
));
367 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
370 return(-1 != arg_getattr(arg
, argc
, argv
));
375 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
379 for (i
= 0; i
< (int)argc
; i
++)
380 if (argv
[i
].arg
== arg
)
388 termp_dq_pre(DECL_ARGS
)
391 if (MDOC_BODY
!= node
->type
)
395 p
->flags
|= TERMP_NOSPACE
;
402 termp_dq_post(DECL_ARGS
)
405 if (MDOC_BODY
!= node
->type
)
408 p
->flags
|= TERMP_NOSPACE
;
415 termp_it_pre_block(DECL_ARGS
)
417 const struct mdoc_node
*n
;
418 const struct mdoc_block
*bl
;
420 n
= node
->parent
->parent
;
424 if ( ! arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
425 if (node
->prev
|| n
->prev
)
434 termp_it_pre(DECL_ARGS
)
436 const struct mdoc_block
*bl
;
439 size_t width
, offset
;
441 if (MDOC_BLOCK
== node
->type
)
442 return(termp_it_pre_block(p
, pair
, meta
, node
));
444 /* Get ptr to list block, type, etc. */
446 bl
= &node
->parent
->parent
->parent
->data
.block
;
447 type
= arg_listtype(node
->parent
->parent
->parent
);
449 /* Save parent attributes. */
451 pair
->offset
= p
->offset
;
452 pair
->rmargin
= p
->rmargin
;
453 pair
->flag
= p
->flags
;
455 /* Get list width and offset. */
457 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
458 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
460 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
461 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
464 * List-type can override the width in the case of fixed-head
465 * values (bullet, dash/hyphen, enum). Tags need a non-zero
477 width
= width
> 4 ? width
: 4;
482 errx(1, "need non-zero %s for list type",
483 mdoc_argnames
[MDOC_Width
]);
489 * Whitespace control. Inset bodies need an initial space.
496 if (MDOC_BODY
== node
->type
)
497 p
->flags
&= ~TERMP_NOSPACE
;
499 p
->flags
|= TERMP_NOSPACE
;
502 p
->flags
|= TERMP_NOSPACE
;
507 * Style flags. Diagnostic heads need TTYPE_DIAG.
512 if (MDOC_HEAD
== node
->type
)
513 p
->flags
|= ttypes
[TTYPE_DIAG
];
520 * Pad and break control. This is the tricker part. Lists with
521 * set right-margins for the head get TERMP_NOBREAK because, if
522 * they overrun the margin, they wrap to the new margin.
523 * Correspondingly, the body for these types don't left-pad, as
524 * the head will pad out to to the right.
537 if (MDOC_HEAD
== node
->type
)
538 p
->flags
|= TERMP_NOBREAK
;
540 p
->flags
|= TERMP_NOLPAD
;
541 if (MDOC_HEAD
== node
->type
&& MDOC_Tag
== type
)
542 if (NULL
== node
->next
||
543 NULL
== node
->next
->child
)
544 p
->flags
|= TERMP_NONOBREAK
;
547 if (MDOC_HEAD
== node
->type
)
548 p
->flags
|= TERMP_NOBREAK
;
555 * Margin control. Set-head-width lists have their right
556 * margins shortened. The body for these lists has the offset
557 * necessarily lengthened. Everybody gets the offset.
572 if (MDOC_HEAD
== node
->type
)
573 p
->rmargin
= p
->offset
+ width
;
582 * The dash, hyphen, bullet and enum lists all have a special
583 * HEAD character. Print it now.
586 if (MDOC_HEAD
== node
->type
)
597 /* TODO: have a wordfmt or something. */
598 (pair
->ppair
->ppair
->count
)++;
599 (void)snprintf(buf
, sizeof(buf
), "%d.",
600 pair
->ppair
->ppair
->count
);
608 * If we're not going to process our header children, indicate
612 if (MDOC_HEAD
== node
->type
)
634 termp_it_post(DECL_ARGS
)
638 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
641 type
= arg_listtype(node
->parent
->parent
->parent
);
649 if (MDOC_BODY
!= node
->type
)
658 p
->offset
= pair
->offset
;
659 p
->rmargin
= pair
->rmargin
;
660 p
->flags
= pair
->flag
;
666 termp_nm_pre(DECL_ARGS
)
669 if (SEC_SYNOPSIS
== node
->sec
)
672 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
673 if (NULL
== node
->child
)
682 termp_fl_pre(DECL_ARGS
)
685 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
687 p
->flags
|= TERMP_NOSPACE
;
694 termp_ar_pre(DECL_ARGS
)
697 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
704 termp_ns_pre(DECL_ARGS
)
707 p
->flags
|= TERMP_NOSPACE
;
714 termp_pp_pre(DECL_ARGS
)
724 termp_st_pre(DECL_ARGS
)
728 /* XXX - if child isn't text? */
730 if ((cp
= mdoc_a2st(node
->child
->data
.text
.string
)))
738 termp_rs_pre(DECL_ARGS
)
741 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
749 termp_rv_pre(DECL_ARGS
)
753 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
754 node
->data
.elem
.argv
);
760 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
761 word(p
, *node
->data
.elem
.argv
[i
].value
);
762 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
764 word(p
, "() function returns the value 0 if successful;");
765 word(p
, "otherwise the value -1 is returned and the");
766 word(p
, "global variable");
768 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
770 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
772 word(p
, "is set to indicate the error.");
780 termp_ex_pre(DECL_ARGS
)
784 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
785 node
->data
.elem
.argv
);
789 p
->flags
|= ttypes
[TTYPE_PROG
];
790 word(p
, *node
->data
.elem
.argv
[i
].value
);
791 p
->flags
&= ~ttypes
[TTYPE_PROG
];
792 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
800 termp_nd_pre(DECL_ARGS
)
810 termp_bl_post(DECL_ARGS
)
813 if (MDOC_BLOCK
== node
->type
)
820 termp_op_post(DECL_ARGS
)
823 if (MDOC_BODY
!= node
->type
)
825 p
->flags
|= TERMP_NOSPACE
;
832 termp_xr_pre(DECL_ARGS
)
834 const struct mdoc_node
*n
;
839 assert(MDOC_TEXT
== n
->type
);
840 word(p
, n
->data
.text
.string
);
842 if (NULL
== (n
= n
->next
))
845 assert(MDOC_TEXT
== n
->type
);
846 p
->flags
|= TERMP_NOSPACE
;
848 p
->flags
|= TERMP_NOSPACE
;
849 word(p
, n
->data
.text
.string
);
850 p
->flags
|= TERMP_NOSPACE
;
859 termp_vt_pre(DECL_ARGS
)
862 /* FIXME: this can be "type name". */
863 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
870 termp_vt_post(DECL_ARGS
)
873 if (node
->sec
== SEC_SYNOPSIS
)
880 termp_fd_pre(DECL_ARGS
)
884 * FIXME: this naming is bad. This value is used, in general,
885 * for the #include header or other preprocessor statement.
887 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
894 termp_fd_post(DECL_ARGS
)
897 if (node
->sec
!= SEC_SYNOPSIS
)
900 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
907 termp_sh_pre(DECL_ARGS
)
910 switch (node
->type
) {
913 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
927 termp_sh_post(DECL_ARGS
)
930 switch (node
->type
) {
946 termp_op_pre(DECL_ARGS
)
949 switch (node
->type
) {
952 p
->flags
|= TERMP_NOSPACE
;
963 termp_bt_pre(DECL_ARGS
)
966 word(p
, "is currently in beta test.");
973 termp_lb_post(DECL_ARGS
)
982 termp_ud_pre(DECL_ARGS
)
985 word(p
, "currently under development.");
992 termp_d1_pre(DECL_ARGS
)
995 if (MDOC_BODY
!= node
->type
)
998 p
->offset
+= (pair
->offset
= INDENT
);
1005 termp_d1_post(DECL_ARGS
)
1008 if (MDOC_BODY
!= node
->type
)
1011 p
->offset
-= pair
->offset
;
1017 termp_aq_pre(DECL_ARGS
)
1020 if (MDOC_BODY
!= node
->type
)
1023 p
->flags
|= TERMP_NOSPACE
;
1030 termp_aq_post(DECL_ARGS
)
1033 if (MDOC_BODY
!= node
->type
)
1035 p
->flags
|= TERMP_NOSPACE
;
1042 termp_ft_pre(DECL_ARGS
)
1045 if (SEC_SYNOPSIS
== node
->sec
)
1046 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1048 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1055 termp_ft_post(DECL_ARGS
)
1058 if (SEC_SYNOPSIS
== node
->sec
)
1065 termp_fn_pre(DECL_ARGS
)
1067 const struct mdoc_node
*n
;
1069 assert(node
->child
);
1070 assert(MDOC_TEXT
== node
->child
->type
);
1072 /* FIXME: can be "type funcname" "type varname"... */
1074 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1075 word(p
, node
->child
->data
.text
.string
);
1076 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1080 p
->flags
|= TERMP_NOSPACE
;
1081 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1082 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
];
1092 if (SEC_SYNOPSIS
== node
->sec
)
1101 termp_fn_post(DECL_ARGS
)
1104 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1112 termp_sx_pre(DECL_ARGS
)
1115 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1122 termp_fa_pre(DECL_ARGS
)
1124 struct mdoc_node
*n
;
1126 if (node
->parent
->tok
!= MDOC_Fo
) {
1127 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1131 for (n
= node
->child
; n
; n
= n
->next
) {
1132 assert(MDOC_TEXT
== n
->type
);
1134 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1135 word(p
, n
->data
.text
.string
);
1136 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1142 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1151 termp_va_pre(DECL_ARGS
)
1154 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1161 termp_bd_pre(DECL_ARGS
)
1163 const struct mdoc_block
*bl
;
1164 const struct mdoc_node
*n
;
1167 if (MDOC_BLOCK
== node
->type
) {
1171 } else if (MDOC_BODY
!= node
->type
)
1174 pair
->offset
= p
->offset
;
1175 bl
= &node
->parent
->data
.block
;
1177 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++) {
1178 switch (bl
->argv
[i
].arg
) {
1183 case (MDOC_Unfilled
):
1185 case (MDOC_Literal
):
1186 type
= bl
->argv
[i
].arg
;
1190 errx(1, "display type not supported");
1196 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1198 assert(1 == bl
->argv
[i
].sz
);
1199 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1204 case (MDOC_Literal
):
1206 case (MDOC_Unfilled
):
1212 p
->flags
|= TERMP_LITERAL
;
1214 for (n
= node
->child
; n
; n
= n
->next
) {
1215 if (MDOC_TEXT
!= n
->type
) {
1216 warnx("non-text children not yet allowed");
1219 word(p
, n
->data
.text
.string
);
1229 termp_bd_post(DECL_ARGS
)
1232 if (MDOC_BODY
!= node
->type
)
1235 if ( ! (p
->flags
& TERMP_LITERAL
))
1238 p
->flags
&= ~TERMP_LITERAL
;
1239 p
->offset
= pair
->offset
;
1245 termp_qq_pre(DECL_ARGS
)
1248 if (MDOC_BODY
!= node
->type
)
1251 p
->flags
|= TERMP_NOSPACE
;
1258 termp_qq_post(DECL_ARGS
)
1261 if (MDOC_BODY
!= node
->type
)
1263 p
->flags
|= TERMP_NOSPACE
;
1270 termp_bsx_pre(DECL_ARGS
)
1273 word(p
, "BSDI BSD/OS");
1280 termp_bx_post(DECL_ARGS
)
1284 p
->flags
|= TERMP_NOSPACE
;
1291 termp_ox_pre(DECL_ARGS
)
1301 termp_ux_pre(DECL_ARGS
)
1311 termp_fx_pre(DECL_ARGS
)
1321 termp_nx_pre(DECL_ARGS
)
1331 termp_sq_pre(DECL_ARGS
)
1334 if (MDOC_BODY
!= node
->type
)
1337 p
->flags
|= TERMP_NOSPACE
;
1344 termp_sq_post(DECL_ARGS
)
1347 if (MDOC_BODY
!= node
->type
)
1349 p
->flags
|= TERMP_NOSPACE
;
1356 termp_pf_pre(DECL_ARGS
)
1359 p
->flags
|= TERMP_IGNDELIM
;
1366 termp_pf_post(DECL_ARGS
)
1369 p
->flags
&= ~TERMP_IGNDELIM
;
1370 p
->flags
|= TERMP_NOSPACE
;
1376 termp_ss_pre(DECL_ARGS
)
1379 switch (node
->type
) {
1382 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1383 p
->offset
= INDENT
/ 2;
1395 termp_ss_post(DECL_ARGS
)
1398 switch (node
->type
) {
1411 termp_pa_pre(DECL_ARGS
)
1414 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1421 termp_em_pre(DECL_ARGS
)
1424 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1431 termp_cd_pre(DECL_ARGS
)
1434 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1442 termp_cm_pre(DECL_ARGS
)
1445 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1452 termp_ic_pre(DECL_ARGS
)
1455 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1462 termp_in_pre(DECL_ARGS
)
1465 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1466 word(p
, "#include");
1468 p
->flags
|= TERMP_NOSPACE
;
1475 termp_in_post(DECL_ARGS
)
1478 p
->flags
|= TERMP_NOSPACE
;
1482 if (SEC_SYNOPSIS
!= node
->sec
)
1484 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1491 termp_at_pre(DECL_ARGS
)
1498 assert(MDOC_TEXT
== node
->child
->type
);
1499 att
= mdoc_a2att(node
->child
->data
.text
.string
);
1512 termp_bq_pre(DECL_ARGS
)
1515 if (MDOC_BODY
!= node
->type
)
1518 p
->flags
|= TERMP_NOSPACE
;
1525 termp_bq_post(DECL_ARGS
)
1528 if (MDOC_BODY
!= node
->type
)
1536 termp_pq_pre(DECL_ARGS
)
1539 if (MDOC_BODY
!= node
->type
)
1542 p
->flags
|= TERMP_NOSPACE
;
1549 termp_pq_post(DECL_ARGS
)
1552 if (MDOC_BODY
!= node
->type
)
1560 termp_fo_pre(DECL_ARGS
)
1562 const struct mdoc_node
*n
;
1564 if (MDOC_BODY
== node
->type
) {
1566 p
->flags
|= TERMP_NOSPACE
;
1568 } else if (MDOC_HEAD
!= node
->type
)
1571 /* XXX - groff shows only first parameter */
1573 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1574 for (n
= node
->child
; n
; n
= n
->next
) {
1575 assert(MDOC_TEXT
== n
->type
);
1576 word(p
, n
->data
.text
.string
);
1578 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1586 termp_fo_post(DECL_ARGS
)
1589 if (MDOC_BODY
!= node
->type
)
1599 termp_bf_pre(DECL_ARGS
)
1601 const struct mdoc_node
*n
;
1602 const struct mdoc_block
*b
;
1604 /* XXX - we skip over possible trailing HEAD tokens. */
1606 if (MDOC_HEAD
== node
->type
)
1608 else if (MDOC_BLOCK
!= node
->type
)
1611 b
= &node
->data
.block
;
1613 if (NULL
== (n
= b
->head
->child
)) {
1614 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1615 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1616 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1617 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1622 assert(MDOC_TEXT
== n
->type
);
1624 if (0 == strcmp("Em", n
->data
.text
.string
))
1625 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1626 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1627 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1635 termp_sy_pre(DECL_ARGS
)
1638 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1645 termp_ms_pre(DECL_ARGS
)
1648 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1656 termp_sm_pre(DECL_ARGS
)
1660 assert(node
->child
);
1661 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1662 p
->flags
&= ~TERMP_NONOSPACE
;
1663 p
->flags
&= ~TERMP_NOSPACE
;
1665 p
->flags
|= TERMP_NONOSPACE
;
1666 p
->flags
|= TERMP_NOSPACE
;
1676 termp__t_pre(DECL_ARGS
)
1679 /* FIXME: titles are underlined. */
1681 p
->flags
|= TERMP_NOSPACE
;
1688 termp__t_post(DECL_ARGS
)
1691 p
->flags
|= TERMP_NOSPACE
;
1692 /* FIXME: titles are underlined. */
1694 word(p
, node
->next
? "," : ".");
1700 termp____post(DECL_ARGS
)
1703 p
->flags
|= TERMP_NOSPACE
;
1704 word(p
, node
->next
? "," : ".");