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

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