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

Annotation of mandoc/mdoc_term.c, Revision 1.319

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

CVSweb