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

Annotation of mandoc/mdoc_term.c, Revision 1.163

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

CVSweb