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

Annotation of mandoc/mdoc_term.c, Revision 1.374

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

CVSweb