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

Annotation of mandoc/mdoc_term.c, Revision 1.369

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

CVSweb