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