]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.60 2009/03/16 22:19:19 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.
19 #include <sys/types.h>
31 * Performs actions on nodes of the abstract syntax tree. Both pre- and
32 * post-fix operations are defined here.
35 /* FIXME: macro arguments can be escaped. */
38 #define TTYPE_CMD_FLAG 1
39 #define TTYPE_CMD_ARG 2
40 #define TTYPE_SECTION 3
41 #define TTYPE_FUNC_DECL 4
42 #define TTYPE_VAR_DECL 5
43 #define TTYPE_FUNC_TYPE 6
44 #define TTYPE_FUNC_NAME 7
45 #define TTYPE_FUNC_ARG 8
47 #define TTYPE_SSECTION 10
50 #define TTYPE_CONFIG 13
52 #define TTYPE_INCLUDE 15
54 #define TTYPE_SYMBOL 17
56 #define TTYPE_LINK_ANCHOR 19
57 #define TTYPE_LINK_TEXT 20
58 #define TTYPE_REF_TITLE 21
62 * These define "styles" for element types, like command arguments or
63 * executable names. This is useful when multiple macros must decorate
64 * the same thing (like .Ex -std cmd and .Nm cmd).
67 /* TODO: abstract this into mdocterm.c. */
69 const int ttypes
[TTYPE_NMAX
] = {
70 TERMP_BOLD
, /* TTYPE_PROG */
71 TERMP_BOLD
, /* TTYPE_CMD_FLAG */
72 TERMP_UNDER
, /* TTYPE_CMD_ARG */
73 TERMP_BOLD
, /* TTYPE_SECTION */
74 TERMP_BOLD
, /* TTYPE_FUNC_DECL */
75 TERMP_UNDER
, /* TTYPE_VAR_DECL */
76 TERMP_UNDER
, /* TTYPE_FUNC_TYPE */
77 TERMP_BOLD
, /* TTYPE_FUNC_NAME */
78 TERMP_UNDER
, /* TTYPE_FUNC_ARG */
79 TERMP_UNDER
, /* TTYPE_LINK */
80 TERMP_BOLD
, /* TTYPE_SSECTION */
81 TERMP_UNDER
, /* TTYPE_FILE */
82 TERMP_UNDER
, /* TTYPE_EMPH */
83 TERMP_BOLD
, /* TTYPE_CONFIG */
84 TERMP_BOLD
, /* TTYPE_CMD */
85 TERMP_BOLD
, /* TTYPE_INCLUDE */
86 TERMP_BOLD
, /* TTYPE_SYMB */
87 TERMP_BOLD
, /* TTYPE_SYMBOL */
88 TERMP_BOLD
, /* TTYPE_DIAG */
89 TERMP_UNDER
, /* TTYPE_LINK_ANCHOR */
90 TERMP_BOLD
, /* TTYPE_LINK_TEXT */
91 TERMP_UNDER
/* TTYPE_REF_TITLE */
94 static int arg_hasattr(int, const struct mdoc_node
*);
95 static int arg_getattrs(const int *, int *, size_t,
96 const struct mdoc_node
*);
97 static int arg_getattr(int, const struct mdoc_node
*);
98 static size_t arg_offset(const struct mdoc_argv
*);
99 static size_t arg_width(const struct mdoc_argv
*, int);
100 static int arg_listtype(const struct mdoc_node
*);
103 * What follows describes prefix and postfix operations for the abstract
104 * syntax tree descent.
109 struct termpair *pair, \
110 const struct mdoc_meta *meta, \
111 const struct mdoc_node *node
113 #define DECL_PRE(name) \
114 static int name##_pre(DECL_ARGS)
115 #define DECL_POST(name) \
116 static void name##_post(DECL_ARGS)
117 #define DECL_PREPOST(name) \
121 DECL_PREPOST(termp_aq
);
122 DECL_PREPOST(termp_bd
);
123 DECL_PREPOST(termp_bq
);
124 DECL_PREPOST(termp_brq
);
125 DECL_PREPOST(termp_d1
);
126 DECL_PREPOST(termp_dq
);
127 DECL_PREPOST(termp_fd
);
128 DECL_PREPOST(termp_fn
);
129 DECL_PREPOST(termp_fo
);
130 DECL_PREPOST(termp_ft
);
131 DECL_PREPOST(termp_in
);
132 DECL_PREPOST(termp_it
);
133 DECL_PREPOST(termp_lb
);
134 DECL_PREPOST(termp_op
);
135 DECL_PREPOST(termp_pf
);
136 DECL_PREPOST(termp_pq
);
137 DECL_PREPOST(termp_qq
);
138 DECL_PREPOST(termp_sh
);
139 DECL_PREPOST(termp_ss
);
140 DECL_PREPOST(termp_sq
);
141 DECL_PREPOST(termp_vt
);
183 const struct termact __termacts
[MDOC_MAX
] = {
184 { NULL
, NULL
}, /* \" */
185 { NULL
, NULL
}, /* Dd */
186 { NULL
, NULL
}, /* Dt */
187 { NULL
, NULL
}, /* Os */
188 { termp_sh_pre
, termp_sh_post
}, /* Sh */
189 { termp_ss_pre
, termp_ss_post
}, /* Ss */
190 { termp_pp_pre
, NULL
}, /* Pp */
191 { termp_d1_pre
, termp_d1_post
}, /* D1 */
192 { termp_d1_pre
, termp_d1_post
}, /* Dl */
193 { termp_bd_pre
, termp_bd_post
}, /* Bd */
194 { NULL
, NULL
}, /* Ed */
195 { NULL
, termp_bl_post
}, /* Bl */
196 { NULL
, NULL
}, /* El */
197 { termp_it_pre
, termp_it_post
}, /* It */
198 { NULL
, NULL
}, /* Ad */
199 { NULL
, NULL
}, /* An */
200 { termp_ar_pre
, NULL
}, /* Ar */
201 { termp_cd_pre
, NULL
}, /* Cd */
202 { termp_cm_pre
, NULL
}, /* Cm */
203 { NULL
, NULL
}, /* Dv */
204 { NULL
, NULL
}, /* Er */
205 { NULL
, NULL
}, /* Ev */
206 { termp_ex_pre
, NULL
}, /* Ex */
207 { termp_fa_pre
, NULL
}, /* Fa */
208 { termp_fd_pre
, termp_fd_post
}, /* Fd */
209 { termp_fl_pre
, NULL
}, /* Fl */
210 { termp_fn_pre
, termp_fn_post
}, /* Fn */
211 { termp_ft_pre
, termp_ft_post
}, /* Ft */
212 { termp_ic_pre
, NULL
}, /* Ic */
213 { termp_in_pre
, termp_in_post
}, /* In */
214 { NULL
, NULL
}, /* Li */
215 { termp_nd_pre
, NULL
}, /* Nd */
216 { termp_nm_pre
, NULL
}, /* Nm */
217 { termp_op_pre
, termp_op_post
}, /* Op */
218 { NULL
, NULL
}, /* Ot */
219 { termp_pa_pre
, NULL
}, /* Pa */
220 { termp_rv_pre
, NULL
}, /* Rv */
221 { termp_st_pre
, NULL
}, /* St */
222 { termp_va_pre
, NULL
}, /* Va */
223 { termp_vt_pre
, termp_vt_post
}, /* Vt */
224 { termp_xr_pre
, NULL
}, /* Xr */
225 { NULL
, termp____post
}, /* %A */
226 { NULL
, termp____post
}, /* %B */
227 { NULL
, termp____post
}, /* %D */
228 { NULL
, termp____post
}, /* %I */
229 { NULL
, termp____post
}, /* %J */
230 { NULL
, termp____post
}, /* %N */
231 { NULL
, termp____post
}, /* %O */
232 { NULL
, termp____post
}, /* %P */
233 { NULL
, termp____post
}, /* %R */
234 { termp__t_pre
, termp____post
}, /* %T */
235 { NULL
, termp____post
}, /* %V */
236 { NULL
, NULL
}, /* Ac */
237 { termp_aq_pre
, termp_aq_post
}, /* Ao */
238 { termp_aq_pre
, termp_aq_post
}, /* Aq */
239 { termp_at_pre
, NULL
}, /* At */
240 { NULL
, NULL
}, /* Bc */
241 { termp_bf_pre
, NULL
}, /* Bf */
242 { termp_bq_pre
, termp_bq_post
}, /* Bo */
243 { termp_bq_pre
, termp_bq_post
}, /* Bq */
244 { termp_bsx_pre
, NULL
}, /* Bsx */
245 { NULL
, termp_bx_post
}, /* Bx */
246 { NULL
, NULL
}, /* Db */
247 { NULL
, NULL
}, /* Dc */
248 { termp_dq_pre
, termp_dq_post
}, /* Do */
249 { termp_dq_pre
, termp_dq_post
}, /* Dq */
250 { NULL
, NULL
}, /* Ec */
251 { NULL
, NULL
}, /* Ef */
252 { termp_em_pre
, NULL
}, /* Em */
253 { NULL
, NULL
}, /* Eo */
254 { termp_fx_pre
, NULL
}, /* Fx */
255 { termp_ms_pre
, NULL
}, /* Ms */
256 { NULL
, NULL
}, /* No */
257 { termp_ns_pre
, NULL
}, /* Ns */
258 { termp_nx_pre
, NULL
}, /* Nx */
259 { termp_ox_pre
, NULL
}, /* Ox */
260 { NULL
, NULL
}, /* Pc */
261 { termp_pf_pre
, termp_pf_post
}, /* Pf */
262 { termp_pq_pre
, termp_pq_post
}, /* Po */
263 { termp_pq_pre
, termp_pq_post
}, /* Pq */
264 { NULL
, NULL
}, /* Qc */
265 { termp_sq_pre
, termp_sq_post
}, /* Ql */
266 { termp_qq_pre
, termp_qq_post
}, /* Qo */
267 { termp_qq_pre
, termp_qq_post
}, /* Qq */
268 { NULL
, NULL
}, /* Re */
269 { termp_rs_pre
, NULL
}, /* Rs */
270 { NULL
, NULL
}, /* Sc */
271 { termp_sq_pre
, termp_sq_post
}, /* So */
272 { termp_sq_pre
, termp_sq_post
}, /* Sq */
273 { termp_sm_pre
, NULL
}, /* Sm */
274 { termp_sx_pre
, NULL
}, /* Sx */
275 { termp_sy_pre
, NULL
}, /* Sy */
276 { NULL
, NULL
}, /* Tn */
277 { termp_ux_pre
, NULL
}, /* Ux */
278 { NULL
, NULL
}, /* Xc */
279 { NULL
, NULL
}, /* Xo */
280 { termp_fo_pre
, termp_fo_post
}, /* Fo */
281 { NULL
, NULL
}, /* Fc */
282 { termp_op_pre
, termp_op_post
}, /* Oo */
283 { NULL
, NULL
}, /* Oc */
284 { NULL
, NULL
}, /* Bk */
285 { NULL
, NULL
}, /* Ek */
286 { termp_bt_pre
, NULL
}, /* Bt */
287 { NULL
, NULL
}, /* Hf */
288 { NULL
, NULL
}, /* Fr */
289 { termp_ud_pre
, NULL
}, /* Ud */
290 { termp_lb_pre
, termp_lb_post
}, /* Lb */
291 { termp_ap_pre
, NULL
}, /* Lb */
292 { termp_pp_pre
, NULL
}, /* Pp */
293 { termp_lk_pre
, NULL
}, /* Lk */
294 { termp_mt_pre
, NULL
}, /* Mt */
295 { termp_brq_pre
, termp_brq_post
}, /* Brq */
296 { termp_brq_pre
, termp_brq_post
}, /* Bro */
297 { NULL
, NULL
}, /* Brc */
298 { NULL
, NULL
}, /* %C */
299 { NULL
, NULL
}, /* Es */
300 { NULL
, NULL
}, /* En */
303 const struct termact
*termacts
= __termacts
;
307 arg_width(const struct mdoc_argv
*arg
, int pos
)
312 assert(pos
< (int)arg
->sz
&& pos
>= 0);
313 assert(arg
->value
[pos
]);
314 if (0 == strcmp(arg
->value
[pos
], "indent"))
316 if (0 == strcmp(arg
->value
[pos
], "indent-two"))
319 len
= (int)strlen(arg
->value
[pos
]);
322 for (i
= 0; i
< len
- 1; i
++)
323 if ( ! isdigit((u_char
)arg
->value
[pos
][i
]))
327 if ('n' == arg
->value
[pos
][len
- 1]) {
328 v
= (size_t)atoi(arg
->value
[pos
]);
333 return(strlen(arg
->value
[pos
]) + 1);
338 arg_listtype(const struct mdoc_node
*n
)
342 assert(MDOC_BLOCK
== n
->type
);
344 len
= (int)(n
->args
? n
->args
->argc
: 0);
346 for (i
= 0; i
< len
; i
++)
347 switch (n
->args
->argv
[i
].arg
) {
367 return(n
->args
->argv
[i
].arg
);
372 errx(1, "list type not supported");
378 arg_offset(const struct mdoc_argv
*arg
)
383 if (0 == strcmp(*arg
->value
, "indent"))
385 if (0 == strcmp(*arg
->value
, "indent-two"))
387 return(strlen(*arg
->value
));
392 arg_hasattr(int arg
, const struct mdoc_node
*n
)
395 return(-1 != arg_getattr(arg
, n
));
400 arg_getattr(int v
, const struct mdoc_node
*n
)
404 return(arg_getattrs(&v
, &val
, 1, n
) ? val
: -1);
409 arg_getattrs(const int *keys
, int *vals
,
410 size_t sz
, const struct mdoc_node
*n
)
417 for (k
= i
= 0; i
< (int)n
->args
->argc
; i
++)
418 for (j
= 0; j
< (int)sz
; j
++)
419 if (n
->args
->argv
[i
].arg
== keys
[j
]) {
429 termp_dq_pre(DECL_ARGS
)
432 if (MDOC_BODY
!= node
->type
)
436 p
->flags
|= TERMP_NOSPACE
;
443 termp_dq_post(DECL_ARGS
)
446 if (MDOC_BODY
!= node
->type
)
449 p
->flags
|= TERMP_NOSPACE
;
456 termp_it_pre_block(DECL_ARGS
)
460 if ( ! arg_hasattr(MDOC_Compact
, node
->parent
->parent
))
461 /* FIXME: parent->parent->parent? */
462 if (node
->prev
|| node
->parent
->parent
->prev
)
471 termp_it_pre(DECL_ARGS
)
473 const struct mdoc_node
*bl
, *n
;
475 int i
, type
, keys
[3], vals
[3];
476 size_t width
, offset
;
478 if (MDOC_BLOCK
== node
->type
)
479 return(termp_it_pre_block(p
, pair
, meta
, node
));
481 bl
= node
->parent
->parent
->parent
;
483 /* Save parent attributes. */
485 pair
->offset
= p
->offset
;
486 pair
->rmargin
= p
->rmargin
;
487 pair
->flag
= p
->flags
;
489 /* Get list width and offset. */
491 keys
[0] = MDOC_Width
;
492 keys
[1] = MDOC_Offset
;
493 keys
[2] = MDOC_Column
;
495 vals
[0] = vals
[1] = vals
[2] = -1;
499 (void)arg_getattrs(keys
, vals
, 3, bl
);
501 type
= arg_listtype(bl
);
503 /* Calculate real width and offset. */
507 if (MDOC_BODY
== node
->type
)
509 for (i
= 0, n
= node
->prev
; n
; n
= n
->prev
, i
++)
511 (&bl
->args
->argv
[vals
[2]], i
);
512 assert(i
< (int)bl
->args
->argv
[vals
[2]].sz
);
513 width
= arg_width(&bl
->args
->argv
[vals
[2]], i
);
515 offset
+= arg_offset(&bl
->args
->argv
[vals
[1]]);
519 width
= arg_width(&bl
->args
->argv
[vals
[0]], 0);
521 offset
= arg_offset(&bl
->args
->argv
[vals
[1]]);
526 * List-type can override the width in the case of fixed-head
527 * values (bullet, dash/hyphen, enum). Tags need a non-zero
551 * Whitespace control. Inset bodies need an initial space.
558 if (MDOC_BODY
== node
->type
)
559 p
->flags
&= ~TERMP_NOSPACE
;
561 p
->flags
|= TERMP_NOSPACE
;
564 p
->flags
|= TERMP_NOSPACE
;
569 * Style flags. Diagnostic heads need TTYPE_DIAG.
574 if (MDOC_HEAD
== node
->type
)
575 p
->flags
|= ttypes
[TTYPE_DIAG
];
582 * Pad and break control. This is the tricker part. Lists with
583 * set right-margins for the head get TERMP_NOBREAK because, if
584 * they overrun the margin, they wrap to the new margin.
585 * Correspondingly, the body for these types don't left-pad, as
586 * the head will pad out to to the right.
599 if (MDOC_HEAD
== node
->type
)
600 p
->flags
|= TERMP_NOBREAK
;
602 p
->flags
|= TERMP_NOLPAD
;
603 if (MDOC_HEAD
== node
->type
&& MDOC_Tag
== type
)
604 if (NULL
== node
->next
||
605 NULL
== node
->next
->child
)
606 p
->flags
|= TERMP_NONOBREAK
;
609 if (MDOC_HEAD
== node
->type
) {
611 if (MDOC_BODY
== node
->next
->type
)
612 p
->flags
&= ~TERMP_NOBREAK
;
614 p
->flags
|= TERMP_NOBREAK
;
616 p
->flags
|= TERMP_NOLPAD
;
620 if (MDOC_HEAD
== node
->type
)
621 p
->flags
|= TERMP_NOBREAK
;
628 * Margin control. Set-head-width lists have their right
629 * margins shortened. The body for these lists has the offset
630 * necessarily lengthened. Everybody gets the offset.
645 if (MDOC_HEAD
== node
->type
)
646 p
->rmargin
= p
->offset
+ width
;
651 p
->rmargin
= p
->offset
+ width
;
658 * The dash, hyphen, bullet and enum lists all have a special
659 * HEAD character. Print it now.
662 if (MDOC_HEAD
== node
->type
)
673 (pair
->ppair
->ppair
->count
)++;
674 (void)snprintf(buf
, sizeof(buf
), "%d.",
675 pair
->ppair
->ppair
->count
);
683 * If we're not going to process our children, indicate so here.
696 if (MDOC_HEAD
== node
->type
)
700 if (MDOC_BODY
== node
->type
)
713 termp_it_post(DECL_ARGS
)
717 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
720 type
= arg_listtype(node
->parent
->parent
->parent
);
728 if (MDOC_BODY
== node
->type
)
732 if (MDOC_HEAD
== node
->type
)
740 p
->offset
= pair
->offset
;
741 p
->rmargin
= pair
->rmargin
;
742 p
->flags
= pair
->flag
;
748 termp_nm_pre(DECL_ARGS
)
751 if (SEC_SYNOPSIS
== node
->sec
)
754 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
755 if (NULL
== node
->child
)
764 termp_fl_pre(DECL_ARGS
)
767 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
769 p
->flags
|= TERMP_NOSPACE
;
776 termp_ar_pre(DECL_ARGS
)
779 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
786 termp_ns_pre(DECL_ARGS
)
789 p
->flags
|= TERMP_NOSPACE
;
796 termp_pp_pre(DECL_ARGS
)
806 termp_st_pre(DECL_ARGS
)
810 if (node
->child
&& (cp
= mdoc_a2st(node
->child
->string
)))
818 termp_rs_pre(DECL_ARGS
)
821 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
829 termp_rv_pre(DECL_ARGS
)
833 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
834 errx(1, "expected -std argument");
835 if (1 != node
->args
->argv
[i
].sz
)
836 errx(1, "expected -std argument");
841 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
842 word(p
, *node
->args
->argv
[i
].value
);
843 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
844 p
->flags
|= TERMP_NOSPACE
;
846 word(p
, "() function returns the value 0 if successful;");
847 word(p
, "otherwise the value -1 is returned and the");
848 word(p
, "global variable");
850 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
852 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
854 word(p
, "is set to indicate the error.");
862 termp_ex_pre(DECL_ARGS
)
866 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
867 errx(1, "expected -std argument");
868 if (1 != node
->args
->argv
[i
].sz
)
869 errx(1, "expected -std argument");
872 p
->flags
|= ttypes
[TTYPE_PROG
];
873 word(p
, *node
->args
->argv
[i
].value
);
874 p
->flags
&= ~ttypes
[TTYPE_PROG
];
875 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
883 termp_nd_pre(DECL_ARGS
)
893 termp_bl_post(DECL_ARGS
)
896 if (MDOC_BLOCK
== node
->type
)
903 termp_op_post(DECL_ARGS
)
906 if (MDOC_BODY
!= node
->type
)
908 p
->flags
|= TERMP_NOSPACE
;
915 termp_xr_pre(DECL_ARGS
)
917 const struct mdoc_node
*n
;
919 if (NULL
== (n
= node
->child
))
920 errx(1, "expected text line argument");
922 if (NULL
== (n
= n
->next
))
924 p
->flags
|= TERMP_NOSPACE
;
926 p
->flags
|= TERMP_NOSPACE
;
928 p
->flags
|= TERMP_NOSPACE
;
936 termp_vt_pre(DECL_ARGS
)
939 /* FIXME: this can be "type name". */
940 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
947 termp_vt_post(DECL_ARGS
)
950 if (node
->sec
== SEC_SYNOPSIS
)
957 termp_fd_pre(DECL_ARGS
)
961 * FIXME: this naming is bad. This value is used, in general,
962 * for the #include header or other preprocessor statement.
964 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
971 termp_fd_post(DECL_ARGS
)
974 if (node
->sec
!= SEC_SYNOPSIS
)
977 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
984 termp_sh_pre(DECL_ARGS
)
987 switch (node
->type
) {
990 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
1004 termp_sh_post(DECL_ARGS
)
1007 switch (node
->type
) {
1023 termp_op_pre(DECL_ARGS
)
1026 switch (node
->type
) {
1029 p
->flags
|= TERMP_NOSPACE
;
1040 termp_bt_pre(DECL_ARGS
)
1043 word(p
, "is currently in beta test.");
1050 termp_lb_pre(DECL_ARGS
)
1054 if (NULL
== node
->child
)
1055 errx(1, "expected text line argument");
1056 if ((lb
= mdoc_a2lib(node
->child
->string
))) {
1067 termp_lb_post(DECL_ARGS
)
1076 termp_ud_pre(DECL_ARGS
)
1079 word(p
, "currently under development.");
1086 termp_d1_pre(DECL_ARGS
)
1089 if (MDOC_BODY
!= node
->type
)
1092 p
->offset
+= (pair
->offset
= INDENT
);
1099 termp_d1_post(DECL_ARGS
)
1102 if (MDOC_BODY
!= node
->type
)
1105 p
->offset
-= pair
->offset
;
1111 termp_aq_pre(DECL_ARGS
)
1114 if (MDOC_BODY
!= node
->type
)
1117 p
->flags
|= TERMP_NOSPACE
;
1124 termp_aq_post(DECL_ARGS
)
1127 if (MDOC_BODY
!= node
->type
)
1129 p
->flags
|= TERMP_NOSPACE
;
1136 termp_ft_pre(DECL_ARGS
)
1139 if (SEC_SYNOPSIS
== node
->sec
)
1140 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1142 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1149 termp_ft_post(DECL_ARGS
)
1152 if (SEC_SYNOPSIS
== node
->sec
)
1159 termp_fn_pre(DECL_ARGS
)
1161 const struct mdoc_node
*n
;
1163 if (NULL
== node
->child
)
1164 errx(1, "expected text line arguments");
1166 /* FIXME: can be "type funcname" "type varname"... */
1168 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1169 word(p
, node
->child
->string
);
1170 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1174 p
->flags
|= TERMP_NOSPACE
;
1175 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1176 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1178 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1185 if (SEC_SYNOPSIS
== node
->sec
)
1194 termp_fn_post(DECL_ARGS
)
1197 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1205 termp_sx_pre(DECL_ARGS
)
1208 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1215 termp_fa_pre(DECL_ARGS
)
1217 struct mdoc_node
*n
;
1219 if (node
->parent
->tok
!= MDOC_Fo
) {
1220 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1224 for (n
= node
->child
; n
; n
= n
->next
) {
1225 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1227 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1232 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1241 termp_va_pre(DECL_ARGS
)
1244 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1251 termp_bd_pre(DECL_ARGS
)
1253 const struct mdoc_node
*n
;
1256 if (MDOC_BLOCK
== node
->type
) {
1257 /* FIXME: parent prev? */
1261 } else if (MDOC_BODY
!= node
->type
)
1264 if (NULL
== node
->parent
->args
)
1265 errx(1, "missing display type");
1267 pair
->offset
= p
->offset
;
1269 for (type
= -1, i
= 0;
1270 i
< (int)node
->parent
->args
->argc
; i
++) {
1271 switch (node
->parent
->args
->argv
[i
].arg
) {
1276 case (MDOC_Unfilled
):
1278 case (MDOC_Literal
):
1279 type
= node
->parent
->args
->argv
[i
].arg
;
1280 i
= (int)node
->parent
->args
->argc
;
1287 if (NULL
== node
->parent
->args
)
1288 errx(1, "missing display type");
1290 i
= arg_getattr(MDOC_Offset
, node
->parent
);
1292 if (1 != node
->parent
->args
->argv
[i
].sz
)
1293 errx(1, "expected single value");
1294 p
->offset
+= arg_offset(&node
->parent
->args
->argv
[i
]);
1298 case (MDOC_Literal
):
1300 case (MDOC_Unfilled
):
1306 p
->flags
|= TERMP_LITERAL
;
1308 for (n
= node
->child
; n
; n
= n
->next
) {
1309 if (MDOC_TEXT
!= n
->type
) {
1310 warnx("non-text children not yet allowed");
1323 termp_bd_post(DECL_ARGS
)
1326 if (MDOC_BODY
!= node
->type
)
1329 if ( ! (p
->flags
& TERMP_LITERAL
))
1332 p
->flags
&= ~TERMP_LITERAL
;
1333 p
->offset
= pair
->offset
;
1339 termp_qq_pre(DECL_ARGS
)
1342 if (MDOC_BODY
!= node
->type
)
1345 p
->flags
|= TERMP_NOSPACE
;
1352 termp_qq_post(DECL_ARGS
)
1355 if (MDOC_BODY
!= node
->type
)
1357 p
->flags
|= TERMP_NOSPACE
;
1364 termp_bsx_pre(DECL_ARGS
)
1367 word(p
, "BSDI BSD/OS");
1374 termp_bx_post(DECL_ARGS
)
1378 p
->flags
|= TERMP_NOSPACE
;
1385 termp_ox_pre(DECL_ARGS
)
1395 termp_ux_pre(DECL_ARGS
)
1405 termp_fx_pre(DECL_ARGS
)
1415 termp_nx_pre(DECL_ARGS
)
1425 termp_sq_pre(DECL_ARGS
)
1428 if (MDOC_BODY
!= node
->type
)
1431 p
->flags
|= TERMP_NOSPACE
;
1438 termp_sq_post(DECL_ARGS
)
1441 if (MDOC_BODY
!= node
->type
)
1443 p
->flags
|= TERMP_NOSPACE
;
1450 termp_pf_pre(DECL_ARGS
)
1453 p
->flags
|= TERMP_IGNDELIM
;
1460 termp_pf_post(DECL_ARGS
)
1463 p
->flags
&= ~TERMP_IGNDELIM
;
1464 p
->flags
|= TERMP_NOSPACE
;
1470 termp_ss_pre(DECL_ARGS
)
1473 switch (node
->type
) {
1480 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1481 p
->offset
= INDENT
/ 2;
1493 termp_ss_post(DECL_ARGS
)
1496 switch (node
->type
) {
1509 termp_pa_pre(DECL_ARGS
)
1512 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1519 termp_em_pre(DECL_ARGS
)
1522 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1529 termp_cd_pre(DECL_ARGS
)
1532 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1540 termp_cm_pre(DECL_ARGS
)
1543 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1550 termp_ic_pre(DECL_ARGS
)
1553 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1560 termp_in_pre(DECL_ARGS
)
1563 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1564 word(p
, "#include");
1566 p
->flags
|= TERMP_NOSPACE
;
1573 termp_in_post(DECL_ARGS
)
1576 p
->flags
|= TERMP_NOSPACE
;
1580 if (SEC_SYNOPSIS
!= node
->sec
)
1582 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1589 termp_at_pre(DECL_ARGS
)
1596 att
= mdoc_a2att(node
->child
->string
);
1607 termp_brq_pre(DECL_ARGS
)
1610 if (MDOC_BODY
!= node
->type
)
1613 p
->flags
|= TERMP_NOSPACE
;
1620 termp_brq_post(DECL_ARGS
)
1623 if (MDOC_BODY
!= node
->type
)
1625 p
->flags
|= TERMP_NOSPACE
;
1632 termp_bq_pre(DECL_ARGS
)
1635 if (MDOC_BODY
!= node
->type
)
1638 p
->flags
|= TERMP_NOSPACE
;
1645 termp_bq_post(DECL_ARGS
)
1648 if (MDOC_BODY
!= node
->type
)
1650 p
->flags
|= TERMP_NOSPACE
;
1657 termp_pq_pre(DECL_ARGS
)
1660 if (MDOC_BODY
!= node
->type
)
1663 p
->flags
|= TERMP_NOSPACE
;
1670 termp_pq_post(DECL_ARGS
)
1673 if (MDOC_BODY
!= node
->type
)
1681 termp_fo_pre(DECL_ARGS
)
1683 const struct mdoc_node
*n
;
1685 if (MDOC_BODY
== node
->type
) {
1687 p
->flags
|= TERMP_NOSPACE
;
1689 } else if (MDOC_HEAD
!= node
->type
)
1692 /* XXX - groff shows only first parameter */
1694 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1695 for (n
= node
->child
; n
; n
= n
->next
) {
1696 if (MDOC_TEXT
!= n
->type
)
1697 errx(1, "expected text line argument");
1700 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1708 termp_fo_post(DECL_ARGS
)
1711 if (MDOC_BODY
!= node
->type
)
1713 p
->flags
|= TERMP_NOSPACE
;
1715 p
->flags
|= TERMP_NOSPACE
;
1723 termp_bf_pre(DECL_ARGS
)
1725 const struct mdoc_node
*n
;
1727 if (MDOC_HEAD
== node
->type
) {
1729 } else if (MDOC_BLOCK
!= node
->type
)
1732 if (NULL
== (n
= node
->head
->child
)) {
1733 if (arg_hasattr(MDOC_Emphasis
, node
))
1734 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1735 else if (arg_hasattr(MDOC_Symbolic
, node
))
1736 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1741 if (MDOC_TEXT
!= n
->type
)
1742 errx(1, "expected text line arguments");
1744 if (0 == strcmp("Em", n
->string
))
1745 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1746 else if (0 == strcmp("Sy", n
->string
))
1747 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1755 termp_sy_pre(DECL_ARGS
)
1758 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1765 termp_ms_pre(DECL_ARGS
)
1768 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1776 termp_sm_pre(DECL_ARGS
)
1780 assert(node
->child
);
1781 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1782 p
->flags
&= ~TERMP_NONOSPACE
;
1783 p
->flags
&= ~TERMP_NOSPACE
;
1785 p
->flags
|= TERMP_NONOSPACE
;
1786 p
->flags
|= TERMP_NOSPACE
;
1796 termp_ap_pre(DECL_ARGS
)
1799 p
->flags
|= TERMP_NOSPACE
;
1801 p
->flags
|= TERMP_NOSPACE
;
1808 termp__t_pre(DECL_ARGS
)
1811 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_REF_TITLE
]);
1818 termp____post(DECL_ARGS
)
1821 p
->flags
|= TERMP_NOSPACE
;
1822 word(p
, node
->next
? "," : ".");
1828 termp_lk_pre(DECL_ARGS
)
1830 const struct mdoc_node
*n
;
1832 if (NULL
== (n
= node
->child
))
1833 errx(1, "expected line argument");
1835 p
->flags
|= ttypes
[TTYPE_LINK_ANCHOR
];
1837 p
->flags
&= ~ttypes
[TTYPE_LINK_ANCHOR
];
1838 p
->flags
|= TERMP_NOSPACE
;
1841 p
->flags
|= ttypes
[TTYPE_LINK_TEXT
];
1842 for ( ; n
; n
= n
->next
) {
1845 p
->flags
&= ~ttypes
[TTYPE_LINK_TEXT
];
1853 termp_mt_pre(DECL_ARGS
)
1856 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK_ANCHOR
]);