[BACK]Return to man_term.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/man_term.c, Revision 1.151

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