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