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

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

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