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

Annotation of mandoc/mdoc_term.c, Revision 1.361

1.361   ! schwarze    1: /*     $Id: mdoc_term.c,v 1.360 2017/06/04 18:50:35 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.281     schwarze  262:        p->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.29      kristaps  319:        offset = p->offset;
1.30      kristaps  320:        rmargin = p->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)
                    410:                p->offset = offset;
1.354     schwarze  411:        p->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.9       kristaps  431:        p->offset = 0;
1.292     schwarze  432:        sz = term_strlen(p, meta->date);
                    433:        p->rmargin = p->maxrmargin > sz ?
                    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.9       kristaps  441:        p->offset = p->rmargin;
1.292     schwarze  442:        sz = term_strlen(p, meta->os);
                    443:        p->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.1       kristaps  449:        p->offset = p->rmargin;
                    450:        p->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.9       kristaps  458:        p->offset = 0;
                    459:        p->rmargin = p->maxrmargin;
                    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.1       kristaps  499:        p->offset = 0;
1.267     schwarze  500:        p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ?
                    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.1       kristaps  508:        p->offset = p->rmargin;
1.267     schwarze  509:        p->rmargin = p->offset + vollen + titlen < p->maxrmargin ?
1.235     schwarze  510:            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.235     schwarze  517:        if (p->rmargin + titlen <= p->maxrmargin) {
                    518:                p->flags |= TERMP_NOSPACE;
                    519:                p->offset = p->rmargin;
                    520:                p->rmargin = p->maxrmargin;
                    521:                term_word(p, title);
                    522:                term_flushln(p);
                    523:        }
1.1       kristaps  524:
1.235     schwarze  525:        p->flags &= ~TERMP_NOSPACE;
1.9       kristaps  526:        p->offset = 0;
1.1       kristaps  527:        p->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.302     schwarze  652:                if (offset < 0 && (size_t)(-offset) > p->offset)
                    653:                        offset = -p->offset;
                    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.302     schwarze  717:                if (width < 0 && (size_t)(-width) > p->offset)
                    718:                        width = -p->offset;
                    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:
                    818:        p->offset += offset;
                    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.1       kristaps  828:                        p->rmargin = p->offset + width;
1.292     schwarze  829:                else
1.1       kristaps  830:                        p->offset += width;
                    831:                break;
1.264     schwarze  832:        case LIST_column:
1.49      kristaps  833:                assert(width);
1.1       kristaps  834:                p->rmargin = p->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;
                    841:                if (NULL == n->next && p->rmargin < p->maxrmargin)
1.50      kristaps  842:                        p->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.164     schwarze  948:                if (NULL == n->child)
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)
                    957:                        p->offset += term_len(p, 6);
                    958:                else
                    959:                        p->offset += term_len(p, 1) + term_strlen(p, cp);
1.328     schwarze  960:                return 1;
1.164     schwarze  961:        }
                    962:
1.343     schwarze  963:        if (n->child == NULL)
1.328     schwarze  964:                return 0;
1.125     kristaps  965:
1.314     schwarze  966:        if (n->type == ROFFT_HEAD)
1.177     schwarze  967:                synopsis_pre(p, n->parent);
1.102     kristaps  968:
1.314     schwarze  969:        if (n->type == ROFFT_HEAD &&
1.278     schwarze  970:            NULL != n->next && NULL != n->next->child) {
1.263     schwarze  971:                p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND;
1.250     schwarze  972:                p->trailspace = 1;
1.185     schwarze  973:                p->rmargin = p->offset + term_len(p, 1);
                    974:                if (NULL == n->child) {
1.245     schwarze  975:                        p->rmargin += term_strlen(p, meta->name);
1.314     schwarze  976:                } else if (n->child->type == ROFFT_TEXT) {
1.185     schwarze  977:                        p->rmargin += term_strlen(p, n->child->string);
                    978:                        if (n->child->next)
                    979:                                p->flags |= TERMP_HANG;
                    980:                } else {
                    981:                        p->rmargin += term_len(p, 5);
                    982:                        p->flags |= TERMP_HANG;
                    983:                }
1.164     schwarze  984:        }
                    985:
1.102     kristaps  986:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze  987:        return 1;
1.1       kristaps  988: }
                    989:
1.164     schwarze  990: static void
                    991: termp_nm_post(DECL_ARGS)
                    992: {
                    993:
1.314     schwarze  994:        if (n->type == ROFFT_BLOCK) {
1.253     schwarze  995:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.314     schwarze  996:        } else if (n->type == ROFFT_HEAD &&
1.278     schwarze  997:            NULL != n->next && NULL != n->next->child) {
1.164     schwarze  998:                term_flushln(p);
1.263     schwarze  999:                p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1.250     schwarze 1000:                p->trailspace = 0;
1.314     schwarze 1001:        } else if (n->type == ROFFT_BODY && n->child != NULL)
1.164     schwarze 1002:                term_flushln(p);
                   1003: }
                   1004:
1.1       kristaps 1005: static int
                   1006: termp_fl_pre(DECL_ARGS)
                   1007: {
                   1008:
1.320     schwarze 1009:        termp_tag_pre(p, pair, meta, n);
1.102     kristaps 1010:        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1011:        term_word(p, "\\-");
1.103     kristaps 1012:
1.331     schwarze 1013:        if (!(n->child == NULL &&
1.280     schwarze 1014:            (n->next == NULL ||
1.314     schwarze 1015:             n->next->type == ROFFT_TEXT ||
1.338     schwarze 1016:             n->next->flags & NODE_LINE)))
1.103     kristaps 1017:                p->flags |= TERMP_NOSPACE;
                   1018:
1.328     schwarze 1019:        return 1;
1.1       kristaps 1020: }
                   1021:
                   1022: static int
1.184     kristaps 1023: termp__a_pre(DECL_ARGS)
                   1024: {
                   1025:
                   1026:        if (n->prev && MDOC__A == n->prev->tok)
                   1027:                if (NULL == n->next || MDOC__A != n->next->tok)
                   1028:                        term_word(p, "and");
                   1029:
1.328     schwarze 1030:        return 1;
1.184     kristaps 1031: }
                   1032:
                   1033: static int
1.61      kristaps 1034: termp_an_pre(DECL_ARGS)
                   1035: {
                   1036:
1.282     schwarze 1037:        if (n->norm->An.auth == AUTH_split) {
                   1038:                p->flags &= ~TERMP_NOSPLIT;
                   1039:                p->flags |= TERMP_SPLIT;
1.328     schwarze 1040:                return 0;
1.282     schwarze 1041:        }
                   1042:        if (n->norm->An.auth == AUTH_nosplit) {
                   1043:                p->flags &= ~TERMP_SPLIT;
                   1044:                p->flags |= TERMP_NOSPLIT;
1.328     schwarze 1045:                return 0;
1.282     schwarze 1046:        }
1.264     schwarze 1047:
1.282     schwarze 1048:        if (p->flags & TERMP_SPLIT)
1.61      kristaps 1049:                term_newln(p);
                   1050:
1.282     schwarze 1051:        if (n->sec == SEC_AUTHORS && ! (p->flags & TERMP_NOSPLIT))
                   1052:                p->flags |= TERMP_SPLIT;
1.61      kristaps 1053:
1.328     schwarze 1054:        return 1;
1.61      kristaps 1055: }
                   1056:
                   1057: static int
1.1       kristaps 1058: termp_ns_pre(DECL_ARGS)
                   1059: {
                   1060:
1.338     schwarze 1061:        if ( ! (NODE_LINE & n->flags))
1.215     kristaps 1062:                p->flags |= TERMP_NOSPACE;
1.328     schwarze 1063:        return 1;
1.1       kristaps 1064: }
                   1065:
                   1066: static int
                   1067: termp_rs_pre(DECL_ARGS)
                   1068: {
                   1069:
1.86      kristaps 1070:        if (SEC_SEE_ALSO != n->sec)
1.328     schwarze 1071:                return 1;
1.314     schwarze 1072:        if (n->type == ROFFT_BLOCK && n->prev != NULL)
1.1       kristaps 1073:                term_vspace(p);
1.328     schwarze 1074:        return 1;
1.1       kristaps 1075: }
                   1076:
                   1077: static int
                   1078: termp_ex_pre(DECL_ARGS)
                   1079: {
1.224     kristaps 1080:        term_newln(p);
1.341     schwarze 1081:        return 1;
1.1       kristaps 1082: }
                   1083:
                   1084: static int
                   1085: termp_nd_pre(DECL_ARGS)
                   1086: {
1.25      kristaps 1087:
1.314     schwarze 1088:        if (n->type == ROFFT_BODY)
1.297     schwarze 1089:                term_word(p, "\\(en");
1.328     schwarze 1090:        return 1;
1.115     kristaps 1091: }
                   1092:
                   1093: static int
                   1094: termp_bl_pre(DECL_ARGS)
                   1095: {
                   1096:
1.328     schwarze 1097:        return n->type != ROFFT_HEAD;
1.1       kristaps 1098: }
                   1099:
                   1100: static void
                   1101: termp_bl_post(DECL_ARGS)
                   1102: {
                   1103:
1.356     schwarze 1104:        if (n->type != ROFFT_BLOCK)
                   1105:                return;
                   1106:        term_newln(p);
                   1107:        if (n->tok != MDOC_Bl || n->norm->Bl.type != LIST_column)
                   1108:                return;
                   1109:        term_tab_set(p, NULL);
                   1110:        term_tab_set(p, "T");
                   1111:        term_tab_set(p, ".5i");
1.1       kristaps 1112: }
                   1113:
                   1114: static int
                   1115: termp_xr_pre(DECL_ARGS)
                   1116: {
                   1117:
1.225     kristaps 1118:        if (NULL == (n = n->child))
1.328     schwarze 1119:                return 0;
1.113     kristaps 1120:
1.314     schwarze 1121:        assert(n->type == ROFFT_TEXT);
1.225     kristaps 1122:        term_word(p, n->string);
1.11      kristaps 1123:
1.264     schwarze 1124:        if (NULL == (n = n->next))
1.328     schwarze 1125:                return 0;
1.225     kristaps 1126:
1.1       kristaps 1127:        p->flags |= TERMP_NOSPACE;
                   1128:        term_word(p, "(");
1.222     kristaps 1129:        p->flags |= TERMP_NOSPACE;
1.225     kristaps 1130:
1.314     schwarze 1131:        assert(n->type == ROFFT_TEXT);
1.225     kristaps 1132:        term_word(p, n->string);
                   1133:
1.222     kristaps 1134:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1135:        term_word(p, ")");
1.86      kristaps 1136:
1.328     schwarze 1137:        return 0;
1.1       kristaps 1138: }
                   1139:
1.143     kristaps 1140: /*
                   1141:  * This decides how to assert whitespace before any of the SYNOPSIS set
                   1142:  * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
                   1143:  * macro combos).
                   1144:  */
                   1145: static void
1.315     schwarze 1146: synopsis_pre(struct termp *p, const struct roff_node *n)
1.143     kristaps 1147: {
1.264     schwarze 1148:        /*
1.143     kristaps 1149:         * Obviously, if we're not in a SYNOPSIS or no prior macros
                   1150:         * exist, do nothing.
                   1151:         */
1.338     schwarze 1152:        if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
1.143     kristaps 1153:                return;
                   1154:
                   1155:        /*
                   1156:         * If we're the second in a pair of like elements, emit our
                   1157:         * newline and return.  UNLESS we're `Fo', `Fn', `Fn', in which
                   1158:         * case we soldier on.
                   1159:         */
1.264     schwarze 1160:        if (n->prev->tok == n->tok &&
                   1161:            MDOC_Ft != n->tok &&
                   1162:            MDOC_Fo != n->tok &&
                   1163:            MDOC_Fn != n->tok) {
1.143     kristaps 1164:                term_newln(p);
                   1165:                return;
                   1166:        }
                   1167:
                   1168:        /*
                   1169:         * If we're one of the SYNOPSIS set and non-like pair-wise after
                   1170:         * another (or Fn/Fo, which we've let slip through) then assert
                   1171:         * vertical space, else only newline and move on.
                   1172:         */
                   1173:        switch (n->prev->tok) {
1.264     schwarze 1174:        case MDOC_Fd:
                   1175:        case MDOC_Fn:
                   1176:        case MDOC_Fo:
                   1177:        case MDOC_In:
                   1178:        case MDOC_Vt:
1.143     kristaps 1179:                term_vspace(p);
                   1180:                break;
1.264     schwarze 1181:        case MDOC_Ft:
1.143     kristaps 1182:                if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
                   1183:                        term_vspace(p);
                   1184:                        break;
                   1185:                }
                   1186:                /* FALLTHROUGH */
                   1187:        default:
                   1188:                term_newln(p);
                   1189:                break;
                   1190:        }
                   1191: }
                   1192:
1.110     kristaps 1193: static int
                   1194: termp_vt_pre(DECL_ARGS)
                   1195: {
                   1196:
1.314     schwarze 1197:        if (n->type == ROFFT_ELEM) {
1.143     kristaps 1198:                synopsis_pre(p, n);
1.328     schwarze 1199:                return termp_under_pre(p, pair, meta, n);
1.314     schwarze 1200:        } else if (n->type == ROFFT_BLOCK) {
1.143     kristaps 1201:                synopsis_pre(p, n);
1.328     schwarze 1202:                return 1;
1.314     schwarze 1203:        } else if (n->type == ROFFT_HEAD)
1.328     schwarze 1204:                return 0;
1.110     kristaps 1205:
1.328     schwarze 1206:        return termp_under_pre(p, pair, meta, n);
1.110     kristaps 1207: }
                   1208:
1.1       kristaps 1209: static int
1.69      kristaps 1210: termp_bold_pre(DECL_ARGS)
1.1       kristaps 1211: {
                   1212:
1.320     schwarze 1213:        termp_tag_pre(p, pair, meta, n);
1.102     kristaps 1214:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze 1215:        return 1;
1.1       kristaps 1216: }
                   1217:
1.143     kristaps 1218: static int
                   1219: termp_fd_pre(DECL_ARGS)
1.1       kristaps 1220: {
                   1221:
1.143     kristaps 1222:        synopsis_pre(p, n);
1.328     schwarze 1223:        return termp_bold_pre(p, pair, meta, n);
1.1       kristaps 1224: }
                   1225:
1.241     schwarze 1226: static void
                   1227: termp_fd_post(DECL_ARGS)
                   1228: {
                   1229:
                   1230:        term_newln(p);
                   1231: }
                   1232:
1.1       kristaps 1233: static int
                   1234: termp_sh_pre(DECL_ARGS)
                   1235: {
1.85      kristaps 1236:
1.86      kristaps 1237:        switch (n->type) {
1.314     schwarze 1238:        case ROFFT_BLOCK:
1.293     schwarze 1239:                /*
                   1240:                 * Vertical space before sections, except
                   1241:                 * when the previous section was empty.
                   1242:                 */
                   1243:                if (n->prev == NULL ||
1.322     schwarze 1244:                    n->prev->tok != MDOC_Sh ||
1.293     schwarze 1245:                    (n->prev->body != NULL &&
                   1246:                     n->prev->body->child != NULL))
                   1247:                        term_vspace(p);
1.65      kristaps 1248:                break;
1.314     schwarze 1249:        case ROFFT_HEAD:
1.102     kristaps 1250:                term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1251:                break;
1.314     schwarze 1252:        case ROFFT_BODY:
1.238     schwarze 1253:                p->offset = term_len(p, p->defindent);
1.356     schwarze 1254:                term_tab_set(p, NULL);
                   1255:                term_tab_set(p, "T");
                   1256:                term_tab_set(p, ".5i");
1.322     schwarze 1257:                switch (n->sec) {
                   1258:                case SEC_DESCRIPTION:
                   1259:                        fn_prio = 0;
                   1260:                        break;
                   1261:                case SEC_AUTHORS:
1.239     schwarze 1262:                        p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT);
1.322     schwarze 1263:                        break;
                   1264:                default:
                   1265:                        break;
                   1266:                }
1.1       kristaps 1267:                break;
                   1268:        default:
                   1269:                break;
                   1270:        }
1.328     schwarze 1271:        return 1;
1.1       kristaps 1272: }
                   1273:
                   1274: static void
                   1275: termp_sh_post(DECL_ARGS)
                   1276: {
                   1277:
1.86      kristaps 1278:        switch (n->type) {
1.314     schwarze 1279:        case ROFFT_HEAD:
1.1       kristaps 1280:                term_newln(p);
                   1281:                break;
1.314     schwarze 1282:        case ROFFT_BODY:
1.1       kristaps 1283:                term_newln(p);
                   1284:                p->offset = 0;
                   1285:                break;
                   1286:        default:
                   1287:                break;
                   1288:        }
                   1289: }
                   1290:
                   1291: static void
                   1292: termp_lb_post(DECL_ARGS)
                   1293: {
                   1294:
1.338     schwarze 1295:        if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags)
1.81      kristaps 1296:                term_newln(p);
1.1       kristaps 1297: }
                   1298:
                   1299: static int
                   1300: termp_d1_pre(DECL_ARGS)
                   1301: {
                   1302:
1.314     schwarze 1303:        if (n->type != ROFFT_BLOCK)
1.328     schwarze 1304:                return 1;
1.1       kristaps 1305:        term_newln(p);
1.238     schwarze 1306:        p->offset += term_len(p, p->defindent + 1);
1.356     schwarze 1307:        term_tab_set(p, NULL);
                   1308:        term_tab_set(p, "T");
                   1309:        term_tab_set(p, ".5i");
1.328     schwarze 1310:        return 1;
1.1       kristaps 1311: }
                   1312:
                   1313: static int
                   1314: termp_ft_pre(DECL_ARGS)
                   1315: {
                   1316:
1.338     schwarze 1317:        /* NB: NODE_LINE does not effect this! */
1.143     kristaps 1318:        synopsis_pre(p, n);
1.102     kristaps 1319:        term_fontpush(p, TERMFONT_UNDER);
1.328     schwarze 1320:        return 1;
1.1       kristaps 1321: }
                   1322:
                   1323: static int
                   1324: termp_fn_pre(DECL_ARGS)
                   1325: {
1.257     schwarze 1326:        size_t           rmargin = 0;
1.226     kristaps 1327:        int              pretty;
                   1328:
1.338     schwarze 1329:        pretty = NODE_SYNPRETTY & n->flags;
1.1       kristaps 1330:
1.143     kristaps 1331:        synopsis_pre(p, n);
1.139     kristaps 1332:
1.226     kristaps 1333:        if (NULL == (n = n->child))
1.328     schwarze 1334:                return 0;
1.226     kristaps 1335:
1.251     schwarze 1336:        if (pretty) {
                   1337:                rmargin = p->rmargin;
1.257     schwarze 1338:                p->rmargin = p->offset + term_len(p, 4);
1.263     schwarze 1339:                p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
1.251     schwarze 1340:        }
                   1341:
1.314     schwarze 1342:        assert(n->type == ROFFT_TEXT);
1.102     kristaps 1343:        term_fontpush(p, TERMFONT_BOLD);
1.226     kristaps 1344:        term_word(p, n->string);
1.102     kristaps 1345:        term_fontpop(p);
1.1       kristaps 1346:
1.336     schwarze 1347:        if (n->sec == SEC_DESCRIPTION || n->sec == SEC_CUSTOM)
1.324     schwarze 1348:                tag_put(n->string, ++fn_prio, p->line);
1.322     schwarze 1349:
1.251     schwarze 1350:        if (pretty) {
                   1351:                term_flushln(p);
1.263     schwarze 1352:                p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1.360     schwarze 1353:                p->flags |= TERMP_NOPAD;
1.251     schwarze 1354:                p->offset = p->rmargin;
                   1355:                p->rmargin = rmargin;
                   1356:        }
                   1357:
1.1       kristaps 1358:        p->flags |= TERMP_NOSPACE;
                   1359:        term_word(p, "(");
1.222     kristaps 1360:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1361:
1.226     kristaps 1362:        for (n = n->next; n; n = n->next) {
1.314     schwarze 1363:                assert(n->type == ROFFT_TEXT);
1.102     kristaps 1364:                term_fontpush(p, TERMFONT_UNDER);
1.255     schwarze 1365:                if (pretty)
                   1366:                        p->flags |= TERMP_NBRWORD;
1.226     kristaps 1367:                term_word(p, n->string);
1.102     kristaps 1368:                term_fontpop(p);
                   1369:
1.226     kristaps 1370:                if (n->next) {
1.222     kristaps 1371:                        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1372:                        term_word(p, ",");
1.222     kristaps 1373:                }
1.1       kristaps 1374:        }
                   1375:
1.222     kristaps 1376:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1377:        term_word(p, ")");
                   1378:
1.226     kristaps 1379:        if (pretty) {
1.222     kristaps 1380:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1381:                term_word(p, ";");
1.251     schwarze 1382:                term_flushln(p);
1.222     kristaps 1383:        }
1.1       kristaps 1384:
1.328     schwarze 1385:        return 0;
1.1       kristaps 1386: }
                   1387:
                   1388: static int
                   1389: termp_fa_pre(DECL_ARGS)
                   1390: {
1.315     schwarze 1391:        const struct roff_node  *nn;
1.1       kristaps 1392:
1.86      kristaps 1393:        if (n->parent->tok != MDOC_Fo) {
1.102     kristaps 1394:                term_fontpush(p, TERMFONT_UNDER);
1.328     schwarze 1395:                return 1;
1.1       kristaps 1396:        }
                   1397:
1.86      kristaps 1398:        for (nn = n->child; nn; nn = nn->next) {
1.102     kristaps 1399:                term_fontpush(p, TERMFONT_UNDER);
1.258     schwarze 1400:                p->flags |= TERMP_NBRWORD;
1.86      kristaps 1401:                term_word(p, nn->string);
1.102     kristaps 1402:                term_fontpop(p);
                   1403:
1.256     schwarze 1404:                if (nn->next || (n->next && n->next->tok == MDOC_Fa)) {
1.222     kristaps 1405:                        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1406:                        term_word(p, ",");
1.222     kristaps 1407:                }
1.1       kristaps 1408:        }
                   1409:
1.328     schwarze 1410:        return 0;
1.1       kristaps 1411: }
                   1412:
                   1413: static int
                   1414: termp_bd_pre(DECL_ARGS)
                   1415: {
1.361   ! schwarze 1416:        size_t                   lm, len;
1.315     schwarze 1417:        struct roff_node        *nn;
1.302     schwarze 1418:        int                      offset;
1.1       kristaps 1419:
1.314     schwarze 1420:        if (n->type == ROFFT_BLOCK) {
1.151     kristaps 1421:                print_bvspace(p, n, n);
1.328     schwarze 1422:                return 1;
1.314     schwarze 1423:        } else if (n->type == ROFFT_HEAD)
1.328     schwarze 1424:                return 0;
1.1       kristaps 1425:
1.288     schwarze 1426:        /* Handle the -offset argument. */
                   1427:
                   1428:        if (n->norm->Bd.offs == NULL ||
                   1429:            ! strcmp(n->norm->Bd.offs, "left"))
                   1430:                /* nothing */;
                   1431:        else if ( ! strcmp(n->norm->Bd.offs, "indent"))
                   1432:                p->offset += term_len(p, p->defindent + 1);
                   1433:        else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
                   1434:                p->offset += term_len(p, (p->defindent + 1) * 2);
1.302     schwarze 1435:        else {
                   1436:                offset = a2width(p, n->norm->Bd.offs);
                   1437:                if (offset < 0 && (size_t)(-offset) > p->offset)
                   1438:                        p->offset = 0;
                   1439:                else if (offset < SHRT_MAX)
                   1440:                        p->offset += offset;
                   1441:        }
1.85      kristaps 1442:
                   1443:        /*
                   1444:         * If -ragged or -filled are specified, the block does nothing
                   1445:         * but change the indentation.  If -unfilled or -literal are
                   1446:         * specified, text is printed exactly as entered in the display:
                   1447:         * for macro lines, a newline is appended to the line.  Blank
                   1448:         * lines are allowed.
                   1449:         */
1.264     schwarze 1450:
                   1451:        if (DISP_literal != n->norm->Bd.type &&
1.272     schwarze 1452:            DISP_unfilled != n->norm->Bd.type &&
                   1453:            DISP_centered != n->norm->Bd.type)
1.328     schwarze 1454:                return 1;
1.1       kristaps 1455:
1.356     schwarze 1456:        if (n->norm->Bd.type == DISP_literal) {
                   1457:                term_tab_set(p, NULL);
                   1458:                term_tab_set(p, "T");
                   1459:                term_tab_set(p, "8n");
                   1460:        }
1.208     kristaps 1461:
1.272     schwarze 1462:        lm = p->offset;
1.361   ! schwarze 1463:        p->flags |= TERMP_BRNEVER;
1.86      kristaps 1464:        for (nn = n->child; nn; nn = nn->next) {
1.272     schwarze 1465:                if (DISP_centered == n->norm->Bd.type) {
1.314     schwarze 1466:                        if (nn->type == ROFFT_TEXT) {
1.272     schwarze 1467:                                len = term_strlen(p, nn->string);
1.361   ! schwarze 1468:                                p->offset = len >= p->rmargin ? 0 :
        !          1469:                                    lm + len >= p->rmargin ? p->rmargin - len :
        !          1470:                                    (lm + p->rmargin - len) / 2;
1.272     schwarze 1471:                        } else
                   1472:                                p->offset = lm;
                   1473:                }
1.245     schwarze 1474:                print_mdoc_node(p, pair, meta, nn);
1.190     kristaps 1475:                /*
                   1476:                 * If the printed node flushes its own line, then we
                   1477:                 * needn't do it here as well.  This is hacky, but the
                   1478:                 * notion of selective eoln whitespace is pretty dumb
                   1479:                 * anyway, so don't sweat it.
                   1480:                 */
1.356     schwarze 1481:                if (nn->tok < ROFF_MAX)
                   1482:                        continue;
1.190     kristaps 1483:                switch (nn->tok) {
1.264     schwarze 1484:                case MDOC_Sm:
                   1485:                case MDOC_Bl:
                   1486:                case MDOC_D1:
                   1487:                case MDOC_Dl:
                   1488:                case MDOC_Lp:
                   1489:                case MDOC_Pp:
1.190     kristaps 1490:                        continue;
                   1491:                default:
                   1492:                        break;
                   1493:                }
1.299     schwarze 1494:                if (p->flags & TERMP_NONEWLINE ||
1.338     schwarze 1495:                    (nn->next && ! (nn->next->flags & NODE_LINE)))
1.180     schwarze 1496:                        continue;
                   1497:                term_flushln(p);
                   1498:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1499:        }
1.361   ! schwarze 1500:        p->flags &= ~TERMP_BRNEVER;
1.328     schwarze 1501:        return 0;
1.1       kristaps 1502: }
                   1503:
                   1504: static void
                   1505: termp_bd_post(DECL_ARGS)
                   1506: {
1.314     schwarze 1507:        if (n->type != ROFFT_BODY)
1.1       kristaps 1508:                return;
1.264     schwarze 1509:        if (DISP_literal == n->norm->Bd.type ||
                   1510:            DISP_unfilled == n->norm->Bd.type)
1.361   ! schwarze 1511:                p->flags |= TERMP_BRNEVER;
1.60      kristaps 1512:        p->flags |= TERMP_NOSPACE;
1.130     schwarze 1513:        term_newln(p);
1.361   ! schwarze 1514:        p->flags &= ~TERMP_BRNEVER;
1.1       kristaps 1515: }
                   1516:
                   1517: static int
1.26      kristaps 1518: termp_xx_pre(DECL_ARGS)
1.1       kristaps 1519: {
1.339     schwarze 1520:        if ((n->aux = p->flags & TERMP_PREKEEP) == 0)
                   1521:                p->flags |= TERMP_PREKEEP;
                   1522:        return 1;
                   1523: }
1.1       kristaps 1524:
1.339     schwarze 1525: static void
                   1526: termp_xx_post(DECL_ARGS)
                   1527: {
                   1528:        if (n->aux == 0)
                   1529:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.1       kristaps 1530: }
                   1531:
                   1532: static void
                   1533: termp_pf_post(DECL_ARGS)
                   1534: {
                   1535:
1.338     schwarze 1536:        if ( ! (n->next == NULL || n->next->flags & NODE_LINE))
1.298     schwarze 1537:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1538: }
                   1539:
                   1540: static int
                   1541: termp_ss_pre(DECL_ARGS)
                   1542: {
1.337     schwarze 1543:        struct roff_node *nn;
1.1       kristaps 1544:
1.86      kristaps 1545:        switch (n->type) {
1.314     schwarze 1546:        case ROFFT_BLOCK:
1.1       kristaps 1547:                term_newln(p);
1.337     schwarze 1548:                for (nn = n->prev; nn != NULL; nn = nn->prev)
                   1549:                        if ((nn->flags & NODE_NOPRT) == 0)
                   1550:                                break;
                   1551:                if (nn != NULL)
1.1       kristaps 1552:                        term_vspace(p);
                   1553:                break;
1.314     schwarze 1554:        case ROFFT_HEAD:
1.102     kristaps 1555:                term_fontpush(p, TERMFONT_BOLD);
1.238     schwarze 1556:                p->offset = term_len(p, (p->defindent+1)/2);
1.1       kristaps 1557:                break;
1.314     schwarze 1558:        case ROFFT_BODY:
1.274     schwarze 1559:                p->offset = term_len(p, p->defindent);
1.356     schwarze 1560:                term_tab_set(p, NULL);
                   1561:                term_tab_set(p, "T");
                   1562:                term_tab_set(p, ".5i");
1.274     schwarze 1563:                break;
1.1       kristaps 1564:        default:
                   1565:                break;
                   1566:        }
                   1567:
1.328     schwarze 1568:        return 1;
1.1       kristaps 1569: }
                   1570:
                   1571: static void
                   1572: termp_ss_post(DECL_ARGS)
                   1573: {
                   1574:
1.314     schwarze 1575:        if (n->type == ROFFT_HEAD || n->type == ROFFT_BODY)
1.1       kristaps 1576:                term_newln(p);
                   1577: }
                   1578:
                   1579: static int
                   1580: termp_cd_pre(DECL_ARGS)
                   1581: {
                   1582:
1.143     kristaps 1583:        synopsis_pre(p, n);
1.102     kristaps 1584:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze 1585:        return 1;
1.1       kristaps 1586: }
                   1587:
                   1588: static int
                   1589: termp_in_pre(DECL_ARGS)
                   1590: {
1.142     schwarze 1591:
1.143     kristaps 1592:        synopsis_pre(p, n);
1.1       kristaps 1593:
1.338     schwarze 1594:        if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags) {
1.138     kristaps 1595:                term_fontpush(p, TERMFONT_BOLD);
1.22      kristaps 1596:                term_word(p, "#include");
1.138     kristaps 1597:                term_word(p, "<");
                   1598:        } else {
                   1599:                term_word(p, "<");
                   1600:                term_fontpush(p, TERMFONT_UNDER);
                   1601:        }
1.22      kristaps 1602:
1.1       kristaps 1603:        p->flags |= TERMP_NOSPACE;
1.328     schwarze 1604:        return 1;
1.1       kristaps 1605: }
                   1606:
                   1607: static void
                   1608: termp_in_post(DECL_ARGS)
                   1609: {
                   1610:
1.338     schwarze 1611:        if (NODE_SYNPRETTY & n->flags)
1.138     kristaps 1612:                term_fontpush(p, TERMFONT_BOLD);
                   1613:
1.79      kristaps 1614:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1615:        term_word(p, ">");
                   1616:
1.338     schwarze 1617:        if (NODE_SYNPRETTY & n->flags)
1.138     kristaps 1618:                term_fontpop(p);
1.1       kristaps 1619: }
                   1620:
                   1621: static int
1.355     schwarze 1622: termp_pp_pre(DECL_ARGS)
1.45      kristaps 1623: {
1.355     schwarze 1624:        fn_prio = 0;
                   1625:        term_vspace(p);
1.328     schwarze 1626:        return 0;
1.45      kristaps 1627: }
                   1628:
                   1629: static int
1.294     schwarze 1630: termp_skip_pre(DECL_ARGS)
1.268     schwarze 1631: {
                   1632:
1.328     schwarze 1633:        return 0;
1.268     schwarze 1634: }
                   1635:
                   1636: static int
1.188     kristaps 1637: termp_quote_pre(DECL_ARGS)
1.1       kristaps 1638: {
                   1639:
1.314     schwarze 1640:        if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1.328     schwarze 1641:                return 1;
1.1       kristaps 1642:
1.188     kristaps 1643:        switch (n->tok) {
1.264     schwarze 1644:        case MDOC_Ao:
                   1645:        case MDOC_Aq:
1.331     schwarze 1646:                term_word(p, n->child != NULL && n->child->next == NULL &&
1.303     schwarze 1647:                    n->child->tok == MDOC_Mt ? "<" : "\\(la");
1.188     kristaps 1648:                break;
1.264     schwarze 1649:        case MDOC_Bro:
                   1650:        case MDOC_Brq:
1.188     kristaps 1651:                term_word(p, "{");
                   1652:                break;
1.264     schwarze 1653:        case MDOC_Oo:
                   1654:        case MDOC_Op:
                   1655:        case MDOC_Bo:
                   1656:        case MDOC_Bq:
1.188     kristaps 1657:                term_word(p, "[");
                   1658:                break;
1.346     schwarze 1659:        case MDOC__T:
                   1660:                /* FALLTHROUGH */
1.264     schwarze 1661:        case MDOC_Do:
                   1662:        case MDOC_Dq:
1.311     schwarze 1663:                term_word(p, "\\(Lq");
1.188     kristaps 1664:                break;
1.268     schwarze 1665:        case MDOC_En:
                   1666:                if (NULL == n->norm->Es ||
                   1667:                    NULL == n->norm->Es->child)
1.328     schwarze 1668:                        return 1;
1.268     schwarze 1669:                term_word(p, n->norm->Es->child->string);
                   1670:                break;
1.264     schwarze 1671:        case MDOC_Po:
                   1672:        case MDOC_Pq:
1.188     kristaps 1673:                term_word(p, "(");
                   1674:                break;
1.264     schwarze 1675:        case MDOC_Qo:
                   1676:        case MDOC_Qq:
1.188     kristaps 1677:                term_word(p, "\"");
                   1678:                break;
1.264     schwarze 1679:        case MDOC_Ql:
                   1680:        case MDOC_So:
                   1681:        case MDOC_Sq:
1.249     schwarze 1682:                term_word(p, "\\(oq");
1.188     kristaps 1683:                break;
                   1684:        default:
                   1685:                abort();
                   1686:        }
1.1       kristaps 1687:
                   1688:        p->flags |= TERMP_NOSPACE;
1.328     schwarze 1689:        return 1;
1.1       kristaps 1690: }
                   1691:
                   1692: static void
1.188     kristaps 1693: termp_quote_post(DECL_ARGS)
1.1       kristaps 1694: {
                   1695:
1.314     schwarze 1696:        if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1.1       kristaps 1697:                return;
                   1698:
1.306     schwarze 1699:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1700:
1.188     kristaps 1701:        switch (n->tok) {
1.264     schwarze 1702:        case MDOC_Ao:
                   1703:        case MDOC_Aq:
1.331     schwarze 1704:                term_word(p, n->child != NULL && n->child->next == NULL &&
1.303     schwarze 1705:                    n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1.188     kristaps 1706:                break;
1.264     schwarze 1707:        case MDOC_Bro:
                   1708:        case MDOC_Brq:
1.188     kristaps 1709:                term_word(p, "}");
                   1710:                break;
1.264     schwarze 1711:        case MDOC_Oo:
                   1712:        case MDOC_Op:
                   1713:        case MDOC_Bo:
                   1714:        case MDOC_Bq:
1.188     kristaps 1715:                term_word(p, "]");
                   1716:                break;
1.346     schwarze 1717:        case MDOC__T:
                   1718:                /* FALLTHROUGH */
1.264     schwarze 1719:        case MDOC_Do:
                   1720:        case MDOC_Dq:
1.311     schwarze 1721:                term_word(p, "\\(Rq");
1.268     schwarze 1722:                break;
                   1723:        case MDOC_En:
1.306     schwarze 1724:                if (n->norm->Es == NULL ||
                   1725:                    n->norm->Es->child == NULL ||
                   1726:                    n->norm->Es->child->next == NULL)
                   1727:                        p->flags &= ~TERMP_NOSPACE;
                   1728:                else
1.268     schwarze 1729:                        term_word(p, n->norm->Es->child->next->string);
1.188     kristaps 1730:                break;
1.264     schwarze 1731:        case MDOC_Po:
                   1732:        case MDOC_Pq:
1.188     kristaps 1733:                term_word(p, ")");
                   1734:                break;
1.264     schwarze 1735:        case MDOC_Qo:
                   1736:        case MDOC_Qq:
1.188     kristaps 1737:                term_word(p, "\"");
                   1738:                break;
1.264     schwarze 1739:        case MDOC_Ql:
                   1740:        case MDOC_So:
                   1741:        case MDOC_Sq:
1.249     schwarze 1742:                term_word(p, "\\(cq");
1.188     kristaps 1743:                break;
                   1744:        default:
                   1745:                abort();
                   1746:        }
1.306     schwarze 1747: }
                   1748:
                   1749: static int
                   1750: termp_eo_pre(DECL_ARGS)
                   1751: {
                   1752:
1.314     schwarze 1753:        if (n->type != ROFFT_BODY)
1.328     schwarze 1754:                return 1;
1.306     schwarze 1755:
                   1756:        if (n->end == ENDBODY_NOT &&
                   1757:            n->parent->head->child == NULL &&
                   1758:            n->child != NULL &&
                   1759:            n->child->end != ENDBODY_NOT)
                   1760:                term_word(p, "\\&");
                   1761:        else if (n->end != ENDBODY_NOT ? n->child != NULL :
1.309     schwarze 1762:             n->parent->head->child != NULL && (n->child != NULL ||
                   1763:             (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1.306     schwarze 1764:                p->flags |= TERMP_NOSPACE;
                   1765:
1.328     schwarze 1766:        return 1;
1.306     schwarze 1767: }
                   1768:
                   1769: static void
                   1770: termp_eo_post(DECL_ARGS)
                   1771: {
                   1772:        int      body, tail;
                   1773:
1.314     schwarze 1774:        if (n->type != ROFFT_BODY)
1.306     schwarze 1775:                return;
                   1776:
                   1777:        if (n->end != ENDBODY_NOT) {
                   1778:                p->flags &= ~TERMP_NOSPACE;
                   1779:                return;
                   1780:        }
                   1781:
                   1782:        body = n->child != NULL || n->parent->head->child != NULL;
                   1783:        tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
                   1784:
                   1785:        if (body && tail)
                   1786:                p->flags |= TERMP_NOSPACE;
                   1787:        else if ( ! (body || tail))
                   1788:                term_word(p, "\\&");
                   1789:        else if ( ! tail)
                   1790:                p->flags &= ~TERMP_NOSPACE;
1.1       kristaps 1791: }
                   1792:
                   1793: static int
                   1794: termp_fo_pre(DECL_ARGS)
                   1795: {
1.257     schwarze 1796:        size_t           rmargin = 0;
1.256     schwarze 1797:        int              pretty;
                   1798:
1.338     schwarze 1799:        pretty = NODE_SYNPRETTY & n->flags;
1.1       kristaps 1800:
1.314     schwarze 1801:        if (n->type == ROFFT_BLOCK) {
1.143     kristaps 1802:                synopsis_pre(p, n);
1.328     schwarze 1803:                return 1;
1.314     schwarze 1804:        } else if (n->type == ROFFT_BODY) {
1.256     schwarze 1805:                if (pretty) {
                   1806:                        rmargin = p->rmargin;
1.257     schwarze 1807:                        p->rmargin = p->offset + term_len(p, 4);
1.263     schwarze 1808:                        p->flags |= TERMP_NOBREAK | TERMP_BRIND |
                   1809:                                        TERMP_HANG;
1.256     schwarze 1810:                }
1.33      kristaps 1811:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1812:                term_word(p, "(");
1.222     kristaps 1813:                p->flags |= TERMP_NOSPACE;
1.256     schwarze 1814:                if (pretty) {
                   1815:                        term_flushln(p);
1.263     schwarze 1816:                        p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
                   1817:                                        TERMP_HANG);
1.360     schwarze 1818:                        p->flags |= TERMP_NOPAD;
1.256     schwarze 1819:                        p->offset = p->rmargin;
                   1820:                        p->rmargin = rmargin;
                   1821:                }
1.328     schwarze 1822:                return 1;
1.256     schwarze 1823:        }
1.141     kristaps 1824:
1.169     kristaps 1825:        if (NULL == n->child)
1.328     schwarze 1826:                return 0;
1.169     kristaps 1827:
1.141     kristaps 1828:        /* XXX: we drop non-initial arguments as per groff. */
1.1       kristaps 1829:
1.141     kristaps 1830:        assert(n->child->string);
1.102     kristaps 1831:        term_fontpush(p, TERMFONT_BOLD);
1.141     kristaps 1832:        term_word(p, n->child->string);
1.328     schwarze 1833:        return 0;
1.1       kristaps 1834: }
                   1835:
                   1836: static void
                   1837: termp_fo_post(DECL_ARGS)
                   1838: {
                   1839:
1.314     schwarze 1840:        if (n->type != ROFFT_BODY)
1.143     kristaps 1841:                return;
                   1842:
1.222     kristaps 1843:        p->flags |= TERMP_NOSPACE;
1.143     kristaps 1844:        term_word(p, ")");
                   1845:
1.338     schwarze 1846:        if (NODE_SYNPRETTY & n->flags) {
1.222     kristaps 1847:                p->flags |= TERMP_NOSPACE;
1.143     kristaps 1848:                term_word(p, ";");
1.256     schwarze 1849:                term_flushln(p);
1.222     kristaps 1850:        }
1.1       kristaps 1851: }
                   1852:
                   1853: static int
                   1854: termp_bf_pre(DECL_ARGS)
                   1855: {
                   1856:
1.314     schwarze 1857:        if (n->type == ROFFT_HEAD)
1.328     schwarze 1858:                return 0;
1.314     schwarze 1859:        else if (n->type != ROFFT_BODY)
1.328     schwarze 1860:                return 1;
1.1       kristaps 1861:
1.264     schwarze 1862:        if (FONT_Em == n->norm->Bf.font)
1.102     kristaps 1863:                term_fontpush(p, TERMFONT_UNDER);
1.264     schwarze 1864:        else if (FONT_Sy == n->norm->Bf.font)
1.102     kristaps 1865:                term_fontpush(p, TERMFONT_BOLD);
1.264     schwarze 1866:        else
1.102     kristaps 1867:                term_fontpush(p, TERMFONT_NONE);
1.1       kristaps 1868:
1.328     schwarze 1869:        return 1;
1.1       kristaps 1870: }
                   1871:
                   1872: static int
                   1873: termp_sm_pre(DECL_ARGS)
                   1874: {
                   1875:
1.269     schwarze 1876:        if (NULL == n->child)
                   1877:                p->flags ^= TERMP_NONOSPACE;
                   1878:        else if (0 == strcmp("on", n->child->string))
1.1       kristaps 1879:                p->flags &= ~TERMP_NONOSPACE;
1.269     schwarze 1880:        else
1.1       kristaps 1881:                p->flags |= TERMP_NONOSPACE;
1.269     schwarze 1882:
                   1883:        if (p->col && ! (TERMP_NONOSPACE & p->flags))
                   1884:                p->flags &= ~TERMP_NOSPACE;
1.1       kristaps 1885:
1.328     schwarze 1886:        return 0;
1.1       kristaps 1887: }
                   1888:
                   1889: static int
                   1890: termp_ap_pre(DECL_ARGS)
                   1891: {
                   1892:
                   1893:        p->flags |= TERMP_NOSPACE;
1.188     kristaps 1894:        term_word(p, "'");
1.1       kristaps 1895:        p->flags |= TERMP_NOSPACE;
1.328     schwarze 1896:        return 1;
1.1       kristaps 1897: }
                   1898:
                   1899: static void
                   1900: termp____post(DECL_ARGS)
                   1901: {
1.184     kristaps 1902:
                   1903:        /*
                   1904:         * Handle lists of authors.  In general, print each followed by
                   1905:         * a comma.  Don't print the comma if there are only two
                   1906:         * authors.
                   1907:         */
                   1908:        if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
                   1909:                if (NULL == n->next->next || MDOC__A != n->next->next->tok)
                   1910:                        if (NULL == n->prev || MDOC__A != n->prev->tok)
                   1911:                                return;
1.1       kristaps 1912:
1.95      kristaps 1913:        /* TODO: %U. */
                   1914:
1.187     kristaps 1915:        if (NULL == n->parent || MDOC_Rs != n->parent->tok)
                   1916:                return;
                   1917:
1.222     kristaps 1918:        p->flags |= TERMP_NOSPACE;
1.186     kristaps 1919:        if (NULL == n->next) {
                   1920:                term_word(p, ".");
                   1921:                p->flags |= TERMP_SENTENCE;
                   1922:        } else
                   1923:                term_word(p, ",");
1.1       kristaps 1924: }
                   1925:
                   1926: static int
1.102     kristaps 1927: termp_li_pre(DECL_ARGS)
                   1928: {
                   1929:
1.335     schwarze 1930:        termp_tag_pre(p, pair, meta, n);
1.102     kristaps 1931:        term_fontpush(p, TERMFONT_NONE);
1.328     schwarze 1932:        return 1;
1.102     kristaps 1933: }
                   1934:
                   1935: static int
1.1       kristaps 1936: termp_lk_pre(DECL_ARGS)
                   1937: {
1.358     schwarze 1938:        const struct roff_node *link, *descr, *punct;
1.348     schwarze 1939:        int display;
1.1       kristaps 1940:
1.349     schwarze 1941:        if ((link = n->child) == NULL)
1.328     schwarze 1942:                return 0;
1.181     kristaps 1943:
1.358     schwarze 1944:        /* Find beginning of trailing punctuation. */
                   1945:        punct = n->last;
                   1946:        while (punct != link && punct->flags & NODE_DELIMC)
                   1947:                punct = punct->prev;
                   1948:        punct = punct->next;
                   1949:
1.349     schwarze 1950:        /* Link text. */
1.358     schwarze 1951:        if ((descr = link->next) != NULL && descr != punct) {
1.240     schwarze 1952:                term_fontpush(p, TERMFONT_UNDER);
1.358     schwarze 1953:                while (descr != punct) {
                   1954:                        if (descr->flags & (NODE_DELIMC | NODE_DELIMO))
                   1955:                                p->flags |= TERMP_NOSPACE;
1.240     schwarze 1956:                        term_word(p, descr->string);
                   1957:                        descr = descr->next;
                   1958:                }
1.347     schwarze 1959:                term_fontpop(p);
1.240     schwarze 1960:                p->flags |= TERMP_NOSPACE;
                   1961:                term_word(p, ":");
                   1962:        }
1.1       kristaps 1963:
1.349     schwarze 1964:        /* Link target. */
1.348     schwarze 1965:        display = term_strlen(p, link->string) >= 26;
                   1966:        if (display) {
                   1967:                term_newln(p);
                   1968:                p->offset += term_len(p, p->defindent + 1);
                   1969:        }
1.102     kristaps 1970:        term_fontpush(p, TERMFONT_BOLD);
1.240     schwarze 1971:        term_word(p, link->string);
1.102     kristaps 1972:        term_fontpop(p);
1.348     schwarze 1973:
1.349     schwarze 1974:        /* Trailing punctuation. */
1.358     schwarze 1975:        while (punct != NULL) {
1.349     schwarze 1976:                p->flags |= TERMP_NOSPACE;
1.358     schwarze 1977:                term_word(p, punct->string);
                   1978:                punct = punct->next;
1.349     schwarze 1979:        }
1.348     schwarze 1980:        if (display)
                   1981:                term_newln(p);
1.328     schwarze 1982:        return 0;
1.1       kristaps 1983: }
                   1984:
1.159     schwarze 1985: static int
                   1986: termp_bk_pre(DECL_ARGS)
                   1987: {
                   1988:
1.161     schwarze 1989:        switch (n->type) {
1.314     schwarze 1990:        case ROFFT_BLOCK:
1.166     kristaps 1991:                break;
1.314     schwarze 1992:        case ROFFT_HEAD:
1.328     schwarze 1993:                return 0;
1.314     schwarze 1994:        case ROFFT_BODY:
1.331     schwarze 1995:                if (n->parent->args != NULL || n->prev->child == NULL)
1.200     schwarze 1996:                        p->flags |= TERMP_PREKEEP;
1.166     kristaps 1997:                break;
1.161     schwarze 1998:        default:
                   1999:                abort();
                   2000:        }
1.166     kristaps 2001:
1.328     schwarze 2002:        return 1;
1.159     schwarze 2003: }
                   2004:
                   2005: static void
                   2006: termp_bk_post(DECL_ARGS)
                   2007: {
                   2008:
1.314     schwarze 2009:        if (n->type == ROFFT_BODY)
1.161     schwarze 2010:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.203     kristaps 2011: }
                   2012:
                   2013: static void
                   2014: termp__t_post(DECL_ARGS)
                   2015: {
                   2016:
                   2017:        /*
                   2018:         * If we're in an `Rs' and there's a journal present, then quote
                   2019:         * us instead of underlining us (for disambiguation).
                   2020:         */
1.217     schwarze 2021:        if (n->parent && MDOC_Rs == n->parent->tok &&
1.264     schwarze 2022:            n->parent->norm->Rs.quote_T)
1.245     schwarze 2023:                termp_quote_post(p, pair, meta, n);
1.203     kristaps 2024:
1.245     schwarze 2025:        termp____post(p, pair, meta, n);
1.203     kristaps 2026: }
                   2027:
                   2028: static int
                   2029: termp__t_pre(DECL_ARGS)
                   2030: {
                   2031:
                   2032:        /*
                   2033:         * If we're in an `Rs' and there's a journal present, then quote
                   2034:         * us instead of underlining us (for disambiguation).
                   2035:         */
                   2036:        if (n->parent && MDOC_Rs == n->parent->tok &&
1.264     schwarze 2037:            n->parent->norm->Rs.quote_T)
1.328     schwarze 2038:                return termp_quote_pre(p, pair, meta, n);
1.203     kristaps 2039:
                   2040:        term_fontpush(p, TERMFONT_UNDER);
1.328     schwarze 2041:        return 1;
1.159     schwarze 2042: }
1.1       kristaps 2043:
                   2044: static int
1.69      kristaps 2045: termp_under_pre(DECL_ARGS)
1.1       kristaps 2046: {
                   2047:
1.102     kristaps 2048:        term_fontpush(p, TERMFONT_UNDER);
1.334     schwarze 2049:        return 1;
                   2050: }
                   2051:
                   2052: static int
                   2053: termp_em_pre(DECL_ARGS)
                   2054: {
                   2055:        if (n->child != NULL &&
                   2056:            n->child->type == ROFFT_TEXT)
                   2057:                tag_put(n->child->string, 0, p->line);
                   2058:        term_fontpush(p, TERMFONT_UNDER);
                   2059:        return 1;
                   2060: }
                   2061:
                   2062: static int
                   2063: termp_sy_pre(DECL_ARGS)
                   2064: {
                   2065:        if (n->child != NULL &&
                   2066:            n->child->type == ROFFT_TEXT)
                   2067:                tag_put(n->child->string, 0, p->line);
                   2068:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze 2069:        return 1;
1.323     schwarze 2070: }
                   2071:
                   2072: static int
                   2073: termp_er_pre(DECL_ARGS)
                   2074: {
                   2075:
                   2076:        if (n->sec == SEC_ERRORS &&
                   2077:            (n->parent->tok == MDOC_It ||
                   2078:             (n->parent->tok == MDOC_Bq &&
1.324     schwarze 2079:              n->parent->parent->parent->tok == MDOC_It)))
                   2080:                tag_put(n->child->string, 1, p->line);
1.328     schwarze 2081:        return 1;
1.320     schwarze 2082: }
                   2083:
                   2084: static int
                   2085: termp_tag_pre(DECL_ARGS)
                   2086: {
                   2087:
                   2088:        if (n->child != NULL &&
                   2089:            n->child->type == ROFFT_TEXT &&
1.333     schwarze 2090:            (n->prev == NULL ||
                   2091:             (n->prev->type == ROFFT_TEXT &&
                   2092:              strcmp(n->prev->string, "|") == 0)) &&
1.320     schwarze 2093:            (n->parent->tok == MDOC_It ||
                   2094:             (n->parent->tok == MDOC_Xo &&
                   2095:              n->parent->parent->prev == NULL &&
1.324     schwarze 2096:              n->parent->parent->parent->tok == MDOC_It)))
                   2097:                tag_put(n->child->string, 1, p->line);
1.328     schwarze 2098:        return 1;
1.84      kristaps 2099: }

CVSweb