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

Annotation of mandoc/mdoc_term.c, Revision 1.353

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

CVSweb