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