255b4e4e9b8f4e73b590e21361452cc384949af0
1 /* $Id: term.c,v 1.17 2009/02/25 11:37:05 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.
28 * Performs actions on nodes of the abstract syntax tree. Both pre- and
29 * post-fix operations are defined here.
32 /* FIXME: indent/tab. */
33 /* FIXME: handle nested lists. */
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 const int ttypes
[TTYPE_NMAX
] = {
62 TERMP_BOLD
, /* TTYPE_PROG */
63 TERMP_BOLD
, /* TTYPE_CMD_FLAG */
64 TERMP_UNDERLINE
, /* TTYPE_CMD_ARG */
65 TERMP_BOLD
, /* TTYPE_SECTION */
66 TERMP_BOLD
, /* TTYPE_FUNC_DECL */
67 TERMP_UNDERLINE
, /* TTYPE_VAR_DECL */
68 TERMP_UNDERLINE
, /* TTYPE_FUNC_TYPE */
69 TERMP_BOLD
, /* TTYPE_FUNC_NAME */
70 TERMP_UNDERLINE
, /* TTYPE_FUNC_ARG */
71 TERMP_UNDERLINE
, /* TTYPE_LINK */
72 TERMP_BOLD
, /* TTYPE_SSECTION */
73 TERMP_UNDERLINE
, /* TTYPE_FILE */
74 TERMP_UNDERLINE
, /* TTYPE_EMPH */
75 TERMP_BOLD
, /* TTYPE_CONFIG */
76 TERMP_BOLD
, /* TTYPE_CMD */
77 TERMP_BOLD
, /* TTYPE_INCLUDE */
78 TERMP_BOLD
, /* TTYPE_SYMB */
79 TERMP_BOLD
/* TTYPE_SYMBOL */
82 static int arg_hasattr(int, size_t,
83 const struct mdoc_arg
*);
84 static int arg_getattr(int, size_t,
85 const struct mdoc_arg
*);
86 static size_t arg_offset(const struct mdoc_arg
*);
87 static size_t arg_width(const struct mdoc_arg
*);
90 * What follows describes prefix and postfix operations for the abstract
91 * syntax tree descent.
96 const struct mdoc_meta *meta, \
97 const struct mdoc_node *node
99 #define DECL_PRE(name) \
100 static int name##_pre(DECL_ARGS)
101 #define DECL_POST(name) \
102 static void name##_post(DECL_ARGS)
103 #define DECL_PREPOST(name) \
107 DECL_PREPOST(termp_aq
);
108 DECL_PREPOST(termp_ar
);
109 DECL_PREPOST(termp_bf
);
110 DECL_PREPOST(termp_bd
);
111 DECL_PREPOST(termp_bq
);
112 DECL_PREPOST(termp_cd
);
113 DECL_PREPOST(termp_cm
);
114 DECL_PREPOST(termp_d1
);
115 DECL_PREPOST(termp_dq
);
116 DECL_PREPOST(termp_em
);
117 DECL_PREPOST(termp_fa
);
118 DECL_PREPOST(termp_fd
);
119 DECL_PREPOST(termp_fl
);
120 DECL_PREPOST(termp_fn
);
121 DECL_PREPOST(termp_fo
);
122 DECL_PREPOST(termp_ft
);
123 DECL_PREPOST(termp_ic
);
124 DECL_PREPOST(termp_in
);
125 DECL_PREPOST(termp_it
);
126 DECL_PREPOST(termp_ms
);
127 DECL_PREPOST(termp_nm
);
128 DECL_PREPOST(termp_op
);
129 DECL_PREPOST(termp_pa
);
130 DECL_PREPOST(termp_pf
);
131 DECL_PREPOST(termp_pq
);
132 DECL_PREPOST(termp_qq
);
133 DECL_PREPOST(termp_sh
);
134 DECL_PREPOST(termp_ss
);
135 DECL_PREPOST(termp_sq
);
136 DECL_PREPOST(termp_sx
);
137 DECL_PREPOST(termp_sy
);
138 DECL_PREPOST(termp_va
);
139 DECL_PREPOST(termp_vt
);
160 const struct termact __termacts
[MDOC_MAX
] = {
161 { NULL
, NULL
}, /* \" */
162 { NULL
, NULL
}, /* Dd */
163 { NULL
, NULL
}, /* Dt */
164 { NULL
, NULL
}, /* Os */
165 { termp_sh_pre
, termp_sh_post
}, /* Sh */
166 { termp_ss_pre
, termp_ss_post
}, /* Ss */
167 { termp_pp_pre
, NULL
}, /* Pp */
168 { termp_d1_pre
, termp_d1_post
}, /* D1 */
169 { NULL
, NULL
}, /* Dl */
170 { termp_bd_pre
, termp_bd_post
}, /* Bd */
171 { NULL
, NULL
}, /* Ed */
172 { NULL
, termp_bl_post
}, /* Bl */
173 { NULL
, NULL
}, /* El */
174 { termp_it_pre
, termp_it_post
}, /* It */
175 { NULL
, NULL
}, /* Ad */
176 { NULL
, NULL
}, /* An */
177 { termp_ar_pre
, termp_ar_post
}, /* Ar */
178 { termp_cd_pre
, termp_cd_post
}, /* Cd */
179 { termp_cm_pre
, termp_cm_post
}, /* Cm */
180 { NULL
, NULL
}, /* Dv */
181 { NULL
, NULL
}, /* Er */
182 { NULL
, NULL
}, /* Ev */
183 { termp_ex_pre
, NULL
}, /* Ex */
184 { termp_fa_pre
, termp_fa_post
}, /* Fa */
185 { termp_fd_pre
, termp_fd_post
}, /* Fd */
186 { termp_fl_pre
, termp_fl_post
}, /* Fl */
187 { termp_fn_pre
, termp_fn_post
}, /* Fn */
188 { termp_ft_pre
, termp_ft_post
}, /* Ft */
189 { termp_ic_pre
, termp_ic_post
}, /* Ic */
190 { termp_in_pre
, termp_in_post
}, /* In */
191 { NULL
, NULL
}, /* Li */
192 { termp_nd_pre
, NULL
}, /* Nd */
193 { termp_nm_pre
, termp_nm_post
}, /* Nm */
194 { termp_op_pre
, termp_op_post
}, /* Op */
195 { NULL
, NULL
}, /* Ot */
196 { termp_pa_pre
, termp_pa_post
}, /* Pa */
197 { termp_rv_pre
, NULL
}, /* Rv */
198 { termp_st_pre
, NULL
}, /* St */
199 { termp_va_pre
, termp_va_post
}, /* Va */
200 { termp_vt_pre
, termp_vt_post
}, /* Vt */
201 { termp_xr_pre
, NULL
}, /* Xr */
202 { NULL
, NULL
}, /* %A */
203 { NULL
, NULL
}, /* %B */
204 { NULL
, NULL
}, /* %D */
205 { NULL
, NULL
}, /* %I */
206 { NULL
, NULL
}, /* %J */
207 { NULL
, NULL
}, /* %N */
208 { NULL
, NULL
}, /* %O */
209 { NULL
, NULL
}, /* %P */
210 { NULL
, NULL
}, /* %R */
211 { NULL
, NULL
}, /* %T */
212 { NULL
, NULL
}, /* %V */
213 { NULL
, NULL
}, /* Ac */
214 { termp_aq_pre
, termp_aq_post
}, /* Ao */
215 { termp_aq_pre
, termp_aq_post
}, /* Aq */
216 { termp_at_pre
, NULL
}, /* At */
217 { NULL
, NULL
}, /* Bc */
218 { termp_bf_pre
, termp_bf_post
}, /* Bf */
219 { termp_bq_pre
, termp_bq_post
}, /* Bo */
220 { termp_bq_pre
, termp_bq_post
}, /* Bq */
221 { termp_bsx_pre
, NULL
}, /* Bsx */
222 { termp_bx_pre
, NULL
}, /* Bx */
223 { NULL
, NULL
}, /* Db */
224 { NULL
, NULL
}, /* Dc */
225 { termp_dq_pre
, termp_dq_post
}, /* Do */
226 { termp_dq_pre
, termp_dq_post
}, /* Dq */
227 { NULL
, NULL
}, /* Ec */
228 { NULL
, NULL
}, /* Ef */
229 { termp_em_pre
, termp_em_post
}, /* Em */
230 { NULL
, NULL
}, /* Eo */
231 { termp_fx_pre
, NULL
}, /* Fx */
232 { termp_ms_pre
, termp_ms_post
}, /* Ms */
233 { NULL
, NULL
}, /* No */
234 { termp_ns_pre
, NULL
}, /* Ns */
235 { termp_nx_pre
, NULL
}, /* Nx */
236 { termp_ox_pre
, NULL
}, /* Ox */
237 { NULL
, NULL
}, /* Pc */
238 { termp_pf_pre
, termp_pf_post
}, /* Pf */
239 { termp_pq_pre
, termp_pq_post
}, /* Po */
240 { termp_pq_pre
, termp_pq_post
}, /* Pq */
241 { NULL
, NULL
}, /* Qc */
242 { termp_sq_pre
, termp_sq_post
}, /* Ql */
243 { termp_qq_pre
, termp_qq_post
}, /* Qo */
244 { termp_qq_pre
, termp_qq_post
}, /* Qq */
245 { NULL
, NULL
}, /* Re */
246 { NULL
, NULL
}, /* Rs */
247 { NULL
, NULL
}, /* Sc */
248 { termp_sq_pre
, termp_sq_post
}, /* So */
249 { termp_sq_pre
, termp_sq_post
}, /* Sq */
250 { NULL
, NULL
}, /* Sm */
251 { termp_sx_pre
, termp_sx_post
}, /* Sx */
252 { termp_sy_pre
, termp_sy_post
}, /* Sy */
253 { NULL
, NULL
}, /* Tn */
254 { termp_ux_pre
, NULL
}, /* Ux */
255 { NULL
, NULL
}, /* Xc */
256 { NULL
, NULL
}, /* Xo */
257 { termp_fo_pre
, termp_fo_post
}, /* Fo */
258 { NULL
, NULL
}, /* Fc */
259 { termp_op_pre
, termp_op_post
}, /* Oo */
260 { NULL
, NULL
}, /* Oc */
261 { NULL
, NULL
}, /* Bk */
262 { NULL
, NULL
}, /* Ek */
263 { termp_bt_pre
, NULL
}, /* Bt */
264 { NULL
, NULL
}, /* Hf */
265 { NULL
, NULL
}, /* Fr */
266 { termp_ud_pre
, NULL
}, /* Ud */
269 const struct termact
*termacts
= __termacts
;
273 arg_width(const struct mdoc_arg
*arg
)
278 return(strlen(*arg
->value
));
283 arg_offset(const struct mdoc_arg
*arg
)
288 if (0 == strcmp(*arg
->value
, "indent"))
290 if (0 == strcmp(*arg
->value
, "indent-two"))
293 return(strlen(*arg
->value
));
298 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
301 return(-1 != arg_getattr(arg
, argc
, argv
));
306 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
310 for (i
= 0; i
< (int)argc
; i
++)
311 if (argv
[i
].arg
== arg
)
319 termp_dq_pre(DECL_ARGS
)
322 if (MDOC_BODY
!= node
->type
)
326 p
->flags
|= TERMP_NOSPACE
;
333 termp_dq_post(DECL_ARGS
)
336 if (MDOC_BODY
!= node
->type
)
339 p
->flags
|= TERMP_NOSPACE
;
346 termp_it_post(DECL_ARGS
)
348 const struct mdoc_node
*n
, *it
;
349 const struct mdoc_block
*bl
;
351 size_t width
, offset
;
354 * This (and termp_it_pre()) are the most complicated functions
355 * here. They must account for a considerable number of
356 * switches that completely change the output behaviour, like
357 * -tag versus -column. Yech.
360 switch (node
->type
) {
370 assert(MDOC_BLOCK
== it
->type
);
371 assert(MDOC_It
== it
->tok
);
374 assert(MDOC_BODY
== n
->type
);
375 assert(MDOC_Bl
== n
->tok
);
379 /* If `-tag', adjust our margins accordingly. */
381 if (arg_hasattr(MDOC_Tag
, bl
->argc
, bl
->argv
)) {
384 /* FIXME: this should auto-size. */
385 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
386 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 10;
388 /* FIXME: nesting! Should happen at block. */
389 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
390 offset
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
392 if (MDOC_HEAD
== node
->type
) {
393 p
->rmargin
= p
->maxrmargin
;
395 p
->flags
&= ~TERMP_NOBREAK
;
398 p
->flags
&= ~TERMP_NOLPAD
;
402 if (arg_hasattr(MDOC_Ohang
, bl
->argc
, bl
->argv
)) {
403 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
404 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
415 termp_it_pre(DECL_ARGS
)
417 const struct mdoc_node
*n
, *it
;
418 const struct mdoc_block
*bl
;
420 size_t width
, offset
;
423 * Also see termp_it_post() for general comments.
426 switch (node
->type
) {
439 assert(MDOC_BLOCK
== it
->type
);
440 assert(MDOC_It
== it
->tok
);
443 assert(MDOC_BODY
== n
->type
);
444 assert(MDOC_Bl
== n
->tok
);
448 /* If `-compact', don't assert vertical space. */
450 if (MDOC_BLOCK
== node
->type
) {
451 if (arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
458 assert(MDOC_HEAD
== node
->type
459 || MDOC_BODY
== node
->type
);
461 /* FIXME: see termp_it_post(). */
463 /* If `-tag', adjust our margins accordingly. */
465 if (arg_hasattr(MDOC_Tag
, bl
->argc
, bl
->argv
)) {
466 p
->flags
|= TERMP_NOSPACE
;
468 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
469 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 10;
471 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
472 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
474 if (MDOC_HEAD
== node
->type
) {
475 p
->flags
|= TERMP_NOBREAK
;
477 p
->rmargin
= p
->offset
+ width
;
479 p
->flags
|= TERMP_NOSPACE
;
480 p
->flags
|= TERMP_NOLPAD
;
486 /* If `-ohang', adjust left-margin. */
488 if (arg_hasattr(MDOC_Ohang
, bl
->argc
, bl
->argv
)) {
489 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
490 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
492 p
->flags
|= TERMP_NOSPACE
;
503 termp_nm_post(DECL_ARGS
)
506 p
->flags
&= ~ttypes
[TTYPE_PROG
];
512 termp_fl_post(DECL_ARGS
)
515 p
->flags
&= ~ttypes
[TTYPE_CMD_FLAG
];
521 termp_ar_pre(DECL_ARGS
)
524 p
->flags
|= ttypes
[TTYPE_CMD_ARG
];
525 if (NULL
== node
->child
)
533 termp_nm_pre(DECL_ARGS
)
536 p
->flags
|= ttypes
[TTYPE_PROG
];
537 if (NULL
== node
->child
)
545 termp_ns_pre(DECL_ARGS
)
548 p
->flags
|= TERMP_NOSPACE
;
555 termp_pp_pre(DECL_ARGS
)
565 termp_ar_post(DECL_ARGS
)
568 p
->flags
&= ~ttypes
[TTYPE_CMD_ARG
];
574 termp_st_pre(DECL_ARGS
)
578 assert(1 == node
->data
.elem
.argc
);
580 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
589 termp_rv_pre(DECL_ARGS
)
593 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
594 node
->data
.elem
.argv
);
600 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
601 word(p
, *node
->data
.elem
.argv
[i
].value
);
602 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
604 word(p
, "() function returns the value 0 if successful;");
605 word(p
, "otherwise the value -1 is returned and the");
606 word(p
, "global variable");
608 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
610 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
612 word(p
, "is set to indicate the error.");
620 termp_ex_pre(DECL_ARGS
)
624 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
625 node
->data
.elem
.argv
);
629 p
->flags
|= ttypes
[TTYPE_PROG
];
630 word(p
, *node
->data
.elem
.argv
[i
].value
);
631 p
->flags
&= ~ttypes
[TTYPE_PROG
];
632 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
640 termp_nd_pre(DECL_ARGS
)
650 termp_bl_post(DECL_ARGS
)
653 if (MDOC_BLOCK
== node
->type
)
660 termp_op_post(DECL_ARGS
)
663 if (MDOC_BODY
!= node
->type
)
665 p
->flags
|= TERMP_NOSPACE
;
672 termp_sh_post(DECL_ARGS
)
675 switch (node
->type
) {
677 p
->flags
&= ~ttypes
[TTYPE_SECTION
];
692 termp_xr_pre(DECL_ARGS
)
694 const struct mdoc_node
*n
;
699 assert(MDOC_TEXT
== n
->type
);
700 word(p
, n
->data
.text
.string
);
702 if (NULL
== (n
= n
->next
))
705 assert(MDOC_TEXT
== n
->type
);
706 p
->flags
|= TERMP_NOSPACE
;
708 p
->flags
|= TERMP_NOSPACE
;
709 word(p
, n
->data
.text
.string
);
710 p
->flags
|= TERMP_NOSPACE
;
719 termp_vt_pre(DECL_ARGS
)
722 /* FIXME: this can be "type name". */
723 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
730 termp_vt_post(DECL_ARGS
)
733 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
734 if (node
->sec
== SEC_SYNOPSIS
)
741 termp_fd_pre(DECL_ARGS
)
745 * FIXME: this naming is bad. This value is used, in general,
746 * for the #include header or other preprocessor statement.
748 p
->flags
|= ttypes
[TTYPE_FUNC_DECL
];
755 termp_fd_post(DECL_ARGS
)
758 p
->flags
&= ~ttypes
[TTYPE_FUNC_DECL
];
759 if (node
->sec
== SEC_SYNOPSIS
)
767 termp_sh_pre(DECL_ARGS
)
770 switch (node
->type
) {
773 p
->flags
|= ttypes
[TTYPE_SECTION
];
787 termp_op_pre(DECL_ARGS
)
790 switch (node
->type
) {
793 p
->flags
|= TERMP_NOSPACE
;
804 termp_bt_pre(DECL_ARGS
)
807 word(p
, "is currently in beta test.");
814 termp_ud_pre(DECL_ARGS
)
817 word(p
, "currently under development.");
824 termp_fl_pre(DECL_ARGS
)
827 p
->flags
|= ttypes
[TTYPE_CMD_FLAG
];
829 p
->flags
|= TERMP_NOSPACE
;
836 termp_d1_pre(DECL_ARGS
)
839 if (MDOC_BODY
!= node
->type
)
849 termp_d1_post(DECL_ARGS
)
852 if (MDOC_BODY
!= node
->type
)
861 termp_aq_pre(DECL_ARGS
)
864 if (MDOC_BODY
!= node
->type
)
867 p
->flags
|= TERMP_NOSPACE
;
874 termp_aq_post(DECL_ARGS
)
877 if (MDOC_BODY
!= node
->type
)
879 p
->flags
|= TERMP_NOSPACE
;
886 termp_ft_pre(DECL_ARGS
)
889 p
->flags
|= ttypes
[TTYPE_FUNC_TYPE
];
896 termp_ft_post(DECL_ARGS
)
899 p
->flags
&= ~ttypes
[TTYPE_FUNC_TYPE
];
900 if (node
->sec
== SEC_SYNOPSIS
)
908 termp_fn_pre(DECL_ARGS
)
910 const struct mdoc_node
*n
;
913 assert(MDOC_TEXT
== node
->child
->type
);
915 /* FIXME: can be "type funcname" "type varname"... */
917 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
918 word(p
, node
->child
->data
.text
.string
);
919 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
923 p
->flags
|= TERMP_NOSPACE
;
924 for (n
= node
->child
->next
; n
; n
= n
->next
) {
925 assert(MDOC_TEXT
== n
->type
);
926 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
927 word(p
, n
->data
.text
.string
);
928 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
935 if (SEC_SYNOPSIS
== node
->sec
)
944 termp_fn_post(DECL_ARGS
)
947 if (node
->sec
== SEC_SYNOPSIS
)
955 termp_sx_pre(DECL_ARGS
)
958 p
->flags
|= ttypes
[TTYPE_LINK
];
965 termp_sx_post(DECL_ARGS
)
968 p
->flags
&= ~ttypes
[TTYPE_LINK
];
974 termp_fa_pre(DECL_ARGS
)
978 if (node
->parent
->tok
!= MDOC_Fo
) {
979 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
983 for (n
= node
->child
; n
; n
= n
->next
) {
984 assert(MDOC_TEXT
== n
->type
);
986 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
987 word(p
, n
->data
.text
.string
);
988 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
994 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1003 termp_fa_post(DECL_ARGS
)
1006 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1012 termp_va_pre(DECL_ARGS
)
1015 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
1022 termp_va_post(DECL_ARGS
)
1025 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
1031 termp_bd_pre(DECL_ARGS
)
1033 const struct mdoc_block
*bl
;
1034 const struct mdoc_node
*n
;
1037 if (MDOC_BLOCK
== node
->type
) {
1040 } else if (MDOC_BODY
!= node
->type
)
1043 assert(MDOC_BLOCK
== node
->parent
->type
);
1045 bl
= &node
->parent
->data
.block
;
1047 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1049 assert(1 == bl
->argv
[i
].sz
);
1050 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1053 if ( ! arg_hasattr(MDOC_Literal
, bl
->argc
, bl
->argv
))
1056 p
->flags
|= TERMP_LITERAL
;
1058 for (n
= node
->child
; n
; n
= n
->next
) {
1059 assert(MDOC_TEXT
== n
->type
); /* FIXME */
1060 if ((*n
->data
.text
.string
)) {
1061 word(p
, n
->data
.text
.string
);
1068 p
->flags
&= ~TERMP_LITERAL
;
1075 termp_bd_post(DECL_ARGS
)
1078 const struct mdoc_block
*bl
;
1080 if (MDOC_BODY
!= node
->type
)
1083 assert(MDOC_BLOCK
== node
->parent
->type
);
1084 bl
= &node
->parent
->data
.block
;
1086 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1088 assert(1 == bl
->argv
[i
].sz
);
1089 p
->offset
-= arg_offset(&bl
->argv
[i
]);
1096 termp_qq_pre(DECL_ARGS
)
1099 if (MDOC_BODY
!= node
->type
)
1102 p
->flags
|= TERMP_NOSPACE
;
1109 termp_qq_post(DECL_ARGS
)
1112 if (MDOC_BODY
!= node
->type
)
1114 p
->flags
|= TERMP_NOSPACE
;
1121 termp_bsx_pre(DECL_ARGS
)
1124 word(p
, "BSDI BSD/OS");
1131 termp_bx_pre(DECL_ARGS
)
1141 termp_ox_pre(DECL_ARGS
)
1151 termp_ux_pre(DECL_ARGS
)
1161 termp_fx_pre(DECL_ARGS
)
1171 termp_nx_pre(DECL_ARGS
)
1181 termp_sq_pre(DECL_ARGS
)
1184 if (MDOC_BODY
!= node
->type
)
1187 p
->flags
|= TERMP_NOSPACE
;
1194 termp_sq_post(DECL_ARGS
)
1197 if (MDOC_BODY
!= node
->type
)
1199 p
->flags
|= TERMP_NOSPACE
;
1206 termp_pf_pre(DECL_ARGS
)
1209 p
->flags
|= TERMP_IGNDELIM
;
1216 termp_pf_post(DECL_ARGS
)
1219 p
->flags
&= ~TERMP_IGNDELIM
;
1220 p
->flags
|= TERMP_NOSPACE
;
1226 termp_ss_pre(DECL_ARGS
)
1229 switch (node
->type
) {
1232 p
->flags
|= ttypes
[TTYPE_SSECTION
];
1233 p
->offset
= INDENT
/ 2;
1245 termp_ss_post(DECL_ARGS
)
1248 switch (node
->type
) {
1250 p
->flags
&= ~ttypes
[TTYPE_SSECTION
];
1262 termp_pa_pre(DECL_ARGS
)
1265 p
->flags
|= ttypes
[TTYPE_FILE
];
1272 termp_pa_post(DECL_ARGS
)
1275 p
->flags
&= ~ttypes
[TTYPE_FILE
];
1281 termp_em_pre(DECL_ARGS
)
1284 p
->flags
|= ttypes
[TTYPE_EMPH
];
1291 termp_em_post(DECL_ARGS
)
1294 p
->flags
&= ~ttypes
[TTYPE_EMPH
];
1300 termp_cd_pre(DECL_ARGS
)
1303 p
->flags
|= ttypes
[TTYPE_CONFIG
];
1310 termp_cd_post(DECL_ARGS
)
1313 p
->flags
&= ~ttypes
[TTYPE_CONFIG
];
1319 termp_cm_pre(DECL_ARGS
)
1322 p
->flags
|= ttypes
[TTYPE_CMD_FLAG
];
1329 termp_cm_post(DECL_ARGS
)
1332 p
->flags
&= ~ttypes
[TTYPE_CMD_FLAG
];
1338 termp_ic_pre(DECL_ARGS
)
1341 p
->flags
|= ttypes
[TTYPE_CMD
];
1348 termp_ic_post(DECL_ARGS
)
1351 p
->flags
&= ~ttypes
[TTYPE_CMD
];
1357 termp_in_pre(DECL_ARGS
)
1360 p
->flags
|= ttypes
[TTYPE_INCLUDE
];
1367 termp_in_post(DECL_ARGS
)
1370 p
->flags
&= ~ttypes
[TTYPE_INCLUDE
];
1376 termp_at_pre(DECL_ARGS
)
1382 assert(MDOC_TEXT
== node
->child
->type
);
1383 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1386 word(p
, mdoc_att2a(c
));
1393 termp_bq_pre(DECL_ARGS
)
1396 if (MDOC_BODY
!= node
->type
)
1399 p
->flags
|= TERMP_NOSPACE
;
1406 termp_bq_post(DECL_ARGS
)
1409 if (MDOC_BODY
!= node
->type
)
1417 termp_pq_pre(DECL_ARGS
)
1420 if (MDOC_BODY
!= node
->type
)
1423 p
->flags
|= TERMP_NOSPACE
;
1430 termp_pq_post(DECL_ARGS
)
1433 if (MDOC_BODY
!= node
->type
)
1441 termp_fo_pre(DECL_ARGS
)
1443 const struct mdoc_node
*n
;
1445 if (MDOC_BODY
== node
->type
) {
1447 p
->flags
|= TERMP_NOSPACE
;
1449 } else if (MDOC_HEAD
!= node
->type
)
1452 /* XXX - groff shows only first parameter */
1454 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1455 for (n
= node
->child
; n
; n
= n
->next
) {
1456 assert(MDOC_TEXT
== n
->type
);
1457 word(p
, n
->data
.text
.string
);
1459 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1467 termp_fo_post(DECL_ARGS
)
1470 if (MDOC_BODY
!= node
->type
)
1480 termp_bf_pre(DECL_ARGS
)
1482 const struct mdoc_node
*n
;
1483 const struct mdoc_block
*b
;
1485 /* XXX - we skip over possible trailing HEAD tokens. */
1487 if (MDOC_HEAD
== node
->type
)
1489 else if (MDOC_BLOCK
!= node
->type
)
1492 b
= &node
->data
.block
;
1494 if (NULL
== (n
= b
->head
->child
)) {
1495 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1496 p
->flags
|= ttypes
[TTYPE_EMPH
];
1497 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1498 p
->flags
|= ttypes
[TTYPE_SYMB
];
1503 assert(MDOC_TEXT
== n
->type
);
1505 if (0 == strcmp("Em", n
->data
.text
.string
))
1506 p
->flags
|= ttypes
[TTYPE_EMPH
];
1507 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1508 p
->flags
|= ttypes
[TTYPE_SYMB
];
1516 termp_bf_post(DECL_ARGS
)
1518 const struct mdoc_node
*n
;
1519 const struct mdoc_block
*b
;
1521 if (MDOC_BLOCK
!= node
->type
)
1524 b
= &node
->data
.block
;
1526 if (NULL
== (n
= b
->head
->child
)) {
1527 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1528 p
->flags
&= ~ttypes
[TTYPE_EMPH
];
1529 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1530 p
->flags
&= ~ttypes
[TTYPE_SYMB
];
1535 assert(MDOC_TEXT
== n
->type
);
1537 if (0 == strcmp("Emphasis", n
->data
.text
.string
))
1538 p
->flags
&= ~ttypes
[TTYPE_EMPH
];
1539 else if (0 == strcmp("Symbolic", n
->data
.text
.string
))
1540 p
->flags
&= ~ttypes
[TTYPE_SYMB
];
1548 termp_sy_pre(DECL_ARGS
)
1551 p
->flags
|= ttypes
[TTYPE_SYMB
];
1558 termp_sy_post(DECL_ARGS
)
1561 p
->flags
&= ~ttypes
[TTYPE_SYMB
];
1567 termp_ms_pre(DECL_ARGS
)
1570 p
->flags
|= ttypes
[TTYPE_SYMBOL
];
1577 termp_ms_post(DECL_ARGS
)
1580 p
->flags
&= ~ttypes
[TTYPE_SYMBOL
];