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