Annotation of src/usr.bin/mandoc/man_term.c, Revision 1.145
1.145 ! schwarze 1: /* $OpenBSD: man_term.c,v 1.144 2017/02/15 14:09:07 schwarze Exp $ */
1.1 kristaps 2: /*
1.84 schwarze 3: * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
1.142 schwarze 4: * Copyright (c) 2010-2015, 2017 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.124 schwarze 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.2 schwarze 11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.124 schwarze 12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.2 schwarze 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.13 schwarze 18: #include <sys/types.h>
19:
1.1 kristaps 20: #include <assert.h>
1.11 schwarze 21: #include <ctype.h>
1.117 schwarze 22: #include <limits.h>
1.1 kristaps 23: #include <stdio.h>
24: #include <stdlib.h>
25: #include <string.h>
26:
1.124 schwarze 27: #include "mandoc_aux.h"
1.37 schwarze 28: #include "mandoc.h"
1.124 schwarze 29: #include "roff.h"
30: #include "man.h"
1.18 schwarze 31: #include "out.h"
1.1 kristaps 32: #include "term.h"
1.18 schwarze 33: #include "main.h"
1.10 schwarze 34:
1.70 schwarze 35: #define MAXMARGINS 64 /* maximum number of indented scopes */
1.1 kristaps 36:
1.11 schwarze 37: struct mtermp {
38: int fl;
39: #define MANT_LITERAL (1 << 0)
1.116 schwarze 40: int lmargin[MAXMARGINS]; /* margins (incl. vis. page) */
1.70 schwarze 41: int lmargincur; /* index of current margin */
42: int lmarginsz; /* actual number of nested margins */
43: size_t offset; /* default offset to visible page */
1.88 schwarze 44: int pardist; /* vert. space before par., unit: [v] */
1.11 schwarze 45: };
46:
1.100 schwarze 47: #define DECL_ARGS struct termp *p, \
1.11 schwarze 48: struct mtermp *mt, \
1.125 schwarze 49: struct roff_node *n, \
1.126 schwarze 50: const struct roff_meta *meta
1.1 kristaps 51:
52: struct termact {
53: int (*pre)(DECL_ARGS);
54: void (*post)(DECL_ARGS);
1.26 schwarze 55: int flags;
56: #define MAN_NOTEXT (1 << 0) /* Never has text children. */
1.1 kristaps 57: };
58:
1.21 schwarze 59: static void print_man_nodelist(DECL_ARGS);
1.19 schwarze 60: static void print_man_node(DECL_ARGS);
1.126 schwarze 61: static void print_man_head(struct termp *,
62: const struct roff_meta *);
63: static void print_man_foot(struct termp *,
64: const struct roff_meta *);
1.100 schwarze 65: static void print_bvspace(struct termp *,
1.125 schwarze 66: const struct roff_node *, int);
1.18 schwarze 67:
1.1 kristaps 68: static int pre_B(DECL_ARGS);
1.11 schwarze 69: static int pre_HP(DECL_ARGS);
1.1 kristaps 70: static int pre_I(DECL_ARGS);
71: static int pre_IP(DECL_ARGS);
1.82 schwarze 72: static int pre_OP(DECL_ARGS);
1.88 schwarze 73: static int pre_PD(DECL_ARGS);
1.1 kristaps 74: static int pre_PP(DECL_ARGS);
1.13 schwarze 75: static int pre_RS(DECL_ARGS);
1.1 kristaps 76: static int pre_SH(DECL_ARGS);
77: static int pre_SS(DECL_ARGS);
78: static int pre_TP(DECL_ARGS);
1.91 schwarze 79: static int pre_UR(DECL_ARGS);
1.82 schwarze 80: static int pre_alternate(DECL_ARGS);
81: static int pre_ft(DECL_ARGS);
1.14 schwarze 82: static int pre_ign(DECL_ARGS);
1.45 schwarze 83: static int pre_in(DECL_ARGS);
84: static int pre_literal(DECL_ARGS);
1.97 schwarze 85: static int pre_ll(DECL_ARGS);
1.11 schwarze 86: static int pre_sp(DECL_ARGS);
1.1 kristaps 87:
1.11 schwarze 88: static void post_IP(DECL_ARGS);
89: static void post_HP(DECL_ARGS);
1.13 schwarze 90: static void post_RS(DECL_ARGS);
1.1 kristaps 91: static void post_SH(DECL_ARGS);
92: static void post_SS(DECL_ARGS);
1.11 schwarze 93: static void post_TP(DECL_ARGS);
1.91 schwarze 94: static void post_UR(DECL_ARGS);
1.1 kristaps 95:
1.145 ! schwarze 96: static const struct termact __termacts[MAN_MAX - MAN_TH] = {
1.26 schwarze 97: { NULL, NULL, 0 }, /* TH */
98: { pre_SH, post_SH, 0 }, /* SH */
99: { pre_SS, post_SS, 0 }, /* SS */
100: { pre_TP, post_TP, 0 }, /* TP */
101: { pre_PP, NULL, 0 }, /* LP */
102: { pre_PP, NULL, 0 }, /* PP */
103: { pre_PP, NULL, 0 }, /* P */
104: { pre_IP, post_IP, 0 }, /* IP */
1.100 schwarze 105: { pre_HP, post_HP, 0 }, /* HP */
1.26 schwarze 106: { NULL, NULL, 0 }, /* SM */
107: { pre_B, NULL, 0 }, /* SB */
1.51 schwarze 108: { pre_alternate, NULL, 0 }, /* BI */
109: { pre_alternate, NULL, 0 }, /* IB */
110: { pre_alternate, NULL, 0 }, /* BR */
111: { pre_alternate, NULL, 0 }, /* RB */
1.26 schwarze 112: { NULL, NULL, 0 }, /* R */
113: { pre_B, NULL, 0 }, /* B */
114: { pre_I, NULL, 0 }, /* I */
1.51 schwarze 115: { pre_alternate, NULL, 0 }, /* IR */
116: { pre_alternate, NULL, 0 }, /* RI */
1.145 ! schwarze 117: { pre_sp, NULL, MAN_NOTEXT }, /* br */
1.26 schwarze 118: { pre_sp, NULL, MAN_NOTEXT }, /* sp */
1.45 schwarze 119: { pre_literal, NULL, 0 }, /* nf */
120: { pre_literal, NULL, 0 }, /* fi */
1.26 schwarze 121: { NULL, NULL, 0 }, /* RE */
122: { pre_RS, post_RS, 0 }, /* RS */
123: { pre_ign, NULL, 0 }, /* DT */
1.111 schwarze 124: { pre_ign, NULL, MAN_NOTEXT }, /* UC */
1.88 schwarze 125: { pre_PD, NULL, MAN_NOTEXT }, /* PD */
1.36 schwarze 126: { pre_ign, NULL, 0 }, /* AT */
1.45 schwarze 127: { pre_in, NULL, MAN_NOTEXT }, /* in */
1.52 schwarze 128: { pre_ft, NULL, MAN_NOTEXT }, /* ft */
1.82 schwarze 129: { pre_OP, NULL, 0 }, /* OP */
1.83 schwarze 130: { pre_literal, NULL, 0 }, /* EX */
131: { pre_literal, NULL, 0 }, /* EE */
1.91 schwarze 132: { pre_UR, post_UR, 0 }, /* UR */
133: { NULL, NULL, 0 }, /* UE */
1.97 schwarze 134: { pre_ll, NULL, MAN_NOTEXT }, /* ll */
1.1 kristaps 135: };
1.145 ! schwarze 136: static const struct termact *termacts = __termacts - MAN_TH;
1.11 schwarze 137:
1.1 kristaps 138:
1.16 schwarze 139: void
1.133 schwarze 140: terminal_man(void *arg, const struct roff_man *man)
1.1 kristaps 141: {
1.18 schwarze 142: struct termp *p;
1.125 schwarze 143: struct roff_node *n;
1.18 schwarze 144: struct mtermp mt;
1.142 schwarze 145: size_t save_defindent;
1.18 schwarze 146:
147: p = (struct termp *)arg;
1.39 schwarze 148: p->overstep = 0;
1.104 schwarze 149: p->rmargin = p->maxrmargin = p->defrmargin;
1.42 schwarze 150: p->tabwidth = term_len(p, 5);
1.18 schwarze 151:
1.70 schwarze 152: memset(&mt, 0, sizeof(struct mtermp));
1.77 schwarze 153: mt.lmargin[mt.lmargincur] = term_len(p, p->defindent);
154: mt.offset = term_len(p, p->defindent);
1.88 schwarze 155: mt.pardist = 1;
1.11 schwarze 156:
1.134 schwarze 157: n = man->first->child;
1.104 schwarze 158: if (p->synopsisonly) {
159: while (n != NULL) {
160: if (n->tok == MAN_SH &&
1.124 schwarze 161: n->child->child->type == ROFFT_TEXT &&
1.104 schwarze 162: !strcmp(n->child->child->string, "SYNOPSIS")) {
163: if (n->child->next->child != NULL)
164: print_man_nodelist(p, &mt,
1.134 schwarze 165: n->child->next->child,
166: &man->meta);
1.104 schwarze 167: term_newln(p);
168: break;
169: }
170: n = n->next;
171: }
172: } else {
1.142 schwarze 173: save_defindent = p->defindent;
1.104 schwarze 174: if (p->defindent == 0)
175: p->defindent = 7;
1.134 schwarze 176: term_begin(p, print_man_head, print_man_foot, &man->meta);
1.104 schwarze 177: p->flags |= TERMP_NOSPACE;
178: if (n != NULL)
1.134 schwarze 179: print_man_nodelist(p, &mt, n, &man->meta);
1.104 schwarze 180: term_end(p);
1.142 schwarze 181: p->defindent = save_defindent;
1.104 schwarze 182: }
1.1 kristaps 183: }
184:
1.69 schwarze 185: /*
186: * Printing leading vertical space before a block.
187: * This is used for the paragraph macros.
188: * The rules are pretty simple, since there's very little nesting going
189: * on here. Basically, if we're the first within another block (SS/SH),
190: * then don't emit vertical space. If we are (RS), then do. If not the
191: * first, print it.
192: */
1.18 schwarze 193: static void
1.125 schwarze 194: print_bvspace(struct termp *p, const struct roff_node *n, int pardist)
1.18 schwarze 195: {
1.88 schwarze 196: int i;
1.69 schwarze 197:
1.18 schwarze 198: term_newln(p);
1.64 schwarze 199:
1.69 schwarze 200: if (n->body && n->body->child)
1.124 schwarze 201: if (n->body->child->type == ROFFT_TBL)
1.69 schwarze 202: return;
1.11 schwarze 203:
1.124 schwarze 204: if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
1.69 schwarze 205: if (NULL == n->prev)
206: return;
1.11 schwarze 207:
1.88 schwarze 208: for (i = 0; i < pardist; i++)
209: term_vspace(p);
1.14 schwarze 210: }
211:
1.100 schwarze 212:
1.14 schwarze 213: static int
214: pre_ign(DECL_ARGS)
215: {
216:
1.138 schwarze 217: return 0;
1.97 schwarze 218: }
219:
220: static int
221: pre_ll(DECL_ARGS)
222: {
223:
1.140 schwarze 224: term_setwidth(p, n->child != NULL ? n->child->string : NULL);
1.138 schwarze 225: return 0;
1.11 schwarze 226: }
227:
1.1 kristaps 228: static int
229: pre_I(DECL_ARGS)
230: {
231:
1.21 schwarze 232: term_fontrepl(p, TERMFONT_UNDER);
1.138 schwarze 233: return 1;
1.1 kristaps 234: }
235:
1.11 schwarze 236: static int
1.45 schwarze 237: pre_literal(DECL_ARGS)
1.11 schwarze 238: {
239:
1.45 schwarze 240: term_newln(p);
1.53 schwarze 241:
1.83 schwarze 242: if (MAN_nf == n->tok || MAN_EX == n->tok)
1.45 schwarze 243: mt->fl |= MANT_LITERAL;
1.53 schwarze 244: else
1.45 schwarze 245: mt->fl &= ~MANT_LITERAL;
246:
1.72 schwarze 247: /*
248: * Unlike .IP and .TP, .HP does not have a HEAD.
249: * So in case a second call to term_flushln() is needed,
250: * indentation has to be set up explicitly.
251: */
252: if (MAN_HP == n->parent->tok && p->rmargin < p->maxrmargin) {
1.76 schwarze 253: p->offset = p->rmargin;
1.72 schwarze 254: p->rmargin = p->maxrmargin;
1.93 schwarze 255: p->trailspace = 0;
1.99 schwarze 256: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
1.72 schwarze 257: p->flags |= TERMP_NOSPACE;
258: }
259:
1.138 schwarze 260: return 0;
1.11 schwarze 261: }
262:
263: static int
1.88 schwarze 264: pre_PD(DECL_ARGS)
265: {
1.113 schwarze 266: struct roffsu su;
1.88 schwarze 267:
268: n = n->child;
1.113 schwarze 269: if (n == NULL) {
1.88 schwarze 270: mt->pardist = 1;
1.138 schwarze 271: return 0;
1.88 schwarze 272: }
1.124 schwarze 273: assert(n->type == ROFFT_TEXT);
1.113 schwarze 274: if (a2roffsu(n->string, &su, SCALE_VS))
275: mt->pardist = term_vspan(p, &su);
1.138 schwarze 276: return 0;
1.88 schwarze 277: }
278:
279: static int
1.51 schwarze 280: pre_alternate(DECL_ARGS)
1.1 kristaps 281: {
1.51 schwarze 282: enum termfont font[2];
1.125 schwarze 283: struct roff_node *nn;
1.51 schwarze 284: int savelit, i;
1.1 kristaps 285:
1.51 schwarze 286: switch (n->tok) {
1.100 schwarze 287: case MAN_RB:
1.51 schwarze 288: font[0] = TERMFONT_NONE;
289: font[1] = TERMFONT_BOLD;
290: break;
1.100 schwarze 291: case MAN_RI:
1.51 schwarze 292: font[0] = TERMFONT_NONE;
293: font[1] = TERMFONT_UNDER;
294: break;
1.100 schwarze 295: case MAN_BR:
1.51 schwarze 296: font[0] = TERMFONT_BOLD;
297: font[1] = TERMFONT_NONE;
298: break;
1.100 schwarze 299: case MAN_BI:
1.51 schwarze 300: font[0] = TERMFONT_BOLD;
301: font[1] = TERMFONT_UNDER;
302: break;
1.100 schwarze 303: case MAN_IR:
1.51 schwarze 304: font[0] = TERMFONT_UNDER;
305: font[1] = TERMFONT_NONE;
306: break;
1.100 schwarze 307: case MAN_IB:
1.51 schwarze 308: font[0] = TERMFONT_UNDER;
309: font[1] = TERMFONT_BOLD;
310: break;
311: default:
312: abort();
313: }
1.17 schwarze 314:
1.51 schwarze 315: savelit = MANT_LITERAL & mt->fl;
316: mt->fl &= ~MANT_LITERAL;
1.17 schwarze 317:
1.51 schwarze 318: for (i = 0, nn = n->child; nn; nn = nn->next, i = 1 - i) {
319: term_fontrepl(p, font[i]);
320: if (savelit && NULL == nn->next)
321: mt->fl |= MANT_LITERAL;
1.132 schwarze 322: assert(nn->type == ROFFT_TEXT);
323: term_word(p, nn->string);
1.141 schwarze 324: if (nn->flags & NODE_EOS)
1.132 schwarze 325: p->flags |= TERMP_SENTENCE;
1.51 schwarze 326: if (nn->next)
1.1 kristaps 327: p->flags |= TERMP_NOSPACE;
328: }
1.17 schwarze 329:
1.138 schwarze 330: return 0;
1.1 kristaps 331: }
332:
333: static int
334: pre_B(DECL_ARGS)
335: {
336:
1.21 schwarze 337: term_fontrepl(p, TERMFONT_BOLD);
1.138 schwarze 338: return 1;
1.82 schwarze 339: }
340:
341: static int
342: pre_OP(DECL_ARGS)
343: {
344:
345: term_word(p, "[");
346: p->flags |= TERMP_NOSPACE;
347:
348: if (NULL != (n = n->child)) {
349: term_fontrepl(p, TERMFONT_BOLD);
350: term_word(p, n->string);
351: }
352: if (NULL != n && NULL != n->next) {
353: term_fontrepl(p, TERMFONT_UNDER);
354: term_word(p, n->next->string);
355: }
356:
357: term_fontrepl(p, TERMFONT_NONE);
358: p->flags |= TERMP_NOSPACE;
359: term_word(p, "]");
1.138 schwarze 360: return 0;
1.52 schwarze 361: }
362:
363: static int
364: pre_ft(DECL_ARGS)
365: {
366: const char *cp;
367:
368: if (NULL == n->child) {
369: term_fontlast(p);
1.138 schwarze 370: return 0;
1.52 schwarze 371: }
372:
373: cp = n->child->string;
374: switch (*cp) {
1.100 schwarze 375: case '4':
376: case '3':
377: case 'B':
1.52 schwarze 378: term_fontrepl(p, TERMFONT_BOLD);
379: break;
1.100 schwarze 380: case '2':
381: case 'I':
1.52 schwarze 382: term_fontrepl(p, TERMFONT_UNDER);
383: break;
1.100 schwarze 384: case 'P':
1.52 schwarze 385: term_fontlast(p);
386: break;
1.100 schwarze 387: case '1':
388: case 'C':
389: case 'R':
1.52 schwarze 390: term_fontrepl(p, TERMFONT_NONE);
391: break;
392: default:
393: break;
394: }
1.138 schwarze 395: return 0;
1.1 kristaps 396: }
397:
398: static int
1.45 schwarze 399: pre_in(DECL_ARGS)
1.11 schwarze 400: {
1.116 schwarze 401: struct roffsu su;
402: const char *cp;
1.45 schwarze 403: size_t v;
1.116 schwarze 404: int less;
1.45 schwarze 405:
406: term_newln(p);
407:
408: if (NULL == n->child) {
409: p->offset = mt->offset;
1.138 schwarze 410: return 0;
1.45 schwarze 411: }
1.11 schwarze 412:
1.45 schwarze 413: cp = n->child->string;
414: less = 0;
1.11 schwarze 415:
1.45 schwarze 416: if ('-' == *cp)
417: less = -1;
418: else if ('+' == *cp)
419: less = 1;
420: else
421: cp--;
422:
1.116 schwarze 423: if ( ! a2roffsu(++cp, &su, SCALE_EN))
1.138 schwarze 424: return 0;
1.45 schwarze 425:
1.128 schwarze 426: v = (term_hspan(p, &su) + 11) / 24;
1.45 schwarze 427:
428: if (less < 0)
429: p->offset -= p->offset > v ? v : p->offset;
430: else if (less > 0)
431: p->offset += v;
1.100 schwarze 432: else
1.45 schwarze 433: p->offset = v;
1.117 schwarze 434: if (p->offset > SHRT_MAX)
435: p->offset = term_len(p, p->defindent);
1.59 schwarze 436:
1.138 schwarze 437: return 0;
1.11 schwarze 438: }
439:
440: static int
1.45 schwarze 441: pre_sp(DECL_ARGS)
1.8 schwarze 442: {
1.115 schwarze 443: struct roffsu su;
1.116 schwarze 444: int i, len;
1.45 schwarze 445:
1.69 schwarze 446: if ((NULL == n->prev && n->parent)) {
1.86 schwarze 447: switch (n->parent->tok) {
1.100 schwarze 448: case MAN_SH:
449: case MAN_SS:
450: case MAN_PP:
451: case MAN_LP:
452: case MAN_P:
1.138 schwarze 453: return 0;
1.86 schwarze 454: default:
455: break;
456: }
1.69 schwarze 457: }
458:
1.116 schwarze 459: if (n->tok == MAN_br)
1.45 schwarze 460: len = 0;
1.116 schwarze 461: else if (n->child == NULL)
462: len = 1;
463: else {
464: if ( ! a2roffsu(n->child->string, &su, SCALE_VS))
1.115 schwarze 465: su.scale = 1.0;
466: len = term_vspan(p, &su);
1.45 schwarze 467: }
468:
1.116 schwarze 469: if (len == 0)
1.45 schwarze 470: term_newln(p);
1.116 schwarze 471: else if (len < 0)
472: p->skipvsp -= len;
1.85 schwarze 473: else
474: for (i = 0; i < len; i++)
475: term_vspace(p);
1.136 schwarze 476:
477: /*
478: * Handle an explicit break request in the same way
479: * as an overflowing line.
480: */
481:
482: if (p->flags & TERMP_BRIND) {
483: p->offset = p->rmargin;
484: p->rmargin = p->maxrmargin;
485: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
486: }
1.8 schwarze 487:
1.138 schwarze 488: return 0;
1.8 schwarze 489: }
490:
491: static int
1.11 schwarze 492: pre_HP(DECL_ARGS)
493: {
1.116 schwarze 494: struct roffsu su;
1.125 schwarze 495: const struct roff_node *nn;
1.116 schwarze 496: int len;
1.11 schwarze 497:
498: switch (n->type) {
1.124 schwarze 499: case ROFFT_BLOCK:
1.88 schwarze 500: print_bvspace(p, n, mt->pardist);
1.138 schwarze 501: return 1;
1.124 schwarze 502: case ROFFT_BODY:
1.11 schwarze 503: break;
504: default:
1.138 schwarze 505: return 0;
1.11 schwarze 506: }
507:
1.84 schwarze 508: if ( ! (MANT_LITERAL & mt->fl)) {
1.99 schwarze 509: p->flags |= TERMP_NOBREAK | TERMP_BRIND;
1.93 schwarze 510: p->trailspace = 2;
1.84 schwarze 511: }
512:
1.11 schwarze 513: /* Calculate offset. */
514:
1.116 schwarze 515: if ((nn = n->parent->head->child) != NULL &&
516: a2roffsu(nn->string, &su, SCALE_EN)) {
1.128 schwarze 517: len = term_hspan(p, &su) / 24;
1.117 schwarze 518: if (len < 0 && (size_t)(-len) > mt->offset)
519: len = -mt->offset;
520: else if (len > SHRT_MAX)
521: len = term_len(p, p->defindent);
1.116 schwarze 522: mt->lmargin[mt->lmargincur] = len;
523: } else
524: len = mt->lmargin[mt->lmargincur];
1.11 schwarze 525:
1.13 schwarze 526: p->offset = mt->offset;
1.117 schwarze 527: p->rmargin = mt->offset + len;
1.138 schwarze 528: return 1;
1.11 schwarze 529: }
530:
531: static void
532: post_HP(DECL_ARGS)
533: {
534:
535: switch (n->type) {
1.124 schwarze 536: case ROFFT_BODY:
1.90 schwarze 537: term_newln(p);
1.127 schwarze 538:
539: /*
540: * Compatibility with a groff bug.
541: * The .HP macro uses the undocumented .tag request
542: * which causes a line break and cancels no-space
543: * mode even if there isn't any output.
544: */
545:
546: if (n->child == NULL)
547: term_vspace(p);
548:
1.99 schwarze 549: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
1.93 schwarze 550: p->trailspace = 0;
1.13 schwarze 551: p->offset = mt->offset;
1.11 schwarze 552: p->rmargin = p->maxrmargin;
553: break;
554: default:
555: break;
556: }
557: }
558:
559: static int
1.1 kristaps 560: pre_PP(DECL_ARGS)
561: {
562:
1.11 schwarze 563: switch (n->type) {
1.124 schwarze 564: case ROFFT_BLOCK:
1.77 schwarze 565: mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
1.88 schwarze 566: print_bvspace(p, n, mt->pardist);
1.11 schwarze 567: break;
568: default:
1.13 schwarze 569: p->offset = mt->offset;
1.11 schwarze 570: break;
571: }
572:
1.138 schwarze 573: return n->type != ROFFT_HEAD;
1.1 kristaps 574: }
575:
576: static int
577: pre_IP(DECL_ARGS)
578: {
1.116 schwarze 579: struct roffsu su;
1.125 schwarze 580: const struct roff_node *nn;
1.116 schwarze 581: int len, savelit;
1.11 schwarze 582:
583: switch (n->type) {
1.124 schwarze 584: case ROFFT_BODY:
1.11 schwarze 585: p->flags |= TERMP_NOSPACE;
586: break;
1.124 schwarze 587: case ROFFT_HEAD:
1.11 schwarze 588: p->flags |= TERMP_NOBREAK;
1.93 schwarze 589: p->trailspace = 1;
1.11 schwarze 590: break;
1.124 schwarze 591: case ROFFT_BLOCK:
1.88 schwarze 592: print_bvspace(p, n, mt->pardist);
1.11 schwarze 593: /* FALLTHROUGH */
594: default:
1.138 schwarze 595: return 1;
1.11 schwarze 596: }
597:
1.57 schwarze 598: /* Calculate the offset from the optional second argument. */
1.116 schwarze 599: if ((nn = n->parent->head->child) != NULL &&
600: (nn = nn->next) != NULL &&
601: a2roffsu(nn->string, &su, SCALE_EN)) {
1.128 schwarze 602: len = term_hspan(p, &su) / 24;
1.116 schwarze 603: if (len < 0 && (size_t)(-len) > mt->offset)
604: len = -mt->offset;
1.117 schwarze 605: else if (len > SHRT_MAX)
606: len = term_len(p, p->defindent);
607: mt->lmargin[mt->lmargincur] = len;
1.116 schwarze 608: } else
609: len = mt->lmargin[mt->lmargincur];
1.11 schwarze 610:
611: switch (n->type) {
1.124 schwarze 612: case ROFFT_HEAD:
1.13 schwarze 613: p->offset = mt->offset;
614: p->rmargin = mt->offset + len;
1.11 schwarze 615:
1.57 schwarze 616: savelit = MANT_LITERAL & mt->fl;
617: mt->fl &= ~MANT_LITERAL;
618:
619: if (n->child)
1.89 schwarze 620: print_man_node(p, mt, n->child, meta);
1.57 schwarze 621:
622: if (savelit)
623: mt->fl |= MANT_LITERAL;
624:
1.138 schwarze 625: return 0;
1.124 schwarze 626: case ROFFT_BODY:
1.13 schwarze 627: p->offset = mt->offset + len;
1.109 schwarze 628: p->rmargin = p->maxrmargin;
1.11 schwarze 629: break;
630: default:
631: break;
632: }
1.1 kristaps 633:
1.138 schwarze 634: return 1;
1.11 schwarze 635: }
1.1 kristaps 636:
1.11 schwarze 637: static void
638: post_IP(DECL_ARGS)
639: {
1.4 schwarze 640:
1.11 schwarze 641: switch (n->type) {
1.124 schwarze 642: case ROFFT_HEAD:
1.11 schwarze 643: term_flushln(p);
644: p->flags &= ~TERMP_NOBREAK;
1.93 schwarze 645: p->trailspace = 0;
1.11 schwarze 646: p->rmargin = p->maxrmargin;
647: break;
1.124 schwarze 648: case ROFFT_BODY:
1.57 schwarze 649: term_newln(p);
1.92 schwarze 650: p->offset = mt->offset;
1.11 schwarze 651: break;
652: default:
653: break;
654: }
1.1 kristaps 655: }
656:
657: static int
658: pre_TP(DECL_ARGS)
659: {
1.116 schwarze 660: struct roffsu su;
1.125 schwarze 661: struct roff_node *nn;
1.116 schwarze 662: int len, savelit;
1.11 schwarze 663:
664: switch (n->type) {
1.124 schwarze 665: case ROFFT_HEAD:
1.137 schwarze 666: p->flags |= TERMP_NOBREAK | TERMP_BRTRSP;
1.93 schwarze 667: p->trailspace = 1;
1.11 schwarze 668: break;
1.124 schwarze 669: case ROFFT_BODY:
1.11 schwarze 670: p->flags |= TERMP_NOSPACE;
671: break;
1.124 schwarze 672: case ROFFT_BLOCK:
1.88 schwarze 673: print_bvspace(p, n, mt->pardist);
1.11 schwarze 674: /* FALLTHROUGH */
675: default:
1.138 schwarze 676: return 1;
1.11 schwarze 677: }
678:
679: /* Calculate offset. */
1.1 kristaps 680:
1.116 schwarze 681: if ((nn = n->parent->head->child) != NULL &&
1.141 schwarze 682: nn->string != NULL && ! (NODE_LINE & nn->flags) &&
1.116 schwarze 683: a2roffsu(nn->string, &su, SCALE_EN)) {
1.128 schwarze 684: len = term_hspan(p, &su) / 24;
1.116 schwarze 685: if (len < 0 && (size_t)(-len) > mt->offset)
686: len = -mt->offset;
1.117 schwarze 687: else if (len > SHRT_MAX)
688: len = term_len(p, p->defindent);
689: mt->lmargin[mt->lmargincur] = len;
1.116 schwarze 690: } else
691: len = mt->lmargin[mt->lmargincur];
1.8 schwarze 692:
1.11 schwarze 693: switch (n->type) {
1.124 schwarze 694: case ROFFT_HEAD:
1.13 schwarze 695: p->offset = mt->offset;
696: p->rmargin = mt->offset + len;
1.11 schwarze 697:
1.57 schwarze 698: savelit = MANT_LITERAL & mt->fl;
699: mt->fl &= ~MANT_LITERAL;
700:
1.11 schwarze 701: /* Don't print same-line elements. */
1.95 schwarze 702: nn = n->child;
1.141 schwarze 703: while (NULL != nn && 0 == (NODE_LINE & nn->flags))
1.95 schwarze 704: nn = nn->next;
705:
706: while (NULL != nn) {
707: print_man_node(p, mt, nn, meta);
708: nn = nn->next;
709: }
1.11 schwarze 710:
1.57 schwarze 711: if (savelit)
712: mt->fl |= MANT_LITERAL;
1.138 schwarze 713: return 0;
1.124 schwarze 714: case ROFFT_BODY:
1.13 schwarze 715: p->offset = mt->offset + len;
1.109 schwarze 716: p->rmargin = p->maxrmargin;
1.93 schwarze 717: p->trailspace = 0;
1.137 schwarze 718: p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP);
1.11 schwarze 719: break;
720: default:
721: break;
722: }
1.1 kristaps 723:
1.138 schwarze 724: return 1;
1.11 schwarze 725: }
1.1 kristaps 726:
1.11 schwarze 727: static void
728: post_TP(DECL_ARGS)
729: {
1.1 kristaps 730:
1.11 schwarze 731: switch (n->type) {
1.124 schwarze 732: case ROFFT_HEAD:
1.11 schwarze 733: term_flushln(p);
734: break;
1.124 schwarze 735: case ROFFT_BODY:
1.57 schwarze 736: term_newln(p);
1.92 schwarze 737: p->offset = mt->offset;
1.11 schwarze 738: break;
739: default:
740: break;
741: }
1.1 kristaps 742: }
743:
744: static int
745: pre_SS(DECL_ARGS)
746: {
1.88 schwarze 747: int i;
1.1 kristaps 748:
1.11 schwarze 749: switch (n->type) {
1.124 schwarze 750: case ROFFT_BLOCK:
1.69 schwarze 751: mt->fl &= ~MANT_LITERAL;
1.77 schwarze 752: mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
753: mt->offset = term_len(p, p->defindent);
1.111 schwarze 754:
755: /*
756: * No vertical space before the first subsection
757: * and after an empty subsection.
758: */
759:
760: do {
761: n = n->prev;
1.135 schwarze 762: } while (n != NULL && n->tok != TOKEN_NONE &&
1.123 schwarze 763: termacts[n->tok].flags & MAN_NOTEXT);
1.111 schwarze 764: if (n == NULL || (n->tok == MAN_SS && n->body->child == NULL))
1.11 schwarze 765: break;
1.111 schwarze 766:
1.88 schwarze 767: for (i = 0; i < mt->pardist; i++)
768: term_vspace(p);
1.11 schwarze 769: break;
1.124 schwarze 770: case ROFFT_HEAD:
1.21 schwarze 771: term_fontrepl(p, TERMFONT_BOLD);
1.87 schwarze 772: p->offset = term_len(p, 3);
1.129 schwarze 773: p->rmargin = mt->offset;
774: p->trailspace = mt->offset;
775: p->flags |= TERMP_NOBREAK | TERMP_BRIND;
1.11 schwarze 776: break;
1.124 schwarze 777: case ROFFT_BODY:
1.13 schwarze 778: p->offset = mt->offset;
1.129 schwarze 779: p->rmargin = p->maxrmargin;
780: p->trailspace = 0;
781: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
1.11 schwarze 782: break;
783: default:
784: break;
785: }
786:
1.138 schwarze 787: return 1;
1.1 kristaps 788: }
789:
790: static void
791: post_SS(DECL_ARGS)
792: {
1.100 schwarze 793:
1.11 schwarze 794: switch (n->type) {
1.124 schwarze 795: case ROFFT_HEAD:
1.11 schwarze 796: term_newln(p);
797: break;
1.124 schwarze 798: case ROFFT_BODY:
1.11 schwarze 799: term_newln(p);
800: break;
801: default:
802: break;
803: }
1.1 kristaps 804: }
805:
806: static int
807: pre_SH(DECL_ARGS)
808: {
1.88 schwarze 809: int i;
1.1 kristaps 810:
1.11 schwarze 811: switch (n->type) {
1.124 schwarze 812: case ROFFT_BLOCK:
1.69 schwarze 813: mt->fl &= ~MANT_LITERAL;
1.77 schwarze 814: mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
815: mt->offset = term_len(p, p->defindent);
1.111 schwarze 816:
817: /*
818: * No vertical space before the first section
819: * and after an empty section.
820: */
821:
822: do {
823: n = n->prev;
1.144 schwarze 824: } while (n != NULL && n->tok != TOKEN_NONE &&
1.143 schwarze 825: termacts[n->tok].flags & MAN_NOTEXT);
1.111 schwarze 826: if (n == NULL || (n->tok == MAN_SH && n->body->child == NULL))
1.29 schwarze 827: break;
1.111 schwarze 828:
1.88 schwarze 829: for (i = 0; i < mt->pardist; i++)
830: term_vspace(p);
1.11 schwarze 831: break;
1.124 schwarze 832: case ROFFT_HEAD:
1.21 schwarze 833: term_fontrepl(p, TERMFONT_BOLD);
1.11 schwarze 834: p->offset = 0;
1.129 schwarze 835: p->rmargin = mt->offset;
836: p->trailspace = mt->offset;
837: p->flags |= TERMP_NOBREAK | TERMP_BRIND;
1.11 schwarze 838: break;
1.124 schwarze 839: case ROFFT_BODY:
1.13 schwarze 840: p->offset = mt->offset;
1.129 schwarze 841: p->rmargin = p->maxrmargin;
842: p->trailspace = 0;
843: p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
1.11 schwarze 844: break;
845: default:
846: break;
847: }
848:
1.138 schwarze 849: return 1;
1.1 kristaps 850: }
851:
852: static void
853: post_SH(DECL_ARGS)
854: {
1.100 schwarze 855:
1.11 schwarze 856: switch (n->type) {
1.124 schwarze 857: case ROFFT_HEAD:
1.11 schwarze 858: term_newln(p);
859: break;
1.124 schwarze 860: case ROFFT_BODY:
1.11 schwarze 861: term_newln(p);
862: break;
863: default:
1.13 schwarze 864: break;
865: }
866: }
867:
868: static int
869: pre_RS(DECL_ARGS)
870: {
1.116 schwarze 871: struct roffsu su;
1.13 schwarze 872:
873: switch (n->type) {
1.124 schwarze 874: case ROFFT_BLOCK:
1.13 schwarze 875: term_newln(p);
1.138 schwarze 876: return 1;
1.124 schwarze 877: case ROFFT_HEAD:
1.138 schwarze 878: return 0;
1.13 schwarze 879: default:
880: break;
881: }
882:
1.118 schwarze 883: n = n->parent->head;
884: n->aux = SHRT_MAX + 1;
1.130 schwarze 885: if (n->child == NULL)
886: n->aux = mt->lmargin[mt->lmargincur];
887: else if (a2roffsu(n->child->string, &su, SCALE_EN))
1.128 schwarze 888: n->aux = term_hspan(p, &su) / 24;
1.118 schwarze 889: if (n->aux < 0 && (size_t)(-n->aux) > mt->offset)
890: n->aux = -mt->offset;
891: else if (n->aux > SHRT_MAX)
892: n->aux = term_len(p, p->defindent);
1.13 schwarze 893:
1.118 schwarze 894: mt->offset += n->aux;
1.94 schwarze 895: p->offset = mt->offset;
1.109 schwarze 896: p->rmargin = p->maxrmargin;
1.13 schwarze 897:
1.70 schwarze 898: if (++mt->lmarginsz < MAXMARGINS)
899: mt->lmargincur = mt->lmarginsz;
900:
1.131 schwarze 901: mt->lmargin[mt->lmargincur] = term_len(p, p->defindent);
1.138 schwarze 902: return 1;
1.13 schwarze 903: }
904:
905: static void
906: post_RS(DECL_ARGS)
907: {
908:
909: switch (n->type) {
1.124 schwarze 910: case ROFFT_BLOCK:
1.69 schwarze 911: return;
1.124 schwarze 912: case ROFFT_HEAD:
1.69 schwarze 913: return;
1.13 schwarze 914: default:
915: term_newln(p);
1.11 schwarze 916: break;
917: }
1.69 schwarze 918:
1.118 schwarze 919: mt->offset -= n->parent->head->aux;
1.69 schwarze 920: p->offset = mt->offset;
1.70 schwarze 921:
922: if (--mt->lmarginsz < MAXMARGINS)
923: mt->lmargincur = mt->lmarginsz;
1.91 schwarze 924: }
925:
926: static int
927: pre_UR(DECL_ARGS)
928: {
929:
1.138 schwarze 930: return n->type != ROFFT_HEAD;
1.91 schwarze 931: }
932:
933: static void
934: post_UR(DECL_ARGS)
935: {
936:
1.124 schwarze 937: if (n->type != ROFFT_BLOCK)
1.91 schwarze 938: return;
939:
940: term_word(p, "<");
941: p->flags |= TERMP_NOSPACE;
942:
943: if (NULL != n->child->child)
944: print_man_node(p, mt, n->child->child, meta);
945:
946: p->flags |= TERMP_NOSPACE;
947: term_word(p, ">");
1.47 schwarze 948: }
949:
1.1 kristaps 950: static void
1.19 schwarze 951: print_man_node(DECL_ARGS)
1.1 kristaps 952: {
1.32 schwarze 953: size_t rm, rmax;
1.21 schwarze 954: int c;
1.1 kristaps 955:
956: switch (n->type) {
1.124 schwarze 957: case ROFFT_TEXT:
1.61 schwarze 958: /*
959: * If we have a blank line, output a vertical space.
960: * If we have a space as the first character, break
961: * before printing the line's data.
962: */
1.60 schwarze 963: if ('\0' == *n->string) {
1.1 kristaps 964: term_vspace(p);
1.61 schwarze 965: return;
1.141 schwarze 966: } else if (' ' == *n->string && NODE_LINE & n->flags)
1.60 schwarze 967: term_newln(p);
1.21 schwarze 968:
1.1 kristaps 969: term_word(p, n->string);
1.84 schwarze 970: goto out;
1.21 schwarze 971:
1.124 schwarze 972: case ROFFT_EQN:
1.141 schwarze 973: if ( ! (n->flags & NODE_LINE))
1.105 schwarze 974: p->flags |= TERMP_NOSPACE;
1.71 schwarze 975: term_eqn(p, n->eqn);
1.141 schwarze 976: if (n->next != NULL && ! (n->next->flags & NODE_LINE))
1.106 schwarze 977: p->flags |= TERMP_NOSPACE;
1.61 schwarze 978: return;
1.124 schwarze 979: case ROFFT_TBL:
1.122 schwarze 980: if (p->tbl.cols == NULL)
981: term_vspace(p);
1.58 schwarze 982: term_tbl(p, n->span);
1.61 schwarze 983: return;
1.1 kristaps 984: default:
985: break;
986: }
987:
1.61 schwarze 988: if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
989: term_fontrepl(p, TERMFONT_NONE);
990:
991: c = 1;
992: if (termacts[n->tok].pre)
1.89 schwarze 993: c = (*termacts[n->tok].pre)(p, mt, n, meta);
1.61 schwarze 994:
1.1 kristaps 995: if (c && n->child)
1.89 schwarze 996: print_man_nodelist(p, mt, n->child, meta);
1.1 kristaps 997:
1.61 schwarze 998: if (termacts[n->tok].post)
1.89 schwarze 999: (*termacts[n->tok].post)(p, mt, n, meta);
1.61 schwarze 1000: if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
1001: term_fontrepl(p, TERMFONT_NONE);
1.30 schwarze 1002:
1.84 schwarze 1003: out:
1004: /*
1005: * If we're in a literal context, make sure that words
1006: * together on the same line stay together. This is a
1007: * POST-printing call, so we check the NEXT word. Since
1008: * -man doesn't have nested macros, we don't need to be
1009: * more specific than this.
1010: */
1.110 schwarze 1011: if (mt->fl & MANT_LITERAL &&
1012: ! (p->flags & (TERMP_NOBREAK | TERMP_NONEWLINE)) &&
1.141 schwarze 1013: (n->next == NULL || n->next->flags & NODE_LINE)) {
1.84 schwarze 1014: rm = p->rmargin;
1015: rmax = p->maxrmargin;
1016: p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1017: p->flags |= TERMP_NOSPACE;
1.110 schwarze 1018: if (n->string != NULL && *n->string != '\0')
1.84 schwarze 1019: term_flushln(p);
1020: else
1021: term_newln(p);
1022: if (rm < rmax && n->parent->tok == MAN_HP) {
1023: p->offset = rm;
1024: p->rmargin = rmax;
1025: } else
1026: p->rmargin = rm;
1027: p->maxrmargin = rmax;
1028: }
1.141 schwarze 1029: if (NODE_EOS & n->flags)
1.30 schwarze 1030: p->flags |= TERMP_SENTENCE;
1.1 kristaps 1031: }
1032:
1033:
1034: static void
1.21 schwarze 1035: print_man_nodelist(DECL_ARGS)
1.1 kristaps 1036: {
1.11 schwarze 1037:
1.121 schwarze 1038: while (n != NULL) {
1039: print_man_node(p, mt, n, meta);
1040: n = n->next;
1041: }
1.1 kristaps 1042: }
1043:
1044: static void
1.126 schwarze 1045: print_man_foot(struct termp *p, const struct roff_meta *meta)
1.1 kristaps 1046: {
1.101 schwarze 1047: char *title;
1.109 schwarze 1048: size_t datelen, titlen;
1.41 schwarze 1049:
1.80 schwarze 1050: assert(meta->title);
1051: assert(meta->msec);
1052: assert(meta->date);
1.21 schwarze 1053:
1054: term_fontrepl(p, TERMFONT_NONE);
1.1 kristaps 1055:
1.103 schwarze 1056: if (meta->hasbody)
1057: term_vspace(p);
1.81 schwarze 1058:
1059: /*
1060: * Temporary, undocumented option to imitate mdoc(7) output.
1.126 schwarze 1061: * In the bottom right corner, use the operating system
1062: * instead of the title.
1.81 schwarze 1063: */
1064:
1.79 schwarze 1065: if ( ! p->mdocstyle) {
1.103 schwarze 1066: if (meta->hasbody) {
1067: term_vspace(p);
1068: term_vspace(p);
1069: }
1.101 schwarze 1070: mandoc_asprintf(&title, "%s(%s)",
1071: meta->title, meta->msec);
1.126 schwarze 1072: } else if (meta->os) {
1073: title = mandoc_strdup(meta->os);
1.79 schwarze 1074: } else {
1.101 schwarze 1075: title = mandoc_strdup("");
1.79 schwarze 1076: }
1.78 schwarze 1077: datelen = term_strlen(p, meta->date);
1.1 kristaps 1078:
1.126 schwarze 1079: /* Bottom left corner: operating system. */
1.81 schwarze 1080:
1.1 kristaps 1081: p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
1.93 schwarze 1082: p->trailspace = 1;
1.1 kristaps 1083: p->offset = 0;
1.109 schwarze 1084: p->rmargin = p->maxrmargin > datelen ?
1085: (p->maxrmargin + term_len(p, 1) - datelen) / 2 : 0;
1.1 kristaps 1086:
1.126 schwarze 1087: if (meta->os)
1088: term_word(p, meta->os);
1.1 kristaps 1089: term_flushln(p);
1090:
1.81 schwarze 1091: /* At the bottom in the middle: manual date. */
1092:
1.109 schwarze 1093: p->offset = p->rmargin;
1094: titlen = term_strlen(p, title);
1095: p->rmargin = p->maxrmargin > titlen ? p->maxrmargin - titlen : 0;
1.72 schwarze 1096: p->flags |= TERMP_NOSPACE;
1.78 schwarze 1097:
1098: term_word(p, meta->date);
1099: term_flushln(p);
1100:
1.81 schwarze 1101: /* Bottom right corner: manual title and section. */
1102:
1.78 schwarze 1103: p->flags &= ~TERMP_NOBREAK;
1104: p->flags |= TERMP_NOSPACE;
1.93 schwarze 1105: p->trailspace = 0;
1.78 schwarze 1106: p->offset = p->rmargin;
1.1 kristaps 1107: p->rmargin = p->maxrmargin;
1108:
1.78 schwarze 1109: term_word(p, title);
1.1 kristaps 1110: term_flushln(p);
1.101 schwarze 1111: free(title);
1.1 kristaps 1112: }
1113:
1114: static void
1.126 schwarze 1115: print_man_head(struct termp *p, const struct roff_meta *meta)
1.1 kristaps 1116: {
1.102 schwarze 1117: const char *volume;
1.101 schwarze 1118: char *title;
1.102 schwarze 1119: size_t vollen, titlen;
1.41 schwarze 1120:
1.89 schwarze 1121: assert(meta->title);
1122: assert(meta->msec);
1.1 kristaps 1123:
1.102 schwarze 1124: volume = NULL == meta->vol ? "" : meta->vol;
1125: vollen = term_strlen(p, volume);
1.1 kristaps 1126:
1.81 schwarze 1127: /* Top left corner: manual title and section. */
1128:
1.101 schwarze 1129: mandoc_asprintf(&title, "%s(%s)", meta->title, meta->msec);
1.42 schwarze 1130: titlen = term_strlen(p, title);
1.1 kristaps 1131:
1.73 schwarze 1132: p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
1.93 schwarze 1133: p->trailspace = 1;
1.1 kristaps 1134: p->offset = 0;
1.102 schwarze 1135: p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ?
1136: (p->maxrmargin - vollen + term_len(p, 1)) / 2 :
1.109 schwarze 1137: vollen < p->maxrmargin ? p->maxrmargin - vollen : 0;
1.1 kristaps 1138:
1139: term_word(p, title);
1140: term_flushln(p);
1141:
1.81 schwarze 1142: /* At the top in the middle: manual volume. */
1143:
1.72 schwarze 1144: p->flags |= TERMP_NOSPACE;
1.1 kristaps 1145: p->offset = p->rmargin;
1.102 schwarze 1146: p->rmargin = p->offset + vollen + titlen < p->maxrmargin ?
1.25 schwarze 1147: p->maxrmargin - titlen : p->maxrmargin;
1.1 kristaps 1148:
1.102 schwarze 1149: term_word(p, volume);
1.1 kristaps 1150: term_flushln(p);
1151:
1.81 schwarze 1152: /* Top right corner: title and section, again. */
1153:
1.1 kristaps 1154: p->flags &= ~TERMP_NOBREAK;
1.93 schwarze 1155: p->trailspace = 0;
1.25 schwarze 1156: if (p->rmargin + titlen <= p->maxrmargin) {
1.72 schwarze 1157: p->flags |= TERMP_NOSPACE;
1.25 schwarze 1158: p->offset = p->rmargin;
1159: p->rmargin = p->maxrmargin;
1160: term_word(p, title);
1161: term_flushln(p);
1162: }
1.1 kristaps 1163:
1.73 schwarze 1164: p->flags &= ~TERMP_NOSPACE;
1165: p->offset = 0;
1.1 kristaps 1166: p->rmargin = p->maxrmargin;
1.29 schwarze 1167:
1.100 schwarze 1168: /*
1.81 schwarze 1169: * Groff prints three blank lines before the content.
1170: * Do the same, except in the temporary, undocumented
1171: * mode imitating mdoc(7) output.
1.29 schwarze 1172: */
1173:
1174: term_vspace(p);
1.79 schwarze 1175: if ( ! p->mdocstyle) {
1176: term_vspace(p);
1177: term_vspace(p);
1178: }
1.101 schwarze 1179: free(title);
1.1 kristaps 1180: }