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

Annotation of mandoc/mdoc_term.c, Revision 1.377

1.377   ! schwarze    1: /*     $Id: mdoc_term.c,v 1.376 2020/01/20 10:37:15 schwarze Exp $ */
1.1       kristaps    2: /*
1.217     schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.375     schwarze    4:  * Copyright (c) 2010, 2012-2020 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.377   ! schwarze   57:                        struct roff_node *, struct roff_node *);
1.264     schwarze   58: static void      print_mdoc_node(DECL_ARGS);
1.145     kristaps   59: static void      print_mdoc_nodelist(DECL_ARGS);
1.316     schwarze   60: static void      print_mdoc_head(struct termp *, const struct roff_meta *);
                     61: static void      print_mdoc_foot(struct termp *, const struct roff_meta *);
1.377   ! schwarze   62: static void      synopsis_pre(struct termp *, struct roff_node *);
1.96      kristaps   63:
1.31      kristaps   64: static void      termp____post(DECL_ARGS);
1.203     kristaps   65: static void      termp__t_post(DECL_ARGS);
1.31      kristaps   66: static void      termp_bd_post(DECL_ARGS);
1.159     schwarze   67: static void      termp_bk_post(DECL_ARGS);
1.31      kristaps   68: static void      termp_bl_post(DECL_ARGS);
1.306     schwarze   69: static void      termp_eo_post(DECL_ARGS);
1.241     schwarze   70: static void      termp_fd_post(DECL_ARGS);
1.31      kristaps   71: static void      termp_fo_post(DECL_ARGS);
                     72: static void      termp_in_post(DECL_ARGS);
                     73: static void      termp_it_post(DECL_ARGS);
                     74: static void      termp_lb_post(DECL_ARGS);
1.164     schwarze   75: static void      termp_nm_post(DECL_ARGS);
1.31      kristaps   76: static void      termp_pf_post(DECL_ARGS);
1.188     kristaps   77: static void      termp_quote_post(DECL_ARGS);
1.31      kristaps   78: static void      termp_sh_post(DECL_ARGS);
                     79: static void      termp_ss_post(DECL_ARGS);
1.339     schwarze   80: static void      termp_xx_post(DECL_ARGS);
1.31      kristaps   81:
1.184     kristaps   82: static int       termp__a_pre(DECL_ARGS);
1.203     kristaps   83: static int       termp__t_pre(DECL_ARGS);
1.369     schwarze   84: static int       termp_abort_pre(DECL_ARGS);
1.61      kristaps   85: static int       termp_an_pre(DECL_ARGS);
1.31      kristaps   86: static int       termp_ap_pre(DECL_ARGS);
                     87: static int       termp_bd_pre(DECL_ARGS);
                     88: static int       termp_bf_pre(DECL_ARGS);
1.159     schwarze   89: static int       termp_bk_pre(DECL_ARGS);
1.115     kristaps   90: static int       termp_bl_pre(DECL_ARGS);
1.69      kristaps   91: static int       termp_bold_pre(DECL_ARGS);
1.31      kristaps   92: static int       termp_cd_pre(DECL_ARGS);
                     93: static int       termp_d1_pre(DECL_ARGS);
1.306     schwarze   94: static int       termp_eo_pre(DECL_ARGS);
1.334     schwarze   95: static int       termp_em_pre(DECL_ARGS);
1.323     schwarze   96: static int       termp_er_pre(DECL_ARGS);
1.31      kristaps   97: static int       termp_ex_pre(DECL_ARGS);
                     98: static int       termp_fa_pre(DECL_ARGS);
1.188     kristaps   99: static int       termp_fd_pre(DECL_ARGS);
1.31      kristaps  100: static int       termp_fl_pre(DECL_ARGS);
                    101: static int       termp_fn_pre(DECL_ARGS);
                    102: static int       termp_fo_pre(DECL_ARGS);
                    103: static int       termp_ft_pre(DECL_ARGS);
                    104: static int       termp_in_pre(DECL_ARGS);
                    105: static int       termp_it_pre(DECL_ARGS);
1.102     kristaps  106: static int       termp_li_pre(DECL_ARGS);
1.31      kristaps  107: static int       termp_lk_pre(DECL_ARGS);
                    108: static int       termp_nd_pre(DECL_ARGS);
                    109: static int       termp_nm_pre(DECL_ARGS);
                    110: static int       termp_ns_pre(DECL_ARGS);
1.188     kristaps  111: static int       termp_quote_pre(DECL_ARGS);
1.31      kristaps  112: static int       termp_rs_pre(DECL_ARGS);
                    113: static int       termp_sh_pre(DECL_ARGS);
1.294     schwarze  114: static int       termp_skip_pre(DECL_ARGS);
1.31      kristaps  115: static int       termp_sm_pre(DECL_ARGS);
1.355     schwarze  116: static int       termp_pp_pre(DECL_ARGS);
1.31      kristaps  117: static int       termp_ss_pre(DECL_ARGS);
1.334     schwarze  118: static int       termp_sy_pre(DECL_ARGS);
1.320     schwarze  119: static int       termp_tag_pre(DECL_ARGS);
1.375     schwarze  120: static int       termp_tg_pre(DECL_ARGS);
1.69      kristaps  121: static int       termp_under_pre(DECL_ARGS);
1.110     kristaps  122: static int       termp_vt_pre(DECL_ARGS);
1.31      kristaps  123: static int       termp_xr_pre(DECL_ARGS);
                    124: static int       termp_xx_pre(DECL_ARGS);
                    125:
1.368     schwarze  126: static const struct mdoc_term_act mdoc_term_acts[MDOC_MAX - MDOC_Dd] = {
1.1       kristaps  127:        { NULL, NULL }, /* Dd */
                    128:        { NULL, NULL }, /* Dt */
                    129:        { NULL, NULL }, /* Os */
                    130:        { termp_sh_pre, termp_sh_post }, /* Sh */
1.264     schwarze  131:        { termp_ss_pre, termp_ss_post }, /* Ss */
1.355     schwarze  132:        { termp_pp_pre, NULL }, /* Pp */
1.241     schwarze  133:        { termp_d1_pre, termp_bl_post }, /* D1 */
                    134:        { termp_d1_pre, termp_bl_post }, /* Dl */
1.1       kristaps  135:        { termp_bd_pre, termp_bd_post }, /* Bd */
                    136:        { NULL, NULL }, /* Ed */
1.115     kristaps  137:        { termp_bl_pre, termp_bl_post }, /* Bl */
1.1       kristaps  138:        { NULL, NULL }, /* El */
                    139:        { termp_it_pre, termp_it_post }, /* It */
1.264     schwarze  140:        { termp_under_pre, NULL }, /* Ad */
1.282     schwarze  141:        { termp_an_pre, NULL }, /* An */
1.350     schwarze  142:        { termp_ap_pre, NULL }, /* Ap */
1.69      kristaps  143:        { termp_under_pre, NULL }, /* Ar */
1.1       kristaps  144:        { termp_cd_pre, NULL }, /* Cd */
1.69      kristaps  145:        { termp_bold_pre, NULL }, /* Cm */
1.325     schwarze  146:        { termp_li_pre, NULL }, /* Dv */
1.323     schwarze  147:        { termp_er_pre, NULL }, /* Er */
1.320     schwarze  148:        { termp_tag_pre, NULL }, /* Ev */
1.1       kristaps  149:        { termp_ex_pre, NULL }, /* Ex */
1.264     schwarze  150:        { termp_fa_pre, NULL }, /* Fa */
                    151:        { termp_fd_pre, termp_fd_post }, /* Fd */
1.1       kristaps  152:        { termp_fl_pre, NULL }, /* Fl */
1.264     schwarze  153:        { termp_fn_pre, NULL }, /* Fn */
                    154:        { termp_ft_pre, NULL }, /* Ft */
                    155:        { termp_bold_pre, NULL }, /* Ic */
                    156:        { termp_in_pre, termp_in_post }, /* In */
1.102     kristaps  157:        { termp_li_pre, NULL }, /* Li */
1.264     schwarze  158:        { termp_nd_pre, NULL }, /* Nd */
                    159:        { termp_nm_pre, termp_nm_post }, /* Nm */
1.188     kristaps  160:        { termp_quote_pre, termp_quote_post }, /* Op */
1.369     schwarze  161:        { termp_abort_pre, NULL }, /* Ot */
1.69      kristaps  162:        { termp_under_pre, NULL }, /* Pa */
1.341     schwarze  163:        { termp_ex_pre, NULL }, /* Rv */
1.264     schwarze  164:        { NULL, NULL }, /* St */
1.69      kristaps  165:        { termp_under_pre, NULL }, /* Va */
1.143     kristaps  166:        { termp_vt_pre, NULL }, /* Vt */
1.1       kristaps  167:        { termp_xr_pre, NULL }, /* Xr */
1.184     kristaps  168:        { termp__a_pre, termp____post }, /* %A */
1.84      kristaps  169:        { termp_under_pre, termp____post }, /* %B */
1.1       kristaps  170:        { NULL, termp____post }, /* %D */
1.84      kristaps  171:        { termp_under_pre, termp____post }, /* %I */
1.69      kristaps  172:        { termp_under_pre, termp____post }, /* %J */
1.1       kristaps  173:        { NULL, termp____post }, /* %N */
                    174:        { NULL, termp____post }, /* %O */
                    175:        { NULL, termp____post }, /* %P */
                    176:        { NULL, termp____post }, /* %R */
1.203     kristaps  177:        { termp__t_pre, termp__t_post }, /* %T */
1.1       kristaps  178:        { NULL, termp____post }, /* %V */
                    179:        { NULL, NULL }, /* Ac */
1.188     kristaps  180:        { termp_quote_pre, termp_quote_post }, /* Ao */
                    181:        { termp_quote_pre, termp_quote_post }, /* Aq */
1.35      kristaps  182:        { NULL, NULL }, /* At */
1.1       kristaps  183:        { NULL, NULL }, /* Bc */
1.264     schwarze  184:        { termp_bf_pre, NULL }, /* Bf */
1.188     kristaps  185:        { termp_quote_pre, termp_quote_post }, /* Bo */
                    186:        { termp_quote_pre, termp_quote_post }, /* Bq */
1.339     schwarze  187:        { termp_xx_pre, termp_xx_post }, /* Bsx */
1.340     schwarze  188:        { NULL, NULL }, /* Bx */
1.294     schwarze  189:        { termp_skip_pre, NULL }, /* Db */
1.1       kristaps  190:        { NULL, NULL }, /* Dc */
1.188     kristaps  191:        { termp_quote_pre, termp_quote_post }, /* Do */
                    192:        { termp_quote_pre, termp_quote_post }, /* Dq */
1.112     kristaps  193:        { NULL, NULL }, /* Ec */ /* FIXME: no space */
1.1       kristaps  194:        { NULL, NULL }, /* Ef */
1.334     schwarze  195:        { termp_em_pre, NULL }, /* Em */
1.306     schwarze  196:        { termp_eo_pre, termp_eo_post }, /* Eo */
1.339     schwarze  197:        { termp_xx_pre, termp_xx_post }, /* Fx */
1.176     kristaps  198:        { termp_bold_pre, NULL }, /* Ms */
1.290     schwarze  199:        { termp_li_pre, NULL }, /* No */
1.1       kristaps  200:        { termp_ns_pre, NULL }, /* Ns */
1.339     schwarze  201:        { termp_xx_pre, termp_xx_post }, /* Nx */
                    202:        { termp_xx_pre, termp_xx_post }, /* Ox */
1.1       kristaps  203:        { NULL, NULL }, /* Pc */
1.254     schwarze  204:        { NULL, termp_pf_post }, /* Pf */
1.188     kristaps  205:        { termp_quote_pre, termp_quote_post }, /* Po */
                    206:        { termp_quote_pre, termp_quote_post }, /* Pq */
1.1       kristaps  207:        { NULL, NULL }, /* Qc */
1.188     kristaps  208:        { termp_quote_pre, termp_quote_post }, /* Ql */
                    209:        { termp_quote_pre, termp_quote_post }, /* Qo */
                    210:        { termp_quote_pre, termp_quote_post }, /* Qq */
1.1       kristaps  211:        { NULL, NULL }, /* Re */
                    212:        { termp_rs_pre, NULL }, /* Rs */
                    213:        { NULL, NULL }, /* Sc */
1.188     kristaps  214:        { termp_quote_pre, termp_quote_post }, /* So */
                    215:        { termp_quote_pre, termp_quote_post }, /* Sq */
1.1       kristaps  216:        { termp_sm_pre, NULL }, /* Sm */
1.69      kristaps  217:        { termp_under_pre, NULL }, /* Sx */
1.334     schwarze  218:        { termp_sy_pre, NULL }, /* Sy */
1.1       kristaps  219:        { NULL, NULL }, /* Tn */
1.339     schwarze  220:        { termp_xx_pre, termp_xx_post }, /* Ux */
1.1       kristaps  221:        { NULL, NULL }, /* Xc */
                    222:        { NULL, NULL }, /* Xo */
1.264     schwarze  223:        { termp_fo_pre, termp_fo_post }, /* Fo */
                    224:        { NULL, NULL }, /* Fc */
1.188     kristaps  225:        { termp_quote_pre, termp_quote_post }, /* Oo */
1.1       kristaps  226:        { NULL, NULL }, /* Oc */
1.159     schwarze  227:        { termp_bk_pre, termp_bk_post }, /* Bk */
1.1       kristaps  228:        { NULL, NULL }, /* Ek */
1.341     schwarze  229:        { NULL, NULL }, /* Bt */
1.1       kristaps  230:        { NULL, NULL }, /* Hf */
1.268     schwarze  231:        { termp_under_pre, NULL }, /* Fr */
1.341     schwarze  232:        { NULL, NULL }, /* Ud */
1.37      kristaps  233:        { NULL, termp_lb_post }, /* Lb */
1.369     schwarze  234:        { termp_abort_pre, NULL }, /* Lp */
1.264     schwarze  235:        { termp_lk_pre, NULL }, /* Lk */
                    236:        { termp_under_pre, NULL }, /* Mt */
                    237:        { termp_quote_pre, termp_quote_post }, /* Brq */
                    238:        { termp_quote_pre, termp_quote_post }, /* Bro */
                    239:        { NULL, NULL }, /* Brc */
                    240:        { NULL, termp____post }, /* %C */
1.294     schwarze  241:        { termp_skip_pre, NULL }, /* Es */
1.268     schwarze  242:        { termp_quote_pre, termp_quote_post }, /* En */
1.339     schwarze  243:        { termp_xx_pre, termp_xx_post }, /* Dx */
1.264     schwarze  244:        { NULL, termp____post }, /* %Q */
                    245:        { NULL, termp____post }, /* %U */
                    246:        { NULL, NULL }, /* Ta */
1.375     schwarze  247:        { termp_tg_pre, NULL }, /* Tg */
1.1       kristaps  248: };
                    249:
1.376     schwarze  250: static int      fn_prio = TAG_STRONG;
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.377   ! schwarze  583: print_bvspace(struct termp *p, struct roff_node *bl, struct roff_node *n)
1.1       kristaps  584: {
1.377   ! schwarze  585:        struct roff_node *nn;
1.1       kristaps  586:
                    587:        term_newln(p);
1.150     kristaps  588:
1.377   ! schwarze  589:        if ((bl->tok == MDOC_Bd && bl->norm->Bd.comp) ||
        !           590:            (bl->tok == MDOC_Bl && bl->norm->Bl.comp))
1.54      kristaps  591:                return;
                    592:
1.85      kristaps  593:        /* Do not vspace directly after Ss/Sh. */
1.1       kristaps  594:
1.289     schwarze  595:        nn = n;
1.377   ! schwarze  596:        while (roff_node_prev(nn) == NULL) {
1.289     schwarze  597:                do {
                    598:                        nn = nn->parent;
1.314     schwarze  599:                        if (nn->type == ROFFT_ROOT)
1.289     schwarze  600:                                return;
1.314     schwarze  601:                } while (nn->type != ROFFT_BLOCK);
1.289     schwarze  602:                if (nn->tok == MDOC_Sh || nn->tok == MDOC_Ss)
1.54      kristaps  603:                        return;
1.289     schwarze  604:                if (nn->tok == MDOC_It &&
                    605:                    nn->parent->parent->norm->Bl.type != LIST_item)
                    606:                        break;
1.1       kristaps  607:        }
                    608:
1.377   ! schwarze  609:        /*
        !           610:         * No vertical space after:
        !           611:         * items in .Bl -column
        !           612:         * items without a body in .Bl -diag
        !           613:         */
1.54      kristaps  614:
1.377   ! schwarze  615:        if (bl->tok != MDOC_Bl ||
        !           616:            n->prev == NULL || n->prev->tok != MDOC_It ||
        !           617:            (bl->norm->Bl.type != LIST_column &&
        !           618:             (bl->norm->Bl.type != LIST_diag ||
        !           619:              n->prev->body->child != NULL)))
        !           620:                term_vspace(p);
1.260     schwarze  621: }
                    622:
1.1       kristaps  623:
                    624: static int
                    625: termp_it_pre(DECL_ARGS)
                    626: {
1.345     schwarze  627:        struct roffsu           su;
1.302     schwarze  628:        char                    buf[24];
1.315     schwarze  629:        const struct roff_node *bl, *nn;
1.302     schwarze  630:        size_t                  ncols, dcol;
                    631:        int                     i, offset, width;
1.126     kristaps  632:        enum mdoc_list          type;
1.1       kristaps  633:
1.314     schwarze  634:        if (n->type == ROFFT_BLOCK) {
1.151     kristaps  635:                print_bvspace(p, n->parent->parent, n);
1.328     schwarze  636:                return 1;
1.54      kristaps  637:        }
1.1       kristaps  638:
1.86      kristaps  639:        bl = n->parent->parent->parent;
1.202     kristaps  640:        type = bl->norm->Bl.type;
1.1       kristaps  641:
1.264     schwarze  642:        /*
1.302     schwarze  643:         * Defaults for specific list types.
                    644:         */
                    645:
                    646:        switch (type) {
                    647:        case LIST_bullet:
                    648:        case LIST_dash:
                    649:        case LIST_hyphen:
                    650:        case LIST_enum:
                    651:                width = term_len(p, 2);
                    652:                break;
                    653:        case LIST_hang:
1.332     schwarze  654:        case LIST_tag:
1.302     schwarze  655:                width = term_len(p, 8);
                    656:                break;
                    657:        case LIST_column:
                    658:                width = term_len(p, 10);
                    659:                break;
                    660:        default:
                    661:                width = 0;
                    662:                break;
                    663:        }
                    664:        offset = 0;
                    665:
                    666:        /*
1.108     kristaps  667:         * First calculate width and offset.  This is pretty easy unless
                    668:         * we're a -column list, in which case all prior columns must
                    669:         * be accounted for.
                    670:         */
                    671:
1.302     schwarze  672:        if (bl->norm->Bl.offs != NULL) {
1.288     schwarze  673:                offset = a2width(p, bl->norm->Bl.offs);
1.362     schwarze  674:                if (offset < 0 && (size_t)(-offset) > p->tcol->offset)
                    675:                        offset = -p->tcol->offset;
1.302     schwarze  676:                else if (offset > SHRT_MAX)
                    677:                        offset = 0;
                    678:        }
1.152     kristaps  679:
1.1       kristaps  680:        switch (type) {
1.264     schwarze  681:        case LIST_column:
1.314     schwarze  682:                if (n->type == ROFFT_HEAD)
1.1       kristaps  683:                        break;
1.155     kristaps  684:
1.105     kristaps  685:                /*
1.108     kristaps  686:                 * Imitate groff's column handling:
                    687:                 * - For each earlier column, add its width.
                    688:                 * - For less than 5 columns, add four more blanks per
                    689:                 *   column.
                    690:                 * - For exactly 5 columns, add three more blank per
                    691:                 *   column.
                    692:                 * - For more than 5 columns, add only one column.
1.105     kristaps  693:                 */
1.202     kristaps  694:                ncols = bl->norm->Bl.ncols;
1.264     schwarze  695:                dcol = ncols < 5 ? term_len(p, 4) :
                    696:                    ncols == 5 ? term_len(p, 3) : term_len(p, 1);
1.108     kristaps  697:
1.134     kristaps  698:                /*
1.314     schwarze  699:                 * Calculate the offset by applying all prior ROFFT_BODY,
                    700:                 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
1.134     kristaps  701:                 */
                    702:
1.264     schwarze  703:                for (i = 0, nn = n->prev;
                    704:                    nn->prev && i < (int)ncols;
1.345     schwarze  705:                    nn = nn->prev, i++) {
                    706:                        SCALE_HS_INIT(&su,
                    707:                            term_strlen(p, bl->norm->Bl.cols[i]));
                    708:                        su.scale /= term_strlen(p, "0");
1.364     schwarze  709:                        offset += term_hen(p, &su) + dcol;
1.345     schwarze  710:                }
1.105     kristaps  711:
                    712:                /*
1.108     kristaps  713:                 * When exceeding the declared number of columns, leave
                    714:                 * the remaining widths at 0.  This will later be
                    715:                 * adjusted to the default width of 10, or, for the last
                    716:                 * column, stretched to the right margin.
1.58      kristaps  717:                 */
1.108     kristaps  718:                if (i >= (int)ncols)
                    719:                        break;
1.58      kristaps  720:
1.105     kristaps  721:                /*
1.108     kristaps  722:                 * Use the declared column widths, extended as explained
                    723:                 * in the preceding paragraph.
1.105     kristaps  724:                 */
1.345     schwarze  725:                SCALE_HS_INIT(&su, term_strlen(p, bl->norm->Bl.cols[i]));
                    726:                su.scale /= term_strlen(p, "0");
1.364     schwarze  727:                width = term_hen(p, &su) + dcol;
1.1       kristaps  728:                break;
                    729:        default:
1.202     kristaps  730:                if (NULL == bl->norm->Bl.width)
1.108     kristaps  731:                        break;
                    732:
1.264     schwarze  733:                /*
1.108     kristaps  734:                 * Note: buffer the width by 2, which is groff's magic
                    735:                 * number for buffering single arguments.  See the above
                    736:                 * handling for column for how this changes.
                    737:                 */
1.202     kristaps  738:                width = a2width(p, bl->norm->Bl.width) + term_len(p, 2);
1.362     schwarze  739:                if (width < 0 && (size_t)(-width) > p->tcol->offset)
                    740:                        width = -p->tcol->offset;
1.302     schwarze  741:                else if (width > SHRT_MAX)
                    742:                        width = 0;
1.1       kristaps  743:                break;
                    744:        }
                    745:
1.264     schwarze  746:        /*
1.17      kristaps  747:         * Whitespace control.  Inset bodies need an initial space,
                    748:         * while diagonal bodies need two.
1.1       kristaps  749:         */
                    750:
1.51      kristaps  751:        p->flags |= TERMP_NOSPACE;
                    752:
1.1       kristaps  753:        switch (type) {
1.264     schwarze  754:        case LIST_diag:
1.314     schwarze  755:                if (n->type == ROFFT_BODY)
1.62      kristaps  756:                        term_word(p, "\\ \\ ");
1.51      kristaps  757:                break;
1.264     schwarze  758:        case LIST_inset:
1.331     schwarze  759:                if (n->type == ROFFT_BODY && n->parent->head->child != NULL)
1.51      kristaps  760:                        term_word(p, "\\ ");
1.1       kristaps  761:                break;
                    762:        default:
                    763:                break;
                    764:        }
                    765:
1.51      kristaps  766:        p->flags |= TERMP_NOSPACE;
                    767:
1.1       kristaps  768:        switch (type) {
1.264     schwarze  769:        case LIST_diag:
1.314     schwarze  770:                if (n->type == ROFFT_HEAD)
1.102     kristaps  771:                        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps  772:                break;
                    773:        default:
                    774:                break;
                    775:        }
                    776:
                    777:        /*
1.109     kristaps  778:         * Pad and break control.  This is the tricky part.  These flags
                    779:         * are documented in term_flushln() in term.c.  Note that we're
                    780:         * going to unset all of these flags in termp_it_post() when we
                    781:         * exit.
1.1       kristaps  782:         */
                    783:
                    784:        switch (type) {
1.264     schwarze  785:        case LIST_enum:
1.329     schwarze  786:        case LIST_bullet:
                    787:        case LIST_dash:
                    788:        case LIST_hyphen:
1.360     schwarze  789:                if (n->type == ROFFT_HEAD) {
                    790:                        p->flags |= TERMP_NOBREAK | TERMP_HANG;
                    791:                        p->trailspace = 1;
                    792:                } else if (width <= (int)term_len(p, 2))
                    793:                        p->flags |= TERMP_NOPAD;
1.39      kristaps  794:                break;
1.264     schwarze  795:        case LIST_hang:
1.314     schwarze  796:                if (n->type != ROFFT_HEAD)
1.59      kristaps  797:                        break;
1.263     schwarze  798:                p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
1.250     schwarze  799:                p->trailspace = 1;
1.39      kristaps  800:                break;
1.264     schwarze  801:        case LIST_tag:
1.314     schwarze  802:                if (n->type != ROFFT_HEAD)
1.39      kristaps  803:                        break;
1.250     schwarze  804:
1.326     schwarze  805:                p->flags |= TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND;
1.250     schwarze  806:                p->trailspace = 2;
                    807:
1.86      kristaps  808:                if (NULL == n->next || NULL == n->next->child)
1.360     schwarze  809:                        p->flags |= TERMP_HANG;
1.1       kristaps  810:                break;
1.264     schwarze  811:        case LIST_column:
1.314     schwarze  812:                if (n->type == ROFFT_HEAD)
1.134     kristaps  813:                        break;
                    814:
1.250     schwarze  815:                if (NULL == n->next) {
1.134     kristaps  816:                        p->flags &= ~TERMP_NOBREAK;
1.250     schwarze  817:                        p->trailspace = 0;
                    818:                } else {
1.134     kristaps  819:                        p->flags |= TERMP_NOBREAK;
1.250     schwarze  820:                        p->trailspace = 1;
                    821:                }
1.134     kristaps  822:
1.1       kristaps  823:                break;
1.264     schwarze  824:        case LIST_diag:
1.314     schwarze  825:                if (n->type != ROFFT_HEAD)
1.250     schwarze  826:                        break;
1.263     schwarze  827:                p->flags |= TERMP_NOBREAK | TERMP_BRIND;
1.250     schwarze  828:                p->trailspace = 1;
1.1       kristaps  829:                break;
                    830:        default:
                    831:                break;
                    832:        }
                    833:
1.264     schwarze  834:        /*
1.1       kristaps  835:         * Margin control.  Set-head-width lists have their right
                    836:         * margins shortened.  The body for these lists has the offset
                    837:         * necessarily lengthened.  Everybody gets the offset.
                    838:         */
                    839:
1.362     schwarze  840:        p->tcol->offset += offset;
1.1       kristaps  841:
                    842:        switch (type) {
1.264     schwarze  843:        case LIST_bullet:
                    844:        case LIST_dash:
                    845:        case LIST_enum:
                    846:        case LIST_hyphen:
1.360     schwarze  847:        case LIST_hang:
1.264     schwarze  848:        case LIST_tag:
1.314     schwarze  849:                if (n->type == ROFFT_HEAD)
1.362     schwarze  850:                        p->tcol->rmargin = p->tcol->offset + width;
1.292     schwarze  851:                else
1.362     schwarze  852:                        p->tcol->offset += width;
1.1       kristaps  853:                break;
1.264     schwarze  854:        case LIST_column:
1.49      kristaps  855:                assert(width);
1.362     schwarze  856:                p->tcol->rmargin = p->tcol->offset + width;
1.264     schwarze  857:                /*
1.50      kristaps  858:                 * XXX - this behaviour is not documented: the
                    859:                 * right-most column is filled to the right margin.
                    860:                 */
1.314     schwarze  861:                if (n->type == ROFFT_HEAD)
1.134     kristaps  862:                        break;
1.362     schwarze  863:                if (n->next == NULL && p->tcol->rmargin < p->maxrmargin)
                    864:                        p->tcol->rmargin = p->maxrmargin;
1.1       kristaps  865:                break;
                    866:        default:
                    867:                break;
                    868:        }
                    869:
1.264     schwarze  870:        /*
1.1       kristaps  871:         * The dash, hyphen, bullet and enum lists all have a special
1.264     schwarze  872:         * HEAD character (temporarily bold, in some cases).
1.1       kristaps  873:         */
                    874:
1.314     schwarze  875:        if (n->type == ROFFT_HEAD)
1.1       kristaps  876:                switch (type) {
1.264     schwarze  877:                case LIST_bullet:
1.102     kristaps  878:                        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps  879:                        term_word(p, "\\[bu]");
1.102     kristaps  880:                        term_fontpop(p);
1.1       kristaps  881:                        break;
1.264     schwarze  882:                case LIST_dash:
                    883:                case LIST_hyphen:
1.102     kristaps  884:                        term_fontpush(p, TERMFONT_BOLD);
1.330     schwarze  885:                        term_word(p, "-");
1.102     kristaps  886:                        term_fontpop(p);
1.1       kristaps  887:                        break;
1.264     schwarze  888:                case LIST_enum:
1.1       kristaps  889:                        (pair->ppair->ppair->count)++;
1.265     schwarze  890:                        (void)snprintf(buf, sizeof(buf), "%d.",
1.264     schwarze  891:                            pair->ppair->ppair->count);
1.1       kristaps  892:                        term_word(p, buf);
                    893:                        break;
                    894:                default:
                    895:                        break;
                    896:                }
                    897:
1.264     schwarze  898:        /*
1.1       kristaps  899:         * If we're not going to process our children, indicate so here.
                    900:         */
                    901:
                    902:        switch (type) {
1.264     schwarze  903:        case LIST_bullet:
                    904:        case LIST_item:
                    905:        case LIST_dash:
                    906:        case LIST_hyphen:
                    907:        case LIST_enum:
1.314     schwarze  908:                if (n->type == ROFFT_HEAD)
1.328     schwarze  909:                        return 0;
1.1       kristaps  910:                break;
1.264     schwarze  911:        case LIST_column:
1.314     schwarze  912:                if (n->type == ROFFT_HEAD)
1.328     schwarze  913:                        return 0;
1.360     schwarze  914:                p->minbl = 0;
1.1       kristaps  915:                break;
                    916:        default:
                    917:                break;
                    918:        }
                    919:
1.328     schwarze  920:        return 1;
1.1       kristaps  921: }
                    922:
                    923: static void
                    924: termp_it_post(DECL_ARGS)
                    925: {
1.126     kristaps  926:        enum mdoc_list     type;
1.1       kristaps  927:
1.314     schwarze  928:        if (n->type == ROFFT_BLOCK)
1.1       kristaps  929:                return;
                    930:
1.202     kristaps  931:        type = n->parent->parent->parent->norm->Bl.type;
1.1       kristaps  932:
                    933:        switch (type) {
1.264     schwarze  934:        case LIST_item:
                    935:        case LIST_diag:
                    936:        case LIST_inset:
1.314     schwarze  937:                if (n->type == ROFFT_BODY)
1.130     schwarze  938:                        term_newln(p);
1.1       kristaps  939:                break;
1.264     schwarze  940:        case LIST_column:
1.314     schwarze  941:                if (n->type == ROFFT_BODY)
1.1       kristaps  942:                        term_flushln(p);
                    943:                break;
                    944:        default:
1.130     schwarze  945:                term_newln(p);
1.1       kristaps  946:                break;
                    947:        }
                    948:
1.264     schwarze  949:        /*
1.109     kristaps  950:         * Now that our output is flushed, we can reset our tags.  Since
                    951:         * only `It' sets these flags, we're free to assume that nobody
                    952:         * has munged them in the meanwhile.
                    953:         */
                    954:
1.360     schwarze  955:        p->flags &= ~(TERMP_NOBREAK | TERMP_BRTRSP | TERMP_BRIND | TERMP_HANG);
1.250     schwarze  956:        p->trailspace = 0;
1.1       kristaps  957: }
                    958:
                    959: static int
                    960: termp_nm_pre(DECL_ARGS)
                    961: {
1.296     schwarze  962:        const char      *cp;
1.1       kristaps  963:
1.314     schwarze  964:        if (n->type == ROFFT_BLOCK) {
1.253     schwarze  965:                p->flags |= TERMP_PREKEEP;
1.328     schwarze  966:                return 1;
1.253     schwarze  967:        }
1.164     schwarze  968:
1.314     schwarze  969:        if (n->type == ROFFT_BODY) {
1.362     schwarze  970:                if (n->child == NULL)
1.328     schwarze  971:                        return 0;
1.234     schwarze  972:                p->flags |= TERMP_NOSPACE;
1.296     schwarze  973:                cp = NULL;
                    974:                if (n->prev->child != NULL)
                    975:                    cp = n->prev->child->string;
                    976:                if (cp == NULL)
                    977:                        cp = meta->name;
                    978:                if (cp == NULL)
1.362     schwarze  979:                        p->tcol->offset += term_len(p, 6);
1.296     schwarze  980:                else
1.362     schwarze  981:                        p->tcol->offset += term_len(p, 1) +
                    982:                            term_strlen(p, cp);
1.328     schwarze  983:                return 1;
1.164     schwarze  984:        }
                    985:
1.343     schwarze  986:        if (n->child == NULL)
1.328     schwarze  987:                return 0;
1.125     kristaps  988:
1.314     schwarze  989:        if (n->type == ROFFT_HEAD)
1.177     schwarze  990:                synopsis_pre(p, n->parent);
1.102     kristaps  991:
1.314     schwarze  992:        if (n->type == ROFFT_HEAD &&
1.362     schwarze  993:            n->next != NULL && n->next->child != NULL) {
1.263     schwarze  994:                p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND;
1.250     schwarze  995:                p->trailspace = 1;
1.362     schwarze  996:                p->tcol->rmargin = p->tcol->offset + term_len(p, 1);
                    997:                if (n->child == NULL)
                    998:                        p->tcol->rmargin += term_strlen(p, meta->name);
                    999:                else if (n->child->type == ROFFT_TEXT) {
                   1000:                        p->tcol->rmargin += term_strlen(p, n->child->string);
                   1001:                        if (n->child->next != NULL)
1.185     schwarze 1002:                                p->flags |= TERMP_HANG;
                   1003:                } else {
1.362     schwarze 1004:                        p->tcol->rmargin += term_len(p, 5);
1.185     schwarze 1005:                        p->flags |= TERMP_HANG;
                   1006:                }
1.164     schwarze 1007:        }
                   1008:
1.102     kristaps 1009:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze 1010:        return 1;
1.1       kristaps 1011: }
                   1012:
1.164     schwarze 1013: static void
                   1014: termp_nm_post(DECL_ARGS)
                   1015: {
                   1016:
1.314     schwarze 1017:        if (n->type == ROFFT_BLOCK) {
1.253     schwarze 1018:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.314     schwarze 1019:        } else if (n->type == ROFFT_HEAD &&
1.278     schwarze 1020:            NULL != n->next && NULL != n->next->child) {
1.164     schwarze 1021:                term_flushln(p);
1.263     schwarze 1022:                p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1.250     schwarze 1023:                p->trailspace = 0;
1.314     schwarze 1024:        } else if (n->type == ROFFT_BODY && n->child != NULL)
1.164     schwarze 1025:                term_flushln(p);
                   1026: }
                   1027:
1.1       kristaps 1028: static int
                   1029: termp_fl_pre(DECL_ARGS)
                   1030: {
1.377   ! schwarze 1031:        struct roff_node *nn;
1.1       kristaps 1032:
1.320     schwarze 1033:        termp_tag_pre(p, pair, meta, n);
1.102     kristaps 1034:        term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1035:        term_word(p, "\\-");
1.103     kristaps 1036:
1.377   ! schwarze 1037:        if (n->child != NULL ||
        !          1038:            ((nn = roff_node_next(n)) != NULL &&
        !          1039:             nn->type != ROFFT_TEXT &&
        !          1040:             (nn->flags & NODE_LINE) == 0))
1.103     kristaps 1041:                p->flags |= TERMP_NOSPACE;
                   1042:
1.328     schwarze 1043:        return 1;
1.1       kristaps 1044: }
                   1045:
                   1046: static int
1.184     kristaps 1047: termp__a_pre(DECL_ARGS)
                   1048: {
1.377   ! schwarze 1049:        struct roff_node *nn;
1.184     kristaps 1050:
1.377   ! schwarze 1051:        if ((nn = roff_node_prev(n)) != NULL && nn->tok == MDOC__A &&
        !          1052:            ((nn = roff_node_next(n)) == NULL || nn->tok != MDOC__A))
        !          1053:                term_word(p, "and");
1.184     kristaps 1054:
1.328     schwarze 1055:        return 1;
1.184     kristaps 1056: }
                   1057:
                   1058: static int
1.61      kristaps 1059: termp_an_pre(DECL_ARGS)
                   1060: {
                   1061:
1.282     schwarze 1062:        if (n->norm->An.auth == AUTH_split) {
                   1063:                p->flags &= ~TERMP_NOSPLIT;
                   1064:                p->flags |= TERMP_SPLIT;
1.328     schwarze 1065:                return 0;
1.282     schwarze 1066:        }
                   1067:        if (n->norm->An.auth == AUTH_nosplit) {
                   1068:                p->flags &= ~TERMP_SPLIT;
                   1069:                p->flags |= TERMP_NOSPLIT;
1.328     schwarze 1070:                return 0;
1.282     schwarze 1071:        }
1.264     schwarze 1072:
1.282     schwarze 1073:        if (p->flags & TERMP_SPLIT)
1.61      kristaps 1074:                term_newln(p);
                   1075:
1.282     schwarze 1076:        if (n->sec == SEC_AUTHORS && ! (p->flags & TERMP_NOSPLIT))
                   1077:                p->flags |= TERMP_SPLIT;
1.61      kristaps 1078:
1.328     schwarze 1079:        return 1;
1.61      kristaps 1080: }
                   1081:
                   1082: static int
1.1       kristaps 1083: termp_ns_pre(DECL_ARGS)
                   1084: {
                   1085:
1.338     schwarze 1086:        if ( ! (NODE_LINE & n->flags))
1.215     kristaps 1087:                p->flags |= TERMP_NOSPACE;
1.328     schwarze 1088:        return 1;
1.1       kristaps 1089: }
                   1090:
                   1091: static int
                   1092: termp_rs_pre(DECL_ARGS)
                   1093: {
1.86      kristaps 1094:        if (SEC_SEE_ALSO != n->sec)
1.328     schwarze 1095:                return 1;
1.377   ! schwarze 1096:        if (n->type == ROFFT_BLOCK && roff_node_prev(n) != NULL)
1.1       kristaps 1097:                term_vspace(p);
1.328     schwarze 1098:        return 1;
1.1       kristaps 1099: }
                   1100:
                   1101: static int
                   1102: termp_ex_pre(DECL_ARGS)
                   1103: {
1.224     kristaps 1104:        term_newln(p);
1.341     schwarze 1105:        return 1;
1.1       kristaps 1106: }
                   1107:
                   1108: static int
                   1109: termp_nd_pre(DECL_ARGS)
                   1110: {
1.25      kristaps 1111:
1.314     schwarze 1112:        if (n->type == ROFFT_BODY)
1.297     schwarze 1113:                term_word(p, "\\(en");
1.328     schwarze 1114:        return 1;
1.115     kristaps 1115: }
                   1116:
                   1117: static int
                   1118: termp_bl_pre(DECL_ARGS)
                   1119: {
                   1120:
1.328     schwarze 1121:        return n->type != ROFFT_HEAD;
1.1       kristaps 1122: }
                   1123:
                   1124: static void
                   1125: termp_bl_post(DECL_ARGS)
                   1126: {
                   1127:
1.356     schwarze 1128:        if (n->type != ROFFT_BLOCK)
                   1129:                return;
                   1130:        term_newln(p);
                   1131:        if (n->tok != MDOC_Bl || n->norm->Bl.type != LIST_column)
                   1132:                return;
                   1133:        term_tab_set(p, NULL);
                   1134:        term_tab_set(p, "T");
                   1135:        term_tab_set(p, ".5i");
1.1       kristaps 1136: }
                   1137:
                   1138: static int
                   1139: termp_xr_pre(DECL_ARGS)
                   1140: {
                   1141:
1.225     kristaps 1142:        if (NULL == (n = n->child))
1.328     schwarze 1143:                return 0;
1.113     kristaps 1144:
1.314     schwarze 1145:        assert(n->type == ROFFT_TEXT);
1.225     kristaps 1146:        term_word(p, n->string);
1.11      kristaps 1147:
1.264     schwarze 1148:        if (NULL == (n = n->next))
1.328     schwarze 1149:                return 0;
1.225     kristaps 1150:
1.1       kristaps 1151:        p->flags |= TERMP_NOSPACE;
                   1152:        term_word(p, "(");
1.222     kristaps 1153:        p->flags |= TERMP_NOSPACE;
1.225     kristaps 1154:
1.314     schwarze 1155:        assert(n->type == ROFFT_TEXT);
1.225     kristaps 1156:        term_word(p, n->string);
                   1157:
1.222     kristaps 1158:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1159:        term_word(p, ")");
1.86      kristaps 1160:
1.328     schwarze 1161:        return 0;
1.1       kristaps 1162: }
                   1163:
1.143     kristaps 1164: /*
                   1165:  * This decides how to assert whitespace before any of the SYNOPSIS set
                   1166:  * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
                   1167:  * macro combos).
                   1168:  */
                   1169: static void
1.377   ! schwarze 1170: synopsis_pre(struct termp *p, struct roff_node *n)
1.143     kristaps 1171: {
1.377   ! schwarze 1172:        struct roff_node        *np;
        !          1173:
        !          1174:        if ((n->flags & NODE_SYNPRETTY) == 0 ||
        !          1175:            (np = roff_node_prev(n)) == NULL)
1.143     kristaps 1176:                return;
                   1177:
                   1178:        /*
                   1179:         * If we're the second in a pair of like elements, emit our
                   1180:         * newline and return.  UNLESS we're `Fo', `Fn', `Fn', in which
                   1181:         * case we soldier on.
                   1182:         */
1.377   ! schwarze 1183:        if (np->tok == n->tok &&
1.264     schwarze 1184:            MDOC_Ft != n->tok &&
                   1185:            MDOC_Fo != n->tok &&
                   1186:            MDOC_Fn != n->tok) {
1.143     kristaps 1187:                term_newln(p);
                   1188:                return;
                   1189:        }
                   1190:
                   1191:        /*
                   1192:         * If we're one of the SYNOPSIS set and non-like pair-wise after
                   1193:         * another (or Fn/Fo, which we've let slip through) then assert
                   1194:         * vertical space, else only newline and move on.
                   1195:         */
1.377   ! schwarze 1196:        switch (np->tok) {
1.264     schwarze 1197:        case MDOC_Fd:
                   1198:        case MDOC_Fn:
                   1199:        case MDOC_Fo:
                   1200:        case MDOC_In:
                   1201:        case MDOC_Vt:
1.143     kristaps 1202:                term_vspace(p);
                   1203:                break;
1.264     schwarze 1204:        case MDOC_Ft:
1.377   ! schwarze 1205:                if (n->tok != MDOC_Fn && n->tok != MDOC_Fo) {
1.143     kristaps 1206:                        term_vspace(p);
                   1207:                        break;
                   1208:                }
                   1209:                /* FALLTHROUGH */
                   1210:        default:
                   1211:                term_newln(p);
                   1212:                break;
                   1213:        }
                   1214: }
                   1215:
1.110     kristaps 1216: static int
                   1217: termp_vt_pre(DECL_ARGS)
                   1218: {
                   1219:
1.314     schwarze 1220:        if (n->type == ROFFT_ELEM) {
1.143     kristaps 1221:                synopsis_pre(p, n);
1.328     schwarze 1222:                return termp_under_pre(p, pair, meta, n);
1.314     schwarze 1223:        } else if (n->type == ROFFT_BLOCK) {
1.143     kristaps 1224:                synopsis_pre(p, n);
1.328     schwarze 1225:                return 1;
1.314     schwarze 1226:        } else if (n->type == ROFFT_HEAD)
1.328     schwarze 1227:                return 0;
1.110     kristaps 1228:
1.328     schwarze 1229:        return termp_under_pre(p, pair, meta, n);
1.110     kristaps 1230: }
                   1231:
1.1       kristaps 1232: static int
1.69      kristaps 1233: termp_bold_pre(DECL_ARGS)
1.1       kristaps 1234: {
                   1235:
1.320     schwarze 1236:        termp_tag_pre(p, pair, meta, n);
1.102     kristaps 1237:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze 1238:        return 1;
1.1       kristaps 1239: }
                   1240:
1.143     kristaps 1241: static int
                   1242: termp_fd_pre(DECL_ARGS)
1.1       kristaps 1243: {
                   1244:
1.143     kristaps 1245:        synopsis_pre(p, n);
1.328     schwarze 1246:        return termp_bold_pre(p, pair, meta, n);
1.1       kristaps 1247: }
                   1248:
1.241     schwarze 1249: static void
                   1250: termp_fd_post(DECL_ARGS)
                   1251: {
                   1252:
                   1253:        term_newln(p);
                   1254: }
                   1255:
1.1       kristaps 1256: static int
                   1257: termp_sh_pre(DECL_ARGS)
                   1258: {
1.377   ! schwarze 1259:        struct roff_node        *np;
1.85      kristaps 1260:
1.86      kristaps 1261:        switch (n->type) {
1.314     schwarze 1262:        case ROFFT_BLOCK:
1.293     schwarze 1263:                /*
                   1264:                 * Vertical space before sections, except
                   1265:                 * when the previous section was empty.
                   1266:                 */
1.377   ! schwarze 1267:                if ((np = roff_node_prev(n)) == NULL ||
        !          1268:                    np->tok != MDOC_Sh ||
        !          1269:                    (np->body != NULL && np->body->child != NULL))
1.293     schwarze 1270:                        term_vspace(p);
1.65      kristaps 1271:                break;
1.314     schwarze 1272:        case ROFFT_HEAD:
1.102     kristaps 1273:                term_fontpush(p, TERMFONT_BOLD);
1.1       kristaps 1274:                break;
1.314     schwarze 1275:        case ROFFT_BODY:
1.362     schwarze 1276:                p->tcol->offset = term_len(p, p->defindent);
1.356     schwarze 1277:                term_tab_set(p, NULL);
                   1278:                term_tab_set(p, "T");
                   1279:                term_tab_set(p, ".5i");
1.322     schwarze 1280:                switch (n->sec) {
                   1281:                case SEC_DESCRIPTION:
1.376     schwarze 1282:                        fn_prio = TAG_STRONG;
1.322     schwarze 1283:                        break;
                   1284:                case SEC_AUTHORS:
1.239     schwarze 1285:                        p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT);
1.322     schwarze 1286:                        break;
                   1287:                default:
                   1288:                        break;
                   1289:                }
1.1       kristaps 1290:                break;
                   1291:        default:
                   1292:                break;
                   1293:        }
1.328     schwarze 1294:        return 1;
1.1       kristaps 1295: }
                   1296:
                   1297: static void
                   1298: termp_sh_post(DECL_ARGS)
                   1299: {
                   1300:
1.86      kristaps 1301:        switch (n->type) {
1.314     schwarze 1302:        case ROFFT_HEAD:
1.1       kristaps 1303:                term_newln(p);
                   1304:                break;
1.314     schwarze 1305:        case ROFFT_BODY:
1.1       kristaps 1306:                term_newln(p);
1.362     schwarze 1307:                p->tcol->offset = 0;
1.1       kristaps 1308:                break;
                   1309:        default:
                   1310:                break;
                   1311:        }
                   1312: }
                   1313:
                   1314: static void
                   1315: termp_lb_post(DECL_ARGS)
                   1316: {
                   1317:
1.338     schwarze 1318:        if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags)
1.81      kristaps 1319:                term_newln(p);
1.1       kristaps 1320: }
                   1321:
                   1322: static int
                   1323: termp_d1_pre(DECL_ARGS)
                   1324: {
                   1325:
1.314     schwarze 1326:        if (n->type != ROFFT_BLOCK)
1.328     schwarze 1327:                return 1;
1.1       kristaps 1328:        term_newln(p);
1.362     schwarze 1329:        p->tcol->offset += term_len(p, p->defindent + 1);
1.356     schwarze 1330:        term_tab_set(p, NULL);
                   1331:        term_tab_set(p, "T");
                   1332:        term_tab_set(p, ".5i");
1.328     schwarze 1333:        return 1;
1.1       kristaps 1334: }
                   1335:
                   1336: static int
                   1337: termp_ft_pre(DECL_ARGS)
                   1338: {
                   1339:
1.338     schwarze 1340:        /* NB: NODE_LINE does not effect this! */
1.143     kristaps 1341:        synopsis_pre(p, n);
1.102     kristaps 1342:        term_fontpush(p, TERMFONT_UNDER);
1.328     schwarze 1343:        return 1;
1.1       kristaps 1344: }
                   1345:
                   1346: static int
                   1347: termp_fn_pre(DECL_ARGS)
                   1348: {
1.257     schwarze 1349:        size_t           rmargin = 0;
1.226     kristaps 1350:        int              pretty;
                   1351:
1.338     schwarze 1352:        pretty = NODE_SYNPRETTY & n->flags;
1.1       kristaps 1353:
1.143     kristaps 1354:        synopsis_pre(p, n);
1.139     kristaps 1355:
1.226     kristaps 1356:        if (NULL == (n = n->child))
1.328     schwarze 1357:                return 0;
1.226     kristaps 1358:
1.251     schwarze 1359:        if (pretty) {
1.362     schwarze 1360:                rmargin = p->tcol->rmargin;
                   1361:                p->tcol->rmargin = p->tcol->offset + term_len(p, 4);
1.263     schwarze 1362:                p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
1.251     schwarze 1363:        }
                   1364:
1.314     schwarze 1365:        assert(n->type == ROFFT_TEXT);
1.102     kristaps 1366:        term_fontpush(p, TERMFONT_BOLD);
1.226     kristaps 1367:        term_word(p, n->string);
1.102     kristaps 1368:        term_fontpop(p);
1.1       kristaps 1369:
1.336     schwarze 1370:        if (n->sec == SEC_DESCRIPTION || n->sec == SEC_CUSTOM)
1.376     schwarze 1371:                tag_put(n->string, fn_prio++, p->line);
1.322     schwarze 1372:
1.251     schwarze 1373:        if (pretty) {
                   1374:                term_flushln(p);
1.263     schwarze 1375:                p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1.360     schwarze 1376:                p->flags |= TERMP_NOPAD;
1.362     schwarze 1377:                p->tcol->offset = p->tcol->rmargin;
                   1378:                p->tcol->rmargin = rmargin;
1.251     schwarze 1379:        }
                   1380:
1.1       kristaps 1381:        p->flags |= TERMP_NOSPACE;
                   1382:        term_word(p, "(");
1.222     kristaps 1383:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1384:
1.226     kristaps 1385:        for (n = n->next; n; n = n->next) {
1.314     schwarze 1386:                assert(n->type == ROFFT_TEXT);
1.102     kristaps 1387:                term_fontpush(p, TERMFONT_UNDER);
1.255     schwarze 1388:                if (pretty)
                   1389:                        p->flags |= TERMP_NBRWORD;
1.226     kristaps 1390:                term_word(p, n->string);
1.102     kristaps 1391:                term_fontpop(p);
                   1392:
1.226     kristaps 1393:                if (n->next) {
1.222     kristaps 1394:                        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1395:                        term_word(p, ",");
1.222     kristaps 1396:                }
1.1       kristaps 1397:        }
                   1398:
1.222     kristaps 1399:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1400:        term_word(p, ")");
                   1401:
1.226     kristaps 1402:        if (pretty) {
1.222     kristaps 1403:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1404:                term_word(p, ";");
1.251     schwarze 1405:                term_flushln(p);
1.222     kristaps 1406:        }
1.1       kristaps 1407:
1.328     schwarze 1408:        return 0;
1.1       kristaps 1409: }
                   1410:
                   1411: static int
                   1412: termp_fa_pre(DECL_ARGS)
                   1413: {
1.315     schwarze 1414:        const struct roff_node  *nn;
1.1       kristaps 1415:
1.86      kristaps 1416:        if (n->parent->tok != MDOC_Fo) {
1.102     kristaps 1417:                term_fontpush(p, TERMFONT_UNDER);
1.328     schwarze 1418:                return 1;
1.1       kristaps 1419:        }
1.377   ! schwarze 1420:        for (nn = n->child; nn != NULL; nn = nn->next) {
1.102     kristaps 1421:                term_fontpush(p, TERMFONT_UNDER);
1.258     schwarze 1422:                p->flags |= TERMP_NBRWORD;
1.86      kristaps 1423:                term_word(p, nn->string);
1.102     kristaps 1424:                term_fontpop(p);
1.377   ! schwarze 1425:                if (nn->next != NULL) {
1.222     kristaps 1426:                        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1427:                        term_word(p, ",");
1.222     kristaps 1428:                }
1.1       kristaps 1429:        }
1.377   ! schwarze 1430:        if (n->child != NULL &&
        !          1431:            (nn = roff_node_next(n)) != NULL &&
        !          1432:            nn->tok == MDOC_Fa) {
        !          1433:                p->flags |= TERMP_NOSPACE;
        !          1434:                term_word(p, ",");
        !          1435:        }
1.328     schwarze 1436:        return 0;
1.1       kristaps 1437: }
                   1438:
                   1439: static int
                   1440: termp_bd_pre(DECL_ARGS)
                   1441: {
1.302     schwarze 1442:        int                      offset;
1.1       kristaps 1443:
1.314     schwarze 1444:        if (n->type == ROFFT_BLOCK) {
1.151     kristaps 1445:                print_bvspace(p, n, n);
1.328     schwarze 1446:                return 1;
1.314     schwarze 1447:        } else if (n->type == ROFFT_HEAD)
1.328     schwarze 1448:                return 0;
1.1       kristaps 1449:
1.288     schwarze 1450:        /* Handle the -offset argument. */
                   1451:
                   1452:        if (n->norm->Bd.offs == NULL ||
                   1453:            ! strcmp(n->norm->Bd.offs, "left"))
                   1454:                /* nothing */;
                   1455:        else if ( ! strcmp(n->norm->Bd.offs, "indent"))
1.362     schwarze 1456:                p->tcol->offset += term_len(p, p->defindent + 1);
1.288     schwarze 1457:        else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
1.362     schwarze 1458:                p->tcol->offset += term_len(p, (p->defindent + 1) * 2);
1.302     schwarze 1459:        else {
                   1460:                offset = a2width(p, n->norm->Bd.offs);
1.362     schwarze 1461:                if (offset < 0 && (size_t)(-offset) > p->tcol->offset)
                   1462:                        p->tcol->offset = 0;
1.302     schwarze 1463:                else if (offset < SHRT_MAX)
1.362     schwarze 1464:                        p->tcol->offset += offset;
1.302     schwarze 1465:        }
1.85      kristaps 1466:
1.372     schwarze 1467:        switch (n->norm->Bd.type) {
                   1468:        case DISP_literal:
1.356     schwarze 1469:                term_tab_set(p, NULL);
                   1470:                term_tab_set(p, "T");
                   1471:                term_tab_set(p, "8n");
1.372     schwarze 1472:                break;
                   1473:        case DISP_centered:
                   1474:                p->flags |= TERMP_CENTER;
                   1475:                break;
                   1476:        default:
                   1477:                break;
1.356     schwarze 1478:        }
1.372     schwarze 1479:        return 1;
1.1       kristaps 1480: }
                   1481:
                   1482: static void
                   1483: termp_bd_post(DECL_ARGS)
                   1484: {
1.314     schwarze 1485:        if (n->type != ROFFT_BODY)
1.1       kristaps 1486:                return;
1.372     schwarze 1487:        if (n->norm->Bd.type == DISP_unfilled ||
                   1488:            n->norm->Bd.type == DISP_literal)
1.361     schwarze 1489:                p->flags |= TERMP_BRNEVER;
1.60      kristaps 1490:        p->flags |= TERMP_NOSPACE;
1.130     schwarze 1491:        term_newln(p);
1.361     schwarze 1492:        p->flags &= ~TERMP_BRNEVER;
1.372     schwarze 1493:        if (n->norm->Bd.type == DISP_centered)
                   1494:                p->flags &= ~TERMP_CENTER;
1.1       kristaps 1495: }
                   1496:
                   1497: static int
1.26      kristaps 1498: termp_xx_pre(DECL_ARGS)
1.1       kristaps 1499: {
1.339     schwarze 1500:        if ((n->aux = p->flags & TERMP_PREKEEP) == 0)
                   1501:                p->flags |= TERMP_PREKEEP;
                   1502:        return 1;
                   1503: }
1.1       kristaps 1504:
1.339     schwarze 1505: static void
                   1506: termp_xx_post(DECL_ARGS)
                   1507: {
                   1508:        if (n->aux == 0)
                   1509:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.1       kristaps 1510: }
                   1511:
                   1512: static void
                   1513: termp_pf_post(DECL_ARGS)
                   1514: {
1.377   ! schwarze 1515:        if (n->next != NULL && (n->next->flags & NODE_LINE) == 0)
1.298     schwarze 1516:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1517: }
                   1518:
                   1519: static int
                   1520: termp_ss_pre(DECL_ARGS)
                   1521: {
1.86      kristaps 1522:        switch (n->type) {
1.314     schwarze 1523:        case ROFFT_BLOCK:
1.377   ! schwarze 1524:                if (roff_node_prev(n) == NULL)
        !          1525:                        term_newln(p);
        !          1526:                else
1.1       kristaps 1527:                        term_vspace(p);
                   1528:                break;
1.314     schwarze 1529:        case ROFFT_HEAD:
1.102     kristaps 1530:                term_fontpush(p, TERMFONT_BOLD);
1.362     schwarze 1531:                p->tcol->offset = term_len(p, (p->defindent+1)/2);
1.1       kristaps 1532:                break;
1.314     schwarze 1533:        case ROFFT_BODY:
1.362     schwarze 1534:                p->tcol->offset = term_len(p, p->defindent);
1.356     schwarze 1535:                term_tab_set(p, NULL);
                   1536:                term_tab_set(p, "T");
                   1537:                term_tab_set(p, ".5i");
1.274     schwarze 1538:                break;
1.1       kristaps 1539:        default:
                   1540:                break;
                   1541:        }
1.328     schwarze 1542:        return 1;
1.1       kristaps 1543: }
                   1544:
                   1545: static void
                   1546: termp_ss_post(DECL_ARGS)
                   1547: {
1.314     schwarze 1548:        if (n->type == ROFFT_HEAD || n->type == ROFFT_BODY)
1.1       kristaps 1549:                term_newln(p);
                   1550: }
                   1551:
                   1552: static int
                   1553: termp_cd_pre(DECL_ARGS)
                   1554: {
                   1555:
1.143     kristaps 1556:        synopsis_pre(p, n);
1.102     kristaps 1557:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze 1558:        return 1;
1.1       kristaps 1559: }
                   1560:
                   1561: static int
                   1562: termp_in_pre(DECL_ARGS)
                   1563: {
1.142     schwarze 1564:
1.143     kristaps 1565:        synopsis_pre(p, n);
1.1       kristaps 1566:
1.338     schwarze 1567:        if (NODE_SYNPRETTY & n->flags && NODE_LINE & n->flags) {
1.138     kristaps 1568:                term_fontpush(p, TERMFONT_BOLD);
1.22      kristaps 1569:                term_word(p, "#include");
1.138     kristaps 1570:                term_word(p, "<");
                   1571:        } else {
                   1572:                term_word(p, "<");
                   1573:                term_fontpush(p, TERMFONT_UNDER);
                   1574:        }
1.22      kristaps 1575:
1.1       kristaps 1576:        p->flags |= TERMP_NOSPACE;
1.328     schwarze 1577:        return 1;
1.1       kristaps 1578: }
                   1579:
                   1580: static void
                   1581: termp_in_post(DECL_ARGS)
                   1582: {
                   1583:
1.338     schwarze 1584:        if (NODE_SYNPRETTY & n->flags)
1.138     kristaps 1585:                term_fontpush(p, TERMFONT_BOLD);
                   1586:
1.79      kristaps 1587:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1588:        term_word(p, ">");
                   1589:
1.338     schwarze 1590:        if (NODE_SYNPRETTY & n->flags)
1.138     kristaps 1591:                term_fontpop(p);
1.1       kristaps 1592: }
                   1593:
                   1594: static int
1.355     schwarze 1595: termp_pp_pre(DECL_ARGS)
1.45      kristaps 1596: {
1.376     schwarze 1597:        fn_prio = TAG_STRONG;
1.355     schwarze 1598:        term_vspace(p);
1.328     schwarze 1599:        return 0;
1.45      kristaps 1600: }
                   1601:
                   1602: static int
1.294     schwarze 1603: termp_skip_pre(DECL_ARGS)
1.268     schwarze 1604: {
                   1605:
1.328     schwarze 1606:        return 0;
1.268     schwarze 1607: }
                   1608:
                   1609: static int
1.188     kristaps 1610: termp_quote_pre(DECL_ARGS)
1.1       kristaps 1611: {
                   1612:
1.314     schwarze 1613:        if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1.328     schwarze 1614:                return 1;
1.1       kristaps 1615:
1.188     kristaps 1616:        switch (n->tok) {
1.264     schwarze 1617:        case MDOC_Ao:
                   1618:        case MDOC_Aq:
1.331     schwarze 1619:                term_word(p, n->child != NULL && n->child->next == NULL &&
1.303     schwarze 1620:                    n->child->tok == MDOC_Mt ? "<" : "\\(la");
1.188     kristaps 1621:                break;
1.264     schwarze 1622:        case MDOC_Bro:
                   1623:        case MDOC_Brq:
1.188     kristaps 1624:                term_word(p, "{");
                   1625:                break;
1.264     schwarze 1626:        case MDOC_Oo:
                   1627:        case MDOC_Op:
                   1628:        case MDOC_Bo:
                   1629:        case MDOC_Bq:
1.188     kristaps 1630:                term_word(p, "[");
                   1631:                break;
1.346     schwarze 1632:        case MDOC__T:
                   1633:                /* FALLTHROUGH */
1.264     schwarze 1634:        case MDOC_Do:
                   1635:        case MDOC_Dq:
1.366     schwarze 1636:                term_word(p, "\\(lq");
1.188     kristaps 1637:                break;
1.268     schwarze 1638:        case MDOC_En:
                   1639:                if (NULL == n->norm->Es ||
                   1640:                    NULL == n->norm->Es->child)
1.328     schwarze 1641:                        return 1;
1.268     schwarze 1642:                term_word(p, n->norm->Es->child->string);
                   1643:                break;
1.264     schwarze 1644:        case MDOC_Po:
                   1645:        case MDOC_Pq:
1.188     kristaps 1646:                term_word(p, "(");
                   1647:                break;
1.264     schwarze 1648:        case MDOC_Qo:
                   1649:        case MDOC_Qq:
1.188     kristaps 1650:                term_word(p, "\"");
                   1651:                break;
1.264     schwarze 1652:        case MDOC_Ql:
                   1653:        case MDOC_So:
                   1654:        case MDOC_Sq:
1.249     schwarze 1655:                term_word(p, "\\(oq");
1.188     kristaps 1656:                break;
                   1657:        default:
                   1658:                abort();
                   1659:        }
1.1       kristaps 1660:
                   1661:        p->flags |= TERMP_NOSPACE;
1.328     schwarze 1662:        return 1;
1.1       kristaps 1663: }
                   1664:
                   1665: static void
1.188     kristaps 1666: termp_quote_post(DECL_ARGS)
1.1       kristaps 1667: {
                   1668:
1.314     schwarze 1669:        if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1.1       kristaps 1670:                return;
                   1671:
1.306     schwarze 1672:        p->flags |= TERMP_NOSPACE;
1.1       kristaps 1673:
1.188     kristaps 1674:        switch (n->tok) {
1.264     schwarze 1675:        case MDOC_Ao:
                   1676:        case MDOC_Aq:
1.331     schwarze 1677:                term_word(p, n->child != NULL && n->child->next == NULL &&
1.303     schwarze 1678:                    n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1.188     kristaps 1679:                break;
1.264     schwarze 1680:        case MDOC_Bro:
                   1681:        case MDOC_Brq:
1.188     kristaps 1682:                term_word(p, "}");
                   1683:                break;
1.264     schwarze 1684:        case MDOC_Oo:
                   1685:        case MDOC_Op:
                   1686:        case MDOC_Bo:
                   1687:        case MDOC_Bq:
1.188     kristaps 1688:                term_word(p, "]");
                   1689:                break;
1.346     schwarze 1690:        case MDOC__T:
                   1691:                /* FALLTHROUGH */
1.264     schwarze 1692:        case MDOC_Do:
                   1693:        case MDOC_Dq:
1.366     schwarze 1694:                term_word(p, "\\(rq");
1.268     schwarze 1695:                break;
                   1696:        case MDOC_En:
1.306     schwarze 1697:                if (n->norm->Es == NULL ||
                   1698:                    n->norm->Es->child == NULL ||
                   1699:                    n->norm->Es->child->next == NULL)
                   1700:                        p->flags &= ~TERMP_NOSPACE;
                   1701:                else
1.268     schwarze 1702:                        term_word(p, n->norm->Es->child->next->string);
1.188     kristaps 1703:                break;
1.264     schwarze 1704:        case MDOC_Po:
                   1705:        case MDOC_Pq:
1.188     kristaps 1706:                term_word(p, ")");
                   1707:                break;
1.264     schwarze 1708:        case MDOC_Qo:
                   1709:        case MDOC_Qq:
1.188     kristaps 1710:                term_word(p, "\"");
                   1711:                break;
1.264     schwarze 1712:        case MDOC_Ql:
                   1713:        case MDOC_So:
                   1714:        case MDOC_Sq:
1.249     schwarze 1715:                term_word(p, "\\(cq");
1.188     kristaps 1716:                break;
                   1717:        default:
                   1718:                abort();
                   1719:        }
1.306     schwarze 1720: }
                   1721:
                   1722: static int
                   1723: termp_eo_pre(DECL_ARGS)
                   1724: {
                   1725:
1.314     schwarze 1726:        if (n->type != ROFFT_BODY)
1.328     schwarze 1727:                return 1;
1.306     schwarze 1728:
                   1729:        if (n->end == ENDBODY_NOT &&
                   1730:            n->parent->head->child == NULL &&
                   1731:            n->child != NULL &&
                   1732:            n->child->end != ENDBODY_NOT)
                   1733:                term_word(p, "\\&");
                   1734:        else if (n->end != ENDBODY_NOT ? n->child != NULL :
1.309     schwarze 1735:             n->parent->head->child != NULL && (n->child != NULL ||
                   1736:             (n->parent->tail != NULL && n->parent->tail->child != NULL)))
1.306     schwarze 1737:                p->flags |= TERMP_NOSPACE;
                   1738:
1.328     schwarze 1739:        return 1;
1.306     schwarze 1740: }
                   1741:
                   1742: static void
                   1743: termp_eo_post(DECL_ARGS)
                   1744: {
                   1745:        int      body, tail;
                   1746:
1.314     schwarze 1747:        if (n->type != ROFFT_BODY)
1.306     schwarze 1748:                return;
                   1749:
                   1750:        if (n->end != ENDBODY_NOT) {
                   1751:                p->flags &= ~TERMP_NOSPACE;
                   1752:                return;
                   1753:        }
                   1754:
                   1755:        body = n->child != NULL || n->parent->head->child != NULL;
                   1756:        tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
                   1757:
                   1758:        if (body && tail)
                   1759:                p->flags |= TERMP_NOSPACE;
                   1760:        else if ( ! (body || tail))
                   1761:                term_word(p, "\\&");
                   1762:        else if ( ! tail)
                   1763:                p->flags &= ~TERMP_NOSPACE;
1.1       kristaps 1764: }
                   1765:
                   1766: static int
                   1767: termp_fo_pre(DECL_ARGS)
                   1768: {
1.257     schwarze 1769:        size_t           rmargin = 0;
1.256     schwarze 1770:        int              pretty;
                   1771:
1.338     schwarze 1772:        pretty = NODE_SYNPRETTY & n->flags;
1.1       kristaps 1773:
1.314     schwarze 1774:        if (n->type == ROFFT_BLOCK) {
1.143     kristaps 1775:                synopsis_pre(p, n);
1.328     schwarze 1776:                return 1;
1.314     schwarze 1777:        } else if (n->type == ROFFT_BODY) {
1.256     schwarze 1778:                if (pretty) {
1.362     schwarze 1779:                        rmargin = p->tcol->rmargin;
                   1780:                        p->tcol->rmargin = p->tcol->offset + term_len(p, 4);
1.263     schwarze 1781:                        p->flags |= TERMP_NOBREAK | TERMP_BRIND |
                   1782:                                        TERMP_HANG;
1.256     schwarze 1783:                }
1.33      kristaps 1784:                p->flags |= TERMP_NOSPACE;
1.1       kristaps 1785:                term_word(p, "(");
1.222     kristaps 1786:                p->flags |= TERMP_NOSPACE;
1.256     schwarze 1787:                if (pretty) {
                   1788:                        term_flushln(p);
1.263     schwarze 1789:                        p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
                   1790:                                        TERMP_HANG);
1.360     schwarze 1791:                        p->flags |= TERMP_NOPAD;
1.362     schwarze 1792:                        p->tcol->offset = p->tcol->rmargin;
                   1793:                        p->tcol->rmargin = rmargin;
1.256     schwarze 1794:                }
1.328     schwarze 1795:                return 1;
1.256     schwarze 1796:        }
1.141     kristaps 1797:
1.169     kristaps 1798:        if (NULL == n->child)
1.328     schwarze 1799:                return 0;
1.169     kristaps 1800:
1.141     kristaps 1801:        /* XXX: we drop non-initial arguments as per groff. */
1.1       kristaps 1802:
1.141     kristaps 1803:        assert(n->child->string);
1.102     kristaps 1804:        term_fontpush(p, TERMFONT_BOLD);
1.141     kristaps 1805:        term_word(p, n->child->string);
1.328     schwarze 1806:        return 0;
1.1       kristaps 1807: }
                   1808:
                   1809: static void
                   1810: termp_fo_post(DECL_ARGS)
                   1811: {
                   1812:
1.314     schwarze 1813:        if (n->type != ROFFT_BODY)
1.143     kristaps 1814:                return;
                   1815:
1.222     kristaps 1816:        p->flags |= TERMP_NOSPACE;
1.143     kristaps 1817:        term_word(p, ")");
                   1818:
1.338     schwarze 1819:        if (NODE_SYNPRETTY & n->flags) {
1.222     kristaps 1820:                p->flags |= TERMP_NOSPACE;
1.143     kristaps 1821:                term_word(p, ";");
1.256     schwarze 1822:                term_flushln(p);
1.222     kristaps 1823:        }
1.1       kristaps 1824: }
                   1825:
                   1826: static int
                   1827: termp_bf_pre(DECL_ARGS)
                   1828: {
                   1829:
1.314     schwarze 1830:        if (n->type == ROFFT_HEAD)
1.328     schwarze 1831:                return 0;
1.314     schwarze 1832:        else if (n->type != ROFFT_BODY)
1.328     schwarze 1833:                return 1;
1.1       kristaps 1834:
1.264     schwarze 1835:        if (FONT_Em == n->norm->Bf.font)
1.102     kristaps 1836:                term_fontpush(p, TERMFONT_UNDER);
1.264     schwarze 1837:        else if (FONT_Sy == n->norm->Bf.font)
1.102     kristaps 1838:                term_fontpush(p, TERMFONT_BOLD);
1.264     schwarze 1839:        else
1.102     kristaps 1840:                term_fontpush(p, TERMFONT_NONE);
1.1       kristaps 1841:
1.328     schwarze 1842:        return 1;
1.1       kristaps 1843: }
                   1844:
                   1845: static int
                   1846: termp_sm_pre(DECL_ARGS)
                   1847: {
                   1848:
1.269     schwarze 1849:        if (NULL == n->child)
                   1850:                p->flags ^= TERMP_NONOSPACE;
                   1851:        else if (0 == strcmp("on", n->child->string))
1.1       kristaps 1852:                p->flags &= ~TERMP_NONOSPACE;
1.269     schwarze 1853:        else
1.1       kristaps 1854:                p->flags |= TERMP_NONOSPACE;
1.269     schwarze 1855:
                   1856:        if (p->col && ! (TERMP_NONOSPACE & p->flags))
                   1857:                p->flags &= ~TERMP_NOSPACE;
1.1       kristaps 1858:
1.328     schwarze 1859:        return 0;
1.1       kristaps 1860: }
                   1861:
                   1862: static int
                   1863: termp_ap_pre(DECL_ARGS)
                   1864: {
                   1865:
                   1866:        p->flags |= TERMP_NOSPACE;
1.188     kristaps 1867:        term_word(p, "'");
1.1       kristaps 1868:        p->flags |= TERMP_NOSPACE;
1.328     schwarze 1869:        return 1;
1.1       kristaps 1870: }
                   1871:
                   1872: static void
                   1873: termp____post(DECL_ARGS)
                   1874: {
1.377   ! schwarze 1875:        struct roff_node *nn;
1.184     kristaps 1876:
                   1877:        /*
                   1878:         * Handle lists of authors.  In general, print each followed by
                   1879:         * a comma.  Don't print the comma if there are only two
                   1880:         * authors.
                   1881:         */
1.377   ! schwarze 1882:        if (n->tok == MDOC__A &&
        !          1883:            (nn = roff_node_next(n)) != NULL && nn->tok == MDOC__A &&
        !          1884:            ((nn = roff_node_next(nn)) == NULL || nn->tok != MDOC__A) &&
        !          1885:            ((nn = roff_node_prev(n)) == NULL || nn->tok != MDOC__A))
        !          1886:                return;
1.1       kristaps 1887:
1.95      kristaps 1888:        /* TODO: %U. */
                   1889:
1.377   ! schwarze 1890:        if (n->parent == NULL || n->parent->tok != MDOC_Rs)
1.187     kristaps 1891:                return;
                   1892:
1.222     kristaps 1893:        p->flags |= TERMP_NOSPACE;
1.377   ! schwarze 1894:        if (roff_node_next(n) == NULL) {
1.186     kristaps 1895:                term_word(p, ".");
                   1896:                p->flags |= TERMP_SENTENCE;
                   1897:        } else
                   1898:                term_word(p, ",");
1.1       kristaps 1899: }
                   1900:
                   1901: static int
1.102     kristaps 1902: termp_li_pre(DECL_ARGS)
                   1903: {
                   1904:
1.335     schwarze 1905:        termp_tag_pre(p, pair, meta, n);
1.102     kristaps 1906:        term_fontpush(p, TERMFONT_NONE);
1.328     schwarze 1907:        return 1;
1.102     kristaps 1908: }
                   1909:
                   1910: static int
1.1       kristaps 1911: termp_lk_pre(DECL_ARGS)
                   1912: {
1.358     schwarze 1913:        const struct roff_node *link, *descr, *punct;
1.1       kristaps 1914:
1.349     schwarze 1915:        if ((link = n->child) == NULL)
1.328     schwarze 1916:                return 0;
1.181     kristaps 1917:
1.358     schwarze 1918:        /* Find beginning of trailing punctuation. */
                   1919:        punct = n->last;
                   1920:        while (punct != link && punct->flags & NODE_DELIMC)
                   1921:                punct = punct->prev;
                   1922:        punct = punct->next;
                   1923:
1.349     schwarze 1924:        /* Link text. */
1.358     schwarze 1925:        if ((descr = link->next) != NULL && descr != punct) {
1.240     schwarze 1926:                term_fontpush(p, TERMFONT_UNDER);
1.358     schwarze 1927:                while (descr != punct) {
                   1928:                        if (descr->flags & (NODE_DELIMC | NODE_DELIMO))
                   1929:                                p->flags |= TERMP_NOSPACE;
1.240     schwarze 1930:                        term_word(p, descr->string);
                   1931:                        descr = descr->next;
                   1932:                }
1.347     schwarze 1933:                term_fontpop(p);
1.240     schwarze 1934:                p->flags |= TERMP_NOSPACE;
                   1935:                term_word(p, ":");
                   1936:        }
1.1       kristaps 1937:
1.349     schwarze 1938:        /* Link target. */
1.102     kristaps 1939:        term_fontpush(p, TERMFONT_BOLD);
1.240     schwarze 1940:        term_word(p, link->string);
1.102     kristaps 1941:        term_fontpop(p);
1.348     schwarze 1942:
1.349     schwarze 1943:        /* Trailing punctuation. */
1.358     schwarze 1944:        while (punct != NULL) {
1.349     schwarze 1945:                p->flags |= TERMP_NOSPACE;
1.358     schwarze 1946:                term_word(p, punct->string);
                   1947:                punct = punct->next;
1.349     schwarze 1948:        }
1.328     schwarze 1949:        return 0;
1.1       kristaps 1950: }
                   1951:
1.159     schwarze 1952: static int
                   1953: termp_bk_pre(DECL_ARGS)
                   1954: {
                   1955:
1.161     schwarze 1956:        switch (n->type) {
1.314     schwarze 1957:        case ROFFT_BLOCK:
1.166     kristaps 1958:                break;
1.314     schwarze 1959:        case ROFFT_HEAD:
1.328     schwarze 1960:                return 0;
1.314     schwarze 1961:        case ROFFT_BODY:
1.331     schwarze 1962:                if (n->parent->args != NULL || n->prev->child == NULL)
1.200     schwarze 1963:                        p->flags |= TERMP_PREKEEP;
1.166     kristaps 1964:                break;
1.161     schwarze 1965:        default:
                   1966:                abort();
                   1967:        }
1.166     kristaps 1968:
1.328     schwarze 1969:        return 1;
1.159     schwarze 1970: }
                   1971:
                   1972: static void
                   1973: termp_bk_post(DECL_ARGS)
                   1974: {
                   1975:
1.314     schwarze 1976:        if (n->type == ROFFT_BODY)
1.161     schwarze 1977:                p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1.203     kristaps 1978: }
                   1979:
                   1980: static void
                   1981: termp__t_post(DECL_ARGS)
                   1982: {
                   1983:
                   1984:        /*
                   1985:         * If we're in an `Rs' and there's a journal present, then quote
                   1986:         * us instead of underlining us (for disambiguation).
                   1987:         */
1.217     schwarze 1988:        if (n->parent && MDOC_Rs == n->parent->tok &&
1.264     schwarze 1989:            n->parent->norm->Rs.quote_T)
1.245     schwarze 1990:                termp_quote_post(p, pair, meta, n);
1.203     kristaps 1991:
1.245     schwarze 1992:        termp____post(p, pair, meta, n);
1.203     kristaps 1993: }
                   1994:
                   1995: static int
                   1996: termp__t_pre(DECL_ARGS)
                   1997: {
                   1998:
                   1999:        /*
                   2000:         * If we're in an `Rs' and there's a journal present, then quote
                   2001:         * us instead of underlining us (for disambiguation).
                   2002:         */
                   2003:        if (n->parent && MDOC_Rs == n->parent->tok &&
1.264     schwarze 2004:            n->parent->norm->Rs.quote_T)
1.328     schwarze 2005:                return termp_quote_pre(p, pair, meta, n);
1.203     kristaps 2006:
                   2007:        term_fontpush(p, TERMFONT_UNDER);
1.328     schwarze 2008:        return 1;
1.159     schwarze 2009: }
1.1       kristaps 2010:
                   2011: static int
1.69      kristaps 2012: termp_under_pre(DECL_ARGS)
1.1       kristaps 2013: {
                   2014:
1.102     kristaps 2015:        term_fontpush(p, TERMFONT_UNDER);
1.334     schwarze 2016:        return 1;
                   2017: }
                   2018:
                   2019: static int
                   2020: termp_em_pre(DECL_ARGS)
                   2021: {
                   2022:        if (n->child != NULL &&
                   2023:            n->child->type == ROFFT_TEXT)
1.376     schwarze 2024:                tag_put(n->child->string, TAG_FALLBACK, p->line);
1.334     schwarze 2025:        term_fontpush(p, TERMFONT_UNDER);
                   2026:        return 1;
                   2027: }
                   2028:
                   2029: static int
                   2030: termp_sy_pre(DECL_ARGS)
                   2031: {
                   2032:        if (n->child != NULL &&
                   2033:            n->child->type == ROFFT_TEXT)
1.376     schwarze 2034:                tag_put(n->child->string, TAG_FALLBACK, p->line);
1.334     schwarze 2035:        term_fontpush(p, TERMFONT_BOLD);
1.328     schwarze 2036:        return 1;
1.323     schwarze 2037: }
                   2038:
                   2039: static int
                   2040: termp_er_pre(DECL_ARGS)
                   2041: {
                   2042:
                   2043:        if (n->sec == SEC_ERRORS &&
                   2044:            (n->parent->tok == MDOC_It ||
                   2045:             (n->parent->tok == MDOC_Bq &&
1.324     schwarze 2046:              n->parent->parent->parent->tok == MDOC_It)))
1.376     schwarze 2047:                tag_put(n->child->string, TAG_STRONG, p->line);
1.328     schwarze 2048:        return 1;
1.320     schwarze 2049: }
                   2050:
                   2051: static int
                   2052: termp_tag_pre(DECL_ARGS)
                   2053: {
                   2054:
                   2055:        if (n->child != NULL &&
                   2056:            n->child->type == ROFFT_TEXT &&
1.333     schwarze 2057:            (n->prev == NULL ||
                   2058:             (n->prev->type == ROFFT_TEXT &&
                   2059:              strcmp(n->prev->string, "|") == 0)) &&
1.320     schwarze 2060:            (n->parent->tok == MDOC_It ||
                   2061:             (n->parent->tok == MDOC_Xo &&
                   2062:              n->parent->parent->prev == NULL &&
1.324     schwarze 2063:              n->parent->parent->parent->tok == MDOC_It)))
1.376     schwarze 2064:                tag_put(n->child->string, TAG_STRONG, p->line);
1.328     schwarze 2065:        return 1;
1.375     schwarze 2066: }
                   2067:
                   2068: static int
                   2069: termp_tg_pre(DECL_ARGS)
                   2070: {
1.376     schwarze 2071:        tag_put(n->child->string, TAG_MANUAL, p->line);
1.375     schwarze 2072:        return 0;
1.369     schwarze 2073: }
                   2074:
                   2075: static int
                   2076: termp_abort_pre(DECL_ARGS)
                   2077: {
                   2078:        abort();
1.84      kristaps 2079: }

CVSweb