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

Annotation of mandoc/mdoc_term.c, Revision 1.356

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

CVSweb