]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
2f10c0a53dcc6b5bfd21fdc810dc683e7e137d02
1 /* $Id: term.c,v 1.33 2009/03/01 23:27:14 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 { NULL
, termp_bx_post
}, /* 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
) + 1);
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 else if (MDOC_BODY
== node
->type
)
556 p
->flags
&= ~TERMP_NOLPAD
;
562 termp_nm_pre(DECL_ARGS
)
565 if (SEC_SYNOPSIS
== node
->sec
)
568 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
569 if (NULL
== node
->child
)
578 termp_fl_pre(DECL_ARGS
)
581 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
583 p
->flags
|= TERMP_NOSPACE
;
590 termp_ar_pre(DECL_ARGS
)
593 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
594 if (NULL
== node
->child
) {
604 termp_ns_pre(DECL_ARGS
)
607 p
->flags
|= TERMP_NOSPACE
;
614 termp_pp_pre(DECL_ARGS
)
624 termp_st_pre(DECL_ARGS
)
628 assert(1 == node
->data
.elem
.argc
);
630 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
639 termp_rs_pre(DECL_ARGS
)
642 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
650 termp_rv_pre(DECL_ARGS
)
654 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
655 node
->data
.elem
.argv
);
661 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
662 word(p
, *node
->data
.elem
.argv
[i
].value
);
663 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
665 word(p
, "() function returns the value 0 if successful;");
666 word(p
, "otherwise the value -1 is returned and the");
667 word(p
, "global variable");
669 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
671 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
673 word(p
, "is set to indicate the error.");
681 termp_ex_pre(DECL_ARGS
)
685 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
686 node
->data
.elem
.argv
);
690 p
->flags
|= ttypes
[TTYPE_PROG
];
691 word(p
, *node
->data
.elem
.argv
[i
].value
);
692 p
->flags
&= ~ttypes
[TTYPE_PROG
];
693 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
701 termp_nd_pre(DECL_ARGS
)
711 termp_bl_post(DECL_ARGS
)
714 if (MDOC_BLOCK
== node
->type
)
721 termp_op_post(DECL_ARGS
)
724 if (MDOC_BODY
!= node
->type
)
726 p
->flags
|= TERMP_NOSPACE
;
733 termp_xr_pre(DECL_ARGS
)
735 const struct mdoc_node
*n
;
740 assert(MDOC_TEXT
== n
->type
);
741 word(p
, n
->data
.text
.string
);
743 if (NULL
== (n
= n
->next
))
746 assert(MDOC_TEXT
== n
->type
);
747 p
->flags
|= TERMP_NOSPACE
;
749 p
->flags
|= TERMP_NOSPACE
;
750 word(p
, n
->data
.text
.string
);
751 p
->flags
|= TERMP_NOSPACE
;
760 termp_vt_pre(DECL_ARGS
)
763 /* FIXME: this can be "type name". */
764 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
771 termp_vt_post(DECL_ARGS
)
774 if (node
->sec
== SEC_SYNOPSIS
)
781 termp_fd_pre(DECL_ARGS
)
785 * FIXME: this naming is bad. This value is used, in general,
786 * for the #include header or other preprocessor statement.
788 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
795 termp_fd_post(DECL_ARGS
)
798 if (node
->sec
!= SEC_SYNOPSIS
)
801 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
808 termp_sh_pre(DECL_ARGS
)
811 switch (node
->type
) {
814 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
828 termp_sh_post(DECL_ARGS
)
831 switch (node
->type
) {
847 termp_op_pre(DECL_ARGS
)
850 switch (node
->type
) {
853 p
->flags
|= TERMP_NOSPACE
;
864 termp_bt_pre(DECL_ARGS
)
867 word(p
, "is currently in beta test.");
874 termp_ud_pre(DECL_ARGS
)
877 word(p
, "currently under development.");
884 termp_d1_pre(DECL_ARGS
)
887 if (MDOC_BODY
!= node
->type
)
890 p
->offset
+= (pair
->offset
= INDENT
);
897 termp_d1_post(DECL_ARGS
)
900 if (MDOC_BODY
!= node
->type
)
903 p
->offset
-= pair
->offset
;
909 termp_aq_pre(DECL_ARGS
)
912 if (MDOC_BODY
!= node
->type
)
915 p
->flags
|= TERMP_NOSPACE
;
922 termp_aq_post(DECL_ARGS
)
925 if (MDOC_BODY
!= node
->type
)
927 p
->flags
|= TERMP_NOSPACE
;
934 termp_ft_pre(DECL_ARGS
)
937 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
944 termp_ft_post(DECL_ARGS
)
947 if (node
->sec
== SEC_SYNOPSIS
)
954 termp_fn_pre(DECL_ARGS
)
956 const struct mdoc_node
*n
;
959 assert(MDOC_TEXT
== node
->child
->type
);
961 /* FIXME: can be "type funcname" "type varname"... */
963 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
964 word(p
, node
->child
->data
.text
.string
);
965 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
969 p
->flags
|= TERMP_NOSPACE
;
970 for (n
= node
->child
->next
; n
; n
= n
->next
) {
971 assert(MDOC_TEXT
== n
->type
);
972 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
973 word(p
, n
->data
.text
.string
);
974 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
981 if (SEC_SYNOPSIS
== node
->sec
)
990 termp_fn_post(DECL_ARGS
)
993 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1001 termp_sx_pre(DECL_ARGS
)
1004 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1011 termp_fa_pre(DECL_ARGS
)
1013 struct mdoc_node
*n
;
1015 if (node
->parent
->tok
!= MDOC_Fo
) {
1016 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1020 for (n
= node
->child
; n
; n
= n
->next
) {
1021 assert(MDOC_TEXT
== n
->type
);
1023 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1024 word(p
, n
->data
.text
.string
);
1025 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1031 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1040 termp_va_pre(DECL_ARGS
)
1043 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1050 termp_bd_pre(DECL_ARGS
)
1052 const struct mdoc_block
*bl
;
1053 const struct mdoc_node
*n
;
1056 if (MDOC_BLOCK
== node
->type
) {
1060 } else if (MDOC_BODY
!= node
->type
)
1063 assert(MDOC_BLOCK
== node
->parent
->type
);
1064 pair
->offset
= p
->offset
;
1066 bl
= &node
->parent
->data
.block
;
1068 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1070 assert(1 == bl
->argv
[i
].sz
);
1071 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1074 p
->flags
|= TERMP_LITERAL
;
1076 for (n
= node
->child
; n
; n
= n
->next
) {
1077 if (MDOC_TEXT
!= n
->type
)
1078 errx(1, "non-text displays unsupported");
1079 if ((*n
->data
.text
.string
)) {
1080 word(p
, n
->data
.text
.string
);
1087 p
->flags
&= ~TERMP_LITERAL
;
1094 termp_bd_post(DECL_ARGS
)
1097 if (MDOC_BODY
!= node
->type
)
1100 p
->offset
= pair
->offset
;
1106 termp_qq_pre(DECL_ARGS
)
1109 if (MDOC_BODY
!= node
->type
)
1112 p
->flags
|= TERMP_NOSPACE
;
1119 termp_qq_post(DECL_ARGS
)
1122 if (MDOC_BODY
!= node
->type
)
1124 p
->flags
|= TERMP_NOSPACE
;
1131 termp_bsx_pre(DECL_ARGS
)
1134 word(p
, "BSDI BSD/OS");
1141 termp_bx_post(DECL_ARGS
)
1144 p
->flags
|= TERMP_NOSPACE
;
1151 termp_ox_pre(DECL_ARGS
)
1161 termp_ux_pre(DECL_ARGS
)
1171 termp_fx_pre(DECL_ARGS
)
1181 termp_nx_pre(DECL_ARGS
)
1191 termp_sq_pre(DECL_ARGS
)
1194 if (MDOC_BODY
!= node
->type
)
1197 p
->flags
|= TERMP_NOSPACE
;
1204 termp_sq_post(DECL_ARGS
)
1207 if (MDOC_BODY
!= node
->type
)
1209 p
->flags
|= TERMP_NOSPACE
;
1216 termp_pf_pre(DECL_ARGS
)
1219 p
->flags
|= TERMP_IGNDELIM
;
1226 termp_pf_post(DECL_ARGS
)
1229 p
->flags
&= ~TERMP_IGNDELIM
;
1230 p
->flags
|= TERMP_NOSPACE
;
1236 termp_ss_pre(DECL_ARGS
)
1239 switch (node
->type
) {
1242 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1243 p
->offset
= INDENT
/ 2;
1255 termp_ss_post(DECL_ARGS
)
1258 switch (node
->type
) {
1271 termp_pa_pre(DECL_ARGS
)
1274 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1281 termp_em_pre(DECL_ARGS
)
1284 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1291 termp_cd_pre(DECL_ARGS
)
1294 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1302 termp_cm_pre(DECL_ARGS
)
1305 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1312 termp_ic_pre(DECL_ARGS
)
1315 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1322 termp_in_pre(DECL_ARGS
)
1325 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1326 word(p
, "#include");
1328 p
->flags
|= TERMP_NOSPACE
;
1335 termp_in_post(DECL_ARGS
)
1338 p
->flags
|= TERMP_NOSPACE
;
1342 if (SEC_SYNOPSIS
!= node
->sec
)
1344 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1351 termp_at_pre(DECL_ARGS
)
1357 assert(MDOC_TEXT
== node
->child
->type
);
1358 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1361 word(p
, mdoc_att2a(c
));
1368 termp_bq_pre(DECL_ARGS
)
1371 if (MDOC_BODY
!= node
->type
)
1374 p
->flags
|= TERMP_NOSPACE
;
1381 termp_bq_post(DECL_ARGS
)
1384 if (MDOC_BODY
!= node
->type
)
1392 termp_pq_pre(DECL_ARGS
)
1395 if (MDOC_BODY
!= node
->type
)
1398 p
->flags
|= TERMP_NOSPACE
;
1405 termp_pq_post(DECL_ARGS
)
1408 if (MDOC_BODY
!= node
->type
)
1416 termp_fo_pre(DECL_ARGS
)
1418 const struct mdoc_node
*n
;
1420 if (MDOC_BODY
== node
->type
) {
1422 p
->flags
|= TERMP_NOSPACE
;
1424 } else if (MDOC_HEAD
!= node
->type
)
1427 /* XXX - groff shows only first parameter */
1429 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1430 for (n
= node
->child
; n
; n
= n
->next
) {
1431 assert(MDOC_TEXT
== n
->type
);
1432 word(p
, n
->data
.text
.string
);
1434 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1442 termp_fo_post(DECL_ARGS
)
1445 if (MDOC_BODY
!= node
->type
)
1455 termp_bf_pre(DECL_ARGS
)
1457 const struct mdoc_node
*n
;
1458 const struct mdoc_block
*b
;
1460 /* XXX - we skip over possible trailing HEAD tokens. */
1462 if (MDOC_HEAD
== node
->type
)
1464 else if (MDOC_BLOCK
!= node
->type
)
1467 b
= &node
->data
.block
;
1469 if (NULL
== (n
= b
->head
->child
)) {
1470 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1471 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1472 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1473 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1478 assert(MDOC_TEXT
== n
->type
);
1480 if (0 == strcmp("Em", n
->data
.text
.string
))
1481 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1482 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1483 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1491 termp_sy_pre(DECL_ARGS
)
1494 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1501 termp_ms_pre(DECL_ARGS
)
1504 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1512 termp_sm_pre(DECL_ARGS
)
1516 assert(node
->child
);
1517 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1518 p
->flags
&= ~TERMP_NONOSPACE
;
1519 p
->flags
&= ~TERMP_NOSPACE
;
1521 p
->flags
|= TERMP_NONOSPACE
;
1522 p
->flags
|= TERMP_NOSPACE
;
1532 termp__t_pre(DECL_ARGS
)
1536 p
->flags
|= TERMP_NOSPACE
;
1543 termp__t_post(DECL_ARGS
)
1546 p
->flags
|= TERMP_NOSPACE
;
1548 word(p
, node
->next
? "," : ".");
1554 termp____post(DECL_ARGS
)
1557 p
->flags
|= TERMP_NOSPACE
;
1558 word(p
, node
->next
? "," : ".");