xref: /illumos-gate/usr/src/cmd/mandoc/mdoc_man.c (revision 4d131170e62381276a07ffc0aeb1b62e527d940c)
1*4d131170SRobert Mustacchi /*	$Id: mdoc_man.c,v 1.137 2021/07/04 15:38:26 schwarze Exp $ */
295c635efSGarrett D'Amore /*
3*4d131170SRobert Mustacchi  * Copyright (c) 2011-2021 Ingo Schwarze <schwarze@openbsd.org>
495c635efSGarrett D'Amore  *
595c635efSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
695c635efSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
795c635efSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
895c635efSGarrett D'Amore  *
995c635efSGarrett D'Amore  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1095c635efSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1195c635efSGarrett D'Amore  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1295c635efSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1395c635efSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1495c635efSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1595c635efSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1695c635efSGarrett D'Amore  */
1795c635efSGarrett D'Amore #include "config.h"
18260e9a87SYuri Pankov 
19260e9a87SYuri Pankov #include <sys/types.h>
2095c635efSGarrett D'Amore 
21698f87a4SGarrett D'Amore #include <assert.h>
2295c635efSGarrett D'Amore #include <stdio.h>
23c66b8046SYuri Pankov #include <stdlib.h>
2495c635efSGarrett D'Amore #include <string.h>
2595c635efSGarrett D'Amore 
26260e9a87SYuri Pankov #include "mandoc_aux.h"
27371584c2SYuri Pankov #include "mandoc.h"
28371584c2SYuri Pankov #include "roff.h"
2995c635efSGarrett D'Amore #include "mdoc.h"
30371584c2SYuri Pankov #include "man.h"
31371584c2SYuri Pankov #include "out.h"
3295c635efSGarrett D'Amore #include "main.h"
3395c635efSGarrett D'Amore 
34371584c2SYuri Pankov #define	DECL_ARGS const struct roff_meta *meta, struct roff_node *n
3595c635efSGarrett D'Amore 
36c66b8046SYuri Pankov typedef	int	(*int_fp)(DECL_ARGS);
37c66b8046SYuri Pankov typedef	void	(*void_fp)(DECL_ARGS);
38c66b8046SYuri Pankov 
39cec8643bSMichal Nowak struct	mdoc_man_act {
40c66b8046SYuri Pankov 	int_fp		  cond; /* DON'T run actions */
41c66b8046SYuri Pankov 	int_fp		  pre; /* pre-node action */
42c66b8046SYuri Pankov 	void_fp		  post; /* post-node action */
4395c635efSGarrett D'Amore 	const char	 *prefix; /* pre-node string constant */
4495c635efSGarrett D'Amore 	const char	 *suffix; /* post-node string constant */
4595c635efSGarrett D'Amore };
4695c635efSGarrett D'Amore 
4795c635efSGarrett D'Amore static	int	  cond_body(DECL_ARGS);
4895c635efSGarrett D'Amore static	int	  cond_head(DECL_ARGS);
49698f87a4SGarrett D'Amore static  void	  font_push(char);
50698f87a4SGarrett D'Amore static	void	  font_pop(void);
51c66b8046SYuri Pankov static	int	  man_strlen(const char *);
52698f87a4SGarrett D'Amore static	void	  mid_it(void);
53698f87a4SGarrett D'Amore static	void	  post__t(DECL_ARGS);
54260e9a87SYuri Pankov static	void	  post_aq(DECL_ARGS);
5595c635efSGarrett D'Amore static	void	  post_bd(DECL_ARGS);
56698f87a4SGarrett D'Amore static	void	  post_bf(DECL_ARGS);
57698f87a4SGarrett D'Amore static	void	  post_bk(DECL_ARGS);
58698f87a4SGarrett D'Amore static	void	  post_bl(DECL_ARGS);
5995c635efSGarrett D'Amore static	void	  post_dl(DECL_ARGS);
60260e9a87SYuri Pankov static	void	  post_en(DECL_ARGS);
6195c635efSGarrett D'Amore static	void	  post_enc(DECL_ARGS);
62698f87a4SGarrett D'Amore static	void	  post_eo(DECL_ARGS);
63698f87a4SGarrett D'Amore static	void	  post_fa(DECL_ARGS);
64698f87a4SGarrett D'Amore static	void	  post_fd(DECL_ARGS);
65698f87a4SGarrett D'Amore static	void	  post_fl(DECL_ARGS);
66698f87a4SGarrett D'Amore static	void	  post_fn(DECL_ARGS);
67698f87a4SGarrett D'Amore static	void	  post_fo(DECL_ARGS);
68698f87a4SGarrett D'Amore static	void	  post_font(DECL_ARGS);
69698f87a4SGarrett D'Amore static	void	  post_in(DECL_ARGS);
70698f87a4SGarrett D'Amore static	void	  post_it(DECL_ARGS);
71698f87a4SGarrett D'Amore static	void	  post_lb(DECL_ARGS);
7295c635efSGarrett D'Amore static	void	  post_nm(DECL_ARGS);
7395c635efSGarrett D'Amore static	void	  post_percent(DECL_ARGS);
7495c635efSGarrett D'Amore static	void	  post_pf(DECL_ARGS);
7595c635efSGarrett D'Amore static	void	  post_sect(DECL_ARGS);
76698f87a4SGarrett D'Amore static	void	  post_vt(DECL_ARGS);
77698f87a4SGarrett D'Amore static	int	  pre__t(DECL_ARGS);
78cec8643bSMichal Nowak static	int	  pre_abort(DECL_ARGS);
79698f87a4SGarrett D'Amore static	int	  pre_an(DECL_ARGS);
8095c635efSGarrett D'Amore static	int	  pre_ap(DECL_ARGS);
81260e9a87SYuri Pankov static	int	  pre_aq(DECL_ARGS);
8295c635efSGarrett D'Amore static	int	  pre_bd(DECL_ARGS);
83698f87a4SGarrett D'Amore static	int	  pre_bf(DECL_ARGS);
84698f87a4SGarrett D'Amore static	int	  pre_bk(DECL_ARGS);
85698f87a4SGarrett D'Amore static	int	  pre_bl(DECL_ARGS);
86c66b8046SYuri Pankov static	void	  pre_br(DECL_ARGS);
8795c635efSGarrett D'Amore static	int	  pre_dl(DECL_ARGS);
88260e9a87SYuri Pankov static	int	  pre_en(DECL_ARGS);
8995c635efSGarrett D'Amore static	int	  pre_enc(DECL_ARGS);
90698f87a4SGarrett D'Amore static	int	  pre_em(DECL_ARGS);
91260e9a87SYuri Pankov static	int	  pre_skip(DECL_ARGS);
92260e9a87SYuri Pankov static	int	  pre_eo(DECL_ARGS);
93260e9a87SYuri Pankov static	int	  pre_ex(DECL_ARGS);
94698f87a4SGarrett D'Amore static	int	  pre_fa(DECL_ARGS);
95698f87a4SGarrett D'Amore static	int	  pre_fd(DECL_ARGS);
96698f87a4SGarrett D'Amore static	int	  pre_fl(DECL_ARGS);
97698f87a4SGarrett D'Amore static	int	  pre_fn(DECL_ARGS);
98698f87a4SGarrett D'Amore static	int	  pre_fo(DECL_ARGS);
99c66b8046SYuri Pankov static	void	  pre_ft(DECL_ARGS);
100c66b8046SYuri Pankov static	int	  pre_Ft(DECL_ARGS);
101698f87a4SGarrett D'Amore static	int	  pre_in(DECL_ARGS);
10295c635efSGarrett D'Amore static	int	  pre_it(DECL_ARGS);
103698f87a4SGarrett D'Amore static	int	  pre_lk(DECL_ARGS);
104698f87a4SGarrett D'Amore static	int	  pre_li(DECL_ARGS);
10595c635efSGarrett D'Amore static	int	  pre_nm(DECL_ARGS);
106698f87a4SGarrett D'Amore static	int	  pre_no(DECL_ARGS);
107cec8643bSMichal Nowak static	void	  pre_noarg(DECL_ARGS);
10895c635efSGarrett D'Amore static	int	  pre_ns(DECL_ARGS);
109c66b8046SYuri Pankov static	void	  pre_onearg(DECL_ARGS);
11095c635efSGarrett D'Amore static	int	  pre_pp(DECL_ARGS);
111698f87a4SGarrett D'Amore static	int	  pre_rs(DECL_ARGS);
112698f87a4SGarrett D'Amore static	int	  pre_sm(DECL_ARGS);
113c66b8046SYuri Pankov static	void	  pre_sp(DECL_ARGS);
11495c635efSGarrett D'Amore static	int	  pre_sect(DECL_ARGS);
115698f87a4SGarrett D'Amore static	int	  pre_sy(DECL_ARGS);
116*4d131170SRobert Mustacchi static	void	  pre_syn(struct roff_node *);
117c66b8046SYuri Pankov static	void	  pre_ta(DECL_ARGS);
118698f87a4SGarrett D'Amore static	int	  pre_vt(DECL_ARGS);
11995c635efSGarrett D'Amore static	int	  pre_xr(DECL_ARGS);
120698f87a4SGarrett D'Amore static	void	  print_word(const char *);
121698f87a4SGarrett D'Amore static	void	  print_line(const char *, int);
122698f87a4SGarrett D'Amore static	void	  print_block(const char *, int);
123260e9a87SYuri Pankov static	void	  print_offs(const char *, int);
124260e9a87SYuri Pankov static	void	  print_width(const struct mdoc_bl *,
125371584c2SYuri Pankov 			const struct roff_node *);
126698f87a4SGarrett D'Amore static	void	  print_count(int *);
12795c635efSGarrett D'Amore static	void	  print_node(DECL_ARGS);
12895c635efSGarrett D'Amore 
129cec8643bSMichal Nowak static const void_fp roff_man_acts[ROFF_MAX] = {
130c66b8046SYuri Pankov 	pre_br,		/* br */
131c66b8046SYuri Pankov 	pre_onearg,	/* ce */
132cec8643bSMichal Nowak 	pre_noarg,	/* fi */
133c66b8046SYuri Pankov 	pre_ft,		/* ft */
134c66b8046SYuri Pankov 	pre_onearg,	/* ll */
135c66b8046SYuri Pankov 	pre_onearg,	/* mc */
136cec8643bSMichal Nowak 	pre_noarg,	/* nf */
137c66b8046SYuri Pankov 	pre_onearg,	/* po */
138c66b8046SYuri Pankov 	pre_onearg,	/* rj */
139c66b8046SYuri Pankov 	pre_sp,		/* sp */
140c66b8046SYuri Pankov 	pre_ta,		/* ta */
141c66b8046SYuri Pankov 	pre_onearg,	/* ti */
142c66b8046SYuri Pankov };
143c66b8046SYuri Pankov 
144cec8643bSMichal Nowak static const struct mdoc_man_act mdoc_man_acts[MDOC_MAX - MDOC_Dd] = {
14595c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Dd */
14695c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Dt */
14795c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Os */
14895c635efSGarrett D'Amore 	{ NULL, pre_sect, post_sect, ".SH", NULL }, /* Sh */
14995c635efSGarrett D'Amore 	{ NULL, pre_sect, post_sect, ".SS", NULL }, /* Ss */
15095c635efSGarrett D'Amore 	{ NULL, pre_pp, NULL, NULL, NULL }, /* Pp */
15195c635efSGarrett D'Amore 	{ cond_body, pre_dl, post_dl, NULL, NULL }, /* D1 */
15295c635efSGarrett D'Amore 	{ cond_body, pre_dl, post_dl, NULL, NULL }, /* Dl */
15395c635efSGarrett D'Amore 	{ cond_body, pre_bd, post_bd, NULL, NULL }, /* Bd */
15495c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Ed */
155698f87a4SGarrett D'Amore 	{ cond_body, pre_bl, post_bl, NULL, NULL }, /* Bl */
15695c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* El */
157698f87a4SGarrett D'Amore 	{ NULL, pre_it, post_it, NULL, NULL }, /* It */
158698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_font, NULL, NULL }, /* Ad */
159698f87a4SGarrett D'Amore 	{ NULL, pre_an, NULL, NULL, NULL }, /* An */
160c66b8046SYuri Pankov 	{ NULL, pre_ap, NULL, NULL, NULL }, /* Ap */
161698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_font, NULL, NULL }, /* Ar */
162698f87a4SGarrett D'Amore 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Cd */
163698f87a4SGarrett D'Amore 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Cm */
164698f87a4SGarrett D'Amore 	{ NULL, pre_li, post_font, NULL, NULL }, /* Dv */
165698f87a4SGarrett D'Amore 	{ NULL, pre_li, post_font, NULL, NULL }, /* Er */
166698f87a4SGarrett D'Amore 	{ NULL, pre_li, post_font, NULL, NULL }, /* Ev */
167260e9a87SYuri Pankov 	{ NULL, pre_ex, NULL, NULL, NULL }, /* Ex */
168698f87a4SGarrett D'Amore 	{ NULL, pre_fa, post_fa, NULL, NULL }, /* Fa */
169698f87a4SGarrett D'Amore 	{ NULL, pre_fd, post_fd, NULL, NULL }, /* Fd */
170698f87a4SGarrett D'Amore 	{ NULL, pre_fl, post_fl, NULL, NULL }, /* Fl */
171698f87a4SGarrett D'Amore 	{ NULL, pre_fn, post_fn, NULL, NULL }, /* Fn */
172c66b8046SYuri Pankov 	{ NULL, pre_Ft, post_font, NULL, NULL }, /* Ft */
173698f87a4SGarrett D'Amore 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Ic */
174698f87a4SGarrett D'Amore 	{ NULL, pre_in, post_in, NULL, NULL }, /* In */
175698f87a4SGarrett D'Amore 	{ NULL, pre_li, post_font, NULL, NULL }, /* Li */
17695c635efSGarrett D'Amore 	{ cond_head, pre_enc, NULL, "\\- ", NULL }, /* Nd */
17795c635efSGarrett D'Amore 	{ NULL, pre_nm, post_nm, NULL, NULL }, /* Nm */
17895c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Op */
179cec8643bSMichal Nowak 	{ NULL, pre_abort, NULL, NULL, NULL }, /* Ot */
180698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_font, NULL, NULL }, /* Pa */
181a40ea1a7SYuri Pankov 	{ NULL, pre_ex, NULL, NULL, NULL }, /* Rv */
18295c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* St */
183698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_font, NULL, NULL }, /* Va */
184698f87a4SGarrett D'Amore 	{ NULL, pre_vt, post_vt, NULL, NULL }, /* Vt */
18595c635efSGarrett D'Amore 	{ NULL, pre_xr, NULL, NULL, NULL }, /* Xr */
186698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %A */
187698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_percent, NULL, NULL }, /* %B */
188698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %D */
189698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_percent, NULL, NULL }, /* %I */
190698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_percent, NULL, NULL }, /* %J */
191698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %N */
192698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %O */
193698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %P */
194698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %R */
195698f87a4SGarrett D'Amore 	{ NULL, pre__t, post__t, NULL, NULL }, /* %T */
196698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %V */
19795c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Ac */
198260e9a87SYuri Pankov 	{ cond_body, pre_aq, post_aq, NULL, NULL }, /* Ao */
199260e9a87SYuri Pankov 	{ cond_body, pre_aq, post_aq, NULL, NULL }, /* Aq */
20095c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* At */
20195c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Bc */
202698f87a4SGarrett D'Amore 	{ NULL, pre_bf, post_bf, NULL, NULL }, /* Bf */
20395c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bo */
20495c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Bq */
205c66b8046SYuri Pankov 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Bsx */
206c66b8046SYuri Pankov 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Bx */
207260e9a87SYuri Pankov 	{ NULL, pre_skip, NULL, NULL, NULL }, /* Db */
20895c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Dc */
2096640c13bSYuri Pankov 	{ cond_body, pre_enc, post_enc, "\\(lq", "\\(rq" }, /* Do */
2106640c13bSYuri Pankov 	{ cond_body, pre_enc, post_enc, "\\(lq", "\\(rq" }, /* Dq */
211698f87a4SGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Ec */
212698f87a4SGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Ef */
213698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_font, NULL, NULL }, /* Em */
214260e9a87SYuri Pankov 	{ cond_body, pre_eo, post_eo, NULL, NULL }, /* Eo */
215c66b8046SYuri Pankov 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Fx */
216698f87a4SGarrett D'Amore 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Ms */
217698f87a4SGarrett D'Amore 	{ NULL, pre_no, NULL, NULL, NULL }, /* No */
21895c635efSGarrett D'Amore 	{ NULL, pre_ns, NULL, NULL, NULL }, /* Ns */
219c66b8046SYuri Pankov 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Nx */
220c66b8046SYuri Pankov 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Ox */
22195c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Pc */
22295c635efSGarrett D'Amore 	{ NULL, NULL, post_pf, NULL, NULL }, /* Pf */
22395c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "(", ")" }, /* Po */
22495c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "(", ")" }, /* Pq */
22595c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Qc */
226698f87a4SGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* Ql */
22795c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qo */
22895c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qq */
22995c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Re */
230698f87a4SGarrett D'Amore 	{ cond_body, pre_rs, NULL, NULL, NULL }, /* Rs */
23195c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Sc */
232698f87a4SGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* So */
233698f87a4SGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* Sq */
234698f87a4SGarrett D'Amore 	{ NULL, pre_sm, NULL, NULL, NULL }, /* Sm */
235698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_font, NULL, NULL }, /* Sx */
236698f87a4SGarrett D'Amore 	{ NULL, pre_sy, post_font, NULL, NULL }, /* Sy */
237698f87a4SGarrett D'Amore 	{ NULL, pre_li, post_font, NULL, NULL }, /* Tn */
238a40ea1a7SYuri Pankov 	{ NULL, NULL, NULL, NULL, NULL }, /* Ux */
239698f87a4SGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Xc */
240698f87a4SGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Xo */
241698f87a4SGarrett D'Amore 	{ NULL, pre_fo, post_fo, NULL, NULL }, /* Fo */
242698f87a4SGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Fc */
24395c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "[", "]" }, /* Oo */
24495c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Oc */
245698f87a4SGarrett D'Amore 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Bk */
246698f87a4SGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Ek */
247a40ea1a7SYuri Pankov 	{ NULL, NULL, NULL, NULL, NULL }, /* Bt */
24895c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Hf */
249260e9a87SYuri Pankov 	{ NULL, pre_em, post_font, NULL, NULL }, /* Fr */
250a40ea1a7SYuri Pankov 	{ NULL, NULL, NULL, NULL, NULL }, /* Ud */
251698f87a4SGarrett D'Amore 	{ NULL, NULL, post_lb, NULL, NULL }, /* Lb */
252cec8643bSMichal Nowak 	{ NULL, pre_abort, NULL, NULL, NULL }, /* Lp */
253698f87a4SGarrett D'Amore 	{ NULL, pre_lk, NULL, NULL, NULL }, /* Lk */
254698f87a4SGarrett D'Amore 	{ NULL, pre_em, post_font, NULL, NULL }, /* Mt */
25595c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "{", "}" }, /* Brq */
25695c635efSGarrett D'Amore 	{ cond_body, pre_enc, post_enc, "{", "}" }, /* Bro */
25795c635efSGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Brc */
258698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %C */
259260e9a87SYuri Pankov 	{ NULL, pre_skip, NULL, NULL, NULL }, /* Es */
260260e9a87SYuri Pankov 	{ cond_body, pre_en, post_en, NULL, NULL }, /* En */
261c66b8046SYuri Pankov 	{ NULL, pre_bk, post_bk, NULL, NULL }, /* Dx */
262698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %Q */
263698f87a4SGarrett D'Amore 	{ NULL, NULL, post_percent, NULL, NULL }, /* %U */
264698f87a4SGarrett D'Amore 	{ NULL, NULL, NULL, NULL, NULL }, /* Ta */
265*4d131170SRobert Mustacchi 	{ NULL, pre_skip, NULL, NULL, NULL }, /* Tg */
26695c635efSGarrett D'Amore };
267cec8643bSMichal Nowak static const struct mdoc_man_act *mdoc_man_act(enum roff_tok);
26895c635efSGarrett D'Amore 
269698f87a4SGarrett D'Amore static	int		outflags;
270698f87a4SGarrett D'Amore #define	MMAN_spc	(1 << 0)  /* blank character before next word */
271698f87a4SGarrett D'Amore #define	MMAN_spc_force	(1 << 1)  /* even before trailing punctuation */
272698f87a4SGarrett D'Amore #define	MMAN_nl		(1 << 2)  /* break man(7) code line */
273698f87a4SGarrett D'Amore #define	MMAN_br		(1 << 3)  /* break output line */
274698f87a4SGarrett D'Amore #define	MMAN_sp		(1 << 4)  /* insert a blank output line */
275698f87a4SGarrett D'Amore #define	MMAN_PP		(1 << 5)  /* reset indentation etc. */
276698f87a4SGarrett D'Amore #define	MMAN_Sm		(1 << 6)  /* horizontal spacing mode */
277698f87a4SGarrett D'Amore #define	MMAN_Bk		(1 << 7)  /* word keep mode */
278698f87a4SGarrett D'Amore #define	MMAN_Bk_susp	(1 << 8)  /* suspend this (after a macro) */
279698f87a4SGarrett D'Amore #define	MMAN_An_split	(1 << 9)  /* author mode is "split" */
280698f87a4SGarrett D'Amore #define	MMAN_An_nosplit	(1 << 10) /* author mode is "nosplit" */
281698f87a4SGarrett D'Amore #define	MMAN_PD		(1 << 11) /* inter-paragraph spacing disabled */
282698f87a4SGarrett D'Amore #define	MMAN_nbrword	(1 << 12) /* do not break the next word */
283698f87a4SGarrett D'Amore 
284698f87a4SGarrett D'Amore #define	BL_STACK_MAX	32
285698f87a4SGarrett D'Amore 
286260e9a87SYuri Pankov static	int		Bl_stack[BL_STACK_MAX];  /* offsets [chars] */
287698f87a4SGarrett D'Amore static	int		Bl_stack_post[BL_STACK_MAX];  /* add final .RE */
288698f87a4SGarrett D'Amore static	int		Bl_stack_len;  /* number of nested Bl blocks */
289698f87a4SGarrett D'Amore static	int		TPremain;  /* characters before tag is full */
290698f87a4SGarrett D'Amore 
291698f87a4SGarrett D'Amore static	struct {
292698f87a4SGarrett D'Amore 	char	*head;
293698f87a4SGarrett D'Amore 	char	*tail;
294698f87a4SGarrett D'Amore 	size_t	 size;
295698f87a4SGarrett D'Amore }	fontqueue;
296698f87a4SGarrett D'Amore 
297260e9a87SYuri Pankov 
298cec8643bSMichal Nowak static const struct mdoc_man_act *
mdoc_man_act(enum roff_tok tok)299cec8643bSMichal Nowak mdoc_man_act(enum roff_tok tok)
300cec8643bSMichal Nowak {
301cec8643bSMichal Nowak 	assert(tok >= MDOC_Dd && tok <= MDOC_MAX);
302cec8643bSMichal Nowak 	return mdoc_man_acts + (tok - MDOC_Dd);
303cec8643bSMichal Nowak }
304cec8643bSMichal Nowak 
305c66b8046SYuri Pankov static int
man_strlen(const char * cp)306c66b8046SYuri Pankov man_strlen(const char *cp)
307c66b8046SYuri Pankov {
308c66b8046SYuri Pankov 	size_t	 rsz;
309c66b8046SYuri Pankov 	int	 skip, sz;
310c66b8046SYuri Pankov 
311c66b8046SYuri Pankov 	sz = 0;
312c66b8046SYuri Pankov 	skip = 0;
313c66b8046SYuri Pankov 	for (;;) {
314c66b8046SYuri Pankov 		rsz = strcspn(cp, "\\");
315c66b8046SYuri Pankov 		if (rsz) {
316c66b8046SYuri Pankov 			cp += rsz;
317c66b8046SYuri Pankov 			if (skip) {
318c66b8046SYuri Pankov 				skip = 0;
319c66b8046SYuri Pankov 				rsz--;
320c66b8046SYuri Pankov 			}
321c66b8046SYuri Pankov 			sz += rsz;
322c66b8046SYuri Pankov 		}
323c66b8046SYuri Pankov 		if ('\0' == *cp)
324c66b8046SYuri Pankov 			break;
325c66b8046SYuri Pankov 		cp++;
326c66b8046SYuri Pankov 		switch (mandoc_escape(&cp, NULL, NULL)) {
327c66b8046SYuri Pankov 		case ESCAPE_ERROR:
328c66b8046SYuri Pankov 			return sz;
329c66b8046SYuri Pankov 		case ESCAPE_UNICODE:
330c66b8046SYuri Pankov 		case ESCAPE_NUMBERED:
331c66b8046SYuri Pankov 		case ESCAPE_SPECIAL:
332cec8643bSMichal Nowak 		case ESCAPE_UNDEF:
333c66b8046SYuri Pankov 		case ESCAPE_OVERSTRIKE:
334c66b8046SYuri Pankov 			if (skip)
335c66b8046SYuri Pankov 				skip = 0;
336c66b8046SYuri Pankov 			else
337c66b8046SYuri Pankov 				sz++;
338c66b8046SYuri Pankov 			break;
339c66b8046SYuri Pankov 		case ESCAPE_SKIPCHAR:
340c66b8046SYuri Pankov 			skip = 1;
341c66b8046SYuri Pankov 			break;
342c66b8046SYuri Pankov 		default:
343c66b8046SYuri Pankov 			break;
344c66b8046SYuri Pankov 		}
345c66b8046SYuri Pankov 	}
346c66b8046SYuri Pankov 	return sz;
347c66b8046SYuri Pankov }
348c66b8046SYuri Pankov 
34995c635efSGarrett D'Amore static void
font_push(char newfont)350698f87a4SGarrett D'Amore font_push(char newfont)
35195c635efSGarrett D'Amore {
35295c635efSGarrett D'Amore 
353698f87a4SGarrett D'Amore 	if (fontqueue.head + fontqueue.size <= ++fontqueue.tail) {
354698f87a4SGarrett D'Amore 		fontqueue.size += 8;
355698f87a4SGarrett D'Amore 		fontqueue.head = mandoc_realloc(fontqueue.head,
356698f87a4SGarrett D'Amore 		    fontqueue.size);
357698f87a4SGarrett D'Amore 	}
358698f87a4SGarrett D'Amore 	*fontqueue.tail = newfont;
359698f87a4SGarrett D'Amore 	print_word("");
360698f87a4SGarrett D'Amore 	printf("\\f");
361698f87a4SGarrett D'Amore 	putchar(newfont);
362698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
363698f87a4SGarrett D'Amore }
364698f87a4SGarrett D'Amore 
365698f87a4SGarrett D'Amore static void
font_pop(void)366698f87a4SGarrett D'Amore font_pop(void)
367698f87a4SGarrett D'Amore {
368698f87a4SGarrett D'Amore 
369698f87a4SGarrett D'Amore 	if (fontqueue.tail > fontqueue.head)
370698f87a4SGarrett D'Amore 		fontqueue.tail--;
371698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
372698f87a4SGarrett D'Amore 	print_word("");
373698f87a4SGarrett D'Amore 	printf("\\f");
374698f87a4SGarrett D'Amore 	putchar(*fontqueue.tail);
375698f87a4SGarrett D'Amore }
376698f87a4SGarrett D'Amore 
377698f87a4SGarrett D'Amore static void
print_word(const char * s)378698f87a4SGarrett D'Amore print_word(const char *s)
379698f87a4SGarrett D'Amore {
380698f87a4SGarrett D'Amore 
381698f87a4SGarrett D'Amore 	if ((MMAN_PP | MMAN_sp | MMAN_br | MMAN_nl) & outflags) {
38295c635efSGarrett D'Amore 		/*
38395c635efSGarrett D'Amore 		 * If we need a newline, print it now and start afresh.
38495c635efSGarrett D'Amore 		 */
385698f87a4SGarrett D'Amore 		if (MMAN_PP & outflags) {
386698f87a4SGarrett D'Amore 			if (MMAN_sp & outflags) {
387698f87a4SGarrett D'Amore 				if (MMAN_PD & outflags) {
388698f87a4SGarrett D'Amore 					printf("\n.PD");
389698f87a4SGarrett D'Amore 					outflags &= ~MMAN_PD;
390698f87a4SGarrett D'Amore 				}
391698f87a4SGarrett D'Amore 			} else if ( ! (MMAN_PD & outflags)) {
392698f87a4SGarrett D'Amore 				printf("\n.PD 0");
393698f87a4SGarrett D'Amore 				outflags |= MMAN_PD;
394698f87a4SGarrett D'Amore 			}
395698f87a4SGarrett D'Amore 			printf("\n.PP\n");
396698f87a4SGarrett D'Amore 		} else if (MMAN_sp & outflags)
397698f87a4SGarrett D'Amore 			printf("\n.sp\n");
398698f87a4SGarrett D'Amore 		else if (MMAN_br & outflags)
399698f87a4SGarrett D'Amore 			printf("\n.br\n");
400698f87a4SGarrett D'Amore 		else if (MMAN_nl & outflags)
40195c635efSGarrett D'Amore 			putchar('\n');
402698f87a4SGarrett D'Amore 		outflags &= ~(MMAN_PP|MMAN_sp|MMAN_br|MMAN_nl|MMAN_spc);
403698f87a4SGarrett D'Amore 		if (1 == TPremain)
404698f87a4SGarrett D'Amore 			printf(".br\n");
405698f87a4SGarrett D'Amore 		TPremain = 0;
406698f87a4SGarrett D'Amore 	} else if (MMAN_spc & outflags) {
40795c635efSGarrett D'Amore 		/*
408698f87a4SGarrett D'Amore 		 * If we need a space, only print it if
409698f87a4SGarrett D'Amore 		 * (1) it is forced by `No' or
410698f87a4SGarrett D'Amore 		 * (2) what follows is not terminating punctuation or
411698f87a4SGarrett D'Amore 		 * (3) what follows is longer than one character.
41295c635efSGarrett D'Amore 		 */
413698f87a4SGarrett D'Amore 		if (MMAN_spc_force & outflags || '\0' == s[0] ||
414698f87a4SGarrett D'Amore 		    NULL == strchr(".,:;)]?!", s[0]) || '\0' != s[1]) {
415698f87a4SGarrett D'Amore 			if (MMAN_Bk & outflags &&
416698f87a4SGarrett D'Amore 			    ! (MMAN_Bk_susp & outflags))
417698f87a4SGarrett D'Amore 				putchar('\\');
41895c635efSGarrett D'Amore 			putchar(' ');
419698f87a4SGarrett D'Amore 			if (TPremain)
420698f87a4SGarrett D'Amore 				TPremain--;
421698f87a4SGarrett D'Amore 		}
422698f87a4SGarrett D'Amore 	}
42395c635efSGarrett D'Amore 
42495c635efSGarrett D'Amore 	/*
42595c635efSGarrett D'Amore 	 * Reassign needing space if we're not following opening
42695c635efSGarrett D'Amore 	 * punctuation.
42795c635efSGarrett D'Amore 	 */
428698f87a4SGarrett D'Amore 	if (MMAN_Sm & outflags && ('\0' == s[0] ||
429698f87a4SGarrett D'Amore 	    (('(' != s[0] && '[' != s[0]) || '\0' != s[1])))
430698f87a4SGarrett D'Amore 		outflags |= MMAN_spc;
431698f87a4SGarrett D'Amore 	else
432698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
433698f87a4SGarrett D'Amore 	outflags &= ~(MMAN_spc_force | MMAN_Bk_susp);
43495c635efSGarrett D'Amore 
43595c635efSGarrett D'Amore 	for ( ; *s; s++) {
43695c635efSGarrett D'Amore 		switch (*s) {
437260e9a87SYuri Pankov 		case ASCII_NBRSP:
438698f87a4SGarrett D'Amore 			printf("\\ ");
43995c635efSGarrett D'Amore 			break;
440260e9a87SYuri Pankov 		case ASCII_HYPH:
44195c635efSGarrett D'Amore 			putchar('-');
44295c635efSGarrett D'Amore 			break;
443260e9a87SYuri Pankov 		case ASCII_BREAK:
444260e9a87SYuri Pankov 			printf("\\:");
445260e9a87SYuri Pankov 			break;
446260e9a87SYuri Pankov 		case ' ':
447698f87a4SGarrett D'Amore 			if (MMAN_nbrword & outflags) {
448698f87a4SGarrett D'Amore 				printf("\\ ");
449698f87a4SGarrett D'Amore 				break;
450698f87a4SGarrett D'Amore 			}
451698f87a4SGarrett D'Amore 			/* FALLTHROUGH */
45295c635efSGarrett D'Amore 		default:
45395c635efSGarrett D'Amore 			putchar((unsigned char)*s);
45495c635efSGarrett D'Amore 			break;
45595c635efSGarrett D'Amore 		}
456698f87a4SGarrett D'Amore 		if (TPremain)
457698f87a4SGarrett D'Amore 			TPremain--;
45895c635efSGarrett D'Amore 	}
459698f87a4SGarrett D'Amore 	outflags &= ~MMAN_nbrword;
460698f87a4SGarrett D'Amore }
461698f87a4SGarrett D'Amore 
462698f87a4SGarrett D'Amore static void
print_line(const char * s,int newflags)463698f87a4SGarrett D'Amore print_line(const char *s, int newflags)
464698f87a4SGarrett D'Amore {
465698f87a4SGarrett D'Amore 
466698f87a4SGarrett D'Amore 	outflags |= MMAN_nl;
467698f87a4SGarrett D'Amore 	print_word(s);
468698f87a4SGarrett D'Amore 	outflags |= newflags;
469698f87a4SGarrett D'Amore }
470698f87a4SGarrett D'Amore 
471698f87a4SGarrett D'Amore static void
print_block(const char * s,int newflags)472698f87a4SGarrett D'Amore print_block(const char *s, int newflags)
473698f87a4SGarrett D'Amore {
474698f87a4SGarrett D'Amore 
475698f87a4SGarrett D'Amore 	outflags &= ~MMAN_PP;
476698f87a4SGarrett D'Amore 	if (MMAN_sp & outflags) {
477698f87a4SGarrett D'Amore 		outflags &= ~(MMAN_sp | MMAN_br);
478698f87a4SGarrett D'Amore 		if (MMAN_PD & outflags) {
479698f87a4SGarrett D'Amore 			print_line(".PD", 0);
480698f87a4SGarrett D'Amore 			outflags &= ~MMAN_PD;
481698f87a4SGarrett D'Amore 		}
482698f87a4SGarrett D'Amore 	} else if (! (MMAN_PD & outflags))
483698f87a4SGarrett D'Amore 		print_line(".PD 0", MMAN_PD);
484698f87a4SGarrett D'Amore 	outflags |= MMAN_nl;
485698f87a4SGarrett D'Amore 	print_word(s);
486698f87a4SGarrett D'Amore 	outflags |= MMAN_Bk_susp | newflags;
487698f87a4SGarrett D'Amore }
488698f87a4SGarrett D'Amore 
489698f87a4SGarrett D'Amore static void
print_offs(const char * v,int keywords)490260e9a87SYuri Pankov print_offs(const char *v, int keywords)
491698f87a4SGarrett D'Amore {
492698f87a4SGarrett D'Amore 	char		  buf[24];
493698f87a4SGarrett D'Amore 	struct roffsu	  su;
494c66b8046SYuri Pankov 	const char	 *end;
495260e9a87SYuri Pankov 	int		  sz;
496698f87a4SGarrett D'Amore 
497698f87a4SGarrett D'Amore 	print_line(".RS", MMAN_Bk_susp);
498698f87a4SGarrett D'Amore 
499698f87a4SGarrett D'Amore 	/* Convert v into a number (of characters). */
500260e9a87SYuri Pankov 	if (NULL == v || '\0' == *v || (keywords && !strcmp(v, "left")))
501698f87a4SGarrett D'Amore 		sz = 0;
502260e9a87SYuri Pankov 	else if (keywords && !strcmp(v, "indent"))
503698f87a4SGarrett D'Amore 		sz = 6;
504260e9a87SYuri Pankov 	else if (keywords && !strcmp(v, "indent-two"))
505698f87a4SGarrett D'Amore 		sz = 12;
506c66b8046SYuri Pankov 	else {
507c66b8046SYuri Pankov 		end = a2roffsu(v, &su, SCALE_EN);
508c66b8046SYuri Pankov 		if (end == NULL || *end != '\0')
509c66b8046SYuri Pankov 			sz = man_strlen(v);
510c66b8046SYuri Pankov 		else if (SCALE_EN == su.unit)
511698f87a4SGarrett D'Amore 			sz = su.scale;
512698f87a4SGarrett D'Amore 		else {
513698f87a4SGarrett D'Amore 			/*
514698f87a4SGarrett D'Amore 			 * XXX
515698f87a4SGarrett D'Amore 			 * If we are inside an enclosing list,
516698f87a4SGarrett D'Amore 			 * there is no easy way to add the two
517698f87a4SGarrett D'Amore 			 * indentations because they are provided
518698f87a4SGarrett D'Amore 			 * in terms of different units.
519698f87a4SGarrett D'Amore 			 */
520698f87a4SGarrett D'Amore 			print_word(v);
521698f87a4SGarrett D'Amore 			outflags |= MMAN_nl;
522698f87a4SGarrett D'Amore 			return;
523698f87a4SGarrett D'Amore 		}
524c66b8046SYuri Pankov 	}
525698f87a4SGarrett D'Amore 
526698f87a4SGarrett D'Amore 	/*
527698f87a4SGarrett D'Amore 	 * We are inside an enclosing list.
528698f87a4SGarrett D'Amore 	 * Add the two indentations.
529698f87a4SGarrett D'Amore 	 */
530698f87a4SGarrett D'Amore 	if (Bl_stack_len)
531698f87a4SGarrett D'Amore 		sz += Bl_stack[Bl_stack_len - 1];
532698f87a4SGarrett D'Amore 
533260e9a87SYuri Pankov 	(void)snprintf(buf, sizeof(buf), "%dn", sz);
534698f87a4SGarrett D'Amore 	print_word(buf);
535698f87a4SGarrett D'Amore 	outflags |= MMAN_nl;
536698f87a4SGarrett D'Amore }
537698f87a4SGarrett D'Amore 
538698f87a4SGarrett D'Amore /*
539698f87a4SGarrett D'Amore  * Set up the indentation for a list item; used from pre_it().
540698f87a4SGarrett D'Amore  */
541260e9a87SYuri Pankov static void
print_width(const struct mdoc_bl * bl,const struct roff_node * child)542371584c2SYuri Pankov print_width(const struct mdoc_bl *bl, const struct roff_node *child)
543698f87a4SGarrett D'Amore {
544698f87a4SGarrett D'Amore 	char		  buf[24];
545698f87a4SGarrett D'Amore 	struct roffsu	  su;
546c66b8046SYuri Pankov 	const char	 *end;
547260e9a87SYuri Pankov 	int		  numeric, remain, sz, chsz;
548698f87a4SGarrett D'Amore 
549698f87a4SGarrett D'Amore 	numeric = 1;
550698f87a4SGarrett D'Amore 	remain = 0;
551698f87a4SGarrett D'Amore 
552260e9a87SYuri Pankov 	/* Convert the width into a number (of characters). */
553260e9a87SYuri Pankov 	if (bl->width == NULL)
554260e9a87SYuri Pankov 		sz = (bl->type == LIST_hang) ? 6 : 0;
555c66b8046SYuri Pankov 	else {
556c66b8046SYuri Pankov 		end = a2roffsu(bl->width, &su, SCALE_MAX);
557c66b8046SYuri Pankov 		if (end == NULL || *end != '\0')
558c66b8046SYuri Pankov 			sz = man_strlen(bl->width);
559c66b8046SYuri Pankov 		else if (SCALE_EN == su.unit)
560698f87a4SGarrett D'Amore 			sz = su.scale;
561698f87a4SGarrett D'Amore 		else {
562698f87a4SGarrett D'Amore 			sz = 0;
563698f87a4SGarrett D'Amore 			numeric = 0;
564698f87a4SGarrett D'Amore 		}
565c66b8046SYuri Pankov 	}
566698f87a4SGarrett D'Amore 
567698f87a4SGarrett D'Amore 	/* XXX Rough estimation, might have multiple parts. */
568260e9a87SYuri Pankov 	if (bl->type == LIST_enum)
569260e9a87SYuri Pankov 		chsz = (bl->count > 8) + 1;
570371584c2SYuri Pankov 	else if (child != NULL && child->type == ROFFT_TEXT)
571c66b8046SYuri Pankov 		chsz = man_strlen(child->string);
572260e9a87SYuri Pankov 	else
573260e9a87SYuri Pankov 		chsz = 0;
574698f87a4SGarrett D'Amore 
575698f87a4SGarrett D'Amore 	/* Maybe we are inside an enclosing list? */
576698f87a4SGarrett D'Amore 	mid_it();
577698f87a4SGarrett D'Amore 
578698f87a4SGarrett D'Amore 	/*
579698f87a4SGarrett D'Amore 	 * Save our own indentation,
580698f87a4SGarrett D'Amore 	 * such that child lists can use it.
581698f87a4SGarrett D'Amore 	 */
582698f87a4SGarrett D'Amore 	Bl_stack[Bl_stack_len++] = sz + 2;
583698f87a4SGarrett D'Amore 
584698f87a4SGarrett D'Amore 	/* Set up the current list. */
585260e9a87SYuri Pankov 	if (chsz > sz && bl->type != LIST_tag)
586*4d131170SRobert Mustacchi 		print_block(".HP", MMAN_spc);
587698f87a4SGarrett D'Amore 	else {
588*4d131170SRobert Mustacchi 		print_block(".TP", MMAN_spc);
589698f87a4SGarrett D'Amore 		remain = sz + 2;
590698f87a4SGarrett D'Amore 	}
591698f87a4SGarrett D'Amore 	if (numeric) {
592260e9a87SYuri Pankov 		(void)snprintf(buf, sizeof(buf), "%dn", sz + 2);
593698f87a4SGarrett D'Amore 		print_word(buf);
594698f87a4SGarrett D'Amore 	} else
595260e9a87SYuri Pankov 		print_word(bl->width);
596698f87a4SGarrett D'Amore 	TPremain = remain;
597698f87a4SGarrett D'Amore }
598698f87a4SGarrett D'Amore 
599260e9a87SYuri Pankov static void
print_count(int * count)600698f87a4SGarrett D'Amore print_count(int *count)
601698f87a4SGarrett D'Amore {
602260e9a87SYuri Pankov 	char		  buf[24];
603698f87a4SGarrett D'Amore 
604260e9a87SYuri Pankov 	(void)snprintf(buf, sizeof(buf), "%d.\\&", ++*count);
605698f87a4SGarrett D'Amore 	print_word(buf);
60695c635efSGarrett D'Amore }
60795c635efSGarrett D'Amore 
60895c635efSGarrett D'Amore void
man_mdoc(void * arg,const struct roff_meta * mdoc)609cec8643bSMichal Nowak man_mdoc(void *arg, const struct roff_meta *mdoc)
61095c635efSGarrett D'Amore {
611371584c2SYuri Pankov 	struct roff_node *n;
61295c635efSGarrett D'Amore 
6136640c13bSYuri Pankov 	printf(".\\\" Automatically generated from an mdoc input file."
6146640c13bSYuri Pankov 	    "  Do not edit.\n");
6156640c13bSYuri Pankov 	for (n = mdoc->first->child; n != NULL; n = n->next) {
6166640c13bSYuri Pankov 		if (n->type != ROFFT_COMMENT)
6176640c13bSYuri Pankov 			break;
6186640c13bSYuri Pankov 		printf(".\\\"%s\n", n->string);
6196640c13bSYuri Pankov 	}
6206640c13bSYuri Pankov 
621698f87a4SGarrett D'Amore 	printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
622cec8643bSMichal Nowak 	    mdoc->title, (mdoc->msec == NULL ? "" : mdoc->msec),
623cec8643bSMichal Nowak 	    mdoc->date, mdoc->os, mdoc->vol);
62495c635efSGarrett D'Amore 
625698f87a4SGarrett D'Amore 	/* Disable hyphenation and if nroff, disable justification. */
626698f87a4SGarrett D'Amore 	printf(".nh\n.if n .ad l");
62795c635efSGarrett D'Amore 
628698f87a4SGarrett D'Amore 	outflags = MMAN_nl | MMAN_Sm;
629698f87a4SGarrett D'Amore 	if (0 == fontqueue.size) {
630698f87a4SGarrett D'Amore 		fontqueue.size = 8;
631698f87a4SGarrett D'Amore 		fontqueue.head = fontqueue.tail = mandoc_malloc(8);
632698f87a4SGarrett D'Amore 		*fontqueue.tail = 'R';
633698f87a4SGarrett D'Amore 	}
6346640c13bSYuri Pankov 	for (; n != NULL; n = n->next)
635cec8643bSMichal Nowak 		print_node(mdoc, n);
63695c635efSGarrett D'Amore 	putchar('\n');
63795c635efSGarrett D'Amore }
63895c635efSGarrett D'Amore 
63995c635efSGarrett D'Amore static void
print_node(DECL_ARGS)64095c635efSGarrett D'Amore print_node(DECL_ARGS)
64195c635efSGarrett D'Amore {
642cec8643bSMichal Nowak 	const struct mdoc_man_act	*act;
643371584c2SYuri Pankov 	struct roff_node		*sub;
64495c635efSGarrett D'Amore 	int				 cond, do_sub;
64595c635efSGarrett D'Amore 
646a40ea1a7SYuri Pankov 	if (n->flags & NODE_NOPRT)
647a40ea1a7SYuri Pankov 		return;
648a40ea1a7SYuri Pankov 
64995c635efSGarrett D'Amore 	/*
65095c635efSGarrett D'Amore 	 * Break the line if we were parsed subsequent the current node.
65195c635efSGarrett D'Amore 	 * This makes the page structure be more consistent.
65295c635efSGarrett D'Amore 	 */
653*4d131170SRobert Mustacchi 	if (outflags & MMAN_spc &&
654*4d131170SRobert Mustacchi 	    n->flags & NODE_LINE &&
655*4d131170SRobert Mustacchi 	    !roff_node_transparent(n))
656698f87a4SGarrett D'Amore 		outflags |= MMAN_nl;
65795c635efSGarrett D'Amore 
65895c635efSGarrett D'Amore 	act = NULL;
65995c635efSGarrett D'Amore 	cond = 0;
66095c635efSGarrett D'Amore 	do_sub = 1;
661a40ea1a7SYuri Pankov 	n->flags &= ~NODE_ENDED;
66295c635efSGarrett D'Amore 
663*4d131170SRobert Mustacchi 	switch (n->type) {
664*4d131170SRobert Mustacchi 	case ROFFT_EQN:
665*4d131170SRobert Mustacchi 	case ROFFT_TBL:
666*4d131170SRobert Mustacchi 		mandoc_msg(n->type == ROFFT_EQN ? MANDOCERR_EQN_TMAN :
667*4d131170SRobert Mustacchi 		    MANDOCERR_TBL_TMAN, n->line, n->pos, NULL);
668*4d131170SRobert Mustacchi 		outflags |= MMAN_PP | MMAN_sp | MMAN_nl;
669*4d131170SRobert Mustacchi 		print_word("The");
670*4d131170SRobert Mustacchi 		print_line(".B \\-T man", MMAN_nl);
671*4d131170SRobert Mustacchi 		print_word("output mode does not support");
672*4d131170SRobert Mustacchi 		print_word(n->type == ROFFT_EQN ? "eqn(7)" : "tbl(7)");
673*4d131170SRobert Mustacchi 		print_word("input.");
674*4d131170SRobert Mustacchi 		outflags |= MMAN_PP | MMAN_sp | MMAN_nl;
675*4d131170SRobert Mustacchi 		return;
676*4d131170SRobert Mustacchi 	case ROFFT_TEXT:
67795c635efSGarrett D'Amore 		/*
67895c635efSGarrett D'Amore 		 * Make sure that we don't happen to start with a
67995c635efSGarrett D'Amore 		 * control character at the start of a line.
68095c635efSGarrett D'Amore 		 */
681260e9a87SYuri Pankov 		if (MMAN_nl & outflags &&
682260e9a87SYuri Pankov 		    ('.' == *n->string || '\'' == *n->string)) {
683698f87a4SGarrett D'Amore 			print_word("");
684698f87a4SGarrett D'Amore 			printf("\\&");
685698f87a4SGarrett D'Amore 			outflags &= ~MMAN_spc;
68695c635efSGarrett D'Amore 		}
687a40ea1a7SYuri Pankov 		if (n->flags & NODE_DELIMC)
688a40ea1a7SYuri Pankov 			outflags &= ~(MMAN_spc | MMAN_spc_force);
689a40ea1a7SYuri Pankov 		else if (outflags & MMAN_Sm)
690260e9a87SYuri Pankov 			outflags |= MMAN_spc_force;
691698f87a4SGarrett D'Amore 		print_word(n->string);
692a40ea1a7SYuri Pankov 		if (n->flags & NODE_DELIMO)
693a40ea1a7SYuri Pankov 			outflags &= ~(MMAN_spc | MMAN_spc_force);
694a40ea1a7SYuri Pankov 		else if (outflags & MMAN_Sm)
695260e9a87SYuri Pankov 			outflags |= MMAN_spc;
696*4d131170SRobert Mustacchi 		break;
697*4d131170SRobert Mustacchi 	default:
698*4d131170SRobert Mustacchi 		if (n->tok < ROFF_MAX) {
699cec8643bSMichal Nowak 			(*roff_man_acts[n->tok])(meta, n);
700c66b8046SYuri Pankov 			return;
701*4d131170SRobert Mustacchi 		}
702cec8643bSMichal Nowak 		act = mdoc_man_act(n->tok);
703260e9a87SYuri Pankov 		cond = act->cond == NULL || (*act->cond)(meta, n);
704371584c2SYuri Pankov 		if (cond && act->pre != NULL &&
705371584c2SYuri Pankov 		    (n->end == ENDBODY_NOT || n->child != NULL))
706698f87a4SGarrett D'Amore 			do_sub = (*act->pre)(meta, n);
707*4d131170SRobert Mustacchi 		break;
70895c635efSGarrett D'Amore 	}
70995c635efSGarrett D'Amore 
71095c635efSGarrett D'Amore 	/*
71195c635efSGarrett D'Amore 	 * Conditionally run all child nodes.
71295c635efSGarrett D'Amore 	 * Note that this iterates over children instead of using
71395c635efSGarrett D'Amore 	 * recursion.  This prevents unnecessary depth in the stack.
71495c635efSGarrett D'Amore 	 */
71595c635efSGarrett D'Amore 	if (do_sub)
71695c635efSGarrett D'Amore 		for (sub = n->child; sub; sub = sub->next)
717698f87a4SGarrett D'Amore 			print_node(meta, sub);
71895c635efSGarrett D'Amore 
71995c635efSGarrett D'Amore 	/*
72095c635efSGarrett D'Amore 	 * Lastly, conditionally run the post-node handler.
72195c635efSGarrett D'Amore 	 */
722a40ea1a7SYuri Pankov 	if (NODE_ENDED & n->flags)
723260e9a87SYuri Pankov 		return;
724260e9a87SYuri Pankov 
72595c635efSGarrett D'Amore 	if (cond && act->post)
726698f87a4SGarrett D'Amore 		(*act->post)(meta, n);
727260e9a87SYuri Pankov 
728260e9a87SYuri Pankov 	if (ENDBODY_NOT != n->end)
729a40ea1a7SYuri Pankov 		n->body->flags |= NODE_ENDED;
73095c635efSGarrett D'Amore }
73195c635efSGarrett D'Amore 
73295c635efSGarrett D'Amore static int
cond_head(DECL_ARGS)73395c635efSGarrett D'Amore cond_head(DECL_ARGS)
73495c635efSGarrett D'Amore {
73595c635efSGarrett D'Amore 
736371584c2SYuri Pankov 	return n->type == ROFFT_HEAD;
73795c635efSGarrett D'Amore }
73895c635efSGarrett D'Amore 
73995c635efSGarrett D'Amore static int
cond_body(DECL_ARGS)74095c635efSGarrett D'Amore cond_body(DECL_ARGS)
74195c635efSGarrett D'Amore {
74295c635efSGarrett D'Amore 
743371584c2SYuri Pankov 	return n->type == ROFFT_BODY;
74495c635efSGarrett D'Amore }
74595c635efSGarrett D'Amore 
74695c635efSGarrett D'Amore static int
pre_abort(DECL_ARGS)747cec8643bSMichal Nowak pre_abort(DECL_ARGS)
748cec8643bSMichal Nowak {
749cec8643bSMichal Nowak 	abort();
750cec8643bSMichal Nowak }
751cec8643bSMichal Nowak 
752cec8643bSMichal Nowak static int
pre_enc(DECL_ARGS)75395c635efSGarrett D'Amore pre_enc(DECL_ARGS)
75495c635efSGarrett D'Amore {
75595c635efSGarrett D'Amore 	const char	*prefix;
75695c635efSGarrett D'Amore 
757cec8643bSMichal Nowak 	prefix = mdoc_man_act(n->tok)->prefix;
75895c635efSGarrett D'Amore 	if (NULL == prefix)
759371584c2SYuri Pankov 		return 1;
760698f87a4SGarrett D'Amore 	print_word(prefix);
761698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
762371584c2SYuri Pankov 	return 1;
76395c635efSGarrett D'Amore }
76495c635efSGarrett D'Amore 
76595c635efSGarrett D'Amore static void
post_enc(DECL_ARGS)76695c635efSGarrett D'Amore post_enc(DECL_ARGS)
76795c635efSGarrett D'Amore {
76895c635efSGarrett D'Amore 	const char *suffix;
76995c635efSGarrett D'Amore 
770cec8643bSMichal Nowak 	suffix = mdoc_man_act(n->tok)->suffix;
77195c635efSGarrett D'Amore 	if (NULL == suffix)
77295c635efSGarrett D'Amore 		return;
773260e9a87SYuri Pankov 	outflags &= ~(MMAN_spc | MMAN_nl);
774698f87a4SGarrett D'Amore 	print_word(suffix);
77595c635efSGarrett D'Amore }
77695c635efSGarrett D'Amore 
777260e9a87SYuri Pankov static int
pre_ex(DECL_ARGS)778260e9a87SYuri Pankov pre_ex(DECL_ARGS)
779260e9a87SYuri Pankov {
780260e9a87SYuri Pankov 	outflags |= MMAN_br | MMAN_nl;
781a40ea1a7SYuri Pankov 	return 1;
782260e9a87SYuri Pankov }
783260e9a87SYuri Pankov 
784698f87a4SGarrett D'Amore static void
post_font(DECL_ARGS)785698f87a4SGarrett D'Amore post_font(DECL_ARGS)
786698f87a4SGarrett D'Amore {
787698f87a4SGarrett D'Amore 
788698f87a4SGarrett D'Amore 	font_pop();
789698f87a4SGarrett D'Amore }
790698f87a4SGarrett D'Amore 
79195c635efSGarrett D'Amore static void
post_percent(DECL_ARGS)79295c635efSGarrett D'Amore post_percent(DECL_ARGS)
79395c635efSGarrett D'Amore {
794*4d131170SRobert Mustacchi 	struct roff_node *np, *nn, *nnn;
79595c635efSGarrett D'Amore 
796cec8643bSMichal Nowak 	if (mdoc_man_act(n->tok)->pre == pre_em)
797698f87a4SGarrett D'Amore 		font_pop();
798*4d131170SRobert Mustacchi 
799*4d131170SRobert Mustacchi 	if ((nn = roff_node_next(n)) != NULL) {
800*4d131170SRobert Mustacchi 		np = roff_node_prev(n);
801*4d131170SRobert Mustacchi 		nnn = nn == NULL ? NULL : roff_node_next(nn);
802*4d131170SRobert Mustacchi 		if (nn->tok != n->tok ||
803*4d131170SRobert Mustacchi 		    (np != NULL && np->tok == n->tok) ||
804*4d131170SRobert Mustacchi 		    (nnn != NULL && nnn->tok == n->tok))
805698f87a4SGarrett D'Amore 			print_word(",");
806*4d131170SRobert Mustacchi 		if (nn->tok == n->tok &&
807*4d131170SRobert Mustacchi 		    (nnn == NULL || nnn->tok != n->tok))
808698f87a4SGarrett D'Amore 			print_word("and");
809698f87a4SGarrett D'Amore 	} else {
810698f87a4SGarrett D'Amore 		print_word(".");
811698f87a4SGarrett D'Amore 		outflags |= MMAN_nl;
81295c635efSGarrett D'Amore 	}
81395c635efSGarrett D'Amore }
81495c635efSGarrett D'Amore 
815698f87a4SGarrett D'Amore static int
pre__t(DECL_ARGS)816698f87a4SGarrett D'Amore pre__t(DECL_ARGS)
817698f87a4SGarrett D'Amore {
818698f87a4SGarrett D'Amore 
819c66b8046SYuri Pankov 	if (n->parent->tok == MDOC_Rs && n->parent->norm->Rs.quote_T) {
820a40ea1a7SYuri Pankov 		print_word("\\(lq");
821698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
822698f87a4SGarrett D'Amore 	} else
823698f87a4SGarrett D'Amore 		font_push('I');
824371584c2SYuri Pankov 	return 1;
825698f87a4SGarrett D'Amore }
826698f87a4SGarrett D'Amore 
827698f87a4SGarrett D'Amore static void
post__t(DECL_ARGS)828698f87a4SGarrett D'Amore post__t(DECL_ARGS)
829698f87a4SGarrett D'Amore {
830698f87a4SGarrett D'Amore 
831c66b8046SYuri Pankov 	if (n->parent->tok  == MDOC_Rs && n->parent->norm->Rs.quote_T) {
832698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
833a40ea1a7SYuri Pankov 		print_word("\\(rq");
834698f87a4SGarrett D'Amore 	} else
835698f87a4SGarrett D'Amore 		font_pop();
836698f87a4SGarrett D'Amore 	post_percent(meta, n);
837698f87a4SGarrett D'Amore }
838698f87a4SGarrett D'Amore 
83995c635efSGarrett D'Amore /*
84095c635efSGarrett D'Amore  * Print before a section header.
84195c635efSGarrett D'Amore  */
84295c635efSGarrett D'Amore static int
pre_sect(DECL_ARGS)84395c635efSGarrett D'Amore pre_sect(DECL_ARGS)
84495c635efSGarrett D'Amore {
84595c635efSGarrett D'Amore 
846371584c2SYuri Pankov 	if (n->type == ROFFT_HEAD) {
847698f87a4SGarrett D'Amore 		outflags |= MMAN_sp;
848cec8643bSMichal Nowak 		print_block(mdoc_man_act(n->tok)->prefix, 0);
849698f87a4SGarrett D'Amore 		print_word("");
850698f87a4SGarrett D'Amore 		putchar('\"');
851698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
852698f87a4SGarrett D'Amore 	}
853371584c2SYuri Pankov 	return 1;
85495c635efSGarrett D'Amore }
85595c635efSGarrett D'Amore 
85695c635efSGarrett D'Amore /*
85795c635efSGarrett D'Amore  * Print subsequent a section header.
85895c635efSGarrett D'Amore  */
85995c635efSGarrett D'Amore static void
post_sect(DECL_ARGS)86095c635efSGarrett D'Amore post_sect(DECL_ARGS)
86195c635efSGarrett D'Amore {
86295c635efSGarrett D'Amore 
863371584c2SYuri Pankov 	if (n->type != ROFFT_HEAD)
86495c635efSGarrett D'Amore 		return;
865698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
866698f87a4SGarrett D'Amore 	print_word("");
867698f87a4SGarrett D'Amore 	putchar('\"');
868698f87a4SGarrett D'Amore 	outflags |= MMAN_nl;
869698f87a4SGarrett D'Amore 	if (MDOC_Sh == n->tok && SEC_AUTHORS == n->sec)
870698f87a4SGarrett D'Amore 		outflags &= ~(MMAN_An_split | MMAN_An_nosplit);
871698f87a4SGarrett D'Amore }
872698f87a4SGarrett D'Amore 
873698f87a4SGarrett D'Amore /* See mdoc_term.c, synopsis_pre() for comments. */
874698f87a4SGarrett D'Amore static void
pre_syn(struct roff_node * n)875*4d131170SRobert Mustacchi pre_syn(struct roff_node *n)
876698f87a4SGarrett D'Amore {
877*4d131170SRobert Mustacchi 	struct roff_node *np;
878698f87a4SGarrett D'Amore 
879*4d131170SRobert Mustacchi 	if ((n->flags & NODE_SYNPRETTY) == 0 ||
880*4d131170SRobert Mustacchi 	    (np = roff_node_prev(n)) == NULL)
881698f87a4SGarrett D'Amore 		return;
882698f87a4SGarrett D'Amore 
883*4d131170SRobert Mustacchi 	if (np->tok == n->tok &&
884698f87a4SGarrett D'Amore 	    MDOC_Ft != n->tok &&
885698f87a4SGarrett D'Amore 	    MDOC_Fo != n->tok &&
886698f87a4SGarrett D'Amore 	    MDOC_Fn != n->tok) {
887698f87a4SGarrett D'Amore 		outflags |= MMAN_br;
888698f87a4SGarrett D'Amore 		return;
889698f87a4SGarrett D'Amore 	}
890698f87a4SGarrett D'Amore 
891*4d131170SRobert Mustacchi 	switch (np->tok) {
892260e9a87SYuri Pankov 	case MDOC_Fd:
893260e9a87SYuri Pankov 	case MDOC_Fn:
894260e9a87SYuri Pankov 	case MDOC_Fo:
895260e9a87SYuri Pankov 	case MDOC_In:
896260e9a87SYuri Pankov 	case MDOC_Vt:
897698f87a4SGarrett D'Amore 		outflags |= MMAN_sp;
898698f87a4SGarrett D'Amore 		break;
899260e9a87SYuri Pankov 	case MDOC_Ft:
900698f87a4SGarrett D'Amore 		if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
901698f87a4SGarrett D'Amore 			outflags |= MMAN_sp;
902698f87a4SGarrett D'Amore 			break;
903698f87a4SGarrett D'Amore 		}
904698f87a4SGarrett D'Amore 		/* FALLTHROUGH */
905698f87a4SGarrett D'Amore 	default:
906698f87a4SGarrett D'Amore 		outflags |= MMAN_br;
907698f87a4SGarrett D'Amore 		break;
908698f87a4SGarrett D'Amore 	}
909698f87a4SGarrett D'Amore }
910698f87a4SGarrett D'Amore 
911698f87a4SGarrett D'Amore static int
pre_an(DECL_ARGS)912698f87a4SGarrett D'Amore pre_an(DECL_ARGS)
913698f87a4SGarrett D'Amore {
914698f87a4SGarrett D'Amore 
915698f87a4SGarrett D'Amore 	switch (n->norm->An.auth) {
916260e9a87SYuri Pankov 	case AUTH_split:
917698f87a4SGarrett D'Amore 		outflags &= ~MMAN_An_nosplit;
918698f87a4SGarrett D'Amore 		outflags |= MMAN_An_split;
919371584c2SYuri Pankov 		return 0;
920260e9a87SYuri Pankov 	case AUTH_nosplit:
921698f87a4SGarrett D'Amore 		outflags &= ~MMAN_An_split;
922698f87a4SGarrett D'Amore 		outflags |= MMAN_An_nosplit;
923371584c2SYuri Pankov 		return 0;
924698f87a4SGarrett D'Amore 	default:
925698f87a4SGarrett D'Amore 		if (MMAN_An_split & outflags)
926698f87a4SGarrett D'Amore 			outflags |= MMAN_br;
927698f87a4SGarrett D'Amore 		else if (SEC_AUTHORS == n->sec &&
928698f87a4SGarrett D'Amore 		    ! (MMAN_An_nosplit & outflags))
929698f87a4SGarrett D'Amore 			outflags |= MMAN_An_split;
930371584c2SYuri Pankov 		return 1;
931698f87a4SGarrett D'Amore 	}
93295c635efSGarrett D'Amore }
93395c635efSGarrett D'Amore 
93495c635efSGarrett D'Amore static int
pre_ap(DECL_ARGS)93595c635efSGarrett D'Amore pre_ap(DECL_ARGS)
93695c635efSGarrett D'Amore {
93795c635efSGarrett D'Amore 
938698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
939698f87a4SGarrett D'Amore 	print_word("'");
940698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
941371584c2SYuri Pankov 	return 0;
94295c635efSGarrett D'Amore }
94395c635efSGarrett D'Amore 
94495c635efSGarrett D'Amore static int
pre_aq(DECL_ARGS)945260e9a87SYuri Pankov pre_aq(DECL_ARGS)
946260e9a87SYuri Pankov {
947260e9a87SYuri Pankov 
948371584c2SYuri Pankov 	print_word(n->child != NULL && n->child->next == NULL &&
949260e9a87SYuri Pankov 	    n->child->tok == MDOC_Mt ?  "<" : "\\(la");
950260e9a87SYuri Pankov 	outflags &= ~MMAN_spc;
951371584c2SYuri Pankov 	return 1;
952260e9a87SYuri Pankov }
953260e9a87SYuri Pankov 
954260e9a87SYuri Pankov static void
post_aq(DECL_ARGS)955260e9a87SYuri Pankov post_aq(DECL_ARGS)
956260e9a87SYuri Pankov {
957260e9a87SYuri Pankov 
958260e9a87SYuri Pankov 	outflags &= ~(MMAN_spc | MMAN_nl);
959371584c2SYuri Pankov 	print_word(n->child != NULL && n->child->next == NULL &&
960260e9a87SYuri Pankov 	    n->child->tok == MDOC_Mt ?  ">" : "\\(ra");
961260e9a87SYuri Pankov }
962260e9a87SYuri Pankov 
963260e9a87SYuri Pankov static int
pre_bd(DECL_ARGS)96495c635efSGarrett D'Amore pre_bd(DECL_ARGS)
96595c635efSGarrett D'Amore {
966698f87a4SGarrett D'Amore 	outflags &= ~(MMAN_PP | MMAN_sp | MMAN_br);
967*4d131170SRobert Mustacchi 	if (n->norm->Bd.type == DISP_unfilled ||
968*4d131170SRobert Mustacchi 	    n->norm->Bd.type == DISP_literal)
969698f87a4SGarrett D'Amore 		print_line(".nf", 0);
970*4d131170SRobert Mustacchi 	if (n->norm->Bd.comp == 0 && roff_node_prev(n->parent) != NULL)
971698f87a4SGarrett D'Amore 		outflags |= MMAN_sp;
972260e9a87SYuri Pankov 	print_offs(n->norm->Bd.offs, 1);
973371584c2SYuri Pankov 	return 1;
97495c635efSGarrett D'Amore }
97595c635efSGarrett D'Amore 
97695c635efSGarrett D'Amore static void
post_bd(DECL_ARGS)97795c635efSGarrett D'Amore post_bd(DECL_ARGS)
97895c635efSGarrett D'Amore {
979cec8643bSMichal Nowak 	enum roff_tok	 bef, now;
98095c635efSGarrett D'Amore 
981698f87a4SGarrett D'Amore 	/* Close out this display. */
982698f87a4SGarrett D'Amore 	print_line(".RE", MMAN_nl);
983cec8643bSMichal Nowak 	bef = n->flags & NODE_NOFILL ? ROFF_nf : ROFF_fi;
984cec8643bSMichal Nowak 	if (n->last == NULL)
985cec8643bSMichal Nowak 		now = n->norm->Bd.type == DISP_unfilled ||
986cec8643bSMichal Nowak 		    n->norm->Bd.type == DISP_literal ? ROFF_nf : ROFF_fi;
987cec8643bSMichal Nowak 	else if (n->last->tok == ROFF_nf)
988cec8643bSMichal Nowak 		now = ROFF_nf;
989cec8643bSMichal Nowak 	else if (n->last->tok == ROFF_fi)
990cec8643bSMichal Nowak 		now = ROFF_fi;
991cec8643bSMichal Nowak 	else
992cec8643bSMichal Nowak 		now = n->last->flags & NODE_NOFILL ? ROFF_nf : ROFF_fi;
993cec8643bSMichal Nowak 	if (bef != now) {
994cec8643bSMichal Nowak 		outflags |= MMAN_nl;
995cec8643bSMichal Nowak 		print_word(".");
996cec8643bSMichal Nowak 		outflags &= ~MMAN_spc;
997cec8643bSMichal Nowak 		print_word(roff_name[bef]);
998cec8643bSMichal Nowak 		outflags |= MMAN_nl;
999cec8643bSMichal Nowak 	}
1000698f87a4SGarrett D'Amore 
1001698f87a4SGarrett D'Amore 	/* Maybe we are inside an enclosing list? */
1002*4d131170SRobert Mustacchi 	if (roff_node_next(n->parent) != NULL)
1003698f87a4SGarrett D'Amore 		mid_it();
100495c635efSGarrett D'Amore }
1005698f87a4SGarrett D'Amore 
1006698f87a4SGarrett D'Amore static int
pre_bf(DECL_ARGS)1007698f87a4SGarrett D'Amore pre_bf(DECL_ARGS)
1008698f87a4SGarrett D'Amore {
1009698f87a4SGarrett D'Amore 
1010698f87a4SGarrett D'Amore 	switch (n->type) {
1011371584c2SYuri Pankov 	case ROFFT_BLOCK:
1012371584c2SYuri Pankov 		return 1;
1013371584c2SYuri Pankov 	case ROFFT_BODY:
1014698f87a4SGarrett D'Amore 		break;
1015698f87a4SGarrett D'Amore 	default:
1016371584c2SYuri Pankov 		return 0;
1017698f87a4SGarrett D'Amore 	}
1018698f87a4SGarrett D'Amore 	switch (n->norm->Bf.font) {
1019260e9a87SYuri Pankov 	case FONT_Em:
1020698f87a4SGarrett D'Amore 		font_push('I');
1021698f87a4SGarrett D'Amore 		break;
1022260e9a87SYuri Pankov 	case FONT_Sy:
1023698f87a4SGarrett D'Amore 		font_push('B');
1024698f87a4SGarrett D'Amore 		break;
1025698f87a4SGarrett D'Amore 	default:
1026698f87a4SGarrett D'Amore 		font_push('R');
1027698f87a4SGarrett D'Amore 		break;
1028698f87a4SGarrett D'Amore 	}
1029371584c2SYuri Pankov 	return 1;
1030698f87a4SGarrett D'Amore }
1031698f87a4SGarrett D'Amore 
1032698f87a4SGarrett D'Amore static void
post_bf(DECL_ARGS)1033698f87a4SGarrett D'Amore post_bf(DECL_ARGS)
1034698f87a4SGarrett D'Amore {
1035698f87a4SGarrett D'Amore 
1036371584c2SYuri Pankov 	if (n->type == ROFFT_BODY)
1037698f87a4SGarrett D'Amore 		font_pop();
1038698f87a4SGarrett D'Amore }
1039698f87a4SGarrett D'Amore 
1040698f87a4SGarrett D'Amore static int
pre_bk(DECL_ARGS)1041698f87a4SGarrett D'Amore pre_bk(DECL_ARGS)
1042698f87a4SGarrett D'Amore {
1043698f87a4SGarrett D'Amore 	switch (n->type) {
1044371584c2SYuri Pankov 	case ROFFT_BLOCK:
1045371584c2SYuri Pankov 		return 1;
1046371584c2SYuri Pankov 	case ROFFT_BODY:
1047c66b8046SYuri Pankov 	case ROFFT_ELEM:
1048698f87a4SGarrett D'Amore 		outflags |= MMAN_Bk;
1049371584c2SYuri Pankov 		return 1;
1050698f87a4SGarrett D'Amore 	default:
1051371584c2SYuri Pankov 		return 0;
1052698f87a4SGarrett D'Amore 	}
1053698f87a4SGarrett D'Amore }
1054698f87a4SGarrett D'Amore 
1055698f87a4SGarrett D'Amore static void
post_bk(DECL_ARGS)1056698f87a4SGarrett D'Amore post_bk(DECL_ARGS)
1057698f87a4SGarrett D'Amore {
1058c66b8046SYuri Pankov 	switch (n->type) {
1059c66b8046SYuri Pankov 	case ROFFT_ELEM:
1060c66b8046SYuri Pankov 		while ((n = n->parent) != NULL)
1061c66b8046SYuri Pankov 			 if (n->tok == MDOC_Bk)
1062c66b8046SYuri Pankov 				return;
1063c66b8046SYuri Pankov 		/* FALLTHROUGH */
1064c66b8046SYuri Pankov 	case ROFFT_BODY:
1065698f87a4SGarrett D'Amore 		outflags &= ~MMAN_Bk;
1066c66b8046SYuri Pankov 		break;
1067c66b8046SYuri Pankov 	default:
1068c66b8046SYuri Pankov 		break;
1069c66b8046SYuri Pankov 	}
1070698f87a4SGarrett D'Amore }
1071698f87a4SGarrett D'Amore 
1072698f87a4SGarrett D'Amore static int
pre_bl(DECL_ARGS)1073698f87a4SGarrett D'Amore pre_bl(DECL_ARGS)
1074698f87a4SGarrett D'Amore {
1075698f87a4SGarrett D'Amore 	size_t		 icol;
1076698f87a4SGarrett D'Amore 
1077698f87a4SGarrett D'Amore 	/*
1078698f87a4SGarrett D'Amore 	 * print_offs() will increase the -offset to account for
1079698f87a4SGarrett D'Amore 	 * a possible enclosing .It, but any enclosed .It blocks
1080698f87a4SGarrett D'Amore 	 * just nest and do not add up their indentation.
1081698f87a4SGarrett D'Amore 	 */
1082698f87a4SGarrett D'Amore 	if (n->norm->Bl.offs) {
1083260e9a87SYuri Pankov 		print_offs(n->norm->Bl.offs, 0);
1084698f87a4SGarrett D'Amore 		Bl_stack[Bl_stack_len++] = 0;
1085698f87a4SGarrett D'Amore 	}
1086698f87a4SGarrett D'Amore 
1087698f87a4SGarrett D'Amore 	switch (n->norm->Bl.type) {
1088260e9a87SYuri Pankov 	case LIST_enum:
1089698f87a4SGarrett D'Amore 		n->norm->Bl.count = 0;
1090371584c2SYuri Pankov 		return 1;
1091260e9a87SYuri Pankov 	case LIST_column:
1092698f87a4SGarrett D'Amore 		break;
1093698f87a4SGarrett D'Amore 	default:
1094371584c2SYuri Pankov 		return 1;
1095698f87a4SGarrett D'Amore 	}
1096698f87a4SGarrett D'Amore 
1097371584c2SYuri Pankov 	if (n->child != NULL) {
1098698f87a4SGarrett D'Amore 		print_line(".TS", MMAN_nl);
1099698f87a4SGarrett D'Amore 		for (icol = 0; icol < n->norm->Bl.ncols; icol++)
1100698f87a4SGarrett D'Amore 			print_word("l");
1101698f87a4SGarrett D'Amore 		print_word(".");
1102260e9a87SYuri Pankov 	}
1103698f87a4SGarrett D'Amore 	outflags |= MMAN_nl;
1104371584c2SYuri Pankov 	return 1;
1105698f87a4SGarrett D'Amore }
1106698f87a4SGarrett D'Amore 
1107698f87a4SGarrett D'Amore static void
post_bl(DECL_ARGS)1108698f87a4SGarrett D'Amore post_bl(DECL_ARGS)
1109698f87a4SGarrett D'Amore {
1110698f87a4SGarrett D'Amore 
1111698f87a4SGarrett D'Amore 	switch (n->norm->Bl.type) {
1112260e9a87SYuri Pankov 	case LIST_column:
1113371584c2SYuri Pankov 		if (n->child != NULL)
1114698f87a4SGarrett D'Amore 			print_line(".TE", 0);
1115698f87a4SGarrett D'Amore 		break;
1116260e9a87SYuri Pankov 	case LIST_enum:
1117698f87a4SGarrett D'Amore 		n->norm->Bl.count = 0;
1118698f87a4SGarrett D'Amore 		break;
1119698f87a4SGarrett D'Amore 	default:
1120698f87a4SGarrett D'Amore 		break;
1121698f87a4SGarrett D'Amore 	}
1122698f87a4SGarrett D'Amore 
1123698f87a4SGarrett D'Amore 	if (n->norm->Bl.offs) {
1124698f87a4SGarrett D'Amore 		print_line(".RE", MMAN_nl);
1125698f87a4SGarrett D'Amore 		assert(Bl_stack_len);
1126698f87a4SGarrett D'Amore 		Bl_stack_len--;
1127*4d131170SRobert Mustacchi 		assert(Bl_stack[Bl_stack_len] == 0);
1128698f87a4SGarrett D'Amore 	} else {
1129698f87a4SGarrett D'Amore 		outflags |= MMAN_PP | MMAN_nl;
1130698f87a4SGarrett D'Amore 		outflags &= ~(MMAN_sp | MMAN_br);
1131698f87a4SGarrett D'Amore 	}
1132698f87a4SGarrett D'Amore 
1133698f87a4SGarrett D'Amore 	/* Maybe we are inside an enclosing list? */
1134*4d131170SRobert Mustacchi 	if (roff_node_next(n->parent) != NULL)
1135698f87a4SGarrett D'Amore 		mid_it();
113695c635efSGarrett D'Amore }
113795c635efSGarrett D'Amore 
1138c66b8046SYuri Pankov static void
pre_br(DECL_ARGS)113995c635efSGarrett D'Amore pre_br(DECL_ARGS)
114095c635efSGarrett D'Amore {
1141698f87a4SGarrett D'Amore 	outflags |= MMAN_br;
114295c635efSGarrett D'Amore }
114395c635efSGarrett D'Amore 
114495c635efSGarrett D'Amore static int
pre_dl(DECL_ARGS)114595c635efSGarrett D'Amore pre_dl(DECL_ARGS)
114695c635efSGarrett D'Amore {
1147260e9a87SYuri Pankov 	print_offs("6n", 0);
1148371584c2SYuri Pankov 	return 1;
114995c635efSGarrett D'Amore }
115095c635efSGarrett D'Amore 
115195c635efSGarrett D'Amore static void
post_dl(DECL_ARGS)115295c635efSGarrett D'Amore post_dl(DECL_ARGS)
115395c635efSGarrett D'Amore {
1154698f87a4SGarrett D'Amore 	print_line(".RE", MMAN_nl);
1155698f87a4SGarrett D'Amore 
1156698f87a4SGarrett D'Amore 	/* Maybe we are inside an enclosing list? */
1157*4d131170SRobert Mustacchi 	if (roff_node_next(n->parent) != NULL)
1158698f87a4SGarrett D'Amore 		mid_it();
1159698f87a4SGarrett D'Amore }
1160698f87a4SGarrett D'Amore 
1161698f87a4SGarrett D'Amore static int
pre_em(DECL_ARGS)1162698f87a4SGarrett D'Amore pre_em(DECL_ARGS)
1163698f87a4SGarrett D'Amore {
1164698f87a4SGarrett D'Amore 
1165698f87a4SGarrett D'Amore 	font_push('I');
1166371584c2SYuri Pankov 	return 1;
1167698f87a4SGarrett D'Amore }
1168698f87a4SGarrett D'Amore 
1169260e9a87SYuri Pankov static int
pre_en(DECL_ARGS)1170260e9a87SYuri Pankov pre_en(DECL_ARGS)
1171260e9a87SYuri Pankov {
1172260e9a87SYuri Pankov 
1173260e9a87SYuri Pankov 	if (NULL == n->norm->Es ||
1174260e9a87SYuri Pankov 	    NULL == n->norm->Es->child)
1175371584c2SYuri Pankov 		return 1;
1176260e9a87SYuri Pankov 
1177260e9a87SYuri Pankov 	print_word(n->norm->Es->child->string);
1178260e9a87SYuri Pankov 	outflags &= ~MMAN_spc;
1179371584c2SYuri Pankov 	return 1;
1180260e9a87SYuri Pankov }
1181260e9a87SYuri Pankov 
1182260e9a87SYuri Pankov static void
post_en(DECL_ARGS)1183260e9a87SYuri Pankov post_en(DECL_ARGS)
1184260e9a87SYuri Pankov {
1185260e9a87SYuri Pankov 
1186260e9a87SYuri Pankov 	if (NULL == n->norm->Es ||
1187260e9a87SYuri Pankov 	    NULL == n->norm->Es->child ||
1188260e9a87SYuri Pankov 	    NULL == n->norm->Es->child->next)
1189260e9a87SYuri Pankov 		return;
1190260e9a87SYuri Pankov 
1191260e9a87SYuri Pankov 	outflags &= ~MMAN_spc;
1192260e9a87SYuri Pankov 	print_word(n->norm->Es->child->next->string);
1193260e9a87SYuri Pankov 	return;
1194260e9a87SYuri Pankov }
1195260e9a87SYuri Pankov 
1196260e9a87SYuri Pankov static int
pre_eo(DECL_ARGS)1197260e9a87SYuri Pankov pre_eo(DECL_ARGS)
1198260e9a87SYuri Pankov {
1199260e9a87SYuri Pankov 
1200260e9a87SYuri Pankov 	if (n->end == ENDBODY_NOT &&
1201260e9a87SYuri Pankov 	    n->parent->head->child == NULL &&
1202260e9a87SYuri Pankov 	    n->child != NULL &&
1203260e9a87SYuri Pankov 	    n->child->end != ENDBODY_NOT)
1204260e9a87SYuri Pankov 		print_word("\\&");
1205260e9a87SYuri Pankov 	else if (n->end != ENDBODY_NOT ? n->child != NULL :
1206260e9a87SYuri Pankov 	    n->parent->head->child != NULL && (n->child != NULL ||
1207260e9a87SYuri Pankov 	    (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1208260e9a87SYuri Pankov 		outflags &= ~(MMAN_spc | MMAN_nl);
1209371584c2SYuri Pankov 	return 1;
1210260e9a87SYuri Pankov }
1211260e9a87SYuri Pankov 
1212698f87a4SGarrett D'Amore static void
post_eo(DECL_ARGS)1213698f87a4SGarrett D'Amore post_eo(DECL_ARGS)
1214698f87a4SGarrett D'Amore {
1215260e9a87SYuri Pankov 	int	 body, tail;
1216698f87a4SGarrett D'Amore 
1217260e9a87SYuri Pankov 	if (n->end != ENDBODY_NOT) {
1218260e9a87SYuri Pankov 		outflags |= MMAN_spc;
1219260e9a87SYuri Pankov 		return;
1220260e9a87SYuri Pankov 	}
1221260e9a87SYuri Pankov 
1222260e9a87SYuri Pankov 	body = n->child != NULL || n->parent->head->child != NULL;
1223260e9a87SYuri Pankov 	tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
1224260e9a87SYuri Pankov 
1225260e9a87SYuri Pankov 	if (body && tail)
1226698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1227260e9a87SYuri Pankov 	else if ( ! (body || tail))
1228260e9a87SYuri Pankov 		print_word("\\&");
1229260e9a87SYuri Pankov 	else if ( ! tail)
1230260e9a87SYuri Pankov 		outflags |= MMAN_spc;
1231698f87a4SGarrett D'Amore }
1232698f87a4SGarrett D'Amore 
1233698f87a4SGarrett D'Amore static int
pre_fa(DECL_ARGS)1234698f87a4SGarrett D'Amore pre_fa(DECL_ARGS)
1235698f87a4SGarrett D'Amore {
1236698f87a4SGarrett D'Amore 	int	 am_Fa;
1237698f87a4SGarrett D'Amore 
1238698f87a4SGarrett D'Amore 	am_Fa = MDOC_Fa == n->tok;
1239698f87a4SGarrett D'Amore 
1240698f87a4SGarrett D'Amore 	if (am_Fa)
1241698f87a4SGarrett D'Amore 		n = n->child;
1242698f87a4SGarrett D'Amore 
1243698f87a4SGarrett D'Amore 	while (NULL != n) {
1244698f87a4SGarrett D'Amore 		font_push('I');
1245a40ea1a7SYuri Pankov 		if (am_Fa || NODE_SYNPRETTY & n->flags)
1246698f87a4SGarrett D'Amore 			outflags |= MMAN_nbrword;
1247698f87a4SGarrett D'Amore 		print_node(meta, n);
1248698f87a4SGarrett D'Amore 		font_pop();
1249698f87a4SGarrett D'Amore 		if (NULL != (n = n->next))
1250698f87a4SGarrett D'Amore 			print_word(",");
1251698f87a4SGarrett D'Amore 	}
1252371584c2SYuri Pankov 	return 0;
1253698f87a4SGarrett D'Amore }
1254698f87a4SGarrett D'Amore 
1255698f87a4SGarrett D'Amore static void
post_fa(DECL_ARGS)1256698f87a4SGarrett D'Amore post_fa(DECL_ARGS)
1257698f87a4SGarrett D'Amore {
1258*4d131170SRobert Mustacchi 	struct roff_node *nn;
1259698f87a4SGarrett D'Amore 
1260*4d131170SRobert Mustacchi 	if ((nn = roff_node_next(n)) != NULL && nn->tok == MDOC_Fa)
1261698f87a4SGarrett D'Amore 		print_word(",");
1262698f87a4SGarrett D'Amore }
1263698f87a4SGarrett D'Amore 
1264698f87a4SGarrett D'Amore static int
pre_fd(DECL_ARGS)1265698f87a4SGarrett D'Amore pre_fd(DECL_ARGS)
1266698f87a4SGarrett D'Amore {
1267698f87a4SGarrett D'Amore 	pre_syn(n);
1268698f87a4SGarrett D'Amore 	font_push('B');
1269371584c2SYuri Pankov 	return 1;
1270698f87a4SGarrett D'Amore }
1271698f87a4SGarrett D'Amore 
1272698f87a4SGarrett D'Amore static void
post_fd(DECL_ARGS)1273698f87a4SGarrett D'Amore post_fd(DECL_ARGS)
1274698f87a4SGarrett D'Amore {
1275698f87a4SGarrett D'Amore 	font_pop();
1276698f87a4SGarrett D'Amore 	outflags |= MMAN_br;
1277698f87a4SGarrett D'Amore }
1278698f87a4SGarrett D'Amore 
1279698f87a4SGarrett D'Amore static int
pre_fl(DECL_ARGS)1280698f87a4SGarrett D'Amore pre_fl(DECL_ARGS)
1281698f87a4SGarrett D'Amore {
1282698f87a4SGarrett D'Amore 	font_push('B');
1283698f87a4SGarrett D'Amore 	print_word("\\-");
1284371584c2SYuri Pankov 	if (n->child != NULL)
1285698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1286371584c2SYuri Pankov 	return 1;
1287698f87a4SGarrett D'Amore }
1288698f87a4SGarrett D'Amore 
1289698f87a4SGarrett D'Amore static void
post_fl(DECL_ARGS)1290698f87a4SGarrett D'Amore post_fl(DECL_ARGS)
1291698f87a4SGarrett D'Amore {
1292*4d131170SRobert Mustacchi 	struct roff_node *nn;
1293698f87a4SGarrett D'Amore 
1294698f87a4SGarrett D'Amore 	font_pop();
1295*4d131170SRobert Mustacchi 	if (n->child == NULL &&
1296*4d131170SRobert Mustacchi 	    ((nn = roff_node_next(n)) != NULL &&
1297*4d131170SRobert Mustacchi 	    nn->type != ROFFT_TEXT &&
1298*4d131170SRobert Mustacchi 	    (nn->flags & NODE_LINE) == 0))
1299698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1300698f87a4SGarrett D'Amore }
1301698f87a4SGarrett D'Amore 
1302698f87a4SGarrett D'Amore static int
pre_fn(DECL_ARGS)1303698f87a4SGarrett D'Amore pre_fn(DECL_ARGS)
1304698f87a4SGarrett D'Amore {
1305698f87a4SGarrett D'Amore 
1306698f87a4SGarrett D'Amore 	pre_syn(n);
1307698f87a4SGarrett D'Amore 
1308698f87a4SGarrett D'Amore 	n = n->child;
1309698f87a4SGarrett D'Amore 	if (NULL == n)
1310371584c2SYuri Pankov 		return 0;
1311698f87a4SGarrett D'Amore 
1312a40ea1a7SYuri Pankov 	if (NODE_SYNPRETTY & n->flags)
1313698f87a4SGarrett D'Amore 		print_block(".HP 4n", MMAN_nl);
1314698f87a4SGarrett D'Amore 
1315698f87a4SGarrett D'Amore 	font_push('B');
1316698f87a4SGarrett D'Amore 	print_node(meta, n);
1317698f87a4SGarrett D'Amore 	font_pop();
1318698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
1319698f87a4SGarrett D'Amore 	print_word("(");
1320698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
1321698f87a4SGarrett D'Amore 
1322698f87a4SGarrett D'Amore 	n = n->next;
1323698f87a4SGarrett D'Amore 	if (NULL != n)
1324698f87a4SGarrett D'Amore 		pre_fa(meta, n);
1325371584c2SYuri Pankov 	return 0;
1326698f87a4SGarrett D'Amore }
1327698f87a4SGarrett D'Amore 
1328698f87a4SGarrett D'Amore static void
post_fn(DECL_ARGS)1329698f87a4SGarrett D'Amore post_fn(DECL_ARGS)
1330698f87a4SGarrett D'Amore {
1331698f87a4SGarrett D'Amore 
1332698f87a4SGarrett D'Amore 	print_word(")");
1333a40ea1a7SYuri Pankov 	if (NODE_SYNPRETTY & n->flags) {
1334698f87a4SGarrett D'Amore 		print_word(";");
1335698f87a4SGarrett D'Amore 		outflags |= MMAN_PP;
1336698f87a4SGarrett D'Amore 	}
1337698f87a4SGarrett D'Amore }
1338698f87a4SGarrett D'Amore 
1339698f87a4SGarrett D'Amore static int
pre_fo(DECL_ARGS)1340698f87a4SGarrett D'Amore pre_fo(DECL_ARGS)
1341698f87a4SGarrett D'Amore {
1342698f87a4SGarrett D'Amore 
1343698f87a4SGarrett D'Amore 	switch (n->type) {
1344371584c2SYuri Pankov 	case ROFFT_BLOCK:
1345698f87a4SGarrett D'Amore 		pre_syn(n);
1346698f87a4SGarrett D'Amore 		break;
1347371584c2SYuri Pankov 	case ROFFT_HEAD:
1348260e9a87SYuri Pankov 		if (n->child == NULL)
1349371584c2SYuri Pankov 			return 0;
1350a40ea1a7SYuri Pankov 		if (NODE_SYNPRETTY & n->flags)
1351698f87a4SGarrett D'Amore 			print_block(".HP 4n", MMAN_nl);
1352698f87a4SGarrett D'Amore 		font_push('B');
1353698f87a4SGarrett D'Amore 		break;
1354371584c2SYuri Pankov 	case ROFFT_BODY:
1355260e9a87SYuri Pankov 		outflags &= ~(MMAN_spc | MMAN_nl);
1356698f87a4SGarrett D'Amore 		print_word("(");
1357698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1358698f87a4SGarrett D'Amore 		break;
1359698f87a4SGarrett D'Amore 	default:
1360698f87a4SGarrett D'Amore 		break;
1361698f87a4SGarrett D'Amore 	}
1362371584c2SYuri Pankov 	return 1;
1363698f87a4SGarrett D'Amore }
1364698f87a4SGarrett D'Amore 
1365698f87a4SGarrett D'Amore static void
post_fo(DECL_ARGS)1366698f87a4SGarrett D'Amore post_fo(DECL_ARGS)
1367698f87a4SGarrett D'Amore {
1368698f87a4SGarrett D'Amore 
1369698f87a4SGarrett D'Amore 	switch (n->type) {
1370371584c2SYuri Pankov 	case ROFFT_HEAD:
1371260e9a87SYuri Pankov 		if (n->child != NULL)
1372698f87a4SGarrett D'Amore 			font_pop();
1373698f87a4SGarrett D'Amore 		break;
1374371584c2SYuri Pankov 	case ROFFT_BODY:
1375698f87a4SGarrett D'Amore 		post_fn(meta, n);
1376698f87a4SGarrett D'Amore 		break;
1377698f87a4SGarrett D'Amore 	default:
1378698f87a4SGarrett D'Amore 		break;
1379698f87a4SGarrett D'Amore 	}
1380698f87a4SGarrett D'Amore }
1381698f87a4SGarrett D'Amore 
1382698f87a4SGarrett D'Amore static int
pre_Ft(DECL_ARGS)1383c66b8046SYuri Pankov pre_Ft(DECL_ARGS)
1384698f87a4SGarrett D'Amore {
1385698f87a4SGarrett D'Amore 
1386698f87a4SGarrett D'Amore 	pre_syn(n);
1387698f87a4SGarrett D'Amore 	font_push('I');
1388371584c2SYuri Pankov 	return 1;
1389698f87a4SGarrett D'Amore }
1390698f87a4SGarrett D'Amore 
1391c66b8046SYuri Pankov static void
pre_ft(DECL_ARGS)1392c66b8046SYuri Pankov pre_ft(DECL_ARGS)
1393c66b8046SYuri Pankov {
1394c66b8046SYuri Pankov 	print_line(".ft", 0);
1395c66b8046SYuri Pankov 	print_word(n->child->string);
1396c66b8046SYuri Pankov 	outflags |= MMAN_nl;
1397c66b8046SYuri Pankov }
1398c66b8046SYuri Pankov 
1399698f87a4SGarrett D'Amore static int
pre_in(DECL_ARGS)1400698f87a4SGarrett D'Amore pre_in(DECL_ARGS)
1401698f87a4SGarrett D'Amore {
1402698f87a4SGarrett D'Amore 
1403a40ea1a7SYuri Pankov 	if (NODE_SYNPRETTY & n->flags) {
1404698f87a4SGarrett D'Amore 		pre_syn(n);
1405698f87a4SGarrett D'Amore 		font_push('B');
1406698f87a4SGarrett D'Amore 		print_word("#include <");
1407698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1408698f87a4SGarrett D'Amore 	} else {
1409698f87a4SGarrett D'Amore 		print_word("<");
1410698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1411698f87a4SGarrett D'Amore 		font_push('I');
1412698f87a4SGarrett D'Amore 	}
1413371584c2SYuri Pankov 	return 1;
1414698f87a4SGarrett D'Amore }
1415698f87a4SGarrett D'Amore 
1416698f87a4SGarrett D'Amore static void
post_in(DECL_ARGS)1417698f87a4SGarrett D'Amore post_in(DECL_ARGS)
1418698f87a4SGarrett D'Amore {
1419698f87a4SGarrett D'Amore 
1420a40ea1a7SYuri Pankov 	if (NODE_SYNPRETTY & n->flags) {
1421698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1422698f87a4SGarrett D'Amore 		print_word(">");
1423698f87a4SGarrett D'Amore 		font_pop();
1424698f87a4SGarrett D'Amore 		outflags |= MMAN_br;
1425698f87a4SGarrett D'Amore 	} else {
1426698f87a4SGarrett D'Amore 		font_pop();
1427698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
1428698f87a4SGarrett D'Amore 		print_word(">");
1429698f87a4SGarrett D'Amore 	}
143095c635efSGarrett D'Amore }
143195c635efSGarrett D'Amore 
143295c635efSGarrett D'Amore static int
pre_it(DECL_ARGS)143395c635efSGarrett D'Amore pre_it(DECL_ARGS)
143495c635efSGarrett D'Amore {
1435371584c2SYuri Pankov 	const struct roff_node *bln;
143695c635efSGarrett D'Amore 
1437698f87a4SGarrett D'Amore 	switch (n->type) {
1438371584c2SYuri Pankov 	case ROFFT_HEAD:
1439698f87a4SGarrett D'Amore 		outflags |= MMAN_PP | MMAN_nl;
1440698f87a4SGarrett D'Amore 		bln = n->parent->parent;
1441*4d131170SRobert Mustacchi 		if (bln->norm->Bl.comp == 0 ||
1442*4d131170SRobert Mustacchi 		    (n->parent->prev == NULL &&
1443*4d131170SRobert Mustacchi 		     roff_node_prev(bln->parent) == NULL))
1444698f87a4SGarrett D'Amore 			outflags |= MMAN_sp;
1445698f87a4SGarrett D'Amore 		outflags &= ~MMAN_br;
144695c635efSGarrett D'Amore 		switch (bln->norm->Bl.type) {
1447260e9a87SYuri Pankov 		case LIST_item:
1448371584c2SYuri Pankov 			return 0;
1449260e9a87SYuri Pankov 		case LIST_inset:
1450260e9a87SYuri Pankov 		case LIST_diag:
1451260e9a87SYuri Pankov 		case LIST_ohang:
1452698f87a4SGarrett D'Amore 			if (bln->norm->Bl.type == LIST_diag)
1453698f87a4SGarrett D'Amore 				print_line(".B \"", 0);
1454698f87a4SGarrett D'Amore 			else
14556640c13bSYuri Pankov 				print_line(".BR \\& \"", 0);
1456698f87a4SGarrett D'Amore 			outflags &= ~MMAN_spc;
1457371584c2SYuri Pankov 			return 1;
1458260e9a87SYuri Pankov 		case LIST_bullet:
1459260e9a87SYuri Pankov 		case LIST_dash:
1460260e9a87SYuri Pankov 		case LIST_hyphen:
1461260e9a87SYuri Pankov 			print_width(&bln->norm->Bl, NULL);
1462698f87a4SGarrett D'Amore 			TPremain = 0;
1463698f87a4SGarrett D'Amore 			outflags |= MMAN_nl;
1464698f87a4SGarrett D'Amore 			font_push('B');
1465698f87a4SGarrett D'Amore 			if (LIST_bullet == bln->norm->Bl.type)
1466260e9a87SYuri Pankov 				print_word("\\(bu");
1467698f87a4SGarrett D'Amore 			else
1468698f87a4SGarrett D'Amore 				print_word("-");
1469698f87a4SGarrett D'Amore 			font_pop();
1470260e9a87SYuri Pankov 			outflags |= MMAN_nl;
1471371584c2SYuri Pankov 			return 0;
1472260e9a87SYuri Pankov 		case LIST_enum:
1473260e9a87SYuri Pankov 			print_width(&bln->norm->Bl, NULL);
1474698f87a4SGarrett D'Amore 			TPremain = 0;
1475698f87a4SGarrett D'Amore 			outflags |= MMAN_nl;
1476698f87a4SGarrett D'Amore 			print_count(&bln->norm->Bl.count);
1477260e9a87SYuri Pankov 			outflags |= MMAN_nl;
1478371584c2SYuri Pankov 			return 0;
1479260e9a87SYuri Pankov 		case LIST_hang:
1480260e9a87SYuri Pankov 			print_width(&bln->norm->Bl, n->child);
1481698f87a4SGarrett D'Amore 			TPremain = 0;
1482260e9a87SYuri Pankov 			outflags |= MMAN_nl;
1483371584c2SYuri Pankov 			return 1;
1484260e9a87SYuri Pankov 		case LIST_tag:
1485260e9a87SYuri Pankov 			print_width(&bln->norm->Bl, n->child);
1486698f87a4SGarrett D'Amore 			putchar('\n');
1487698f87a4SGarrett D'Amore 			outflags &= ~MMAN_spc;
1488371584c2SYuri Pankov 			return 1;
1489698f87a4SGarrett D'Amore 		default:
1490371584c2SYuri Pankov 			return 1;
1491698f87a4SGarrett D'Amore 		}
1492698f87a4SGarrett D'Amore 	default:
1493698f87a4SGarrett D'Amore 		break;
1494698f87a4SGarrett D'Amore 	}
1495371584c2SYuri Pankov 	return 1;
1496698f87a4SGarrett D'Amore }
1497698f87a4SGarrett D'Amore 
1498698f87a4SGarrett D'Amore /*
1499698f87a4SGarrett D'Amore  * This function is called after closing out an indented block.
1500698f87a4SGarrett D'Amore  * If we are inside an enclosing list, restore its indentation.
1501698f87a4SGarrett D'Amore  */
1502698f87a4SGarrett D'Amore static void
mid_it(void)1503698f87a4SGarrett D'Amore mid_it(void)
1504698f87a4SGarrett D'Amore {
1505698f87a4SGarrett D'Amore 	char		 buf[24];
1506698f87a4SGarrett D'Amore 
1507698f87a4SGarrett D'Amore 	/* Nothing to do outside a list. */
1508698f87a4SGarrett D'Amore 	if (0 == Bl_stack_len || 0 == Bl_stack[Bl_stack_len - 1])
1509698f87a4SGarrett D'Amore 		return;
1510698f87a4SGarrett D'Amore 
1511698f87a4SGarrett D'Amore 	/* The indentation has already been set up. */
1512698f87a4SGarrett D'Amore 	if (Bl_stack_post[Bl_stack_len - 1])
1513698f87a4SGarrett D'Amore 		return;
1514698f87a4SGarrett D'Amore 
1515698f87a4SGarrett D'Amore 	/* Restore the indentation of the enclosing list. */
1516698f87a4SGarrett D'Amore 	print_line(".RS", MMAN_Bk_susp);
1517260e9a87SYuri Pankov 	(void)snprintf(buf, sizeof(buf), "%dn",
1518260e9a87SYuri Pankov 	    Bl_stack[Bl_stack_len - 1]);
1519698f87a4SGarrett D'Amore 	print_word(buf);
1520698f87a4SGarrett D'Amore 
1521698f87a4SGarrett D'Amore 	/* Remeber to close out this .RS block later. */
1522698f87a4SGarrett D'Amore 	Bl_stack_post[Bl_stack_len - 1] = 1;
1523698f87a4SGarrett D'Amore }
1524698f87a4SGarrett D'Amore 
1525698f87a4SGarrett D'Amore static void
post_it(DECL_ARGS)1526698f87a4SGarrett D'Amore post_it(DECL_ARGS)
1527698f87a4SGarrett D'Amore {
1528371584c2SYuri Pankov 	const struct roff_node *bln;
1529698f87a4SGarrett D'Amore 
1530698f87a4SGarrett D'Amore 	bln = n->parent->parent;
1531698f87a4SGarrett D'Amore 
1532698f87a4SGarrett D'Amore 	switch (n->type) {
1533371584c2SYuri Pankov 	case ROFFT_HEAD:
1534698f87a4SGarrett D'Amore 		switch (bln->norm->Bl.type) {
1535260e9a87SYuri Pankov 		case LIST_diag:
1536698f87a4SGarrett D'Amore 			outflags &= ~MMAN_spc;
1537698f87a4SGarrett D'Amore 			print_word("\\ ");
1538698f87a4SGarrett D'Amore 			break;
1539260e9a87SYuri Pankov 		case LIST_ohang:
1540698f87a4SGarrett D'Amore 			outflags |= MMAN_br;
154195c635efSGarrett D'Amore 			break;
154295c635efSGarrett D'Amore 		default:
154395c635efSGarrett D'Amore 			break;
154495c635efSGarrett D'Amore 		}
1545698f87a4SGarrett D'Amore 		break;
1546371584c2SYuri Pankov 	case ROFFT_BODY:
1547698f87a4SGarrett D'Amore 		switch (bln->norm->Bl.type) {
1548260e9a87SYuri Pankov 		case LIST_bullet:
1549260e9a87SYuri Pankov 		case LIST_dash:
1550260e9a87SYuri Pankov 		case LIST_hyphen:
1551260e9a87SYuri Pankov 		case LIST_enum:
1552260e9a87SYuri Pankov 		case LIST_hang:
1553260e9a87SYuri Pankov 		case LIST_tag:
1554698f87a4SGarrett D'Amore 			assert(Bl_stack_len);
1555698f87a4SGarrett D'Amore 			Bl_stack[--Bl_stack_len] = 0;
1556698f87a4SGarrett D'Amore 
1557698f87a4SGarrett D'Amore 			/*
1558698f87a4SGarrett D'Amore 			 * Our indentation had to be restored
1559698f87a4SGarrett D'Amore 			 * after a child display or child list.
1560698f87a4SGarrett D'Amore 			 * Close out that indentation block now.
1561698f87a4SGarrett D'Amore 			 */
1562698f87a4SGarrett D'Amore 			if (Bl_stack_post[Bl_stack_len]) {
1563698f87a4SGarrett D'Amore 				print_line(".RE", MMAN_nl);
1564698f87a4SGarrett D'Amore 				Bl_stack_post[Bl_stack_len] = 0;
156595c635efSGarrett D'Amore 			}
1566698f87a4SGarrett D'Amore 			break;
1567260e9a87SYuri Pankov 		case LIST_column:
1568698f87a4SGarrett D'Amore 			if (NULL != n->next) {
1569698f87a4SGarrett D'Amore 				putchar('\t');
1570698f87a4SGarrett D'Amore 				outflags &= ~MMAN_spc;
1571698f87a4SGarrett D'Amore 			}
1572698f87a4SGarrett D'Amore 			break;
1573698f87a4SGarrett D'Amore 		default:
1574698f87a4SGarrett D'Amore 			break;
1575698f87a4SGarrett D'Amore 		}
1576698f87a4SGarrett D'Amore 		break;
1577698f87a4SGarrett D'Amore 	default:
1578698f87a4SGarrett D'Amore 		break;
1579698f87a4SGarrett D'Amore 	}
1580698f87a4SGarrett D'Amore }
1581698f87a4SGarrett D'Amore 
1582698f87a4SGarrett D'Amore static void
post_lb(DECL_ARGS)1583698f87a4SGarrett D'Amore post_lb(DECL_ARGS)
1584698f87a4SGarrett D'Amore {
1585698f87a4SGarrett D'Amore 
1586698f87a4SGarrett D'Amore 	if (SEC_LIBRARY == n->sec)
1587698f87a4SGarrett D'Amore 		outflags |= MMAN_br;
1588698f87a4SGarrett D'Amore }
1589698f87a4SGarrett D'Amore 
1590698f87a4SGarrett D'Amore static int
pre_lk(DECL_ARGS)1591698f87a4SGarrett D'Amore pre_lk(DECL_ARGS)
1592698f87a4SGarrett D'Amore {
1593c66b8046SYuri Pankov 	const struct roff_node *link, *descr, *punct;
1594698f87a4SGarrett D'Amore 
1595c66b8046SYuri Pankov 	if ((link = n->child) == NULL)
1596371584c2SYuri Pankov 		return 0;
1597698f87a4SGarrett D'Amore 
1598c66b8046SYuri Pankov 	/* Find beginning of trailing punctuation. */
1599c66b8046SYuri Pankov 	punct = n->last;
1600c66b8046SYuri Pankov 	while (punct != link && punct->flags & NODE_DELIMC)
1601c66b8046SYuri Pankov 		punct = punct->prev;
1602c66b8046SYuri Pankov 	punct = punct->next;
1603c66b8046SYuri Pankov 
1604c66b8046SYuri Pankov 	/* Link text. */
1605c66b8046SYuri Pankov 	if ((descr = link->next) != NULL && descr != punct) {
1606698f87a4SGarrett D'Amore 		font_push('I');
1607c66b8046SYuri Pankov 		while (descr != punct) {
1608698f87a4SGarrett D'Amore 			print_word(descr->string);
1609698f87a4SGarrett D'Amore 			descr = descr->next;
1610698f87a4SGarrett D'Amore 		}
1611698f87a4SGarrett D'Amore 		font_pop();
1612c66b8046SYuri Pankov 		print_word(":");
1613698f87a4SGarrett D'Amore 	}
1614698f87a4SGarrett D'Amore 
1615c66b8046SYuri Pankov 	/* Link target. */
1616698f87a4SGarrett D'Amore 	font_push('B');
1617698f87a4SGarrett D'Amore 	print_word(link->string);
1618698f87a4SGarrett D'Amore 	font_pop();
1619c66b8046SYuri Pankov 
1620c66b8046SYuri Pankov 	/* Trailing punctuation. */
1621c66b8046SYuri Pankov 	while (punct != NULL) {
1622c66b8046SYuri Pankov 		print_word(punct->string);
1623c66b8046SYuri Pankov 		punct = punct->next;
1624c66b8046SYuri Pankov 	}
1625371584c2SYuri Pankov 	return 0;
1626698f87a4SGarrett D'Amore }
1627698f87a4SGarrett D'Amore 
1628c66b8046SYuri Pankov static void
pre_onearg(DECL_ARGS)1629c66b8046SYuri Pankov pre_onearg(DECL_ARGS)
1630260e9a87SYuri Pankov {
1631c66b8046SYuri Pankov 	outflags |= MMAN_nl;
1632c66b8046SYuri Pankov 	print_word(".");
1633c66b8046SYuri Pankov 	outflags &= ~MMAN_spc;
1634c66b8046SYuri Pankov 	print_word(roff_name[n->tok]);
1635c66b8046SYuri Pankov 	if (n->child != NULL)
1636c66b8046SYuri Pankov 		print_word(n->child->string);
1637c66b8046SYuri Pankov 	outflags |= MMAN_nl;
1638c66b8046SYuri Pankov 	if (n->tok == ROFF_ce)
1639c66b8046SYuri Pankov 		for (n = n->child->next; n != NULL; n = n->next)
1640c66b8046SYuri Pankov 			print_node(meta, n);
1641260e9a87SYuri Pankov }
1642260e9a87SYuri Pankov 
1643260e9a87SYuri Pankov static int
pre_li(DECL_ARGS)1644698f87a4SGarrett D'Amore pre_li(DECL_ARGS)
1645698f87a4SGarrett D'Amore {
1646698f87a4SGarrett D'Amore 	font_push('R');
1647371584c2SYuri Pankov 	return 1;
164895c635efSGarrett D'Amore }
164995c635efSGarrett D'Amore 
165095c635efSGarrett D'Amore static int
pre_nm(DECL_ARGS)165195c635efSGarrett D'Amore pre_nm(DECL_ARGS)
165295c635efSGarrett D'Amore {
1653698f87a4SGarrett D'Amore 	char	*name;
165495c635efSGarrett D'Amore 
1655*4d131170SRobert Mustacchi 	switch (n->type) {
1656*4d131170SRobert Mustacchi 	case ROFFT_BLOCK:
1657698f87a4SGarrett D'Amore 		outflags |= MMAN_Bk;
1658698f87a4SGarrett D'Amore 		pre_syn(n);
1659371584c2SYuri Pankov 		return 1;
1660*4d131170SRobert Mustacchi 	case ROFFT_HEAD:
1661*4d131170SRobert Mustacchi 	case ROFFT_ELEM:
1662*4d131170SRobert Mustacchi 		break;
1663*4d131170SRobert Mustacchi 	default:
1664*4d131170SRobert Mustacchi 		return 1;
1665*4d131170SRobert Mustacchi 	}
1666a40ea1a7SYuri Pankov 	name = n->child == NULL ? NULL : n->child->string;
1667*4d131170SRobert Mustacchi 	if (name == NULL)
1668371584c2SYuri Pankov 		return 0;
1669371584c2SYuri Pankov 	if (n->type == ROFFT_HEAD) {
1670*4d131170SRobert Mustacchi 		if (roff_node_prev(n->parent) == NULL)
1671698f87a4SGarrett D'Amore 			outflags |= MMAN_sp;
1672698f87a4SGarrett D'Amore 		print_block(".HP", 0);
1673c66b8046SYuri Pankov 		printf(" %dn", man_strlen(name) + 1);
1674698f87a4SGarrett D'Amore 		outflags |= MMAN_nl;
1675698f87a4SGarrett D'Amore 	}
1676698f87a4SGarrett D'Amore 	font_push('B');
1677371584c2SYuri Pankov 	return 1;
167895c635efSGarrett D'Amore }
167995c635efSGarrett D'Amore 
168095c635efSGarrett D'Amore static void
post_nm(DECL_ARGS)168195c635efSGarrett D'Amore post_nm(DECL_ARGS)
168295c635efSGarrett D'Amore {
1683698f87a4SGarrett D'Amore 	switch (n->type) {
1684371584c2SYuri Pankov 	case ROFFT_BLOCK:
1685698f87a4SGarrett D'Amore 		outflags &= ~MMAN_Bk;
1686698f87a4SGarrett D'Amore 		break;
1687371584c2SYuri Pankov 	case ROFFT_HEAD:
1688371584c2SYuri Pankov 	case ROFFT_ELEM:
1689a40ea1a7SYuri Pankov 		if (n->child != NULL && n->child->string != NULL)
1690698f87a4SGarrett D'Amore 			font_pop();
1691698f87a4SGarrett D'Amore 		break;
1692698f87a4SGarrett D'Amore 	default:
1693698f87a4SGarrett D'Amore 		break;
1694698f87a4SGarrett D'Amore 	}
1695698f87a4SGarrett D'Amore }
1696698f87a4SGarrett D'Amore 
1697698f87a4SGarrett D'Amore static int
pre_no(DECL_ARGS)1698698f87a4SGarrett D'Amore pre_no(DECL_ARGS)
1699698f87a4SGarrett D'Amore {
1700698f87a4SGarrett D'Amore 	outflags |= MMAN_spc_force;
1701371584c2SYuri Pankov 	return 1;
170295c635efSGarrett D'Amore }
170395c635efSGarrett D'Amore 
1704cec8643bSMichal Nowak static void
pre_noarg(DECL_ARGS)1705cec8643bSMichal Nowak pre_noarg(DECL_ARGS)
1706cec8643bSMichal Nowak {
1707cec8643bSMichal Nowak 	outflags |= MMAN_nl;
1708cec8643bSMichal Nowak 	print_word(".");
1709cec8643bSMichal Nowak 	outflags &= ~MMAN_spc;
1710cec8643bSMichal Nowak 	print_word(roff_name[n->tok]);
1711cec8643bSMichal Nowak 	outflags |= MMAN_nl;
1712cec8643bSMichal Nowak }
1713cec8643bSMichal Nowak 
171495c635efSGarrett D'Amore static int
pre_ns(DECL_ARGS)171595c635efSGarrett D'Amore pre_ns(DECL_ARGS)
171695c635efSGarrett D'Amore {
1717698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
1718371584c2SYuri Pankov 	return 0;
171995c635efSGarrett D'Amore }
172095c635efSGarrett D'Amore 
172195c635efSGarrett D'Amore static void
post_pf(DECL_ARGS)172295c635efSGarrett D'Amore post_pf(DECL_ARGS)
172395c635efSGarrett D'Amore {
172495c635efSGarrett D'Amore 
1725a40ea1a7SYuri Pankov 	if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1726698f87a4SGarrett D'Amore 		outflags &= ~MMAN_spc;
172795c635efSGarrett D'Amore }
172895c635efSGarrett D'Amore 
172995c635efSGarrett D'Amore static int
pre_pp(DECL_ARGS)173095c635efSGarrett D'Amore pre_pp(DECL_ARGS)
173195c635efSGarrett D'Amore {
173295c635efSGarrett D'Amore 
1733698f87a4SGarrett D'Amore 	if (MDOC_It != n->parent->tok)
1734698f87a4SGarrett D'Amore 		outflags |= MMAN_PP;
1735698f87a4SGarrett D'Amore 	outflags |= MMAN_sp | MMAN_nl;
1736698f87a4SGarrett D'Amore 	outflags &= ~MMAN_br;
1737371584c2SYuri Pankov 	return 0;
1738698f87a4SGarrett D'Amore }
1739698f87a4SGarrett D'Amore 
1740698f87a4SGarrett D'Amore static int
pre_rs(DECL_ARGS)1741698f87a4SGarrett D'Amore pre_rs(DECL_ARGS)
1742698f87a4SGarrett D'Amore {
1743698f87a4SGarrett D'Amore 
1744698f87a4SGarrett D'Amore 	if (SEC_SEE_ALSO == n->sec) {
1745698f87a4SGarrett D'Amore 		outflags |= MMAN_PP | MMAN_sp | MMAN_nl;
1746698f87a4SGarrett D'Amore 		outflags &= ~MMAN_br;
1747698f87a4SGarrett D'Amore 	}
1748371584c2SYuri Pankov 	return 1;
174995c635efSGarrett D'Amore }
175095c635efSGarrett D'Amore 
175195c635efSGarrett D'Amore static int
pre_skip(DECL_ARGS)1752260e9a87SYuri Pankov pre_skip(DECL_ARGS)
1753260e9a87SYuri Pankov {
1754260e9a87SYuri Pankov 
1755371584c2SYuri Pankov 	return 0;
1756260e9a87SYuri Pankov }
1757260e9a87SYuri Pankov 
1758260e9a87SYuri Pankov static int
pre_sm(DECL_ARGS)1759698f87a4SGarrett D'Amore pre_sm(DECL_ARGS)
1760698f87a4SGarrett D'Amore {
1761698f87a4SGarrett D'Amore 
1762260e9a87SYuri Pankov 	if (NULL == n->child)
1763260e9a87SYuri Pankov 		outflags ^= MMAN_Sm;
1764260e9a87SYuri Pankov 	else if (0 == strcmp("on", n->child->string))
1765260e9a87SYuri Pankov 		outflags |= MMAN_Sm;
1766698f87a4SGarrett D'Amore 	else
1767698f87a4SGarrett D'Amore 		outflags &= ~MMAN_Sm;
1768260e9a87SYuri Pankov 
1769260e9a87SYuri Pankov 	if (MMAN_Sm & outflags)
1770260e9a87SYuri Pankov 		outflags |= MMAN_spc;
1771260e9a87SYuri Pankov 
1772371584c2SYuri Pankov 	return 0;
1773698f87a4SGarrett D'Amore }
1774698f87a4SGarrett D'Amore 
1775c66b8046SYuri Pankov static void
pre_sp(DECL_ARGS)177695c635efSGarrett D'Amore pre_sp(DECL_ARGS)
177795c635efSGarrett D'Amore {
1778c66b8046SYuri Pankov 	if (outflags & MMAN_PP) {
1779698f87a4SGarrett D'Amore 		outflags &= ~MMAN_PP;
1780698f87a4SGarrett D'Amore 		print_line(".PP", 0);
1781c66b8046SYuri Pankov 	} else {
1782698f87a4SGarrett D'Amore 		print_line(".sp", 0);
1783c66b8046SYuri Pankov 		if (n->child != NULL)
1784c66b8046SYuri Pankov 			print_word(n->child->string);
178595c635efSGarrett D'Amore 	}
1786698f87a4SGarrett D'Amore 	outflags |= MMAN_nl;
1787698f87a4SGarrett D'Amore }
1788698f87a4SGarrett D'Amore 
1789698f87a4SGarrett D'Amore static int
pre_sy(DECL_ARGS)1790698f87a4SGarrett D'Amore pre_sy(DECL_ARGS)
1791698f87a4SGarrett D'Amore {
1792698f87a4SGarrett D'Amore 
1793698f87a4SGarrett D'Amore 	font_push('B');
1794371584c2SYuri Pankov 	return 1;
1795698f87a4SGarrett D'Amore }
1796698f87a4SGarrett D'Amore 
1797c66b8046SYuri Pankov static void
pre_ta(DECL_ARGS)1798c66b8046SYuri Pankov pre_ta(DECL_ARGS)
1799c66b8046SYuri Pankov {
1800c66b8046SYuri Pankov 	print_line(".ta", 0);
1801c66b8046SYuri Pankov 	for (n = n->child; n != NULL; n = n->next)
1802c66b8046SYuri Pankov 		print_word(n->string);
1803c66b8046SYuri Pankov 	outflags |= MMAN_nl;
1804c66b8046SYuri Pankov }
1805c66b8046SYuri Pankov 
1806698f87a4SGarrett D'Amore static int
pre_vt(DECL_ARGS)1807698f87a4SGarrett D'Amore pre_vt(DECL_ARGS)
1808698f87a4SGarrett D'Amore {
1809698f87a4SGarrett D'Amore 
1810a40ea1a7SYuri Pankov 	if (NODE_SYNPRETTY & n->flags) {
1811698f87a4SGarrett D'Amore 		switch (n->type) {
1812371584c2SYuri Pankov 		case ROFFT_BLOCK:
1813698f87a4SGarrett D'Amore 			pre_syn(n);
1814371584c2SYuri Pankov 			return 1;
1815371584c2SYuri Pankov 		case ROFFT_BODY:
1816698f87a4SGarrett D'Amore 			break;
1817698f87a4SGarrett D'Amore 		default:
1818371584c2SYuri Pankov 			return 0;
1819698f87a4SGarrett D'Amore 		}
1820698f87a4SGarrett D'Amore 	}
1821698f87a4SGarrett D'Amore 	font_push('I');
1822371584c2SYuri Pankov 	return 1;
1823698f87a4SGarrett D'Amore }
1824698f87a4SGarrett D'Amore 
1825698f87a4SGarrett D'Amore static void
post_vt(DECL_ARGS)1826698f87a4SGarrett D'Amore post_vt(DECL_ARGS)
1827698f87a4SGarrett D'Amore {
1828698f87a4SGarrett D'Amore 
1829a40ea1a7SYuri Pankov 	if (n->flags & NODE_SYNPRETTY && n->type != ROFFT_BODY)
1830698f87a4SGarrett D'Amore 		return;
1831698f87a4SGarrett D'Amore 	font_pop();
183295c635efSGarrett D'Amore }
183395c635efSGarrett D'Amore 
183495c635efSGarrett D'Amore static int
pre_xr(DECL_ARGS)183595c635efSGarrett D'Amore pre_xr(DECL_ARGS)
183695c635efSGarrett D'Amore {
183795c635efSGarrett D'Amore 
183895c635efSGarrett D'Amore 	n = n->child;
183995c635efSGarrett D'Amore 	if (NULL == n)
1840371584c2SYuri Pankov 		return 0;
1841698f87a4SGarrett D'Amore 	print_node(meta, n);
184295c635efSGarrett D'Amore 	n = n->next;
184395c635efSGarrett D'Amore 	if (NULL == n)
1844371584c2SYuri Pankov 		return 0;
1845698f87a4SGarrett D'Amore 	outflags &= ~MMAN_spc;
1846698f87a4SGarrett D'Amore 	print_word("(");
1847698f87a4SGarrett D'Amore 	print_node(meta, n);
1848698f87a4SGarrett D'Amore 	print_word(")");
1849371584c2SYuri Pankov 	return 0;
185095c635efSGarrett D'Amore }
1851