]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_man.c
958a1e99f3d646fd7a2d19a55480b32699b4b26d
[mandoc.git] / mdoc_man.c
1 /* $Id: mdoc_man.c,v 1.13 2012/07/07 13:57:19 schwarze Exp $ */
2 /*
3 * Copyright (c) 2011, 2012 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 *m, \
32 const struct mdoc_node *n, \
33 struct mman *mm
34
35 struct mman {
36 int mode_space; /* spacing mode: 1 = on */
37 int need_space; /* next word needs prior ws */
38 int mode_keep; /* currently inside a keep */
39 int need_nl; /* next word needs prior nl */
40 };
41
42 struct manact {
43 int (*cond)(DECL_ARGS); /* DON'T run actions */
44 int (*pre)(DECL_ARGS); /* pre-node action */
45 void (*post)(DECL_ARGS); /* post-node action */
46 const char *prefix; /* pre-node string constant */
47 const char *suffix; /* post-node string constant */
48 };
49
50 static int cond_body(DECL_ARGS);
51 static int cond_head(DECL_ARGS);
52 static void post_bd(DECL_ARGS);
53 static void post_bk(DECL_ARGS);
54 static void post_dl(DECL_ARGS);
55 static void post_enc(DECL_ARGS);
56 static void post_nm(DECL_ARGS);
57 static void post_percent(DECL_ARGS);
58 static void post_pf(DECL_ARGS);
59 static void post_sect(DECL_ARGS);
60 static void post_sp(DECL_ARGS);
61 static int pre_ap(DECL_ARGS);
62 static int pre_bd(DECL_ARGS);
63 static int pre_bk(DECL_ARGS);
64 static int pre_br(DECL_ARGS);
65 static int pre_bx(DECL_ARGS);
66 static int pre_dl(DECL_ARGS);
67 static int pre_enc(DECL_ARGS);
68 static int pre_it(DECL_ARGS);
69 static int pre_nm(DECL_ARGS);
70 static int pre_ns(DECL_ARGS);
71 static int pre_pp(DECL_ARGS);
72 static int pre_sm(DECL_ARGS);
73 static int pre_sp(DECL_ARGS);
74 static int pre_sect(DECL_ARGS);
75 static int pre_ux(DECL_ARGS);
76 static int pre_xr(DECL_ARGS);
77 static void print_word(struct mman *, const char *);
78 static void print_offs(struct mman *, const char *);
79 static void print_node(DECL_ARGS);
80
81 static const struct manact manacts[MDOC_MAX + 1] = {
82 { NULL, pre_ap, NULL, NULL, NULL }, /* Ap */
83 { NULL, NULL, NULL, NULL, NULL }, /* Dd */
84 { NULL, NULL, NULL, NULL, NULL }, /* Dt */
85 { NULL, NULL, NULL, NULL, NULL }, /* Os */
86 { NULL, pre_sect, post_sect, ".SH", NULL }, /* Sh */
87 { NULL, pre_sect, post_sect, ".SS", NULL }, /* Ss */
88 { NULL, pre_pp, NULL, NULL, NULL }, /* Pp */
89 { cond_body, pre_dl, post_dl, NULL, NULL }, /* D1 */
90 { cond_body, pre_dl, post_dl, NULL, NULL }, /* Dl */
91 { cond_body, pre_bd, post_bd, NULL, NULL }, /* Bd */
92 { NULL, NULL, NULL, NULL, NULL }, /* Ed */
93 { NULL, NULL, NULL, NULL, NULL }, /* Bl */
94 { NULL, NULL, NULL, NULL, NULL }, /* El */
95 { NULL, pre_it, NULL, NULL, NULL }, /* _It */
96 { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Ad */
97 { NULL, NULL, NULL, NULL, NULL }, /* _An */
98 { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Ar */
99 { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Cd */
100 { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Cm */
101 { NULL, pre_enc, post_enc, "\\fR", "\\fP" }, /* Dv */
102 { NULL, pre_enc, post_enc, "\\fR", "\\fP" }, /* Er */
103 { NULL, pre_enc, post_enc, "\\fR", "\\fP" }, /* Ev */
104 { NULL, pre_enc, post_enc, "The \\fB",
105 "\\fP\nutility exits 0 on success, and >0 if an error occurs."
106 }, /* Ex */
107 { NULL, NULL, NULL, NULL, NULL }, /* _Fa */
108 { NULL, NULL, NULL, NULL, NULL }, /* _Fd */
109 { NULL, pre_enc, post_enc, "\\fB-", "\\fP" }, /* Fl */
110 { NULL, NULL, NULL, NULL, NULL }, /* _Fn */
111 { NULL, NULL, NULL, NULL, NULL }, /* _Ft */
112 { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Ic */
113 { NULL, NULL, NULL, NULL, NULL }, /* _In */
114 { NULL, pre_enc, post_enc, "\\fR", "\\fP" }, /* Li */
115 { cond_head, pre_enc, NULL, "\\- ", NULL }, /* Nd */
116 { NULL, pre_nm, post_nm, NULL, NULL }, /* Nm */
117 { cond_body, pre_enc, post_enc, "[", "]" }, /* Op */
118 { NULL, NULL, NULL, NULL, NULL }, /* Ot */
119 { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Pa */
120 { NULL, pre_enc, post_enc, "The \\fB",
121 "\\fP\nfunction returns the value 0 if successful;\n"
122 "otherwise the value -1 is returned and the global\n"
123 "variable \\fIerrno\\fP is set to indicate the error."
124 }, /* Rv */
125 { NULL, NULL, NULL, NULL, NULL }, /* St */
126 { NULL, NULL, NULL, NULL, NULL }, /* _Va */
127 { NULL, NULL, NULL, NULL, NULL }, /* _Vt */
128 { NULL, pre_xr, NULL, NULL, NULL }, /* Xr */
129 { NULL, NULL, post_percent, NULL, NULL }, /* _%A */
130 { NULL, NULL, NULL, NULL, NULL }, /* _%B */
131 { NULL, NULL, post_percent, NULL, NULL }, /* _%D */
132 { NULL, NULL, NULL, NULL, NULL }, /* _%I */
133 { NULL, pre_enc, post_percent, "\\fI", "\\fP" }, /* %J */
134 { NULL, NULL, NULL, NULL, NULL }, /* _%N */
135 { NULL, NULL, NULL, NULL, NULL }, /* _%O */
136 { NULL, NULL, NULL, NULL, NULL }, /* _%P */
137 { NULL, NULL, NULL, NULL, NULL }, /* _%R */
138 { NULL, pre_enc, post_percent, "\"", "\"" }, /* %T */
139 { NULL, NULL, NULL, NULL, NULL }, /* _%V */
140 { NULL, NULL, NULL, NULL, NULL }, /* Ac */
141 { cond_body, pre_enc, post_enc, "<", ">" }, /* Ao */
142 { cond_body, pre_enc, post_enc, "<", ">" }, /* Aq */
143 { NULL, NULL, NULL, NULL, NULL }, /* At */
144 { NULL, NULL, NULL, NULL, NULL }, /* Bc */
145 { NULL, NULL, NULL, NULL, NULL }, /* _Bf */
146 { cond_body, pre_enc, post_enc, "[", "]" }, /* Bo */
147 { cond_body, pre_enc, post_enc, "[", "]" }, /* Bq */
148 { NULL, pre_ux, NULL, "BSD/OS", NULL }, /* Bsx */
149 { NULL, pre_bx, NULL, NULL, NULL }, /* Bx */
150 { NULL, NULL, NULL, NULL, NULL }, /* Db */
151 { NULL, NULL, NULL, NULL, NULL }, /* Dc */
152 { cond_body, pre_enc, post_enc, "``", "''" }, /* Do */
153 { cond_body, pre_enc, post_enc, "``", "''" }, /* Dq */
154 { NULL, NULL, NULL, NULL, NULL }, /* _Ec */
155 { NULL, NULL, NULL, NULL, NULL }, /* _Ef */
156 { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Em */
157 { NULL, NULL, NULL, NULL, NULL }, /* _Eo */
158 { NULL, pre_ux, NULL, "FreeBSD", NULL }, /* Fx */
159 { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Ms */
160 { NULL, NULL, NULL, NULL, NULL }, /* No */
161 { NULL, pre_ns, NULL, NULL, NULL }, /* Ns */
162 { NULL, pre_ux, NULL, "NetBSD", NULL }, /* Nx */
163 { NULL, pre_ux, NULL, "OpenBSD", NULL }, /* Ox */
164 { NULL, NULL, NULL, NULL, NULL }, /* Pc */
165 { NULL, NULL, post_pf, NULL, NULL }, /* Pf */
166 { cond_body, pre_enc, post_enc, "(", ")" }, /* Po */
167 { cond_body, pre_enc, post_enc, "(", ")" }, /* Pq */
168 { NULL, NULL, NULL, NULL, NULL }, /* Qc */
169 { cond_body, pre_enc, post_enc, "`", "'" }, /* Ql */
170 { cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qo */
171 { cond_body, pre_enc, post_enc, "\"", "\"" }, /* Qq */
172 { NULL, NULL, NULL, NULL, NULL }, /* Re */
173 { cond_body, pre_pp, NULL, NULL, NULL }, /* Rs */
174 { NULL, NULL, NULL, NULL, NULL }, /* Sc */
175 { cond_body, pre_enc, post_enc, "`", "'" }, /* So */
176 { cond_body, pre_enc, post_enc, "`", "'" }, /* Sq */
177 { NULL, pre_sm, NULL, NULL, NULL }, /* Sm */
178 { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Sx */
179 { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Sy */
180 { NULL, pre_enc, post_enc, "\\fR", "\\fP" }, /* Tn */
181 { NULL, pre_ux, NULL, "UNIX", NULL }, /* Ux */
182 { NULL, NULL, NULL, NULL, NULL }, /* _Xc */
183 { NULL, NULL, NULL, NULL, NULL }, /* _Xo */
184 { NULL, NULL, NULL, NULL, NULL }, /* _Fo */
185 { NULL, NULL, NULL, NULL, NULL }, /* _Fc */
186 { cond_body, pre_enc, post_enc, "[", "]" }, /* Oo */
187 { NULL, NULL, NULL, NULL, NULL }, /* Oc */
188 { NULL, pre_bk, post_bk, NULL, NULL }, /* Bk */
189 { NULL, NULL, NULL, NULL, NULL }, /* Ek */
190 { NULL, pre_ux, NULL, "is currently in beta test.", NULL }, /* Bt */
191 { NULL, NULL, NULL, NULL, NULL }, /* Hf */
192 { NULL, NULL, NULL, NULL, NULL }, /* Fr */
193 { NULL, pre_ux, NULL, "currently under development.", NULL }, /* Ud */
194 { NULL, NULL, NULL, NULL, NULL }, /* _Lb */
195 { NULL, pre_pp, NULL, NULL, NULL }, /* Lp */
196 { NULL, NULL, NULL, NULL, NULL }, /* _Lk */
197 { NULL, NULL, NULL, NULL, NULL }, /* _Mt */
198 { cond_body, pre_enc, post_enc, "{", "}" }, /* Brq */
199 { cond_body, pre_enc, post_enc, "{", "}" }, /* Bro */
200 { NULL, NULL, NULL, NULL, NULL }, /* Brc */
201 { NULL, NULL, NULL, NULL, NULL }, /* _%C */
202 { NULL, NULL, NULL, NULL, NULL }, /* _Es */
203 { NULL, NULL, NULL, NULL, NULL }, /* _En */
204 { NULL, pre_ux, NULL, "DragonFly", NULL }, /* Dx */
205 { NULL, NULL, NULL, NULL, NULL }, /* _%Q */
206 { NULL, pre_br, NULL, NULL, NULL }, /* br */
207 { NULL, pre_sp, post_sp, NULL, NULL }, /* sp */
208 { NULL, NULL, NULL, NULL, NULL }, /* _%U */
209 { NULL, NULL, NULL, NULL, NULL }, /* _Ta */
210 { NULL, NULL, NULL, NULL, NULL }, /* ROOT */
211 };
212
213 static void
214 print_word(struct mman *mm, const char *s)
215 {
216
217 if (mm->need_nl) {
218 /*
219 * If we need a newline, print it now and start afresh.
220 */
221 putchar('\n');
222 mm->need_space = 0;
223 mm->need_nl = 0;
224 } else if (mm->need_space && '\0' != s[0])
225 /*
226 * If we need a space, only print it before
227 * (1) a nonzero length word;
228 * (2) a word that is non-punctuation; and
229 * (3) if punctuation, non-terminating puncutation.
230 */
231 if (NULL == strchr(".,:;)]?!", s[0]) || '\0' != s[1]) {
232 if (mm->mode_keep) {
233 putchar('\\');
234 putchar('~');
235 } else
236 putchar(' ');
237 }
238
239 /*
240 * Reassign needing space if we're not following opening
241 * punctuation.
242 */
243 mm->need_space = mm->mode_space &&
244 (('(' != s[0] && '[' != s[0]) || '\0' != s[1]);
245
246 for ( ; *s; s++) {
247 switch (*s) {
248 case (ASCII_NBRSP):
249 printf("\\~");
250 break;
251 case (ASCII_HYPH):
252 putchar('-');
253 break;
254 default:
255 putchar((unsigned char)*s);
256 break;
257 }
258 }
259 }
260
261 static void
262 print_offs(struct mman *mm, const char *v)
263 {
264 char buf[24];
265 struct roffsu su;
266 size_t sz;
267
268 if (NULL == v || '\0' == *v || 0 == strcmp(v, "left"))
269 sz = 0;
270 else if (0 == strcmp(v, "indent"))
271 sz = 6;
272 else if (0 == strcmp(v, "indent-two"))
273 sz = 12;
274 else if (a2roffsu(v, &su, SCALE_MAX)) {
275 print_word(mm, v);
276 return;
277 } else
278 sz = strlen(v);
279
280 snprintf(buf, sizeof(buf), "%ldn", sz);
281 print_word(mm, buf);
282 }
283
284 void
285 man_man(void *arg, const struct man *man)
286 {
287
288 /*
289 * Dump the keep buffer.
290 * We're guaranteed by now that this exists (is non-NULL).
291 * Flush stdout afterward, just in case.
292 */
293 fputs(mparse_getkeep(man_mparse(man)), stdout);
294 fflush(stdout);
295 }
296
297 void
298 man_mdoc(void *arg, const struct mdoc *mdoc)
299 {
300 const struct mdoc_meta *m;
301 const struct mdoc_node *n;
302 struct mman mm;
303
304 m = mdoc_meta(mdoc);
305 n = mdoc_node(mdoc);
306
307 printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
308 m->title, m->msec, m->date, m->os, m->vol);
309
310 memset(&mm, 0, sizeof(struct mman));
311
312 mm.mode_space = 1;
313 mm.need_nl = 1;
314 print_node(m, n, &mm);
315 putchar('\n');
316 }
317
318 static void
319 print_node(DECL_ARGS)
320 {
321 const struct mdoc_node *prev, *sub;
322 const struct manact *act;
323 int cond, do_sub;
324
325 /*
326 * Break the line if we were parsed subsequent the current node.
327 * This makes the page structure be more consistent.
328 */
329 prev = n->prev ? n->prev : n->parent;
330 if (prev && prev->line < n->line && MDOC_Ns != prev->tok)
331 mm->need_nl = 1;
332
333 act = NULL;
334 cond = 0;
335 do_sub = 1;
336
337 if (MDOC_TEXT == n->type) {
338 /*
339 * Make sure that we don't happen to start with a
340 * control character at the start of a line.
341 */
342 if (mm->need_nl && ('.' == *n->string ||
343 '\'' == *n->string)) {
344 print_word(mm, "\\&");
345 mm->need_space = 0;
346 }
347 print_word(mm, n->string);
348 } else {
349 /*
350 * Conditionally run the pre-node action handler for a
351 * node.
352 */
353 act = manacts + n->tok;
354 cond = NULL == act->cond || (*act->cond)(m, n, mm);
355 if (cond && act->pre)
356 do_sub = (*act->pre)(m, n, mm);
357 }
358
359 /*
360 * Conditionally run all child nodes.
361 * Note that this iterates over children instead of using
362 * recursion. This prevents unnecessary depth in the stack.
363 */
364 if (do_sub)
365 for (sub = n->child; sub; sub = sub->next)
366 print_node(m, sub, mm);
367
368 /*
369 * Lastly, conditionally run the post-node handler.
370 */
371 if (cond && act->post)
372 (*act->post)(m, n, mm);
373 }
374
375 static int
376 cond_head(DECL_ARGS)
377 {
378
379 return(MDOC_HEAD == n->type);
380 }
381
382 static int
383 cond_body(DECL_ARGS)
384 {
385
386 return(MDOC_BODY == n->type);
387 }
388
389 /*
390 * Output a font encoding before a node, e.g., \fR.
391 * This obviously has no trailing space.
392 */
393 static int
394 pre_enc(DECL_ARGS)
395 {
396 const char *prefix;
397
398 prefix = manacts[n->tok].prefix;
399 if (NULL == prefix)
400 return(1);
401 print_word(mm, prefix);
402 mm->need_space = 0;
403 return(1);
404 }
405
406 /*
407 * Output a font encoding subsequent a node, e.g., \fP.
408 */
409 static void
410 post_enc(DECL_ARGS)
411 {
412 const char *suffix;
413
414 suffix = manacts[n->tok].suffix;
415 if (NULL == suffix)
416 return;
417 mm->need_space = 0;
418 print_word(mm, suffix);
419 if (MDOC_Fl == n->tok && 0 == n->nchild)
420 mm->need_space = 0;
421 }
422
423 /*
424 * Used in listings (percent = %A, e.g.).
425 * FIXME: this is incomplete.
426 * It doesn't print a nice ", and" for lists.
427 */
428 static void
429 post_percent(DECL_ARGS)
430 {
431
432 post_enc(m, n, mm);
433 if (n->next)
434 print_word(mm, ",");
435 else {
436 print_word(mm, ".");
437 mm->need_nl = 1;
438 }
439 }
440
441 /*
442 * Print before a section header.
443 */
444 static int
445 pre_sect(DECL_ARGS)
446 {
447
448 if (MDOC_HEAD != n->type)
449 return(1);
450 mm->need_nl = 1;
451 print_word(mm, manacts[n->tok].prefix);
452 print_word(mm, "\"");
453 mm->need_space = 0;
454 return(1);
455 }
456
457 /*
458 * Print subsequent a section header.
459 */
460 static void
461 post_sect(DECL_ARGS)
462 {
463
464 if (MDOC_HEAD != n->type)
465 return;
466 mm->need_space = 0;
467 print_word(mm, "\"");
468 mm->need_nl = 1;
469 }
470
471 static int
472 pre_ap(DECL_ARGS)
473 {
474
475 mm->need_space = 0;
476 print_word(mm, "'");
477 mm->need_space = 0;
478 return(0);
479 }
480
481 static int
482 pre_bd(DECL_ARGS)
483 {
484
485 if (0 == n->norm->Bd.comp) {
486 mm->need_nl = 1;
487 print_word(mm, ".sp");
488 }
489 if (DISP_unfilled == n->norm->Bd.type ||
490 DISP_literal == n->norm->Bd.type) {
491 mm->need_nl = 1;
492 print_word(mm, ".nf");
493 }
494 mm->need_nl = 1;
495 print_word(mm, ".RS");
496 print_offs(mm, n->norm->Bd.offs);
497 mm->need_nl = 1;
498 return(1);
499 }
500
501 static void
502 post_bd(DECL_ARGS)
503 {
504
505 mm->need_nl = 1;
506 print_word(mm, ".RE");
507 if (DISP_unfilled == n->norm->Bd.type ||
508 DISP_literal == n->norm->Bd.type) {
509 mm->need_nl = 1;
510 print_word(mm, ".fi");
511 }
512 mm->need_nl = 1;
513 }
514
515 static int
516 pre_bk(DECL_ARGS)
517 {
518
519 switch (n->type) {
520 case (MDOC_BLOCK):
521 return(1);
522 case (MDOC_BODY):
523 mm->mode_keep = 1;
524 return(1);
525 default:
526 return(0);
527 }
528 }
529
530 static void
531 post_bk(DECL_ARGS)
532 {
533
534 if (MDOC_BODY == n->type)
535 mm->mode_keep = 0;
536 }
537
538 static int
539 pre_br(DECL_ARGS)
540 {
541
542 mm->need_nl = 1;
543 print_word(mm, ".br");
544 mm->need_nl = 1;
545 return(0);
546 }
547
548 static int
549 pre_bx(DECL_ARGS)
550 {
551
552 n = n->child;
553 if (n) {
554 print_word(mm, n->string);
555 mm->need_space = 0;
556 n = n->next;
557 }
558 print_word(mm, "BSD");
559 if (NULL == n)
560 return(0);
561 mm->need_space = 0;
562 print_word(mm, "-");
563 mm->need_space = 0;
564 print_word(mm, n->string);
565 return(0);
566 }
567
568 static int
569 pre_dl(DECL_ARGS)
570 {
571
572 mm->need_nl = 1;
573 print_word(mm, ".RS 6n");
574 mm->need_nl = 1;
575 return(1);
576 }
577
578 static void
579 post_dl(DECL_ARGS)
580 {
581
582 mm->need_nl = 1;
583 print_word(mm, ".RE");
584 mm->need_nl = 1;
585 }
586
587 static int
588 pre_it(DECL_ARGS)
589 {
590 const struct mdoc_node *bln;
591
592 if (MDOC_HEAD == n->type) {
593 mm->need_nl = 1;
594 print_word(mm, ".TP");
595 bln = n->parent->parent->prev;
596 switch (bln->norm->Bl.type) {
597 case (LIST_bullet):
598 print_word(mm, "4n");
599 mm->need_nl = 1;
600 print_word(mm, "\\fBo\\fP");
601 break;
602 default:
603 if (bln->norm->Bl.width)
604 print_word(mm, bln->norm->Bl.width);
605 break;
606 }
607 mm->need_nl = 1;
608 }
609 return(1);
610 }
611
612 static int
613 pre_nm(DECL_ARGS)
614 {
615
616 if (MDOC_ELEM != n->type && MDOC_HEAD != n->type)
617 return(1);
618 if (MDOC_SYNPRETTY & n->flags) {
619 mm->need_nl = 1;
620 print_word(mm, ".br");
621 mm->need_nl = 1;
622 }
623 print_word(mm, "\\fB");
624 mm->need_space = 0;
625 if (NULL == n->child)
626 print_word(mm, m->name);
627 return(1);
628 }
629
630 static void
631 post_nm(DECL_ARGS)
632 {
633
634 if (MDOC_ELEM != n->type && MDOC_HEAD != n->type)
635 return;
636 mm->need_space = 0;
637 print_word(mm, "\\fP");
638 }
639
640 static int
641 pre_ns(DECL_ARGS)
642 {
643
644 mm->need_space = 0;
645 return(0);
646 }
647
648 static void
649 post_pf(DECL_ARGS)
650 {
651
652 mm->need_space = 0;
653 }
654
655 static int
656 pre_pp(DECL_ARGS)
657 {
658
659 mm->need_nl = 1;
660 if (MDOC_It == n->parent->tok)
661 print_word(mm, ".sp");
662 else
663 print_word(mm, ".PP");
664 mm->need_nl = 1;
665 return(MDOC_Rs == n->tok);
666 }
667
668 static int
669 pre_sm(DECL_ARGS)
670 {
671
672 assert(n->child && MDOC_TEXT == n->child->type);
673 if (0 == strcmp("on", n->child->string))
674 mm->mode_space = 1;
675 else
676 mm->mode_space = 0;
677 return(0);
678 }
679
680 static int
681 pre_sp(DECL_ARGS)
682 {
683
684 mm->need_nl = 1;
685 print_word(mm, ".sp");
686 return(1);
687 }
688
689 static void
690 post_sp(DECL_ARGS)
691 {
692
693 mm->need_nl = 1;
694 }
695
696 static int
697 pre_xr(DECL_ARGS)
698 {
699
700 n = n->child;
701 if (NULL == n)
702 return(0);
703 print_node(m, n, mm);
704 n = n->next;
705 if (NULL == n)
706 return(0);
707 mm->need_space = 0;
708 print_word(mm, "(");
709 print_node(m, n, mm);
710 print_word(mm, ")");
711 return(0);
712 }
713
714 static int
715 pre_ux(DECL_ARGS)
716 {
717
718 print_word(mm, manacts[n->tok].prefix);
719 if (NULL == n->child)
720 return(0);
721 mm->need_space = 0;
722 print_word(mm, "\\~");
723 mm->need_space = 0;
724 return(1);
725 }