]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_man.c
when indenting, extend the right margin accordingly, when needed;
[mandoc.git] / mdoc_man.c
1 /* $Id: mdoc_man.c,v 1.58 2014/01/22 20:58:39 schwarze Exp $ */
2 /*
3 * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <assert.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "mandoc.h"
26 #include "out.h"
27 #include "man.h"
28 #include "mdoc.h"
29 #include "main.h"
30
31 #define DECL_ARGS const struct mdoc_meta *meta, \
32 const struct mdoc_node *n
33
34 struct manact {
35 int (*cond)(DECL_ARGS); /* DON'T run actions */
36 int (*pre)(DECL_ARGS); /* pre-node action */
37 void (*post)(DECL_ARGS); /* post-node action */
38 const char *prefix; /* pre-node string constant */
39 const char *suffix; /* post-node string constant */
40 };
41
42 static int cond_body(DECL_ARGS);
43 static int cond_head(DECL_ARGS);
44 static void font_push(char);
45 static void font_pop(void);
46 static void mid_it(void);
47 static void post__t(DECL_ARGS);
48 static void post_bd(DECL_ARGS);
49 static void post_bf(DECL_ARGS);
50 static void post_bk(DECL_ARGS);
51 static void post_bl(DECL_ARGS);
52 static void post_dl(DECL_ARGS);
53 static void post_enc(DECL_ARGS);
54 static void post_eo(DECL_ARGS);
55 static void post_fa(DECL_ARGS);
56 static void post_fd(DECL_ARGS);
57 static void post_fl(DECL_ARGS);
58 static void post_fn(DECL_ARGS);
59 static void post_fo(DECL_ARGS);
60 static void post_font(DECL_ARGS);
61 static void post_in(DECL_ARGS);
62 static void post_it(DECL_ARGS);
63 static void post_lb(DECL_ARGS);
64 static void post_nm(DECL_ARGS);
65 static void post_percent(DECL_ARGS);
66 static void post_pf(DECL_ARGS);
67 static void post_sect(DECL_ARGS);
68 static void post_sp(DECL_ARGS);
69 static void post_vt(DECL_ARGS);
70 static int pre__t(DECL_ARGS);
71 static int pre_an(DECL_ARGS);
72 static int pre_ap(DECL_ARGS);
73 static int pre_bd(DECL_ARGS);
74 static int pre_bf(DECL_ARGS);
75 static int pre_bk(DECL_ARGS);
76 static int pre_bl(DECL_ARGS);
77 static int pre_br(DECL_ARGS);
78 static int pre_bx(DECL_ARGS);
79 static int pre_dl(DECL_ARGS);
80 static int pre_enc(DECL_ARGS);
81 static int pre_em(DECL_ARGS);
82 static int pre_fa(DECL_ARGS);
83 static int pre_fd(DECL_ARGS);
84 static int pre_fl(DECL_ARGS);
85 static int pre_fn(DECL_ARGS);
86 static int pre_fo(DECL_ARGS);
87 static int pre_ft(DECL_ARGS);
88 static int pre_in(DECL_ARGS);
89 static int pre_it(DECL_ARGS);
90 static int pre_lk(DECL_ARGS);
91 static int pre_li(DECL_ARGS);
92 static int pre_nm(DECL_ARGS);
93 static int pre_no(DECL_ARGS);
94 static int pre_ns(DECL_ARGS);
95 static int pre_pp(DECL_ARGS);
96 static int pre_rs(DECL_ARGS);
97 static int pre_sm(DECL_ARGS);
98 static int pre_sp(DECL_ARGS);
99 static int pre_sect(DECL_ARGS);
100 static int pre_sy(DECL_ARGS);
101 static void pre_syn(const struct mdoc_node *);
102 static int pre_vt(DECL_ARGS);
103 static int pre_ux(DECL_ARGS);
104 static int pre_xr(DECL_ARGS);
105 static void print_word(const char *);
106 static void print_line(const char *, int);
107 static void print_block(const char *, int);
108 static void print_offs(const char *);
109 static void print_width(const char *,
110 const struct mdoc_node *, size_t);
111 static void print_count(int *);
112 static void print_node(DECL_ARGS);
113
114 static const struct manact manacts[MDOC_MAX + 1] = {
115 { NULL, pre_ap, NULL, NULL, NULL }, /* Ap */
116 { NULL, NULL, NULL, NULL, NULL }, /* Dd */
117 { NULL, NULL, NULL, NULL, NULL }, /* Dt */
118 { NULL, NULL, NULL, NULL, NULL }, /* Os */
119 { NULL, pre_sect, post_sect, ".SH", NULL }, /* Sh */
120 { NULL, pre_sect, post_sect, ".SS", NULL }, /* Ss */
121 { NULL, pre_pp, NULL, NULL, NULL }, /* Pp */
122 { cond_body, pre_dl, post_dl, NULL, NULL }, /* D1 */
123 { cond_body, pre_dl, post_dl, NULL, NULL }, /* Dl */
124 { cond_body, pre_bd, post_bd, NULL, NULL }, /* Bd */
125 { NULL, NULL, NULL, NULL, NULL }, /* Ed */
126 { cond_body, pre_bl, post_bl, NULL, NULL }, /* Bl */
127 { NULL, NULL, NULL, NULL, NULL }, /* El */
128 { NULL, pre_it, post_it, NULL, NULL }, /* It */
129 { NULL, pre_em, post_font, NULL, NULL }, /* Ad */
130 { NULL, pre_an, NULL, NULL, NULL }, /* An */
131 { NULL, pre_em, post_font, NULL, NULL }, /* Ar */
132 { NULL, pre_sy, post_font, NULL, NULL }, /* Cd */
133 { NULL, pre_sy, post_font, NULL, NULL }, /* Cm */
134 { NULL, pre_li, post_font, NULL, NULL }, /* Dv */
135 { NULL, pre_li, post_font, NULL, NULL }, /* Er */
136 { NULL, pre_li, post_font, NULL, NULL }, /* Ev */
137 { NULL, pre_enc, post_enc, "The \\fB",
138 "\\fP\nutility exits 0 on success, and >0 if an error occurs."
139 }, /* Ex */
140 { NULL, pre_fa, post_fa, NULL, NULL }, /* Fa */
141 { NULL, pre_fd, post_fd, NULL, NULL }, /* Fd */
142 { NULL, pre_fl, post_fl, NULL, NULL }, /* Fl */
143 { NULL, pre_fn, post_fn, NULL, NULL }, /* Fn */
144 { NULL, pre_ft, post_font, NULL, NULL }, /* Ft */
145 { NULL, pre_sy, post_font, NULL, NULL }, /* Ic */
146 { NULL, pre_in, post_in, NULL, NULL }, /* In */
147 { NULL, pre_li, post_font, NULL, NULL }, /* Li */
148 { cond_head, pre_enc, NULL, "\\- ", NULL }, /* Nd */
149 { NULL, pre_nm, post_nm, NULL, NULL }, /* Nm */
150 { cond_body, pre_enc, post_enc, "[", "]" }, /* Op */
151 { NULL, NULL, NULL, NULL, NULL }, /* Ot */
152 { NULL, pre_em, post_font, NULL, NULL }, /* Pa */
153 { NULL, pre_enc, post_enc, "The \\fB",
154 "\\fP\nfunction returns the value 0 if successful;\n"
155 "otherwise the value -1 is returned and the global\n"
156 "variable \\fIerrno\\fP is set to indicate the error."
157 }, /* Rv */
158 { NULL, NULL, NULL, NULL, NULL }, /* St */
159 { NULL, pre_em, post_font, NULL, NULL }, /* Va */
160 { NULL, pre_vt, post_vt, NULL, NULL }, /* Vt */
161 { NULL, pre_xr, NULL, NULL, NULL }, /* Xr */
162 { NULL, NULL, post_percent, NULL, NULL }, /* %A */
163 { NULL, pre_em, post_percent, NULL, NULL }, /* %B */
164 { NULL, NULL, post_percent, NULL, NULL }, /* %D */
165 { NULL, pre_em, post_percent, NULL, NULL }, /* %I */
166 { NULL, pre_em, post_percent, NULL, NULL }, /* %J */
167 { NULL, NULL, post_percent, NULL, NULL }, /* %N */
168 { NULL, NULL, post_percent, NULL, NULL }, /* %O */
169 { NULL, NULL, post_percent, NULL, NULL }, /* %P */
170 { NULL, NULL, post_percent, NULL, NULL }, /* %R */
171 { NULL, pre__t, post__t, NULL, NULL }, /* %T */
172 { NULL, NULL, post_percent, NULL, NULL }, /* %V */
173 { NULL, NULL, NULL, NULL, NULL }, /* Ac */
174 { cond_body, pre_enc, post_enc, "<", ">" }, /* Ao */
175 { cond_body, pre_enc, post_enc, "<", ">" }, /* Aq */
176 { NULL, NULL, NULL, NULL, NULL }, /* At */
177 { NULL, NULL, NULL, NULL, NULL }, /* Bc */
178 { NULL, pre_bf, post_bf, NULL, NULL }, /* Bf */
179 { cond_body, pre_enc, post_enc, "[", "]" }, /* Bo */
180 { cond_body, pre_enc, post_enc, "[", "]" }, /* Bq */
181 { NULL, pre_ux, NULL, "BSD/OS", NULL }, /* Bsx */
182 { NULL, pre_bx, NULL, NULL, NULL }, /* Bx */
183 { NULL, NULL, NULL, NULL, NULL }, /* Db */
184 { NULL, NULL, NULL, NULL, NULL }, /* Dc */
185 { cond_body, pre_enc, post_enc, "\\(lq", "\\(rq" }, /* Do */
186 { cond_body, pre_enc, post_enc, "\\(lq", "\\(rq" }, /* Dq */
187 { NULL, NULL, NULL, NULL, NULL }, /* Ec */
188 { NULL, NULL, NULL, NULL, NULL }, /* Ef */
189 { NULL, pre_em, post_font, NULL, NULL }, /* Em */
190 { NULL, NULL, post_eo, NULL, NULL }, /* Eo */
191 { NULL, pre_ux, NULL, "FreeBSD", NULL }, /* Fx */
192 { NULL, pre_sy, post_font, NULL, NULL }, /* Ms */
193 { NULL, pre_no, NULL, NULL, NULL }, /* No */
194 { NULL, pre_ns, NULL, NULL, NULL }, /* Ns */
195 { NULL, pre_ux, NULL, "NetBSD", NULL }, /* Nx */
196 { NULL, pre_ux, NULL, "OpenBSD", NULL }, /* Ox */
197 { NULL, NULL, NULL, NULL, NULL }, /* Pc */
198 { NULL, NULL, post_pf, NULL, NULL }, /* Pf */
199 { cond_body, pre_enc, post_enc, "(", ")" }, /* Po */
200 { cond_body, pre_enc, post_enc, "(", ")" }, /* Pq */
201 { NULL, NULL, NULL, NULL, NULL }, /* Qc */
202 { cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* Ql */
203 { cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qo */
204 { cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qq */
205 { NULL, NULL, NULL, NULL, NULL }, /* Re */
206 { cond_body, pre_rs, NULL, NULL, NULL }, /* Rs */
207 { NULL, NULL, NULL, NULL, NULL }, /* Sc */
208 { cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* So */
209 { cond_body, pre_enc, post_enc, "\\(oq", "\\(cq" }, /* Sq */
210 { NULL, pre_sm, NULL, NULL, NULL }, /* Sm */
211 { NULL, pre_em, post_font, NULL, NULL }, /* Sx */
212 { NULL, pre_sy, post_font, NULL, NULL }, /* Sy */
213 { NULL, pre_li, post_font, NULL, NULL }, /* Tn */
214 { NULL, pre_ux, NULL, "UNIX", NULL }, /* Ux */
215 { NULL, NULL, NULL, NULL, NULL }, /* Xc */
216 { NULL, NULL, NULL, NULL, NULL }, /* Xo */
217 { NULL, pre_fo, post_fo, NULL, NULL }, /* Fo */
218 { NULL, NULL, NULL, NULL, NULL }, /* Fc */
219 { cond_body, pre_enc, post_enc, "[", "]" }, /* Oo */
220 { NULL, NULL, NULL, NULL, NULL }, /* Oc */
221 { NULL, pre_bk, post_bk, NULL, NULL }, /* Bk */
222 { NULL, NULL, NULL, NULL, NULL }, /* Ek */
223 { NULL, pre_ux, NULL, "is currently in beta test.", NULL }, /* Bt */
224 { NULL, NULL, NULL, NULL, NULL }, /* Hf */
225 { NULL, NULL, NULL, NULL, NULL }, /* Fr */
226 { NULL, pre_ux, NULL, "currently under development.", NULL }, /* Ud */
227 { NULL, NULL, post_lb, NULL, NULL }, /* Lb */
228 { NULL, pre_pp, NULL, NULL, NULL }, /* Lp */
229 { NULL, pre_lk, NULL, NULL, NULL }, /* Lk */
230 { NULL, pre_em, post_font, NULL, NULL }, /* Mt */
231 { cond_body, pre_enc, post_enc, "{", "}" }, /* Brq */
232 { cond_body, pre_enc, post_enc, "{", "}" }, /* Bro */
233 { NULL, NULL, NULL, NULL, NULL }, /* Brc */
234 { NULL, NULL, post_percent, NULL, NULL }, /* %C */
235 { NULL, NULL, NULL, NULL, NULL }, /* Es */
236 { NULL, NULL, NULL, NULL, NULL }, /* En */
237 { NULL, pre_ux, NULL, "DragonFly", NULL }, /* Dx */
238 { NULL, NULL, post_percent, NULL, NULL }, /* %Q */
239 { NULL, pre_br, NULL, NULL, NULL }, /* br */
240 { NULL, pre_sp, post_sp, NULL, NULL }, /* sp */
241 { NULL, NULL, post_percent, NULL, NULL }, /* %U */
242 { NULL, NULL, NULL, NULL, NULL }, /* Ta */
243 { NULL, NULL, NULL, NULL, NULL }, /* ROOT */
244 };
245
246 static int outflags;
247 #define MMAN_spc (1 << 0) /* blank character before next word */
248 #define MMAN_spc_force (1 << 1) /* even before trailing punctuation */
249 #define MMAN_nl (1 << 2) /* break man(7) code line */
250 #define MMAN_br (1 << 3) /* break output line */
251 #define MMAN_sp (1 << 4) /* insert a blank output line */
252 #define MMAN_PP (1 << 5) /* reset indentation etc. */
253 #define MMAN_Sm (1 << 6) /* horizontal spacing mode */
254 #define MMAN_Bk (1 << 7) /* word keep mode */
255 #define MMAN_Bk_susp (1 << 8) /* suspend this (after a macro) */
256 #define MMAN_An_split (1 << 9) /* author mode is "split" */
257 #define MMAN_An_nosplit (1 << 10) /* author mode is "nosplit" */
258 #define MMAN_PD (1 << 11) /* inter-paragraph spacing disabled */
259 #define MMAN_nbrword (1 << 12) /* do not break the next word */
260
261 #define BL_STACK_MAX 32
262
263 static size_t Bl_stack[BL_STACK_MAX]; /* offsets [chars] */
264 static int Bl_stack_post[BL_STACK_MAX]; /* add final .RE */
265 static int Bl_stack_len; /* number of nested Bl blocks */
266 static int TPremain; /* characters before tag is full */
267
268 static struct {
269 char *head;
270 char *tail;
271 size_t size;
272 } fontqueue;
273
274 static void
275 font_push(char newfont)
276 {
277
278 if (fontqueue.head + fontqueue.size <= ++fontqueue.tail) {
279 fontqueue.size += 8;
280 fontqueue.head = mandoc_realloc(fontqueue.head,
281 fontqueue.size);
282 }
283 *fontqueue.tail = newfont;
284 print_word("");
285 printf("\\f");
286 putchar(newfont);
287 outflags &= ~MMAN_spc;
288 }
289
290 static void
291 font_pop(void)
292 {
293
294 if (fontqueue.tail > fontqueue.head)
295 fontqueue.tail--;
296 outflags &= ~MMAN_spc;
297 print_word("");
298 printf("\\f");
299 putchar(*fontqueue.tail);
300 }
301
302 static void
303 print_word(const char *s)
304 {
305
306 if ((MMAN_PP | MMAN_sp | MMAN_br | MMAN_nl) & outflags) {
307 /*
308 * If we need a newline, print it now and start afresh.
309 */
310 if (MMAN_PP & outflags) {
311 if (MMAN_sp & outflags) {
312 if (MMAN_PD & outflags) {
313 printf("\n.PD");
314 outflags &= ~MMAN_PD;
315 }
316 } else if ( ! (MMAN_PD & outflags)) {
317 printf("\n.PD 0");
318 outflags |= MMAN_PD;
319 }
320 printf("\n.PP\n");
321 } else if (MMAN_sp & outflags)
322 printf("\n.sp\n");
323 else if (MMAN_br & outflags)
324 printf("\n.br\n");
325 else if (MMAN_nl & outflags)
326 putchar('\n');
327 outflags &= ~(MMAN_PP|MMAN_sp|MMAN_br|MMAN_nl|MMAN_spc);
328 if (1 == TPremain)
329 printf(".br\n");
330 TPremain = 0;
331 } else if (MMAN_spc & outflags) {
332 /*
333 * If we need a space, only print it if
334 * (1) it is forced by `No' or
335 * (2) what follows is not terminating punctuation or
336 * (3) what follows is longer than one character.
337 */
338 if (MMAN_spc_force & outflags || '\0' == s[0] ||
339 NULL == strchr(".,:;)]?!", s[0]) || '\0' != s[1]) {
340 if (MMAN_Bk & outflags &&
341 ! (MMAN_Bk_susp & outflags))
342 putchar('\\');
343 putchar(' ');
344 if (TPremain)
345 TPremain--;
346 }
347 }
348
349 /*
350 * Reassign needing space if we're not following opening
351 * punctuation.
352 */
353 if (MMAN_Sm & outflags && ('\0' == s[0] ||
354 (('(' != s[0] && '[' != s[0]) || '\0' != s[1])))
355 outflags |= MMAN_spc;
356 else
357 outflags &= ~MMAN_spc;
358 outflags &= ~(MMAN_spc_force | MMAN_Bk_susp);
359
360 for ( ; *s; s++) {
361 switch (*s) {
362 case (ASCII_NBRSP):
363 printf("\\ ");
364 break;
365 case (ASCII_HYPH):
366 putchar('-');
367 break;
368 case (ASCII_BREAK):
369 printf("\\:");
370 break;
371 case (' '):
372 if (MMAN_nbrword & outflags) {
373 printf("\\ ");
374 break;
375 }
376 /* FALLTHROUGH */
377 default:
378 putchar((unsigned char)*s);
379 break;
380 }
381 if (TPremain)
382 TPremain--;
383 }
384 outflags &= ~MMAN_nbrword;
385 }
386
387 static void
388 print_line(const char *s, int newflags)
389 {
390
391 outflags &= ~MMAN_br;
392 outflags |= MMAN_nl;
393 print_word(s);
394 outflags |= newflags;
395 }
396
397 static void
398 print_block(const char *s, int newflags)
399 {
400
401 outflags &= ~MMAN_PP;
402 if (MMAN_sp & outflags) {
403 outflags &= ~(MMAN_sp | MMAN_br);
404 if (MMAN_PD & outflags) {
405 print_line(".PD", 0);
406 outflags &= ~MMAN_PD;
407 }
408 } else if (! (MMAN_PD & outflags))
409 print_line(".PD 0", MMAN_PD);
410 outflags |= MMAN_nl;
411 print_word(s);
412 outflags |= MMAN_Bk_susp | newflags;
413 }
414
415 static void
416 print_offs(const char *v)
417 {
418 char buf[24];
419 struct roffsu su;
420 size_t sz;
421
422 print_line(".RS", MMAN_Bk_susp);
423
424 /* Convert v into a number (of characters). */
425 if (NULL == v || '\0' == *v || 0 == strcmp(v, "left"))
426 sz = 0;
427 else if (0 == strcmp(v, "indent"))
428 sz = 6;
429 else if (0 == strcmp(v, "indent-two"))
430 sz = 12;
431 else if (a2roffsu(v, &su, SCALE_MAX)) {
432 if (SCALE_EN == su.unit)
433 sz = su.scale;
434 else {
435 /*
436 * XXX
437 * If we are inside an enclosing list,
438 * there is no easy way to add the two
439 * indentations because they are provided
440 * in terms of different units.
441 */
442 print_word(v);
443 outflags |= MMAN_nl;
444 return;
445 }
446 } else
447 sz = strlen(v);
448
449 /*
450 * We are inside an enclosing list.
451 * Add the two indentations.
452 */
453 if (Bl_stack_len)
454 sz += Bl_stack[Bl_stack_len - 1];
455
456 snprintf(buf, sizeof(buf), "%zun", sz);
457 print_word(buf);
458 outflags |= MMAN_nl;
459 }
460
461 /*
462 * Set up the indentation for a list item; used from pre_it().
463 */
464 void
465 print_width(const char *v, const struct mdoc_node *child, size_t defsz)
466 {
467 char buf[24];
468 struct roffsu su;
469 size_t sz, chsz;
470 int numeric, remain;
471
472 numeric = 1;
473 remain = 0;
474
475 /* Convert v into a number (of characters). */
476 if (NULL == v)
477 sz = defsz;
478 else if (a2roffsu(v, &su, SCALE_MAX)) {
479 if (SCALE_EN == su.unit)
480 sz = su.scale;
481 else {
482 sz = 0;
483 numeric = 0;
484 }
485 } else
486 sz = strlen(v);
487
488 /* XXX Rough estimation, might have multiple parts. */
489 chsz = (NULL != child && MDOC_TEXT == child->type) ?
490 strlen(child->string) : 0;
491
492 /* Maybe we are inside an enclosing list? */
493 mid_it();
494
495 /*
496 * Save our own indentation,
497 * such that child lists can use it.
498 */
499 Bl_stack[Bl_stack_len++] = sz + 2;
500
501 /* Set up the current list. */
502 if (defsz && chsz > sz)
503 print_block(".HP", 0);
504 else {
505 print_block(".TP", 0);
506 remain = sz + 2;
507 }
508 if (numeric) {
509 snprintf(buf, sizeof(buf), "%zun", sz + 2);
510 print_word(buf);
511 } else
512 print_word(v);
513 TPremain = remain;
514 }
515
516 void
517 print_count(int *count)
518 {
519 char buf[12];
520
521 snprintf(buf, sizeof(buf), "%d.", ++*count);
522 print_word(buf);
523 }
524
525 void
526 man_man(void *arg, const struct man *man)
527 {
528
529 /*
530 * Dump the keep buffer.
531 * We're guaranteed by now that this exists (is non-NULL).
532 * Flush stdout afterward, just in case.
533 */
534 fputs(mparse_getkeep(man_mparse(man)), stdout);
535 fflush(stdout);
536 }
537
538 void
539 man_mdoc(void *arg, const struct mdoc *mdoc)
540 {
541 const struct mdoc_meta *meta;
542 const struct mdoc_node *n;
543
544 meta = mdoc_meta(mdoc);
545 n = mdoc_node(mdoc);
546
547 printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
548 meta->title, meta->msec, meta->date,
549 meta->os, meta->vol);
550
551 /* Disable hyphenation and if nroff, disable justification. */
552 printf(".nh\n.if n .ad l");
553
554 outflags = MMAN_nl | MMAN_Sm;
555 if (0 == fontqueue.size) {
556 fontqueue.size = 8;
557 fontqueue.head = fontqueue.tail = mandoc_malloc(8);
558 *fontqueue.tail = 'R';
559 }
560 print_node(meta, n);
561 putchar('\n');
562 }
563
564 static void
565 print_node(DECL_ARGS)
566 {
567 const struct mdoc_node *sub;
568 const struct manact *act;
569 int cond, do_sub;
570
571 /*
572 * Break the line if we were parsed subsequent the current node.
573 * This makes the page structure be more consistent.
574 */
575 if (MMAN_spc & outflags && MDOC_LINE & n->flags)
576 outflags |= MMAN_nl;
577
578 act = NULL;
579 cond = 0;
580 do_sub = 1;
581
582 if (MDOC_TEXT == n->type) {
583 /*
584 * Make sure that we don't happen to start with a
585 * control character at the start of a line.
586 */
587 if (MMAN_nl & outflags && ('.' == *n->string ||
588 '\'' == *n->string)) {
589 print_word("");
590 printf("\\&");
591 outflags &= ~MMAN_spc;
592 }
593 print_word(n->string);
594 } else {
595 /*
596 * Conditionally run the pre-node action handler for a
597 * node.
598 */
599 act = manacts + n->tok;
600 cond = NULL == act->cond || (*act->cond)(meta, n);
601 if (cond && act->pre)
602 do_sub = (*act->pre)(meta, n);
603 }
604
605 /*
606 * Conditionally run all child nodes.
607 * Note that this iterates over children instead of using
608 * recursion. This prevents unnecessary depth in the stack.
609 */
610 if (do_sub)
611 for (sub = n->child; sub; sub = sub->next)
612 print_node(meta, sub);
613
614 /*
615 * Lastly, conditionally run the post-node handler.
616 */
617 if (cond && act->post)
618 (*act->post)(meta, n);
619 }
620
621 static int
622 cond_head(DECL_ARGS)
623 {
624
625 return(MDOC_HEAD == n->type);
626 }
627
628 static int
629 cond_body(DECL_ARGS)
630 {
631
632 return(MDOC_BODY == n->type);
633 }
634
635 static int
636 pre_enc(DECL_ARGS)
637 {
638 const char *prefix;
639
640 prefix = manacts[n->tok].prefix;
641 if (NULL == prefix)
642 return(1);
643 print_word(prefix);
644 outflags &= ~MMAN_spc;
645 return(1);
646 }
647
648 static void
649 post_enc(DECL_ARGS)
650 {
651 const char *suffix;
652
653 suffix = manacts[n->tok].suffix;
654 if (NULL == suffix)
655 return;
656 outflags &= ~MMAN_spc;
657 print_word(suffix);
658 }
659
660 static void
661 post_font(DECL_ARGS)
662 {
663
664 font_pop();
665 }
666
667 static void
668 post_percent(DECL_ARGS)
669 {
670
671 if (pre_em == manacts[n->tok].pre)
672 font_pop();
673 if (n->next) {
674 print_word(",");
675 if (n->prev && n->prev->tok == n->tok &&
676 n->next->tok == n->tok)
677 print_word("and");
678 } else {
679 print_word(".");
680 outflags |= MMAN_nl;
681 }
682 }
683
684 static int
685 pre__t(DECL_ARGS)
686 {
687
688 if (n->parent && MDOC_Rs == n->parent->tok &&
689 n->parent->norm->Rs.quote_T) {
690 print_word("");
691 putchar('\"');
692 outflags &= ~MMAN_spc;
693 } else
694 font_push('I');
695 return(1);
696 }
697
698 static void
699 post__t(DECL_ARGS)
700 {
701
702 if (n->parent && MDOC_Rs == n->parent->tok &&
703 n->parent->norm->Rs.quote_T) {
704 outflags &= ~MMAN_spc;
705 print_word("");
706 putchar('\"');
707 } else
708 font_pop();
709 post_percent(meta, n);
710 }
711
712 /*
713 * Print before a section header.
714 */
715 static int
716 pre_sect(DECL_ARGS)
717 {
718
719 if (MDOC_HEAD == n->type) {
720 outflags |= MMAN_sp;
721 print_block(manacts[n->tok].prefix, 0);
722 print_word("");
723 putchar('\"');
724 outflags &= ~MMAN_spc;
725 }
726 return(1);
727 }
728
729 /*
730 * Print subsequent a section header.
731 */
732 static void
733 post_sect(DECL_ARGS)
734 {
735
736 if (MDOC_HEAD != n->type)
737 return;
738 outflags &= ~MMAN_spc;
739 print_word("");
740 putchar('\"');
741 outflags |= MMAN_nl;
742 if (MDOC_Sh == n->tok && SEC_AUTHORS == n->sec)
743 outflags &= ~(MMAN_An_split | MMAN_An_nosplit);
744 }
745
746 /* See mdoc_term.c, synopsis_pre() for comments. */
747 static void
748 pre_syn(const struct mdoc_node *n)
749 {
750
751 if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
752 return;
753
754 if (n->prev->tok == n->tok &&
755 MDOC_Ft != n->tok &&
756 MDOC_Fo != n->tok &&
757 MDOC_Fn != n->tok) {
758 outflags |= MMAN_br;
759 return;
760 }
761
762 switch (n->prev->tok) {
763 case (MDOC_Fd):
764 /* FALLTHROUGH */
765 case (MDOC_Fn):
766 /* FALLTHROUGH */
767 case (MDOC_Fo):
768 /* FALLTHROUGH */
769 case (MDOC_In):
770 /* FALLTHROUGH */
771 case (MDOC_Vt):
772 outflags |= MMAN_sp;
773 break;
774 case (MDOC_Ft):
775 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
776 outflags |= MMAN_sp;
777 break;
778 }
779 /* FALLTHROUGH */
780 default:
781 outflags |= MMAN_br;
782 break;
783 }
784 }
785
786 static int
787 pre_an(DECL_ARGS)
788 {
789
790 switch (n->norm->An.auth) {
791 case (AUTH_split):
792 outflags &= ~MMAN_An_nosplit;
793 outflags |= MMAN_An_split;
794 return(0);
795 case (AUTH_nosplit):
796 outflags &= ~MMAN_An_split;
797 outflags |= MMAN_An_nosplit;
798 return(0);
799 default:
800 if (MMAN_An_split & outflags)
801 outflags |= MMAN_br;
802 else if (SEC_AUTHORS == n->sec &&
803 ! (MMAN_An_nosplit & outflags))
804 outflags |= MMAN_An_split;
805 return(1);
806 }
807 }
808
809 static int
810 pre_ap(DECL_ARGS)
811 {
812
813 outflags &= ~MMAN_spc;
814 print_word("'");
815 outflags &= ~MMAN_spc;
816 return(0);
817 }
818
819 static int
820 pre_bd(DECL_ARGS)
821 {
822
823 outflags &= ~(MMAN_PP | MMAN_sp | MMAN_br);
824
825 if (DISP_unfilled == n->norm->Bd.type ||
826 DISP_literal == n->norm->Bd.type)
827 print_line(".nf", 0);
828 if (0 == n->norm->Bd.comp && NULL != n->parent->prev)
829 outflags |= MMAN_sp;
830 print_offs(n->norm->Bd.offs);
831 return(1);
832 }
833
834 static void
835 post_bd(DECL_ARGS)
836 {
837
838 /* Close out this display. */
839 print_line(".RE", MMAN_nl);
840 if (DISP_unfilled == n->norm->Bd.type ||
841 DISP_literal == n->norm->Bd.type)
842 print_line(".fi", MMAN_nl);
843
844 /* Maybe we are inside an enclosing list? */
845 if (NULL != n->parent->next)
846 mid_it();
847 }
848
849 static int
850 pre_bf(DECL_ARGS)
851 {
852
853 switch (n->type) {
854 case (MDOC_BLOCK):
855 return(1);
856 case (MDOC_BODY):
857 break;
858 default:
859 return(0);
860 }
861 switch (n->norm->Bf.font) {
862 case (FONT_Em):
863 font_push('I');
864 break;
865 case (FONT_Sy):
866 font_push('B');
867 break;
868 default:
869 font_push('R');
870 break;
871 }
872 return(1);
873 }
874
875 static void
876 post_bf(DECL_ARGS)
877 {
878
879 if (MDOC_BODY == n->type)
880 font_pop();
881 }
882
883 static int
884 pre_bk(DECL_ARGS)
885 {
886
887 switch (n->type) {
888 case (MDOC_BLOCK):
889 return(1);
890 case (MDOC_BODY):
891 outflags |= MMAN_Bk;
892 return(1);
893 default:
894 return(0);
895 }
896 }
897
898 static void
899 post_bk(DECL_ARGS)
900 {
901
902 if (MDOC_BODY == n->type)
903 outflags &= ~MMAN_Bk;
904 }
905
906 static int
907 pre_bl(DECL_ARGS)
908 {
909 size_t icol;
910
911 /*
912 * print_offs() will increase the -offset to account for
913 * a possible enclosing .It, but any enclosed .It blocks
914 * just nest and do not add up their indentation.
915 */
916 if (n->norm->Bl.offs) {
917 print_offs(n->norm->Bl.offs);
918 Bl_stack[Bl_stack_len++] = 0;
919 }
920
921 switch (n->norm->Bl.type) {
922 case (LIST_enum):
923 n->norm->Bl.count = 0;
924 return(1);
925 case (LIST_column):
926 break;
927 default:
928 return(1);
929 }
930
931 print_line(".TS", MMAN_nl);
932 for (icol = 0; icol < n->norm->Bl.ncols; icol++)
933 print_word("l");
934 print_word(".");
935 outflags |= MMAN_nl;
936 return(1);
937 }
938
939 static void
940 post_bl(DECL_ARGS)
941 {
942
943 switch (n->norm->Bl.type) {
944 case (LIST_column):
945 print_line(".TE", 0);
946 break;
947 case (LIST_enum):
948 n->norm->Bl.count = 0;
949 break;
950 default:
951 break;
952 }
953
954 if (n->norm->Bl.offs) {
955 print_line(".RE", MMAN_nl);
956 assert(Bl_stack_len);
957 Bl_stack_len--;
958 assert(0 == Bl_stack[Bl_stack_len]);
959 } else {
960 outflags |= MMAN_PP | MMAN_nl;
961 outflags &= ~(MMAN_sp | MMAN_br);
962 }
963
964 /* Maybe we are inside an enclosing list? */
965 if (NULL != n->parent->next)
966 mid_it();
967
968 }
969
970 static int
971 pre_br(DECL_ARGS)
972 {
973
974 outflags |= MMAN_br;
975 return(0);
976 }
977
978 static int
979 pre_bx(DECL_ARGS)
980 {
981
982 n = n->child;
983 if (n) {
984 print_word(n->string);
985 outflags &= ~MMAN_spc;
986 n = n->next;
987 }
988 print_word("BSD");
989 if (NULL == n)
990 return(0);
991 outflags &= ~MMAN_spc;
992 print_word("-");
993 outflags &= ~MMAN_spc;
994 print_word(n->string);
995 return(0);
996 }
997
998 static int
999 pre_dl(DECL_ARGS)
1000 {
1001
1002 print_offs("6n");
1003 return(1);
1004 }
1005
1006 static void
1007 post_dl(DECL_ARGS)
1008 {
1009
1010 print_line(".RE", MMAN_nl);
1011
1012 /* Maybe we are inside an enclosing list? */
1013 if (NULL != n->parent->next)
1014 mid_it();
1015 }
1016
1017 static int
1018 pre_em(DECL_ARGS)
1019 {
1020
1021 font_push('I');
1022 return(1);
1023 }
1024
1025 static void
1026 post_eo(DECL_ARGS)
1027 {
1028
1029 if (MDOC_HEAD == n->type || MDOC_BODY == n->type)
1030 outflags &= ~MMAN_spc;
1031 }
1032
1033 static int
1034 pre_fa(DECL_ARGS)
1035 {
1036 int am_Fa;
1037
1038 am_Fa = MDOC_Fa == n->tok;
1039
1040 if (am_Fa)
1041 n = n->child;
1042
1043 while (NULL != n) {
1044 font_push('I');
1045 if (am_Fa || MDOC_SYNPRETTY & n->flags)
1046 outflags |= MMAN_nbrword;
1047 print_node(meta, n);
1048 font_pop();
1049 if (NULL != (n = n->next))
1050 print_word(",");
1051 }
1052 return(0);
1053 }
1054
1055 static void
1056 post_fa(DECL_ARGS)
1057 {
1058
1059 if (NULL != n->next && MDOC_Fa == n->next->tok)
1060 print_word(",");
1061 }
1062
1063 static int
1064 pre_fd(DECL_ARGS)
1065 {
1066
1067 pre_syn(n);
1068 font_push('B');
1069 return(1);
1070 }
1071
1072 static void
1073 post_fd(DECL_ARGS)
1074 {
1075
1076 font_pop();
1077 outflags |= MMAN_br;
1078 }
1079
1080 static int
1081 pre_fl(DECL_ARGS)
1082 {
1083
1084 font_push('B');
1085 print_word("\\-");
1086 outflags &= ~MMAN_spc;
1087 return(1);
1088 }
1089
1090 static void
1091 post_fl(DECL_ARGS)
1092 {
1093
1094 font_pop();
1095 if (0 == n->nchild && NULL != n->next &&
1096 n->next->line == n->line)
1097 outflags &= ~MMAN_spc;
1098 }
1099
1100 static int
1101 pre_fn(DECL_ARGS)
1102 {
1103
1104 pre_syn(n);
1105
1106 n = n->child;
1107 if (NULL == n)
1108 return(0);
1109
1110 if (MDOC_SYNPRETTY & n->flags)
1111 print_block(".HP 4n", MMAN_nl);
1112
1113 font_push('B');
1114 print_node(meta, n);
1115 font_pop();
1116 outflags &= ~MMAN_spc;
1117 print_word("(");
1118 outflags &= ~MMAN_spc;
1119
1120 n = n->next;
1121 if (NULL != n)
1122 pre_fa(meta, n);
1123 return(0);
1124 }
1125
1126 static void
1127 post_fn(DECL_ARGS)
1128 {
1129
1130 print_word(")");
1131 if (MDOC_SYNPRETTY & n->flags) {
1132 print_word(";");
1133 outflags |= MMAN_PP;
1134 }
1135 }
1136
1137 static int
1138 pre_fo(DECL_ARGS)
1139 {
1140
1141 switch (n->type) {
1142 case (MDOC_BLOCK):
1143 pre_syn(n);
1144 break;
1145 case (MDOC_HEAD):
1146 if (MDOC_SYNPRETTY & n->flags)
1147 print_block(".HP 4n", MMAN_nl);
1148 font_push('B');
1149 break;
1150 case (MDOC_BODY):
1151 outflags &= ~MMAN_spc;
1152 print_word("(");
1153 outflags &= ~MMAN_spc;
1154 break;
1155 default:
1156 break;
1157 }
1158 return(1);
1159 }
1160
1161 static void
1162 post_fo(DECL_ARGS)
1163 {
1164
1165 switch (n->type) {
1166 case (MDOC_HEAD):
1167 font_pop();
1168 break;
1169 case (MDOC_BODY):
1170 post_fn(meta, n);
1171 break;
1172 default:
1173 break;
1174 }
1175 }
1176
1177 static int
1178 pre_ft(DECL_ARGS)
1179 {
1180
1181 pre_syn(n);
1182 font_push('I');
1183 return(1);
1184 }
1185
1186 static int
1187 pre_in(DECL_ARGS)
1188 {
1189
1190 if (MDOC_SYNPRETTY & n->flags) {
1191 pre_syn(n);
1192 font_push('B');
1193 print_word("#include <");
1194 outflags &= ~MMAN_spc;
1195 } else {
1196 print_word("<");
1197 outflags &= ~MMAN_spc;
1198 font_push('I');
1199 }
1200 return(1);
1201 }
1202
1203 static void
1204 post_in(DECL_ARGS)
1205 {
1206
1207 if (MDOC_SYNPRETTY & n->flags) {
1208 outflags &= ~MMAN_spc;
1209 print_word(">");
1210 font_pop();
1211 outflags |= MMAN_br;
1212 } else {
1213 font_pop();
1214 outflags &= ~MMAN_spc;
1215 print_word(">");
1216 }
1217 }
1218
1219 static int
1220 pre_it(DECL_ARGS)
1221 {
1222 const struct mdoc_node *bln;
1223
1224 switch (n->type) {
1225 case (MDOC_HEAD):
1226 outflags |= MMAN_PP | MMAN_nl;
1227 bln = n->parent->parent;
1228 if (0 == bln->norm->Bl.comp ||
1229 (NULL == n->parent->prev &&
1230 NULL == bln->parent->prev))
1231 outflags |= MMAN_sp;
1232 outflags &= ~MMAN_br;
1233 switch (bln->norm->Bl.type) {
1234 case (LIST_item):
1235 return(0);
1236 case (LIST_inset):
1237 /* FALLTHROUGH */
1238 case (LIST_diag):
1239 /* FALLTHROUGH */
1240 case (LIST_ohang):
1241 if (bln->norm->Bl.type == LIST_diag)
1242 print_line(".B \"", 0);
1243 else
1244 print_line(".R \"", 0);
1245 outflags &= ~MMAN_spc;
1246 return(1);
1247 case (LIST_bullet):
1248 /* FALLTHROUGH */
1249 case (LIST_dash):
1250 /* FALLTHROUGH */
1251 case (LIST_hyphen):
1252 print_width(bln->norm->Bl.width, NULL, 0);
1253 TPremain = 0;
1254 outflags |= MMAN_nl;
1255 font_push('B');
1256 if (LIST_bullet == bln->norm->Bl.type)
1257 print_word("o");
1258 else
1259 print_word("-");
1260 font_pop();
1261 break;
1262 case (LIST_enum):
1263 print_width(bln->norm->Bl.width, NULL, 0);
1264 TPremain = 0;
1265 outflags |= MMAN_nl;
1266 print_count(&bln->norm->Bl.count);
1267 break;
1268 case (LIST_hang):
1269 print_width(bln->norm->Bl.width, n->child, 6);
1270 TPremain = 0;
1271 break;
1272 case (LIST_tag):
1273 print_width(bln->norm->Bl.width, n->child, 0);
1274 putchar('\n');
1275 outflags &= ~MMAN_spc;
1276 return(1);
1277 default:
1278 return(1);
1279 }
1280 outflags |= MMAN_nl;
1281 default:
1282 break;
1283 }
1284 return(1);
1285 }
1286
1287 /*
1288 * This function is called after closing out an indented block.
1289 * If we are inside an enclosing list, restore its indentation.
1290 */
1291 static void
1292 mid_it(void)
1293 {
1294 char buf[24];
1295
1296 /* Nothing to do outside a list. */
1297 if (0 == Bl_stack_len || 0 == Bl_stack[Bl_stack_len - 1])
1298 return;
1299
1300 /* The indentation has already been set up. */
1301 if (Bl_stack_post[Bl_stack_len - 1])
1302 return;
1303
1304 /* Restore the indentation of the enclosing list. */
1305 print_line(".RS", MMAN_Bk_susp);
1306 snprintf(buf, sizeof(buf), "%zun", Bl_stack[Bl_stack_len - 1]);
1307 print_word(buf);
1308
1309 /* Remeber to close out this .RS block later. */
1310 Bl_stack_post[Bl_stack_len - 1] = 1;
1311 }
1312
1313 static void
1314 post_it(DECL_ARGS)
1315 {
1316 const struct mdoc_node *bln;
1317
1318 bln = n->parent->parent;
1319
1320 switch (n->type) {
1321 case (MDOC_HEAD):
1322 switch (bln->norm->Bl.type) {
1323 case (LIST_diag):
1324 outflags &= ~MMAN_spc;
1325 print_word("\\ ");
1326 break;
1327 case (LIST_ohang):
1328 outflags |= MMAN_br;
1329 break;
1330 default:
1331 break;
1332 }
1333 break;
1334 case (MDOC_BODY):
1335 switch (bln->norm->Bl.type) {
1336 case (LIST_bullet):
1337 /* FALLTHROUGH */
1338 case (LIST_dash):
1339 /* FALLTHROUGH */
1340 case (LIST_hyphen):
1341 /* FALLTHROUGH */
1342 case (LIST_enum):
1343 /* FALLTHROUGH */
1344 case (LIST_hang):
1345 /* FALLTHROUGH */
1346 case (LIST_tag):
1347 assert(Bl_stack_len);
1348 Bl_stack[--Bl_stack_len] = 0;
1349
1350 /*
1351 * Our indentation had to be restored
1352 * after a child display or child list.
1353 * Close out that indentation block now.
1354 */
1355 if (Bl_stack_post[Bl_stack_len]) {
1356 print_line(".RE", MMAN_nl);
1357 Bl_stack_post[Bl_stack_len] = 0;
1358 }
1359 break;
1360 case (LIST_column):
1361 if (NULL != n->next) {
1362 putchar('\t');
1363 outflags &= ~MMAN_spc;
1364 }
1365 break;
1366 default:
1367 break;
1368 }
1369 break;
1370 default:
1371 break;
1372 }
1373 }
1374
1375 static void
1376 post_lb(DECL_ARGS)
1377 {
1378
1379 if (SEC_LIBRARY == n->sec)
1380 outflags |= MMAN_br;
1381 }
1382
1383 static int
1384 pre_lk(DECL_ARGS)
1385 {
1386 const struct mdoc_node *link, *descr;
1387
1388 if (NULL == (link = n->child))
1389 return(0);
1390
1391 if (NULL != (descr = link->next)) {
1392 font_push('I');
1393 while (NULL != descr) {
1394 print_word(descr->string);
1395 descr = descr->next;
1396 }
1397 print_word(":");
1398 font_pop();
1399 }
1400
1401 font_push('B');
1402 print_word(link->string);
1403 font_pop();
1404 return(0);
1405 }
1406
1407 static int
1408 pre_li(DECL_ARGS)
1409 {
1410
1411 font_push('R');
1412 return(1);
1413 }
1414
1415 static int
1416 pre_nm(DECL_ARGS)
1417 {
1418 char *name;
1419
1420 if (MDOC_BLOCK == n->type) {
1421 outflags |= MMAN_Bk;
1422 pre_syn(n);
1423 }
1424 if (MDOC_ELEM != n->type && MDOC_HEAD != n->type)
1425 return(1);
1426 name = n->child ? n->child->string : meta->name;
1427 if (NULL == name)
1428 return(0);
1429 if (MDOC_HEAD == n->type) {
1430 if (NULL == n->parent->prev)
1431 outflags |= MMAN_sp;
1432 print_block(".HP", 0);
1433 printf(" %zun", strlen(name) + 1);
1434 outflags |= MMAN_nl;
1435 }
1436 font_push('B');
1437 if (NULL == n->child)
1438 print_word(meta->name);
1439 return(1);
1440 }
1441
1442 static void
1443 post_nm(DECL_ARGS)
1444 {
1445
1446 switch (n->type) {
1447 case (MDOC_BLOCK):
1448 outflags &= ~MMAN_Bk;
1449 break;
1450 case (MDOC_HEAD):
1451 /* FALLTHROUGH */
1452 case (MDOC_ELEM):
1453 font_pop();
1454 break;
1455 default:
1456 break;
1457 }
1458 }
1459
1460 static int
1461 pre_no(DECL_ARGS)
1462 {
1463
1464 outflags |= MMAN_spc_force;
1465 return(1);
1466 }
1467
1468 static int
1469 pre_ns(DECL_ARGS)
1470 {
1471
1472 outflags &= ~MMAN_spc;
1473 return(0);
1474 }
1475
1476 static void
1477 post_pf(DECL_ARGS)
1478 {
1479
1480 outflags &= ~MMAN_spc;
1481 }
1482
1483 static int
1484 pre_pp(DECL_ARGS)
1485 {
1486
1487 if (MDOC_It != n->parent->tok)
1488 outflags |= MMAN_PP;
1489 outflags |= MMAN_sp | MMAN_nl;
1490 outflags &= ~MMAN_br;
1491 return(0);
1492 }
1493
1494 static int
1495 pre_rs(DECL_ARGS)
1496 {
1497
1498 if (SEC_SEE_ALSO == n->sec) {
1499 outflags |= MMAN_PP | MMAN_sp | MMAN_nl;
1500 outflags &= ~MMAN_br;
1501 }
1502 return(1);
1503 }
1504
1505 static int
1506 pre_sm(DECL_ARGS)
1507 {
1508
1509 assert(n->child && MDOC_TEXT == n->child->type);
1510 if (0 == strcmp("on", n->child->string))
1511 outflags |= MMAN_Sm | MMAN_spc;
1512 else
1513 outflags &= ~MMAN_Sm;
1514 return(0);
1515 }
1516
1517 static int
1518 pre_sp(DECL_ARGS)
1519 {
1520
1521 if (MMAN_PP & outflags) {
1522 outflags &= ~MMAN_PP;
1523 print_line(".PP", 0);
1524 } else
1525 print_line(".sp", 0);
1526 return(1);
1527 }
1528
1529 static void
1530 post_sp(DECL_ARGS)
1531 {
1532
1533 outflags |= MMAN_nl;
1534 }
1535
1536 static int
1537 pre_sy(DECL_ARGS)
1538 {
1539
1540 font_push('B');
1541 return(1);
1542 }
1543
1544 static int
1545 pre_vt(DECL_ARGS)
1546 {
1547
1548 if (MDOC_SYNPRETTY & n->flags) {
1549 switch (n->type) {
1550 case (MDOC_BLOCK):
1551 pre_syn(n);
1552 return(1);
1553 case (MDOC_BODY):
1554 break;
1555 default:
1556 return(0);
1557 }
1558 }
1559 font_push('I');
1560 return(1);
1561 }
1562
1563 static void
1564 post_vt(DECL_ARGS)
1565 {
1566
1567 if (MDOC_SYNPRETTY & n->flags && MDOC_BODY != n->type)
1568 return;
1569 font_pop();
1570 }
1571
1572 static int
1573 pre_xr(DECL_ARGS)
1574 {
1575
1576 n = n->child;
1577 if (NULL == n)
1578 return(0);
1579 print_node(meta, n);
1580 n = n->next;
1581 if (NULL == n)
1582 return(0);
1583 outflags &= ~MMAN_spc;
1584 print_word("(");
1585 print_node(meta, n);
1586 print_word(")");
1587 return(0);
1588 }
1589
1590 static int
1591 pre_ux(DECL_ARGS)
1592 {
1593
1594 print_word(manacts[n->tok].prefix);
1595 if (NULL == n->child)
1596 return(0);
1597 outflags &= ~MMAN_spc;
1598 print_word("\\ ");
1599 outflags &= ~MMAN_spc;
1600 return(1);
1601 }