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

Annotation of mandoc/mdoc_term.c, Revision 1.345

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

CVSweb