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