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

Annotation of mandoc/mdoc_term.c, Revision 1.134

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

CVSweb