]>
git.cameronkatri.com Git - mandoc.git/blob - term.c
1 /* $Id: term.c,v 1.58 2009/03/13 07:46:10 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 */
298 { NULL
, NULL
}, /* %C */
301 const struct termact
*termacts
= __termacts
;
305 arg_width(const struct mdoc_argv
*arg
, int pos
)
310 assert(pos
< (int)arg
->sz
&& pos
>= 0);
311 assert(arg
->value
[pos
]);
312 if (0 == strcmp(arg
->value
[pos
], "indent"))
314 if (0 == strcmp(arg
->value
[pos
], "indent-two"))
317 len
= (int)strlen(arg
->value
[pos
]);
320 for (i
= 0; i
< len
- 1; i
++)
321 if ( ! isdigit((u_char
)arg
->value
[pos
][i
]))
325 if ('n' == arg
->value
[pos
][len
- 1]) {
326 v
= (size_t)atoi(arg
->value
[pos
]);
331 return(strlen(arg
->value
[pos
]) + 1);
336 arg_listtype(const struct mdoc_node
*n
)
340 assert(MDOC_BLOCK
== n
->type
);
342 len
= (int)(n
->args
? n
->args
->argc
: 0);
344 for (i
= 0; i
< len
; i
++)
345 switch (n
->args
->argv
[i
].arg
) {
365 return(n
->args
->argv
[i
].arg
);
370 errx(1, "list type not supported");
376 arg_offset(const struct mdoc_argv
*arg
)
381 if (0 == strcmp(*arg
->value
, "indent"))
383 if (0 == strcmp(*arg
->value
, "indent-two"))
385 return(strlen(*arg
->value
));
390 arg_hasattr(int arg
, const struct mdoc_node
*n
)
393 return(-1 != arg_getattr(arg
, n
));
398 arg_getattr(int v
, const struct mdoc_node
*n
)
402 return(arg_getattrs(&v
, &val
, 1, n
) ? val
: -1);
407 arg_getattrs(const int *keys
, int *vals
,
408 size_t sz
, const struct mdoc_node
*n
)
415 for (k
= i
= 0; i
< (int)n
->args
->argc
; i
++)
416 for (j
= 0; j
< (int)sz
; j
++)
417 if (n
->args
->argv
[i
].arg
== keys
[j
]) {
427 termp_dq_pre(DECL_ARGS
)
430 if (MDOC_BODY
!= node
->type
)
434 p
->flags
|= TERMP_NOSPACE
;
441 termp_dq_post(DECL_ARGS
)
444 if (MDOC_BODY
!= node
->type
)
447 p
->flags
|= TERMP_NOSPACE
;
454 termp_it_pre_block(DECL_ARGS
)
458 if ( ! arg_hasattr(MDOC_Compact
, node
->parent
->parent
))
459 /* FIXME: parent->parent->parent? */
460 if (node
->prev
|| node
->parent
->parent
->prev
)
469 termp_it_pre(DECL_ARGS
)
471 const struct mdoc_node
*bl
, *n
;
473 int i
, type
, keys
[3], vals
[3];
474 size_t width
, offset
;
476 if (MDOC_BLOCK
== node
->type
)
477 return(termp_it_pre_block(p
, pair
, meta
, node
));
479 bl
= node
->parent
->parent
->parent
;
481 /* Save parent attributes. */
483 pair
->offset
= p
->offset
;
484 pair
->rmargin
= p
->rmargin
;
485 pair
->flag
= p
->flags
;
487 /* Get list width and offset. */
489 keys
[0] = MDOC_Width
;
490 keys
[1] = MDOC_Offset
;
491 keys
[2] = MDOC_Column
;
493 vals
[0] = vals
[1] = vals
[2] = -1;
497 (void)arg_getattrs(keys
, vals
, 3, bl
);
499 type
= arg_listtype(bl
);
501 /* Calculate real width and offset. */
505 if (MDOC_BODY
== node
->type
)
507 for (i
= 0, n
= node
->prev
; n
; n
= n
->prev
, i
++)
509 (&bl
->args
->argv
[vals
[2]], i
);
510 assert(i
< (int)bl
->args
->argv
[vals
[2]].sz
);
511 width
= arg_width(&bl
->args
->argv
[vals
[2]], i
);
513 offset
+= arg_offset(&bl
->args
->argv
[vals
[1]]);
517 width
= arg_width(&bl
->args
->argv
[vals
[0]], 0);
519 offset
= arg_offset(&bl
->args
->argv
[vals
[1]]);
524 * List-type can override the width in the case of fixed-head
525 * values (bullet, dash/hyphen, enum). Tags need a non-zero
549 * Whitespace control. Inset bodies need an initial space.
556 if (MDOC_BODY
== node
->type
)
557 p
->flags
&= ~TERMP_NOSPACE
;
559 p
->flags
|= TERMP_NOSPACE
;
562 p
->flags
|= TERMP_NOSPACE
;
567 * Style flags. Diagnostic heads need TTYPE_DIAG.
572 if (MDOC_HEAD
== node
->type
)
573 p
->flags
|= ttypes
[TTYPE_DIAG
];
580 * Pad and break control. This is the tricker part. Lists with
581 * set right-margins for the head get TERMP_NOBREAK because, if
582 * they overrun the margin, they wrap to the new margin.
583 * Correspondingly, the body for these types don't left-pad, as
584 * the head will pad out to to the right.
597 if (MDOC_HEAD
== node
->type
)
598 p
->flags
|= TERMP_NOBREAK
;
600 p
->flags
|= TERMP_NOLPAD
;
601 if (MDOC_HEAD
== node
->type
&& MDOC_Tag
== type
)
602 if (NULL
== node
->next
||
603 NULL
== node
->next
->child
)
604 p
->flags
|= TERMP_NONOBREAK
;
607 if (MDOC_HEAD
== node
->type
) {
609 if (MDOC_BODY
== node
->next
->type
)
610 p
->flags
&= ~TERMP_NOBREAK
;
612 p
->flags
|= TERMP_NOBREAK
;
614 p
->flags
|= TERMP_NOLPAD
;
618 if (MDOC_HEAD
== node
->type
)
619 p
->flags
|= TERMP_NOBREAK
;
626 * Margin control. Set-head-width lists have their right
627 * margins shortened. The body for these lists has the offset
628 * necessarily lengthened. Everybody gets the offset.
643 if (MDOC_HEAD
== node
->type
)
644 p
->rmargin
= p
->offset
+ width
;
649 p
->rmargin
= p
->offset
+ width
;
656 * The dash, hyphen, bullet and enum lists all have a special
657 * HEAD character. Print it now.
660 if (MDOC_HEAD
== node
->type
)
671 (pair
->ppair
->ppair
->count
)++;
672 (void)snprintf(buf
, sizeof(buf
), "%d.",
673 pair
->ppair
->ppair
->count
);
681 * If we're not going to process our children, indicate so here.
694 if (MDOC_HEAD
== node
->type
)
698 if (MDOC_BODY
== node
->type
)
711 termp_it_post(DECL_ARGS
)
715 if (MDOC_BODY
!= node
->type
&& MDOC_HEAD
!= node
->type
)
718 type
= arg_listtype(node
->parent
->parent
->parent
);
726 if (MDOC_BODY
== node
->type
)
730 if (MDOC_HEAD
== node
->type
)
738 p
->offset
= pair
->offset
;
739 p
->rmargin
= pair
->rmargin
;
740 p
->flags
= pair
->flag
;
746 termp_nm_pre(DECL_ARGS
)
749 if (SEC_SYNOPSIS
== node
->sec
)
752 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_PROG
]);
753 if (NULL
== node
->child
)
762 termp_fl_pre(DECL_ARGS
)
765 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
767 p
->flags
|= TERMP_NOSPACE
;
774 termp_ar_pre(DECL_ARGS
)
777 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_ARG
]);
784 termp_ns_pre(DECL_ARGS
)
787 p
->flags
|= TERMP_NOSPACE
;
794 termp_pp_pre(DECL_ARGS
)
804 termp_st_pre(DECL_ARGS
)
808 if (node
->child
&& (cp
= mdoc_a2st(node
->child
->string
)))
816 termp_rs_pre(DECL_ARGS
)
819 if (MDOC_BLOCK
== node
->type
&& node
->prev
)
827 termp_rv_pre(DECL_ARGS
)
831 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
832 errx(1, "expected -std argument");
833 if (1 != node
->args
->argv
[i
].sz
)
834 errx(1, "expected -std argument");
839 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
840 word(p
, *node
->args
->argv
[i
].value
);
841 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
842 p
->flags
|= TERMP_NOSPACE
;
844 word(p
, "() function returns the value 0 if successful;");
845 word(p
, "otherwise the value -1 is returned and the");
846 word(p
, "global variable");
848 p
->flags
|= ttypes
[TTYPE_VAR_DECL
];
850 p
->flags
&= ~ttypes
[TTYPE_VAR_DECL
];
852 word(p
, "is set to indicate the error.");
860 termp_ex_pre(DECL_ARGS
)
864 if (-1 == (i
= arg_getattr(MDOC_Std
, node
)))
865 errx(1, "expected -std argument");
866 if (1 != node
->args
->argv
[i
].sz
)
867 errx(1, "expected -std argument");
870 p
->flags
|= ttypes
[TTYPE_PROG
];
871 word(p
, *node
->args
->argv
[i
].value
);
872 p
->flags
&= ~ttypes
[TTYPE_PROG
];
873 word(p
, "utility exits 0 on success, and >0 if an error occurs.");
881 termp_nd_pre(DECL_ARGS
)
891 termp_bl_post(DECL_ARGS
)
894 if (MDOC_BLOCK
== node
->type
)
901 termp_op_post(DECL_ARGS
)
904 if (MDOC_BODY
!= node
->type
)
906 p
->flags
|= TERMP_NOSPACE
;
913 termp_xr_pre(DECL_ARGS
)
915 const struct mdoc_node
*n
;
917 if (NULL
== (n
= node
->child
))
918 errx(1, "expected text line argument");
920 if (NULL
== (n
= n
->next
))
922 p
->flags
|= TERMP_NOSPACE
;
924 p
->flags
|= TERMP_NOSPACE
;
926 p
->flags
|= TERMP_NOSPACE
;
934 termp_vt_pre(DECL_ARGS
)
937 /* FIXME: this can be "type name". */
938 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
945 termp_vt_post(DECL_ARGS
)
948 if (node
->sec
== SEC_SYNOPSIS
)
955 termp_fd_pre(DECL_ARGS
)
959 * FIXME: this naming is bad. This value is used, in general,
960 * for the #include header or other preprocessor statement.
962 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_DECL
]);
969 termp_fd_post(DECL_ARGS
)
972 if (node
->sec
!= SEC_SYNOPSIS
)
975 if (node
->next
&& MDOC_Fd
!= node
->next
->tok
)
982 termp_sh_pre(DECL_ARGS
)
985 switch (node
->type
) {
988 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SECTION
]);
1002 termp_sh_post(DECL_ARGS
)
1005 switch (node
->type
) {
1021 termp_op_pre(DECL_ARGS
)
1024 switch (node
->type
) {
1027 p
->flags
|= TERMP_NOSPACE
;
1038 termp_bt_pre(DECL_ARGS
)
1041 word(p
, "is currently in beta test.");
1048 termp_lb_pre(DECL_ARGS
)
1052 if (NULL
== node
->child
)
1053 errx(1, "expected text line argument");
1054 if ((lb
= mdoc_a2lib(node
->child
->string
))) {
1065 termp_lb_post(DECL_ARGS
)
1074 termp_ud_pre(DECL_ARGS
)
1077 word(p
, "currently under development.");
1084 termp_d1_pre(DECL_ARGS
)
1087 if (MDOC_BODY
!= node
->type
)
1090 p
->offset
+= (pair
->offset
= INDENT
);
1097 termp_d1_post(DECL_ARGS
)
1100 if (MDOC_BODY
!= node
->type
)
1103 p
->offset
-= pair
->offset
;
1109 termp_aq_pre(DECL_ARGS
)
1112 if (MDOC_BODY
!= node
->type
)
1115 p
->flags
|= TERMP_NOSPACE
;
1122 termp_aq_post(DECL_ARGS
)
1125 if (MDOC_BODY
!= node
->type
)
1127 p
->flags
|= TERMP_NOSPACE
;
1134 termp_ft_pre(DECL_ARGS
)
1137 if (SEC_SYNOPSIS
== node
->sec
)
1138 if (node
->prev
&& MDOC_Fo
== node
->prev
->tok
)
1140 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_TYPE
]);
1147 termp_ft_post(DECL_ARGS
)
1150 if (SEC_SYNOPSIS
== node
->sec
)
1157 termp_fn_pre(DECL_ARGS
)
1159 const struct mdoc_node
*n
;
1161 if (NULL
== node
->child
)
1162 errx(1, "expected text line arguments");
1164 /* FIXME: can be "type funcname" "type varname"... */
1166 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1167 word(p
, node
->child
->string
);
1168 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1172 p
->flags
|= TERMP_NOSPACE
;
1173 for (n
= node
->child
->next
; n
; n
= n
->next
) {
1174 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1176 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1183 if (SEC_SYNOPSIS
== node
->sec
)
1192 termp_fn_post(DECL_ARGS
)
1195 if (node
->sec
== SEC_SYNOPSIS
&& node
->next
)
1203 termp_sx_pre(DECL_ARGS
)
1206 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK
]);
1213 termp_fa_pre(DECL_ARGS
)
1215 struct mdoc_node
*n
;
1217 if (node
->parent
->tok
!= MDOC_Fo
) {
1218 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FUNC_ARG
]);
1222 for (n
= node
->child
; n
; n
= n
->next
) {
1223 p
->flags
|= ttypes
[TTYPE_FUNC_ARG
];
1225 p
->flags
&= ~ttypes
[TTYPE_FUNC_ARG
];
1230 if (node
->next
&& node
->next
->tok
== MDOC_Fa
)
1239 termp_va_pre(DECL_ARGS
)
1242 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_VAR_DECL
]);
1249 termp_bd_pre(DECL_ARGS
)
1251 const struct mdoc_node
*n
;
1254 if (MDOC_BLOCK
== node
->type
) {
1255 /* FIXME: parent prev? */
1259 } else if (MDOC_BODY
!= node
->type
)
1262 if (NULL
== node
->parent
->args
)
1263 errx(1, "missing display type");
1265 pair
->offset
= p
->offset
;
1267 for (type
= -1, i
= 0;
1268 i
< (int)node
->parent
->args
->argc
; i
++) {
1269 switch (node
->parent
->args
->argv
[i
].arg
) {
1274 case (MDOC_Unfilled
):
1276 case (MDOC_Literal
):
1277 type
= node
->parent
->args
->argv
[i
].arg
;
1278 i
= (int)node
->parent
->args
->argc
;
1285 if (NULL
== node
->parent
->args
)
1286 errx(1, "missing display type");
1288 i
= arg_getattr(MDOC_Offset
, node
->parent
);
1290 if (1 != node
->parent
->args
->argv
[i
].sz
)
1291 errx(1, "expected single value");
1292 p
->offset
+= arg_offset(&node
->parent
->args
->argv
[i
]);
1296 case (MDOC_Literal
):
1298 case (MDOC_Unfilled
):
1304 p
->flags
|= TERMP_LITERAL
;
1306 for (n
= node
->child
; n
; n
= n
->next
) {
1307 if (MDOC_TEXT
!= n
->type
) {
1308 warnx("non-text children not yet allowed");
1321 termp_bd_post(DECL_ARGS
)
1324 if (MDOC_BODY
!= node
->type
)
1327 if ( ! (p
->flags
& TERMP_LITERAL
))
1330 p
->flags
&= ~TERMP_LITERAL
;
1331 p
->offset
= pair
->offset
;
1337 termp_qq_pre(DECL_ARGS
)
1340 if (MDOC_BODY
!= node
->type
)
1343 p
->flags
|= TERMP_NOSPACE
;
1350 termp_qq_post(DECL_ARGS
)
1353 if (MDOC_BODY
!= node
->type
)
1355 p
->flags
|= TERMP_NOSPACE
;
1362 termp_bsx_pre(DECL_ARGS
)
1365 word(p
, "BSDI BSD/OS");
1372 termp_bx_post(DECL_ARGS
)
1376 p
->flags
|= TERMP_NOSPACE
;
1383 termp_ox_pre(DECL_ARGS
)
1393 termp_ux_pre(DECL_ARGS
)
1403 termp_fx_pre(DECL_ARGS
)
1413 termp_nx_pre(DECL_ARGS
)
1423 termp_sq_pre(DECL_ARGS
)
1426 if (MDOC_BODY
!= node
->type
)
1429 p
->flags
|= TERMP_NOSPACE
;
1436 termp_sq_post(DECL_ARGS
)
1439 if (MDOC_BODY
!= node
->type
)
1441 p
->flags
|= TERMP_NOSPACE
;
1448 termp_pf_pre(DECL_ARGS
)
1451 p
->flags
|= TERMP_IGNDELIM
;
1458 termp_pf_post(DECL_ARGS
)
1461 p
->flags
&= ~TERMP_IGNDELIM
;
1462 p
->flags
|= TERMP_NOSPACE
;
1468 termp_ss_pre(DECL_ARGS
)
1471 switch (node
->type
) {
1478 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SSECTION
]);
1479 p
->offset
= INDENT
/ 2;
1491 termp_ss_post(DECL_ARGS
)
1494 switch (node
->type
) {
1507 termp_pa_pre(DECL_ARGS
)
1510 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_FILE
]);
1517 termp_em_pre(DECL_ARGS
)
1520 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1527 termp_cd_pre(DECL_ARGS
)
1530 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CONFIG
]);
1538 termp_cm_pre(DECL_ARGS
)
1541 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD_FLAG
]);
1548 termp_ic_pre(DECL_ARGS
)
1551 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_CMD
]);
1558 termp_in_pre(DECL_ARGS
)
1561 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_INCLUDE
]);
1562 word(p
, "#include");
1564 p
->flags
|= TERMP_NOSPACE
;
1571 termp_in_post(DECL_ARGS
)
1574 p
->flags
|= TERMP_NOSPACE
;
1578 if (SEC_SYNOPSIS
!= node
->sec
)
1580 if (node
->next
&& MDOC_In
!= node
->next
->tok
)
1587 termp_at_pre(DECL_ARGS
)
1594 att
= mdoc_a2att(node
->child
->string
);
1605 termp_brq_pre(DECL_ARGS
)
1608 if (MDOC_BODY
!= node
->type
)
1611 p
->flags
|= TERMP_NOSPACE
;
1618 termp_brq_post(DECL_ARGS
)
1621 if (MDOC_BODY
!= node
->type
)
1623 p
->flags
|= TERMP_NOSPACE
;
1630 termp_bq_pre(DECL_ARGS
)
1633 if (MDOC_BODY
!= node
->type
)
1636 p
->flags
|= TERMP_NOSPACE
;
1643 termp_bq_post(DECL_ARGS
)
1646 if (MDOC_BODY
!= node
->type
)
1648 p
->flags
|= TERMP_NOSPACE
;
1655 termp_pq_pre(DECL_ARGS
)
1658 if (MDOC_BODY
!= node
->type
)
1661 p
->flags
|= TERMP_NOSPACE
;
1668 termp_pq_post(DECL_ARGS
)
1671 if (MDOC_BODY
!= node
->type
)
1679 termp_fo_pre(DECL_ARGS
)
1681 const struct mdoc_node
*n
;
1683 if (MDOC_BODY
== node
->type
) {
1685 p
->flags
|= TERMP_NOSPACE
;
1687 } else if (MDOC_HEAD
!= node
->type
)
1690 /* XXX - groff shows only first parameter */
1692 p
->flags
|= ttypes
[TTYPE_FUNC_NAME
];
1693 for (n
= node
->child
; n
; n
= n
->next
) {
1694 if (MDOC_TEXT
!= n
->type
)
1695 errx(1, "expected text line argument");
1698 p
->flags
&= ~ttypes
[TTYPE_FUNC_NAME
];
1706 termp_fo_post(DECL_ARGS
)
1709 if (MDOC_BODY
!= node
->type
)
1711 p
->flags
|= TERMP_NOSPACE
;
1713 p
->flags
|= TERMP_NOSPACE
;
1721 termp_bf_pre(DECL_ARGS
)
1723 const struct mdoc_node
*n
;
1725 if (MDOC_HEAD
== node
->type
) {
1727 } else if (MDOC_BLOCK
!= node
->type
)
1730 if (NULL
== (n
= node
->head
->child
)) {
1731 if (arg_hasattr(MDOC_Emphasis
, node
))
1732 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1733 else if (arg_hasattr(MDOC_Symbolic
, node
))
1734 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1739 if (MDOC_TEXT
!= n
->type
)
1740 errx(1, "expected text line arguments");
1742 if (0 == strcmp("Em", n
->string
))
1743 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1744 else if (0 == strcmp("Sy", n
->string
))
1745 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_EMPH
]);
1753 termp_sy_pre(DECL_ARGS
)
1756 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMB
]);
1763 termp_ms_pre(DECL_ARGS
)
1766 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_SYMBOL
]);
1774 termp_sm_pre(DECL_ARGS
)
1778 assert(node
->child
);
1779 if (0 == strcmp("off", node
->child
->data
.text
.string
)) {
1780 p
->flags
&= ~TERMP_NONOSPACE
;
1781 p
->flags
&= ~TERMP_NOSPACE
;
1783 p
->flags
|= TERMP_NONOSPACE
;
1784 p
->flags
|= TERMP_NOSPACE
;
1794 termp_ap_pre(DECL_ARGS
)
1797 p
->flags
|= TERMP_NOSPACE
;
1799 p
->flags
|= TERMP_NOSPACE
;
1806 termp__t_pre(DECL_ARGS
)
1809 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_REF_TITLE
]);
1816 termp____post(DECL_ARGS
)
1819 p
->flags
|= TERMP_NOSPACE
;
1820 word(p
, node
->next
? "," : ".");
1826 termp_lk_pre(DECL_ARGS
)
1828 const struct mdoc_node
*n
;
1830 if (NULL
== (n
= node
->child
))
1831 errx(1, "expected line argument");
1833 p
->flags
|= ttypes
[TTYPE_LINK_ANCHOR
];
1835 p
->flags
&= ~ttypes
[TTYPE_LINK_ANCHOR
];
1836 p
->flags
|= TERMP_NOSPACE
;
1839 p
->flags
|= ttypes
[TTYPE_LINK_TEXT
];
1840 for ( ; n
; n
= n
->next
) {
1843 p
->flags
&= ~ttypes
[TTYPE_LINK_TEXT
];
1851 termp_mt_pre(DECL_ARGS
)
1854 TERMPAIR_SETFLAG(p
, pair
, ttypes
[TTYPE_LINK_ANCHOR
]);