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

Annotation of mandoc/mdoc_term.c, Revision 1.164

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

CVSweb