[BACK]Return to mdoc_term.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/mdoc_term.c, Revision 1.8

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