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