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

Annotation of mandoc/mdoc_term.c, Revision 1.220

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

CVSweb