[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.132

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