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

Annotation of mandoc/mdoc_term.c, Revision 1.351

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

CVSweb