]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
e1fa44da23f3308da1146805af1fab906b44ec40
1 /* $Id: term.c,v 1.34 2009/03/02 12:09:32 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: indent/tab. */
34 /* FIXME: macro arguments can be escaped. */
37 #define TTYPE_CMD_FLAG 1
38 #define TTYPE_CMD_ARG 2
39 #define TTYPE_SECTION 3
40 #define TTYPE_FUNC_DECL 4
41 #define TTYPE_VAR_DECL 5
42 #define TTYPE_FUNC_TYPE 6
43 #define TTYPE_FUNC_NAME 7
44 #define TTYPE_FUNC_ARG 8
46 #define TTYPE_SSECTION 10
49 #define TTYPE_CONFIG 13
51 #define TTYPE_INCLUDE 15
53 #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 const int ttypes
[TTYPE_NMAX
] = {
63 TERMP_BOLD
, /* TTYPE_PROG */
64 TERMP_BOLD
, /* TTYPE_CMD_FLAG */
65 TERMP_UNDERLINE
, /* TTYPE_CMD_ARG */
66 TERMP_BOLD
, /* TTYPE_SECTION */
67 TERMP_BOLD
, /* TTYPE_FUNC_DECL */
68 TERMP_UNDERLINE
, /* TTYPE_VAR_DECL */
69 TERMP_UNDERLINE
, /* TTYPE_FUNC_TYPE */
70 TERMP_BOLD
, /* TTYPE_FUNC_NAME */
71 TERMP_UNDERLINE
, /* TTYPE_FUNC_ARG */
72 TERMP_UNDERLINE
, /* TTYPE_LINK */
73 TERMP_BOLD
, /* TTYPE_SSECTION */
74 TERMP_UNDERLINE
, /* TTYPE_FILE */
75 TERMP_UNDERLINE
, /* TTYPE_EMPH */
76 TERMP_BOLD
, /* TTYPE_CONFIG */
77 TERMP_BOLD
, /* TTYPE_CMD */
78 TERMP_BOLD
, /* TTYPE_INCLUDE */
79 TERMP_BOLD
, /* TTYPE_SYMB */
80 TERMP_BOLD
/* TTYPE_SYMBOL */
83 static int arg_hasattr(int, size_t,
84 const struct mdoc_arg
*);
85 static int arg_getattr(int, size_t,
86 const struct mdoc_arg
*);
87 static size_t arg_offset(const struct mdoc_arg
*);
88 static size_t arg_width(const struct mdoc_arg
*);
91 * What follows describes prefix and postfix operations for the abstract
92 * syntax tree descent.
97 struct termpair *pair, \
98 const struct mdoc_meta *meta, \
99 const struct mdoc_node *node
101 #define DECL_PRE(name) \
102 static int name##_pre(DECL_ARGS)
103 #define DECL_POST(name) \
104 static void name##_post(DECL_ARGS)
105 #define DECL_PREPOST(name) \
109 DECL_PREPOST(termp__t
);
110 DECL_PREPOST(termp_aq
);
111 DECL_PREPOST(termp_bd
);
112 DECL_PREPOST(termp_bq
);
113 DECL_PREPOST(termp_d1
);
114 DECL_PREPOST(termp_dq
);
115 DECL_PREPOST(termp_fd
);
116 DECL_PREPOST(termp_fn
);
117 DECL_PREPOST(termp_fo
);
118 DECL_PREPOST(termp_ft
);
119 DECL_PREPOST(termp_in
);
120 DECL_PREPOST(termp_it
);
121 DECL_PREPOST(termp_op
);
122 DECL_PREPOST(termp_pf
);
123 DECL_PREPOST(termp_pq
);
124 DECL_PREPOST(termp_qq
);
125 DECL_PREPOST(termp_sh
);
126 DECL_PREPOST(termp_ss
);
127 DECL_PREPOST(termp_sq
);
128 DECL_PREPOST(termp_vt
);
166 const struct termact __termacts
[MDOC_MAX
] = {
167 { NULL
, NULL
}, /* \" */
168 { NULL
, NULL
}, /* Dd */
169 { NULL
, NULL
}, /* Dt */
170 { NULL
, NULL
}, /* Os */
171 { termp_sh_pre
, termp_sh_post
}, /* Sh */
172 { termp_ss_pre
, termp_ss_post
}, /* Ss */
173 { termp_pp_pre
, NULL
}, /* Pp */
174 { termp_d1_pre
, termp_d1_post
}, /* D1 */
175 { termp_d1_pre
, termp_d1_post
}, /* Dl */
176 { termp_bd_pre
, termp_bd_post
}, /* Bd */
177 { NULL
, NULL
}, /* Ed */
178 { NULL
, termp_bl_post
}, /* Bl */
179 { NULL
, NULL
}, /* El */
180 { termp_it_pre
, termp_it_post
}, /* It */
181 { NULL
, NULL
}, /* Ad */
182 { NULL
, NULL
}, /* An */
183 { termp_ar_pre
, NULL
}, /* Ar */
184 { termp_cd_pre
, NULL
}, /* Cd */
185 { termp_cm_pre
, NULL
}, /* Cm */
186 { NULL
, NULL
}, /* Dv */
187 { NULL
, NULL
}, /* Er */
188 { NULL
, NULL
}, /* Ev */
189 { termp_ex_pre
, NULL
}, /* Ex */
190 { termp_fa_pre
, NULL
}, /* Fa */
191 { termp_fd_pre
, termp_fd_post
}, /* Fd */
192 { termp_fl_pre
, NULL
}, /* Fl */
193 { termp_fn_pre
, termp_fn_post
}, /* Fn */
194 { termp_ft_pre
, termp_ft_post
}, /* Ft */
195 { termp_ic_pre
, NULL
}, /* Ic */
196 { termp_in_pre
, termp_in_post
}, /* In */
197 { NULL
, NULL
}, /* Li */
198 { termp_nd_pre
, NULL
}, /* Nd */
199 { termp_nm_pre
, NULL
}, /* Nm */
200 { termp_op_pre
, termp_op_post
}, /* Op */
201 { NULL
, NULL
}, /* Ot */
202 { termp_pa_pre
, NULL
}, /* Pa */
203 { termp_rv_pre
, NULL
}, /* Rv */
204 { termp_st_pre
, NULL
}, /* St */
205 { termp_va_pre
, NULL
}, /* Va */
206 { termp_vt_pre
, termp_vt_post
}, /* Vt */
207 { termp_xr_pre
, NULL
}, /* Xr */
208 { NULL
, termp____post
}, /* %A */
209 { NULL
, termp____post
}, /* %B */
210 { NULL
, termp____post
}, /* %D */
211 { NULL
, termp____post
}, /* %I */
212 { NULL
, termp____post
}, /* %J */
213 { NULL
, termp____post
}, /* %N */
214 { NULL
, termp____post
}, /* %O */
215 { NULL
, termp____post
}, /* %P */
216 { NULL
, termp____post
}, /* %R */
217 { termp__t_pre
, termp__t_post
}, /* %T */
218 { NULL
, termp____post
}, /* %V */
219 { NULL
, NULL
}, /* Ac */
220 { termp_aq_pre
, termp_aq_post
}, /* Ao */
221 { termp_aq_pre
, termp_aq_post
}, /* Aq */
222 { termp_at_pre
, NULL
}, /* At */
223 { NULL
, NULL
}, /* Bc */
224 { termp_bf_pre
, NULL
}, /* Bf */
225 { termp_bq_pre
, termp_bq_post
}, /* Bo */
226 { termp_bq_pre
, termp_bq_post
}, /* Bq */
227 { termp_bsx_pre
, NULL
}, /* Bsx */
228 { NULL
, termp_bx_post
}, /* Bx */
229 { NULL
, NULL
}, /* Db */
230 { NULL
, NULL
}, /* Dc */
231 { termp_dq_pre
, termp_dq_post
}, /* Do */
232 { termp_dq_pre
, termp_dq_post
}, /* Dq */
233 { NULL
, NULL
}, /* Ec */
234 { NULL
, NULL
}, /* Ef */
235 { termp_em_pre
, NULL
}, /* Em */
236 { NULL
, NULL
}, /* Eo */
237 { termp_fx_pre
, NULL
}, /* Fx */
238 { termp_ms_pre
, NULL
}, /* Ms */
239 { NULL
, NULL
}, /* No */
240 { termp_ns_pre
, NULL
}, /* Ns */
241 { termp_nx_pre
, NULL
}, /* Nx */
242 { termp_ox_pre
, NULL
}, /* Ox */
243 { NULL
, NULL
}, /* Pc */
244 { termp_pf_pre
, termp_pf_post
}, /* Pf */
245 { termp_pq_pre
, termp_pq_post
}, /* Po */
246 { termp_pq_pre
, termp_pq_post
}, /* Pq */
247 { NULL
, NULL
}, /* Qc */
248 { termp_sq_pre
, termp_sq_post
}, /* Ql */
249 { termp_qq_pre
, termp_qq_post
}, /* Qo */
250 { termp_qq_pre
, termp_qq_post
}, /* Qq */
251 { NULL
, NULL
}, /* Re */
252 { termp_rs_pre
, NULL
}, /* Rs */
253 { NULL
, NULL
}, /* Sc */
254 { termp_sq_pre
, termp_sq_post
}, /* So */
255 { termp_sq_pre
, termp_sq_post
}, /* Sq */
256 { termp_sm_pre
, NULL
}, /* Sm */
257 { termp_sx_pre
, NULL
}, /* Sx */
258 { termp_sy_pre
, NULL
}, /* Sy */
259 { NULL
, NULL
}, /* Tn */
260 { termp_ux_pre
, NULL
}, /* Ux */
261 { NULL
, NULL
}, /* Xc */
262 { NULL
, NULL
}, /* Xo */
263 { termp_fo_pre
, termp_fo_post
}, /* Fo */
264 { NULL
, NULL
}, /* Fc */
265 { termp_op_pre
, termp_op_post
}, /* Oo */
266 { NULL
, NULL
}, /* Oc */
267 { NULL
, NULL
}, /* Bk */
268 { NULL
, NULL
}, /* Ek */
269 { termp_bt_pre
, NULL
}, /* Bt */
270 { NULL
, NULL
}, /* Hf */
271 { NULL
, NULL
}, /* Fr */
272 { termp_ud_pre
, NULL
}, /* Ud */
275 const struct termact
*termacts
= __termacts
;
279 arg_width(const struct mdoc_arg
*arg
)
285 if (0 == strcmp(*arg
->value
, "indent"))
287 if (0 == strcmp(*arg
->value
, "indent-two"))
290 len
= (int)strlen(*arg
->value
);
293 for (i
= 0; i
< len
- 1; i
++)
294 if ( ! isdigit((int)(*arg
->value
)[i
]))
298 if ('n' == (*arg
->value
)[len
- 1]) {
299 v
= (size_t)atoi(*arg
->value
);
304 return(strlen(*arg
->value
) + 1);
309 arg_offset(const struct mdoc_arg
*arg
)
314 if (0 == strcmp(*arg
->value
, "indent"))
316 if (0 == strcmp(*arg
->value
, "indent-two"))
318 return(strlen(*arg
->value
));
323 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
326 return(-1 != arg_getattr(arg
, argc
, argv
));
331 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
335 for (i
= 0; i
< (int)argc
; i
++)
336 if (argv
[i
].arg
== arg
)
344 termp_dq_pre(DECL_ARGS
)
347 if (MDOC_BODY
!= node
->type
)
351 p
->flags
|= TERMP_NOSPACE
;
358 termp_dq_post(DECL_ARGS
)
361 if (MDOC_BODY
!= node
->type
)
364 p
->flags
|= TERMP_NOSPACE
;
371 termp_it_pre(DECL_ARGS
)
373 const struct mdoc_node
*n
, *it
;
374 const struct mdoc_block
*bl
;
377 size_t width
, offset
;
379 switch (node
->type
) {
392 n
= it
->parent
->parent
;
395 if (MDOC_BLOCK
== node
->type
) {
397 if ( ! arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
398 if (node
->prev
|| n
->prev
)
403 /* Get our list type. */
405 for (type
= -1, i
= 0; i
< (int)bl
->argc
; i
++)
406 switch (bl
->argv
[i
].arg
) {
418 type
= bl
->argv
[i
].arg
;
422 errx(1, "list type not supported");
428 /* Save our existing (inherited) margin and offset. */
430 pair
->offset
= p
->offset
;
431 pair
->rmargin
= p
->rmargin
;
433 /* Get list width and offset. */
435 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
436 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 0;
438 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
439 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
441 /* Override the width. */
451 width
= width
> 6 ? width
: 6;
454 /* FIXME: auto-size. */
456 errx(1, "need non-zero -width");
462 /* Word-wrap control. */
464 p
->flags
|= TERMP_NOSPACE
;
476 if (MDOC_HEAD
== node
->type
)
477 p
->flags
|= TERMP_NOBREAK
;
478 else if (MDOC_BODY
== node
->type
)
479 p
->flags
|= TERMP_NOLPAD
;
486 * Get a token to use as the HEAD lead-in. If NULL, we use the
492 if (MDOC_HEAD
== node
->type
) {
493 if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
))
495 if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
))
497 if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
498 (pair
->ppair
->ppair
->count
)++;
499 (void)snprintf(buf
, sizeof(buf
), "%d.",
500 pair
->ppair
->ppair
->count
);
503 if (arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
))
507 /* Margin control. */
521 if (MDOC_HEAD
== node
->type
)
522 p
->rmargin
= p
->offset
+ width
;
523 else if (MDOC_BODY
== node
->type
)
540 termp_it_post(DECL_ARGS
)
543 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
548 p
->offset
= pair
->offset
;
549 p
->rmargin
= pair
->rmargin
;
551 if (MDOC_HEAD
== node
->type
)
552 p
->flags
&= ~TERMP_NOBREAK
;
553 else if (MDOC_BODY
== node
->type
)
554 p
->flags
&= ~TERMP_NOLPAD
;
560 termp_nm_pre(DECL_ARGS
)
563 if (SEC_SYNOPSIS
== node
->sec
)
566 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
567 if (NULL
== node
->child
)
576 termp_fl_pre(DECL_ARGS
)
579 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
581 p
->flags
|= TERMP_NOSPACE
;
588 termp_ar_pre(DECL_ARGS
)
591 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
592 if (NULL
== node
->child
) {
602 termp_ns_pre(DECL_ARGS
)
605 p
->flags
|= TERMP_NOSPACE
;
612 termp_pp_pre(DECL_ARGS
)
622 termp_st_pre(DECL_ARGS
)
626 assert(1 == node
->data
.elem
.argc
);
628 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
637 termp_rs_pre(DECL_ARGS
)
640 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
648 termp_rv_pre(DECL_ARGS
)
652 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
653 node
->data
.elem
.argv
);
659 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
660 word(p
, *node
->data
.elem
.argv
[i
].value
);
661 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
663 word(p
, "() function returns the value 0 if successful;");
664 word(p
, "otherwise the value -1 is returned and the");
665 word(p
, "global variable");
667 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
669 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
671 word(p
, "is set to indicate the error.");
679 termp_ex_pre(DECL_ARGS
)
683 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
684 node
->data
.elem
.argv
);
688 p
->flags
|= ttypes
[TTYPE_PROG
];
689 word(p
, *node
->data
.elem
.argv
[i
].value
);
690 p
->flags
&= ~ttypes
[TTYPE_PROG
];
691 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
699 termp_nd_pre(DECL_ARGS
)
709 termp_bl_post(DECL_ARGS
)
712 if (MDOC_BLOCK
== node
->type
)
719 termp_op_post(DECL_ARGS
)
722 if (MDOC_BODY
!= node
->type
)
724 p
->flags
|= TERMP_NOSPACE
;
731 termp_xr_pre(DECL_ARGS
)
733 const struct mdoc_node
*n
;
738 assert(MDOC_TEXT
== n
->type
);
739 word(p
, n
->data
.text
.string
);
741 if (NULL
== (n
= n
->next
))
744 assert(MDOC_TEXT
== n
->type
);
745 p
->flags
|= TERMP_NOSPACE
;
747 p
->flags
|= TERMP_NOSPACE
;
748 word(p
, n
->data
.text
.string
);
749 p
->flags
|= TERMP_NOSPACE
;
758 termp_vt_pre(DECL_ARGS
)
761 /* FIXME: this can be "type name". */
762 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
769 termp_vt_post(DECL_ARGS
)
772 if (node
->sec
== SEC_SYNOPSIS
)
779 termp_fd_pre(DECL_ARGS
)
783 * FIXME: this naming is bad. This value is used, in general,
784 * for the #include header or other preprocessor statement.
786 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
793 termp_fd_post(DECL_ARGS
)
796 if (node
->sec
!= SEC_SYNOPSIS
)
799 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
806 termp_sh_pre(DECL_ARGS
)
809 switch (node
->type
) {
812 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
826 termp_sh_post(DECL_ARGS
)
829 switch (node
->type
) {
845 termp_op_pre(DECL_ARGS
)
848 switch (node
->type
) {
851 p
->flags
|= TERMP_NOSPACE
;
862 termp_bt_pre(DECL_ARGS
)
865 word(p
, "is currently in beta test.");
872 termp_ud_pre(DECL_ARGS
)
875 word(p
, "currently under development.");
882 termp_d1_pre(DECL_ARGS
)
885 if (MDOC_BODY
!= node
->type
)
888 p
->offset
+= (pair
->offset
= INDENT
);
895 termp_d1_post(DECL_ARGS
)
898 if (MDOC_BODY
!= node
->type
)
901 p
->offset
-= pair
->offset
;
907 termp_aq_pre(DECL_ARGS
)
910 if (MDOC_BODY
!= node
->type
)
913 p
->flags
|= TERMP_NOSPACE
;
920 termp_aq_post(DECL_ARGS
)
923 if (MDOC_BODY
!= node
->type
)
925 p
->flags
|= TERMP_NOSPACE
;
932 termp_ft_pre(DECL_ARGS
)
935 if (SEC_SYNOPSIS
== node
->sec
)
936 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
938 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
945 termp_ft_post(DECL_ARGS
)
948 if (SEC_SYNOPSIS
== node
->sec
)
955 termp_fn_pre(DECL_ARGS
)
957 const struct mdoc_node
*n
;
960 assert(MDOC_TEXT
== node
->child
->type
);
962 /* FIXME: can be "type funcname" "type varname"... */
964 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
965 word(p
, node
->child
->data
.text
.string
);
966 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
970 p
->flags
|= TERMP_NOSPACE
;
971 for (n
= node
->child
->next
; n
; n
= n
->next
) {
972 assert(MDOC_TEXT
== n
->type
);
973 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
974 word(p
, n
->data
.text
.string
);
975 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
982 if (SEC_SYNOPSIS
== node
->sec
)
991 termp_fn_post(DECL_ARGS
)
994 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1002 termp_sx_pre(DECL_ARGS
)
1005 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1012 termp_fa_pre(DECL_ARGS
)
1014 struct mdoc_node
*n
;
1016 if (node
->parent
->tok
!= MDOC_Fo
) {
1017 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1021 for (n
= node
->child
; n
; n
= n
->next
) {
1022 assert(MDOC_TEXT
== n
->type
);
1024 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1025 word(p
, n
->data
.text
.string
);
1026 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1032 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1041 termp_va_pre(DECL_ARGS
)
1044 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1051 termp_bd_pre(DECL_ARGS
)
1053 const struct mdoc_block
*bl
;
1054 const struct mdoc_node
*n
;
1057 if (MDOC_BLOCK
== node
->type
) {
1061 } else if (MDOC_BODY
!= node
->type
)
1064 assert(MDOC_BLOCK
== node
->parent
->type
);
1065 pair
->offset
= p
->offset
;
1067 bl
= &node
->parent
->data
.block
;
1069 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
1071 assert(1 == bl
->argv
[i
].sz
);
1072 p
->offset
+= arg_offset(&bl
->argv
[i
]);
1075 p
->flags
|= TERMP_LITERAL
;
1077 for (n
= node
->child
; n
; n
= n
->next
) {
1078 if (MDOC_TEXT
!= n
->type
)
1079 errx(1, "non-text displays unsupported");
1080 if ((*n
->data
.text
.string
)) {
1081 word(p
, n
->data
.text
.string
);
1088 p
->flags
&= ~TERMP_LITERAL
;
1095 termp_bd_post(DECL_ARGS
)
1098 if (MDOC_BODY
!= node
->type
)
1101 p
->offset
= pair
->offset
;
1107 termp_qq_pre(DECL_ARGS
)
1110 if (MDOC_BODY
!= node
->type
)
1113 p
->flags
|= TERMP_NOSPACE
;
1120 termp_qq_post(DECL_ARGS
)
1123 if (MDOC_BODY
!= node
->type
)
1125 p
->flags
|= TERMP_NOSPACE
;
1132 termp_bsx_pre(DECL_ARGS
)
1135 word(p
, "BSDI BSD/OS");
1142 termp_bx_post(DECL_ARGS
)
1146 p
->flags
|= TERMP_NOSPACE
;
1153 termp_ox_pre(DECL_ARGS
)
1163 termp_ux_pre(DECL_ARGS
)
1173 termp_fx_pre(DECL_ARGS
)
1183 termp_nx_pre(DECL_ARGS
)
1193 termp_sq_pre(DECL_ARGS
)
1196 if (MDOC_BODY
!= node
->type
)
1199 p
->flags
|= TERMP_NOSPACE
;
1206 termp_sq_post(DECL_ARGS
)
1209 if (MDOC_BODY
!= node
->type
)
1211 p
->flags
|= TERMP_NOSPACE
;
1218 termp_pf_pre(DECL_ARGS
)
1221 p
->flags
|= TERMP_IGNDELIM
;
1228 termp_pf_post(DECL_ARGS
)
1231 p
->flags
&= ~TERMP_IGNDELIM
;
1232 p
->flags
|= TERMP_NOSPACE
;
1238 termp_ss_pre(DECL_ARGS
)
1241 switch (node
->type
) {
1244 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1245 p
->offset
= INDENT
/ 2;
1257 termp_ss_post(DECL_ARGS
)
1260 switch (node
->type
) {
1273 termp_pa_pre(DECL_ARGS
)
1276 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1283 termp_em_pre(DECL_ARGS
)
1286 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1293 termp_cd_pre(DECL_ARGS
)
1296 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1304 termp_cm_pre(DECL_ARGS
)
1307 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1314 termp_ic_pre(DECL_ARGS
)
1317 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1324 termp_in_pre(DECL_ARGS
)
1327 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1328 word(p
, "#include");
1330 p
->flags
|= TERMP_NOSPACE
;
1337 termp_in_post(DECL_ARGS
)
1340 p
->flags
|= TERMP_NOSPACE
;
1344 if (SEC_SYNOPSIS
!= node
->sec
)
1346 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1353 termp_at_pre(DECL_ARGS
)
1359 assert(MDOC_TEXT
== node
->child
->type
);
1360 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1363 word(p
, mdoc_att2a(c
));
1370 termp_bq_pre(DECL_ARGS
)
1373 if (MDOC_BODY
!= node
->type
)
1376 p
->flags
|= TERMP_NOSPACE
;
1383 termp_bq_post(DECL_ARGS
)
1386 if (MDOC_BODY
!= node
->type
)
1394 termp_pq_pre(DECL_ARGS
)
1397 if (MDOC_BODY
!= node
->type
)
1400 p
->flags
|= TERMP_NOSPACE
;
1407 termp_pq_post(DECL_ARGS
)
1410 if (MDOC_BODY
!= node
->type
)
1418 termp_fo_pre(DECL_ARGS
)
1420 const struct mdoc_node
*n
;
1422 if (MDOC_BODY
== node
->type
) {
1424 p
->flags
|= TERMP_NOSPACE
;
1426 } else if (MDOC_HEAD
!= node
->type
)
1429 /* XXX - groff shows only first parameter */
1431 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1432 for (n
= node
->child
; n
; n
= n
->next
) {
1433 assert(MDOC_TEXT
== n
->type
);
1434 word(p
, n
->data
.text
.string
);
1436 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1444 termp_fo_post(DECL_ARGS
)
1447 if (MDOC_BODY
!= node
->type
)
1457 termp_bf_pre(DECL_ARGS
)
1459 const struct mdoc_node
*n
;
1460 const struct mdoc_block
*b
;
1462 /* XXX - we skip over possible trailing HEAD tokens. */
1464 if (MDOC_HEAD
== node
->type
)
1466 else if (MDOC_BLOCK
!= node
->type
)
1469 b
= &node
->data
.block
;
1471 if (NULL
== (n
= b
->head
->child
)) {
1472 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1473 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1474 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1475 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1480 assert(MDOC_TEXT
== n
->type
);
1482 if (0 == strcmp("Em", n
->data
.text
.string
))
1483 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1484 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1485 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1493 termp_sy_pre(DECL_ARGS
)
1496 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1503 termp_ms_pre(DECL_ARGS
)
1506 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1514 termp_sm_pre(DECL_ARGS
)
1518 assert(node
->child
);
1519 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1520 p
->flags
&= ~TERMP_NONOSPACE
;
1521 p
->flags
&= ~TERMP_NOSPACE
;
1523 p
->flags
|= TERMP_NONOSPACE
;
1524 p
->flags
|= TERMP_NOSPACE
;
1534 termp__t_pre(DECL_ARGS
)
1538 p
->flags
|= TERMP_NOSPACE
;
1545 termp__t_post(DECL_ARGS
)
1548 p
->flags
|= TERMP_NOSPACE
;
1550 word(p
, node
->next
? "," : ".");
1556 termp____post(DECL_ARGS
)
1559 p
->flags
|= TERMP_NOSPACE
;
1560 word(p
, node
->next
? "," : ".");