]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
2236703ecd95cd1ee42bfadfdb411582f710a6f3
1 /* $Id: term.c,v 1.39 2009/03/04 13:57:35 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
;
541 if (MDOC_HEAD
== node
->type
)
542 p
->flags
|= TERMP_NOBREAK
;
549 * Margin control. Set-head-width lists have their right
550 * margins shortened. The body for these lists has the offset
551 * necessarily lengthened. Everybody gets the offset.
566 if (MDOC_HEAD
== node
->type
)
567 p
->rmargin
= p
->offset
+ width
;
576 * The dash, hyphen, bullet and enum lists all have a special
577 * HEAD character. Print it now.
580 if (MDOC_HEAD
== node
->type
)
591 /* TODO: have a wordfmt or something. */
592 (pair
->ppair
->ppair
->count
)++;
593 (void)snprintf(buf
, sizeof(buf
), "%d.",
594 pair
->ppair
->ppair
->count
);
602 * If we're not going to process our header children, indicate
606 if (MDOC_HEAD
== node
->type
)
628 termp_it_post(DECL_ARGS
)
632 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
635 type
= arg_listtype(node
->parent
->parent
->parent
);
643 if (MDOC_BODY
!= node
->type
)
652 p
->offset
= pair
->offset
;
653 p
->rmargin
= pair
->rmargin
;
654 p
->flags
= pair
->flag
;
660 termp_nm_pre(DECL_ARGS
)
663 if (SEC_SYNOPSIS
== node
->sec
)
666 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
667 if (NULL
== node
->child
)
676 termp_fl_pre(DECL_ARGS
)
679 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
681 p
->flags
|= TERMP_NOSPACE
;
688 termp_ar_pre(DECL_ARGS
)
691 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
692 if (NULL
== node
->child
) {
702 termp_ns_pre(DECL_ARGS
)
705 p
->flags
|= TERMP_NOSPACE
;
712 termp_pp_pre(DECL_ARGS
)
722 termp_st_pre(DECL_ARGS
)
726 assert(1 == node
->data
.elem
.argc
);
728 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
737 termp_rs_pre(DECL_ARGS
)
740 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
748 termp_rv_pre(DECL_ARGS
)
752 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
753 node
->data
.elem
.argv
);
759 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
760 word(p
, *node
->data
.elem
.argv
[i
].value
);
761 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
763 word(p
, "() function returns the value 0 if successful;");
764 word(p
, "otherwise the value -1 is returned and the");
765 word(p
, "global variable");
767 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
769 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
771 word(p
, "is set to indicate the error.");
779 termp_ex_pre(DECL_ARGS
)
783 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
784 node
->data
.elem
.argv
);
788 p
->flags
|= ttypes
[TTYPE_PROG
];
789 word(p
, *node
->data
.elem
.argv
[i
].value
);
790 p
->flags
&= ~ttypes
[TTYPE_PROG
];
791 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
799 termp_nd_pre(DECL_ARGS
)
809 termp_bl_post(DECL_ARGS
)
812 if (MDOC_BLOCK
== node
->type
)
819 termp_op_post(DECL_ARGS
)
822 if (MDOC_BODY
!= node
->type
)
824 p
->flags
|= TERMP_NOSPACE
;
831 termp_xr_pre(DECL_ARGS
)
833 const struct mdoc_node
*n
;
838 assert(MDOC_TEXT
== n
->type
);
839 word(p
, n
->data
.text
.string
);
841 if (NULL
== (n
= n
->next
))
844 assert(MDOC_TEXT
== n
->type
);
845 p
->flags
|= TERMP_NOSPACE
;
847 p
->flags
|= TERMP_NOSPACE
;
848 word(p
, n
->data
.text
.string
);
849 p
->flags
|= TERMP_NOSPACE
;
858 termp_vt_pre(DECL_ARGS
)
861 /* FIXME: this can be "type name". */
862 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
869 termp_vt_post(DECL_ARGS
)
872 if (node
->sec
== SEC_SYNOPSIS
)
879 termp_fd_pre(DECL_ARGS
)
883 * FIXME: this naming is bad. This value is used, in general,
884 * for the #include header or other preprocessor statement.
886 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
893 termp_fd_post(DECL_ARGS
)
896 if (node
->sec
!= SEC_SYNOPSIS
)
899 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
906 termp_sh_pre(DECL_ARGS
)
909 switch (node
->type
) {
912 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
926 termp_sh_post(DECL_ARGS
)
929 switch (node
->type
) {
945 termp_op_pre(DECL_ARGS
)
948 switch (node
->type
) {
951 p
->flags
|= TERMP_NOSPACE
;
962 termp_bt_pre(DECL_ARGS
)
965 word(p
, "is currently in beta test.");
972 termp_ud_pre(DECL_ARGS
)
975 word(p
, "currently under development.");
982 termp_d1_pre(DECL_ARGS
)
985 if (MDOC_BODY
!= node
->type
)
988 p
->offset
+= (pair
->offset
= INDENT
);
995 termp_d1_post(DECL_ARGS
)
998 if (MDOC_BODY
!= node
->type
)
1001 p
->offset
-= pair
->offset
;
1007 termp_aq_pre(DECL_ARGS
)
1010 if (MDOC_BODY
!= node
->type
)
1013 p
->flags
|= TERMP_NOSPACE
;
1020 termp_aq_post(DECL_ARGS
)
1023 if (MDOC_BODY
!= node
->type
)
1025 p
->flags
|= TERMP_NOSPACE
;
1032 termp_ft_pre(DECL_ARGS
)
1035 if (SEC_SYNOPSIS
== node
->sec
)
1036 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1038 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1045 termp_ft_post(DECL_ARGS
)
1048 if (SEC_SYNOPSIS
== node
->sec
)
1055 termp_fn_pre(DECL_ARGS
)
1057 const struct mdoc_node
*n
;
1059 assert(node
->child
);
1060 assert(MDOC_TEXT
== node
->child
->type
);
1062 /* FIXME: can be "type funcname" "type varname"... */
1064 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1065 word(p
, node
->child
->data
.text
.string
);
1066 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1070 p
->flags
|= TERMP_NOSPACE
;
1071 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1072 assert(MDOC_TEXT
== n
->type
);
1073 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1074 word(p
, n
->data
.text
.string
);
1075 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1082 if (SEC_SYNOPSIS
== node
->sec
)
1091 termp_fn_post(DECL_ARGS
)
1094 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1102 termp_sx_pre(DECL_ARGS
)
1105 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1112 termp_fa_pre(DECL_ARGS
)
1114 struct mdoc_node
*n
;
1116 if (node
->parent
->tok
!= MDOC_Fo
) {
1117 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1121 for (n
= node
->child
; n
; n
= n
->next
) {
1122 assert(MDOC_TEXT
== n
->type
);
1124 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1125 word(p
, n
->data
.text
.string
);
1126 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1132 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1141 termp_va_pre(DECL_ARGS
)
1144 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1151 termp_bd_pre(DECL_ARGS
)
1153 const struct mdoc_block
*bl
;
1154 const struct mdoc_node
*n
;
1157 if (MDOC_BLOCK
== node
->type
) {
1161 } else if (MDOC_BODY
!= node
->type
)
1164 pair
->offset
= p
->offset
;
1165 bl
= &node
->parent
->data
.block
;
1167 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++) {
1168 switch (bl
->argv
[i
].arg
) {
1173 case (MDOC_Unfilled
):
1175 case (MDOC_Literal
):
1176 type
= bl
->argv
[i
].arg
;
1180 errx(1, "display type not supported");
1186 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1188 assert(1 == bl
->argv
[i
].sz
);
1189 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1194 case (MDOC_Literal
):
1196 case (MDOC_Unfilled
):
1202 p
->flags
|= TERMP_LITERAL
;
1204 for (n
= node
->child
; n
; n
= n
->next
) {
1205 if (MDOC_TEXT
!= n
->type
) {
1206 warnx("non-text children not yet allowed");
1209 word(p
, n
->data
.text
.string
);
1219 termp_bd_post(DECL_ARGS
)
1222 if (MDOC_BODY
!= node
->type
)
1225 if ( ! (p
->flags
& TERMP_LITERAL
))
1228 p
->flags
&= ~TERMP_LITERAL
;
1229 p
->offset
= pair
->offset
;
1235 termp_qq_pre(DECL_ARGS
)
1238 if (MDOC_BODY
!= node
->type
)
1241 p
->flags
|= TERMP_NOSPACE
;
1248 termp_qq_post(DECL_ARGS
)
1251 if (MDOC_BODY
!= node
->type
)
1253 p
->flags
|= TERMP_NOSPACE
;
1260 termp_bsx_pre(DECL_ARGS
)
1263 word(p
, "BSDI BSD/OS");
1270 termp_bx_post(DECL_ARGS
)
1274 p
->flags
|= TERMP_NOSPACE
;
1281 termp_ox_pre(DECL_ARGS
)
1291 termp_ux_pre(DECL_ARGS
)
1301 termp_fx_pre(DECL_ARGS
)
1311 termp_nx_pre(DECL_ARGS
)
1321 termp_sq_pre(DECL_ARGS
)
1324 if (MDOC_BODY
!= node
->type
)
1327 p
->flags
|= TERMP_NOSPACE
;
1334 termp_sq_post(DECL_ARGS
)
1337 if (MDOC_BODY
!= node
->type
)
1339 p
->flags
|= TERMP_NOSPACE
;
1346 termp_pf_pre(DECL_ARGS
)
1349 p
->flags
|= TERMP_IGNDELIM
;
1356 termp_pf_post(DECL_ARGS
)
1359 p
->flags
&= ~TERMP_IGNDELIM
;
1360 p
->flags
|= TERMP_NOSPACE
;
1366 termp_ss_pre(DECL_ARGS
)
1369 switch (node
->type
) {
1372 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1373 p
->offset
= INDENT
/ 2;
1385 termp_ss_post(DECL_ARGS
)
1388 switch (node
->type
) {
1401 termp_pa_pre(DECL_ARGS
)
1404 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1411 termp_em_pre(DECL_ARGS
)
1414 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1421 termp_cd_pre(DECL_ARGS
)
1424 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1432 termp_cm_pre(DECL_ARGS
)
1435 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1442 termp_ic_pre(DECL_ARGS
)
1445 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1452 termp_in_pre(DECL_ARGS
)
1455 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1456 word(p
, "#include");
1458 p
->flags
|= TERMP_NOSPACE
;
1465 termp_in_post(DECL_ARGS
)
1468 p
->flags
|= TERMP_NOSPACE
;
1472 if (SEC_SYNOPSIS
!= node
->sec
)
1474 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1481 termp_at_pre(DECL_ARGS
)
1487 assert(MDOC_TEXT
== node
->child
->type
);
1488 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1491 word(p
, mdoc_att2a(c
));
1498 termp_bq_pre(DECL_ARGS
)
1501 if (MDOC_BODY
!= node
->type
)
1504 p
->flags
|= TERMP_NOSPACE
;
1511 termp_bq_post(DECL_ARGS
)
1514 if (MDOC_BODY
!= node
->type
)
1522 termp_pq_pre(DECL_ARGS
)
1525 if (MDOC_BODY
!= node
->type
)
1528 p
->flags
|= TERMP_NOSPACE
;
1535 termp_pq_post(DECL_ARGS
)
1538 if (MDOC_BODY
!= node
->type
)
1546 termp_fo_pre(DECL_ARGS
)
1548 const struct mdoc_node
*n
;
1550 if (MDOC_BODY
== node
->type
) {
1552 p
->flags
|= TERMP_NOSPACE
;
1554 } else if (MDOC_HEAD
!= node
->type
)
1557 /* XXX - groff shows only first parameter */
1559 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1560 for (n
= node
->child
; n
; n
= n
->next
) {
1561 assert(MDOC_TEXT
== n
->type
);
1562 word(p
, n
->data
.text
.string
);
1564 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1572 termp_fo_post(DECL_ARGS
)
1575 if (MDOC_BODY
!= node
->type
)
1585 termp_bf_pre(DECL_ARGS
)
1587 const struct mdoc_node
*n
;
1588 const struct mdoc_block
*b
;
1590 /* XXX - we skip over possible trailing HEAD tokens. */
1592 if (MDOC_HEAD
== node
->type
)
1594 else if (MDOC_BLOCK
!= node
->type
)
1597 b
= &node
->data
.block
;
1599 if (NULL
== (n
= b
->head
->child
)) {
1600 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1601 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1602 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1603 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1608 assert(MDOC_TEXT
== n
->type
);
1610 if (0 == strcmp("Em", n
->data
.text
.string
))
1611 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1612 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1613 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1621 termp_sy_pre(DECL_ARGS
)
1624 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1631 termp_ms_pre(DECL_ARGS
)
1634 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1642 termp_sm_pre(DECL_ARGS
)
1646 assert(node
->child
);
1647 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1648 p
->flags
&= ~TERMP_NONOSPACE
;
1649 p
->flags
&= ~TERMP_NOSPACE
;
1651 p
->flags
|= TERMP_NONOSPACE
;
1652 p
->flags
|= TERMP_NOSPACE
;
1662 termp__t_pre(DECL_ARGS
)
1666 p
->flags
|= TERMP_NOSPACE
;
1673 termp__t_post(DECL_ARGS
)
1676 p
->flags
|= TERMP_NOSPACE
;
1678 word(p
, node
->next
? "," : ".");
1684 termp____post(DECL_ARGS
)
1687 p
->flags
|= TERMP_NOSPACE
;
1688 word(p
, node
->next
? "," : ".");