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

Annotation of mandoc/mdoc_term.c, Revision 1.150

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

CVSweb