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

Annotation of mandoc/mdoc_term.c, Revision 1.219

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

CVSweb