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

Annotation of mandoc/mdoc_term.c, Revision 1.221

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

CVSweb