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

Annotation of mandoc/mdoc_term.c, Revision 1.365

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

CVSweb