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

Annotation of mandoc/mdoc_term.c, Revision 1.357

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

CVSweb