]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
34778b1e4e0e634737c523847bcf7b729f31b624
1 /* $Id: term.c,v 1.30 2009/02/28 21:31:13 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.
31 * Performs actions on nodes of the abstract syntax tree. Both pre- and
32 * post-fix operations are defined here.
35 /* FIXME: indent/tab. */
36 /* FIXME: macro arguments can be escaped. */
39 #define TTYPE_CMD_FLAG 1
40 #define TTYPE_CMD_ARG 2
41 #define TTYPE_SECTION 3
42 #define TTYPE_FUNC_DECL 4
43 #define TTYPE_VAR_DECL 5
44 #define TTYPE_FUNC_TYPE 6
45 #define TTYPE_FUNC_NAME 7
46 #define TTYPE_FUNC_ARG 8
48 #define TTYPE_SSECTION 10
51 #define TTYPE_CONFIG 13
53 #define TTYPE_INCLUDE 15
55 #define TTYPE_SYMBOL 17
59 * These define "styles" for element types, like command arguments or
60 * executable names. This is useful when multiple macros must decorate
61 * the same thing (like .Ex -std cmd and .Nm cmd).
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 */
85 static int arg_hasattr(int, size_t,
86 const struct mdoc_arg
*);
87 static int arg_getattr(int, size_t,
88 const struct mdoc_arg
*);
89 static size_t arg_offset(const struct mdoc_arg
*);
90 static size_t arg_width(const struct mdoc_arg
*);
93 * What follows describes prefix and postfix operations for the abstract
94 * syntax tree descent.
99 struct termpair *pair, \
100 const struct mdoc_meta *meta, \
101 const struct mdoc_node *node
103 #define DECL_PRE(name) \
104 static int name##_pre(DECL_ARGS)
105 #define DECL_POST(name) \
106 static void name##_post(DECL_ARGS)
107 #define DECL_PREPOST(name) \
111 DECL_PREPOST(termp__t
);
112 DECL_PREPOST(termp_aq
);
113 DECL_PREPOST(termp_bd
);
114 DECL_PREPOST(termp_bq
);
115 DECL_PREPOST(termp_d1
);
116 DECL_PREPOST(termp_dq
);
117 DECL_PREPOST(termp_fd
);
118 DECL_PREPOST(termp_fn
);
119 DECL_PREPOST(termp_fo
);
120 DECL_PREPOST(termp_ft
);
121 DECL_PREPOST(termp_in
);
122 DECL_PREPOST(termp_it
);
123 DECL_PREPOST(termp_op
);
124 DECL_PREPOST(termp_pf
);
125 DECL_PREPOST(termp_pq
);
126 DECL_PREPOST(termp_qq
);
127 DECL_PREPOST(termp_sh
);
128 DECL_PREPOST(termp_ss
);
129 DECL_PREPOST(termp_sq
);
130 DECL_PREPOST(termp_vt
);
168 const struct termact __termacts
[MDOC_MAX
] = {
169 { NULL
, NULL
}, /* \" */
170 { NULL
, NULL
}, /* Dd */
171 { NULL
, NULL
}, /* Dt */
172 { NULL
, NULL
}, /* Os */
173 { termp_sh_pre
, termp_sh_post
}, /* Sh */
174 { termp_ss_pre
, termp_ss_post
}, /* Ss */
175 { termp_pp_pre
, NULL
}, /* Pp */
176 { termp_d1_pre
, termp_d1_post
}, /* D1 */
177 { termp_d1_pre
, termp_d1_post
}, /* Dl */
178 { termp_bd_pre
, termp_bd_post
}, /* Bd */
179 { NULL
, NULL
}, /* Ed */
180 { NULL
, termp_bl_post
}, /* Bl */
181 { NULL
, NULL
}, /* El */
182 { termp_it_pre
, termp_it_post
}, /* It */
183 { NULL
, NULL
}, /* Ad */
184 { NULL
, NULL
}, /* An */
185 { termp_ar_pre
, NULL
}, /* Ar */
186 { termp_cd_pre
, NULL
}, /* Cd */
187 { termp_cm_pre
, NULL
}, /* Cm */
188 { NULL
, NULL
}, /* Dv */
189 { NULL
, NULL
}, /* Er */
190 { NULL
, NULL
}, /* Ev */
191 { termp_ex_pre
, NULL
}, /* Ex */
192 { termp_fa_pre
, NULL
}, /* Fa */
193 { termp_fd_pre
, termp_fd_post
}, /* Fd */
194 { termp_fl_pre
, NULL
}, /* Fl */
195 { termp_fn_pre
, termp_fn_post
}, /* Fn */
196 { termp_ft_pre
, termp_ft_post
}, /* Ft */
197 { termp_ic_pre
, NULL
}, /* Ic */
198 { termp_in_pre
, termp_in_post
}, /* In */
199 { NULL
, NULL
}, /* Li */
200 { termp_nd_pre
, NULL
}, /* Nd */
201 { termp_nm_pre
, NULL
}, /* Nm */
202 { termp_op_pre
, termp_op_post
}, /* Op */
203 { NULL
, NULL
}, /* Ot */
204 { termp_pa_pre
, NULL
}, /* Pa */
205 { termp_rv_pre
, NULL
}, /* Rv */
206 { termp_st_pre
, NULL
}, /* St */
207 { termp_va_pre
, NULL
}, /* Va */
208 { termp_vt_pre
, termp_vt_post
}, /* Vt */
209 { termp_xr_pre
, NULL
}, /* Xr */
210 { NULL
, termp____post
}, /* %A */
211 { NULL
, termp____post
}, /* %B */
212 { NULL
, termp____post
}, /* %D */
213 { NULL
, termp____post
}, /* %I */
214 { NULL
, termp____post
}, /* %J */
215 { NULL
, termp____post
}, /* %N */
216 { NULL
, termp____post
}, /* %O */
217 { NULL
, termp____post
}, /* %P */
218 { NULL
, termp____post
}, /* %R */
219 { termp__t_pre
, termp__t_post
}, /* %T */
220 { NULL
, termp____post
}, /* %V */
221 { NULL
, NULL
}, /* Ac */
222 { termp_aq_pre
, termp_aq_post
}, /* Ao */
223 { termp_aq_pre
, termp_aq_post
}, /* Aq */
224 { termp_at_pre
, NULL
}, /* At */
225 { NULL
, NULL
}, /* Bc */
226 { termp_bf_pre
, NULL
}, /* Bf */
227 { termp_bq_pre
, termp_bq_post
}, /* Bo */
228 { termp_bq_pre
, termp_bq_post
}, /* Bq */
229 { termp_bsx_pre
, NULL
}, /* Bsx */
230 { termp_bx_pre
, NULL
}, /* Bx */
231 { NULL
, NULL
}, /* Db */
232 { NULL
, NULL
}, /* Dc */
233 { termp_dq_pre
, termp_dq_post
}, /* Do */
234 { termp_dq_pre
, termp_dq_post
}, /* Dq */
235 { NULL
, NULL
}, /* Ec */
236 { NULL
, NULL
}, /* Ef */
237 { termp_em_pre
, NULL
}, /* Em */
238 { NULL
, NULL
}, /* Eo */
239 { termp_fx_pre
, NULL
}, /* Fx */
240 { termp_ms_pre
, NULL
}, /* Ms */
241 { NULL
, NULL
}, /* No */
242 { termp_ns_pre
, NULL
}, /* Ns */
243 { termp_nx_pre
, NULL
}, /* Nx */
244 { termp_ox_pre
, NULL
}, /* Ox */
245 { NULL
, NULL
}, /* Pc */
246 { termp_pf_pre
, termp_pf_post
}, /* Pf */
247 { termp_pq_pre
, termp_pq_post
}, /* Po */
248 { termp_pq_pre
, termp_pq_post
}, /* Pq */
249 { NULL
, NULL
}, /* Qc */
250 { termp_sq_pre
, termp_sq_post
}, /* Ql */
251 { termp_qq_pre
, termp_qq_post
}, /* Qo */
252 { termp_qq_pre
, termp_qq_post
}, /* Qq */
253 { NULL
, NULL
}, /* Re */
254 { termp_rs_pre
, NULL
}, /* Rs */
255 { NULL
, NULL
}, /* Sc */
256 { termp_sq_pre
, termp_sq_post
}, /* So */
257 { termp_sq_pre
, termp_sq_post
}, /* Sq */
258 { termp_sm_pre
, NULL
}, /* Sm */
259 { termp_sx_pre
, NULL
}, /* Sx */
260 { termp_sy_pre
, NULL
}, /* Sy */
261 { NULL
, NULL
}, /* Tn */
262 { termp_ux_pre
, NULL
}, /* Ux */
263 { NULL
, NULL
}, /* Xc */
264 { NULL
, NULL
}, /* Xo */
265 { termp_fo_pre
, termp_fo_post
}, /* Fo */
266 { NULL
, NULL
}, /* Fc */
267 { termp_op_pre
, termp_op_post
}, /* Oo */
268 { NULL
, NULL
}, /* Oc */
269 { NULL
, NULL
}, /* Bk */
270 { NULL
, NULL
}, /* Ek */
271 { termp_bt_pre
, NULL
}, /* Bt */
272 { NULL
, NULL
}, /* Hf */
273 { NULL
, NULL
}, /* Fr */
274 { termp_ud_pre
, NULL
}, /* Ud */
277 const struct termact
*termacts
= __termacts
;
281 arg_width(const struct mdoc_arg
*arg
)
287 if (0 == strcmp(*arg
->value
, "indent"))
289 if (0 == strcmp(*arg
->value
, "indent-two"))
292 len
= (int)strlen(*arg
->value
);
295 for (i
= 0; i
< len
- 1; i
++)
296 if ( ! isdigit((int)(*arg
->value
)[i
]))
300 if ('n' == (*arg
->value
)[len
- 1]) {
301 v
= (size_t)atoi(*arg
->value
);
306 return(strlen(*arg
->value
) + 2);
311 arg_offset(const struct mdoc_arg
*arg
)
316 if (0 == strcmp(*arg
->value
, "indent"))
318 if (0 == strcmp(*arg
->value
, "indent-two"))
320 return(strlen(*arg
->value
));
325 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
328 return(-1 != arg_getattr(arg
, argc
, argv
));
333 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
337 for (i
= 0; i
< (int)argc
; i
++)
338 if (argv
[i
].arg
== arg
)
346 termp_dq_pre(DECL_ARGS
)
349 if (MDOC_BODY
!= node
->type
)
353 p
->flags
|= TERMP_NOSPACE
;
360 termp_dq_post(DECL_ARGS
)
363 if (MDOC_BODY
!= node
->type
)
366 p
->flags
|= TERMP_NOSPACE
;
373 termp_it_pre(DECL_ARGS
)
375 const struct mdoc_node
*n
, *it
;
376 const struct mdoc_block
*bl
;
379 size_t width
, offset
;
381 switch (node
->type
) {
394 n
= it
->parent
->parent
;
397 if (MDOC_BLOCK
== node
->type
) {
399 if ( ! arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
400 if (node
->prev
|| n
->prev
)
405 /* Get our list type. */
407 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++)
408 switch (bl
->argv
[i
].arg
) {
420 type
= bl
->argv
[i
].arg
;
424 errx(1, "list type not supported");
430 /* Save our existing (inherited) margin and offset. */
432 pair
->offset
= p
->offset
;
433 pair
->rmargin
= p
->rmargin
;
435 /* Get list width and offset. */
437 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
438 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
440 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
441 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
443 /* Override the width. */
453 width
= width
> 6 ? width
: 6;
456 /* FIXME: auto-size. */
458 errx(1, "need non-zero -width");
464 /* Word-wrap control. */
466 p
->flags
|= TERMP_NOSPACE
;
478 if (MDOC_HEAD
== node
->type
)
479 p
->flags
|= TERMP_NOBREAK
;
480 else if (MDOC_BODY
== node
->type
)
481 p
->flags
|= TERMP_NOLPAD
;
488 * Get a token to use as the HEAD lead-in. If NULL, we use the
494 if (MDOC_HEAD
== node
->type
) {
495 if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
))
497 if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
))
499 if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
500 (pair
->ppair
->ppair
->count
)++;
501 (void)snprintf(buf
, sizeof(buf
), "%d.",
502 pair
->ppair
->ppair
->count
);
505 if (arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
))
509 /* Margin control. */
523 if (MDOC_HEAD
== node
->type
)
524 p
->rmargin
= p
->offset
+ width
;
525 else if (MDOC_BODY
== node
->type
)
542 termp_it_post(DECL_ARGS
)
545 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
550 p
->offset
= pair
->offset
;
551 p
->rmargin
= pair
->rmargin
;
553 if (MDOC_HEAD
== node
->type
) {
554 p
->flags
&= ~TERMP_NOBREAK
;
555 p
->flags
&= ~TERMP_NORPAD
;
556 } else if (MDOC_BODY
== node
->type
)
557 p
->flags
&= ~TERMP_NOLPAD
;
563 termp_nm_pre(DECL_ARGS
)
566 if (SEC_SYNOPSIS
== node
->sec
)
569 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_PROG
]);
570 if (NULL
== node
->child
)
578 termp_fl_pre(DECL_ARGS
)
581 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
583 p
->flags
|= TERMP_NOSPACE
;
590 termp_ar_pre(DECL_ARGS
)
594 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_ARG
]);
597 p
->flags
|= ttypes
[TTYPE_CMD_ARG
];
600 p
->flags
&= ~ttypes
[TTYPE_CMD_ARG
];
607 termp_ns_pre(DECL_ARGS
)
610 p
->flags
|= TERMP_NOSPACE
;
617 termp_pp_pre(DECL_ARGS
)
627 termp_st_pre(DECL_ARGS
)
631 assert(1 == node
->data
.elem
.argc
);
633 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
642 termp_rs_pre(DECL_ARGS
)
645 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
653 termp_rv_pre(DECL_ARGS
)
657 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
658 node
->data
.elem
.argv
);
664 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
665 word(p
, *node
->data
.elem
.argv
[i
].value
);
666 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
668 word(p
, "() function returns the value 0 if successful;");
669 word(p
, "otherwise the value -1 is returned and the");
670 word(p
, "global variable");
672 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
674 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
676 word(p
, "is set to indicate the error.");
684 termp_ex_pre(DECL_ARGS
)
688 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
689 node
->data
.elem
.argv
);
693 p
->flags
|= ttypes
[TTYPE_PROG
];
694 word(p
, *node
->data
.elem
.argv
[i
].value
);
695 p
->flags
&= ~ttypes
[TTYPE_PROG
];
696 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
704 termp_nd_pre(DECL_ARGS
)
714 termp_bl_post(DECL_ARGS
)
717 if (MDOC_BLOCK
== node
->type
)
724 termp_op_post(DECL_ARGS
)
727 if (MDOC_BODY
!= node
->type
)
729 p
->flags
|= TERMP_NOSPACE
;
736 termp_xr_pre(DECL_ARGS
)
738 const struct mdoc_node
*n
;
743 assert(MDOC_TEXT
== n
->type
);
744 word(p
, n
->data
.text
.string
);
746 if (NULL
== (n
= n
->next
))
749 assert(MDOC_TEXT
== n
->type
);
750 p
->flags
|= TERMP_NOSPACE
;
752 p
->flags
|= TERMP_NOSPACE
;
753 word(p
, n
->data
.text
.string
);
754 p
->flags
|= TERMP_NOSPACE
;
763 termp_vt_pre(DECL_ARGS
)
766 /* FIXME: this can be "type name". */
767 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
774 termp_vt_post(DECL_ARGS
)
777 if (node
->sec
== SEC_SYNOPSIS
)
784 termp_fd_pre(DECL_ARGS
)
788 * FIXME: this naming is bad. This value is used, in general,
789 * for the #include header or other preprocessor statement.
791 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_DECL
]);
798 termp_fd_post(DECL_ARGS
)
801 if (node
->sec
!= SEC_SYNOPSIS
)
804 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
811 termp_sh_pre(DECL_ARGS
)
814 switch (node
->type
) {
817 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SECTION
]);
831 termp_sh_post(DECL_ARGS
)
834 switch (node
->type
) {
850 termp_op_pre(DECL_ARGS
)
853 switch (node
->type
) {
856 p
->flags
|= TERMP_NOSPACE
;
867 termp_bt_pre(DECL_ARGS
)
870 word(p
, "is currently in beta test.");
877 termp_ud_pre(DECL_ARGS
)
880 word(p
, "currently under development.");
887 termp_d1_pre(DECL_ARGS
)
890 if (MDOC_BODY
!= node
->type
)
893 p
->offset
+= (pair
->offset
= INDENT
);
900 termp_d1_post(DECL_ARGS
)
903 if (MDOC_BODY
!= node
->type
)
906 p
->offset
-= pair
->offset
;
912 termp_aq_pre(DECL_ARGS
)
915 if (MDOC_BODY
!= node
->type
)
918 p
->flags
|= TERMP_NOSPACE
;
925 termp_aq_post(DECL_ARGS
)
928 if (MDOC_BODY
!= node
->type
)
930 p
->flags
|= TERMP_NOSPACE
;
937 termp_ft_pre(DECL_ARGS
)
940 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_TYPE
]);
947 termp_ft_post(DECL_ARGS
)
950 if (node
->sec
== SEC_SYNOPSIS
)
957 termp_fn_pre(DECL_ARGS
)
959 const struct mdoc_node
*n
;
962 assert(MDOC_TEXT
== node
->child
->type
);
964 /* FIXME: can be "type funcname" "type varname"... */
966 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
967 word(p
, node
->child
->data
.text
.string
);
968 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
972 p
->flags
|= TERMP_NOSPACE
;
973 for (n
= node
->child
->next
; n
; n
= n
->next
) {
974 assert(MDOC_TEXT
== n
->type
);
975 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
976 word(p
, n
->data
.text
.string
);
977 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
984 if (SEC_SYNOPSIS
== node
->sec
)
993 termp_fn_post(DECL_ARGS
)
996 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1004 termp_sx_pre(DECL_ARGS
)
1007 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_LINK
]);
1014 termp_fa_pre(DECL_ARGS
)
1016 struct mdoc_node
*n
;
1018 if (node
->parent
->tok
!= MDOC_Fo
) {
1019 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_ARG
]);
1023 for (n
= node
->child
; n
; n
= n
->next
) {
1024 assert(MDOC_TEXT
== n
->type
);
1026 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1027 word(p
, n
->data
.text
.string
);
1028 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1034 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1043 termp_va_pre(DECL_ARGS
)
1046 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
1053 termp_bd_pre(DECL_ARGS
)
1055 const struct mdoc_block
*bl
;
1056 const struct mdoc_node
*n
;
1059 if (MDOC_BLOCK
== node
->type
) {
1063 } else if (MDOC_BODY
!= node
->type
)
1066 assert(MDOC_BLOCK
== node
->parent
->type
);
1067 pair
->offset
= p
->offset
;
1069 bl
= &node
->parent
->data
.block
;
1072 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1074 assert(1 == bl
->argv
[i
].sz
);
1075 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1078 if ( ! arg_hasattr(MDOC_Literal
, bl
->argc
, bl
->argv
))
1081 p
->flags
|= TERMP_LITERAL
;
1083 for (n
= node
->child
; n
; n
= n
->next
) {
1084 assert(MDOC_TEXT
== n
->type
); /* FIXME */
1085 if ((*n
->data
.text
.string
)) {
1086 word(p
, n
->data
.text
.string
);
1093 p
->flags
&= ~TERMP_LITERAL
;
1100 termp_bd_post(DECL_ARGS
)
1103 if (MDOC_BODY
!= node
->type
)
1106 p
->offset
= pair
->offset
;
1112 termp_qq_pre(DECL_ARGS
)
1115 if (MDOC_BODY
!= node
->type
)
1118 p
->flags
|= TERMP_NOSPACE
;
1125 termp_qq_post(DECL_ARGS
)
1128 if (MDOC_BODY
!= node
->type
)
1130 p
->flags
|= TERMP_NOSPACE
;
1137 termp_bsx_pre(DECL_ARGS
)
1140 word(p
, "BSDI BSD/OS");
1147 termp_bx_pre(DECL_ARGS
)
1157 termp_ox_pre(DECL_ARGS
)
1167 termp_ux_pre(DECL_ARGS
)
1177 termp_fx_pre(DECL_ARGS
)
1187 termp_nx_pre(DECL_ARGS
)
1197 termp_sq_pre(DECL_ARGS
)
1200 if (MDOC_BODY
!= node
->type
)
1203 p
->flags
|= TERMP_NOSPACE
;
1210 termp_sq_post(DECL_ARGS
)
1213 if (MDOC_BODY
!= node
->type
)
1215 p
->flags
|= TERMP_NOSPACE
;
1222 termp_pf_pre(DECL_ARGS
)
1225 p
->flags
|= TERMP_IGNDELIM
;
1232 termp_pf_post(DECL_ARGS
)
1235 p
->flags
&= ~TERMP_IGNDELIM
;
1236 p
->flags
|= TERMP_NOSPACE
;
1242 termp_ss_pre(DECL_ARGS
)
1245 switch (node
->type
) {
1248 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SSECTION
]);
1249 p
->offset
= INDENT
/ 2;
1261 termp_ss_post(DECL_ARGS
)
1264 switch (node
->type
) {
1277 termp_pa_pre(DECL_ARGS
)
1280 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FILE
]);
1287 termp_em_pre(DECL_ARGS
)
1290 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1297 termp_cd_pre(DECL_ARGS
)
1300 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CONFIG
]);
1307 termp_cm_pre(DECL_ARGS
)
1310 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
1317 termp_ic_pre(DECL_ARGS
)
1320 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD
]);
1327 termp_in_pre(DECL_ARGS
)
1330 p
->flags
|= ttypes
[TTYPE_INCLUDE
];
1331 word(p
, "#include");
1333 p
->flags
&= ~ttypes
[TTYPE_INCLUDE
];
1334 p
->flags
|= TERMP_NOSPACE
;
1335 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_INCLUDE
]);
1342 termp_in_post(DECL_ARGS
)
1345 p
->flags
|= TERMP_NOSPACE
;
1349 if (SEC_SYNOPSIS
!= node
->sec
)
1351 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1358 termp_at_pre(DECL_ARGS
)
1364 assert(MDOC_TEXT
== node
->child
->type
);
1365 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1368 word(p
, mdoc_att2a(c
));
1375 termp_bq_pre(DECL_ARGS
)
1378 if (MDOC_BODY
!= node
->type
)
1381 p
->flags
|= TERMP_NOSPACE
;
1388 termp_bq_post(DECL_ARGS
)
1391 if (MDOC_BODY
!= node
->type
)
1399 termp_pq_pre(DECL_ARGS
)
1402 if (MDOC_BODY
!= node
->type
)
1405 p
->flags
|= TERMP_NOSPACE
;
1412 termp_pq_post(DECL_ARGS
)
1415 if (MDOC_BODY
!= node
->type
)
1423 termp_fo_pre(DECL_ARGS
)
1425 const struct mdoc_node
*n
;
1427 if (MDOC_BODY
== node
->type
) {
1429 p
->flags
|= TERMP_NOSPACE
;
1431 } else if (MDOC_HEAD
!= node
->type
)
1434 /* XXX - groff shows only first parameter */
1436 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1437 for (n
= node
->child
; n
; n
= n
->next
) {
1438 assert(MDOC_TEXT
== n
->type
);
1439 word(p
, n
->data
.text
.string
);
1441 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1449 termp_fo_post(DECL_ARGS
)
1452 if (MDOC_BODY
!= node
->type
)
1462 termp_bf_pre(DECL_ARGS
)
1464 const struct mdoc_node
*n
;
1465 const struct mdoc_block
*b
;
1467 /* XXX - we skip over possible trailing HEAD tokens. */
1469 if (MDOC_HEAD
== node
->type
)
1471 else if (MDOC_BLOCK
!= node
->type
)
1474 b
= &node
->data
.block
;
1476 if (NULL
== (n
= b
->head
->child
)) {
1477 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1478 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1479 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1480 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1485 assert(MDOC_TEXT
== n
->type
);
1487 if (0 == strcmp("Em", n
->data
.text
.string
))
1488 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1489 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1490 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1498 termp_sy_pre(DECL_ARGS
)
1501 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1508 termp_ms_pre(DECL_ARGS
)
1511 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMBOL
]);
1519 termp_sm_pre(DECL_ARGS
)
1523 assert(node
->child
);
1524 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1525 p
->flags
&= ~TERMP_NONOSPACE
;
1526 p
->flags
&= ~TERMP_NOSPACE
;
1528 p
->flags
|= TERMP_NONOSPACE
;
1529 p
->flags
|= TERMP_NOSPACE
;
1539 termp__t_pre(DECL_ARGS
)
1543 p
->flags
|= TERMP_NOSPACE
;
1550 termp__t_post(DECL_ARGS
)
1553 p
->flags
|= TERMP_NOSPACE
;
1555 word(p
, node
->next
? "," : ".");
1561 termp____post(DECL_ARGS
)
1564 p
->flags
|= TERMP_NOSPACE
;
1565 word(p
, node
->next
? "," : ".");