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

Annotation of mandoc/mdoc_term.c, Revision 1.341

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

CVSweb