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