]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.46 2009/03/08 14:01:46 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: 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
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 /* TODO: abstract this into mdocterm.c. */
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 */
83 TERMP_BOLD
/* TTYPE_DIAG */
86 static int arg_hasattr(int, const struct mdoc_node
*);
87 static int arg_getattr(int, const struct mdoc_node
*);
88 static size_t arg_offset(const struct mdoc_argv
*);
89 static size_t arg_width(const struct mdoc_argv
*);
90 static int arg_listtype(const struct mdoc_node
*);
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
);
169 const struct termact __termacts
[MDOC_MAX
] = {
170 { NULL
, NULL
}, /* \" */
171 { NULL
, NULL
}, /* Dd */
172 { NULL
, NULL
}, /* Dt */
173 { NULL
, NULL
}, /* Os */
174 { termp_sh_pre
, termp_sh_post
}, /* Sh */
175 { termp_ss_pre
, termp_ss_post
}, /* Ss */
176 { termp_pp_pre
, NULL
}, /* Pp */
177 { termp_d1_pre
, termp_d1_post
}, /* D1 */
178 { termp_d1_pre
, termp_d1_post
}, /* Dl */
179 { termp_bd_pre
, termp_bd_post
}, /* Bd */
180 { NULL
, NULL
}, /* Ed */
181 { NULL
, termp_bl_post
}, /* Bl */
182 { NULL
, NULL
}, /* El */
183 { termp_it_pre
, termp_it_post
}, /* It */
184 { NULL
, NULL
}, /* Ad */
185 { NULL
, NULL
}, /* An */
186 { termp_ar_pre
, NULL
}, /* Ar */
187 { termp_cd_pre
, NULL
}, /* Cd */
188 { termp_cm_pre
, NULL
}, /* Cm */
189 { NULL
, NULL
}, /* Dv */
190 { NULL
, NULL
}, /* Er */
191 { NULL
, NULL
}, /* Ev */
192 { termp_ex_pre
, NULL
}, /* Ex */
193 { termp_fa_pre
, NULL
}, /* Fa */
194 { termp_fd_pre
, termp_fd_post
}, /* Fd */
195 { termp_fl_pre
, NULL
}, /* Fl */
196 { termp_fn_pre
, termp_fn_post
}, /* Fn */
197 { termp_ft_pre
, termp_ft_post
}, /* Ft */
198 { termp_ic_pre
, NULL
}, /* Ic */
199 { termp_in_pre
, termp_in_post
}, /* In */
200 { NULL
, NULL
}, /* Li */
201 { termp_nd_pre
, NULL
}, /* Nd */
202 { termp_nm_pre
, NULL
}, /* Nm */
203 { termp_op_pre
, termp_op_post
}, /* Op */
204 { NULL
, NULL
}, /* Ot */
205 { termp_pa_pre
, NULL
}, /* Pa */
206 { termp_rv_pre
, NULL
}, /* Rv */
207 { termp_st_pre
, NULL
}, /* St */
208 { termp_va_pre
, NULL
}, /* Va */
209 { termp_vt_pre
, termp_vt_post
}, /* Vt */
210 { termp_xr_pre
, NULL
}, /* Xr */
211 { NULL
, termp____post
}, /* %A */
212 { NULL
, termp____post
}, /* %B */
213 { NULL
, termp____post
}, /* %D */
214 { NULL
, termp____post
}, /* %I */
215 { NULL
, termp____post
}, /* %J */
216 { NULL
, termp____post
}, /* %N */
217 { NULL
, termp____post
}, /* %O */
218 { NULL
, termp____post
}, /* %P */
219 { NULL
, termp____post
}, /* %R */
220 { termp__t_pre
, termp__t_post
}, /* %T */
221 { NULL
, termp____post
}, /* %V */
222 { NULL
, NULL
}, /* Ac */
223 { termp_aq_pre
, termp_aq_post
}, /* Ao */
224 { termp_aq_pre
, termp_aq_post
}, /* Aq */
225 { termp_at_pre
, NULL
}, /* At */
226 { NULL
, NULL
}, /* Bc */
227 { termp_bf_pre
, NULL
}, /* Bf */
228 { termp_bq_pre
, termp_bq_post
}, /* Bo */
229 { termp_bq_pre
, termp_bq_post
}, /* Bq */
230 { termp_bsx_pre
, NULL
}, /* Bsx */
231 { NULL
, termp_bx_post
}, /* Bx */
232 { NULL
, NULL
}, /* Db */
233 { NULL
, NULL
}, /* Dc */
234 { termp_dq_pre
, termp_dq_post
}, /* Do */
235 { termp_dq_pre
, termp_dq_post
}, /* Dq */
236 { NULL
, NULL
}, /* Ec */
237 { NULL
, NULL
}, /* Ef */
238 { termp_em_pre
, NULL
}, /* Em */
239 { NULL
, NULL
}, /* Eo */
240 { termp_fx_pre
, NULL
}, /* Fx */
241 { termp_ms_pre
, NULL
}, /* Ms */
242 { NULL
, NULL
}, /* No */
243 { termp_ns_pre
, NULL
}, /* Ns */
244 { termp_nx_pre
, NULL
}, /* Nx */
245 { termp_ox_pre
, NULL
}, /* Ox */
246 { NULL
, NULL
}, /* Pc */
247 { termp_pf_pre
, termp_pf_post
}, /* Pf */
248 { termp_pq_pre
, termp_pq_post
}, /* Po */
249 { termp_pq_pre
, termp_pq_post
}, /* Pq */
250 { NULL
, NULL
}, /* Qc */
251 { termp_sq_pre
, termp_sq_post
}, /* Ql */
252 { termp_qq_pre
, termp_qq_post
}, /* Qo */
253 { termp_qq_pre
, termp_qq_post
}, /* Qq */
254 { NULL
, NULL
}, /* Re */
255 { termp_rs_pre
, NULL
}, /* Rs */
256 { NULL
, NULL
}, /* Sc */
257 { termp_sq_pre
, termp_sq_post
}, /* So */
258 { termp_sq_pre
, termp_sq_post
}, /* Sq */
259 { termp_sm_pre
, NULL
}, /* Sm */
260 { termp_sx_pre
, NULL
}, /* Sx */
261 { termp_sy_pre
, NULL
}, /* Sy */
262 { NULL
, NULL
}, /* Tn */
263 { termp_ux_pre
, NULL
}, /* Ux */
264 { NULL
, NULL
}, /* Xc */
265 { NULL
, NULL
}, /* Xo */
266 { termp_fo_pre
, termp_fo_post
}, /* Fo */
267 { NULL
, NULL
}, /* Fc */
268 { termp_op_pre
, termp_op_post
}, /* Oo */
269 { NULL
, NULL
}, /* Oc */
270 { NULL
, NULL
}, /* Bk */
271 { NULL
, NULL
}, /* Ek */
272 { termp_bt_pre
, NULL
}, /* Bt */
273 { NULL
, NULL
}, /* Hf */
274 { NULL
, NULL
}, /* Fr */
275 { termp_ud_pre
, NULL
}, /* Ud */
276 { NULL
, termp_lb_post
}, /* lb */
279 const struct termact
*termacts
= __termacts
;
283 arg_width(const struct mdoc_argv
*arg
)
289 if (0 == strcmp(*arg
->value
, "indent"))
291 if (0 == strcmp(*arg
->value
, "indent-two"))
294 len
= (int)strlen(*arg
->value
);
297 for (i
= 0; i
< len
- 1; i
++)
298 if ( ! isdigit((u_char
)(*arg
->value
)[i
]))
302 if ('n' == (*arg
->value
)[len
- 1]) {
303 v
= (size_t)atoi(*arg
->value
);
308 return(strlen(*arg
->value
) + 1);
313 arg_listtype(const struct mdoc_node
*n
)
317 assert(MDOC_BLOCK
== n
->type
);
319 len
= (int)(n
->args
? n
->args
->argc
: 0);
321 for (i
= 0; i
< len
; i
++)
322 switch (n
->args
->argv
[i
].arg
) {
340 return(n
->args
->argv
[i
].arg
);
345 errx(1, "list type not supported");
351 arg_offset(const struct mdoc_argv
*arg
)
356 if (0 == strcmp(*arg
->value
, "indent"))
358 if (0 == strcmp(*arg
->value
, "indent-two"))
360 return(strlen(*arg
->value
));
365 arg_hasattr(int arg
, const struct mdoc_node
*n
)
368 return(-1 != arg_getattr(arg
, n
));
373 arg_getattr(int arg
, const struct mdoc_node
*n
)
379 for (i
= 0; i
< (int)n
->args
->argc
; i
++)
380 if (n
->args
->argv
[i
].arg
== arg
)
388 termp_dq_pre(DECL_ARGS
)
391 if (MDOC_BODY
!= node
->type
)
395 p
->flags
|= TERMP_NOSPACE
;
402 termp_dq_post(DECL_ARGS
)
405 if (MDOC_BODY
!= node
->type
)
408 p
->flags
|= TERMP_NOSPACE
;
415 termp_it_pre_block(DECL_ARGS
)
419 if ( ! arg_hasattr(MDOC_Compact
, node
->parent
->parent
))
420 if (node
->prev
|| node
->parent
->parent
->prev
)
429 termp_it_pre(DECL_ARGS
)
431 const struct mdoc_node
*bl
;
434 size_t width
, offset
;
436 if (MDOC_BLOCK
== node
->type
)
437 return(termp_it_pre_block(p
, pair
, meta
, node
));
439 /* Get ptr to list block, type, etc. */
441 bl
= node
->parent
->parent
->parent
;
442 type
= arg_listtype(bl
);
444 /* Save parent attributes. */
446 pair
->offset
= p
->offset
;
447 pair
->rmargin
= p
->rmargin
;
448 pair
->flag
= p
->flags
;
450 /* Get list width and offset. */
452 i
= arg_getattr(MDOC_Width
, bl
);
453 width
= i
>= 0 ? arg_width(&bl
->args
->argv
[i
]) : 0;
455 i
= arg_getattr(MDOC_Offset
, bl
);
456 offset
= i
>= 0 ? arg_offset(&bl
->args
->argv
[i
]) : 0;
459 * List-type can override the width in the case of fixed-head
460 * values (bullet, dash/hyphen, enum). Tags need a non-zero
472 width
= width
> 4 ? width
: 4;
477 errx(1, "need non-zero %s for list type",
478 mdoc_argnames
[MDOC_Width
]);
484 * Whitespace control. Inset bodies need an initial space.
491 if (MDOC_BODY
== node
->type
)
492 p
->flags
&= ~TERMP_NOSPACE
;
494 p
->flags
|= TERMP_NOSPACE
;
497 p
->flags
|= TERMP_NOSPACE
;
502 * Style flags. Diagnostic heads need TTYPE_DIAG.
507 if (MDOC_HEAD
== node
->type
)
508 p
->flags
|= ttypes
[TTYPE_DIAG
];
515 * Pad and break control. This is the tricker part. Lists with
516 * set right-margins for the head get TERMP_NOBREAK because, if
517 * they overrun the margin, they wrap to the new margin.
518 * Correspondingly, the body for these types don't left-pad, as
519 * the head will pad out to to the right.
532 if (MDOC_HEAD
== node
->type
)
533 p
->flags
|= TERMP_NOBREAK
;
535 p
->flags
|= TERMP_NOLPAD
;
536 if (MDOC_HEAD
== node
->type
&& MDOC_Tag
== type
)
537 if (NULL
== node
->next
||
538 NULL
== node
->next
->child
)
539 p
->flags
|= TERMP_NONOBREAK
;
542 if (MDOC_HEAD
== node
->type
)
543 p
->flags
|= TERMP_NOBREAK
;
550 * Margin control. Set-head-width lists have their right
551 * margins shortened. The body for these lists has the offset
552 * necessarily lengthened. Everybody gets the offset.
567 if (MDOC_HEAD
== node
->type
)
568 p
->rmargin
= p
->offset
+ width
;
577 * The dash, hyphen, bullet and enum lists all have a special
578 * HEAD character. Print it now.
581 if (MDOC_HEAD
== node
->type
)
592 /* TODO: have a wordfmt or something. */
593 (pair
->ppair
->ppair
->count
)++;
594 (void)snprintf(buf
, sizeof(buf
), "%d.",
595 pair
->ppair
->ppair
->count
);
603 * If we're not going to process our header children, indicate
607 if (MDOC_HEAD
== node
->type
)
629 termp_it_post(DECL_ARGS
)
633 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
636 type
= arg_listtype(node
->parent
->parent
->parent
);
644 if (MDOC_BODY
!= node
->type
)
653 p
->offset
= pair
->offset
;
654 p
->rmargin
= pair
->rmargin
;
655 p
->flags
= pair
->flag
;
661 termp_nm_pre(DECL_ARGS
)
664 if (SEC_SYNOPSIS
== node
->sec
)
667 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
668 if (NULL
== node
->child
)
677 termp_fl_pre(DECL_ARGS
)
680 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
682 p
->flags
|= TERMP_NOSPACE
;
689 termp_ar_pre(DECL_ARGS
)
692 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
699 termp_ns_pre(DECL_ARGS
)
702 p
->flags
|= TERMP_NOSPACE
;
709 termp_pp_pre(DECL_ARGS
)
719 termp_st_pre(DECL_ARGS
)
724 if (MDOC_TEXT
!= node
->child
->type
)
725 errx(1, "expected text line arguments");
726 if ((cp
= mdoc_a2st(node
->child
->string
)))
735 termp_rs_pre(DECL_ARGS
)
738 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
746 termp_rv_pre(DECL_ARGS
)
750 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
751 errx(1, "expected -std argument");
752 if (1 != node
->args
->argv
[i
].sz
)
753 errx(1, "expected -std argument");
758 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
759 word(p
, *node
->args
->argv
[i
].value
);
760 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
762 word(p
, "() function returns the value 0 if successful;");
763 word(p
, "otherwise the value -1 is returned and the");
764 word(p
, "global variable");
766 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
768 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
770 word(p
, "is set to indicate the error.");
778 termp_ex_pre(DECL_ARGS
)
782 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
783 errx(1, "expected -std argument");
784 if (1 != node
->args
->argv
[i
].sz
)
785 errx(1, "expected -std argument");
788 p
->flags
|= ttypes
[TTYPE_PROG
];
789 word(p
, *node
->args
->argv
[i
].value
);
790 p
->flags
&= ~ttypes
[TTYPE_PROG
];
791 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
799 termp_nd_pre(DECL_ARGS
)
809 termp_bl_post(DECL_ARGS
)
812 if (MDOC_BLOCK
== node
->type
)
819 termp_op_post(DECL_ARGS
)
822 if (MDOC_BODY
!= node
->type
)
824 p
->flags
|= TERMP_NOSPACE
;
831 termp_xr_pre(DECL_ARGS
)
833 const struct mdoc_node
*n
;
835 if (NULL
== (n
= node
->child
))
836 errx(1, "expected text line argument");
837 if (MDOC_TEXT
!= n
->type
)
838 errx(1, "expected text line argument");
842 if (NULL
== (n
= n
->next
))
844 if (MDOC_TEXT
!= n
->type
)
845 errx(1, "expected text line argument");
847 p
->flags
|= TERMP_NOSPACE
;
849 p
->flags
|= TERMP_NOSPACE
;
851 p
->flags
|= TERMP_NOSPACE
;
860 termp_vt_pre(DECL_ARGS
)
863 /* FIXME: this can be "type name". */
864 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
871 termp_vt_post(DECL_ARGS
)
874 if (node
->sec
== SEC_SYNOPSIS
)
881 termp_fd_pre(DECL_ARGS
)
885 * FIXME: this naming is bad. This value is used, in general,
886 * for the #include header or other preprocessor statement.
888 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
895 termp_fd_post(DECL_ARGS
)
898 if (node
->sec
!= SEC_SYNOPSIS
)
901 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
908 termp_sh_pre(DECL_ARGS
)
911 switch (node
->type
) {
914 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
928 termp_sh_post(DECL_ARGS
)
931 switch (node
->type
) {
947 termp_op_pre(DECL_ARGS
)
950 switch (node
->type
) {
953 p
->flags
|= TERMP_NOSPACE
;
964 termp_bt_pre(DECL_ARGS
)
967 word(p
, "is currently in beta test.");
974 termp_lb_post(DECL_ARGS
)
983 termp_ud_pre(DECL_ARGS
)
986 word(p
, "currently under development.");
993 termp_d1_pre(DECL_ARGS
)
996 if (MDOC_BODY
!= node
->type
)
999 p
->offset
+= (pair
->offset
= INDENT
);
1006 termp_d1_post(DECL_ARGS
)
1009 if (MDOC_BODY
!= node
->type
)
1012 p
->offset
-= pair
->offset
;
1018 termp_aq_pre(DECL_ARGS
)
1021 if (MDOC_BODY
!= node
->type
)
1024 p
->flags
|= TERMP_NOSPACE
;
1031 termp_aq_post(DECL_ARGS
)
1034 if (MDOC_BODY
!= node
->type
)
1036 p
->flags
|= TERMP_NOSPACE
;
1043 termp_ft_pre(DECL_ARGS
)
1046 if (SEC_SYNOPSIS
== node
->sec
)
1047 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1049 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1056 termp_ft_post(DECL_ARGS
)
1059 if (SEC_SYNOPSIS
== node
->sec
)
1066 termp_fn_pre(DECL_ARGS
)
1068 const struct mdoc_node
*n
;
1070 if (NULL
== node
->child
)
1071 errx(1, "expected text line arguments");
1072 if (MDOC_TEXT
!= node
->child
->type
)
1073 errx(1, "expected text line arguments");
1075 /* FIXME: can be "type funcname" "type varname"... */
1077 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1078 word(p
, node
->child
->string
);
1079 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1083 p
->flags
|= TERMP_NOSPACE
;
1084 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1085 if (MDOC_TEXT
!= n
->type
)
1086 errx(1, "expected text line arguments");
1087 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1089 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1096 if (SEC_SYNOPSIS
== node
->sec
)
1105 termp_fn_post(DECL_ARGS
)
1108 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1116 termp_sx_pre(DECL_ARGS
)
1119 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1126 termp_fa_pre(DECL_ARGS
)
1128 struct mdoc_node
*n
;
1130 if (node
->parent
->tok
!= MDOC_Fo
) {
1131 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1135 for (n
= node
->child
; n
; n
= n
->next
) {
1136 if (MDOC_TEXT
!= n
->type
)
1137 errx(1, "expected text line arguments");
1139 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1141 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1147 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1156 termp_va_pre(DECL_ARGS
)
1159 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1166 termp_bd_pre(DECL_ARGS
)
1168 const struct mdoc_node
*n
;
1171 if (MDOC_BLOCK
== node
->type
) {
1175 } else if (MDOC_BODY
!= node
->type
)
1178 if (NULL
== node
->parent
->args
)
1179 errx(1, "missing display type");
1181 pair
->offset
= p
->offset
;
1183 for (type
= -1, i
= 0;
1184 i
< (int)node
->parent
->args
->argc
; i
++) {
1185 switch (node
->parent
->args
->argv
[i
].arg
) {
1190 case (MDOC_Unfilled
):
1192 case (MDOC_Literal
):
1193 type
= node
->parent
->args
->argv
[i
].arg
;
1194 i
= (int)node
->parent
->args
->argc
;
1201 if (NULL
== node
->parent
->args
)
1202 errx(1, "missing display type");
1204 i
= arg_getattr(MDOC_Offset
, node
->parent
);
1206 if (1 != node
->parent
->args
->argv
[i
].sz
)
1207 errx(1, "expected single value");
1208 p
->offset
+= arg_offset(&node
->parent
->args
->argv
[i
]);
1212 case (MDOC_Literal
):
1214 case (MDOC_Unfilled
):
1220 p
->flags
|= TERMP_LITERAL
;
1222 for (n
= node
->child
; n
; n
= n
->next
) {
1223 if (MDOC_TEXT
!= n
->type
) {
1224 warnx("non-text children not yet allowed");
1237 termp_bd_post(DECL_ARGS
)
1240 if (MDOC_BODY
!= node
->type
)
1243 if ( ! (p
->flags
& TERMP_LITERAL
))
1246 p
->flags
&= ~TERMP_LITERAL
;
1247 p
->offset
= pair
->offset
;
1253 termp_qq_pre(DECL_ARGS
)
1256 if (MDOC_BODY
!= node
->type
)
1259 p
->flags
|= TERMP_NOSPACE
;
1266 termp_qq_post(DECL_ARGS
)
1269 if (MDOC_BODY
!= node
->type
)
1271 p
->flags
|= TERMP_NOSPACE
;
1278 termp_bsx_pre(DECL_ARGS
)
1281 word(p
, "BSDI BSD/OS");
1288 termp_bx_post(DECL_ARGS
)
1292 p
->flags
|= TERMP_NOSPACE
;
1299 termp_ox_pre(DECL_ARGS
)
1309 termp_ux_pre(DECL_ARGS
)
1319 termp_fx_pre(DECL_ARGS
)
1329 termp_nx_pre(DECL_ARGS
)
1339 termp_sq_pre(DECL_ARGS
)
1342 if (MDOC_BODY
!= node
->type
)
1345 p
->flags
|= TERMP_NOSPACE
;
1352 termp_sq_post(DECL_ARGS
)
1355 if (MDOC_BODY
!= node
->type
)
1357 p
->flags
|= TERMP_NOSPACE
;
1364 termp_pf_pre(DECL_ARGS
)
1367 p
->flags
|= TERMP_IGNDELIM
;
1374 termp_pf_post(DECL_ARGS
)
1377 p
->flags
&= ~TERMP_IGNDELIM
;
1378 p
->flags
|= TERMP_NOSPACE
;
1384 termp_ss_pre(DECL_ARGS
)
1387 switch (node
->type
) {
1390 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1391 p
->offset
= INDENT
/ 2;
1403 termp_ss_post(DECL_ARGS
)
1406 switch (node
->type
) {
1419 termp_pa_pre(DECL_ARGS
)
1422 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1429 termp_em_pre(DECL_ARGS
)
1432 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1439 termp_cd_pre(DECL_ARGS
)
1442 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1450 termp_cm_pre(DECL_ARGS
)
1453 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1460 termp_ic_pre(DECL_ARGS
)
1463 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1470 termp_in_pre(DECL_ARGS
)
1473 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1474 word(p
, "#include");
1476 p
->flags
|= TERMP_NOSPACE
;
1483 termp_in_post(DECL_ARGS
)
1486 p
->flags
|= TERMP_NOSPACE
;
1490 if (SEC_SYNOPSIS
!= node
->sec
)
1492 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1499 termp_at_pre(DECL_ARGS
)
1506 if (MDOC_TEXT
!= node
->child
->type
)
1507 errx(1, "expected text line argument");
1508 att
= mdoc_a2att(node
->child
->string
);
1521 termp_bq_pre(DECL_ARGS
)
1524 if (MDOC_BODY
!= node
->type
)
1527 p
->flags
|= TERMP_NOSPACE
;
1534 termp_bq_post(DECL_ARGS
)
1537 if (MDOC_BODY
!= node
->type
)
1545 termp_pq_pre(DECL_ARGS
)
1548 if (MDOC_BODY
!= node
->type
)
1551 p
->flags
|= TERMP_NOSPACE
;
1558 termp_pq_post(DECL_ARGS
)
1561 if (MDOC_BODY
!= node
->type
)
1569 termp_fo_pre(DECL_ARGS
)
1571 const struct mdoc_node
*n
;
1573 if (MDOC_BODY
== node
->type
) {
1575 p
->flags
|= TERMP_NOSPACE
;
1577 } else if (MDOC_HEAD
!= node
->type
)
1580 /* XXX - groff shows only first parameter */
1582 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1583 for (n
= node
->child
; n
; n
= n
->next
) {
1584 if (MDOC_TEXT
!= n
->type
)
1585 errx(1, "expected text line argument");
1588 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1596 termp_fo_post(DECL_ARGS
)
1599 if (MDOC_BODY
!= node
->type
)
1609 termp_bf_pre(DECL_ARGS
)
1611 const struct mdoc_node
*n
;
1613 if (MDOC_HEAD
== node
->type
) {
1615 } else if (MDOC_BLOCK
!= node
->type
)
1618 if (NULL
== (n
= node
->head
->child
)) {
1619 if (arg_hasattr(MDOC_Emphasis
, node
))
1620 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1621 else if (arg_hasattr(MDOC_Symbolic
, node
))
1622 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1627 if (MDOC_TEXT
!= n
->type
)
1628 errx(1, "expected text line arguments");
1630 if (0 == strcmp("Em", n
->string
))
1631 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1632 else if (0 == strcmp("Sy", n
->string
))
1633 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1641 termp_sy_pre(DECL_ARGS
)
1644 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1651 termp_ms_pre(DECL_ARGS
)
1654 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1662 termp_sm_pre(DECL_ARGS
)
1666 assert(node
->child
);
1667 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1668 p
->flags
&= ~TERMP_NONOSPACE
;
1669 p
->flags
&= ~TERMP_NOSPACE
;
1671 p
->flags
|= TERMP_NONOSPACE
;
1672 p
->flags
|= TERMP_NOSPACE
;
1682 termp__t_pre(DECL_ARGS
)
1685 /* FIXME: titles are underlined. */
1687 p
->flags
|= TERMP_NOSPACE
;
1694 termp__t_post(DECL_ARGS
)
1697 p
->flags
|= TERMP_NOSPACE
;
1698 /* FIXME: titles are underlined. */
1700 word(p
, node
->next
? "," : ".");
1706 termp____post(DECL_ARGS
)
1709 p
->flags
|= TERMP_NOSPACE
;
1710 word(p
, node
->next
? "," : ".");