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