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

Annotation of mandoc/mdoc_term.c, Revision 1.344

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

CVSweb