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

Annotation of src/usr.bin/mandoc/mdoc_term.c, Revision 1.128

1.128   ! schwarze    1: /*     $Id: mdoc_term.c,v 1.127 2011/02/06 17:33:20 schwarze Exp $ */
1.1       kristaps    2: /*
1.122     schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.95      schwarze    4:  * Copyright (c) 2010 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.2       schwarze   10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     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:  */
                     18: #include <sys/types.h>
                     19:
                     20: #include <assert.h>
                     21: #include <ctype.h>
1.77      schwarze   22: #include <stdint.h>
1.1       kristaps   23: #include <stdio.h>
                     24: #include <stdlib.h>
                     25: #include <string.h>
                     26:
1.81      schwarze   27: #include "mandoc.h"
1.61      schwarze   28: #include "out.h"
1.1       kristaps   29: #include "term.h"
                     30: #include "mdoc.h"
1.61      schwarze   31: #include "chars.h"
                     32: #include "main.h"
1.54      schwarze   33:
1.51      schwarze   34: #define        INDENT            5
                     35: #define        HALFINDENT        3
1.1       kristaps   36:
                     37: struct termpair {
                     38:        struct termpair  *ppair;
1.27      schwarze   39:        int               count;
1.1       kristaps   40: };
                     41:
1.29      schwarze   42: #define        DECL_ARGS struct termp *p, \
                     43:                  struct termpair *pair, \
1.60      schwarze   44:                  const struct mdoc_meta *m, \
                     45:                  const struct mdoc_node *n
1.1       kristaps   46:
                     47: struct termact {
                     48:        int     (*pre)(DECL_ARGS);
                     49:        void    (*post)(DECL_ARGS);
                     50: };
1.29      schwarze   51:
1.89      schwarze   52: static size_t    a2width(const struct termp *, const char *);
                     53: static size_t    a2height(const struct termp *, const char *);
                     54: static size_t    a2offs(const struct termp *, const char *);
1.62      schwarze   55:
                     56: static void      print_bvspace(struct termp *,
                     57:                        const struct mdoc_node *,
                     58:                        const struct mdoc_node *);
1.65      schwarze   59: static void      print_mdoc_node(DECL_ARGS);
                     60: static void      print_mdoc_nodelist(DECL_ARGS);
1.87      schwarze   61: static void      print_mdoc_head(struct termp *, const void *);
                     62: static void      print_mdoc_foot(struct termp *, const void *);
1.86      schwarze   63: static void      synopsis_pre(struct termp *,
                     64:                        const struct mdoc_node *);
1.62      schwarze   65:
1.29      schwarze   66: static void      termp____post(DECL_ARGS);
1.120     schwarze   67: static void      termp__t_post(DECL_ARGS);
1.49      schwarze   68: static void      termp_an_post(DECL_ARGS);
1.29      schwarze   69: static void      termp_bd_post(DECL_ARGS);
1.90      schwarze   70: static void      termp_bk_post(DECL_ARGS);
1.29      schwarze   71: static void      termp_bl_post(DECL_ARGS);
                     72: static void      termp_d1_post(DECL_ARGS);
                     73: static void      termp_fo_post(DECL_ARGS);
                     74: static void      termp_in_post(DECL_ARGS);
                     75: static void      termp_it_post(DECL_ARGS);
                     76: static void      termp_lb_post(DECL_ARGS);
1.94      schwarze   77: static void      termp_nm_post(DECL_ARGS);
1.29      schwarze   78: static void      termp_pf_post(DECL_ARGS);
1.107     schwarze   79: static void      termp_quote_post(DECL_ARGS);
1.29      schwarze   80: static void      termp_sh_post(DECL_ARGS);
                     81: static void      termp_ss_post(DECL_ARGS);
                     82:
1.104     schwarze   83: static int       termp__a_pre(DECL_ARGS);
1.120     schwarze   84: static int       termp__t_pre(DECL_ARGS);
1.49      schwarze   85: static int       termp_an_pre(DECL_ARGS);
1.29      schwarze   86: static int       termp_ap_pre(DECL_ARGS);
                     87: static int       termp_bd_pre(DECL_ARGS);
                     88: static int       termp_bf_pre(DECL_ARGS);
1.90      schwarze   89: static int       termp_bk_pre(DECL_ARGS);
1.73      schwarze   90: static int       termp_bl_pre(DECL_ARGS);
1.54      schwarze   91: static int       termp_bold_pre(DECL_ARGS);
1.29      schwarze   92: static int       termp_bt_pre(DECL_ARGS);
1.126     schwarze   93: static int       termp_bx_pre(DECL_ARGS);
1.29      schwarze   94: static int       termp_cd_pre(DECL_ARGS);
                     95: static int       termp_d1_pre(DECL_ARGS);
                     96: static int       termp_ex_pre(DECL_ARGS);
                     97: static int       termp_fa_pre(DECL_ARGS);
1.107     schwarze   98: static int       termp_fd_pre(DECL_ARGS);
1.29      schwarze   99: static int       termp_fl_pre(DECL_ARGS);
                    100: static int       termp_fn_pre(DECL_ARGS);
                    101: static int       termp_fo_pre(DECL_ARGS);
                    102: static int       termp_ft_pre(DECL_ARGS);
1.109     schwarze  103: static int       termp_igndelim_pre(DECL_ARGS);
1.29      schwarze  104: static int       termp_in_pre(DECL_ARGS);
                    105: static int       termp_it_pre(DECL_ARGS);
1.65      schwarze  106: static int       termp_li_pre(DECL_ARGS);
1.29      schwarze  107: static int       termp_lk_pre(DECL_ARGS);
                    108: static int       termp_nd_pre(DECL_ARGS);
                    109: static int       termp_nm_pre(DECL_ARGS);
                    110: static int       termp_ns_pre(DECL_ARGS);
1.107     schwarze  111: static int       termp_quote_pre(DECL_ARGS);
1.29      schwarze  112: static int       termp_rs_pre(DECL_ARGS);
                    113: static int       termp_rv_pre(DECL_ARGS);
                    114: static int       termp_sh_pre(DECL_ARGS);
                    115: static int       termp_sm_pre(DECL_ARGS);
1.38      schwarze  116: static int       termp_sp_pre(DECL_ARGS);
1.29      schwarze  117: static int       termp_ss_pre(DECL_ARGS);
1.54      schwarze  118: static int       termp_under_pre(DECL_ARGS);
1.29      schwarze  119: static int       termp_ud_pre(DECL_ARGS);
1.69      schwarze  120: static int       termp_vt_pre(DECL_ARGS);
1.29      schwarze  121: static int       termp_xr_pre(DECL_ARGS);
                    122: static int       termp_xx_pre(DECL_ARGS);
1.1       kristaps  123:
1.54      schwarze  124: static const struct termact termacts[MDOC_MAX] = {
1.11      schwarze  125:        { termp_ap_pre, NULL }, /* Ap */
1.1       kristaps  126:        { NULL, NULL }, /* Dd */
                    127:        { NULL, NULL }, /* Dt */
                    128:        { NULL, NULL }, /* Os */
                    129:        { termp_sh_pre, termp_sh_post }, /* Sh */
                    130:        { termp_ss_pre, termp_ss_post }, /* Ss */
1.54      schwarze  131:        { termp_sp_pre, NULL }, /* Pp */
1.1       kristaps  132:        { termp_d1_pre, termp_d1_post }, /* D1 */
                    133:        { termp_d1_pre, termp_d1_post }, /* Dl */
                    134:        { termp_bd_pre, termp_bd_post }, /* Bd */
                    135:        { NULL, NULL }, /* Ed */
1.73      schwarze  136:        { termp_bl_pre, termp_bl_post }, /* Bl */
1.1       kristaps  137:        { NULL, NULL }, /* El */
                    138:        { termp_it_pre, termp_it_post }, /* It */
1.99      schwarze  139:        { termp_under_pre, NULL }, /* Ad */
1.49      schwarze  140:        { termp_an_pre, termp_an_post }, /* An */
1.54      schwarze  141:        { termp_under_pre, NULL }, /* Ar */
1.1       kristaps  142:        { termp_cd_pre, NULL }, /* Cd */
1.54      schwarze  143:        { termp_bold_pre, NULL }, /* Cm */
1.1       kristaps  144:        { NULL, NULL }, /* Dv */
                    145:        { NULL, NULL }, /* Er */
                    146:        { NULL, NULL }, /* Ev */
                    147:        { termp_ex_pre, NULL }, /* Ex */
                    148:        { termp_fa_pre, NULL }, /* Fa */
1.86      schwarze  149:        { termp_fd_pre, NULL }, /* Fd */
1.1       kristaps  150:        { termp_fl_pre, NULL }, /* Fl */
1.86      schwarze  151:        { termp_fn_pre, NULL }, /* Fn */
1.85      schwarze  152:        { termp_ft_pre, NULL }, /* Ft */
1.54      schwarze  153:        { termp_bold_pre, NULL }, /* Ic */
1.1       kristaps  154:        { termp_in_pre, termp_in_post }, /* In */
1.65      schwarze  155:        { termp_li_pre, NULL }, /* Li */
1.1       kristaps  156:        { termp_nd_pre, NULL }, /* Nd */
1.94      schwarze  157:        { termp_nm_pre, termp_nm_post }, /* Nm */
1.107     schwarze  158:        { termp_quote_pre, termp_quote_post }, /* Op */
1.1       kristaps  159:        { NULL, NULL }, /* Ot */
1.54      schwarze  160:        { termp_under_pre, NULL }, /* Pa */
1.1       kristaps  161:        { termp_rv_pre, NULL }, /* Rv */
1.32      schwarze  162:        { NULL, NULL }, /* St */
1.54      schwarze  163:        { termp_under_pre, NULL }, /* Va */
1.86      schwarze  164:        { termp_vt_pre, NULL }, /* Vt */
1.1       kristaps  165:        { termp_xr_pre, NULL }, /* Xr */
1.104     schwarze  166:        { termp__a_pre, termp____post }, /* %A */
1.58      schwarze  167:        { termp_under_pre, termp____post }, /* %B */
1.1       kristaps  168:        { NULL, termp____post }, /* %D */
1.58      schwarze  169:        { termp_under_pre, termp____post }, /* %I */
1.54      schwarze  170:        { termp_under_pre, termp____post }, /* %J */
1.1       kristaps  171:        { NULL, termp____post }, /* %N */
                    172:        { NULL, termp____post }, /* %O */
                    173:        { NULL, termp____post }, /* %P */
                    174:        { NULL, termp____post }, /* %R */
1.120     schwarze  175:        { termp__t_pre, termp__t_post }, /* %T */
1.1       kristaps  176:        { NULL, termp____post }, /* %V */
                    177:        { NULL, NULL }, /* Ac */
1.107     schwarze  178:        { termp_quote_pre, termp_quote_post }, /* Ao */
                    179:        { termp_quote_pre, termp_quote_post }, /* Aq */
1.32      schwarze  180:        { NULL, NULL }, /* At */
1.1       kristaps  181:        { NULL, NULL }, /* Bc */
                    182:        { termp_bf_pre, NULL }, /* Bf */
1.107     schwarze  183:        { termp_quote_pre, termp_quote_post }, /* Bo */
                    184:        { termp_quote_pre, termp_quote_post }, /* Bq */
1.26      schwarze  185:        { termp_xx_pre, NULL }, /* Bsx */
1.126     schwarze  186:        { termp_bx_pre, NULL }, /* Bx */
1.1       kristaps  187:        { NULL, NULL }, /* Db */
                    188:        { NULL, NULL }, /* Dc */
1.107     schwarze  189:        { termp_quote_pre, termp_quote_post }, /* Do */
                    190:        { termp_quote_pre, termp_quote_post }, /* Dq */
1.73      schwarze  191:        { NULL, NULL }, /* Ec */ /* FIXME: no space */
1.1       kristaps  192:        { NULL, NULL }, /* Ef */
1.54      schwarze  193:        { termp_under_pre, NULL }, /* Em */
1.1       kristaps  194:        { NULL, NULL }, /* Eo */
1.26      schwarze  195:        { termp_xx_pre, NULL }, /* Fx */
1.98      schwarze  196:        { termp_bold_pre, NULL }, /* Ms */
1.109     schwarze  197:        { termp_igndelim_pre, NULL }, /* No */
1.1       kristaps  198:        { termp_ns_pre, NULL }, /* Ns */
1.26      schwarze  199:        { termp_xx_pre, NULL }, /* Nx */
                    200:        { termp_xx_pre, NULL }, /* Ox */
1.1       kristaps  201:        { NULL, NULL }, /* Pc */
1.109     schwarze  202:        { termp_igndelim_pre, termp_pf_post }, /* Pf */
1.107     schwarze  203:        { termp_quote_pre, termp_quote_post }, /* Po */
                    204:        { termp_quote_pre, termp_quote_post }, /* Pq */
1.1       kristaps  205:        { NULL, NULL }, /* Qc */
1.107     schwarze  206:        { termp_quote_pre, termp_quote_post }, /* Ql */
                    207:        { termp_quote_pre, termp_quote_post }, /* Qo */
                    208:        { termp_quote_pre, termp_quote_post }, /* Qq */
1.1       kristaps  209:        { NULL, NULL }, /* Re */
                    210:        { termp_rs_pre, NULL }, /* Rs */
                    211:        { NULL, NULL }, /* Sc */
1.107     schwarze  212:        { termp_quote_pre, termp_quote_post }, /* So */
                    213:        { termp_quote_pre, termp_quote_post }, /* Sq */
1.1       kristaps  214:        { termp_sm_pre, NULL }, /* Sm */
1.54      schwarze  215:        { termp_under_pre, NULL }, /* Sx */
                    216:        { termp_bold_pre, NULL }, /* Sy */
1.1       kristaps  217:        { NULL, NULL }, /* Tn */
1.26      schwarze  218:        { termp_xx_pre, NULL }, /* Ux */
1.1       kristaps  219:        { NULL, NULL }, /* Xc */
                    220:        { NULL, NULL }, /* Xo */
                    221:        { termp_fo_pre, termp_fo_post }, /* Fo */
                    222:        { NULL, NULL }, /* Fc */
1.107     schwarze  223:        { termp_quote_pre, termp_quote_post }, /* Oo */
1.1       kristaps  224:        { NULL, NULL }, /* Oc */
1.90      schwarze  225:        { termp_bk_pre, termp_bk_post }, /* Bk */
1.1       kristaps  226:        { NULL, NULL }, /* Ek */
                    227:        { termp_bt_pre, NULL }, /* Bt */
                    228:        { NULL, NULL }, /* Hf */
                    229:        { NULL, NULL }, /* Fr */
                    230:        { termp_ud_pre, NULL }, /* Ud */
1.32      schwarze  231:        { NULL, termp_lb_post }, /* Lb */
1.54      schwarze  232:        { termp_sp_pre, NULL }, /* Lp */
1.1       kristaps  233:        { termp_lk_pre, NULL }, /* Lk */
1.54      schwarze  234:        { termp_under_pre, NULL }, /* Mt */
1.107     schwarze  235:        { termp_quote_pre, termp_quote_post }, /* Brq */
                    236:        { termp_quote_pre, termp_quote_post }, /* Bro */
1.1       kristaps  237:        { NULL, NULL }, /* Brc */
1.58      schwarze  238:        { NULL, termp____post }, /* %C */
                    239:        { NULL, NULL }, /* Es */ /* TODO */
                    240:        { NULL, NULL }, /* En */ /* TODO */
1.26      schwarze  241:        { termp_xx_pre, NULL }, /* Dx */
1.58      schwarze  242:        { NULL, termp____post }, /* %Q */
1.54      schwarze  243:        { termp_sp_pre, NULL }, /* br */
1.38      schwarze  244:        { termp_sp_pre, NULL }, /* sp */
1.62      schwarze  245:        { termp_under_pre, termp____post }, /* %U */
1.85      schwarze  246:        { NULL, NULL }, /* Ta */
1.1       kristaps  247: };
                    248:
                    249:
1.55      schwarze  250: void
1.61      schwarze  251: terminal_mdoc(void *arg, const struct mdoc *mdoc)
1.1       kristaps  252: {
1.55      schwarze  253:        const struct mdoc_node  *n;
                    254:        const struct mdoc_meta  *m;
1.61      schwarze  255:        struct termp            *p;
                    256:
                    257:        p = (struct termp *)arg;
1.71      schwarze  258:
                    259:        p->overstep = 0;
1.80      schwarze  260:        p->maxrmargin = p->defrmargin;
1.89      schwarze  261:        p->tabwidth = term_len(p, 5);
1.61      schwarze  262:
                    263:        if (NULL == p->symtab)
                    264:                switch (p->enc) {
                    265:                case (TERMENC_ASCII):
                    266:                        p->symtab = chars_init(CHARS_ASCII);
                    267:                        break;
                    268:                default:
                    269:                        abort();
                    270:                        /* NOTREACHED */
                    271:                }
1.55      schwarze  272:
                    273:        n = mdoc_node(mdoc);
                    274:        m = mdoc_meta(mdoc);
                    275:
1.87      schwarze  276:        term_begin(p, print_mdoc_head, print_mdoc_foot, m);
                    277:
1.55      schwarze  278:        if (n->child)
1.65      schwarze  279:                print_mdoc_nodelist(p, NULL, m, n->child);
1.87      schwarze  280:
                    281:        term_end(p);
1.1       kristaps  282: }
                    283:
                    284:
                    285: static void
1.65      schwarze  286: print_mdoc_nodelist(DECL_ARGS)
1.1       kristaps  287: {
                    288:
1.65      schwarze  289:        print_mdoc_node(p, pair, m, n);
1.60      schwarze  290:        if (n->next)
1.65      schwarze  291:                print_mdoc_nodelist(p, pair, m, n->next);
1.1       kristaps  292: }
                    293:
                    294:
1.54      schwarze  295: /* ARGSUSED */
1.1       kristaps  296: static void
1.65      schwarze  297: print_mdoc_node(DECL_ARGS)
1.1       kristaps  298: {
1.65      schwarze  299:        int              chld;
                    300:        const void      *font;
1.1       kristaps  301:        struct termpair  npair;
1.28      schwarze  302:        size_t           offset, rmargin;
1.1       kristaps  303:
1.54      schwarze  304:        chld = 1;
1.28      schwarze  305:        offset = p->offset;
                    306:        rmargin = p->rmargin;
1.65      schwarze  307:        font = term_fontq(p);
1.1       kristaps  308:
1.63      schwarze  309:        memset(&npair, 0, sizeof(struct termpair));
1.1       kristaps  310:        npair.ppair = pair;
1.65      schwarze  311:
1.95      schwarze  312:        /*
                    313:         * Keeps only work until the end of a line.  If a keep was
                    314:         * invoked in a prior line, revert it to PREKEEP.
1.116     schwarze  315:         *
                    316:         * Also let SYNPRETTY sections behave as if they were wrapped
                    317:         * in a `Bk' block.
1.95      schwarze  318:         */
                    319:
1.116     schwarze  320:        if (TERMP_KEEP & p->flags || MDOC_SYNPRETTY & n->flags) {
1.95      schwarze  321:                if (n->prev && n->prev->line != n->line) {
                    322:                        p->flags &= ~TERMP_KEEP;
                    323:                        p->flags |= TERMP_PREKEEP;
                    324:                } else if (NULL == n->prev) {
                    325:                        if (n->parent && n->parent->line != n->line) {
                    326:                                p->flags &= ~TERMP_KEEP;
                    327:                                p->flags |= TERMP_PREKEEP;
                    328:                        }
                    329:                }
                    330:        }
1.116     schwarze  331:
                    332:        /*
                    333:         * Since SYNPRETTY sections aren't "turned off" with `Ek',
                    334:         * we have to intuit whether we should disable formatting.
                    335:         */
                    336:
                    337:        if ( ! (MDOC_SYNPRETTY & n->flags) &&
                    338:            ((n->prev   && MDOC_SYNPRETTY & n->prev->flags) ||
                    339:             (n->parent && MDOC_SYNPRETTY & n->parent->flags)))
                    340:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.128   ! schwarze  341:
        !           342:        /*
        !           343:         * After the keep flags have been set up, we may now
        !           344:         * produce output.  Note that some pre-handlers do so.
        !           345:         */
        !           346:
        !           347:        switch (n->type) {
        !           348:        case (MDOC_TEXT):
        !           349:                if (' ' == *n->string && MDOC_LINE & n->flags)
        !           350:                        term_newln(p);
        !           351:                term_word(p, n->string);
        !           352:                break;
        !           353:        case (MDOC_TBL):
        !           354:                term_tbl(p, n->span);
        !           355:                break;
        !           356:        default:
        !           357:                if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
        !           358:                        chld = (*termacts[n->tok].pre)
        !           359:                                (p, &npair, m, n);
        !           360:                break;
        !           361:        }
1.95      schwarze  362:
1.60      schwarze  363:        if (chld && n->child)
1.65      schwarze  364:                print_mdoc_nodelist(p, &npair, m, n->child);
1.1       kristaps  365:
1.65      schwarze  366:        term_fontpopq(p, font);
1.1       kristaps  367:
1.122     schwarze  368:        switch (n->type) {
                    369:        case (MDOC_TEXT):
                    370:                break;
                    371:        case (MDOC_TBL):
                    372:                break;
                    373:        default:
                    374:                if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
                    375:                        break;
1.95      schwarze  376:                (void)(*termacts[n->tok].post)(p, &npair, m, n);
1.93      schwarze  377:
                    378:                /*
                    379:                 * Explicit end tokens not only call the post
                    380:                 * handler, but also tell the respective block
                    381:                 * that it must not call the post handler again.
                    382:                 */
1.95      schwarze  383:                if (ENDBODY_NOT != n->end)
1.93      schwarze  384:                        n->pending->flags |= MDOC_ENDED;
                    385:
                    386:                /*
                    387:                 * End of line terminating an implicit block
                    388:                 * while an explicit block is still open.
                    389:                 * Continue the explicit block without spacing.
                    390:                 */
                    391:                if (ENDBODY_NOSPACE == n->end)
                    392:                        p->flags |= TERMP_NOSPACE;
1.122     schwarze  393:                break;
1.93      schwarze  394:        }
1.28      schwarze  395:
1.78      schwarze  396:        if (MDOC_EOS & n->flags)
                    397:                p->flags |= TERMP_SENTENCE;
                    398:
1.28      schwarze  399:        p->offset = offset;
                    400:        p->rmargin = rmargin;
1.1       kristaps  401: }
                    402:
                    403:
                    404: static void
1.87      schwarze  405: print_mdoc_foot(struct termp *p, const void *arg)
1.1       kristaps  406: {
1.63      schwarze  407:        char            buf[DATESIZ], os[BUFSIZ];
1.87      schwarze  408:        const struct mdoc_meta *m;
                    409:
                    410:        m = (const struct mdoc_meta *)arg;
1.1       kristaps  411:
1.65      schwarze  412:        term_fontrepl(p, TERMFONT_NONE);
                    413:
1.7       schwarze  414:        /*
                    415:         * Output the footer in new-groff style, that is, three columns
                    416:         * with the middle being the manual date and flanking columns
                    417:         * being the operating system:
                    418:         *
                    419:         * SYSTEM                  DATE                    SYSTEM
                    420:         */
                    421:
1.62      schwarze  422:        time2a(m->date, buf, DATESIZ);
1.63      schwarze  423:        strlcpy(os, m->os, BUFSIZ);
1.1       kristaps  424:
                    425:        term_vspace(p);
                    426:
1.7       schwarze  427:        p->offset = 0;
1.89      schwarze  428:        p->rmargin = (p->maxrmargin -
                    429:                        term_strlen(p, buf) + term_len(p, 1)) / 2;
1.1       kristaps  430:        p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
                    431:
                    432:        term_word(p, os);
                    433:        term_flushln(p);
                    434:
1.7       schwarze  435:        p->offset = p->rmargin;
1.89      schwarze  436:        p->rmargin = p->maxrmargin - term_strlen(p, os);
1.1       kristaps  437:        p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.7       schwarze  438:
                    439:        term_word(p, buf);
                    440:        term_flushln(p);
                    441:
1.1       kristaps  442:        p->offset = p->rmargin;
                    443:        p->rmargin = p->maxrmargin;
                    444:        p->flags &= ~TERMP_NOBREAK;
1.7       schwarze  445:        p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.1       kristaps  446:
1.7       schwarze  447:        term_word(p, os);
1.1       kristaps  448:        term_flushln(p);
1.7       schwarze  449:
                    450:        p->offset = 0;
                    451:        p->rmargin = p->maxrmargin;
                    452:        p->flags = 0;
1.1       kristaps  453: }
                    454:
                    455:
                    456: static void
1.87      schwarze  457: print_mdoc_head(struct termp *p, const void *arg)
1.1       kristaps  458: {
1.63      schwarze  459:        char            buf[BUFSIZ], title[BUFSIZ];
1.87      schwarze  460:        const struct mdoc_meta *m;
                    461:
                    462:        m = (const struct mdoc_meta *)arg;
1.1       kristaps  463:
                    464:        p->rmargin = p->maxrmargin;
                    465:        p->offset = 0;
                    466:
                    467:        /*
                    468:         * The header is strange.  It has three components, which are
                    469:         * really two with the first duplicated.  It goes like this:
                    470:         *
                    471:         * IDENTIFIER              TITLE                   IDENTIFIER
                    472:         *
                    473:         * The IDENTIFIER is NAME(SECTION), which is the command-name
                    474:         * (if given, or "unknown" if not) followed by the manual page
                    475:         * section.  These are given in `Dt'.  The TITLE is a free-form
                    476:         * string depending on the manual volume.  If not specified, it
                    477:         * switches on the manual section.
                    478:         */
                    479:
1.60      schwarze  480:        assert(m->vol);
1.63      schwarze  481:        strlcpy(buf, m->vol, BUFSIZ);
1.1       kristaps  482:
1.60      schwarze  483:        if (m->arch) {
1.63      schwarze  484:                strlcat(buf, " (", BUFSIZ);
                    485:                strlcat(buf, m->arch, BUFSIZ);
                    486:                strlcat(buf, ")", BUFSIZ);
1.1       kristaps  487:        }
                    488:
1.79      schwarze  489:        snprintf(title, BUFSIZ, "%s(%s)", m->title, m->msec);
1.1       kristaps  490:
                    491:        p->offset = 0;
1.89      schwarze  492:        p->rmargin = (p->maxrmargin -
                    493:                        term_strlen(p, buf) + term_len(p, 1)) / 2;
1.1       kristaps  494:        p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
                    495:
                    496:        term_word(p, title);
                    497:        term_flushln(p);
                    498:
                    499:        p->offset = p->rmargin;
1.89      schwarze  500:        p->rmargin = p->maxrmargin - term_strlen(p, title);
1.8       schwarze  501:        p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
1.1       kristaps  502:
                    503:        term_word(p, buf);
                    504:        term_flushln(p);
                    505:
                    506:        p->offset = p->rmargin;
                    507:        p->rmargin = p->maxrmargin;
                    508:        p->flags &= ~TERMP_NOBREAK;
                    509:        p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
                    510:
                    511:        term_word(p, title);
                    512:        term_flushln(p);
                    513:
1.8       schwarze  514:        p->offset = 0;
1.1       kristaps  515:        p->rmargin = p->maxrmargin;
                    516:        p->flags &= ~TERMP_NOSPACE;
                    517: }
                    518:
                    519:
                    520: static size_t
1.89      schwarze  521: a2height(const struct termp *p, const char *v)
1.1       kristaps  522: {
1.61      schwarze  523:        struct roffsu    su;
1.1       kristaps  524:
1.89      schwarze  525:        assert(v);
                    526:        if ( ! a2roffsu(v, &su, SCALE_VS))
                    527:                SCALE_VS_INIT(&su, term_len(p, 1));
1.1       kristaps  528:
1.89      schwarze  529:        return(term_vspan(p, &su));
1.61      schwarze  530: }
1.34      schwarze  531:
1.1       kristaps  532:
1.61      schwarze  533: static size_t
1.89      schwarze  534: a2width(const struct termp *p, const char *v)
1.61      schwarze  535: {
                    536:        struct roffsu    su;
1.1       kristaps  537:
1.88      schwarze  538:        assert(v);
                    539:        if ( ! a2roffsu(v, &su, SCALE_MAX))
1.89      schwarze  540:                SCALE_HS_INIT(&su, term_strlen(p, v));
1.1       kristaps  541:
1.89      schwarze  542:        return(term_hspan(p, &su));
1.1       kristaps  543: }
                    544:
                    545:
                    546: static size_t
1.89      schwarze  547: a2offs(const struct termp *p, const char *v)
1.1       kristaps  548: {
1.61      schwarze  549:        struct roffsu    su;
1.1       kristaps  550:
1.88      schwarze  551:        if ('\0' == *v)
1.61      schwarze  552:                return(0);
1.88      schwarze  553:        else if (0 == strcmp(v, "left"))
1.9       schwarze  554:                return(0);
1.88      schwarze  555:        else if (0 == strcmp(v, "indent"))
1.89      schwarze  556:                return(term_len(p, INDENT + 1));
1.88      schwarze  557:        else if (0 == strcmp(v, "indent-two"))
1.89      schwarze  558:                return(term_len(p, (INDENT + 1) * 2));
1.88      schwarze  559:        else if ( ! a2roffsu(v, &su, SCALE_MAX))
1.89      schwarze  560:                SCALE_HS_INIT(&su, term_strlen(p, v));
1.10      schwarze  561:
1.89      schwarze  562:        return(term_hspan(p, &su));
1.1       kristaps  563: }
                    564:
                    565:
1.68      schwarze  566: /*
                    567:  * Determine how much space to print out before block elements of `It'
                    568:  * (and thus `Bl') and `Bd'.  And then go ahead and print that space,
                    569:  * too.
                    570:  */
1.45      schwarze  571: static void
1.61      schwarze  572: print_bvspace(struct termp *p,
1.1       kristaps  573:                const struct mdoc_node *bl,
1.60      schwarze  574:                const struct mdoc_node *n)
1.1       kristaps  575: {
1.60      schwarze  576:        const struct mdoc_node  *nn;
1.1       kristaps  577:
                    578:        term_newln(p);
1.88      schwarze  579:
1.121     schwarze  580:        if (MDOC_Bd == bl->tok && bl->norm->Bd.comp)
1.88      schwarze  581:                return;
1.121     schwarze  582:        if (MDOC_Bl == bl->tok && bl->norm->Bl.comp)
1.45      schwarze  583:                return;
                    584:
1.60      schwarze  585:        /* Do not vspace directly after Ss/Sh. */
1.1       kristaps  586:
1.60      schwarze  587:        for (nn = n; nn; nn = nn->parent) {
                    588:                if (MDOC_BLOCK != nn->type)
1.1       kristaps  589:                        continue;
1.60      schwarze  590:                if (MDOC_Ss == nn->tok)
1.45      schwarze  591:                        return;
1.60      schwarze  592:                if (MDOC_Sh == nn->tok)
1.45      schwarze  593:                        return;
1.60      schwarze  594:                if (NULL == nn->prev)
1.1       kristaps  595:                        continue;
                    596:                break;
                    597:        }
                    598:
1.60      schwarze  599:        /* A `-column' does not assert vspace within the list. */
1.45      schwarze  600:
1.121     schwarze  601:        if (MDOC_Bl == bl->tok && LIST_column == bl->norm->Bl.type)
1.60      schwarze  602:                if (n->prev && MDOC_It == n->prev->tok)
1.45      schwarze  603:                        return;
                    604:
1.60      schwarze  605:        /* A `-diag' without body does not vspace. */
                    606:
1.121     schwarze  607:        if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->Bl.type)
1.60      schwarze  608:                if (n->prev && MDOC_It == n->prev->tok) {
                    609:                        assert(n->prev->body);
                    610:                        if (NULL == n->prev->body->child)
1.45      schwarze  611:                                return;
                    612:                }
                    613:
                    614:        term_vspace(p);
1.1       kristaps  615: }
                    616:
                    617:
                    618: /* ARGSUSED */
                    619: static int
                    620: termp_it_pre(DECL_ARGS)
                    621: {
1.60      schwarze  622:        const struct mdoc_node *bl, *nn;
1.1       kristaps  623:        char                    buf[7];
1.95      schwarze  624:        int                     i;
1.68      schwarze  625:        size_t                  width, offset, ncols, dcol;
1.82      schwarze  626:        enum mdoc_list          type;
1.1       kristaps  627:
1.60      schwarze  628:        if (MDOC_BLOCK == n->type) {
1.61      schwarze  629:                print_bvspace(p, n->parent->parent, n);
1.45      schwarze  630:                return(1);
                    631:        }
1.1       kristaps  632:
1.60      schwarze  633:        bl = n->parent->parent->parent;
1.121     schwarze  634:        type = bl->norm->Bl.type;
1.1       kristaps  635:
1.68      schwarze  636:        /*
                    637:         * First calculate width and offset.  This is pretty easy unless
                    638:         * we're a -column list, in which case all prior columns must
                    639:         * be accounted for.
                    640:         */
                    641:
                    642:        width = offset = 0;
                    643:
1.121     schwarze  644:        if (bl->norm->Bl.offs)
                    645:                offset = a2offs(p, bl->norm->Bl.offs);
1.66      schwarze  646:
1.1       kristaps  647:        switch (type) {
1.82      schwarze  648:        case (LIST_column):
1.85      schwarze  649:                if (MDOC_HEAD == n->type)
1.1       kristaps  650:                        break;
1.88      schwarze  651:
1.66      schwarze  652:                /*
1.68      schwarze  653:                 * Imitate groff's column handling:
                    654:                 * - For each earlier column, add its width.
                    655:                 * - For less than 5 columns, add four more blanks per
                    656:                 *   column.
                    657:                 * - For exactly 5 columns, add three more blank per
                    658:                 *   column.
                    659:                 * - For more than 5 columns, add only one column.
1.66      schwarze  660:                 */
1.121     schwarze  661:                ncols = bl->norm->Bl.ncols;
1.95      schwarze  662:
1.68      schwarze  663:                /* LINTED */
1.89      schwarze  664:                dcol = ncols < 5 ? term_len(p, 4) :
                    665:                        ncols == 5 ? term_len(p, 3) : term_len(p, 1);
1.68      schwarze  666:
1.85      schwarze  667:                /*
                    668:                 * Calculate the offset by applying all prior MDOC_BODY,
                    669:                 * so we stop at the MDOC_HEAD (NULL == nn->prev).
                    670:                 */
                    671:
1.68      schwarze  672:                for (i = 0, nn = n->prev;
1.85      schwarze  673:                                nn->prev && i < (int)ncols;
1.68      schwarze  674:                                nn = nn->prev, i++)
                    675:                        offset += dcol + a2width
1.121     schwarze  676:                                (p, bl->norm->Bl.cols[i]);
1.66      schwarze  677:
                    678:                /*
1.68      schwarze  679:                 * When exceeding the declared number of columns, leave
                    680:                 * the remaining widths at 0.  This will later be
                    681:                 * adjusted to the default width of 10, or, for the last
                    682:                 * column, stretched to the right margin.
1.46      schwarze  683:                 */
1.68      schwarze  684:                if (i >= (int)ncols)
                    685:                        break;
1.46      schwarze  686:
1.66      schwarze  687:                /*
1.68      schwarze  688:                 * Use the declared column widths, extended as explained
                    689:                 * in the preceding paragraph.
1.66      schwarze  690:                 */
1.121     schwarze  691:                width = a2width(p, bl->norm->Bl.cols[i]) + dcol;
1.1       kristaps  692:                break;
                    693:        default:
1.121     schwarze  694:                if (NULL == bl->norm->Bl.width)
1.68      schwarze  695:                        break;
                    696:
                    697:                /*
                    698:                 * Note: buffer the width by 2, which is groff's magic
                    699:                 * number for buffering single arguments.  See the above
                    700:                 * handling for column for how this changes.
                    701:                 */
1.121     schwarze  702:                assert(bl->norm->Bl.width);
                    703:                width = a2width(p, bl->norm->Bl.width) + term_len(p, 2);
1.1       kristaps  704:                break;
                    705:        }
                    706:
                    707:        /*
                    708:         * List-type can override the width in the case of fixed-head
                    709:         * values (bullet, dash/hyphen, enum).  Tags need a non-zero
1.53      schwarze  710:         * offset.
1.1       kristaps  711:         */
                    712:
                    713:        switch (type) {
1.82      schwarze  714:        case (LIST_bullet):
1.1       kristaps  715:                /* FALLTHROUGH */
1.82      schwarze  716:        case (LIST_dash):
1.1       kristaps  717:                /* FALLTHROUGH */
1.82      schwarze  718:        case (LIST_hyphen):
1.89      schwarze  719:                if (width < term_len(p, 4))
                    720:                        width = term_len(p, 4);
1.19      schwarze  721:                break;
1.82      schwarze  722:        case (LIST_enum):
1.89      schwarze  723:                if (width < term_len(p, 5))
                    724:                        width = term_len(p, 5);
1.1       kristaps  725:                break;
1.82      schwarze  726:        case (LIST_hang):
1.33      schwarze  727:                if (0 == width)
1.89      schwarze  728:                        width = term_len(p, 8);
1.33      schwarze  729:                break;
1.82      schwarze  730:        case (LIST_column):
1.41      schwarze  731:                /* FALLTHROUGH */
1.82      schwarze  732:        case (LIST_tag):
1.1       kristaps  733:                if (0 == width)
1.89      schwarze  734:                        width = term_len(p, 10);
1.1       kristaps  735:                break;
                    736:        default:
                    737:                break;
                    738:        }
                    739:
                    740:        /*
1.16      schwarze  741:         * Whitespace control.  Inset bodies need an initial space,
                    742:         * while diagonal bodies need two.
1.1       kristaps  743:         */
                    744:
1.42      schwarze  745:        p->flags |= TERMP_NOSPACE;
                    746:
1.1       kristaps  747:        switch (type) {
1.82      schwarze  748:        case (LIST_diag):
1.60      schwarze  749:                if (MDOC_BODY == n->type)
1.48      schwarze  750:                        term_word(p, "\\ \\ ");
1.42      schwarze  751:                break;
1.82      schwarze  752:        case (LIST_inset):
1.60      schwarze  753:                if (MDOC_BODY == n->type)
1.42      schwarze  754:                        term_word(p, "\\ ");
1.1       kristaps  755:                break;
                    756:        default:
                    757:                break;
                    758:        }
                    759:
1.42      schwarze  760:        p->flags |= TERMP_NOSPACE;
                    761:
1.1       kristaps  762:        switch (type) {
1.82      schwarze  763:        case (LIST_diag):
1.60      schwarze  764:                if (MDOC_HEAD == n->type)
1.65      schwarze  765:                        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps  766:                break;
                    767:        default:
                    768:                break;
                    769:        }
                    770:
                    771:        /*
1.68      schwarze  772:         * Pad and break control.  This is the tricky part.  These flags
                    773:         * are documented in term_flushln() in term.c.  Note that we're
                    774:         * going to unset all of these flags in termp_it_post() when we
                    775:         * exit.
1.1       kristaps  776:         */
                    777:
                    778:        switch (type) {
1.82      schwarze  779:        case (LIST_bullet):
1.1       kristaps  780:                /* FALLTHROUGH */
1.82      schwarze  781:        case (LIST_dash):
1.1       kristaps  782:                /* FALLTHROUGH */
1.82      schwarze  783:        case (LIST_enum):
1.1       kristaps  784:                /* FALLTHROUGH */
1.82      schwarze  785:        case (LIST_hyphen):
1.60      schwarze  786:                if (MDOC_HEAD == n->type)
1.33      schwarze  787:                        p->flags |= TERMP_NOBREAK;
                    788:                else
                    789:                        p->flags |= TERMP_NOLPAD;
                    790:                break;
1.82      schwarze  791:        case (LIST_hang):
1.60      schwarze  792:                if (MDOC_HEAD == n->type)
1.33      schwarze  793:                        p->flags |= TERMP_NOBREAK;
                    794:                else
                    795:                        p->flags |= TERMP_NOLPAD;
                    796:
1.60      schwarze  797:                if (MDOC_HEAD != n->type)
1.47      schwarze  798:                        break;
                    799:
                    800:                /*
                    801:                 * This is ugly.  If `-hang' is specified and the body
                    802:                 * is a `Bl' or `Bd', then we want basically to nullify
                    803:                 * the "overstep" effect in term_flushln() and treat
                    804:                 * this as a `-ohang' list instead.
                    805:                 */
1.60      schwarze  806:                if (n->next->child &&
                    807:                                (MDOC_Bl == n->next->child->tok ||
                    808:                                 MDOC_Bd == n->next->child->tok)) {
1.47      schwarze  809:                        p->flags &= ~TERMP_NOBREAK;
                    810:                        p->flags &= ~TERMP_NOLPAD;
                    811:                } else
1.33      schwarze  812:                        p->flags |= TERMP_HANG;
                    813:                break;
1.82      schwarze  814:        case (LIST_tag):
1.60      schwarze  815:                if (MDOC_HEAD == n->type)
1.42      schwarze  816:                        p->flags |= TERMP_NOBREAK | TERMP_TWOSPACE;
1.1       kristaps  817:                else
                    818:                        p->flags |= TERMP_NOLPAD;
1.33      schwarze  819:
1.60      schwarze  820:                if (MDOC_HEAD != n->type)
1.33      schwarze  821:                        break;
1.60      schwarze  822:                if (NULL == n->next || NULL == n->next->child)
1.33      schwarze  823:                        p->flags |= TERMP_DANGLE;
1.1       kristaps  824:                break;
1.82      schwarze  825:        case (LIST_column):
1.85      schwarze  826:                if (MDOC_HEAD == n->type)
                    827:                        break;
                    828:
                    829:                if (NULL == n->next)
                    830:                        p->flags &= ~TERMP_NOBREAK;
                    831:                else
                    832:                        p->flags |= TERMP_NOBREAK;
                    833:
                    834:                assert(n->prev);
                    835:                if (MDOC_BODY == n->prev->type)
                    836:                        p->flags |= TERMP_NOLPAD;
                    837:
1.1       kristaps  838:                break;
1.82      schwarze  839:        case (LIST_diag):
1.60      schwarze  840:                if (MDOC_HEAD == n->type)
1.1       kristaps  841:                        p->flags |= TERMP_NOBREAK;
                    842:                break;
                    843:        default:
                    844:                break;
                    845:        }
                    846:
                    847:        /*
                    848:         * Margin control.  Set-head-width lists have their right
                    849:         * margins shortened.  The body for these lists has the offset
                    850:         * necessarily lengthened.  Everybody gets the offset.
                    851:         */
                    852:
                    853:        p->offset += offset;
                    854:
                    855:        switch (type) {
1.82      schwarze  856:        case (LIST_hang):
1.47      schwarze  857:                /*
                    858:                 * Same stipulation as above, regarding `-hang'.  We
                    859:                 * don't want to recalculate rmargin and offsets when
                    860:                 * using `Bd' or `Bl' within `-hang' overstep lists.
                    861:                 */
1.60      schwarze  862:                if (MDOC_HEAD == n->type && n->next->child &&
                    863:                                (MDOC_Bl == n->next->child->tok ||
                    864:                                 MDOC_Bd == n->next->child->tok))
1.47      schwarze  865:                        break;
                    866:                /* FALLTHROUGH */
1.82      schwarze  867:        case (LIST_bullet):
1.1       kristaps  868:                /* FALLTHROUGH */
1.82      schwarze  869:        case (LIST_dash):
1.1       kristaps  870:                /* FALLTHROUGH */
1.82      schwarze  871:        case (LIST_enum):
1.1       kristaps  872:                /* FALLTHROUGH */
1.82      schwarze  873:        case (LIST_hyphen):
1.33      schwarze  874:                /* FALLTHROUGH */
1.82      schwarze  875:        case (LIST_tag):
1.41      schwarze  876:                assert(width);
1.60      schwarze  877:                if (MDOC_HEAD == n->type)
1.1       kristaps  878:                        p->rmargin = p->offset + width;
                    879:                else
                    880:                        p->offset += width;
                    881:                break;
1.82      schwarze  882:        case (LIST_column):
1.41      schwarze  883:                assert(width);
1.1       kristaps  884:                p->rmargin = p->offset + width;
1.43      schwarze  885:                /*
                    886:                 * XXX - this behaviour is not documented: the
                    887:                 * right-most column is filled to the right margin.
                    888:                 */
1.85      schwarze  889:                if (MDOC_HEAD == n->type)
                    890:                        break;
                    891:                if (NULL == n->next && p->rmargin < p->maxrmargin)
1.43      schwarze  892:                        p->rmargin = p->maxrmargin;
1.1       kristaps  893:                break;
                    894:        default:
                    895:                break;
                    896:        }
                    897:
                    898:        /*
                    899:         * The dash, hyphen, bullet and enum lists all have a special
1.12      schwarze  900:         * HEAD character (temporarily bold, in some cases).
1.1       kristaps  901:         */
                    902:
1.60      schwarze  903:        if (MDOC_HEAD == n->type)
1.1       kristaps  904:                switch (type) {
1.82      schwarze  905:                case (LIST_bullet):
1.65      schwarze  906:                        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps  907:                        term_word(p, "\\[bu]");
1.65      schwarze  908:                        term_fontpop(p);
1.1       kristaps  909:                        break;
1.82      schwarze  910:                case (LIST_dash):
1.1       kristaps  911:                        /* FALLTHROUGH */
1.82      schwarze  912:                case (LIST_hyphen):
1.65      schwarze  913:                        term_fontpush(p, TERMFONT_BOLD);
1.35      schwarze  914:                        term_word(p, "\\(hy");
1.65      schwarze  915:                        term_fontpop(p);
1.1       kristaps  916:                        break;
1.82      schwarze  917:                case (LIST_enum):
1.1       kristaps  918:                        (pair->ppair->ppair->count)++;
1.68      schwarze  919:                        snprintf(buf, sizeof(buf), "%d.",
1.1       kristaps  920:                                        pair->ppair->ppair->count);
                    921:                        term_word(p, buf);
                    922:                        break;
                    923:                default:
                    924:                        break;
                    925:                }
1.12      schwarze  926:
1.1       kristaps  927:        /*
                    928:         * If we're not going to process our children, indicate so here.
                    929:         */
                    930:
                    931:        switch (type) {
1.82      schwarze  932:        case (LIST_bullet):
1.1       kristaps  933:                /* FALLTHROUGH */
1.82      schwarze  934:        case (LIST_item):
1.1       kristaps  935:                /* FALLTHROUGH */
1.82      schwarze  936:        case (LIST_dash):
1.1       kristaps  937:                /* FALLTHROUGH */
1.82      schwarze  938:        case (LIST_hyphen):
1.1       kristaps  939:                /* FALLTHROUGH */
1.82      schwarze  940:        case (LIST_enum):
1.60      schwarze  941:                if (MDOC_HEAD == n->type)
1.1       kristaps  942:                        return(0);
                    943:                break;
1.82      schwarze  944:        case (LIST_column):
1.85      schwarze  945:                if (MDOC_HEAD == n->type)
1.1       kristaps  946:                        return(0);
                    947:                break;
                    948:        default:
                    949:                break;
                    950:        }
                    951:
                    952:        return(1);
                    953: }
                    954:
                    955:
                    956: /* ARGSUSED */
                    957: static void
                    958: termp_it_post(DECL_ARGS)
                    959: {
1.82      schwarze  960:        enum mdoc_list     type;
1.1       kristaps  961:
1.68      schwarze  962:        if (MDOC_BLOCK == n->type)
1.1       kristaps  963:                return;
                    964:
1.121     schwarze  965:        type = n->parent->parent->parent->norm->Bl.type;
1.1       kristaps  966:
                    967:        switch (type) {
1.82      schwarze  968:        case (LIST_item):
1.44      schwarze  969:                /* FALLTHROUGH */
1.82      schwarze  970:        case (LIST_diag):
1.1       kristaps  971:                /* FALLTHROUGH */
1.82      schwarze  972:        case (LIST_inset):
1.60      schwarze  973:                if (MDOC_BODY == n->type)
1.74      schwarze  974:                        term_newln(p);
1.1       kristaps  975:                break;
1.82      schwarze  976:        case (LIST_column):
1.85      schwarze  977:                if (MDOC_BODY == n->type)
1.1       kristaps  978:                        term_flushln(p);
                    979:                break;
                    980:        default:
1.74      schwarze  981:                term_newln(p);
1.1       kristaps  982:                break;
                    983:        }
                    984:
1.68      schwarze  985:        /*
                    986:         * Now that our output is flushed, we can reset our tags.  Since
                    987:         * only `It' sets these flags, we're free to assume that nobody
                    988:         * has munged them in the meanwhile.
                    989:         */
                    990:
                    991:        p->flags &= ~TERMP_DANGLE;
                    992:        p->flags &= ~TERMP_NOBREAK;
                    993:        p->flags &= ~TERMP_TWOSPACE;
                    994:        p->flags &= ~TERMP_NOLPAD;
                    995:        p->flags &= ~TERMP_HANG;
1.1       kristaps  996: }
                    997:
                    998:
                    999: /* ARGSUSED */
                   1000: static int
                   1001: termp_nm_pre(DECL_ARGS)
                   1002: {
                   1003:
1.94      schwarze 1004:        if (MDOC_BLOCK == n->type)
                   1005:                return(1);
                   1006:
                   1007:        if (MDOC_BODY == n->type) {
                   1008:                if (NULL == n->child)
                   1009:                        return(0);
                   1010:                p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
                   1011:                p->offset += term_len(p, 1) +
                   1012:                    (NULL == n->prev->child ? term_strlen(p, m->name) :
                   1013:                     MDOC_TEXT == n->prev->child->type ?
                   1014:                        term_strlen(p, n->prev->child->string) :
                   1015:                     term_len(p, 5));
                   1016:                return(1);
                   1017:        }
                   1018:
1.81      schwarze 1019:        if (NULL == n->child && NULL == m->name)
1.94      schwarze 1020:                return(0);
1.81      schwarze 1021:
1.97      schwarze 1022:        if (MDOC_HEAD == n->type)
                   1023:                synopsis_pre(p, n->parent);
1.65      schwarze 1024:
1.94      schwarze 1025:        if (MDOC_HEAD == n->type && n->next->child) {
1.105     schwarze 1026:                p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
                   1027:                p->rmargin = p->offset + term_len(p, 1);
                   1028:                if (NULL == n->child) {
                   1029:                        p->rmargin += term_strlen(p, m->name);
                   1030:                } else if (MDOC_TEXT == n->child->type) {
                   1031:                        p->rmargin += term_strlen(p, n->child->string);
                   1032:                        if (n->child->next)
                   1033:                                p->flags |= TERMP_HANG;
                   1034:                } else {
                   1035:                        p->rmargin += term_len(p, 5);
                   1036:                        p->flags |= TERMP_HANG;
                   1037:                }
1.94      schwarze 1038:        }
                   1039:
1.65      schwarze 1040:        term_fontpush(p, TERMFONT_BOLD);
1.60      schwarze 1041:        if (NULL == n->child)
                   1042:                term_word(p, m->name);
1.1       kristaps 1043:        return(1);
                   1044: }
                   1045:
                   1046:
1.94      schwarze 1047: /* ARGSUSED */
                   1048: static void
                   1049: termp_nm_post(DECL_ARGS)
                   1050: {
                   1051:
                   1052:        if (MDOC_HEAD == n->type && n->next->child) {
                   1053:                term_flushln(p);
                   1054:                p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
                   1055:        } else if (MDOC_BODY == n->type && n->child) {
                   1056:                term_flushln(p);
                   1057:                p->flags &= ~TERMP_NOLPAD;
                   1058:        }
                   1059: }
                   1060:
                   1061:
1.1       kristaps 1062: /* ARGSUSED */
                   1063: static int
                   1064: termp_fl_pre(DECL_ARGS)
                   1065: {
                   1066:
1.65      schwarze 1067:        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1068:        term_word(p, "\\-");
1.67      schwarze 1069:
                   1070:        if (n->child)
                   1071:                p->flags |= TERMP_NOSPACE;
1.73      schwarze 1072:        else if (n->next && n->next->line == n->line)
                   1073:                p->flags |= TERMP_NOSPACE;
1.67      schwarze 1074:
1.1       kristaps 1075:        return(1);
1.49      schwarze 1076: }
                   1077:
                   1078:
                   1079: /* ARGSUSED */
                   1080: static int
1.104     schwarze 1081: termp__a_pre(DECL_ARGS)
                   1082: {
                   1083:
                   1084:        if (n->prev && MDOC__A == n->prev->tok)
                   1085:                if (NULL == n->next || MDOC__A != n->next->tok)
                   1086:                        term_word(p, "and");
                   1087:
                   1088:        return(1);
                   1089: }
                   1090:
                   1091:
                   1092: /* ARGSUSED */
                   1093: static int
1.49      schwarze 1094: termp_an_pre(DECL_ARGS)
                   1095: {
                   1096:
1.60      schwarze 1097:        if (NULL == n->child)
1.49      schwarze 1098:                return(1);
                   1099:
                   1100:        /*
1.60      schwarze 1101:         * If not in the AUTHORS section, `An -split' will cause
                   1102:         * newlines to occur before the author name.  If in the AUTHORS
                   1103:         * section, by default, the first `An' invocation is nosplit,
                   1104:         * then all subsequent ones, regardless of whether interspersed
                   1105:         * with other macros/text, are split.  -split, in this case,
                   1106:         * will override the condition of the implied first -nosplit.
1.49      schwarze 1107:         */
                   1108:
1.60      schwarze 1109:        if (n->sec == SEC_AUTHORS) {
1.49      schwarze 1110:                if ( ! (TERMP_ANPREC & p->flags)) {
                   1111:                        if (TERMP_SPLIT & p->flags)
                   1112:                                term_newln(p);
                   1113:                        return(1);
                   1114:                }
                   1115:                if (TERMP_NOSPLIT & p->flags)
                   1116:                        return(1);
                   1117:                term_newln(p);
                   1118:                return(1);
                   1119:        }
                   1120:
                   1121:        if (TERMP_SPLIT & p->flags)
                   1122:                term_newln(p);
                   1123:
                   1124:        return(1);
                   1125: }
                   1126:
                   1127:
                   1128: /* ARGSUSED */
                   1129: static void
                   1130: termp_an_post(DECL_ARGS)
                   1131: {
                   1132:
1.60      schwarze 1133:        if (n->child) {
                   1134:                if (SEC_AUTHORS == n->sec)
1.49      schwarze 1135:                        p->flags |= TERMP_ANPREC;
                   1136:                return;
                   1137:        }
                   1138:
1.121     schwarze 1139:        if (AUTH_split == n->norm->An.auth) {
1.49      schwarze 1140:                p->flags &= ~TERMP_NOSPLIT;
                   1141:                p->flags |= TERMP_SPLIT;
1.121     schwarze 1142:        } else if (AUTH_nosplit == n->norm->An.auth) {
1.49      schwarze 1143:                p->flags &= ~TERMP_SPLIT;
                   1144:                p->flags |= TERMP_NOSPLIT;
                   1145:        }
                   1146:
1.1       kristaps 1147: }
                   1148:
                   1149:
                   1150: /* ARGSUSED */
                   1151: static int
                   1152: termp_ns_pre(DECL_ARGS)
                   1153: {
                   1154:
1.127     schwarze 1155:        if ( ! (MDOC_LINE & n->flags))
                   1156:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1157:        return(1);
                   1158: }
                   1159:
                   1160:
                   1161: /* ARGSUSED */
                   1162: static int
                   1163: termp_rs_pre(DECL_ARGS)
                   1164: {
                   1165:
1.60      schwarze 1166:        if (SEC_SEE_ALSO != n->sec)
1.57      schwarze 1167:                return(1);
1.60      schwarze 1168:        if (MDOC_BLOCK == n->type && n->prev)
1.1       kristaps 1169:                term_vspace(p);
                   1170:        return(1);
                   1171: }
                   1172:
                   1173:
                   1174: /* ARGSUSED */
                   1175: static int
                   1176: termp_rv_pre(DECL_ARGS)
                   1177: {
1.53      schwarze 1178:        const struct mdoc_node  *nn;
1.1       kristaps 1179:
                   1180:        term_newln(p);
                   1181:        term_word(p, "The");
                   1182:
1.60      schwarze 1183:        for (nn = n->child; nn; nn = nn->next) {
1.65      schwarze 1184:                term_fontpush(p, TERMFONT_BOLD);
1.53      schwarze 1185:                term_word(p, nn->string);
1.65      schwarze 1186:                term_fontpop(p);
1.53      schwarze 1187:                p->flags |= TERMP_NOSPACE;
                   1188:                if (nn->next && NULL == nn->next->next)
                   1189:                        term_word(p, "(), and");
                   1190:                else if (nn->next)
                   1191:                        term_word(p, "(),");
                   1192:                else
                   1193:                        term_word(p, "()");
                   1194:        }
                   1195:
1.81      schwarze 1196:        if (n->child && n->child->next)
1.53      schwarze 1197:                term_word(p, "functions return");
                   1198:        else
                   1199:                term_word(p, "function returns");
1.1       kristaps 1200:
1.53      schwarze 1201:                term_word(p, "the value 0 if successful; otherwise the value "
                   1202:                        "-1 is returned and the global variable");
1.1       kristaps 1203:
1.65      schwarze 1204:        term_fontpush(p, TERMFONT_UNDER);
1.1       kristaps 1205:        term_word(p, "errno");
1.65      schwarze 1206:        term_fontpop(p);
1.1       kristaps 1207:
                   1208:                term_word(p, "is set to indicate the error.");
1.84      schwarze 1209:        p->flags |= TERMP_SENTENCE;
1.1       kristaps 1210:
1.53      schwarze 1211:        return(0);
1.1       kristaps 1212: }
                   1213:
                   1214:
                   1215: /* ARGSUSED */
                   1216: static int
                   1217: termp_ex_pre(DECL_ARGS)
                   1218: {
1.53      schwarze 1219:        const struct mdoc_node  *nn;
1.1       kristaps 1220:
1.53      schwarze 1221:        term_word(p, "The");
1.1       kristaps 1222:
1.60      schwarze 1223:        for (nn = n->child; nn; nn = nn->next) {
1.65      schwarze 1224:                term_fontpush(p, TERMFONT_BOLD);
1.53      schwarze 1225:                term_word(p, nn->string);
1.65      schwarze 1226:                term_fontpop(p);
1.53      schwarze 1227:                p->flags |= TERMP_NOSPACE;
                   1228:                if (nn->next && NULL == nn->next->next)
                   1229:                        term_word(p, ", and");
                   1230:                else if (nn->next)
                   1231:                        term_word(p, ",");
                   1232:                else
                   1233:                        p->flags &= ~TERMP_NOSPACE;
                   1234:        }
                   1235:
1.81      schwarze 1236:        if (n->child && n->child->next)
1.53      schwarze 1237:                term_word(p, "utilities exit");
                   1238:        else
                   1239:                term_word(p, "utility exits");
                   1240:
                   1241:                term_word(p, "0 on success, and >0 if an error occurs.");
1.84      schwarze 1242:        p->flags |= TERMP_SENTENCE;
1.1       kristaps 1243:
1.53      schwarze 1244:        return(0);
1.1       kristaps 1245: }
                   1246:
                   1247:
                   1248: /* ARGSUSED */
                   1249: static int
                   1250: termp_nd_pre(DECL_ARGS)
                   1251: {
1.25      schwarze 1252:
1.60      schwarze 1253:        if (MDOC_BODY != n->type)
1.25      schwarze 1254:                return(1);
                   1255:
                   1256: #if defined(__OpenBSD__) || defined(__linux__)
                   1257:        term_word(p, "\\(en");
1.24      schwarze 1258: #else
                   1259:        term_word(p, "\\(em");
                   1260: #endif
1.1       kristaps 1261:        return(1);
                   1262: }
                   1263:
                   1264:
                   1265: /* ARGSUSED */
1.73      schwarze 1266: static int
                   1267: termp_bl_pre(DECL_ARGS)
                   1268: {
                   1269:
                   1270:        return(MDOC_HEAD != n->type);
                   1271: }
                   1272:
                   1273:
                   1274: /* ARGSUSED */
1.1       kristaps 1275: static void
                   1276: termp_bl_post(DECL_ARGS)
                   1277: {
                   1278:
1.60      schwarze 1279:        if (MDOC_BLOCK == n->type)
1.1       kristaps 1280:                term_newln(p);
                   1281: }
                   1282:
                   1283:
                   1284: /* ARGSUSED */
                   1285: static int
                   1286: termp_xr_pre(DECL_ARGS)
                   1287: {
1.60      schwarze 1288:        const struct mdoc_node *nn;
1.1       kristaps 1289:
1.72      schwarze 1290:        if (NULL == n->child)
                   1291:                return(0);
                   1292:
                   1293:        assert(MDOC_TEXT == n->child->type);
1.60      schwarze 1294:        nn = n->child;
1.10      schwarze 1295:
1.60      schwarze 1296:        term_word(p, nn->string);
                   1297:        if (NULL == (nn = nn->next))
1.1       kristaps 1298:                return(0);
                   1299:        p->flags |= TERMP_NOSPACE;
                   1300:        term_word(p, "(");
1.60      schwarze 1301:        term_word(p, nn->string);
1.1       kristaps 1302:        term_word(p, ")");
1.60      schwarze 1303:
1.1       kristaps 1304:        return(0);
                   1305: }
                   1306:
                   1307:
1.86      schwarze 1308: /*
                   1309:  * This decides how to assert whitespace before any of the SYNOPSIS set
                   1310:  * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
                   1311:  * macro combos).
                   1312:  */
                   1313: static void
                   1314: synopsis_pre(struct termp *p, const struct mdoc_node *n)
                   1315: {
                   1316:        /*
                   1317:         * Obviously, if we're not in a SYNOPSIS or no prior macros
                   1318:         * exist, do nothing.
                   1319:         */
1.92      schwarze 1320:        if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1.86      schwarze 1321:                return;
                   1322:
                   1323:        /*
                   1324:         * If we're the second in a pair of like elements, emit our
                   1325:         * newline and return.  UNLESS we're `Fo', `Fn', `Fn', in which
                   1326:         * case we soldier on.
                   1327:         */
                   1328:        if (n->prev->tok == n->tok &&
                   1329:                        MDOC_Ft != n->tok &&
                   1330:                        MDOC_Fo != n->tok &&
                   1331:                        MDOC_Fn != n->tok) {
                   1332:                term_newln(p);
                   1333:                return;
                   1334:        }
                   1335:
                   1336:        /*
                   1337:         * If we're one of the SYNOPSIS set and non-like pair-wise after
                   1338:         * another (or Fn/Fo, which we've let slip through) then assert
                   1339:         * vertical space, else only newline and move on.
                   1340:         */
                   1341:        switch (n->prev->tok) {
                   1342:        case (MDOC_Fd):
                   1343:                /* FALLTHROUGH */
                   1344:        case (MDOC_Fn):
                   1345:                /* FALLTHROUGH */
                   1346:        case (MDOC_Fo):
                   1347:                /* FALLTHROUGH */
                   1348:        case (MDOC_In):
                   1349:                /* FALLTHROUGH */
                   1350:        case (MDOC_Vt):
                   1351:                term_vspace(p);
                   1352:                break;
                   1353:        case (MDOC_Ft):
                   1354:                if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
                   1355:                        term_vspace(p);
                   1356:                        break;
                   1357:                }
                   1358:                /* FALLTHROUGH */
                   1359:        default:
                   1360:                term_newln(p);
                   1361:                break;
                   1362:        }
                   1363: }
                   1364:
                   1365:
1.69      schwarze 1366: static int
                   1367: termp_vt_pre(DECL_ARGS)
                   1368: {
                   1369:
1.86      schwarze 1370:        if (MDOC_ELEM == n->type) {
                   1371:                synopsis_pre(p, n);
1.69      schwarze 1372:                return(termp_under_pre(p, pair, m, n));
1.86      schwarze 1373:        } else if (MDOC_BLOCK == n->type) {
                   1374:                synopsis_pre(p, n);
                   1375:                return(1);
                   1376:        } else if (MDOC_HEAD == n->type)
1.69      schwarze 1377:                return(0);
                   1378:
                   1379:        return(termp_under_pre(p, pair, m, n));
                   1380: }
                   1381:
                   1382:
1.1       kristaps 1383: /* ARGSUSED */
                   1384: static int
1.54      schwarze 1385: termp_bold_pre(DECL_ARGS)
1.1       kristaps 1386: {
                   1387:
1.65      schwarze 1388:        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1389:        return(1);
                   1390: }
                   1391:
                   1392:
                   1393: /* ARGSUSED */
1.86      schwarze 1394: static int
                   1395: termp_fd_pre(DECL_ARGS)
1.1       kristaps 1396: {
                   1397:
1.86      schwarze 1398:        synopsis_pre(p, n);
                   1399:        return(termp_bold_pre(p, pair, m, n));
1.1       kristaps 1400: }
                   1401:
                   1402:
                   1403: /* ARGSUSED */
                   1404: static int
                   1405: termp_sh_pre(DECL_ARGS)
                   1406: {
1.60      schwarze 1407:
                   1408:        /* No vspace between consecutive `Sh' calls. */
                   1409:
                   1410:        switch (n->type) {
1.52      schwarze 1411:        case (MDOC_BLOCK):
1.60      schwarze 1412:                if (n->prev && MDOC_Sh == n->prev->tok)
                   1413:                        if (NULL == n->prev->body->child)
1.52      schwarze 1414:                                break;
                   1415:                term_vspace(p);
                   1416:                break;
1.1       kristaps 1417:        case (MDOC_HEAD):
1.65      schwarze 1418:                term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1419:                break;
                   1420:        case (MDOC_BODY):
1.89      schwarze 1421:                p->offset = term_len(p, INDENT);
1.1       kristaps 1422:                break;
                   1423:        default:
                   1424:                break;
                   1425:        }
                   1426:        return(1);
                   1427: }
                   1428:
                   1429:
                   1430: /* ARGSUSED */
                   1431: static void
                   1432: termp_sh_post(DECL_ARGS)
                   1433: {
                   1434:
1.60      schwarze 1435:        switch (n->type) {
1.1       kristaps 1436:        case (MDOC_HEAD):
                   1437:                term_newln(p);
                   1438:                break;
                   1439:        case (MDOC_BODY):
                   1440:                term_newln(p);
                   1441:                p->offset = 0;
                   1442:                break;
                   1443:        default:
                   1444:                break;
                   1445:        }
                   1446: }
                   1447:
                   1448:
                   1449: /* ARGSUSED */
                   1450: static int
                   1451: termp_bt_pre(DECL_ARGS)
                   1452: {
                   1453:
                   1454:        term_word(p, "is currently in beta test.");
1.84      schwarze 1455:        p->flags |= TERMP_SENTENCE;
1.59      schwarze 1456:        return(0);
1.1       kristaps 1457: }
                   1458:
                   1459:
                   1460: /* ARGSUSED */
                   1461: static void
                   1462: termp_lb_post(DECL_ARGS)
                   1463: {
                   1464:
1.77      schwarze 1465:        if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1.57      schwarze 1466:                term_newln(p);
1.1       kristaps 1467: }
                   1468:
                   1469:
                   1470: /* ARGSUSED */
                   1471: static int
                   1472: termp_ud_pre(DECL_ARGS)
                   1473: {
                   1474:
                   1475:        term_word(p, "currently under development.");
1.84      schwarze 1476:        p->flags |= TERMP_SENTENCE;
1.60      schwarze 1477:        return(0);
1.1       kristaps 1478: }
                   1479:
                   1480:
                   1481: /* ARGSUSED */
                   1482: static int
                   1483: termp_d1_pre(DECL_ARGS)
                   1484: {
                   1485:
1.60      schwarze 1486:        if (MDOC_BLOCK != n->type)
1.1       kristaps 1487:                return(1);
                   1488:        term_newln(p);
1.89      schwarze 1489:        p->offset += term_len(p, (INDENT + 1));
1.1       kristaps 1490:        return(1);
                   1491: }
                   1492:
                   1493:
                   1494: /* ARGSUSED */
                   1495: static void
                   1496: termp_d1_post(DECL_ARGS)
                   1497: {
                   1498:
1.60      schwarze 1499:        if (MDOC_BLOCK != n->type)
1.1       kristaps 1500:                return;
                   1501:        term_newln(p);
                   1502: }
                   1503:
                   1504:
                   1505: /* ARGSUSED */
                   1506: static int
                   1507: termp_ft_pre(DECL_ARGS)
                   1508: {
                   1509:
1.85      schwarze 1510:        /* NB: MDOC_LINE does not effect this! */
1.86      schwarze 1511:        synopsis_pre(p, n);
1.65      schwarze 1512:        term_fontpush(p, TERMFONT_UNDER);
1.1       kristaps 1513:        return(1);
                   1514: }
                   1515:
                   1516:
                   1517: /* ARGSUSED */
                   1518: static int
                   1519: termp_fn_pre(DECL_ARGS)
                   1520: {
1.60      schwarze 1521:        const struct mdoc_node  *nn;
1.1       kristaps 1522:
1.86      schwarze 1523:        synopsis_pre(p, n);
1.85      schwarze 1524:
1.65      schwarze 1525:        term_fontpush(p, TERMFONT_BOLD);
1.60      schwarze 1526:        term_word(p, n->child->string);
1.65      schwarze 1527:        term_fontpop(p);
1.1       kristaps 1528:
                   1529:        p->flags |= TERMP_NOSPACE;
                   1530:        term_word(p, "(");
                   1531:
1.60      schwarze 1532:        for (nn = n->child->next; nn; nn = nn->next) {
1.65      schwarze 1533:                term_fontpush(p, TERMFONT_UNDER);
1.60      schwarze 1534:                term_word(p, nn->string);
1.65      schwarze 1535:                term_fontpop(p);
                   1536:
1.60      schwarze 1537:                if (nn->next)
1.1       kristaps 1538:                        term_word(p, ",");
                   1539:        }
                   1540:
                   1541:        term_word(p, ")");
                   1542:
1.92      schwarze 1543:        if (MDOC_SYNPRETTY & n->flags)
1.1       kristaps 1544:                term_word(p, ";");
                   1545:
                   1546:        return(0);
                   1547: }
                   1548:
                   1549:
                   1550: /* ARGSUSED */
                   1551: static int
                   1552: termp_fa_pre(DECL_ARGS)
                   1553: {
1.60      schwarze 1554:        const struct mdoc_node  *nn;
1.1       kristaps 1555:
1.60      schwarze 1556:        if (n->parent->tok != MDOC_Fo) {
1.65      schwarze 1557:                term_fontpush(p, TERMFONT_UNDER);
1.1       kristaps 1558:                return(1);
                   1559:        }
                   1560:
1.60      schwarze 1561:        for (nn = n->child; nn; nn = nn->next) {
1.65      schwarze 1562:                term_fontpush(p, TERMFONT_UNDER);
1.60      schwarze 1563:                term_word(p, nn->string);
1.65      schwarze 1564:                term_fontpop(p);
                   1565:
1.60      schwarze 1566:                if (nn->next)
1.1       kristaps 1567:                        term_word(p, ",");
                   1568:        }
                   1569:
1.60      schwarze 1570:        if (n->child && n->next && n->next->tok == MDOC_Fa)
1.1       kristaps 1571:                term_word(p, ",");
                   1572:
                   1573:        return(0);
                   1574: }
                   1575:
                   1576:
                   1577: /* ARGSUSED */
                   1578: static int
                   1579: termp_bd_pre(DECL_ARGS)
                   1580: {
1.99      schwarze 1581:        size_t                   tabwidth, rm, rmax;
1.60      schwarze 1582:        const struct mdoc_node  *nn;
1.1       kristaps 1583:
1.60      schwarze 1584:        if (MDOC_BLOCK == n->type) {
1.61      schwarze 1585:                print_bvspace(p, n, n);
1.45      schwarze 1586:                return(1);
1.73      schwarze 1587:        } else if (MDOC_HEAD == n->type)
                   1588:                return(0);
1.1       kristaps 1589:
1.121     schwarze 1590:        if (n->norm->Bd.offs)
                   1591:                p->offset += a2offs(p, n->norm->Bd.offs);
1.60      schwarze 1592:
                   1593:        /*
                   1594:         * If -ragged or -filled are specified, the block does nothing
                   1595:         * but change the indentation.  If -unfilled or -literal are
                   1596:         * specified, text is printed exactly as entered in the display:
                   1597:         * for macro lines, a newline is appended to the line.  Blank
                   1598:         * lines are allowed.
                   1599:         */
1.48      schwarze 1600:
1.121     schwarze 1601:        if (DISP_literal != n->norm->Bd.type &&
                   1602:                        DISP_unfilled != n->norm->Bd.type)
1.1       kristaps 1603:                return(1);
                   1604:
1.75      schwarze 1605:        tabwidth = p->tabwidth;
1.123     schwarze 1606:        if (DISP_literal == n->norm->Bd.type)
                   1607:                p->tabwidth = term_len(p, 8);
                   1608:
1.77      schwarze 1609:        rm = p->rmargin;
                   1610:        rmax = p->maxrmargin;
                   1611:        p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
                   1612:
1.60      schwarze 1613:        for (nn = n->child; nn; nn = nn->next) {
1.100     schwarze 1614:                print_mdoc_node(p, pair, m, nn);
1.108     schwarze 1615:                /*
                   1616:                 * If the printed node flushes its own line, then we
                   1617:                 * needn't do it here as well.  This is hacky, but the
                   1618:                 * notion of selective eoln whitespace is pretty dumb
                   1619:                 * anyway, so don't sweat it.
                   1620:                 */
                   1621:                switch (nn->tok) {
1.112     schwarze 1622:                case (MDOC_Sm):
                   1623:                        /* FALLTHROUGH */
1.108     schwarze 1624:                case (MDOC_br):
                   1625:                        /* FALLTHROUGH */
                   1626:                case (MDOC_sp):
                   1627:                        /* FALLTHROUGH */
                   1628:                case (MDOC_Bl):
1.115     schwarze 1629:                        /* FALLTHROUGH */
                   1630:                case (MDOC_D1):
                   1631:                        /* FALLTHROUGH */
                   1632:                case (MDOC_Dl):
1.108     schwarze 1633:                        /* FALLTHROUGH */
                   1634:                case (MDOC_Lp):
                   1635:                        /* FALLTHROUGH */
                   1636:                case (MDOC_Pp):
                   1637:                        continue;
                   1638:                default:
                   1639:                        break;
                   1640:                }
1.100     schwarze 1641:                if (nn->next && nn->next->line == nn->line)
                   1642:                        continue;
                   1643:                term_flushln(p);
1.48      schwarze 1644:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1645:        }
1.88      schwarze 1646:
1.75      schwarze 1647:        p->tabwidth = tabwidth;
1.77      schwarze 1648:        p->rmargin = rm;
                   1649:        p->maxrmargin = rmax;
1.1       kristaps 1650:        return(0);
                   1651: }
                   1652:
                   1653:
                   1654: /* ARGSUSED */
                   1655: static void
                   1656: termp_bd_post(DECL_ARGS)
                   1657: {
1.77      schwarze 1658:        size_t           rm, rmax;
1.1       kristaps 1659:
1.60      schwarze 1660:        if (MDOC_BODY != n->type)
1.1       kristaps 1661:                return;
1.77      schwarze 1662:
                   1663:        rm = p->rmargin;
                   1664:        rmax = p->maxrmargin;
                   1665:
1.121     schwarze 1666:        if (DISP_literal == n->norm->Bd.type ||
                   1667:                        DISP_unfilled == n->norm->Bd.type)
1.77      schwarze 1668:                p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
                   1669:
1.48      schwarze 1670:        p->flags |= TERMP_NOSPACE;
1.75      schwarze 1671:        term_newln(p);
1.77      schwarze 1672:
                   1673:        p->rmargin = rm;
                   1674:        p->maxrmargin = rmax;
1.1       kristaps 1675: }
                   1676:
                   1677:
                   1678: /* ARGSUSED */
1.126     schwarze 1679: static int
                   1680: termp_bx_pre(DECL_ARGS)
1.1       kristaps 1681: {
                   1682:
1.126     schwarze 1683:        if (NULL != (n = n->child)) {
                   1684:                term_word(p, n->string);
                   1685:                p->flags |= TERMP_NOSPACE;
                   1686:                term_word(p, "BSD");
                   1687:        } else {
                   1688:                term_word(p, "BSD");
                   1689:                return(0);
                   1690:        }
                   1691:
                   1692:        if (NULL != (n = n->next)) {
                   1693:                p->flags |= TERMP_NOSPACE;
                   1694:                term_word(p, "-");
1.1       kristaps 1695:                p->flags |= TERMP_NOSPACE;
1.126     schwarze 1696:                term_word(p, n->string);
                   1697:        }
                   1698:
                   1699:        return(0);
1.1       kristaps 1700: }
                   1701:
                   1702:
                   1703: /* ARGSUSED */
                   1704: static int
1.26      schwarze 1705: termp_xx_pre(DECL_ARGS)
1.1       kristaps 1706: {
1.26      schwarze 1707:        const char      *pp;
1.1       kristaps 1708:
1.26      schwarze 1709:        pp = NULL;
1.60      schwarze 1710:        switch (n->tok) {
1.26      schwarze 1711:        case (MDOC_Bsx):
1.113     schwarze 1712:                pp = "BSD/OS";
1.26      schwarze 1713:                break;
                   1714:        case (MDOC_Dx):
1.64      schwarze 1715:                pp = "DragonFly";
1.26      schwarze 1716:                break;
                   1717:        case (MDOC_Fx):
                   1718:                pp = "FreeBSD";
                   1719:                break;
                   1720:        case (MDOC_Nx):
                   1721:                pp = "NetBSD";
                   1722:                break;
                   1723:        case (MDOC_Ox):
                   1724:                pp = "OpenBSD";
                   1725:                break;
                   1726:        case (MDOC_Ux):
                   1727:                pp = "UNIX";
                   1728:                break;
                   1729:        default:
                   1730:                break;
                   1731:        }
1.1       kristaps 1732:
1.26      schwarze 1733:        assert(pp);
                   1734:        term_word(p, pp);
1.1       kristaps 1735:        return(1);
                   1736: }
                   1737:
                   1738:
                   1739: /* ARGSUSED */
                   1740: static int
1.109     schwarze 1741: termp_igndelim_pre(DECL_ARGS)
1.1       kristaps 1742: {
                   1743:
                   1744:        p->flags |= TERMP_IGNDELIM;
                   1745:        return(1);
                   1746: }
                   1747:
                   1748:
                   1749: /* ARGSUSED */
                   1750: static void
                   1751: termp_pf_post(DECL_ARGS)
                   1752: {
                   1753:
                   1754:        p->flags |= TERMP_NOSPACE;
                   1755: }
                   1756:
                   1757:
                   1758: /* ARGSUSED */
                   1759: static int
                   1760: termp_ss_pre(DECL_ARGS)
                   1761: {
                   1762:
1.60      schwarze 1763:        switch (n->type) {
1.1       kristaps 1764:        case (MDOC_BLOCK):
                   1765:                term_newln(p);
1.60      schwarze 1766:                if (n->prev)
1.1       kristaps 1767:                        term_vspace(p);
                   1768:                break;
                   1769:        case (MDOC_HEAD):
1.65      schwarze 1770:                term_fontpush(p, TERMFONT_BOLD);
1.89      schwarze 1771:                p->offset = term_len(p, HALFINDENT);
1.1       kristaps 1772:                break;
                   1773:        default:
                   1774:                break;
                   1775:        }
                   1776:
                   1777:        return(1);
                   1778: }
                   1779:
                   1780:
                   1781: /* ARGSUSED */
                   1782: static void
                   1783: termp_ss_post(DECL_ARGS)
                   1784: {
                   1785:
1.60      schwarze 1786:        if (MDOC_HEAD == n->type)
1.1       kristaps 1787:                term_newln(p);
                   1788: }
                   1789:
                   1790:
                   1791: /* ARGSUSED */
                   1792: static int
                   1793: termp_cd_pre(DECL_ARGS)
                   1794: {
                   1795:
1.86      schwarze 1796:        synopsis_pre(p, n);
1.65      schwarze 1797:        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1798:        return(1);
                   1799: }
                   1800:
                   1801:
                   1802: /* ARGSUSED */
                   1803: static int
                   1804: termp_in_pre(DECL_ARGS)
                   1805: {
                   1806:
1.86      schwarze 1807:        synopsis_pre(p, n);
1.85      schwarze 1808:
1.92      schwarze 1809:        if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
1.85      schwarze 1810:                term_fontpush(p, TERMFONT_BOLD);
1.23      schwarze 1811:                term_word(p, "#include");
1.85      schwarze 1812:                term_word(p, "<");
                   1813:        } else {
                   1814:                term_word(p, "<");
                   1815:                term_fontpush(p, TERMFONT_UNDER);
                   1816:        }
1.23      schwarze 1817:
1.1       kristaps 1818:        p->flags |= TERMP_NOSPACE;
                   1819:        return(1);
                   1820: }
                   1821:
                   1822:
                   1823: /* ARGSUSED */
                   1824: static void
                   1825: termp_in_post(DECL_ARGS)
                   1826: {
                   1827:
1.92      schwarze 1828:        if (MDOC_SYNPRETTY & n->flags)
1.85      schwarze 1829:                term_fontpush(p, TERMFONT_BOLD);
                   1830:
1.59      schwarze 1831:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1832:        term_word(p, ">");
                   1833:
1.92      schwarze 1834:        if (MDOC_SYNPRETTY & n->flags)
1.85      schwarze 1835:                term_fontpop(p);
1.38      schwarze 1836: }
                   1837:
                   1838:
                   1839: /* ARGSUSED */
                   1840: static int
                   1841: termp_sp_pre(DECL_ARGS)
                   1842: {
1.61      schwarze 1843:        size_t           i, len;
1.38      schwarze 1844:
1.60      schwarze 1845:        switch (n->tok) {
1.54      schwarze 1846:        case (MDOC_sp):
1.89      schwarze 1847:                len = n->child ? a2height(p, n->child->string) : 1;
1.54      schwarze 1848:                break;
                   1849:        case (MDOC_br):
                   1850:                len = 0;
                   1851:                break;
                   1852:        default:
                   1853:                len = 1;
                   1854:                break;
1.38      schwarze 1855:        }
                   1856:
                   1857:        if (0 == len)
                   1858:                term_newln(p);
                   1859:        for (i = 0; i < len; i++)
                   1860:                term_vspace(p);
                   1861:
                   1862:        return(0);
                   1863: }
                   1864:
                   1865:
                   1866: /* ARGSUSED */
                   1867: static int
1.107     schwarze 1868: termp_quote_pre(DECL_ARGS)
1.1       kristaps 1869: {
                   1870:
1.120     schwarze 1871:        if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1       kristaps 1872:                return(1);
                   1873:
1.107     schwarze 1874:        switch (n->tok) {
                   1875:        case (MDOC_Ao):
                   1876:                /* FALLTHROUGH */
                   1877:        case (MDOC_Aq):
                   1878:                term_word(p, "<");
                   1879:                break;
                   1880:        case (MDOC_Bro):
                   1881:                /* FALLTHROUGH */
                   1882:        case (MDOC_Brq):
                   1883:                term_word(p, "{");
                   1884:                break;
                   1885:        case (MDOC_Oo):
                   1886:                /* FALLTHROUGH */
                   1887:        case (MDOC_Op):
                   1888:                /* FALLTHROUGH */
                   1889:        case (MDOC_Bo):
                   1890:                /* FALLTHROUGH */
                   1891:        case (MDOC_Bq):
                   1892:                term_word(p, "[");
                   1893:                break;
                   1894:        case (MDOC_Do):
                   1895:                /* FALLTHROUGH */
                   1896:        case (MDOC_Dq):
                   1897:                term_word(p, "``");
                   1898:                break;
                   1899:        case (MDOC_Po):
                   1900:                /* FALLTHROUGH */
                   1901:        case (MDOC_Pq):
                   1902:                term_word(p, "(");
                   1903:                break;
1.120     schwarze 1904:        case (MDOC__T):
                   1905:                /* FALLTHROUGH */
1.107     schwarze 1906:        case (MDOC_Qo):
                   1907:                /* FALLTHROUGH */
                   1908:        case (MDOC_Qq):
                   1909:                term_word(p, "\"");
                   1910:                break;
                   1911:        case (MDOC_Ql):
                   1912:                /* FALLTHROUGH */
                   1913:        case (MDOC_So):
                   1914:                /* FALLTHROUGH */
                   1915:        case (MDOC_Sq):
                   1916:                term_word(p, "`");
                   1917:                break;
                   1918:        default:
                   1919:                abort();
                   1920:                /* NOTREACHED */
                   1921:        }
1.1       kristaps 1922:
                   1923:        p->flags |= TERMP_NOSPACE;
                   1924:        return(1);
                   1925: }
                   1926:
                   1927:
                   1928: /* ARGSUSED */
                   1929: static void
1.107     schwarze 1930: termp_quote_post(DECL_ARGS)
1.1       kristaps 1931: {
                   1932:
1.120     schwarze 1933:        if (MDOC_BODY != n->type && MDOC_ELEM != n->type)
1.1       kristaps 1934:                return;
                   1935:
                   1936:        p->flags |= TERMP_NOSPACE;
                   1937:
1.107     schwarze 1938:        switch (n->tok) {
                   1939:        case (MDOC_Ao):
                   1940:                /* FALLTHROUGH */
                   1941:        case (MDOC_Aq):
                   1942:                term_word(p, ">");
                   1943:                break;
                   1944:        case (MDOC_Bro):
                   1945:                /* FALLTHROUGH */
                   1946:        case (MDOC_Brq):
                   1947:                term_word(p, "}");
                   1948:                break;
                   1949:        case (MDOC_Oo):
                   1950:                /* FALLTHROUGH */
                   1951:        case (MDOC_Op):
                   1952:                /* FALLTHROUGH */
                   1953:        case (MDOC_Bo):
                   1954:                /* FALLTHROUGH */
                   1955:        case (MDOC_Bq):
                   1956:                term_word(p, "]");
                   1957:                break;
                   1958:        case (MDOC_Do):
                   1959:                /* FALLTHROUGH */
                   1960:        case (MDOC_Dq):
                   1961:                term_word(p, "''");
                   1962:                break;
                   1963:        case (MDOC_Po):
                   1964:                /* FALLTHROUGH */
                   1965:        case (MDOC_Pq):
                   1966:                term_word(p, ")");
                   1967:                break;
1.120     schwarze 1968:        case (MDOC__T):
                   1969:                /* FALLTHROUGH */
1.107     schwarze 1970:        case (MDOC_Qo):
                   1971:                /* FALLTHROUGH */
                   1972:        case (MDOC_Qq):
                   1973:                term_word(p, "\"");
                   1974:                break;
                   1975:        case (MDOC_Ql):
                   1976:                /* FALLTHROUGH */
                   1977:        case (MDOC_So):
                   1978:                /* FALLTHROUGH */
                   1979:        case (MDOC_Sq):
                   1980:                term_word(p, "'");
                   1981:                break;
                   1982:        default:
                   1983:                abort();
                   1984:                /* NOTREACHED */
                   1985:        }
1.1       kristaps 1986: }
                   1987:
                   1988:
                   1989: /* ARGSUSED */
                   1990: static int
                   1991: termp_fo_pre(DECL_ARGS)
                   1992: {
                   1993:
1.85      schwarze 1994:        if (MDOC_BLOCK == n->type) {
1.86      schwarze 1995:                synopsis_pre(p, n);
1.85      schwarze 1996:                return(1);
                   1997:        } else if (MDOC_BODY == n->type) {
1.31      schwarze 1998:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1999:                term_word(p, "(");
                   2000:                return(1);
1.85      schwarze 2001:        }
                   2002:
1.95      schwarze 2003:        if (NULL == n->child)
                   2004:                return(0);
                   2005:
1.85      schwarze 2006:        /* XXX: we drop non-initial arguments as per groff. */
1.1       kristaps 2007:
1.85      schwarze 2008:        assert(n->child->string);
1.65      schwarze 2009:        term_fontpush(p, TERMFONT_BOLD);
1.85      schwarze 2010:        term_word(p, n->child->string);
1.1       kristaps 2011:        return(0);
                   2012: }
                   2013:
                   2014:
                   2015: /* ARGSUSED */
                   2016: static void
                   2017: termp_fo_post(DECL_ARGS)
                   2018: {
                   2019:
1.86      schwarze 2020:        if (MDOC_BODY != n->type)
                   2021:                return;
                   2022:
                   2023:        term_word(p, ")");
                   2024:
1.107     schwarze 2025:        if (MDOC_SYNPRETTY & n->flags)
1.86      schwarze 2026:                term_word(p, ";");
1.1       kristaps 2027: }
                   2028:
                   2029:
                   2030: /* ARGSUSED */
                   2031: static int
                   2032: termp_bf_pre(DECL_ARGS)
                   2033: {
                   2034:
1.60      schwarze 2035:        if (MDOC_HEAD == n->type)
1.1       kristaps 2036:                return(0);
1.60      schwarze 2037:        else if (MDOC_BLOCK != n->type)
1.1       kristaps 2038:                return(1);
                   2039:
1.121     schwarze 2040:        if (FONT_Em == n->norm->Bf.font)
1.65      schwarze 2041:                term_fontpush(p, TERMFONT_UNDER);
1.121     schwarze 2042:        else if (FONT_Sy == n->norm->Bf.font)
1.65      schwarze 2043:                term_fontpush(p, TERMFONT_BOLD);
1.95      schwarze 2044:        else
1.65      schwarze 2045:                term_fontpush(p, TERMFONT_NONE);
1.1       kristaps 2046:
                   2047:        return(1);
                   2048: }
                   2049:
                   2050:
                   2051: /* ARGSUSED */
                   2052: static int
                   2053: termp_sm_pre(DECL_ARGS)
                   2054: {
                   2055:
1.60      schwarze 2056:        assert(n->child && MDOC_TEXT == n->child->type);
1.96      schwarze 2057:        if (0 == strcmp("on", n->child->string)) {
                   2058:                if (p->col)
                   2059:                        p->flags &= ~TERMP_NOSPACE;
1.1       kristaps 2060:                p->flags &= ~TERMP_NONOSPACE;
1.96      schwarze 2061:        } else
1.1       kristaps 2062:                p->flags |= TERMP_NONOSPACE;
                   2063:
                   2064:        return(0);
                   2065: }
                   2066:
                   2067:
                   2068: /* ARGSUSED */
                   2069: static int
                   2070: termp_ap_pre(DECL_ARGS)
                   2071: {
                   2072:
                   2073:        p->flags |= TERMP_NOSPACE;
1.107     schwarze 2074:        term_word(p, "'");
1.1       kristaps 2075:        p->flags |= TERMP_NOSPACE;
                   2076:        return(1);
                   2077: }
                   2078:
                   2079:
                   2080: /* ARGSUSED */
                   2081: static void
                   2082: termp____post(DECL_ARGS)
                   2083: {
1.104     schwarze 2084:
                   2085:        /*
                   2086:         * Handle lists of authors.  In general, print each followed by
                   2087:         * a comma.  Don't print the comma if there are only two
                   2088:         * authors.
                   2089:         */
                   2090:        if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
                   2091:                if (NULL == n->next->next || MDOC__A != n->next->next->tok)
                   2092:                        if (NULL == n->prev || MDOC__A != n->prev->tok)
                   2093:                                return;
1.1       kristaps 2094:
1.62      schwarze 2095:        /* TODO: %U. */
                   2096:
1.106     schwarze 2097:        if (NULL == n->parent || MDOC_Rs != n->parent->tok)
                   2098:                return;
                   2099:
                   2100:        if (NULL == n->next) {
                   2101:                term_word(p, ".");
                   2102:                p->flags |= TERMP_SENTENCE;
                   2103:        } else
                   2104:                term_word(p, ",");
1.1       kristaps 2105: }
                   2106:
                   2107:
                   2108: /* ARGSUSED */
                   2109: static int
1.65      schwarze 2110: termp_li_pre(DECL_ARGS)
                   2111: {
                   2112:
                   2113:        term_fontpush(p, TERMFONT_NONE);
                   2114:        return(1);
                   2115: }
                   2116:
                   2117:
                   2118: /* ARGSUSED */
                   2119: static int
1.1       kristaps 2120: termp_lk_pre(DECL_ARGS)
                   2121: {
1.101     schwarze 2122:        const struct mdoc_node *nn, *sv;
1.1       kristaps 2123:
1.65      schwarze 2124:        term_fontpush(p, TERMFONT_UNDER);
1.101     schwarze 2125:
                   2126:        nn = sv = n->child;
1.62      schwarze 2127:
1.114     schwarze 2128:        if (NULL == nn || NULL == nn->next)
1.6       schwarze 2129:                return(1);
1.1       kristaps 2130:
1.101     schwarze 2131:        for (nn = nn->next; nn; nn = nn->next)
                   2132:                term_word(p, nn->string);
                   2133:
1.65      schwarze 2134:        term_fontpop(p);
1.62      schwarze 2135:
1.1       kristaps 2136:        term_word(p, ":");
                   2137:
1.65      schwarze 2138:        term_fontpush(p, TERMFONT_BOLD);
1.101     schwarze 2139:        term_word(p, sv->string);
1.65      schwarze 2140:        term_fontpop(p);
1.6       schwarze 2141:
1.1       kristaps 2142:        return(0);
                   2143: }
                   2144:
1.90      schwarze 2145:
                   2146: /* ARGSUSED */
                   2147: static int
                   2148: termp_bk_pre(DECL_ARGS)
                   2149: {
                   2150:
1.91      schwarze 2151:        switch (n->type) {
                   2152:        case (MDOC_BLOCK):
1.95      schwarze 2153:                break;
1.91      schwarze 2154:        case (MDOC_HEAD):
                   2155:                return(0);
                   2156:        case (MDOC_BODY):
1.117     schwarze 2157:                if (n->parent->args || 0 == n->prev->nchild)
                   2158:                        p->flags |= TERMP_PREKEEP;
1.95      schwarze 2159:                break;
1.91      schwarze 2160:        default:
                   2161:                abort();
1.95      schwarze 2162:                /* NOTREACHED */
1.91      schwarze 2163:        }
1.95      schwarze 2164:
                   2165:        return(1);
1.90      schwarze 2166: }
                   2167:
                   2168:
                   2169: /* ARGSUSED */
                   2170: static void
                   2171: termp_bk_post(DECL_ARGS)
                   2172: {
                   2173:
1.91      schwarze 2174:        if (MDOC_BODY == n->type)
                   2175:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.90      schwarze 2176: }
1.120     schwarze 2177:
                   2178: /* ARGSUSED */
                   2179: static void
                   2180: termp__t_post(DECL_ARGS)
                   2181: {
                   2182:
                   2183:        /*
                   2184:         * If we're in an `Rs' and there's a journal present, then quote
                   2185:         * us instead of underlining us (for disambiguation).
                   2186:         */
1.121     schwarze 2187:        if (n->parent && MDOC_Rs == n->parent->tok &&
1.125     schwarze 2188:                        n->parent->norm->Rs.quote_T)
1.120     schwarze 2189:                termp_quote_post(p, pair, m, n);
                   2190:
                   2191:        termp____post(p, pair, m, n);
                   2192: }
                   2193:
                   2194: /* ARGSUSED */
                   2195: static int
                   2196: termp__t_pre(DECL_ARGS)
                   2197: {
                   2198:
                   2199:        /*
                   2200:         * If we're in an `Rs' and there's a journal present, then quote
                   2201:         * us instead of underlining us (for disambiguation).
                   2202:         */
1.121     schwarze 2203:        if (n->parent && MDOC_Rs == n->parent->tok &&
1.125     schwarze 2204:                        n->parent->norm->Rs.quote_T)
1.120     schwarze 2205:                return(termp_quote_pre(p, pair, m, n));
                   2206:
                   2207:        term_fontpush(p, TERMFONT_UNDER);
                   2208:        return(1);
1.121     schwarze 2209: }
1.1       kristaps 2210:
                   2211: /* ARGSUSED */
                   2212: static int
1.54      schwarze 2213: termp_under_pre(DECL_ARGS)
1.1       kristaps 2214: {
                   2215:
1.65      schwarze 2216:        term_fontpush(p, TERMFONT_UNDER);
1.1       kristaps 2217:        return(1);
                   2218: }