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

Annotation of mandoc/mdoc_term.c, Revision 1.158

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

CVSweb