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