Annotation of src/usr.bin/mandoc/mdoc_term.c, Revision 1.122
1.122 ! schwarze 1: /* $Id: mdoc_term.c,v 1.121 2010/12/29 00:47:31 schwarze Exp $ */
1.1 kristaps 2: /*
1.122 ! schwarze 3: * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.95 schwarze 4: * Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org>
1.1 kristaps 5: *
6: * Permission to use, copy, modify, and distribute this software for any
1.2 schwarze 7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 9: *
1.2 schwarze 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 kristaps 17: */
18: #include <sys/types.h>
19:
20: #include <assert.h>
21: #include <ctype.h>
1.77 schwarze 22: #include <stdint.h>
1.1 kristaps 23: #include <stdio.h>
24: #include <stdlib.h>
25: #include <string.h>
26:
1.81 schwarze 27: #include "mandoc.h"
1.61 schwarze 28: #include "out.h"
1.1 kristaps 29: #include "term.h"
30: #include "mdoc.h"
1.61 schwarze 31: #include "chars.h"
32: #include "main.h"
1.54 schwarze 33:
1.51 schwarze 34: #define INDENT 5
35: #define HALFINDENT 3
1.1 kristaps 36:
37: struct termpair {
38: struct termpair *ppair;
1.27 schwarze 39: int count;
1.1 kristaps 40: };
41:
1.29 schwarze 42: #define DECL_ARGS struct termp *p, \
43: struct termpair *pair, \
1.60 schwarze 44: const struct mdoc_meta *m, \
45: const struct mdoc_node *n
1.1 kristaps 46:
47: struct termact {
48: int (*pre)(DECL_ARGS);
49: void (*post)(DECL_ARGS);
50: };
1.29 schwarze 51:
1.89 schwarze 52: static size_t a2width(const struct termp *, const char *);
53: static size_t a2height(const struct termp *, const char *);
54: static size_t a2offs(const struct termp *, const char *);
1.62 schwarze 55:
56: static void print_bvspace(struct termp *,
57: const struct mdoc_node *,
58: const struct mdoc_node *);
1.65 schwarze 59: static void print_mdoc_node(DECL_ARGS);
60: static void print_mdoc_nodelist(DECL_ARGS);
1.87 schwarze 61: static void print_mdoc_head(struct termp *, const void *);
62: static void print_mdoc_foot(struct termp *, const void *);
1.86 schwarze 63: static void synopsis_pre(struct termp *,
64: const struct mdoc_node *);
1.62 schwarze 65:
1.29 schwarze 66: static void termp____post(DECL_ARGS);
1.120 schwarze 67: static void termp__t_post(DECL_ARGS);
1.49 schwarze 68: static void termp_an_post(DECL_ARGS);
1.29 schwarze 69: static void termp_bd_post(DECL_ARGS);
1.90 schwarze 70: static void termp_bk_post(DECL_ARGS);
1.29 schwarze 71: static void termp_bl_post(DECL_ARGS);
72: static void termp_bx_post(DECL_ARGS);
73: static void termp_d1_post(DECL_ARGS);
74: static void termp_fo_post(DECL_ARGS);
75: static void termp_in_post(DECL_ARGS);
76: static void termp_it_post(DECL_ARGS);
77: static void termp_lb_post(DECL_ARGS);
1.94 schwarze 78: static void termp_nm_post(DECL_ARGS);
1.29 schwarze 79: static void termp_pf_post(DECL_ARGS);
1.107 schwarze 80: static void termp_quote_post(DECL_ARGS);
1.29 schwarze 81: static void termp_sh_post(DECL_ARGS);
82: static void termp_ss_post(DECL_ARGS);
83:
1.104 schwarze 84: static int termp__a_pre(DECL_ARGS);
1.120 schwarze 85: static int termp__t_pre(DECL_ARGS);
1.49 schwarze 86: static int termp_an_pre(DECL_ARGS);
1.29 schwarze 87: static int termp_ap_pre(DECL_ARGS);
88: static int termp_bd_pre(DECL_ARGS);
89: static int termp_bf_pre(DECL_ARGS);
1.90 schwarze 90: static int termp_bk_pre(DECL_ARGS);
1.73 schwarze 91: static int termp_bl_pre(DECL_ARGS);
1.54 schwarze 92: static int termp_bold_pre(DECL_ARGS);
1.29 schwarze 93: static int termp_bt_pre(DECL_ARGS);
94: static int termp_cd_pre(DECL_ARGS);
95: static int termp_d1_pre(DECL_ARGS);
96: static int termp_ex_pre(DECL_ARGS);
97: static int termp_fa_pre(DECL_ARGS);
1.107 schwarze 98: static int termp_fd_pre(DECL_ARGS);
1.29 schwarze 99: static int termp_fl_pre(DECL_ARGS);
100: static int termp_fn_pre(DECL_ARGS);
101: static int termp_fo_pre(DECL_ARGS);
102: static int termp_ft_pre(DECL_ARGS);
1.109 schwarze 103: static int termp_igndelim_pre(DECL_ARGS);
1.29 schwarze 104: static int termp_in_pre(DECL_ARGS);
105: static int termp_it_pre(DECL_ARGS);
1.65 schwarze 106: static int termp_li_pre(DECL_ARGS);
1.29 schwarze 107: static int termp_lk_pre(DECL_ARGS);
108: static int termp_nd_pre(DECL_ARGS);
109: static int termp_nm_pre(DECL_ARGS);
110: static int termp_ns_pre(DECL_ARGS);
1.107 schwarze 111: static int termp_quote_pre(DECL_ARGS);
1.29 schwarze 112: static int termp_rs_pre(DECL_ARGS);
113: static int termp_rv_pre(DECL_ARGS);
114: static int termp_sh_pre(DECL_ARGS);
115: static int termp_sm_pre(DECL_ARGS);
1.38 schwarze 116: static int termp_sp_pre(DECL_ARGS);
1.29 schwarze 117: static int termp_ss_pre(DECL_ARGS);
1.54 schwarze 118: static int termp_under_pre(DECL_ARGS);
1.29 schwarze 119: static int termp_ud_pre(DECL_ARGS);
1.69 schwarze 120: static int termp_vt_pre(DECL_ARGS);
1.29 schwarze 121: static int termp_xr_pre(DECL_ARGS);
122: static int termp_xx_pre(DECL_ARGS);
1.1 kristaps 123:
1.54 schwarze 124: static const struct termact termacts[MDOC_MAX] = {
1.11 schwarze 125: { termp_ap_pre, NULL }, /* Ap */
1.1 kristaps 126: { NULL, NULL }, /* Dd */
127: { NULL, NULL }, /* Dt */
128: { NULL, NULL }, /* Os */
129: { termp_sh_pre, termp_sh_post }, /* Sh */
130: { termp_ss_pre, termp_ss_post }, /* Ss */
1.54 schwarze 131: { termp_sp_pre, NULL }, /* Pp */
1.1 kristaps 132: { termp_d1_pre, termp_d1_post }, /* D1 */
133: { termp_d1_pre, termp_d1_post }, /* Dl */
134: { termp_bd_pre, termp_bd_post }, /* Bd */
135: { NULL, NULL }, /* Ed */
1.73 schwarze 136: { termp_bl_pre, termp_bl_post }, /* Bl */
1.1 kristaps 137: { NULL, NULL }, /* El */
138: { termp_it_pre, termp_it_post }, /* It */
1.99 schwarze 139: { termp_under_pre, NULL }, /* Ad */
1.49 schwarze 140: { termp_an_pre, termp_an_post }, /* An */
1.54 schwarze 141: { termp_under_pre, NULL }, /* Ar */
1.1 kristaps 142: { termp_cd_pre, NULL }, /* Cd */
1.54 schwarze 143: { termp_bold_pre, NULL }, /* Cm */
1.1 kristaps 144: { NULL, NULL }, /* Dv */
145: { NULL, NULL }, /* Er */
146: { NULL, NULL }, /* Ev */
147: { termp_ex_pre, NULL }, /* Ex */
148: { termp_fa_pre, NULL }, /* Fa */
1.86 schwarze 149: { termp_fd_pre, NULL }, /* Fd */
1.1 kristaps 150: { termp_fl_pre, NULL }, /* Fl */
1.86 schwarze 151: { termp_fn_pre, NULL }, /* Fn */
1.85 schwarze 152: { termp_ft_pre, NULL }, /* Ft */
1.54 schwarze 153: { termp_bold_pre, NULL }, /* Ic */
1.1 kristaps 154: { termp_in_pre, termp_in_post }, /* In */
1.65 schwarze 155: { termp_li_pre, NULL }, /* Li */
1.1 kristaps 156: { termp_nd_pre, NULL }, /* Nd */
1.94 schwarze 157: { termp_nm_pre, termp_nm_post }, /* Nm */
1.107 schwarze 158: { termp_quote_pre, termp_quote_post }, /* Op */
1.1 kristaps 159: { NULL, NULL }, /* Ot */
1.54 schwarze 160: { termp_under_pre, NULL }, /* Pa */
1.1 kristaps 161: { termp_rv_pre, NULL }, /* Rv */
1.32 schwarze 162: { NULL, NULL }, /* St */
1.54 schwarze 163: { termp_under_pre, NULL }, /* Va */
1.86 schwarze 164: { termp_vt_pre, NULL }, /* Vt */
1.1 kristaps 165: { termp_xr_pre, NULL }, /* Xr */
1.104 schwarze 166: { termp__a_pre, termp____post }, /* %A */
1.58 schwarze 167: { termp_under_pre, termp____post }, /* %B */
1.1 kristaps 168: { NULL, termp____post }, /* %D */
1.58 schwarze 169: { termp_under_pre, termp____post }, /* %I */
1.54 schwarze 170: { termp_under_pre, termp____post }, /* %J */
1.1 kristaps 171: { NULL, termp____post }, /* %N */
172: { NULL, termp____post }, /* %O */
173: { NULL, termp____post }, /* %P */
174: { NULL, termp____post }, /* %R */
1.120 schwarze 175: { termp__t_pre, termp__t_post }, /* %T */
1.1 kristaps 176: { NULL, termp____post }, /* %V */
177: { NULL, NULL }, /* Ac */
1.107 schwarze 178: { termp_quote_pre, termp_quote_post }, /* Ao */
179: { termp_quote_pre, termp_quote_post }, /* Aq */
1.32 schwarze 180: { NULL, NULL }, /* At */
1.1 kristaps 181: { NULL, NULL }, /* Bc */
182: { termp_bf_pre, NULL }, /* Bf */
1.107 schwarze 183: { termp_quote_pre, termp_quote_post }, /* Bo */
184: { termp_quote_pre, termp_quote_post }, /* Bq */
1.26 schwarze 185: { termp_xx_pre, NULL }, /* Bsx */
1.1 kristaps 186: { NULL, termp_bx_post }, /* Bx */
187: { NULL, NULL }, /* Db */
188: { NULL, NULL }, /* Dc */
1.107 schwarze 189: { termp_quote_pre, termp_quote_post }, /* Do */
190: { termp_quote_pre, termp_quote_post }, /* Dq */
1.73 schwarze 191: { NULL, NULL }, /* Ec */ /* FIXME: no space */
1.1 kristaps 192: { NULL, NULL }, /* Ef */
1.54 schwarze 193: { termp_under_pre, NULL }, /* Em */
1.1 kristaps 194: { NULL, NULL }, /* Eo */
1.26 schwarze 195: { termp_xx_pre, NULL }, /* Fx */
1.98 schwarze 196: { termp_bold_pre, NULL }, /* Ms */
1.109 schwarze 197: { termp_igndelim_pre, NULL }, /* No */
1.1 kristaps 198: { termp_ns_pre, NULL }, /* Ns */
1.26 schwarze 199: { termp_xx_pre, NULL }, /* Nx */
200: { termp_xx_pre, NULL }, /* Ox */
1.1 kristaps 201: { NULL, NULL }, /* Pc */
1.109 schwarze 202: { termp_igndelim_pre, termp_pf_post }, /* Pf */
1.107 schwarze 203: { termp_quote_pre, termp_quote_post }, /* Po */
204: { termp_quote_pre, termp_quote_post }, /* Pq */
1.1 kristaps 205: { NULL, NULL }, /* Qc */
1.107 schwarze 206: { termp_quote_pre, termp_quote_post }, /* Ql */
207: { termp_quote_pre, termp_quote_post }, /* Qo */
208: { termp_quote_pre, termp_quote_post }, /* Qq */
1.1 kristaps 209: { NULL, NULL }, /* Re */
210: { termp_rs_pre, NULL }, /* Rs */
211: { NULL, NULL }, /* Sc */
1.107 schwarze 212: { termp_quote_pre, termp_quote_post }, /* So */
213: { termp_quote_pre, termp_quote_post }, /* Sq */
1.1 kristaps 214: { termp_sm_pre, NULL }, /* Sm */
1.54 schwarze 215: { termp_under_pre, NULL }, /* Sx */
216: { termp_bold_pre, NULL }, /* Sy */
1.1 kristaps 217: { NULL, NULL }, /* Tn */
1.26 schwarze 218: { termp_xx_pre, NULL }, /* Ux */
1.1 kristaps 219: { NULL, NULL }, /* Xc */
220: { NULL, NULL }, /* Xo */
221: { termp_fo_pre, termp_fo_post }, /* Fo */
222: { NULL, NULL }, /* Fc */
1.107 schwarze 223: { termp_quote_pre, termp_quote_post }, /* Oo */
1.1 kristaps 224: { NULL, NULL }, /* Oc */
1.90 schwarze 225: { termp_bk_pre, termp_bk_post }, /* Bk */
1.1 kristaps 226: { NULL, NULL }, /* Ek */
227: { termp_bt_pre, NULL }, /* Bt */
228: { NULL, NULL }, /* Hf */
229: { NULL, NULL }, /* Fr */
230: { termp_ud_pre, NULL }, /* Ud */
1.32 schwarze 231: { NULL, termp_lb_post }, /* Lb */
1.54 schwarze 232: { termp_sp_pre, NULL }, /* Lp */
1.1 kristaps 233: { termp_lk_pre, NULL }, /* Lk */
1.54 schwarze 234: { termp_under_pre, NULL }, /* Mt */
1.107 schwarze 235: { termp_quote_pre, termp_quote_post }, /* Brq */
236: { termp_quote_pre, termp_quote_post }, /* Bro */
1.1 kristaps 237: { NULL, NULL }, /* Brc */
1.58 schwarze 238: { NULL, termp____post }, /* %C */
239: { NULL, NULL }, /* Es */ /* TODO */
240: { NULL, NULL }, /* En */ /* TODO */
1.26 schwarze 241: { termp_xx_pre, NULL }, /* Dx */
1.58 schwarze 242: { NULL, termp____post }, /* %Q */
1.54 schwarze 243: { termp_sp_pre, NULL }, /* br */
1.38 schwarze 244: { termp_sp_pre, NULL }, /* sp */
1.62 schwarze 245: { termp_under_pre, termp____post }, /* %U */
1.85 schwarze 246: { NULL, NULL }, /* Ta */
1.1 kristaps 247: };
248:
249:
1.55 schwarze 250: void
1.61 schwarze 251: terminal_mdoc(void *arg, const struct mdoc *mdoc)
1.1 kristaps 252: {
1.55 schwarze 253: const struct mdoc_node *n;
254: const struct mdoc_meta *m;
1.61 schwarze 255: struct termp *p;
256:
257: p = (struct termp *)arg;
1.71 schwarze 258:
259: p->overstep = 0;
1.80 schwarze 260: p->maxrmargin = p->defrmargin;
1.89 schwarze 261: p->tabwidth = term_len(p, 5);
1.61 schwarze 262:
263: if (NULL == p->symtab)
264: switch (p->enc) {
265: case (TERMENC_ASCII):
266: p->symtab = chars_init(CHARS_ASCII);
267: break;
268: default:
269: abort();
270: /* NOTREACHED */
271: }
1.55 schwarze 272:
273: n = mdoc_node(mdoc);
274: m = mdoc_meta(mdoc);
275:
1.87 schwarze 276: term_begin(p, print_mdoc_head, print_mdoc_foot, m);
277:
1.55 schwarze 278: if (n->child)
1.65 schwarze 279: print_mdoc_nodelist(p, NULL, m, n->child);
1.87 schwarze 280:
281: term_end(p);
1.1 kristaps 282: }
283:
284:
285: static void
1.65 schwarze 286: print_mdoc_nodelist(DECL_ARGS)
1.1 kristaps 287: {
288:
1.65 schwarze 289: print_mdoc_node(p, pair, m, n);
1.60 schwarze 290: if (n->next)
1.65 schwarze 291: print_mdoc_nodelist(p, pair, m, n->next);
1.1 kristaps 292: }
293:
294:
1.54 schwarze 295: /* ARGSUSED */
1.1 kristaps 296: static void
1.65 schwarze 297: print_mdoc_node(DECL_ARGS)
1.1 kristaps 298: {
1.65 schwarze 299: int chld;
300: const void *font;
1.1 kristaps 301: struct termpair npair;
1.28 schwarze 302: size_t offset, rmargin;
1.1 kristaps 303:
1.54 schwarze 304: chld = 1;
1.28 schwarze 305: offset = p->offset;
306: rmargin = p->rmargin;
1.65 schwarze 307: font = term_fontq(p);
1.1 kristaps 308:
1.63 schwarze 309: memset(&npair, 0, sizeof(struct termpair));
1.1 kristaps 310: npair.ppair = pair;
1.122 ! schwarze 311:
! 312: switch (n->type) {
! 313: case (MDOC_TEXT):
! 314: term_word(p, n->string);
! 315: break;
! 316: case (MDOC_TBL):
! 317: term_tbl(p, n->span);
! 318: break;
! 319: default:
! 320: if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
! 321: chld = (*termacts[n->tok].pre)
! 322: (p, &npair, m, n);
! 323: break;
! 324: }
1.65 schwarze 325:
1.95 schwarze 326: /*
327: * Keeps only work until the end of a line. If a keep was
328: * invoked in a prior line, revert it to PREKEEP.
1.116 schwarze 329: *
330: * Also let SYNPRETTY sections behave as if they were wrapped
331: * in a `Bk' block.
1.95 schwarze 332: */
333:
1.116 schwarze 334: if (TERMP_KEEP & p->flags || MDOC_SYNPRETTY & n->flags) {
1.95 schwarze 335: if (n->prev && n->prev->line != n->line) {
336: p->flags &= ~TERMP_KEEP;
337: p->flags |= TERMP_PREKEEP;
338: } else if (NULL == n->prev) {
339: if (n->parent && n->parent->line != n->line) {
340: p->flags &= ~TERMP_KEEP;
341: p->flags |= TERMP_PREKEEP;
342: }
343: }
344: }
1.116 schwarze 345:
346: /*
347: * Since SYNPRETTY sections aren't "turned off" with `Ek',
348: * we have to intuit whether we should disable formatting.
349: */
350:
351: if ( ! (MDOC_SYNPRETTY & n->flags) &&
352: ((n->prev && MDOC_SYNPRETTY & n->prev->flags) ||
353: (n->parent && MDOC_SYNPRETTY & n->parent->flags)))
354: p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.95 schwarze 355:
1.60 schwarze 356: if (chld && n->child)
1.65 schwarze 357: print_mdoc_nodelist(p, &npair, m, n->child);
1.1 kristaps 358:
1.65 schwarze 359: term_fontpopq(p, font);
1.1 kristaps 360:
1.122 ! schwarze 361: switch (n->type) {
! 362: case (MDOC_TEXT):
! 363: break;
! 364: case (MDOC_TBL):
! 365: break;
! 366: default:
! 367: if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
! 368: break;
1.95 schwarze 369: (void)(*termacts[n->tok].post)(p, &npair, m, n);
1.93 schwarze 370:
371: /*
372: * Explicit end tokens not only call the post
373: * handler, but also tell the respective block
374: * that it must not call the post handler again.
375: */
1.95 schwarze 376: if (ENDBODY_NOT != n->end)
1.93 schwarze 377: n->pending->flags |= MDOC_ENDED;
378:
379: /*
380: * End of line terminating an implicit block
381: * while an explicit block is still open.
382: * Continue the explicit block without spacing.
383: */
384: if (ENDBODY_NOSPACE == n->end)
385: p->flags |= TERMP_NOSPACE;
1.122 ! schwarze 386: break;
1.93 schwarze 387: }
1.28 schwarze 388:
1.78 schwarze 389: if (MDOC_EOS & n->flags)
390: p->flags |= TERMP_SENTENCE;
391:
1.28 schwarze 392: p->offset = offset;
393: p->rmargin = rmargin;
1.1 kristaps 394: }
395:
396:
397: static void
1.87 schwarze 398: print_mdoc_foot(struct termp *p, const void *arg)
1.1 kristaps 399: {
1.63 schwarze 400: char buf[DATESIZ], os[BUFSIZ];
1.87 schwarze 401: const struct mdoc_meta *m;
402:
403: m = (const struct mdoc_meta *)arg;
1.1 kristaps 404:
1.65 schwarze 405: term_fontrepl(p, TERMFONT_NONE);
406:
1.7 schwarze 407: /*
408: * Output the footer in new-groff style, that is, three columns
409: * with the middle being the manual date and flanking columns
410: * being the operating system:
411: *
412: * SYSTEM DATE SYSTEM
413: */
414:
1.62 schwarze 415: time2a(m->date, buf, DATESIZ);
1.63 schwarze 416: strlcpy(os, m->os, BUFSIZ);
1.1 kristaps 417:
418: term_vspace(p);
419:
1.7 schwarze 420: p->offset = 0;
1.89 schwarze 421: p->rmargin = (p->maxrmargin -
422: term_strlen(p, buf) + term_len(p, 1)) / 2;
1.1 kristaps 423: p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
424:
425: term_word(p, os);
426: term_flushln(p);
427:
1.7 schwarze 428: p->offset = p->rmargin;
1.89 schwarze 429: p->rmargin = p->maxrmargin - term_strlen(p, os);
1.1 kristaps 430: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.7 schwarze 431:
432: term_word(p, buf);
433: term_flushln(p);
434:
1.1 kristaps 435: p->offset = p->rmargin;
436: p->rmargin = p->maxrmargin;
437: p->flags &= ~TERMP_NOBREAK;
1.7 schwarze 438: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.1 kristaps 439:
1.7 schwarze 440: term_word(p, os);
1.1 kristaps 441: term_flushln(p);
1.7 schwarze 442:
443: p->offset = 0;
444: p->rmargin = p->maxrmargin;
445: p->flags = 0;
1.1 kristaps 446: }
447:
448:
449: static void
1.87 schwarze 450: print_mdoc_head(struct termp *p, const void *arg)
1.1 kristaps 451: {
1.63 schwarze 452: char buf[BUFSIZ], title[BUFSIZ];
1.87 schwarze 453: const struct mdoc_meta *m;
454:
455: m = (const struct mdoc_meta *)arg;
1.1 kristaps 456:
457: p->rmargin = p->maxrmargin;
458: p->offset = 0;
459:
460: /*
461: * The header is strange. It has three components, which are
462: * really two with the first duplicated. It goes like this:
463: *
464: * IDENTIFIER TITLE IDENTIFIER
465: *
466: * The IDENTIFIER is NAME(SECTION), which is the command-name
467: * (if given, or "unknown" if not) followed by the manual page
468: * section. These are given in `Dt'. The TITLE is a free-form
469: * string depending on the manual volume. If not specified, it
470: * switches on the manual section.
471: */
472:
1.60 schwarze 473: assert(m->vol);
1.63 schwarze 474: strlcpy(buf, m->vol, BUFSIZ);
1.1 kristaps 475:
1.60 schwarze 476: if (m->arch) {
1.63 schwarze 477: strlcat(buf, " (", BUFSIZ);
478: strlcat(buf, m->arch, BUFSIZ);
479: strlcat(buf, ")", BUFSIZ);
1.1 kristaps 480: }
481:
1.79 schwarze 482: snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
1.1 kristaps 483:
484: p->offset = 0;
1.89 schwarze 485: p->rmargin = (p->maxrmargin -
486: term_strlen(p, buf) + term_len(p, 1)) / 2;
1.1 kristaps 487: p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
488:
489: term_word(p, title);
490: term_flushln(p);
491:
492: p->offset = p->rmargin;
1.89 schwarze 493: p->rmargin = p->maxrmargin - term_strlen(p, title);
1.8 schwarze 494: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.1 kristaps 495:
496: term_word(p, buf);
497: term_flushln(p);
498:
499: p->offset = p->rmargin;
500: p->rmargin = p->maxrmargin;
501: p->flags &= ~TERMP_NOBREAK;
502: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
503:
504: term_word(p, title);
505: term_flushln(p);
506:
1.8 schwarze 507: p->offset = 0;
1.1 kristaps 508: p->rmargin = p->maxrmargin;
509: p->flags &= ~TERMP_NOSPACE;
510: }
511:
512:
513: static size_t
1.89 schwarze 514: a2height(const struct termp *p, const char *v)
1.1 kristaps 515: {
1.61 schwarze 516: struct roffsu su;
1.1 kristaps 517:
1.89 schwarze 518: assert(v);
519: if ( ! a2roffsu(v, &su, SCALE_VS))
520: SCALE_VS_INIT(&su, term_len(p, 1));
1.1 kristaps 521:
1.89 schwarze 522: return(term_vspan(p, &su));
1.61 schwarze 523: }
1.34 schwarze 524:
1.1 kristaps 525:
1.61 schwarze 526: static size_t
1.89 schwarze 527: a2width(const struct termp *p, const char *v)
1.61 schwarze 528: {
529: struct roffsu su;
1.1 kristaps 530:
1.88 schwarze 531: assert(v);
532: if ( ! a2roffsu(v, &su, SCALE_MAX))
1.89 schwarze 533: SCALE_HS_INIT(&su, term_strlen(p, v));
1.1 kristaps 534:
1.89 schwarze 535: return(term_hspan(p, &su));
1.1 kristaps 536: }
537:
538:
539: static size_t
1.89 schwarze 540: a2offs(const struct termp *p, const char *v)
1.1 kristaps 541: {
1.61 schwarze 542: struct roffsu su;
1.1 kristaps 543:
1.88 schwarze 544: if ('\0' == *v)
1.61 schwarze 545: return(0);
1.88 schwarze 546: else if (0 == strcmp(v, "left"))
1.9 schwarze 547: return(0);
1.88 schwarze 548: else if (0 == strcmp(v, "indent"))
1.89 schwarze 549: return(term_len(p, INDENT + 1));
1.88 schwarze 550: else if (0 == strcmp(v, "indent-two"))
1.89 schwarze 551: return(term_len(p, (INDENT + 1) * 2));
1.88 schwarze 552: else if ( ! a2roffsu(v, &su, SCALE_MAX))
1.89 schwarze 553: SCALE_HS_INIT(&su, term_strlen(p, v));
1.10 schwarze 554:
1.89 schwarze 555: return(term_hspan(p, &su));
1.1 kristaps 556: }
557:
558:
1.68 schwarze 559: /*
560: * Determine how much space to print out before block elements of `It'
561: * (and thus `Bl') and `Bd'. And then go ahead and print that space,
562: * too.
563: */
1.45 schwarze 564: static void
1.61 schwarze 565: print_bvspace(struct termp *p,
1.1 kristaps 566: const struct mdoc_node *bl,
1.60 schwarze 567: const struct mdoc_node *n)
1.1 kristaps 568: {
1.60 schwarze 569: const struct mdoc_node *nn;
1.1 kristaps 570:
571: term_newln(p);
1.88 schwarze 572:
1.121 schwarze 573: if (MDOC_Bd == bl->tok && bl->norm->Bd.comp)
1.88 schwarze 574: return;
1.121 schwarze 575: if (MDOC_Bl == bl->tok && bl->norm->Bl.comp)
1.45 schwarze 576: return;
577:
1.60 schwarze 578: /* Do not vspace directly after Ss/Sh. */
1.1 kristaps 579:
1.60 schwarze 580: for (nn = n; nn; nn = nn->parent) {
581: if (MDOC_BLOCK != nn->type)
1.1 kristaps 582: continue;
1.60 schwarze 583: if (MDOC_Ss == nn->tok)
1.45 schwarze 584: return;
1.60 schwarze 585: if (MDOC_Sh == nn->tok)
1.45 schwarze 586: return;
1.60 schwarze 587: if (NULL == nn->prev)
1.1 kristaps 588: continue;
589: break;
590: }
591:
1.60 schwarze 592: /* A `-column' does not assert vspace within the list. */
1.45 schwarze 593:
1.121 schwarze 594: if (MDOC_Bl == bl->tok && LIST_column == bl->norm->Bl.type)
1.60 schwarze 595: if (n->prev && MDOC_It == n->prev->tok)
1.45 schwarze 596: return;
597:
1.60 schwarze 598: /* A `-diag' without body does not vspace. */
599:
1.121 schwarze 600: if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->Bl.type)
1.60 schwarze 601: if (n->prev && MDOC_It == n->prev->tok) {
602: assert(n->prev->body);
603: if (NULL == n->prev->body->child)
1.45 schwarze 604: return;
605: }
606:
607: term_vspace(p);
1.1 kristaps 608: }
609:
610:
611: /* ARGSUSED */
612: static int
613: termp_it_pre(DECL_ARGS)
614: {
1.60 schwarze 615: const struct mdoc_node *bl, *nn;
1.1 kristaps 616: char buf[7];
1.95 schwarze 617: int i;
1.68 schwarze 618: size_t width, offset, ncols, dcol;
1.82 schwarze 619: enum mdoc_list type;
1.1 kristaps 620:
1.60 schwarze 621: if (MDOC_BLOCK == n->type) {
1.61 schwarze 622: print_bvspace(p, n->parent->parent, n);
1.45 schwarze 623: return(1);
624: }
1.1 kristaps 625:
1.60 schwarze 626: bl = n->parent->parent->parent;
1.121 schwarze 627: type = bl->norm->Bl.type;
1.1 kristaps 628:
1.68 schwarze 629: /*
630: * First calculate width and offset. This is pretty easy unless
631: * we're a -column list, in which case all prior columns must
632: * be accounted for.
633: */
634:
635: width = offset = 0;
636:
1.121 schwarze 637: if (bl->norm->Bl.offs)
638: offset = a2offs(p, bl->norm->Bl.offs);
1.66 schwarze 639:
1.1 kristaps 640: switch (type) {
1.82 schwarze 641: case (LIST_column):
1.85 schwarze 642: if (MDOC_HEAD == n->type)
1.1 kristaps 643: break;
1.88 schwarze 644:
1.66 schwarze 645: /*
1.68 schwarze 646: * Imitate groff's column handling:
647: * - For each earlier column, add its width.
648: * - For less than 5 columns, add four more blanks per
649: * column.
650: * - For exactly 5 columns, add three more blank per
651: * column.
652: * - For more than 5 columns, add only one column.
1.66 schwarze 653: */
1.121 schwarze 654: ncols = bl->norm->Bl.ncols;
1.95 schwarze 655:
1.68 schwarze 656: /* LINTED */
1.89 schwarze 657: dcol = ncols < 5 ? term_len(p, 4) :
658: ncols == 5 ? term_len(p, 3) : term_len(p, 1);
1.68 schwarze 659:
1.85 schwarze 660: /*
661: * Calculate the offset by applying all prior MDOC_BODY,
662: * so we stop at the MDOC_HEAD (NULL == nn->prev).
663: */
664:
1.68 schwarze 665: for (i = 0, nn = n->prev;
1.85 schwarze 666: nn->prev && i < (int)ncols;
1.68 schwarze 667: nn = nn->prev, i++)
668: offset += dcol + a2width
1.121 schwarze 669: (p, bl->norm->Bl.cols[i]);
1.66 schwarze 670:
671: /*
1.68 schwarze 672: * When exceeding the declared number of columns, leave
673: * the remaining widths at 0. This will later be
674: * adjusted to the default width of 10, or, for the last
675: * column, stretched to the right margin.
1.46 schwarze 676: */
1.68 schwarze 677: if (i >= (int)ncols)
678: break;
1.46 schwarze 679:
1.66 schwarze 680: /*
1.68 schwarze 681: * Use the declared column widths, extended as explained
682: * in the preceding paragraph.
1.66 schwarze 683: */
1.121 schwarze 684: width = a2width(p, bl->norm->Bl.cols[i]) + dcol;
1.1 kristaps 685: break;
686: default:
1.121 schwarze 687: if (NULL == bl->norm->Bl.width)
1.68 schwarze 688: break;
689:
690: /*
691: * Note: buffer the width by 2, which is groff's magic
692: * number for buffering single arguments. See the above
693: * handling for column for how this changes.
694: */
1.121 schwarze 695: assert(bl->norm->Bl.width);
696: width = a2width(p, bl->norm->Bl.width) + term_len(p, 2);
1.1 kristaps 697: break;
698: }
699:
700: /*
701: * List-type can override the width in the case of fixed-head
702: * values (bullet, dash/hyphen, enum). Tags need a non-zero
1.53 schwarze 703: * offset.
1.1 kristaps 704: */
705:
706: switch (type) {
1.82 schwarze 707: case (LIST_bullet):
1.1 kristaps 708: /* FALLTHROUGH */
1.82 schwarze 709: case (LIST_dash):
1.1 kristaps 710: /* FALLTHROUGH */
1.82 schwarze 711: case (LIST_hyphen):
1.89 schwarze 712: if (width < term_len(p, 4))
713: width = term_len(p, 4);
1.19 schwarze 714: break;
1.82 schwarze 715: case (LIST_enum):
1.89 schwarze 716: if (width < term_len(p, 5))
717: width = term_len(p, 5);
1.1 kristaps 718: break;
1.82 schwarze 719: case (LIST_hang):
1.33 schwarze 720: if (0 == width)
1.89 schwarze 721: width = term_len(p, 8);
1.33 schwarze 722: break;
1.82 schwarze 723: case (LIST_column):
1.41 schwarze 724: /* FALLTHROUGH */
1.82 schwarze 725: case (LIST_tag):
1.1 kristaps 726: if (0 == width)
1.89 schwarze 727: width = term_len(p, 10);
1.1 kristaps 728: break;
729: default:
730: break;
731: }
732:
733: /*
1.16 schwarze 734: * Whitespace control. Inset bodies need an initial space,
735: * while diagonal bodies need two.
1.1 kristaps 736: */
737:
1.42 schwarze 738: p->flags |= TERMP_NOSPACE;
739:
1.1 kristaps 740: switch (type) {
1.82 schwarze 741: case (LIST_diag):
1.60 schwarze 742: if (MDOC_BODY == n->type)
1.48 schwarze 743: term_word(p, "\\ \\ ");
1.42 schwarze 744: break;
1.82 schwarze 745: case (LIST_inset):
1.60 schwarze 746: if (MDOC_BODY == n->type)
1.42 schwarze 747: term_word(p, "\\ ");
1.1 kristaps 748: break;
749: default:
750: break;
751: }
752:
1.42 schwarze 753: p->flags |= TERMP_NOSPACE;
754:
1.1 kristaps 755: switch (type) {
1.82 schwarze 756: case (LIST_diag):
1.60 schwarze 757: if (MDOC_HEAD == n->type)
1.65 schwarze 758: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 759: break;
760: default:
761: break;
762: }
763:
764: /*
1.68 schwarze 765: * Pad and break control. This is the tricky part. These flags
766: * are documented in term_flushln() in term.c. Note that we're
767: * going to unset all of these flags in termp_it_post() when we
768: * exit.
1.1 kristaps 769: */
770:
771: switch (type) {
1.82 schwarze 772: case (LIST_bullet):
1.1 kristaps 773: /* FALLTHROUGH */
1.82 schwarze 774: case (LIST_dash):
1.1 kristaps 775: /* FALLTHROUGH */
1.82 schwarze 776: case (LIST_enum):
1.1 kristaps 777: /* FALLTHROUGH */
1.82 schwarze 778: case (LIST_hyphen):
1.60 schwarze 779: if (MDOC_HEAD == n->type)
1.33 schwarze 780: p->flags |= TERMP_NOBREAK;
781: else
782: p->flags |= TERMP_NOLPAD;
783: break;
1.82 schwarze 784: case (LIST_hang):
1.60 schwarze 785: if (MDOC_HEAD == n->type)
1.33 schwarze 786: p->flags |= TERMP_NOBREAK;
787: else
788: p->flags |= TERMP_NOLPAD;
789:
1.60 schwarze 790: if (MDOC_HEAD != n->type)
1.47 schwarze 791: break;
792:
793: /*
794: * This is ugly. If `-hang' is specified and the body
795: * is a `Bl' or `Bd', then we want basically to nullify
796: * the "overstep" effect in term_flushln() and treat
797: * this as a `-ohang' list instead.
798: */
1.60 schwarze 799: if (n->next->child &&
800: (MDOC_Bl == n->next->child->tok ||
801: MDOC_Bd == n->next->child->tok)) {
1.47 schwarze 802: p->flags &= ~TERMP_NOBREAK;
803: p->flags &= ~TERMP_NOLPAD;
804: } else
1.33 schwarze 805: p->flags |= TERMP_HANG;
806: break;
1.82 schwarze 807: case (LIST_tag):
1.60 schwarze 808: if (MDOC_HEAD == n->type)
1.42 schwarze 809: p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE;
1.1 kristaps 810: else
811: p->flags |= TERMP_NOLPAD;
1.33 schwarze 812:
1.60 schwarze 813: if (MDOC_HEAD != n->type)
1.33 schwarze 814: break;
1.60 schwarze 815: if (NULL == n->next || NULL == n->next->child)
1.33 schwarze 816: p->flags |= TERMP_DANGLE;
1.1 kristaps 817: break;
1.82 schwarze 818: case (LIST_column):
1.85 schwarze 819: if (MDOC_HEAD == n->type)
820: break;
821:
822: if (NULL == n->next)
823: p->flags &= ~TERMP_NOBREAK;
824: else
825: p->flags |= TERMP_NOBREAK;
826:
827: assert(n->prev);
828: if (MDOC_BODY == n->prev->type)
829: p->flags |= TERMP_NOLPAD;
830:
1.1 kristaps 831: break;
1.82 schwarze 832: case (LIST_diag):
1.60 schwarze 833: if (MDOC_HEAD == n->type)
1.1 kristaps 834: p->flags |= TERMP_NOBREAK;
835: break;
836: default:
837: break;
838: }
839:
840: /*
841: * Margin control. Set-head-width lists have their right
842: * margins shortened. The body for these lists has the offset
843: * necessarily lengthened. Everybody gets the offset.
844: */
845:
846: p->offset += offset;
847:
848: switch (type) {
1.82 schwarze 849: case (LIST_hang):
1.47 schwarze 850: /*
851: * Same stipulation as above, regarding `-hang'. We
852: * don't want to recalculate rmargin and offsets when
853: * using `Bd' or `Bl' within `-hang' overstep lists.
854: */
1.60 schwarze 855: if (MDOC_HEAD == n->type && n->next->child &&
856: (MDOC_Bl == n->next->child->tok ||
857: MDOC_Bd == n->next->child->tok))
1.47 schwarze 858: break;
859: /* FALLTHROUGH */
1.82 schwarze 860: case (LIST_bullet):
1.1 kristaps 861: /* FALLTHROUGH */
1.82 schwarze 862: case (LIST_dash):
1.1 kristaps 863: /* FALLTHROUGH */
1.82 schwarze 864: case (LIST_enum):
1.1 kristaps 865: /* FALLTHROUGH */
1.82 schwarze 866: case (LIST_hyphen):
1.33 schwarze 867: /* FALLTHROUGH */
1.82 schwarze 868: case (LIST_tag):
1.41 schwarze 869: assert(width);
1.60 schwarze 870: if (MDOC_HEAD == n->type)
1.1 kristaps 871: p->rmargin = p->offset + width;
872: else
873: p->offset += width;
874: break;
1.82 schwarze 875: case (LIST_column):
1.41 schwarze 876: assert(width);
1.1 kristaps 877: p->rmargin = p->offset + width;
1.43 schwarze 878: /*
879: * XXX - this behaviour is not documented: the
880: * right-most column is filled to the right margin.
881: */
1.85 schwarze 882: if (MDOC_HEAD == n->type)
883: break;
884: if (NULL == n->next && p->rmargin < p->maxrmargin)
1.43 schwarze 885: p->rmargin = p->maxrmargin;
1.1 kristaps 886: break;
887: default:
888: break;
889: }
890:
891: /*
892: * The dash, hyphen, bullet and enum lists all have a special
1.12 schwarze 893: * HEAD character (temporarily bold, in some cases).
1.1 kristaps 894: */
895:
1.60 schwarze 896: if (MDOC_HEAD == n->type)
1.1 kristaps 897: switch (type) {
1.82 schwarze 898: case (LIST_bullet):
1.65 schwarze 899: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 900: term_word(p, "\\[bu]");
1.65 schwarze 901: term_fontpop(p);
1.1 kristaps 902: break;
1.82 schwarze 903: case (LIST_dash):
1.1 kristaps 904: /* FALLTHROUGH */
1.82 schwarze 905: case (LIST_hyphen):
1.65 schwarze 906: term_fontpush(p, TERMFONT_BOLD);
1.35 schwarze 907: term_word(p, "\\(hy");
1.65 schwarze 908: term_fontpop(p);
1.1 kristaps 909: break;
1.82 schwarze 910: case (LIST_enum):
1.1 kristaps 911: (pair->ppair->ppair->count)++;
1.68 schwarze 912: snprintf(buf, sizeof(buf), "%d.",
1.1 kristaps 913: pair->ppair->ppair->count);
914: term_word(p, buf);
915: break;
916: default:
917: break;
918: }
1.12 schwarze 919:
1.1 kristaps 920: /*
921: * If we're not going to process our children, indicate so here.
922: */
923:
924: switch (type) {
1.82 schwarze 925: case (LIST_bullet):
1.1 kristaps 926: /* FALLTHROUGH */
1.82 schwarze 927: case (LIST_item):
1.1 kristaps 928: /* FALLTHROUGH */
1.82 schwarze 929: case (LIST_dash):
1.1 kristaps 930: /* FALLTHROUGH */
1.82 schwarze 931: case (LIST_hyphen):
1.1 kristaps 932: /* FALLTHROUGH */
1.82 schwarze 933: case (LIST_enum):
1.60 schwarze 934: if (MDOC_HEAD == n->type)
1.1 kristaps 935: return(0);
936: break;
1.82 schwarze 937: case (LIST_column):
1.85 schwarze 938: if (MDOC_HEAD == n->type)
1.1 kristaps 939: return(0);
940: break;
941: default:
942: break;
943: }
944:
945: return(1);
946: }
947:
948:
949: /* ARGSUSED */
950: static void
951: termp_it_post(DECL_ARGS)
952: {
1.82 schwarze 953: enum mdoc_list type;
1.1 kristaps 954:
1.68 schwarze 955: if (MDOC_BLOCK == n->type)
1.1 kristaps 956: return;
957:
1.121 schwarze 958: type = n->parent->parent->parent->norm->Bl.type;
1.1 kristaps 959:
960: switch (type) {
1.82 schwarze 961: case (LIST_item):
1.44 schwarze 962: /* FALLTHROUGH */
1.82 schwarze 963: case (LIST_diag):
1.1 kristaps 964: /* FALLTHROUGH */
1.82 schwarze 965: case (LIST_inset):
1.60 schwarze 966: if (MDOC_BODY == n->type)
1.74 schwarze 967: term_newln(p);
1.1 kristaps 968: break;
1.82 schwarze 969: case (LIST_column):
1.85 schwarze 970: if (MDOC_BODY == n->type)
1.1 kristaps 971: term_flushln(p);
972: break;
973: default:
1.74 schwarze 974: term_newln(p);
1.1 kristaps 975: break;
976: }
977:
1.68 schwarze 978: /*
979: * Now that our output is flushed, we can reset our tags. Since
980: * only `It' sets these flags, we're free to assume that nobody
981: * has munged them in the meanwhile.
982: */
983:
984: p->flags &= ~TERMP_DANGLE;
985: p->flags &= ~TERMP_NOBREAK;
986: p->flags &= ~TERMP_TWOSPACE;
987: p->flags &= ~TERMP_NOLPAD;
988: p->flags &= ~TERMP_HANG;
1.1 kristaps 989: }
990:
991:
992: /* ARGSUSED */
993: static int
994: termp_nm_pre(DECL_ARGS)
995: {
996:
1.94 schwarze 997: if (MDOC_BLOCK == n->type)
998: return(1);
999:
1000: if (MDOC_BODY == n->type) {
1001: if (NULL == n->child)
1002: return(0);
1003: p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1004: p->offset += term_len(p, 1) +
1005: (NULL == n->prev->child ? term_strlen(p, m->name) :
1006: MDOC_TEXT == n->prev->child->type ?
1007: term_strlen(p, n->prev->child->string) :
1008: term_len(p, 5));
1009: return(1);
1010: }
1011:
1.81 schwarze 1012: if (NULL == n->child && NULL == m->name)
1.94 schwarze 1013: return(0);
1.81 schwarze 1014:
1.97 schwarze 1015: if (MDOC_HEAD == n->type)
1016: synopsis_pre(p, n->parent);
1.65 schwarze 1017:
1.94 schwarze 1018: if (MDOC_HEAD == n->type && n->next->child) {
1.105 schwarze 1019: p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
1020: p->rmargin = p->offset + term_len(p, 1);
1021: if (NULL == n->child) {
1022: p->rmargin += term_strlen(p, m->name);
1023: } else if (MDOC_TEXT == n->child->type) {
1024: p->rmargin += term_strlen(p, n->child->string);
1025: if (n->child->next)
1026: p->flags |= TERMP_HANG;
1027: } else {
1028: p->rmargin += term_len(p, 5);
1029: p->flags |= TERMP_HANG;
1030: }
1.94 schwarze 1031: }
1032:
1.65 schwarze 1033: term_fontpush(p, TERMFONT_BOLD);
1.60 schwarze 1034: if (NULL == n->child)
1035: term_word(p, m->name);
1.1 kristaps 1036: return(1);
1037: }
1038:
1039:
1.94 schwarze 1040: /* ARGSUSED */
1041: static void
1042: termp_nm_post(DECL_ARGS)
1043: {
1044:
1045: if (MDOC_HEAD == n->type && n->next->child) {
1046: term_flushln(p);
1047: p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
1048: } else if (MDOC_BODY == n->type && n->child) {
1049: term_flushln(p);
1050: p->flags &= ~TERMP_NOLPAD;
1051: }
1052: }
1053:
1054:
1.1 kristaps 1055: /* ARGSUSED */
1056: static int
1057: termp_fl_pre(DECL_ARGS)
1058: {
1059:
1.65 schwarze 1060: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1061: term_word(p, "\\-");
1.67 schwarze 1062:
1063: if (n->child)
1064: p->flags |= TERMP_NOSPACE;
1.73 schwarze 1065: else if (n->next && n->next->line == n->line)
1066: p->flags |= TERMP_NOSPACE;
1.67 schwarze 1067:
1.1 kristaps 1068: return(1);
1.49 schwarze 1069: }
1070:
1071:
1072: /* ARGSUSED */
1073: static int
1.104 schwarze 1074: termp__a_pre(DECL_ARGS)
1075: {
1076:
1077: if (n->prev && MDOC__A == n->prev->tok)
1078: if (NULL == n->next || MDOC__A != n->next->tok)
1079: term_word(p, "and");
1080:
1081: return(1);
1082: }
1083:
1084:
1085: /* ARGSUSED */
1086: static int
1.49 schwarze 1087: termp_an_pre(DECL_ARGS)
1088: {
1089:
1.60 schwarze 1090: if (NULL == n->child)
1.49 schwarze 1091: return(1);
1092:
1093: /*
1.60 schwarze 1094: * If not in the AUTHORS section, `An -split' will cause
1095: * newlines to occur before the author name. If in the AUTHORS
1096: * section, by default, the first `An' invocation is nosplit,
1097: * then all subsequent ones, regardless of whether interspersed
1098: * with other macros/text, are split. -split, in this case,
1099: * will override the condition of the implied first -nosplit.
1.49 schwarze 1100: */
1101:
1.60 schwarze 1102: if (n->sec == SEC_AUTHORS) {
1.49 schwarze 1103: if ( ! (TERMP_ANPREC & p->flags)) {
1104: if (TERMP_SPLIT & p->flags)
1105: term_newln(p);
1106: return(1);
1107: }
1108: if (TERMP_NOSPLIT & p->flags)
1109: return(1);
1110: term_newln(p);
1111: return(1);
1112: }
1113:
1114: if (TERMP_SPLIT & p->flags)
1115: term_newln(p);
1116:
1117: return(1);
1118: }
1119:
1120:
1121: /* ARGSUSED */
1122: static void
1123: termp_an_post(DECL_ARGS)
1124: {
1125:
1.60 schwarze 1126: if (n->child) {
1127: if (SEC_AUTHORS == n->sec)
1.49 schwarze 1128: p->flags |= TERMP_ANPREC;
1129: return;
1130: }
1131:
1.121 schwarze 1132: if (AUTH_split == n->norm->An.auth) {
1.49 schwarze 1133: p->flags &= ~TERMP_NOSPLIT;
1134: p->flags |= TERMP_SPLIT;
1.121 schwarze 1135: } else if (AUTH_nosplit == n->norm->An.auth) {
1.49 schwarze 1136: p->flags &= ~TERMP_SPLIT;
1137: p->flags |= TERMP_NOSPLIT;
1138: }
1139:
1.1 kristaps 1140: }
1141:
1142:
1143: /* ARGSUSED */
1144: static int
1145: termp_ns_pre(DECL_ARGS)
1146: {
1147:
1148: p->flags |= TERMP_NOSPACE;
1149: return(1);
1150: }
1151:
1152:
1153: /* ARGSUSED */
1154: static int
1155: termp_rs_pre(DECL_ARGS)
1156: {
1157:
1.60 schwarze 1158: if (SEC_SEE_ALSO != n->sec)
1.57 schwarze 1159: return(1);
1.60 schwarze 1160: if (MDOC_BLOCK == n->type && n->prev)
1.1 kristaps 1161: term_vspace(p);
1162: return(1);
1163: }
1164:
1165:
1166: /* ARGSUSED */
1167: static int
1168: termp_rv_pre(DECL_ARGS)
1169: {
1.53 schwarze 1170: const struct mdoc_node *nn;
1.1 kristaps 1171:
1172: term_newln(p);
1173: term_word(p, "The");
1174:
1.60 schwarze 1175: for (nn = n->child; nn; nn = nn->next) {
1.65 schwarze 1176: term_fontpush(p, TERMFONT_BOLD);
1.53 schwarze 1177: term_word(p, nn->string);
1.65 schwarze 1178: term_fontpop(p);
1.53 schwarze 1179: p->flags |= TERMP_NOSPACE;
1180: if (nn->next && NULL == nn->next->next)
1181: term_word(p, "(), and");
1182: else if (nn->next)
1183: term_word(p, "(),");
1184: else
1185: term_word(p, "()");
1186: }
1187:
1.81 schwarze 1188: if (n->child && n->child->next)
1.53 schwarze 1189: term_word(p, "functions return");
1190: else
1191: term_word(p, "function returns");
1.1 kristaps 1192:
1.53 schwarze 1193: term_word(p, "the value 0 if successful; otherwise the value "
1194: "-1 is returned and the global variable");
1.1 kristaps 1195:
1.65 schwarze 1196: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1197: term_word(p, "errno");
1.65 schwarze 1198: term_fontpop(p);
1.1 kristaps 1199:
1200: term_word(p, "is set to indicate the error.");
1.84 schwarze 1201: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1202:
1.53 schwarze 1203: return(0);
1.1 kristaps 1204: }
1205:
1206:
1207: /* ARGSUSED */
1208: static int
1209: termp_ex_pre(DECL_ARGS)
1210: {
1.53 schwarze 1211: const struct mdoc_node *nn;
1.1 kristaps 1212:
1.53 schwarze 1213: term_word(p, "The");
1.1 kristaps 1214:
1.60 schwarze 1215: for (nn = n->child; nn; nn = nn->next) {
1.65 schwarze 1216: term_fontpush(p, TERMFONT_BOLD);
1.53 schwarze 1217: term_word(p, nn->string);
1.65 schwarze 1218: term_fontpop(p);
1.53 schwarze 1219: p->flags |= TERMP_NOSPACE;
1220: if (nn->next && NULL == nn->next->next)
1221: term_word(p, ", and");
1222: else if (nn->next)
1223: term_word(p, ",");
1224: else
1225: p->flags &= ~TERMP_NOSPACE;
1226: }
1227:
1.81 schwarze 1228: if (n->child && n->child->next)
1.53 schwarze 1229: term_word(p, "utilities exit");
1230: else
1231: term_word(p, "utility exits");
1232:
1233: term_word(p, "0 on success, and >0 if an error occurs.");
1.84 schwarze 1234: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1235:
1.53 schwarze 1236: return(0);
1.1 kristaps 1237: }
1238:
1239:
1240: /* ARGSUSED */
1241: static int
1242: termp_nd_pre(DECL_ARGS)
1243: {
1.25 schwarze 1244:
1.60 schwarze 1245: if (MDOC_BODY != n->type)
1.25 schwarze 1246: return(1);
1247:
1248: #if defined(__OpenBSD__) || defined(__linux__)
1249: term_word(p, "\\(en");
1.24 schwarze 1250: #else
1251: term_word(p, "\\(em");
1252: #endif
1.1 kristaps 1253: return(1);
1254: }
1255:
1256:
1257: /* ARGSUSED */
1.73 schwarze 1258: static int
1259: termp_bl_pre(DECL_ARGS)
1260: {
1261:
1262: return(MDOC_HEAD != n->type);
1263: }
1264:
1265:
1266: /* ARGSUSED */
1.1 kristaps 1267: static void
1268: termp_bl_post(DECL_ARGS)
1269: {
1270:
1.60 schwarze 1271: if (MDOC_BLOCK == n->type)
1.1 kristaps 1272: term_newln(p);
1273: }
1274:
1275:
1276: /* ARGSUSED */
1277: static int
1278: termp_xr_pre(DECL_ARGS)
1279: {
1.60 schwarze 1280: const struct mdoc_node *nn;
1.1 kristaps 1281:
1.72 schwarze 1282: if (NULL == n->child)
1283: return(0);
1284:
1285: assert(MDOC_TEXT == n->child->type);
1.60 schwarze 1286: nn = n->child;
1.10 schwarze 1287:
1.60 schwarze 1288: term_word(p, nn->string);
1289: if (NULL == (nn = nn->next))
1.1 kristaps 1290: return(0);
1291: p->flags |= TERMP_NOSPACE;
1292: term_word(p, "(");
1.60 schwarze 1293: term_word(p, nn->string);
1.1 kristaps 1294: term_word(p, ")");
1.60 schwarze 1295:
1.1 kristaps 1296: return(0);
1297: }
1298:
1299:
1.86 schwarze 1300: /*
1301: * This decides how to assert whitespace before any of the SYNOPSIS set
1302: * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1303: * macro combos).
1304: */
1305: static void
1306: synopsis_pre(struct termp *p, const struct mdoc_node *n)
1307: {
1308: /*
1309: * Obviously, if we're not in a SYNOPSIS or no prior macros
1310: * exist, do nothing.
1311: */
1.92 schwarze 1312: if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1.86 schwarze 1313: return;
1314:
1315: /*
1316: * If we're the second in a pair of like elements, emit our
1317: * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1318: * case we soldier on.
1319: */
1320: if (n->prev->tok == n->tok &&
1321: MDOC_Ft != n->tok &&
1322: MDOC_Fo != n->tok &&
1323: MDOC_Fn != n->tok) {
1324: term_newln(p);
1325: return;
1326: }
1327:
1328: /*
1329: * If we're one of the SYNOPSIS set and non-like pair-wise after
1330: * another (or Fn/Fo, which we've let slip through) then assert
1331: * vertical space, else only newline and move on.
1332: */
1333: switch (n->prev->tok) {
1334: case (MDOC_Fd):
1335: /* FALLTHROUGH */
1336: case (MDOC_Fn):
1337: /* FALLTHROUGH */
1338: case (MDOC_Fo):
1339: /* FALLTHROUGH */
1340: case (MDOC_In):
1341: /* FALLTHROUGH */
1342: case (MDOC_Vt):
1343: term_vspace(p);
1344: break;
1345: case (MDOC_Ft):
1346: if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1347: term_vspace(p);
1348: break;
1349: }
1350: /* FALLTHROUGH */
1351: default:
1352: term_newln(p);
1353: break;
1354: }
1355: }
1356:
1357:
1.69 schwarze 1358: static int
1359: termp_vt_pre(DECL_ARGS)
1360: {
1361:
1.86 schwarze 1362: if (MDOC_ELEM == n->type) {
1363: synopsis_pre(p, n);
1.69 schwarze 1364: return(termp_under_pre(p, pair, m, n));
1.86 schwarze 1365: } else if (MDOC_BLOCK == n->type) {
1366: synopsis_pre(p, n);
1367: return(1);
1368: } else if (MDOC_HEAD == n->type)
1.69 schwarze 1369: return(0);
1370:
1371: return(termp_under_pre(p, pair, m, n));
1372: }
1373:
1374:
1.1 kristaps 1375: /* ARGSUSED */
1376: static int
1.54 schwarze 1377: termp_bold_pre(DECL_ARGS)
1.1 kristaps 1378: {
1379:
1.65 schwarze 1380: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1381: return(1);
1382: }
1383:
1384:
1385: /* ARGSUSED */
1.86 schwarze 1386: static int
1387: termp_fd_pre(DECL_ARGS)
1.1 kristaps 1388: {
1389:
1.86 schwarze 1390: synopsis_pre(p, n);
1391: return(termp_bold_pre(p, pair, m, n));
1.1 kristaps 1392: }
1393:
1394:
1395: /* ARGSUSED */
1396: static int
1397: termp_sh_pre(DECL_ARGS)
1398: {
1.60 schwarze 1399:
1400: /* No vspace between consecutive `Sh' calls. */
1401:
1402: switch (n->type) {
1.52 schwarze 1403: case (MDOC_BLOCK):
1.60 schwarze 1404: if (n->prev && MDOC_Sh == n->prev->tok)
1405: if (NULL == n->prev->body->child)
1.52 schwarze 1406: break;
1407: term_vspace(p);
1408: break;
1.1 kristaps 1409: case (MDOC_HEAD):
1.65 schwarze 1410: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1411: break;
1412: case (MDOC_BODY):
1.89 schwarze 1413: p->offset = term_len(p, INDENT);
1.1 kristaps 1414: break;
1415: default:
1416: break;
1417: }
1418: return(1);
1419: }
1420:
1421:
1422: /* ARGSUSED */
1423: static void
1424: termp_sh_post(DECL_ARGS)
1425: {
1426:
1.60 schwarze 1427: switch (n->type) {
1.1 kristaps 1428: case (MDOC_HEAD):
1429: term_newln(p);
1430: break;
1431: case (MDOC_BODY):
1432: term_newln(p);
1433: p->offset = 0;
1434: break;
1435: default:
1436: break;
1437: }
1438: }
1439:
1440:
1441: /* ARGSUSED */
1442: static int
1443: termp_bt_pre(DECL_ARGS)
1444: {
1445:
1446: term_word(p, "is currently in beta test.");
1.84 schwarze 1447: p->flags |= TERMP_SENTENCE;
1.59 schwarze 1448: return(0);
1.1 kristaps 1449: }
1450:
1451:
1452: /* ARGSUSED */
1453: static void
1454: termp_lb_post(DECL_ARGS)
1455: {
1456:
1.77 schwarze 1457: if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.57 schwarze 1458: term_newln(p);
1.1 kristaps 1459: }
1460:
1461:
1462: /* ARGSUSED */
1463: static int
1464: termp_ud_pre(DECL_ARGS)
1465: {
1466:
1467: term_word(p, "currently under development.");
1.84 schwarze 1468: p->flags |= TERMP_SENTENCE;
1.60 schwarze 1469: return(0);
1.1 kristaps 1470: }
1471:
1472:
1473: /* ARGSUSED */
1474: static int
1475: termp_d1_pre(DECL_ARGS)
1476: {
1477:
1.60 schwarze 1478: if (MDOC_BLOCK != n->type)
1.1 kristaps 1479: return(1);
1480: term_newln(p);
1.89 schwarze 1481: p->offset += term_len(p, (INDENT + 1));
1.1 kristaps 1482: return(1);
1483: }
1484:
1485:
1486: /* ARGSUSED */
1487: static void
1488: termp_d1_post(DECL_ARGS)
1489: {
1490:
1.60 schwarze 1491: if (MDOC_BLOCK != n->type)
1.1 kristaps 1492: return;
1493: term_newln(p);
1494: }
1495:
1496:
1497: /* ARGSUSED */
1498: static int
1499: termp_ft_pre(DECL_ARGS)
1500: {
1501:
1.85 schwarze 1502: /* NB: MDOC_LINE does not effect this! */
1.86 schwarze 1503: synopsis_pre(p, n);
1.65 schwarze 1504: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1505: return(1);
1506: }
1507:
1508:
1509: /* ARGSUSED */
1510: static int
1511: termp_fn_pre(DECL_ARGS)
1512: {
1.60 schwarze 1513: const struct mdoc_node *nn;
1.1 kristaps 1514:
1.86 schwarze 1515: synopsis_pre(p, n);
1.85 schwarze 1516:
1.65 schwarze 1517: term_fontpush(p, TERMFONT_BOLD);
1.60 schwarze 1518: term_word(p, n->child->string);
1.65 schwarze 1519: term_fontpop(p);
1.1 kristaps 1520:
1521: p->flags |= TERMP_NOSPACE;
1522: term_word(p, "(");
1523:
1.60 schwarze 1524: for (nn = n->child->next; nn; nn = nn->next) {
1.65 schwarze 1525: term_fontpush(p, TERMFONT_UNDER);
1.60 schwarze 1526: term_word(p, nn->string);
1.65 schwarze 1527: term_fontpop(p);
1528:
1.60 schwarze 1529: if (nn->next)
1.1 kristaps 1530: term_word(p, ",");
1531: }
1532:
1533: term_word(p, ")");
1534:
1.92 schwarze 1535: if (MDOC_SYNPRETTY & n->flags)
1.1 kristaps 1536: term_word(p, ";");
1537:
1538: return(0);
1539: }
1540:
1541:
1542: /* ARGSUSED */
1543: static int
1544: termp_fa_pre(DECL_ARGS)
1545: {
1.60 schwarze 1546: const struct mdoc_node *nn;
1.1 kristaps 1547:
1.60 schwarze 1548: if (n->parent->tok != MDOC_Fo) {
1.65 schwarze 1549: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 1550: return(1);
1551: }
1552:
1.60 schwarze 1553: for (nn = n->child; nn; nn = nn->next) {
1.65 schwarze 1554: term_fontpush(p, TERMFONT_UNDER);
1.60 schwarze 1555: term_word(p, nn->string);
1.65 schwarze 1556: term_fontpop(p);
1557:
1.60 schwarze 1558: if (nn->next)
1.1 kristaps 1559: term_word(p, ",");
1560: }
1561:
1.60 schwarze 1562: if (n->child && n->next && n->next->tok == MDOC_Fa)
1.1 kristaps 1563: term_word(p, ",");
1564:
1565: return(0);
1566: }
1567:
1568:
1569: /* ARGSUSED */
1570: static int
1571: termp_bd_pre(DECL_ARGS)
1572: {
1.99 schwarze 1573: size_t tabwidth, rm, rmax;
1.60 schwarze 1574: const struct mdoc_node *nn;
1.1 kristaps 1575:
1.60 schwarze 1576: if (MDOC_BLOCK == n->type) {
1.61 schwarze 1577: print_bvspace(p, n, n);
1.45 schwarze 1578: return(1);
1.73 schwarze 1579: } else if (MDOC_HEAD == n->type)
1580: return(0);
1.1 kristaps 1581:
1.121 schwarze 1582: if (n->norm->Bd.offs)
1583: p->offset += a2offs(p, n->norm->Bd.offs);
1.60 schwarze 1584:
1585: /*
1586: * If -ragged or -filled are specified, the block does nothing
1587: * but change the indentation. If -unfilled or -literal are
1588: * specified, text is printed exactly as entered in the display:
1589: * for macro lines, a newline is appended to the line. Blank
1590: * lines are allowed.
1591: */
1.48 schwarze 1592:
1.121 schwarze 1593: if (DISP_literal != n->norm->Bd.type &&
1594: DISP_unfilled != n->norm->Bd.type)
1.1 kristaps 1595: return(1);
1596:
1.75 schwarze 1597: tabwidth = p->tabwidth;
1.89 schwarze 1598: p->tabwidth = term_len(p, 8);
1.77 schwarze 1599: rm = p->rmargin;
1600: rmax = p->maxrmargin;
1601: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1602:
1.60 schwarze 1603: for (nn = n->child; nn; nn = nn->next) {
1.100 schwarze 1604: print_mdoc_node(p, pair, m, nn);
1.108 schwarze 1605: /*
1606: * If the printed node flushes its own line, then we
1607: * needn't do it here as well. This is hacky, but the
1608: * notion of selective eoln whitespace is pretty dumb
1609: * anyway, so don't sweat it.
1610: */
1611: switch (nn->tok) {
1.112 schwarze 1612: case (MDOC_Sm):
1613: /* FALLTHROUGH */
1.108 schwarze 1614: case (MDOC_br):
1615: /* FALLTHROUGH */
1616: case (MDOC_sp):
1617: /* FALLTHROUGH */
1618: case (MDOC_Bl):
1.115 schwarze 1619: /* FALLTHROUGH */
1620: case (MDOC_D1):
1621: /* FALLTHROUGH */
1622: case (MDOC_Dl):
1.108 schwarze 1623: /* FALLTHROUGH */
1624: case (MDOC_Lp):
1625: /* FALLTHROUGH */
1626: case (MDOC_Pp):
1627: continue;
1628: default:
1629: break;
1630: }
1.100 schwarze 1631: if (nn->next && nn->next->line == nn->line)
1632: continue;
1633: term_flushln(p);
1.48 schwarze 1634: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1635: }
1.88 schwarze 1636:
1.75 schwarze 1637: p->tabwidth = tabwidth;
1.77 schwarze 1638: p->rmargin = rm;
1639: p->maxrmargin = rmax;
1.1 kristaps 1640: return(0);
1641: }
1642:
1643:
1644: /* ARGSUSED */
1645: static void
1646: termp_bd_post(DECL_ARGS)
1647: {
1.77 schwarze 1648: size_t rm, rmax;
1.1 kristaps 1649:
1.60 schwarze 1650: if (MDOC_BODY != n->type)
1.1 kristaps 1651: return;
1.77 schwarze 1652:
1653: rm = p->rmargin;
1654: rmax = p->maxrmargin;
1655:
1.121 schwarze 1656: if (DISP_literal == n->norm->Bd.type ||
1657: DISP_unfilled == n->norm->Bd.type)
1.77 schwarze 1658: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1659:
1.48 schwarze 1660: p->flags |= TERMP_NOSPACE;
1.75 schwarze 1661: term_newln(p);
1.77 schwarze 1662:
1663: p->rmargin = rm;
1664: p->maxrmargin = rmax;
1.1 kristaps 1665: }
1666:
1667:
1668: /* ARGSUSED */
1669: static void
1670: termp_bx_post(DECL_ARGS)
1671: {
1672:
1.60 schwarze 1673: if (n->child)
1.1 kristaps 1674: p->flags |= TERMP_NOSPACE;
1675: term_word(p, "BSD");
1676: }
1677:
1678:
1679: /* ARGSUSED */
1680: static int
1.26 schwarze 1681: termp_xx_pre(DECL_ARGS)
1.1 kristaps 1682: {
1.26 schwarze 1683: const char *pp;
1.1 kristaps 1684:
1.26 schwarze 1685: pp = NULL;
1.60 schwarze 1686: switch (n->tok) {
1.26 schwarze 1687: case (MDOC_Bsx):
1.113 schwarze 1688: pp = "BSD/OS";
1.26 schwarze 1689: break;
1690: case (MDOC_Dx):
1.64 schwarze 1691: pp = "DragonFly";
1.26 schwarze 1692: break;
1693: case (MDOC_Fx):
1694: pp = "FreeBSD";
1695: break;
1696: case (MDOC_Nx):
1697: pp = "NetBSD";
1698: break;
1699: case (MDOC_Ox):
1700: pp = "OpenBSD";
1701: break;
1702: case (MDOC_Ux):
1703: pp = "UNIX";
1704: break;
1705: default:
1706: break;
1707: }
1.1 kristaps 1708:
1.26 schwarze 1709: assert(pp);
1710: term_word(p, pp);
1.1 kristaps 1711: return(1);
1712: }
1713:
1714:
1715: /* ARGSUSED */
1716: static int
1.109 schwarze 1717: termp_igndelim_pre(DECL_ARGS)
1.1 kristaps 1718: {
1719:
1720: p->flags |= TERMP_IGNDELIM;
1721: return(1);
1722: }
1723:
1724:
1725: /* ARGSUSED */
1726: static void
1727: termp_pf_post(DECL_ARGS)
1728: {
1729:
1730: p->flags |= TERMP_NOSPACE;
1731: }
1732:
1733:
1734: /* ARGSUSED */
1735: static int
1736: termp_ss_pre(DECL_ARGS)
1737: {
1738:
1.60 schwarze 1739: switch (n->type) {
1.1 kristaps 1740: case (MDOC_BLOCK):
1741: term_newln(p);
1.60 schwarze 1742: if (n->prev)
1.1 kristaps 1743: term_vspace(p);
1744: break;
1745: case (MDOC_HEAD):
1.65 schwarze 1746: term_fontpush(p, TERMFONT_BOLD);
1.89 schwarze 1747: p->offset = term_len(p, HALFINDENT);
1.1 kristaps 1748: break;
1749: default:
1750: break;
1751: }
1752:
1753: return(1);
1754: }
1755:
1756:
1757: /* ARGSUSED */
1758: static void
1759: termp_ss_post(DECL_ARGS)
1760: {
1761:
1.60 schwarze 1762: if (MDOC_HEAD == n->type)
1.1 kristaps 1763: term_newln(p);
1764: }
1765:
1766:
1767: /* ARGSUSED */
1768: static int
1769: termp_cd_pre(DECL_ARGS)
1770: {
1771:
1.86 schwarze 1772: synopsis_pre(p, n);
1.65 schwarze 1773: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1774: return(1);
1775: }
1776:
1777:
1778: /* ARGSUSED */
1779: static int
1780: termp_in_pre(DECL_ARGS)
1781: {
1782:
1.86 schwarze 1783: synopsis_pre(p, n);
1.85 schwarze 1784:
1.92 schwarze 1785: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
1.85 schwarze 1786: term_fontpush(p, TERMFONT_BOLD);
1.23 schwarze 1787: term_word(p, "#include");
1.85 schwarze 1788: term_word(p, "<");
1789: } else {
1790: term_word(p, "<");
1791: term_fontpush(p, TERMFONT_UNDER);
1792: }
1.23 schwarze 1793:
1.1 kristaps 1794: p->flags |= TERMP_NOSPACE;
1795: return(1);
1796: }
1797:
1798:
1799: /* ARGSUSED */
1800: static void
1801: termp_in_post(DECL_ARGS)
1802: {
1803:
1.92 schwarze 1804: if (MDOC_SYNPRETTY & n->flags)
1.85 schwarze 1805: term_fontpush(p, TERMFONT_BOLD);
1806:
1.59 schwarze 1807: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1808: term_word(p, ">");
1809:
1.92 schwarze 1810: if (MDOC_SYNPRETTY & n->flags)
1.85 schwarze 1811: term_fontpop(p);
1.38 schwarze 1812: }
1813:
1814:
1815: /* ARGSUSED */
1816: static int
1817: termp_sp_pre(DECL_ARGS)
1818: {
1.61 schwarze 1819: size_t i, len;
1.38 schwarze 1820:
1.60 schwarze 1821: switch (n->tok) {
1.54 schwarze 1822: case (MDOC_sp):
1.89 schwarze 1823: len = n->child ? a2height(p, n->child->string) : 1;
1.54 schwarze 1824: break;
1825: case (MDOC_br):
1826: len = 0;
1827: break;
1828: default:
1829: len = 1;
1830: break;
1.38 schwarze 1831: }
1832:
1833: if (0 == len)
1834: term_newln(p);
1835: for (i = 0; i < len; i++)
1836: term_vspace(p);
1837:
1838: return(0);
1839: }
1840:
1841:
1842: /* ARGSUSED */
1843: static int
1.107 schwarze 1844: termp_quote_pre(DECL_ARGS)
1.1 kristaps 1845: {
1846:
1.120 schwarze 1847: if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1 kristaps 1848: return(1);
1849:
1.107 schwarze 1850: switch (n->tok) {
1851: case (MDOC_Ao):
1852: /* FALLTHROUGH */
1853: case (MDOC_Aq):
1854: term_word(p, "<");
1855: break;
1856: case (MDOC_Bro):
1857: /* FALLTHROUGH */
1858: case (MDOC_Brq):
1859: term_word(p, "{");
1860: break;
1861: case (MDOC_Oo):
1862: /* FALLTHROUGH */
1863: case (MDOC_Op):
1864: /* FALLTHROUGH */
1865: case (MDOC_Bo):
1866: /* FALLTHROUGH */
1867: case (MDOC_Bq):
1868: term_word(p, "[");
1869: break;
1870: case (MDOC_Do):
1871: /* FALLTHROUGH */
1872: case (MDOC_Dq):
1873: term_word(p, "``");
1874: break;
1875: case (MDOC_Po):
1876: /* FALLTHROUGH */
1877: case (MDOC_Pq):
1878: term_word(p, "(");
1879: break;
1.120 schwarze 1880: case (MDOC__T):
1881: /* FALLTHROUGH */
1.107 schwarze 1882: case (MDOC_Qo):
1883: /* FALLTHROUGH */
1884: case (MDOC_Qq):
1885: term_word(p, "\"");
1886: break;
1887: case (MDOC_Ql):
1888: /* FALLTHROUGH */
1889: case (MDOC_So):
1890: /* FALLTHROUGH */
1891: case (MDOC_Sq):
1892: term_word(p, "`");
1893: break;
1894: default:
1895: abort();
1896: /* NOTREACHED */
1897: }
1.1 kristaps 1898:
1899: p->flags |= TERMP_NOSPACE;
1900: return(1);
1901: }
1902:
1903:
1904: /* ARGSUSED */
1905: static void
1.107 schwarze 1906: termp_quote_post(DECL_ARGS)
1.1 kristaps 1907: {
1908:
1.120 schwarze 1909: if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1 kristaps 1910: return;
1911:
1912: p->flags |= TERMP_NOSPACE;
1913:
1.107 schwarze 1914: switch (n->tok) {
1915: case (MDOC_Ao):
1916: /* FALLTHROUGH */
1917: case (MDOC_Aq):
1918: term_word(p, ">");
1919: break;
1920: case (MDOC_Bro):
1921: /* FALLTHROUGH */
1922: case (MDOC_Brq):
1923: term_word(p, "}");
1924: break;
1925: case (MDOC_Oo):
1926: /* FALLTHROUGH */
1927: case (MDOC_Op):
1928: /* FALLTHROUGH */
1929: case (MDOC_Bo):
1930: /* FALLTHROUGH */
1931: case (MDOC_Bq):
1932: term_word(p, "]");
1933: break;
1934: case (MDOC_Do):
1935: /* FALLTHROUGH */
1936: case (MDOC_Dq):
1937: term_word(p, "''");
1938: break;
1939: case (MDOC_Po):
1940: /* FALLTHROUGH */
1941: case (MDOC_Pq):
1942: term_word(p, ")");
1943: break;
1.120 schwarze 1944: case (MDOC__T):
1945: /* FALLTHROUGH */
1.107 schwarze 1946: case (MDOC_Qo):
1947: /* FALLTHROUGH */
1948: case (MDOC_Qq):
1949: term_word(p, "\"");
1950: break;
1951: case (MDOC_Ql):
1952: /* FALLTHROUGH */
1953: case (MDOC_So):
1954: /* FALLTHROUGH */
1955: case (MDOC_Sq):
1956: term_word(p, "'");
1957: break;
1958: default:
1959: abort();
1960: /* NOTREACHED */
1961: }
1.1 kristaps 1962: }
1963:
1964:
1965: /* ARGSUSED */
1966: static int
1967: termp_fo_pre(DECL_ARGS)
1968: {
1969:
1.85 schwarze 1970: if (MDOC_BLOCK == n->type) {
1.86 schwarze 1971: synopsis_pre(p, n);
1.85 schwarze 1972: return(1);
1973: } else if (MDOC_BODY == n->type) {
1.31 schwarze 1974: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1975: term_word(p, "(");
1976: return(1);
1.85 schwarze 1977: }
1978:
1.95 schwarze 1979: if (NULL == n->child)
1980: return(0);
1981:
1.85 schwarze 1982: /* XXX: we drop non-initial arguments as per groff. */
1.1 kristaps 1983:
1.85 schwarze 1984: assert(n->child->string);
1.65 schwarze 1985: term_fontpush(p, TERMFONT_BOLD);
1.85 schwarze 1986: term_word(p, n->child->string);
1.1 kristaps 1987: return(0);
1988: }
1989:
1990:
1991: /* ARGSUSED */
1992: static void
1993: termp_fo_post(DECL_ARGS)
1994: {
1995:
1.86 schwarze 1996: if (MDOC_BODY != n->type)
1997: return;
1998:
1999: term_word(p, ")");
2000:
1.107 schwarze 2001: if (MDOC_SYNPRETTY & n->flags)
1.86 schwarze 2002: term_word(p, ";");
1.1 kristaps 2003: }
2004:
2005:
2006: /* ARGSUSED */
2007: static int
2008: termp_bf_pre(DECL_ARGS)
2009: {
2010:
1.60 schwarze 2011: if (MDOC_HEAD == n->type)
1.1 kristaps 2012: return(0);
1.60 schwarze 2013: else if (MDOC_BLOCK != n->type)
1.1 kristaps 2014: return(1);
2015:
1.121 schwarze 2016: if (FONT_Em == n->norm->Bf.font)
1.65 schwarze 2017: term_fontpush(p, TERMFONT_UNDER);
1.121 schwarze 2018: else if (FONT_Sy == n->norm->Bf.font)
1.65 schwarze 2019: term_fontpush(p, TERMFONT_BOLD);
1.95 schwarze 2020: else
1.65 schwarze 2021: term_fontpush(p, TERMFONT_NONE);
1.1 kristaps 2022:
2023: return(1);
2024: }
2025:
2026:
2027: /* ARGSUSED */
2028: static int
2029: termp_sm_pre(DECL_ARGS)
2030: {
2031:
1.60 schwarze 2032: assert(n->child && MDOC_TEXT == n->child->type);
1.96 schwarze 2033: if (0 == strcmp("on", n->child->string)) {
2034: if (p->col)
2035: p->flags &= ~TERMP_NOSPACE;
1.1 kristaps 2036: p->flags &= ~TERMP_NONOSPACE;
1.96 schwarze 2037: } else
1.1 kristaps 2038: p->flags |= TERMP_NONOSPACE;
2039:
2040: return(0);
2041: }
2042:
2043:
2044: /* ARGSUSED */
2045: static int
2046: termp_ap_pre(DECL_ARGS)
2047: {
2048:
2049: p->flags |= TERMP_NOSPACE;
1.107 schwarze 2050: term_word(p, "'");
1.1 kristaps 2051: p->flags |= TERMP_NOSPACE;
2052: return(1);
2053: }
2054:
2055:
2056: /* ARGSUSED */
2057: static void
2058: termp____post(DECL_ARGS)
2059: {
1.104 schwarze 2060:
2061: /*
2062: * Handle lists of authors. In general, print each followed by
2063: * a comma. Don't print the comma if there are only two
2064: * authors.
2065: */
2066: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2067: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2068: if (NULL == n->prev || MDOC__A != n->prev->tok)
2069: return;
1.1 kristaps 2070:
1.62 schwarze 2071: /* TODO: %U. */
2072:
1.106 schwarze 2073: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2074: return;
2075:
2076: if (NULL == n->next) {
2077: term_word(p, ".");
2078: p->flags |= TERMP_SENTENCE;
2079: } else
2080: term_word(p, ",");
1.1 kristaps 2081: }
2082:
2083:
2084: /* ARGSUSED */
2085: static int
1.65 schwarze 2086: termp_li_pre(DECL_ARGS)
2087: {
2088:
2089: term_fontpush(p, TERMFONT_NONE);
2090: return(1);
2091: }
2092:
2093:
2094: /* ARGSUSED */
2095: static int
1.1 kristaps 2096: termp_lk_pre(DECL_ARGS)
2097: {
1.101 schwarze 2098: const struct mdoc_node *nn, *sv;
1.1 kristaps 2099:
1.65 schwarze 2100: term_fontpush(p, TERMFONT_UNDER);
1.101 schwarze 2101:
2102: nn = sv = n->child;
1.62 schwarze 2103:
1.114 schwarze 2104: if (NULL == nn || NULL == nn->next)
1.6 schwarze 2105: return(1);
1.1 kristaps 2106:
1.101 schwarze 2107: for (nn = nn->next; nn; nn = nn->next)
2108: term_word(p, nn->string);
2109:
1.65 schwarze 2110: term_fontpop(p);
1.62 schwarze 2111:
1.1 kristaps 2112: term_word(p, ":");
2113:
1.65 schwarze 2114: term_fontpush(p, TERMFONT_BOLD);
1.101 schwarze 2115: term_word(p, sv->string);
1.65 schwarze 2116: term_fontpop(p);
1.6 schwarze 2117:
1.1 kristaps 2118: return(0);
2119: }
2120:
1.90 schwarze 2121:
2122: /* ARGSUSED */
2123: static int
2124: termp_bk_pre(DECL_ARGS)
2125: {
2126:
1.91 schwarze 2127: switch (n->type) {
2128: case (MDOC_BLOCK):
1.95 schwarze 2129: break;
1.91 schwarze 2130: case (MDOC_HEAD):
2131: return(0);
2132: case (MDOC_BODY):
1.117 schwarze 2133: if (n->parent->args || 0 == n->prev->nchild)
2134: p->flags |= TERMP_PREKEEP;
1.95 schwarze 2135: break;
1.91 schwarze 2136: default:
2137: abort();
1.95 schwarze 2138: /* NOTREACHED */
1.91 schwarze 2139: }
1.95 schwarze 2140:
2141: return(1);
1.90 schwarze 2142: }
2143:
2144:
2145: /* ARGSUSED */
2146: static void
2147: termp_bk_post(DECL_ARGS)
2148: {
2149:
1.91 schwarze 2150: if (MDOC_BODY == n->type)
2151: p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.90 schwarze 2152: }
1.120 schwarze 2153:
2154: /* ARGSUSED */
2155: static void
2156: termp__t_post(DECL_ARGS)
2157: {
2158:
2159: /*
2160: * If we're in an `Rs' and there's a journal present, then quote
2161: * us instead of underlining us (for disambiguation).
2162: */
1.121 schwarze 2163: if (n->parent && MDOC_Rs == n->parent->tok &&
2164: n->parent->norm->Rs.child_J)
1.120 schwarze 2165: termp_quote_post(p, pair, m, n);
2166:
2167: termp____post(p, pair, m, n);
2168: }
2169:
2170: /* ARGSUSED */
2171: static int
2172: termp__t_pre(DECL_ARGS)
2173: {
2174:
2175: /*
2176: * If we're in an `Rs' and there's a journal present, then quote
2177: * us instead of underlining us (for disambiguation).
2178: */
1.121 schwarze 2179: if (n->parent && MDOC_Rs == n->parent->tok &&
2180: n->parent->norm->Rs.child_J)
1.120 schwarze 2181: return(termp_quote_pre(p, pair, m, n));
2182:
2183: term_fontpush(p, TERMFONT_UNDER);
2184: return(1);
1.121 schwarze 2185: }
1.1 kristaps 2186:
2187: /* ARGSUSED */
2188: static int
1.54 schwarze 2189: termp_under_pre(DECL_ARGS)
1.1 kristaps 2190: {
2191:
1.65 schwarze 2192: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 2193: return(1);
2194: }