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