Annotation of src/usr.bin/mandoc/mdoc_term.c, Revision 1.123
1.123 ! schwarze 1: /* $Id: mdoc_term.c,v 1.122 2011/01/04 22:28:17 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.123 ! schwarze 1598: if (DISP_literal == n->norm->Bd.type)
! 1599: p->tabwidth = term_len(p, 8);
! 1600:
1.77 schwarze 1601: rm = p->rmargin;
1602: rmax = p->maxrmargin;
1603: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1604:
1.60 schwarze 1605: for (nn = n->child; nn; nn = nn->next) {
1.100 schwarze 1606: print_mdoc_node(p, pair, m, nn);
1.108 schwarze 1607: /*
1608: * If the printed node flushes its own line, then we
1609: * needn't do it here as well. This is hacky, but the
1610: * notion of selective eoln whitespace is pretty dumb
1611: * anyway, so don't sweat it.
1612: */
1613: switch (nn->tok) {
1.112 schwarze 1614: case (MDOC_Sm):
1615: /* FALLTHROUGH */
1.108 schwarze 1616: case (MDOC_br):
1617: /* FALLTHROUGH */
1618: case (MDOC_sp):
1619: /* FALLTHROUGH */
1620: case (MDOC_Bl):
1.115 schwarze 1621: /* FALLTHROUGH */
1622: case (MDOC_D1):
1623: /* FALLTHROUGH */
1624: case (MDOC_Dl):
1.108 schwarze 1625: /* FALLTHROUGH */
1626: case (MDOC_Lp):
1627: /* FALLTHROUGH */
1628: case (MDOC_Pp):
1629: continue;
1630: default:
1631: break;
1632: }
1.100 schwarze 1633: if (nn->next && nn->next->line == nn->line)
1634: continue;
1635: term_flushln(p);
1.48 schwarze 1636: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1637: }
1.88 schwarze 1638:
1.75 schwarze 1639: p->tabwidth = tabwidth;
1.77 schwarze 1640: p->rmargin = rm;
1641: p->maxrmargin = rmax;
1.1 kristaps 1642: return(0);
1643: }
1644:
1645:
1646: /* ARGSUSED */
1647: static void
1648: termp_bd_post(DECL_ARGS)
1649: {
1.77 schwarze 1650: size_t rm, rmax;
1.1 kristaps 1651:
1.60 schwarze 1652: if (MDOC_BODY != n->type)
1.1 kristaps 1653: return;
1.77 schwarze 1654:
1655: rm = p->rmargin;
1656: rmax = p->maxrmargin;
1657:
1.121 schwarze 1658: if (DISP_literal == n->norm->Bd.type ||
1659: DISP_unfilled == n->norm->Bd.type)
1.77 schwarze 1660: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1661:
1.48 schwarze 1662: p->flags |= TERMP_NOSPACE;
1.75 schwarze 1663: term_newln(p);
1.77 schwarze 1664:
1665: p->rmargin = rm;
1666: p->maxrmargin = rmax;
1.1 kristaps 1667: }
1668:
1669:
1670: /* ARGSUSED */
1671: static void
1672: termp_bx_post(DECL_ARGS)
1673: {
1674:
1.60 schwarze 1675: if (n->child)
1.1 kristaps 1676: p->flags |= TERMP_NOSPACE;
1677: term_word(p, "BSD");
1678: }
1679:
1680:
1681: /* ARGSUSED */
1682: static int
1.26 schwarze 1683: termp_xx_pre(DECL_ARGS)
1.1 kristaps 1684: {
1.26 schwarze 1685: const char *pp;
1.1 kristaps 1686:
1.26 schwarze 1687: pp = NULL;
1.60 schwarze 1688: switch (n->tok) {
1.26 schwarze 1689: case (MDOC_Bsx):
1.113 schwarze 1690: pp = "BSD/OS";
1.26 schwarze 1691: break;
1692: case (MDOC_Dx):
1.64 schwarze 1693: pp = "DragonFly";
1.26 schwarze 1694: break;
1695: case (MDOC_Fx):
1696: pp = "FreeBSD";
1697: break;
1698: case (MDOC_Nx):
1699: pp = "NetBSD";
1700: break;
1701: case (MDOC_Ox):
1702: pp = "OpenBSD";
1703: break;
1704: case (MDOC_Ux):
1705: pp = "UNIX";
1706: break;
1707: default:
1708: break;
1709: }
1.1 kristaps 1710:
1.26 schwarze 1711: assert(pp);
1712: term_word(p, pp);
1.1 kristaps 1713: return(1);
1714: }
1715:
1716:
1717: /* ARGSUSED */
1718: static int
1.109 schwarze 1719: termp_igndelim_pre(DECL_ARGS)
1.1 kristaps 1720: {
1721:
1722: p->flags |= TERMP_IGNDELIM;
1723: return(1);
1724: }
1725:
1726:
1727: /* ARGSUSED */
1728: static void
1729: termp_pf_post(DECL_ARGS)
1730: {
1731:
1732: p->flags |= TERMP_NOSPACE;
1733: }
1734:
1735:
1736: /* ARGSUSED */
1737: static int
1738: termp_ss_pre(DECL_ARGS)
1739: {
1740:
1.60 schwarze 1741: switch (n->type) {
1.1 kristaps 1742: case (MDOC_BLOCK):
1743: term_newln(p);
1.60 schwarze 1744: if (n->prev)
1.1 kristaps 1745: term_vspace(p);
1746: break;
1747: case (MDOC_HEAD):
1.65 schwarze 1748: term_fontpush(p, TERMFONT_BOLD);
1.89 schwarze 1749: p->offset = term_len(p, HALFINDENT);
1.1 kristaps 1750: break;
1751: default:
1752: break;
1753: }
1754:
1755: return(1);
1756: }
1757:
1758:
1759: /* ARGSUSED */
1760: static void
1761: termp_ss_post(DECL_ARGS)
1762: {
1763:
1.60 schwarze 1764: if (MDOC_HEAD == n->type)
1.1 kristaps 1765: term_newln(p);
1766: }
1767:
1768:
1769: /* ARGSUSED */
1770: static int
1771: termp_cd_pre(DECL_ARGS)
1772: {
1773:
1.86 schwarze 1774: synopsis_pre(p, n);
1.65 schwarze 1775: term_fontpush(p, TERMFONT_BOLD);
1.1 kristaps 1776: return(1);
1777: }
1778:
1779:
1780: /* ARGSUSED */
1781: static int
1782: termp_in_pre(DECL_ARGS)
1783: {
1784:
1.86 schwarze 1785: synopsis_pre(p, n);
1.85 schwarze 1786:
1.92 schwarze 1787: if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
1.85 schwarze 1788: term_fontpush(p, TERMFONT_BOLD);
1.23 schwarze 1789: term_word(p, "#include");
1.85 schwarze 1790: term_word(p, "<");
1791: } else {
1792: term_word(p, "<");
1793: term_fontpush(p, TERMFONT_UNDER);
1794: }
1.23 schwarze 1795:
1.1 kristaps 1796: p->flags |= TERMP_NOSPACE;
1797: return(1);
1798: }
1799:
1800:
1801: /* ARGSUSED */
1802: static void
1803: termp_in_post(DECL_ARGS)
1804: {
1805:
1.92 schwarze 1806: if (MDOC_SYNPRETTY & n->flags)
1.85 schwarze 1807: term_fontpush(p, TERMFONT_BOLD);
1808:
1.59 schwarze 1809: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1810: term_word(p, ">");
1811:
1.92 schwarze 1812: if (MDOC_SYNPRETTY & n->flags)
1.85 schwarze 1813: term_fontpop(p);
1.38 schwarze 1814: }
1815:
1816:
1817: /* ARGSUSED */
1818: static int
1819: termp_sp_pre(DECL_ARGS)
1820: {
1.61 schwarze 1821: size_t i, len;
1.38 schwarze 1822:
1.60 schwarze 1823: switch (n->tok) {
1.54 schwarze 1824: case (MDOC_sp):
1.89 schwarze 1825: len = n->child ? a2height(p, n->child->string) : 1;
1.54 schwarze 1826: break;
1827: case (MDOC_br):
1828: len = 0;
1829: break;
1830: default:
1831: len = 1;
1832: break;
1.38 schwarze 1833: }
1834:
1835: if (0 == len)
1836: term_newln(p);
1837: for (i = 0; i < len; i++)
1838: term_vspace(p);
1839:
1840: return(0);
1841: }
1842:
1843:
1844: /* ARGSUSED */
1845: static int
1.107 schwarze 1846: termp_quote_pre(DECL_ARGS)
1.1 kristaps 1847: {
1848:
1.120 schwarze 1849: if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1 kristaps 1850: return(1);
1851:
1.107 schwarze 1852: switch (n->tok) {
1853: case (MDOC_Ao):
1854: /* FALLTHROUGH */
1855: case (MDOC_Aq):
1856: term_word(p, "<");
1857: break;
1858: case (MDOC_Bro):
1859: /* FALLTHROUGH */
1860: case (MDOC_Brq):
1861: term_word(p, "{");
1862: break;
1863: case (MDOC_Oo):
1864: /* FALLTHROUGH */
1865: case (MDOC_Op):
1866: /* FALLTHROUGH */
1867: case (MDOC_Bo):
1868: /* FALLTHROUGH */
1869: case (MDOC_Bq):
1870: term_word(p, "[");
1871: break;
1872: case (MDOC_Do):
1873: /* FALLTHROUGH */
1874: case (MDOC_Dq):
1875: term_word(p, "``");
1876: break;
1877: case (MDOC_Po):
1878: /* FALLTHROUGH */
1879: case (MDOC_Pq):
1880: term_word(p, "(");
1881: break;
1.120 schwarze 1882: case (MDOC__T):
1883: /* FALLTHROUGH */
1.107 schwarze 1884: case (MDOC_Qo):
1885: /* FALLTHROUGH */
1886: case (MDOC_Qq):
1887: term_word(p, "\"");
1888: break;
1889: case (MDOC_Ql):
1890: /* FALLTHROUGH */
1891: case (MDOC_So):
1892: /* FALLTHROUGH */
1893: case (MDOC_Sq):
1894: term_word(p, "`");
1895: break;
1896: default:
1897: abort();
1898: /* NOTREACHED */
1899: }
1.1 kristaps 1900:
1901: p->flags |= TERMP_NOSPACE;
1902: return(1);
1903: }
1904:
1905:
1906: /* ARGSUSED */
1907: static void
1.107 schwarze 1908: termp_quote_post(DECL_ARGS)
1.1 kristaps 1909: {
1910:
1.120 schwarze 1911: if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1 kristaps 1912: return;
1913:
1914: p->flags |= TERMP_NOSPACE;
1915:
1.107 schwarze 1916: switch (n->tok) {
1917: case (MDOC_Ao):
1918: /* FALLTHROUGH */
1919: case (MDOC_Aq):
1920: term_word(p, ">");
1921: break;
1922: case (MDOC_Bro):
1923: /* FALLTHROUGH */
1924: case (MDOC_Brq):
1925: term_word(p, "}");
1926: break;
1927: case (MDOC_Oo):
1928: /* FALLTHROUGH */
1929: case (MDOC_Op):
1930: /* FALLTHROUGH */
1931: case (MDOC_Bo):
1932: /* FALLTHROUGH */
1933: case (MDOC_Bq):
1934: term_word(p, "]");
1935: break;
1936: case (MDOC_Do):
1937: /* FALLTHROUGH */
1938: case (MDOC_Dq):
1939: term_word(p, "''");
1940: break;
1941: case (MDOC_Po):
1942: /* FALLTHROUGH */
1943: case (MDOC_Pq):
1944: term_word(p, ")");
1945: break;
1.120 schwarze 1946: case (MDOC__T):
1947: /* FALLTHROUGH */
1.107 schwarze 1948: case (MDOC_Qo):
1949: /* FALLTHROUGH */
1950: case (MDOC_Qq):
1951: term_word(p, "\"");
1952: break;
1953: case (MDOC_Ql):
1954: /* FALLTHROUGH */
1955: case (MDOC_So):
1956: /* FALLTHROUGH */
1957: case (MDOC_Sq):
1958: term_word(p, "'");
1959: break;
1960: default:
1961: abort();
1962: /* NOTREACHED */
1963: }
1.1 kristaps 1964: }
1965:
1966:
1967: /* ARGSUSED */
1968: static int
1969: termp_fo_pre(DECL_ARGS)
1970: {
1971:
1.85 schwarze 1972: if (MDOC_BLOCK == n->type) {
1.86 schwarze 1973: synopsis_pre(p, n);
1.85 schwarze 1974: return(1);
1975: } else if (MDOC_BODY == n->type) {
1.31 schwarze 1976: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1977: term_word(p, "(");
1978: return(1);
1.85 schwarze 1979: }
1980:
1.95 schwarze 1981: if (NULL == n->child)
1982: return(0);
1983:
1.85 schwarze 1984: /* XXX: we drop non-initial arguments as per groff. */
1.1 kristaps 1985:
1.85 schwarze 1986: assert(n->child->string);
1.65 schwarze 1987: term_fontpush(p, TERMFONT_BOLD);
1.85 schwarze 1988: term_word(p, n->child->string);
1.1 kristaps 1989: return(0);
1990: }
1991:
1992:
1993: /* ARGSUSED */
1994: static void
1995: termp_fo_post(DECL_ARGS)
1996: {
1997:
1.86 schwarze 1998: if (MDOC_BODY != n->type)
1999: return;
2000:
2001: term_word(p, ")");
2002:
1.107 schwarze 2003: if (MDOC_SYNPRETTY & n->flags)
1.86 schwarze 2004: term_word(p, ";");
1.1 kristaps 2005: }
2006:
2007:
2008: /* ARGSUSED */
2009: static int
2010: termp_bf_pre(DECL_ARGS)
2011: {
2012:
1.60 schwarze 2013: if (MDOC_HEAD == n->type)
1.1 kristaps 2014: return(0);
1.60 schwarze 2015: else if (MDOC_BLOCK != n->type)
1.1 kristaps 2016: return(1);
2017:
1.121 schwarze 2018: if (FONT_Em == n->norm->Bf.font)
1.65 schwarze 2019: term_fontpush(p, TERMFONT_UNDER);
1.121 schwarze 2020: else if (FONT_Sy == n->norm->Bf.font)
1.65 schwarze 2021: term_fontpush(p, TERMFONT_BOLD);
1.95 schwarze 2022: else
1.65 schwarze 2023: term_fontpush(p, TERMFONT_NONE);
1.1 kristaps 2024:
2025: return(1);
2026: }
2027:
2028:
2029: /* ARGSUSED */
2030: static int
2031: termp_sm_pre(DECL_ARGS)
2032: {
2033:
1.60 schwarze 2034: assert(n->child && MDOC_TEXT == n->child->type);
1.96 schwarze 2035: if (0 == strcmp("on", n->child->string)) {
2036: if (p->col)
2037: p->flags &= ~TERMP_NOSPACE;
1.1 kristaps 2038: p->flags &= ~TERMP_NONOSPACE;
1.96 schwarze 2039: } else
1.1 kristaps 2040: p->flags |= TERMP_NONOSPACE;
2041:
2042: return(0);
2043: }
2044:
2045:
2046: /* ARGSUSED */
2047: static int
2048: termp_ap_pre(DECL_ARGS)
2049: {
2050:
2051: p->flags |= TERMP_NOSPACE;
1.107 schwarze 2052: term_word(p, "'");
1.1 kristaps 2053: p->flags |= TERMP_NOSPACE;
2054: return(1);
2055: }
2056:
2057:
2058: /* ARGSUSED */
2059: static void
2060: termp____post(DECL_ARGS)
2061: {
1.104 schwarze 2062:
2063: /*
2064: * Handle lists of authors. In general, print each followed by
2065: * a comma. Don't print the comma if there are only two
2066: * authors.
2067: */
2068: if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2069: if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2070: if (NULL == n->prev || MDOC__A != n->prev->tok)
2071: return;
1.1 kristaps 2072:
1.62 schwarze 2073: /* TODO: %U. */
2074:
1.106 schwarze 2075: if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2076: return;
2077:
2078: if (NULL == n->next) {
2079: term_word(p, ".");
2080: p->flags |= TERMP_SENTENCE;
2081: } else
2082: term_word(p, ",");
1.1 kristaps 2083: }
2084:
2085:
2086: /* ARGSUSED */
2087: static int
1.65 schwarze 2088: termp_li_pre(DECL_ARGS)
2089: {
2090:
2091: term_fontpush(p, TERMFONT_NONE);
2092: return(1);
2093: }
2094:
2095:
2096: /* ARGSUSED */
2097: static int
1.1 kristaps 2098: termp_lk_pre(DECL_ARGS)
2099: {
1.101 schwarze 2100: const struct mdoc_node *nn, *sv;
1.1 kristaps 2101:
1.65 schwarze 2102: term_fontpush(p, TERMFONT_UNDER);
1.101 schwarze 2103:
2104: nn = sv = n->child;
1.62 schwarze 2105:
1.114 schwarze 2106: if (NULL == nn || NULL == nn->next)
1.6 schwarze 2107: return(1);
1.1 kristaps 2108:
1.101 schwarze 2109: for (nn = nn->next; nn; nn = nn->next)
2110: term_word(p, nn->string);
2111:
1.65 schwarze 2112: term_fontpop(p);
1.62 schwarze 2113:
1.1 kristaps 2114: term_word(p, ":");
2115:
1.65 schwarze 2116: term_fontpush(p, TERMFONT_BOLD);
1.101 schwarze 2117: term_word(p, sv->string);
1.65 schwarze 2118: term_fontpop(p);
1.6 schwarze 2119:
1.1 kristaps 2120: return(0);
2121: }
2122:
1.90 schwarze 2123:
2124: /* ARGSUSED */
2125: static int
2126: termp_bk_pre(DECL_ARGS)
2127: {
2128:
1.91 schwarze 2129: switch (n->type) {
2130: case (MDOC_BLOCK):
1.95 schwarze 2131: break;
1.91 schwarze 2132: case (MDOC_HEAD):
2133: return(0);
2134: case (MDOC_BODY):
1.117 schwarze 2135: if (n->parent->args || 0 == n->prev->nchild)
2136: p->flags |= TERMP_PREKEEP;
1.95 schwarze 2137: break;
1.91 schwarze 2138: default:
2139: abort();
1.95 schwarze 2140: /* NOTREACHED */
1.91 schwarze 2141: }
1.95 schwarze 2142:
2143: return(1);
1.90 schwarze 2144: }
2145:
2146:
2147: /* ARGSUSED */
2148: static void
2149: termp_bk_post(DECL_ARGS)
2150: {
2151:
1.91 schwarze 2152: if (MDOC_BODY == n->type)
2153: p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.90 schwarze 2154: }
1.120 schwarze 2155:
2156: /* ARGSUSED */
2157: static void
2158: termp__t_post(DECL_ARGS)
2159: {
2160:
2161: /*
2162: * If we're in an `Rs' and there's a journal present, then quote
2163: * us instead of underlining us (for disambiguation).
2164: */
1.121 schwarze 2165: if (n->parent && MDOC_Rs == n->parent->tok &&
2166: n->parent->norm->Rs.child_J)
1.120 schwarze 2167: termp_quote_post(p, pair, m, n);
2168:
2169: termp____post(p, pair, m, n);
2170: }
2171:
2172: /* ARGSUSED */
2173: static int
2174: termp__t_pre(DECL_ARGS)
2175: {
2176:
2177: /*
2178: * If we're in an `Rs' and there's a journal present, then quote
2179: * us instead of underlining us (for disambiguation).
2180: */
1.121 schwarze 2181: if (n->parent && MDOC_Rs == n->parent->tok &&
2182: n->parent->norm->Rs.child_J)
1.120 schwarze 2183: return(termp_quote_pre(p, pair, m, n));
2184:
2185: term_fontpush(p, TERMFONT_UNDER);
2186: return(1);
1.121 schwarze 2187: }
1.1 kristaps 2188:
2189: /* ARGSUSED */
2190: static int
1.54 schwarze 2191: termp_under_pre(DECL_ARGS)
1.1 kristaps 2192: {
2193:
1.65 schwarze 2194: term_fontpush(p, TERMFONT_UNDER);
1.1 kristaps 2195: return(1);
2196: }