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

Annotation of mandoc/mdoc_term.c, Revision 1.119

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

CVSweb