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

Annotation of mandoc/mdoc_term.c, Revision 1.362

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

CVSweb