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

Annotation of mandoc/mdoc_term.c, Revision 1.332

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

CVSweb