[BACK]Return to mdoc_term.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/mdoc_term.c, Revision 1.216

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

CVSweb