]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.21 2009/02/25 15:12:26 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: 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
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 struct termpair *pair, \
97 const struct mdoc_meta *meta, \
98 const struct mdoc_node *node
100 #define DECL_PRE(name) \
101 static int name##_pre(DECL_ARGS)
102 #define DECL_POST(name) \
103 static void name##_post(DECL_ARGS)
104 #define DECL_PREPOST(name) \
108 DECL_PREPOST(termp_aq
);
109 DECL_PREPOST(termp_bd
);
110 DECL_PREPOST(termp_bq
);
111 DECL_PREPOST(termp_d1
);
112 DECL_PREPOST(termp_dq
);
113 DECL_PREPOST(termp_fd
);
114 DECL_PREPOST(termp_fn
);
115 DECL_PREPOST(termp_fo
);
116 DECL_PREPOST(termp_ft
);
117 DECL_PREPOST(termp_it
);
118 DECL_PREPOST(termp_op
);
119 DECL_PREPOST(termp_pf
);
120 DECL_PREPOST(termp_pq
);
121 DECL_PREPOST(termp_qq
);
122 DECL_PREPOST(termp_sh
);
123 DECL_PREPOST(termp_ss
);
124 DECL_PREPOST(termp_sq
);
125 DECL_PREPOST(termp_vt
);
161 const struct termact __termacts
[MDOC_MAX
] = {
162 { NULL
, NULL
}, /* \" */
163 { NULL
, NULL
}, /* Dd */
164 { NULL
, NULL
}, /* Dt */
165 { NULL
, NULL
}, /* Os */
166 { termp_sh_pre
, termp_sh_post
}, /* Sh */
167 { termp_ss_pre
, termp_ss_post
}, /* Ss */
168 { termp_pp_pre
, NULL
}, /* Pp */
169 { termp_d1_pre
, termp_d1_post
}, /* D1 */
170 { NULL
, NULL
}, /* Dl */
171 { termp_bd_pre
, termp_bd_post
}, /* Bd */
172 { NULL
, NULL
}, /* Ed */
173 { NULL
, termp_bl_post
}, /* Bl */
174 { NULL
, NULL
}, /* El */
175 { termp_it_pre
, termp_it_post
}, /* It */
176 { NULL
, NULL
}, /* Ad */
177 { NULL
, NULL
}, /* An */
178 { termp_ar_pre
, NULL
}, /* Ar */
179 { termp_cd_pre
, NULL
}, /* Cd */
180 { termp_cm_pre
, NULL
}, /* Cm */
181 { NULL
, NULL
}, /* Dv */
182 { NULL
, NULL
}, /* Er */
183 { NULL
, NULL
}, /* Ev */
184 { termp_ex_pre
, NULL
}, /* Ex */
185 { termp_fa_pre
, NULL
}, /* Fa */
186 { termp_fd_pre
, termp_fd_post
}, /* Fd */
187 { termp_fl_pre
, NULL
}, /* Fl */
188 { termp_fn_pre
, termp_fn_post
}, /* Fn */
189 { termp_ft_pre
, termp_ft_post
}, /* Ft */
190 { termp_ic_pre
, NULL
}, /* Ic */
191 { termp_in_pre
, NULL
}, /* In */
192 { NULL
, NULL
}, /* Li */
193 { termp_nd_pre
, NULL
}, /* Nd */
194 { termp_nm_pre
, NULL
}, /* Nm */
195 { termp_op_pre
, termp_op_post
}, /* Op */
196 { NULL
, NULL
}, /* Ot */
197 { termp_pa_pre
, NULL
}, /* Pa */
198 { termp_rv_pre
, NULL
}, /* Rv */
199 { termp_st_pre
, NULL
}, /* St */
200 { termp_va_pre
, NULL
}, /* Va */
201 { termp_vt_pre
, termp_vt_post
}, /* Vt */
202 { termp_xr_pre
, NULL
}, /* Xr */
203 { NULL
, NULL
}, /* %A */
204 { NULL
, NULL
}, /* %B */
205 { NULL
, NULL
}, /* %D */
206 { NULL
, NULL
}, /* %I */
207 { NULL
, NULL
}, /* %J */
208 { NULL
, NULL
}, /* %N */
209 { NULL
, NULL
}, /* %O */
210 { NULL
, NULL
}, /* %P */
211 { NULL
, NULL
}, /* %R */
212 { NULL
, NULL
}, /* %T */
213 { NULL
, NULL
}, /* %V */
214 { NULL
, NULL
}, /* Ac */
215 { termp_aq_pre
, termp_aq_post
}, /* Ao */
216 { termp_aq_pre
, termp_aq_post
}, /* Aq */
217 { termp_at_pre
, NULL
}, /* At */
218 { NULL
, NULL
}, /* Bc */
219 { termp_bf_pre
, NULL
}, /* Bf */
220 { termp_bq_pre
, termp_bq_post
}, /* Bo */
221 { termp_bq_pre
, termp_bq_post
}, /* Bq */
222 { termp_bsx_pre
, NULL
}, /* Bsx */
223 { termp_bx_pre
, NULL
}, /* Bx */
224 { NULL
, NULL
}, /* Db */
225 { NULL
, NULL
}, /* Dc */
226 { termp_dq_pre
, termp_dq_post
}, /* Do */
227 { termp_dq_pre
, termp_dq_post
}, /* Dq */
228 { NULL
, NULL
}, /* Ec */
229 { NULL
, NULL
}, /* Ef */
230 { termp_em_pre
, NULL
}, /* Em */
231 { NULL
, NULL
}, /* Eo */
232 { termp_fx_pre
, NULL
}, /* Fx */
233 { termp_ms_pre
, NULL
}, /* Ms */
234 { NULL
, NULL
}, /* No */
235 { termp_ns_pre
, NULL
}, /* Ns */
236 { termp_nx_pre
, NULL
}, /* Nx */
237 { termp_ox_pre
, NULL
}, /* Ox */
238 { NULL
, NULL
}, /* Pc */
239 { termp_pf_pre
, termp_pf_post
}, /* Pf */
240 { termp_pq_pre
, termp_pq_post
}, /* Po */
241 { termp_pq_pre
, termp_pq_post
}, /* Pq */
242 { NULL
, NULL
}, /* Qc */
243 { termp_sq_pre
, termp_sq_post
}, /* Ql */
244 { termp_qq_pre
, termp_qq_post
}, /* Qo */
245 { termp_qq_pre
, termp_qq_post
}, /* Qq */
246 { NULL
, NULL
}, /* Re */
247 { NULL
, NULL
}, /* Rs */
248 { NULL
, NULL
}, /* Sc */
249 { termp_sq_pre
, termp_sq_post
}, /* So */
250 { termp_sq_pre
, termp_sq_post
}, /* Sq */
251 { NULL
, NULL
}, /* Sm */
252 { termp_sx_pre
, NULL
}, /* Sx */
253 { termp_sy_pre
, NULL
}, /* Sy */
254 { NULL
, NULL
}, /* Tn */
255 { termp_ux_pre
, NULL
}, /* Ux */
256 { NULL
, NULL
}, /* Xc */
257 { NULL
, NULL
}, /* Xo */
258 { termp_fo_pre
, termp_fo_post
}, /* Fo */
259 { NULL
, NULL
}, /* Fc */
260 { termp_op_pre
, termp_op_post
}, /* Oo */
261 { NULL
, NULL
}, /* Oc */
262 { NULL
, NULL
}, /* Bk */
263 { NULL
, NULL
}, /* Ek */
264 { termp_bt_pre
, NULL
}, /* Bt */
265 { NULL
, NULL
}, /* Hf */
266 { NULL
, NULL
}, /* Fr */
267 { termp_ud_pre
, NULL
}, /* Ud */
270 const struct termact
*termacts
= __termacts
;
274 arg_width(const struct mdoc_arg
*arg
)
279 return(strlen(*arg
->value
));
284 arg_offset(const struct mdoc_arg
*arg
)
289 if (0 == strcmp(*arg
->value
, "indent"))
291 if (0 == strcmp(*arg
->value
, "indent-two"))
294 return(strlen(*arg
->value
));
299 arg_hasattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
302 return(-1 != arg_getattr(arg
, argc
, argv
));
307 arg_getattr(int arg
, size_t argc
, const struct mdoc_arg
*argv
)
311 for (i
= 0; i
< (int)argc
; i
++)
312 if (argv
[i
].arg
== arg
)
320 termp_dq_pre(DECL_ARGS
)
323 if (MDOC_BODY
!= node
->type
)
327 p
->flags
|= TERMP_NOSPACE
;
334 termp_dq_post(DECL_ARGS
)
337 if (MDOC_BODY
!= node
->type
)
340 p
->flags
|= TERMP_NOSPACE
;
347 termp_it_pre(DECL_ARGS
)
349 const struct mdoc_node
*n
, *it
;
350 const struct mdoc_block
*bl
;
353 size_t width
, offset
;
355 switch (node
->type
) {
368 n
= it
->parent
->parent
;
371 if (MDOC_BLOCK
== node
->type
) {
372 if (arg_hasattr(MDOC_Compact
, bl
->argc
, bl
->argv
))
379 pair
->offset
= p
->offset
;
380 pair
->rmargin
= p
->rmargin
;
382 /* FIXME: auto-size. */
383 i
= arg_getattr(MDOC_Width
, bl
->argc
, bl
->argv
);
384 width
= i
>= 0 ? arg_width(&bl
->argv
[i
]) : 10;
386 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
387 offset
= i
>= 0 ? arg_offset(&bl
->argv
[i
]) : 0;
389 assert(MDOC_HEAD
== node
->type
||
390 MDOC_BODY
== node
->type
);
392 if (arg_hasattr(MDOC_Tag
, bl
->argc
, bl
->argv
)) {
393 p
->flags
|= TERMP_NOSPACE
;
394 if (MDOC_BODY
== node
->type
) {
395 p
->flags
|= TERMP_NOLPAD
;
398 p
->flags
|= TERMP_NOBREAK
;
399 p
->rmargin
= p
->offset
+ offset
+ width
;
402 } else if (arg_hasattr(MDOC_Ohang
, bl
->argc
, bl
->argv
)) {
403 p
->flags
|= TERMP_NOSPACE
;
405 } else if (arg_hasattr(MDOC_Diag
, bl
->argc
, bl
->argv
)) {
408 } else if (arg_hasattr(MDOC_Hang
, bl
->argc
, bl
->argv
)) {
411 } else if (arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
)) {
412 p
->flags
|= TERMP_NOSPACE
;
413 if (MDOC_BODY
== node
->type
) {
414 p
->flags
|= TERMP_NOLPAD
;
418 p
->flags
|= TERMP_NOBREAK
;
419 p
->rmargin
= p
->offset
+ offset
+ 6;
422 } else if (arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
)) {
423 p
->flags
|= TERMP_NOSPACE
;
424 if (MDOC_BODY
== node
->type
) {
425 p
->flags
|= TERMP_NOLPAD
;
428 (pair
->ppair
->ppair
->count
)++;
429 (void)snprintf(buf
, sizeof(buf
), "%d.",
430 pair
->ppair
->ppair
->count
);
432 p
->flags
|= TERMP_NOBREAK
;
433 p
->rmargin
= p
->offset
+ offset
+ 6;
436 } else if (arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
) ||
437 arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
)) {
438 p
->flags
|= TERMP_NOSPACE
;
439 if (MDOC_BODY
== node
->type
) {
440 p
->flags
|= TERMP_NOLPAD
;
445 p
->flags
|= TERMP_NOBREAK
;
446 p
->rmargin
= p
->offset
+ offset
+ 6;
457 termp_it_post(DECL_ARGS
)
459 const struct mdoc_node
*n
, *it
;
460 const struct mdoc_block
*bl
;
462 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
466 n
= it
->parent
->parent
;
469 if (arg_hasattr(MDOC_Tag
, bl
->argc
, bl
->argv
) ||
470 arg_hasattr(MDOC_Bullet
, bl
->argc
, bl
->argv
) ||
471 arg_hasattr(MDOC_Dash
, bl
->argc
, bl
->argv
) ||
472 arg_hasattr(MDOC_Enum
, bl
->argc
, bl
->argv
) ||
473 arg_hasattr(MDOC_Hyphen
, bl
->argc
, bl
->argv
)) {
475 if (MDOC_HEAD
== node
->type
) {
476 p
->rmargin
= pair
->rmargin
;
477 p
->flags
&= ~TERMP_NOBREAK
;
479 p
->flags
&= ~TERMP_NOLPAD
;
481 } else if (arg_hasattr(MDOC_Ohang
, bl
->argc
, bl
->argv
)) {
484 } else if (arg_hasattr(MDOC_Inset
, bl
->argc
, bl
->argv
)) {
485 if (MDOC_BODY
== node
->type
)
488 } else if (arg_hasattr(MDOC_Item
, bl
->argc
, bl
->argv
)) {
489 if (MDOC_BODY
== node
->type
)
493 p
->offset
= pair
->offset
;
499 termp_nm_pre(DECL_ARGS
)
502 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_PROG
]);
503 if (NULL
== node
->child
)
511 termp_fl_pre(DECL_ARGS
)
514 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
516 p
->flags
|= TERMP_NOSPACE
;
523 termp_ar_pre(DECL_ARGS
)
526 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_ARG
]);
527 if (NULL
== node
->child
)
535 termp_ns_pre(DECL_ARGS
)
538 p
->flags
|= TERMP_NOSPACE
;
545 termp_pp_pre(DECL_ARGS
)
555 termp_st_pre(DECL_ARGS
)
559 assert(1 == node
->data
.elem
.argc
);
561 tp
= mdoc_st2a(node
->data
.elem
.argv
[0].arg
);
570 termp_rv_pre(DECL_ARGS
)
574 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
575 node
->data
.elem
.argv
);
581 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
582 word(p
, *node
->data
.elem
.argv
[i
].value
);
583 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
585 word(p
, "() function returns the value 0 if successful;");
586 word(p
, "otherwise the value -1 is returned and the");
587 word(p
, "global variable");
589 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
591 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
593 word(p
, "is set to indicate the error.");
601 termp_ex_pre(DECL_ARGS
)
605 i
= arg_getattr(MDOC_Std
, node
->data
.elem
.argc
,
606 node
->data
.elem
.argv
);
610 p
->flags
|= ttypes
[TTYPE_PROG
];
611 word(p
, *node
->data
.elem
.argv
[i
].value
);
612 p
->flags
&= ~ttypes
[TTYPE_PROG
];
613 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
621 termp_nd_pre(DECL_ARGS
)
631 termp_bl_post(DECL_ARGS
)
634 if (MDOC_BLOCK
== node
->type
)
641 termp_op_post(DECL_ARGS
)
644 if (MDOC_BODY
!= node
->type
)
646 p
->flags
|= TERMP_NOSPACE
;
653 termp_xr_pre(DECL_ARGS
)
655 const struct mdoc_node
*n
;
660 assert(MDOC_TEXT
== n
->type
);
661 word(p
, n
->data
.text
.string
);
663 if (NULL
== (n
= n
->next
))
666 assert(MDOC_TEXT
== n
->type
);
667 p
->flags
|= TERMP_NOSPACE
;
669 p
->flags
|= TERMP_NOSPACE
;
670 word(p
, n
->data
.text
.string
);
671 p
->flags
|= TERMP_NOSPACE
;
680 termp_vt_pre(DECL_ARGS
)
683 /* FIXME: this can be "type name". */
684 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
691 termp_vt_post(DECL_ARGS
)
694 if (node
->sec
== SEC_SYNOPSIS
)
701 termp_fd_pre(DECL_ARGS
)
705 * FIXME: this naming is bad. This value is used, in general,
706 * for the #include header or other preprocessor statement.
708 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_DECL
]);
715 termp_fd_post(DECL_ARGS
)
718 if (node
->sec
== SEC_SYNOPSIS
)
725 termp_sh_pre(DECL_ARGS
)
728 switch (node
->type
) {
731 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SECTION
]);
745 termp_sh_post(DECL_ARGS
)
748 switch (node
->type
) {
764 termp_op_pre(DECL_ARGS
)
767 switch (node
->type
) {
770 p
->flags
|= TERMP_NOSPACE
;
781 termp_bt_pre(DECL_ARGS
)
784 word(p
, "is currently in beta test.");
791 termp_ud_pre(DECL_ARGS
)
794 word(p
, "currently under development.");
801 termp_d1_pre(DECL_ARGS
)
804 if (MDOC_BODY
!= node
->type
)
807 p
->offset
+= (pair
->offset
= INDENT
);
814 termp_d1_post(DECL_ARGS
)
817 if (MDOC_BODY
!= node
->type
)
820 p
->offset
-= pair
->offset
;
826 termp_aq_pre(DECL_ARGS
)
829 if (MDOC_BODY
!= node
->type
)
832 p
->flags
|= TERMP_NOSPACE
;
839 termp_aq_post(DECL_ARGS
)
842 if (MDOC_BODY
!= node
->type
)
844 p
->flags
|= TERMP_NOSPACE
;
851 termp_ft_pre(DECL_ARGS
)
854 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_TYPE
]);
861 termp_ft_post(DECL_ARGS
)
864 if (node
->sec
== SEC_SYNOPSIS
)
871 termp_fn_pre(DECL_ARGS
)
873 const struct mdoc_node
*n
;
876 assert(MDOC_TEXT
== node
->child
->type
);
878 /* FIXME: can be "type funcname" "type varname"... */
880 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
881 word(p
, node
->child
->data
.text
.string
);
882 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
886 p
->flags
|= TERMP_NOSPACE
;
887 for (n
= node
->child
->next
; n
; n
= n
->next
) {
888 assert(MDOC_TEXT
== n
->type
);
889 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
890 word(p
, n
->data
.text
.string
);
891 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
898 if (SEC_SYNOPSIS
== node
->sec
)
907 termp_fn_post(DECL_ARGS
)
910 if (node
->sec
== SEC_SYNOPSIS
)
918 termp_sx_pre(DECL_ARGS
)
921 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_LINK
]);
928 termp_fa_pre(DECL_ARGS
)
932 if (node
->parent
->tok
!= MDOC_Fo
) {
933 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FUNC_ARG
]);
937 for (n
= node
->child
; n
; n
= n
->next
) {
938 assert(MDOC_TEXT
== n
->type
);
940 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
941 word(p
, n
->data
.text
.string
);
942 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
948 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
957 termp_va_pre(DECL_ARGS
)
960 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_VAR_DECL
]);
967 termp_bd_pre(DECL_ARGS
)
969 const struct mdoc_block
*bl
;
970 const struct mdoc_node
*n
;
973 if (MDOC_BLOCK
== node
->type
) {
976 } else if (MDOC_BODY
!= node
->type
)
979 assert(MDOC_BLOCK
== node
->parent
->type
);
980 pair
->offset
= p
->offset
;
982 bl
= &node
->parent
->data
.block
;
985 i
= arg_getattr(MDOC_Offset
, bl
->argc
, bl
->argv
);
987 assert(1 == bl
->argv
[i
].sz
);
988 p
->offset
+= arg_offset(&bl
->argv
[i
]);
991 if ( ! arg_hasattr(MDOC_Literal
, bl
->argc
, bl
->argv
))
994 p
->flags
|= TERMP_LITERAL
;
996 for (n
= node
->child
; n
; n
= n
->next
) {
997 assert(MDOC_TEXT
== n
->type
); /* FIXME */
998 if ((*n
->data
.text
.string
)) {
999 word(p
, n
->data
.text
.string
);
1006 p
->flags
&= ~TERMP_LITERAL
;
1013 termp_bd_post(DECL_ARGS
)
1016 if (MDOC_BODY
!= node
->type
)
1019 p
->offset
= pair
->offset
;
1025 termp_qq_pre(DECL_ARGS
)
1028 if (MDOC_BODY
!= node
->type
)
1031 p
->flags
|= TERMP_NOSPACE
;
1038 termp_qq_post(DECL_ARGS
)
1041 if (MDOC_BODY
!= node
->type
)
1043 p
->flags
|= TERMP_NOSPACE
;
1050 termp_bsx_pre(DECL_ARGS
)
1053 word(p
, "BSDI BSD/OS");
1060 termp_bx_pre(DECL_ARGS
)
1070 termp_ox_pre(DECL_ARGS
)
1080 termp_ux_pre(DECL_ARGS
)
1090 termp_fx_pre(DECL_ARGS
)
1100 termp_nx_pre(DECL_ARGS
)
1110 termp_sq_pre(DECL_ARGS
)
1113 if (MDOC_BODY
!= node
->type
)
1116 p
->flags
|= TERMP_NOSPACE
;
1123 termp_sq_post(DECL_ARGS
)
1126 if (MDOC_BODY
!= node
->type
)
1128 p
->flags
|= TERMP_NOSPACE
;
1135 termp_pf_pre(DECL_ARGS
)
1138 p
->flags
|= TERMP_IGNDELIM
;
1145 termp_pf_post(DECL_ARGS
)
1148 p
->flags
&= ~TERMP_IGNDELIM
;
1149 p
->flags
|= TERMP_NOSPACE
;
1155 termp_ss_pre(DECL_ARGS
)
1158 switch (node
->type
) {
1161 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SSECTION
]);
1162 p
->offset
= INDENT
/ 2;
1174 termp_ss_post(DECL_ARGS
)
1177 switch (node
->type
) {
1190 termp_pa_pre(DECL_ARGS
)
1193 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_FILE
]);
1200 termp_em_pre(DECL_ARGS
)
1203 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1210 termp_cd_pre(DECL_ARGS
)
1213 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CONFIG
]);
1220 termp_cm_pre(DECL_ARGS
)
1223 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD_FLAG
]);
1230 termp_ic_pre(DECL_ARGS
)
1233 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_CMD
]);
1240 termp_in_pre(DECL_ARGS
)
1243 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_INCLUDE
]);
1250 termp_at_pre(DECL_ARGS
)
1256 assert(MDOC_TEXT
== node
->child
->type
);
1257 c
= mdoc_atoatt(node
->child
->data
.text
.string
);
1260 word(p
, mdoc_att2a(c
));
1267 termp_bq_pre(DECL_ARGS
)
1270 if (MDOC_BODY
!= node
->type
)
1273 p
->flags
|= TERMP_NOSPACE
;
1280 termp_bq_post(DECL_ARGS
)
1283 if (MDOC_BODY
!= node
->type
)
1291 termp_pq_pre(DECL_ARGS
)
1294 if (MDOC_BODY
!= node
->type
)
1297 p
->flags
|= TERMP_NOSPACE
;
1304 termp_pq_post(DECL_ARGS
)
1307 if (MDOC_BODY
!= node
->type
)
1315 termp_fo_pre(DECL_ARGS
)
1317 const struct mdoc_node
*n
;
1319 if (MDOC_BODY
== node
->type
) {
1321 p
->flags
|= TERMP_NOSPACE
;
1323 } else if (MDOC_HEAD
!= node
->type
)
1326 /* XXX - groff shows only first parameter */
1328 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1329 for (n
= node
->child
; n
; n
= n
->next
) {
1330 assert(MDOC_TEXT
== n
->type
);
1331 word(p
, n
->data
.text
.string
);
1333 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1341 termp_fo_post(DECL_ARGS
)
1344 if (MDOC_BODY
!= node
->type
)
1354 termp_bf_pre(DECL_ARGS
)
1356 const struct mdoc_node
*n
;
1357 const struct mdoc_block
*b
;
1359 /* XXX - we skip over possible trailing HEAD tokens. */
1361 if (MDOC_HEAD
== node
->type
)
1363 else if (MDOC_BLOCK
!= node
->type
)
1366 b
= &node
->data
.block
;
1368 if (NULL
== (n
= b
->head
->child
)) {
1369 if (arg_hasattr(MDOC_Emphasis
, b
->argc
, b
->argv
))
1370 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1371 else if (arg_hasattr(MDOC_Symbolic
, b
->argc
, b
->argv
))
1372 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1377 assert(MDOC_TEXT
== n
->type
);
1379 if (0 == strcmp("Em", n
->data
.text
.string
))
1380 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1381 else if (0 == strcmp("Sy", n
->data
.text
.string
))
1382 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_EMPH
]);
1390 termp_sy_pre(DECL_ARGS
)
1393 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMB
]);
1400 termp_ms_pre(DECL_ARGS
)
1403 TERMPAIR_SETFLAG(pair
, ttypes
[TTYPE_SYMBOL
]);