]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.54 2009/03/12 02:57:36 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_UNDERLINE
, /* TTYPE_CMD_ARG */
73 TERMP_BOLD
, /* TTYPE_SECTION */
74 TERMP_BOLD
, /* TTYPE_FUNC_DECL */
75 TERMP_UNDERLINE
, /* TTYPE_VAR_DECL */
76 TERMP_UNDERLINE
, /* TTYPE_FUNC_TYPE */
77 TERMP_BOLD
, /* TTYPE_FUNC_NAME */
78 TERMP_UNDERLINE
, /* TTYPE_FUNC_ARG */
79 TERMP_UNDERLINE
, /* TTYPE_LINK */
80 TERMP_BOLD
, /* TTYPE_SSECTION */
81 TERMP_UNDERLINE
, /* TTYPE_FILE */
82 TERMP_UNDERLINE
, /* 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_UNDERLINE
, /* TTYPE_LINK_ANCHOR */
90 TERMP_BOLD
, /* TTYPE_LINK_TEXT */
91 TERMP_UNDERLINE
/* 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 */
300 const struct termact
*termacts
= __termacts
;
304 arg_width(const struct mdoc_argv
*arg
, int pos
)
309 assert(pos
< (int)arg
->sz
&& pos
>= 0);
310 assert(arg
->value
[pos
]);
311 if (0 == strcmp(arg
->value
[pos
], "indent"))
313 if (0 == strcmp(arg
->value
[pos
], "indent-two"))
316 len
= (int)strlen(arg
->value
[pos
]);
319 for (i
= 0; i
< len
- 1; i
++)
320 if ( ! isdigit((u_char
)arg
->value
[pos
][i
]))
324 if ('n' == arg
->value
[pos
][len
- 1]) {
325 v
= (size_t)atoi(arg
->value
[pos
]);
330 return(strlen(arg
->value
[pos
]) + 1);
335 arg_listtype(const struct mdoc_node
*n
)
339 assert(MDOC_BLOCK
== n
->type
);
341 len
= (int)(n
->args
? n
->args
->argc
: 0);
343 for (i
= 0; i
< len
; i
++)
344 switch (n
->args
->argv
[i
].arg
) {
364 return(n
->args
->argv
[i
].arg
);
369 errx(1, "list type not supported");
375 arg_offset(const struct mdoc_argv
*arg
)
380 if (0 == strcmp(*arg
->value
, "indent"))
382 if (0 == strcmp(*arg
->value
, "indent-two"))
384 return(strlen(*arg
->value
));
389 arg_hasattr(int arg
, const struct mdoc_node
*n
)
392 return(-1 != arg_getattr(arg
, n
));
397 arg_getattr(int v
, const struct mdoc_node
*n
)
401 return(arg_getattrs(&v
, &val
, 1, n
) ? val
: -1);
406 arg_getattrs(const int *keys
, int *vals
,
407 size_t sz
, const struct mdoc_node
*n
)
414 for (k
= i
= 0; i
< (int)n
->args
->argc
; i
++)
415 for (j
= 0; j
< (int)sz
; j
++)
416 if (n
->args
->argv
[i
].arg
== keys
[j
]) {
426 termp_dq_pre(DECL_ARGS
)
429 if (MDOC_BODY
!= node
->type
)
433 p
->flags
|= TERMP_NOSPACE
;
440 termp_dq_post(DECL_ARGS
)
443 if (MDOC_BODY
!= node
->type
)
446 p
->flags
|= TERMP_NOSPACE
;
453 termp_it_pre_block(DECL_ARGS
)
457 if ( ! arg_hasattr(MDOC_Compact
, node
->parent
->parent
))
458 /* FIXME: parent->parent->parent? */
459 if (node
->prev
|| node
->parent
->parent
->prev
)
468 termp_it_pre(DECL_ARGS
)
470 const struct mdoc_node
*bl
, *n
;
472 int i
, type
, keys
[3], vals
[3];
473 size_t width
, offset
;
475 if (MDOC_BLOCK
== node
->type
)
476 return(termp_it_pre_block(p
, pair
, meta
, node
));
478 bl
= node
->parent
->parent
->parent
;
480 /* Save parent attributes. */
482 pair
->offset
= p
->offset
;
483 pair
->rmargin
= p
->rmargin
;
484 pair
->flag
= p
->flags
;
486 /* Get list width and offset. */
488 keys
[0] = MDOC_Width
;
489 keys
[1] = MDOC_Offset
;
490 keys
[2] = MDOC_Column
;
492 vals
[0] = vals
[1] = vals
[2] = -1;
496 (void)arg_getattrs(keys
, vals
, 3, bl
);
498 type
= arg_listtype(bl
);
500 /* Calculate real width and offset. */
504 if (MDOC_BODY
== node
->type
)
506 for (i
= 0, n
= node
->prev
; n
; n
= n
->prev
, i
++)
508 (&bl
->args
->argv
[vals
[2]], i
);
509 assert(i
< (int)bl
->args
->argv
[vals
[2]].sz
);
510 width
= arg_width(&bl
->args
->argv
[vals
[2]], i
);
514 width
= arg_width(&bl
->args
->argv
[vals
[0]], 0);
516 offset
= arg_offset(&bl
->args
->argv
[vals
[1]]);
521 * List-type can override the width in the case of fixed-head
522 * values (bullet, dash/hyphen, enum). Tags need a non-zero
546 * Whitespace control. Inset bodies need an initial space.
553 if (MDOC_BODY
== node
->type
)
554 p
->flags
&= ~TERMP_NOSPACE
;
556 p
->flags
|= TERMP_NOSPACE
;
559 p
->flags
|= TERMP_NOSPACE
;
564 * Style flags. Diagnostic heads need TTYPE_DIAG.
569 if (MDOC_HEAD
== node
->type
)
570 p
->flags
|= ttypes
[TTYPE_DIAG
];
577 * Pad and break control. This is the tricker part. Lists with
578 * set right-margins for the head get TERMP_NOBREAK because, if
579 * they overrun the margin, they wrap to the new margin.
580 * Correspondingly, the body for these types don't left-pad, as
581 * the head will pad out to to the right.
594 if (MDOC_HEAD
== node
->type
)
595 p
->flags
|= TERMP_NOBREAK
;
597 p
->flags
|= TERMP_NOLPAD
;
598 if (MDOC_HEAD
== node
->type
&& MDOC_Tag
== type
)
599 if (NULL
== node
->next
||
600 NULL
== node
->next
->child
)
601 p
->flags
|= TERMP_NONOBREAK
;
604 if (MDOC_HEAD
== node
->type
) {
606 if (MDOC_BODY
== node
->next
->type
)
607 p
->flags
&= ~TERMP_NOBREAK
;
609 p
->flags
|= TERMP_NOBREAK
;
611 p
->flags
|= TERMP_NOLPAD
;
615 if (MDOC_HEAD
== node
->type
)
616 p
->flags
|= TERMP_NOBREAK
;
623 * Margin control. Set-head-width lists have their right
624 * margins shortened. The body for these lists has the offset
625 * necessarily lengthened. Everybody gets the offset.
640 if (MDOC_HEAD
== node
->type
)
641 p
->rmargin
= p
->offset
+ width
;
646 p
->rmargin
= p
->offset
+ width
;
653 * The dash, hyphen, bullet and enum lists all have a special
654 * HEAD character. Print it now.
657 if (MDOC_HEAD
== node
->type
)
668 (pair
->ppair
->ppair
->count
)++;
669 (void)snprintf(buf
, sizeof(buf
), "%d.",
670 pair
->ppair
->ppair
->count
);
678 * If we're not going to process our children, indicate so here.
691 if (MDOC_HEAD
== node
->type
)
695 if (MDOC_BODY
== node
->type
)
708 termp_it_post(DECL_ARGS
)
712 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
715 type
= arg_listtype(node
->parent
->parent
->parent
);
723 if (MDOC_BODY
== node
->type
)
727 if (MDOC_HEAD
== node
->type
)
735 p
->offset
= pair
->offset
;
736 p
->rmargin
= pair
->rmargin
;
737 p
->flags
= pair
->flag
;
743 termp_nm_pre(DECL_ARGS
)
746 if (SEC_SYNOPSIS
== node
->sec
)
749 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
750 if (NULL
== node
->child
)
759 termp_fl_pre(DECL_ARGS
)
762 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
764 p
->flags
|= TERMP_NOSPACE
;
771 termp_ar_pre(DECL_ARGS
)
774 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
781 termp_ns_pre(DECL_ARGS
)
784 p
->flags
|= TERMP_NOSPACE
;
791 termp_pp_pre(DECL_ARGS
)
801 termp_st_pre(DECL_ARGS
)
805 if (node
->child
&& (cp
= mdoc_a2st(node
->child
->string
)))
813 termp_rs_pre(DECL_ARGS
)
816 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
824 termp_rv_pre(DECL_ARGS
)
828 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
829 errx(1, "expected -std argument");
830 if (1 != node
->args
->argv
[i
].sz
)
831 errx(1, "expected -std argument");
836 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
837 word(p
, *node
->args
->argv
[i
].value
);
838 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
840 word(p
, "() function returns the value 0 if successful;");
841 word(p
, "otherwise the value -1 is returned and the");
842 word(p
, "global variable");
844 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
846 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
848 word(p
, "is set to indicate the error.");
856 termp_ex_pre(DECL_ARGS
)
860 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
861 errx(1, "expected -std argument");
862 if (1 != node
->args
->argv
[i
].sz
)
863 errx(1, "expected -std argument");
866 p
->flags
|= ttypes
[TTYPE_PROG
];
867 word(p
, *node
->args
->argv
[i
].value
);
868 p
->flags
&= ~ttypes
[TTYPE_PROG
];
869 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
877 termp_nd_pre(DECL_ARGS
)
887 termp_bl_post(DECL_ARGS
)
890 if (MDOC_BLOCK
== node
->type
)
897 termp_op_post(DECL_ARGS
)
900 if (MDOC_BODY
!= node
->type
)
902 p
->flags
|= TERMP_NOSPACE
;
909 termp_xr_pre(DECL_ARGS
)
911 const struct mdoc_node
*n
;
913 if (NULL
== (n
= node
->child
))
914 errx(1, "expected text line argument");
916 if (NULL
== (n
= n
->next
))
918 p
->flags
|= TERMP_NOSPACE
;
920 p
->flags
|= TERMP_NOSPACE
;
922 p
->flags
|= TERMP_NOSPACE
;
930 termp_vt_pre(DECL_ARGS
)
933 /* FIXME: this can be "type name". */
934 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
941 termp_vt_post(DECL_ARGS
)
944 if (node
->sec
== SEC_SYNOPSIS
)
951 termp_fd_pre(DECL_ARGS
)
955 * FIXME: this naming is bad. This value is used, in general,
956 * for the #include header or other preprocessor statement.
958 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
965 termp_fd_post(DECL_ARGS
)
968 if (node
->sec
!= SEC_SYNOPSIS
)
971 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
978 termp_sh_pre(DECL_ARGS
)
981 switch (node
->type
) {
984 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
998 termp_sh_post(DECL_ARGS
)
1001 switch (node
->type
) {
1017 termp_op_pre(DECL_ARGS
)
1020 switch (node
->type
) {
1023 p
->flags
|= TERMP_NOSPACE
;
1034 termp_bt_pre(DECL_ARGS
)
1037 word(p
, "is currently in beta test.");
1044 termp_lb_pre(DECL_ARGS
)
1048 if (NULL
== node
->child
)
1049 errx(1, "expected text line argument");
1050 if ((lb
= mdoc_a2lib(node
->child
->string
))) {
1061 termp_lb_post(DECL_ARGS
)
1070 termp_ud_pre(DECL_ARGS
)
1073 word(p
, "currently under development.");
1080 termp_d1_pre(DECL_ARGS
)
1083 if (MDOC_BODY
!= node
->type
)
1086 p
->offset
+= (pair
->offset
= INDENT
);
1093 termp_d1_post(DECL_ARGS
)
1096 if (MDOC_BODY
!= node
->type
)
1099 p
->offset
-= pair
->offset
;
1105 termp_aq_pre(DECL_ARGS
)
1108 if (MDOC_BODY
!= node
->type
)
1111 p
->flags
|= TERMP_NOSPACE
;
1118 termp_aq_post(DECL_ARGS
)
1121 if (MDOC_BODY
!= node
->type
)
1123 p
->flags
|= TERMP_NOSPACE
;
1130 termp_ft_pre(DECL_ARGS
)
1133 if (SEC_SYNOPSIS
== node
->sec
)
1134 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1136 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1143 termp_ft_post(DECL_ARGS
)
1146 if (SEC_SYNOPSIS
== node
->sec
)
1153 termp_fn_pre(DECL_ARGS
)
1155 const struct mdoc_node
*n
;
1157 if (NULL
== node
->child
)
1158 errx(1, "expected text line arguments");
1160 /* FIXME: can be "type funcname" "type varname"... */
1162 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1163 word(p
, node
->child
->string
);
1164 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1168 p
->flags
|= TERMP_NOSPACE
;
1169 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1170 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1172 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1179 if (SEC_SYNOPSIS
== node
->sec
)
1188 termp_fn_post(DECL_ARGS
)
1191 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1199 termp_sx_pre(DECL_ARGS
)
1202 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1209 termp_fa_pre(DECL_ARGS
)
1211 struct mdoc_node
*n
;
1213 if (node
->parent
->tok
!= MDOC_Fo
) {
1214 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1218 for (n
= node
->child
; n
; n
= n
->next
) {
1219 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1221 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1226 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1235 termp_va_pre(DECL_ARGS
)
1238 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1245 termp_bd_pre(DECL_ARGS
)
1247 const struct mdoc_node
*n
;
1250 if (MDOC_BLOCK
== node
->type
) {
1251 /* FIXME: parent prev? */
1255 } else if (MDOC_BODY
!= node
->type
)
1258 if (NULL
== node
->parent
->args
)
1259 errx(1, "missing display type");
1261 pair
->offset
= p
->offset
;
1263 for (type
= -1, i
= 0;
1264 i
< (int)node
->parent
->args
->argc
; i
++) {
1265 switch (node
->parent
->args
->argv
[i
].arg
) {
1270 case (MDOC_Unfilled
):
1272 case (MDOC_Literal
):
1273 type
= node
->parent
->args
->argv
[i
].arg
;
1274 i
= (int)node
->parent
->args
->argc
;
1281 if (NULL
== node
->parent
->args
)
1282 errx(1, "missing display type");
1284 i
= arg_getattr(MDOC_Offset
, node
->parent
);
1286 if (1 != node
->parent
->args
->argv
[i
].sz
)
1287 errx(1, "expected single value");
1288 p
->offset
+= arg_offset(&node
->parent
->args
->argv
[i
]);
1292 case (MDOC_Literal
):
1294 case (MDOC_Unfilled
):
1300 p
->flags
|= TERMP_LITERAL
;
1302 for (n
= node
->child
; n
; n
= n
->next
) {
1303 if (MDOC_TEXT
!= n
->type
) {
1304 warnx("non-text children not yet allowed");
1317 termp_bd_post(DECL_ARGS
)
1320 if (MDOC_BODY
!= node
->type
)
1323 if ( ! (p
->flags
& TERMP_LITERAL
))
1326 p
->flags
&= ~TERMP_LITERAL
;
1327 p
->offset
= pair
->offset
;
1333 termp_qq_pre(DECL_ARGS
)
1336 if (MDOC_BODY
!= node
->type
)
1339 p
->flags
|= TERMP_NOSPACE
;
1346 termp_qq_post(DECL_ARGS
)
1349 if (MDOC_BODY
!= node
->type
)
1351 p
->flags
|= TERMP_NOSPACE
;
1358 termp_bsx_pre(DECL_ARGS
)
1361 word(p
, "BSDI BSD/OS");
1368 termp_bx_post(DECL_ARGS
)
1372 p
->flags
|= TERMP_NOSPACE
;
1379 termp_ox_pre(DECL_ARGS
)
1389 termp_ux_pre(DECL_ARGS
)
1399 termp_fx_pre(DECL_ARGS
)
1409 termp_nx_pre(DECL_ARGS
)
1419 termp_sq_pre(DECL_ARGS
)
1422 if (MDOC_BODY
!= node
->type
)
1425 p
->flags
|= TERMP_NOSPACE
;
1432 termp_sq_post(DECL_ARGS
)
1435 if (MDOC_BODY
!= node
->type
)
1437 p
->flags
|= TERMP_NOSPACE
;
1444 termp_pf_pre(DECL_ARGS
)
1447 p
->flags
|= TERMP_IGNDELIM
;
1454 termp_pf_post(DECL_ARGS
)
1457 p
->flags
&= ~TERMP_IGNDELIM
;
1458 p
->flags
|= TERMP_NOSPACE
;
1464 termp_ss_pre(DECL_ARGS
)
1467 switch (node
->type
) {
1470 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1471 p
->offset
= INDENT
/ 2;
1483 termp_ss_post(DECL_ARGS
)
1486 switch (node
->type
) {
1499 termp_pa_pre(DECL_ARGS
)
1502 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1509 termp_em_pre(DECL_ARGS
)
1512 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1519 termp_cd_pre(DECL_ARGS
)
1522 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1530 termp_cm_pre(DECL_ARGS
)
1533 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1540 termp_ic_pre(DECL_ARGS
)
1543 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1550 termp_in_pre(DECL_ARGS
)
1553 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1554 word(p
, "#include");
1556 p
->flags
|= TERMP_NOSPACE
;
1563 termp_in_post(DECL_ARGS
)
1566 p
->flags
|= TERMP_NOSPACE
;
1570 if (SEC_SYNOPSIS
!= node
->sec
)
1572 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1579 termp_at_pre(DECL_ARGS
)
1586 att
= mdoc_a2att(node
->child
->string
);
1597 termp_brq_pre(DECL_ARGS
)
1600 if (MDOC_BODY
!= node
->type
)
1603 p
->flags
|= TERMP_NOSPACE
;
1610 termp_brq_post(DECL_ARGS
)
1613 if (MDOC_BODY
!= node
->type
)
1615 p
->flags
|= TERMP_NOSPACE
;
1622 termp_bq_pre(DECL_ARGS
)
1625 if (MDOC_BODY
!= node
->type
)
1628 p
->flags
|= TERMP_NOSPACE
;
1635 termp_bq_post(DECL_ARGS
)
1638 if (MDOC_BODY
!= node
->type
)
1640 p
->flags
|= TERMP_NOSPACE
;
1647 termp_pq_pre(DECL_ARGS
)
1650 if (MDOC_BODY
!= node
->type
)
1653 p
->flags
|= TERMP_NOSPACE
;
1660 termp_pq_post(DECL_ARGS
)
1663 if (MDOC_BODY
!= node
->type
)
1671 termp_fo_pre(DECL_ARGS
)
1673 const struct mdoc_node
*n
;
1675 if (MDOC_BODY
== node
->type
) {
1677 p
->flags
|= TERMP_NOSPACE
;
1679 } else if (MDOC_HEAD
!= node
->type
)
1682 /* XXX - groff shows only first parameter */
1684 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1685 for (n
= node
->child
; n
; n
= n
->next
) {
1686 if (MDOC_TEXT
!= n
->type
)
1687 errx(1, "expected text line argument");
1690 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1698 termp_fo_post(DECL_ARGS
)
1701 if (MDOC_BODY
!= node
->type
)
1703 p
->flags
|= TERMP_NOSPACE
;
1705 p
->flags
|= TERMP_NOSPACE
;
1713 termp_bf_pre(DECL_ARGS
)
1715 const struct mdoc_node
*n
;
1717 if (MDOC_HEAD
== node
->type
) {
1719 } else if (MDOC_BLOCK
!= node
->type
)
1722 if (NULL
== (n
= node
->head
->child
)) {
1723 if (arg_hasattr(MDOC_Emphasis
, node
))
1724 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1725 else if (arg_hasattr(MDOC_Symbolic
, node
))
1726 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1731 if (MDOC_TEXT
!= n
->type
)
1732 errx(1, "expected text line arguments");
1734 if (0 == strcmp("Em", n
->string
))
1735 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1736 else if (0 == strcmp("Sy", n
->string
))
1737 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1745 termp_sy_pre(DECL_ARGS
)
1748 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1755 termp_ms_pre(DECL_ARGS
)
1758 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1766 termp_sm_pre(DECL_ARGS
)
1770 assert(node
->child
);
1771 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1772 p
->flags
&= ~TERMP_NONOSPACE
;
1773 p
->flags
&= ~TERMP_NOSPACE
;
1775 p
->flags
|= TERMP_NONOSPACE
;
1776 p
->flags
|= TERMP_NOSPACE
;
1786 termp_ap_pre(DECL_ARGS
)
1789 p
->flags
|= TERMP_NOSPACE
;
1791 p
->flags
|= TERMP_NOSPACE
;
1798 termp__t_pre(DECL_ARGS
)
1801 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_REF_TITLE
]);
1808 termp____post(DECL_ARGS
)
1811 p
->flags
|= TERMP_NOSPACE
;
1812 word(p
, node
->next
? "," : ".");
1818 termp_lk_pre(DECL_ARGS
)
1820 const struct mdoc_node
*n
;
1822 if (NULL
== (n
= node
->child
))
1823 errx(1, "expected line argument");
1825 p
->flags
|= ttypes
[TTYPE_LINK_ANCHOR
];
1827 p
->flags
&= ~ttypes
[TTYPE_LINK_ANCHOR
];
1828 p
->flags
|= TERMP_NOSPACE
;
1831 p
->flags
|= ttypes
[TTYPE_LINK_TEXT
];
1832 for ( ; n
; n
= n
->next
) {
1835 p
->flags
&= ~ttypes
[TTYPE_LINK_TEXT
];
1843 termp_mt_pre(DECL_ARGS
)
1846 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK_ANCHOR
]);