[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.2

1.2     ! schwarze    1: /*     $Id: mdoc_term.c,v 1.12 2009/06/12 09:18:00 kristaps 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: static void      sanity(const struct mdoc_node *);
                    324:
                    325:
                    326: int
                    327: mdoc_run(struct termp *p, const struct mdoc *m)
                    328: {
                    329:
                    330:        print_head(p, mdoc_meta(m));
                    331:        print_body(p, NULL, mdoc_meta(m), mdoc_node(m));
                    332:        print_foot(p, mdoc_meta(m));
                    333:        return(1);
                    334: }
                    335:
                    336:
                    337: static void
                    338: print_body(DECL_ARGS)
                    339: {
                    340:
                    341:        print_node(p, pair, meta, node);
                    342:        if ( ! node->next)
                    343:                return;
                    344:        print_body(p, pair, meta, node->next);
                    345: }
                    346:
                    347:
                    348: static void
                    349: print_node(DECL_ARGS)
                    350: {
                    351:        int              dochild;
                    352:        struct termpair  npair;
                    353:
                    354:        /* Some quick sanity-checking. */
                    355:
                    356:        sanity(node);
                    357:
                    358:        /* Pre-processing. */
                    359:
                    360:        dochild = 1;
                    361:        npair.ppair = pair;
                    362:        npair.type = 0;
                    363:        npair.offset = npair.rmargin = 0;
                    364:        npair.flag = 0;
                    365:        npair.count = 0;
                    366:
                    367:        if (MDOC_TEXT != node->type) {
                    368:                if (termacts[node->tok].pre)
                    369:                        if ( ! (*termacts[node->tok].pre)(p, &npair, meta, node))
                    370:                                dochild = 0;
                    371:        } else /* MDOC_TEXT == node->type */
                    372:                term_word(p, node->string);
                    373:
                    374:        /* Children. */
                    375:
                    376:        if (TERMPAIR_FLAG & npair.type)
                    377:                p->flags |= npair.flag;
                    378:
                    379:        if (dochild && node->child)
                    380:                print_body(p, &npair, meta, node->child);
                    381:
                    382:        if (TERMPAIR_FLAG & npair.type)
                    383:                p->flags &= ~npair.flag;
                    384:
                    385:        /* Post-processing. */
                    386:
                    387:        if (MDOC_TEXT != node->type)
                    388:                if (termacts[node->tok].post)
                    389:                        (*termacts[node->tok].post)(p, &npair, meta, node);
                    390: }
                    391:
                    392:
                    393: static void
                    394: print_foot(struct termp *p, const struct mdoc_meta *meta)
                    395: {
                    396:        struct tm       *tm;
                    397:        char            *buf, *os;
                    398:
                    399:        if (NULL == (buf = malloc(p->rmargin)))
                    400:                err(1, "malloc");
                    401:        if (NULL == (os = malloc(p->rmargin)))
                    402:                err(1, "malloc");
                    403:
                    404:        tm = localtime(&meta->date);
                    405:
                    406:        if (NULL == strftime(buf, p->rmargin, "%B %d, %Y", tm))
                    407:                err(1, "strftime");
                    408:
                    409:        (void)strlcpy(os, meta->os, p->rmargin);
                    410:
                    411:        /*
                    412:         * This is /slightly/ different from regular groff output
                    413:         * because we don't have page numbers.  Print the following:
                    414:         *
                    415:         * OS                                            MDOCDATE
                    416:         */
                    417:
                    418:        term_vspace(p);
                    419:
                    420:        p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
                    421:        p->rmargin = p->maxrmargin - strlen(buf);
                    422:        p->offset = 0;
                    423:
                    424:        term_word(p, os);
                    425:        term_flushln(p);
                    426:
                    427:        p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
                    428:        p->offset = p->rmargin;
                    429:        p->rmargin = p->maxrmargin;
                    430:        p->flags &= ~TERMP_NOBREAK;
                    431:
                    432:        term_word(p, buf);
                    433:        term_flushln(p);
                    434:
                    435:        free(buf);
                    436:        free(os);
                    437: }
                    438:
                    439:
                    440: static void
                    441: print_head(struct termp *p, const struct mdoc_meta *meta)
                    442: {
                    443:        char            *buf, *title;
                    444:
                    445:        p->rmargin = p->maxrmargin;
                    446:        p->offset = 0;
                    447:
                    448:        if (NULL == (buf = malloc(p->rmargin)))
                    449:                err(1, "malloc");
                    450:        if (NULL == (title = malloc(p->rmargin)))
                    451:                err(1, "malloc");
                    452:
                    453:        /*
                    454:         * The header is strange.  It has three components, which are
                    455:         * really two with the first duplicated.  It goes like this:
                    456:         *
                    457:         * IDENTIFIER              TITLE                   IDENTIFIER
                    458:         *
                    459:         * The IDENTIFIER is NAME(SECTION), which is the command-name
                    460:         * (if given, or "unknown" if not) followed by the manual page
                    461:         * section.  These are given in `Dt'.  The TITLE is a free-form
                    462:         * string depending on the manual volume.  If not specified, it
                    463:         * switches on the manual section.
                    464:         */
                    465:
                    466:        assert(meta->vol);
                    467:        (void)strlcpy(buf, meta->vol, p->rmargin);
                    468:
                    469:        if (meta->arch) {
                    470:                (void)strlcat(buf, " (", p->rmargin);
                    471:                (void)strlcat(buf, meta->arch, p->rmargin);
                    472:                (void)strlcat(buf, ")", p->rmargin);
                    473:        }
                    474:
                    475:        (void)snprintf(title, p->rmargin, "%s(%d)",
                    476:                        meta->title, meta->msec);
                    477:
                    478:        p->offset = 0;
                    479:        p->rmargin = (p->maxrmargin - strlen(buf)) / 2;
                    480:        p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
                    481:
                    482:        term_word(p, title);
                    483:        term_flushln(p);
                    484:
                    485:        p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
                    486:        p->offset = p->rmargin;
                    487:        p->rmargin = p->maxrmargin - strlen(title);
                    488:
                    489:        term_word(p, buf);
                    490:        term_flushln(p);
                    491:
                    492:        p->offset = p->rmargin;
                    493:        p->rmargin = p->maxrmargin;
                    494:        p->flags &= ~TERMP_NOBREAK;
                    495:        p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
                    496:
                    497:        term_word(p, title);
                    498:        term_flushln(p);
                    499:
                    500:        p->rmargin = p->maxrmargin;
                    501:        p->offset = 0;
                    502:        p->flags &= ~TERMP_NOSPACE;
                    503:
                    504:        free(title);
                    505:        free(buf);
                    506: }
                    507:
                    508:
                    509: static void
                    510: sanity(const struct mdoc_node *n)
                    511: {
                    512:        char            *p;
                    513:
                    514:        p = "regular form violated";
                    515:
                    516:        switch (n->type) {
                    517:        case (MDOC_TEXT):
                    518:                if (n->child)
                    519:                        errx(1, p);
                    520:                if (NULL == n->parent)
                    521:                        errx(1, p);
                    522:                if (NULL == n->string)
                    523:                        errx(1, p);
                    524:                switch (n->parent->type) {
                    525:                case (MDOC_TEXT):
                    526:                        /* FALLTHROUGH */
                    527:                case (MDOC_ROOT):
                    528:                        errx(1, p);
                    529:                        /* NOTREACHED */
                    530:                default:
                    531:                        break;
                    532:                }
                    533:                break;
                    534:        case (MDOC_ELEM):
                    535:                if (NULL == n->parent)
                    536:                        errx(1, p);
                    537:                switch (n->parent->type) {
                    538:                case (MDOC_TAIL):
                    539:                        /* FALLTHROUGH */
                    540:                case (MDOC_BODY):
                    541:                        /* FALLTHROUGH */
                    542:                case (MDOC_HEAD):
                    543:                        break;
                    544:                default:
                    545:                        errx(1, p);
                    546:                        /* NOTREACHED */
                    547:                }
                    548:                if (n->child) switch (n->child->type) {
                    549:                case (MDOC_TEXT):
                    550:                        break;
                    551:                default:
                    552:                        errx(1, p);
                    553:                        /* NOTREACHED */
                    554:                }
                    555:                break;
                    556:        case (MDOC_HEAD):
                    557:                /* FALLTHROUGH */
                    558:        case (MDOC_BODY):
                    559:                /* FALLTHROUGH */
                    560:        case (MDOC_TAIL):
                    561:                if (NULL == n->parent)
                    562:                        errx(1, p);
                    563:                if (MDOC_BLOCK != n->parent->type)
                    564:                        errx(1, p);
                    565:                if (n->child) switch (n->child->type) {
                    566:                case (MDOC_BLOCK):
                    567:                        /* FALLTHROUGH */
                    568:                case (MDOC_ELEM):
                    569:                        /* FALLTHROUGH */
                    570:                case (MDOC_TEXT):
                    571:                        break;
                    572:                default:
                    573:                        errx(1, p);
                    574:                        /* NOTREACHED */
                    575:                }
                    576:                break;
                    577:        case (MDOC_BLOCK):
                    578:                if (NULL == n->parent)
                    579:                        errx(1, p);
                    580:                if (NULL == n->child)
                    581:                        errx(1, p);
                    582:                switch (n->parent->type) {
                    583:                case (MDOC_ROOT):
                    584:                        /* FALLTHROUGH */
                    585:                case (MDOC_HEAD):
                    586:                        /* FALLTHROUGH */
                    587:                case (MDOC_BODY):
                    588:                        /* FALLTHROUGH */
                    589:                case (MDOC_TAIL):
                    590:                        break;
                    591:                default:
                    592:                        errx(1, p);
                    593:                        /* NOTREACHED */
                    594:                }
                    595:                switch (n->child->type) {
                    596:                case (MDOC_ROOT):
                    597:                        /* FALLTHROUGH */
                    598:                case (MDOC_ELEM):
                    599:                        errx(1, p);
                    600:                        /* NOTREACHED */
                    601:                default:
                    602:                        break;
                    603:                }
                    604:                break;
                    605:        case (MDOC_ROOT):
                    606:                if (n->parent)
                    607:                        errx(1, p);
                    608:                if (NULL == n->child)
                    609:                        errx(1, p);
                    610:                switch (n->child->type) {
                    611:                case (MDOC_BLOCK):
                    612:                        break;
                    613:                default:
                    614:                        errx(1, p);
                    615:                        /* NOTREACHED */
                    616:                }
                    617:                break;
                    618:        }
                    619: }
                    620:
                    621:
                    622: static size_t
                    623: arg_width(const struct mdoc_argv *arg, int pos)
                    624: {
                    625:        size_t           v;
                    626:        int              i, len;
                    627:
                    628:        assert(pos < (int)arg->sz && pos >= 0);
                    629:        assert(arg->value[pos]);
                    630:        if (0 == strcmp(arg->value[pos], "indent"))
                    631:                return(INDENT);
                    632:        if (0 == strcmp(arg->value[pos], "indent-two"))
                    633:                return(INDENT * 2);
                    634:
                    635:        if (0 == (len = (int)strlen(arg->value[pos])))
                    636:                return(0);
                    637:
                    638:        for (i = 0; i < len - 1; i++)
                    639:                if ( ! isdigit((u_char)arg->value[pos][i]))
                    640:                        break;
                    641:
                    642:        if (i == len - 1) {
                    643:                if ('n' == arg->value[pos][len - 1]) {
                    644:                        v = (size_t)atoi(arg->value[pos]);
                    645:                        return(v);
                    646:                }
                    647:
                    648:        }
                    649:        return(strlen(arg->value[pos]) + 1);
                    650: }
                    651:
                    652:
                    653: static int
                    654: arg_listtype(const struct mdoc_node *n)
                    655: {
                    656:        int              i, len;
                    657:
                    658:        assert(MDOC_BLOCK == n->type);
                    659:
                    660:        len = (int)(n->args ? n->args->argc : 0);
                    661:
                    662:        for (i = 0; i < len; i++)
                    663:                switch (n->args->argv[i].arg) {
                    664:                case (MDOC_Bullet):
                    665:                        /* FALLTHROUGH */
                    666:                case (MDOC_Dash):
                    667:                        /* FALLTHROUGH */
                    668:                case (MDOC_Enum):
                    669:                        /* FALLTHROUGH */
                    670:                case (MDOC_Hyphen):
                    671:                        /* FALLTHROUGH */
                    672:                case (MDOC_Tag):
                    673:                        /* FALLTHROUGH */
                    674:                case (MDOC_Inset):
                    675:                        /* FALLTHROUGH */
                    676:                case (MDOC_Diag):
                    677:                        /* FALLTHROUGH */
                    678:                case (MDOC_Item):
                    679:                        /* FALLTHROUGH */
                    680:                case (MDOC_Column):
                    681:                        /* FALLTHROUGH */
                    682:                case (MDOC_Ohang):
                    683:                        return(n->args->argv[i].arg);
                    684:                default:
                    685:                        break;
                    686:                }
                    687:
                    688:        errx(1, "list type not supported");
                    689:        /* NOTREACHED */
                    690: }
                    691:
                    692:
                    693: static size_t
                    694: arg_offset(const struct mdoc_argv *arg)
                    695: {
                    696:
                    697:        assert(*arg->value);
                    698:        if (0 == strcmp(*arg->value, "indent"))
                    699:                return(INDENT);
                    700:        if (0 == strcmp(*arg->value, "indent-two"))
                    701:                return(INDENT * 2);
                    702:        return(strlen(*arg->value));
                    703: }
                    704:
                    705:
                    706: static int
                    707: arg_hasattr(int arg, const struct mdoc_node *n)
                    708: {
                    709:
                    710:        return(-1 != arg_getattr(arg, n));
                    711: }
                    712:
                    713:
                    714: static int
                    715: arg_getattr(int v, const struct mdoc_node *n)
                    716: {
                    717:        int              val;
                    718:
                    719:        return(arg_getattrs(&v, &val, 1, n) ? val : -1);
                    720: }
                    721:
                    722:
                    723: static int
                    724: arg_getattrs(const int *keys, int *vals,
                    725:                size_t sz, const struct mdoc_node *n)
                    726: {
                    727:        int              i, j, k;
                    728:
                    729:        if (NULL == n->args)
                    730:                return(0);
                    731:
                    732:        for (k = i = 0; i < (int)n->args->argc; i++)
                    733:                for (j = 0; j < (int)sz; j++)
                    734:                        if (n->args->argv[i].arg == keys[j]) {
                    735:                                vals[j] = i;
                    736:                                k++;
                    737:                        }
                    738:        return(k);
                    739: }
                    740:
                    741:
                    742: /* ARGSUSED */
                    743: static int
                    744: fmt_block_vspace(struct termp *p,
                    745:                const struct mdoc_node *bl,
                    746:                const struct mdoc_node *node)
                    747: {
                    748:        const struct mdoc_node *n;
                    749:
                    750:        term_newln(p);
                    751:
                    752:        if (arg_hasattr(MDOC_Compact, bl))
                    753:                return(1);
                    754:
                    755:        for (n = node; n; n = n->parent) {
                    756:                if (MDOC_BLOCK != n->type)
                    757:                        continue;
                    758:                if (MDOC_Ss == n->tok)
                    759:                        break;
                    760:                if (MDOC_Sh == n->tok)
                    761:                        break;
                    762:                if (NULL == n->prev)
                    763:                        continue;
                    764:                term_vspace(p);
                    765:                break;
                    766:        }
                    767:
                    768:        return(1);
                    769: }
                    770:
                    771:
                    772: /* ARGSUSED */
                    773: static int
                    774: termp_dq_pre(DECL_ARGS)
                    775: {
                    776:
                    777:        if (MDOC_BODY != node->type)
                    778:                return(1);
                    779:
                    780:        term_word(p, "\\(lq");
                    781:        p->flags |= TERMP_NOSPACE;
                    782:        return(1);
                    783: }
                    784:
                    785:
                    786: /* ARGSUSED */
                    787: static void
                    788: termp_dq_post(DECL_ARGS)
                    789: {
                    790:
                    791:        if (MDOC_BODY != node->type)
                    792:                return;
                    793:
                    794:        p->flags |= TERMP_NOSPACE;
                    795:        term_word(p, "\\(rq");
                    796: }
                    797:
                    798:
                    799: /* ARGSUSED */
                    800: static int
                    801: termp_it_pre(DECL_ARGS)
                    802: {
                    803:        const struct mdoc_node *bl, *n;
                    804:        char                    buf[7];
                    805:        int                     i, type, keys[3], vals[3];
                    806:        size_t                  width, offset;
                    807:
                    808:        if (MDOC_BLOCK == node->type)
                    809:                return(fmt_block_vspace(p, node->parent->parent, node));
                    810:
                    811:        bl = node->parent->parent->parent;
                    812:
                    813:        /* Save parent attributes. */
                    814:
                    815:        pair->offset = p->offset;
                    816:        pair->rmargin = p->rmargin;
                    817:        pair->flag = p->flags;
                    818:
                    819:        /* Get list width and offset. */
                    820:
                    821:        keys[0] = MDOC_Width;
                    822:        keys[1] = MDOC_Offset;
                    823:        keys[2] = MDOC_Column;
                    824:
                    825:        vals[0] = vals[1] = vals[2] = -1;
                    826:
                    827:        width = offset = 0;
                    828:
                    829:        (void)arg_getattrs(keys, vals, 3, bl);
                    830:
                    831:        type = arg_listtype(bl);
                    832:
                    833:        /* Calculate real width and offset. */
                    834:
                    835:        switch (type) {
                    836:        case (MDOC_Column):
                    837:                if (MDOC_BODY == node->type)
                    838:                        break;
                    839:                for (i = 0, n = node->prev; n; n = n->prev, i++)
                    840:                        offset += arg_width
                    841:                                (&bl->args->argv[vals[2]], i);
                    842:                assert(i < (int)bl->args->argv[vals[2]].sz);
                    843:                width = arg_width(&bl->args->argv[vals[2]], i);
                    844:                if (vals[1] >= 0)
                    845:                        offset += arg_offset(&bl->args->argv[vals[1]]);
                    846:                break;
                    847:        default:
                    848:                if (vals[0] >= 0)
                    849:                        width = arg_width(&bl->args->argv[vals[0]], 0);
                    850:                if (vals[1] >= 0)
                    851:                        offset = arg_offset(&bl->args->argv[vals[1]]);
                    852:                break;
                    853:        }
                    854:
                    855:        /*
                    856:         * List-type can override the width in the case of fixed-head
                    857:         * values (bullet, dash/hyphen, enum).  Tags need a non-zero
                    858:         * offset.
                    859:         */
                    860:
                    861:        switch (type) {
                    862:        case (MDOC_Bullet):
                    863:                /* FALLTHROUGH */
                    864:        case (MDOC_Dash):
                    865:                /* FALLTHROUGH */
                    866:        case (MDOC_Enum):
                    867:                /* FALLTHROUGH */
                    868:        case (MDOC_Hyphen):
                    869:                if (width < 4)
                    870:                        width = 4;
                    871:                break;
                    872:        case (MDOC_Tag):
                    873:                if (0 == width)
                    874:                        width = 10;
                    875:                break;
                    876:        default:
                    877:                break;
                    878:        }
                    879:
                    880:        /*
                    881:         * Whitespace control.  Inset bodies need an initial space.
                    882:         */
                    883:
                    884:        switch (type) {
                    885:        case (MDOC_Diag):
                    886:                /* FALLTHROUGH */
                    887:        case (MDOC_Inset):
                    888:                if (MDOC_BODY == node->type)
                    889:                        p->flags &= ~TERMP_NOSPACE;
                    890:                else
                    891:                        p->flags |= TERMP_NOSPACE;
                    892:                break;
                    893:        default:
                    894:                p->flags |= TERMP_NOSPACE;
                    895:                break;
                    896:        }
                    897:
                    898:        /*
                    899:         * Style flags.  Diagnostic heads need TTYPE_DIAG.
                    900:         */
                    901:
                    902:        switch (type) {
                    903:        case (MDOC_Diag):
                    904:                if (MDOC_HEAD == node->type)
                    905:                        p->flags |= ttypes[TTYPE_DIAG];
                    906:                break;
                    907:        default:
                    908:                break;
                    909:        }
                    910:
                    911:        /*
                    912:         * Pad and break control.  This is the tricker part.  Lists with
                    913:         * set right-margins for the head get TERMP_NOBREAK because, if
                    914:         * they overrun the margin, they wrap to the new margin.
                    915:         * Correspondingly, the body for these types don't left-pad, as
                    916:         * the head will pad out to to the right.
                    917:         */
                    918:
                    919:        switch (type) {
                    920:        case (MDOC_Bullet):
                    921:                /* FALLTHROUGH */
                    922:        case (MDOC_Dash):
                    923:                /* FALLTHROUGH */
                    924:        case (MDOC_Enum):
                    925:                /* FALLTHROUGH */
                    926:        case (MDOC_Hyphen):
                    927:                /* FALLTHROUGH */
                    928:        case (MDOC_Tag):
                    929:                if (MDOC_HEAD == node->type)
                    930:                        p->flags |= TERMP_NOBREAK;
                    931:                else
                    932:                        p->flags |= TERMP_NOLPAD;
                    933:                if (MDOC_HEAD == node->type && MDOC_Tag == type)
                    934:                        if (NULL == node->next ||
                    935:                                        NULL == node->next->child)
                    936:                                p->flags |= TERMP_NONOBREAK;
                    937:                break;
                    938:        case (MDOC_Column):
                    939:                if (MDOC_HEAD == node->type) {
                    940:                        assert(node->next);
                    941:                        if (MDOC_BODY == node->next->type)
                    942:                                p->flags &= ~TERMP_NOBREAK;
                    943:                        else
                    944:                                p->flags |= TERMP_NOBREAK;
                    945:                        if (node->prev)
                    946:                                p->flags |= TERMP_NOLPAD;
                    947:                }
                    948:                break;
                    949:        case (MDOC_Diag):
                    950:                if (MDOC_HEAD == node->type)
                    951:                        p->flags |= TERMP_NOBREAK;
                    952:                break;
                    953:        default:
                    954:                break;
                    955:        }
                    956:
                    957:        /*
                    958:         * Margin control.  Set-head-width lists have their right
                    959:         * margins shortened.  The body for these lists has the offset
                    960:         * necessarily lengthened.  Everybody gets the offset.
                    961:         */
                    962:
                    963:        p->offset += offset;
                    964:
                    965:        switch (type) {
                    966:        case (MDOC_Bullet):
                    967:                /* FALLTHROUGH */
                    968:        case (MDOC_Dash):
                    969:                /* FALLTHROUGH */
                    970:        case (MDOC_Enum):
                    971:                /* FALLTHROUGH */
                    972:        case (MDOC_Hyphen):
                    973:                /* FALLTHROUGH */
                    974:        case (MDOC_Tag):
                    975:                if (MDOC_HEAD == node->type)
                    976:                        p->rmargin = p->offset + width;
                    977:                else
                    978:                        p->offset += width;
                    979:                break;
                    980:        case (MDOC_Column):
                    981:                p->rmargin = p->offset + width;
                    982:                break;
                    983:        default:
                    984:                break;
                    985:        }
                    986:
                    987:        /*
                    988:         * The dash, hyphen, bullet and enum lists all have a special
                    989:         * HEAD character.  Print it now.
                    990:         */
                    991:
                    992:        if (MDOC_HEAD == node->type)
                    993:                switch (type) {
                    994:                case (MDOC_Bullet):
                    995:                        term_word(p, "\\[bu]");
                    996:                        break;
                    997:                case (MDOC_Dash):
                    998:                        /* FALLTHROUGH */
                    999:                case (MDOC_Hyphen):
                   1000:                        term_word(p, "\\-");
                   1001:                        break;
                   1002:                case (MDOC_Enum):
                   1003:                        (pair->ppair->ppair->count)++;
                   1004:                        (void)snprintf(buf, sizeof(buf), "%d.",
                   1005:                                        pair->ppair->ppair->count);
                   1006:                        term_word(p, buf);
                   1007:                        break;
                   1008:                default:
                   1009:                        break;
                   1010:                }
                   1011:
                   1012:        /*
                   1013:         * If we're not going to process our children, indicate so here.
                   1014:         */
                   1015:
                   1016:        switch (type) {
                   1017:        case (MDOC_Bullet):
                   1018:                /* FALLTHROUGH */
                   1019:        case (MDOC_Item):
                   1020:                /* FALLTHROUGH */
                   1021:        case (MDOC_Dash):
                   1022:                /* FALLTHROUGH */
                   1023:        case (MDOC_Hyphen):
                   1024:                /* FALLTHROUGH */
                   1025:        case (MDOC_Enum):
                   1026:                if (MDOC_HEAD == node->type)
                   1027:                        return(0);
                   1028:                break;
                   1029:        case (MDOC_Column):
                   1030:                if (MDOC_BODY == node->type)
                   1031:                        return(0);
                   1032:                break;
                   1033:        default:
                   1034:                break;
                   1035:        }
                   1036:
                   1037:        return(1);
                   1038: }
                   1039:
                   1040:
                   1041: /* ARGSUSED */
                   1042: static void
                   1043: termp_it_post(DECL_ARGS)
                   1044: {
                   1045:        int                type;
                   1046:
                   1047:        if (MDOC_BODY != node->type && MDOC_HEAD != node->type)
                   1048:                return;
                   1049:
                   1050:        type = arg_listtype(node->parent->parent->parent);
                   1051:
                   1052:        switch (type) {
                   1053:        case (MDOC_Diag):
                   1054:                /* FALLTHROUGH */
                   1055:        case (MDOC_Item):
                   1056:                /* FALLTHROUGH */
                   1057:        case (MDOC_Inset):
                   1058:                if (MDOC_BODY == node->type)
                   1059:                        term_flushln(p);
                   1060:                break;
                   1061:        case (MDOC_Column):
                   1062:                if (MDOC_HEAD == node->type)
                   1063:                        term_flushln(p);
                   1064:                break;
                   1065:        default:
                   1066:                term_flushln(p);
                   1067:                break;
                   1068:        }
                   1069:
                   1070:        p->offset = pair->offset;
                   1071:        p->rmargin = pair->rmargin;
                   1072:        p->flags = pair->flag;
                   1073: }
                   1074:
                   1075:
                   1076: /* ARGSUSED */
                   1077: static int
                   1078: termp_nm_pre(DECL_ARGS)
                   1079: {
                   1080:
                   1081:        if (SEC_SYNOPSIS == node->sec)
                   1082:                term_newln(p);
                   1083:
                   1084:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_PROG]);
                   1085:        if (NULL == node->child)
                   1086:                term_word(p, meta->name);
                   1087:
                   1088:        return(1);
                   1089: }
                   1090:
                   1091:
                   1092: /* ARGSUSED */
                   1093: static int
                   1094: termp_fl_pre(DECL_ARGS)
                   1095: {
                   1096:
                   1097:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]);
                   1098:        term_word(p, "\\-");
                   1099:        p->flags |= TERMP_NOSPACE;
                   1100:        return(1);
                   1101: }
                   1102:
                   1103:
                   1104: /* ARGSUSED */
                   1105: static int
                   1106: termp_ar_pre(DECL_ARGS)
                   1107: {
                   1108:
                   1109:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_ARG]);
                   1110:        return(1);
                   1111: }
                   1112:
                   1113:
                   1114: /* ARGSUSED */
                   1115: static int
                   1116: termp_ns_pre(DECL_ARGS)
                   1117: {
                   1118:
                   1119:        p->flags |= TERMP_NOSPACE;
                   1120:        return(1);
                   1121: }
                   1122:
                   1123:
                   1124: /* ARGSUSED */
                   1125: static int
                   1126: termp_pp_pre(DECL_ARGS)
                   1127: {
                   1128:
                   1129:        term_vspace(p);
                   1130:        return(1);
                   1131: }
                   1132:
                   1133:
                   1134: /* ARGSUSED */
                   1135: static int
                   1136: termp_st_pre(DECL_ARGS)
                   1137: {
                   1138:        const char      *cp;
                   1139:
                   1140:        if (node->child && (cp = mdoc_a2st(node->child->string)))
                   1141:                term_word(p, cp);
                   1142:        return(0);
                   1143: }
                   1144:
                   1145:
                   1146: /* ARGSUSED */
                   1147: static int
                   1148: termp_rs_pre(DECL_ARGS)
                   1149: {
                   1150:
                   1151:        if (MDOC_BLOCK == node->type && node->prev)
                   1152:                term_vspace(p);
                   1153:        return(1);
                   1154: }
                   1155:
                   1156:
                   1157: /* ARGSUSED */
                   1158: static int
                   1159: termp_rv_pre(DECL_ARGS)
                   1160: {
                   1161:        int              i;
                   1162:
                   1163:        if (-1 == (i = arg_getattr(MDOC_Std, node)))
                   1164:                errx(1, "expected -std argument");
                   1165:        if (1 != node->args->argv[i].sz)
                   1166:                errx(1, "expected -std argument");
                   1167:
                   1168:        term_newln(p);
                   1169:        term_word(p, "The");
                   1170:
                   1171:        p->flags |= ttypes[TTYPE_FUNC_NAME];
                   1172:        term_word(p, *node->args->argv[i].value);
                   1173:        p->flags &= ~ttypes[TTYPE_FUNC_NAME];
                   1174:        p->flags |= TERMP_NOSPACE;
                   1175:
                   1176:                term_word(p, "() function returns the value 0 if successful;");
                   1177:                term_word(p, "otherwise the value -1 is returned and the");
                   1178:                term_word(p, "global variable");
                   1179:
                   1180:        p->flags |= ttypes[TTYPE_VAR_DECL];
                   1181:        term_word(p, "errno");
                   1182:        p->flags &= ~ttypes[TTYPE_VAR_DECL];
                   1183:
                   1184:                term_word(p, "is set to indicate the error.");
                   1185:
                   1186:        return(1);
                   1187: }
                   1188:
                   1189:
                   1190: /* ARGSUSED */
                   1191: static int
                   1192: termp_ex_pre(DECL_ARGS)
                   1193: {
                   1194:        int              i;
                   1195:
                   1196:        if (-1 == (i = arg_getattr(MDOC_Std, node)))
                   1197:                errx(1, "expected -std argument");
                   1198:        if (1 != node->args->argv[i].sz)
                   1199:                errx(1, "expected -std argument");
                   1200:
                   1201:        term_word(p, "The");
                   1202:        p->flags |= ttypes[TTYPE_PROG];
                   1203:        term_word(p, *node->args->argv[i].value);
                   1204:        p->flags &= ~ttypes[TTYPE_PROG];
                   1205:                term_word(p, "utility exits 0 on success, and >0 if an error occurs.");
                   1206:
                   1207:        return(1);
                   1208: }
                   1209:
                   1210:
                   1211: /* ARGSUSED */
                   1212: static int
                   1213: termp_nd_pre(DECL_ARGS)
                   1214: {
                   1215:
                   1216:        term_word(p, "\\-");
                   1217:        return(1);
                   1218: }
                   1219:
                   1220:
                   1221: /* ARGSUSED */
                   1222: static void
                   1223: termp_bl_post(DECL_ARGS)
                   1224: {
                   1225:
                   1226:        if (MDOC_BLOCK == node->type)
                   1227:                term_newln(p);
                   1228: }
                   1229:
                   1230:
                   1231: /* ARGSUSED */
                   1232: static void
                   1233: termp_op_post(DECL_ARGS)
                   1234: {
                   1235:
                   1236:        if (MDOC_BODY != node->type)
                   1237:                return;
                   1238:        p->flags |= TERMP_NOSPACE;
                   1239:        term_word(p, "\\(rB");
                   1240: }
                   1241:
                   1242:
                   1243: /* ARGSUSED */
                   1244: static int
                   1245: termp_xr_pre(DECL_ARGS)
                   1246: {
                   1247:        const struct mdoc_node *n;
                   1248:
                   1249:        if (NULL == (n = node->child))
                   1250:                errx(1, "expected text line argument");
                   1251:        term_word(p, n->string);
                   1252:        if (NULL == (n = n->next))
                   1253:                return(0);
                   1254:        p->flags |= TERMP_NOSPACE;
                   1255:        term_word(p, "(");
                   1256:        p->flags |= TERMP_NOSPACE;
                   1257:        term_word(p, n->string);
                   1258:        p->flags |= TERMP_NOSPACE;
                   1259:        term_word(p, ")");
                   1260:        return(0);
                   1261: }
                   1262:
                   1263:
                   1264: /* ARGSUSED */
                   1265: static int
                   1266: termp_vt_pre(DECL_ARGS)
                   1267: {
                   1268:
                   1269:        /* FIXME: this can be "type name". */
                   1270:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
                   1271:        return(1);
                   1272: }
                   1273:
                   1274:
                   1275: /* ARGSUSED */
                   1276: static void
                   1277: termp_vt_post(DECL_ARGS)
                   1278: {
                   1279:
                   1280:        if (node->sec == SEC_SYNOPSIS)
                   1281:                term_vspace(p);
                   1282: }
                   1283:
                   1284:
                   1285: /* ARGSUSED */
                   1286: static int
                   1287: termp_fd_pre(DECL_ARGS)
                   1288: {
                   1289:
                   1290:        /*
                   1291:         * FIXME: this naming is bad.  This value is used, in general,
                   1292:         * for the #include header or other preprocessor statement.
                   1293:         */
                   1294:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_DECL]);
                   1295:        return(1);
                   1296: }
                   1297:
                   1298:
                   1299: /* ARGSUSED */
                   1300: static void
                   1301: termp_fd_post(DECL_ARGS)
                   1302: {
                   1303:
                   1304:        if (node->sec != SEC_SYNOPSIS)
                   1305:                return;
                   1306:        term_newln(p);
                   1307:        if (node->next && MDOC_Fd != node->next->tok)
                   1308:                term_vspace(p);
                   1309: }
                   1310:
                   1311:
                   1312: /* ARGSUSED */
                   1313: static int
                   1314: termp_sh_pre(DECL_ARGS)
                   1315: {
                   1316:
                   1317:        switch (node->type) {
                   1318:        case (MDOC_HEAD):
                   1319:                term_vspace(p);
                   1320:                TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SECTION]);
                   1321:                break;
                   1322:        case (MDOC_BODY):
                   1323:                p->offset = INDENT;
                   1324:                break;
                   1325:        default:
                   1326:                break;
                   1327:        }
                   1328:        return(1);
                   1329: }
                   1330:
                   1331:
                   1332: /* ARGSUSED */
                   1333: static void
                   1334: termp_sh_post(DECL_ARGS)
                   1335: {
                   1336:
                   1337:        switch (node->type) {
                   1338:        case (MDOC_HEAD):
                   1339:                term_newln(p);
                   1340:                break;
                   1341:        case (MDOC_BODY):
                   1342:                term_newln(p);
                   1343:                p->offset = 0;
                   1344:                break;
                   1345:        default:
                   1346:                break;
                   1347:        }
                   1348: }
                   1349:
                   1350:
                   1351: /* ARGSUSED */
                   1352: static int
                   1353: termp_op_pre(DECL_ARGS)
                   1354: {
                   1355:
                   1356:        switch (node->type) {
                   1357:        case (MDOC_BODY):
                   1358:                term_word(p, "\\(lB");
                   1359:                p->flags |= TERMP_NOSPACE;
                   1360:                break;
                   1361:        default:
                   1362:                break;
                   1363:        }
                   1364:        return(1);
                   1365: }
                   1366:
                   1367:
                   1368: /* ARGSUSED */
                   1369: static int
                   1370: termp_bt_pre(DECL_ARGS)
                   1371: {
                   1372:
                   1373:        term_word(p, "is currently in beta test.");
                   1374:        return(1);
                   1375: }
                   1376:
                   1377:
                   1378: /* ARGSUSED */
                   1379: static int
                   1380: termp_lb_pre(DECL_ARGS)
                   1381: {
                   1382:        const char      *lb;
                   1383:
                   1384:        if (NULL == node->child)
                   1385:                errx(1, "expected text line argument");
                   1386:        if ((lb = mdoc_a2lib(node->child->string))) {
                   1387:                term_word(p, lb);
                   1388:                return(0);
                   1389:        }
                   1390:        term_word(p, "library");
                   1391:        return(1);
                   1392: }
                   1393:
                   1394:
                   1395: /* ARGSUSED */
                   1396: static void
                   1397: termp_lb_post(DECL_ARGS)
                   1398: {
                   1399:
                   1400:        term_newln(p);
                   1401: }
                   1402:
                   1403:
                   1404: /* ARGSUSED */
                   1405: static int
                   1406: termp_ud_pre(DECL_ARGS)
                   1407: {
                   1408:
                   1409:        term_word(p, "currently under development.");
                   1410:        return(1);
                   1411: }
                   1412:
                   1413:
                   1414: /* ARGSUSED */
                   1415: static int
                   1416: termp_d1_pre(DECL_ARGS)
                   1417: {
                   1418:
                   1419:        if (MDOC_BLOCK != node->type)
                   1420:                return(1);
                   1421:        term_newln(p);
                   1422:        p->offset += (pair->offset = INDENT);
                   1423:        return(1);
                   1424: }
                   1425:
                   1426:
                   1427: /* ARGSUSED */
                   1428: static void
                   1429: termp_d1_post(DECL_ARGS)
                   1430: {
                   1431:
                   1432:        if (MDOC_BLOCK != node->type)
                   1433:                return;
                   1434:        term_newln(p);
                   1435:        p->offset -= pair->offset;
                   1436: }
                   1437:
                   1438:
                   1439: /* ARGSUSED */
                   1440: static int
                   1441: termp_aq_pre(DECL_ARGS)
                   1442: {
                   1443:
                   1444:        if (MDOC_BODY != node->type)
                   1445:                return(1);
                   1446:        term_word(p, "\\(la");
                   1447:        p->flags |= TERMP_NOSPACE;
                   1448:        return(1);
                   1449: }
                   1450:
                   1451:
                   1452: /* ARGSUSED */
                   1453: static void
                   1454: termp_aq_post(DECL_ARGS)
                   1455: {
                   1456:
                   1457:        if (MDOC_BODY != node->type)
                   1458:                return;
                   1459:        p->flags |= TERMP_NOSPACE;
                   1460:        term_word(p, "\\(ra");
                   1461: }
                   1462:
                   1463:
                   1464: /* ARGSUSED */
                   1465: static int
                   1466: termp_ft_pre(DECL_ARGS)
                   1467: {
                   1468:
                   1469:        if (SEC_SYNOPSIS == node->sec)
                   1470:                if (node->prev && MDOC_Fo == node->prev->tok)
                   1471:                        term_vspace(p);
                   1472:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_TYPE]);
                   1473:        return(1);
                   1474: }
                   1475:
                   1476:
                   1477: /* ARGSUSED */
                   1478: static void
                   1479: termp_ft_post(DECL_ARGS)
                   1480: {
                   1481:
                   1482:        if (SEC_SYNOPSIS == node->sec)
                   1483:                term_newln(p);
                   1484: }
                   1485:
                   1486:
                   1487: /* ARGSUSED */
                   1488: static int
                   1489: termp_fn_pre(DECL_ARGS)
                   1490: {
                   1491:        const struct mdoc_node *n;
                   1492:
                   1493:        if (NULL == node->child)
                   1494:                errx(1, "expected text line arguments");
                   1495:
                   1496:        /* FIXME: can be "type funcname" "type varname"... */
                   1497:
                   1498:        p->flags |= ttypes[TTYPE_FUNC_NAME];
                   1499:        term_word(p, node->child->string);
                   1500:        p->flags &= ~ttypes[TTYPE_FUNC_NAME];
                   1501:
                   1502:        p->flags |= TERMP_NOSPACE;
                   1503:        term_word(p, "(");
                   1504:
                   1505:        for (n = node->child->next; n; n = n->next) {
                   1506:                p->flags |= ttypes[TTYPE_FUNC_ARG];
                   1507:                term_word(p, n->string);
                   1508:                p->flags &= ~ttypes[TTYPE_FUNC_ARG];
                   1509:                if (n->next)
                   1510:                        term_word(p, ",");
                   1511:        }
                   1512:
                   1513:        term_word(p, ")");
                   1514:
                   1515:        if (SEC_SYNOPSIS == node->sec)
                   1516:                term_word(p, ";");
                   1517:
                   1518:        return(0);
                   1519: }
                   1520:
                   1521:
                   1522: /* ARGSUSED */
                   1523: static void
                   1524: termp_fn_post(DECL_ARGS)
                   1525: {
                   1526:
                   1527:        if (node->sec == SEC_SYNOPSIS && node->next)
                   1528:                term_vspace(p);
                   1529:
                   1530: }
                   1531:
                   1532:
                   1533: /* ARGSUSED */
                   1534: static int
                   1535: termp_sx_pre(DECL_ARGS)
                   1536: {
                   1537:
                   1538:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK]);
                   1539:        return(1);
                   1540: }
                   1541:
                   1542:
                   1543: /* ARGSUSED */
                   1544: static int
                   1545: termp_fa_pre(DECL_ARGS)
                   1546: {
                   1547:        struct mdoc_node *n;
                   1548:
                   1549:        if (node->parent->tok != MDOC_Fo) {
                   1550:                TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_ARG]);
                   1551:                return(1);
                   1552:        }
                   1553:
                   1554:        for (n = node->child; n; n = n->next) {
                   1555:                p->flags |= ttypes[TTYPE_FUNC_ARG];
                   1556:                term_word(p, n->string);
                   1557:                p->flags &= ~ttypes[TTYPE_FUNC_ARG];
                   1558:                if (n->next)
                   1559:                        term_word(p, ",");
                   1560:        }
                   1561:
                   1562:        if (node->child && node->next && node->next->tok == MDOC_Fa)
                   1563:                term_word(p, ",");
                   1564:
                   1565:        return(0);
                   1566: }
                   1567:
                   1568:
                   1569: /* ARGSUSED */
                   1570: static int
                   1571: termp_va_pre(DECL_ARGS)
                   1572: {
                   1573:
                   1574:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
                   1575:        return(1);
                   1576: }
                   1577:
                   1578:
                   1579: /* ARGSUSED */
                   1580: static int
                   1581: termp_bd_pre(DECL_ARGS)
                   1582: {
                   1583:        int              i, type, ln;
                   1584:
                   1585:        /*
                   1586:         * This is fairly tricky due primarily to crappy documentation.
                   1587:         * If -ragged or -filled are specified, the block does nothing
                   1588:         * but change the indentation.
                   1589:         *
                   1590:         * If, on the other hand, -unfilled or -literal are specified,
                   1591:         * then the game changes.  Text is printed exactly as entered in
                   1592:         * the display: if a macro line, a newline is appended to the
                   1593:         * line.  Blank lines are allowed.
                   1594:         */
                   1595:
                   1596:        if (MDOC_BLOCK == node->type)
                   1597:                return(fmt_block_vspace(p, node, node));
                   1598:        else if (MDOC_BODY != node->type)
                   1599:                return(1);
                   1600:
                   1601:        if (NULL == node->parent->args)
                   1602:                errx(1, "missing display type");
                   1603:
                   1604:        pair->offset = p->offset;
                   1605:
                   1606:        for (type = -1, i = 0;
                   1607:                        i < (int)node->parent->args->argc; i++) {
                   1608:                switch (node->parent->args->argv[i].arg) {
                   1609:                case (MDOC_Ragged):
                   1610:                        /* FALLTHROUGH */
                   1611:                case (MDOC_Filled):
                   1612:                        /* FALLTHROUGH */
                   1613:                case (MDOC_Unfilled):
                   1614:                        /* FALLTHROUGH */
                   1615:                case (MDOC_Literal):
                   1616:                        type = node->parent->args->argv[i].arg;
                   1617:                        i = (int)node->parent->args->argc;
                   1618:                        break;
                   1619:                default:
                   1620:                        break;
                   1621:                }
                   1622:        }
                   1623:
                   1624:        if (NULL == node->parent->args)
                   1625:                errx(1, "missing display type");
                   1626:
                   1627:        i = arg_getattr(MDOC_Offset, node->parent);
                   1628:        if (-1 != i) {
                   1629:                if (1 != node->parent->args->argv[i].sz)
                   1630:                        errx(1, "expected single value");
                   1631:                p->offset += arg_offset(&node->parent->args->argv[i]);
                   1632:        }
                   1633:
                   1634:        switch (type) {
                   1635:        case (MDOC_Literal):
                   1636:                /* FALLTHROUGH */
                   1637:        case (MDOC_Unfilled):
                   1638:                break;
                   1639:        default:
                   1640:                return(1);
                   1641:        }
                   1642:
                   1643:        /*
                   1644:         * Tricky.  Iterate through all children.  If we're on a
                   1645:         * different parse line, append a newline and then the contents.
                   1646:         * Ew.
                   1647:         */
                   1648:
                   1649:        p->flags |= TERMP_LITERAL;
                   1650:        ln = node->child ? node->child->line : 0;
                   1651:
                   1652:        for (node = node->child; node; node = node->next) {
                   1653:                if (ln < node->line) {
                   1654:                        term_flushln(p);
                   1655:                        p->flags |= TERMP_NOSPACE;
                   1656:                }
                   1657:                ln = node->line;
                   1658:                print_node(p, pair, meta, node);
                   1659:        }
                   1660:
                   1661:        return(0);
                   1662: }
                   1663:
                   1664:
                   1665: /* ARGSUSED */
                   1666: static void
                   1667: termp_bd_post(DECL_ARGS)
                   1668: {
                   1669:
                   1670:        if (MDOC_BODY != node->type)
                   1671:                return;
                   1672:
                   1673:        term_flushln(p);
                   1674:        p->flags &= ~TERMP_LITERAL;
                   1675:        p->offset = pair->offset;
                   1676:        p->flags |= TERMP_NOSPACE;
                   1677: }
                   1678:
                   1679:
                   1680: /* ARGSUSED */
                   1681: static int
                   1682: termp_qq_pre(DECL_ARGS)
                   1683: {
                   1684:
                   1685:        if (MDOC_BODY != node->type)
                   1686:                return(1);
                   1687:        term_word(p, "\"");
                   1688:        p->flags |= TERMP_NOSPACE;
                   1689:        return(1);
                   1690: }
                   1691:
                   1692:
                   1693: /* ARGSUSED */
                   1694: static void
                   1695: termp_qq_post(DECL_ARGS)
                   1696: {
                   1697:
                   1698:        if (MDOC_BODY != node->type)
                   1699:                return;
                   1700:        p->flags |= TERMP_NOSPACE;
                   1701:        term_word(p, "\"");
                   1702: }
                   1703:
                   1704:
                   1705: /* ARGSUSED */
                   1706: static int
                   1707: termp_bsx_pre(DECL_ARGS)
                   1708: {
                   1709:
                   1710:        term_word(p, "BSDI BSD/OS");
                   1711:        return(1);
                   1712: }
                   1713:
                   1714:
                   1715: /* ARGSUSED */
                   1716: static void
                   1717: termp_bx_post(DECL_ARGS)
                   1718: {
                   1719:
                   1720:        if (node->child)
                   1721:                p->flags |= TERMP_NOSPACE;
                   1722:        term_word(p, "BSD");
                   1723: }
                   1724:
                   1725:
                   1726: /* FIXME: consolidate the following into termp_system. */
                   1727:
                   1728:
                   1729: /* ARGSUSED */
                   1730: static int
                   1731: termp_ox_pre(DECL_ARGS)
                   1732: {
                   1733:
                   1734:        term_word(p, "OpenBSD");
                   1735:        return(1);
                   1736: }
                   1737:
                   1738:
                   1739: /* ARGSUSED */
                   1740: static int
                   1741: termp_dx_pre(DECL_ARGS)
                   1742: {
                   1743:
                   1744:        term_word(p, "DragonFly");
                   1745:        return(1);
                   1746: }
                   1747:
                   1748:
                   1749: /* ARGSUSED */
                   1750: static int
                   1751: termp_ux_pre(DECL_ARGS)
                   1752: {
                   1753:
                   1754:        term_word(p, "UNIX");
                   1755:        return(1);
                   1756: }
                   1757:
                   1758:
                   1759: /* ARGSUSED */
                   1760: static int
                   1761: termp_fx_pre(DECL_ARGS)
                   1762: {
                   1763:
                   1764:        term_word(p, "FreeBSD");
                   1765:        return(1);
                   1766: }
                   1767:
                   1768:
                   1769: /* ARGSUSED */
                   1770: static int
                   1771: termp_nx_pre(DECL_ARGS)
                   1772: {
                   1773:
                   1774:        term_word(p, "NetBSD");
                   1775:        return(1);
                   1776: }
                   1777:
                   1778:
                   1779: /* ARGSUSED */
                   1780: static int
                   1781: termp_sq_pre(DECL_ARGS)
                   1782: {
                   1783:
                   1784:        if (MDOC_BODY != node->type)
                   1785:                return(1);
                   1786:        term_word(p, "\\(oq");
                   1787:        p->flags |= TERMP_NOSPACE;
                   1788:        return(1);
                   1789: }
                   1790:
                   1791:
                   1792: /* ARGSUSED */
                   1793: static void
                   1794: termp_sq_post(DECL_ARGS)
                   1795: {
                   1796:
                   1797:        if (MDOC_BODY != node->type)
                   1798:                return;
                   1799:        p->flags |= TERMP_NOSPACE;
                   1800:        term_word(p, "\\(aq");
                   1801: }
                   1802:
                   1803:
                   1804: /* ARGSUSED */
                   1805: static int
                   1806: termp_pf_pre(DECL_ARGS)
                   1807: {
                   1808:
                   1809:        p->flags |= TERMP_IGNDELIM;
                   1810:        return(1);
                   1811: }
                   1812:
                   1813:
                   1814: /* ARGSUSED */
                   1815: static void
                   1816: termp_pf_post(DECL_ARGS)
                   1817: {
                   1818:
                   1819:        p->flags &= ~TERMP_IGNDELIM;
                   1820:        p->flags |= TERMP_NOSPACE;
                   1821: }
                   1822:
                   1823:
                   1824: /* ARGSUSED */
                   1825: static int
                   1826: termp_ss_pre(DECL_ARGS)
                   1827: {
                   1828:
                   1829:        switch (node->type) {
                   1830:        case (MDOC_BLOCK):
                   1831:                term_newln(p);
                   1832:                if (node->prev)
                   1833:                        term_vspace(p);
                   1834:                break;
                   1835:        case (MDOC_HEAD):
                   1836:                TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SSECTION]);
                   1837:                p->offset = INDENT / 2;
                   1838:                break;
                   1839:        default:
                   1840:                break;
                   1841:        }
                   1842:
                   1843:        return(1);
                   1844: }
                   1845:
                   1846:
                   1847: /* ARGSUSED */
                   1848: static void
                   1849: termp_ss_post(DECL_ARGS)
                   1850: {
                   1851:
                   1852:        switch (node->type) {
                   1853:        case (MDOC_HEAD):
                   1854:                term_newln(p);
                   1855:                p->offset = INDENT;
                   1856:                break;
                   1857:        default:
                   1858:                break;
                   1859:        }
                   1860: }
                   1861:
                   1862:
                   1863: /* ARGSUSED */
                   1864: static int
                   1865: termp_pa_pre(DECL_ARGS)
                   1866: {
                   1867:
                   1868:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FILE]);
                   1869:        return(1);
                   1870: }
                   1871:
                   1872:
                   1873: /* ARGSUSED */
                   1874: static int
                   1875: termp_em_pre(DECL_ARGS)
                   1876: {
                   1877:
                   1878:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
                   1879:        return(1);
                   1880: }
                   1881:
                   1882:
                   1883: /* ARGSUSED */
                   1884: static int
                   1885: termp_cd_pre(DECL_ARGS)
                   1886: {
                   1887:
                   1888:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CONFIG]);
                   1889:        term_newln(p);
                   1890:        return(1);
                   1891: }
                   1892:
                   1893:
                   1894: /* ARGSUSED */
                   1895: static int
                   1896: termp_cm_pre(DECL_ARGS)
                   1897: {
                   1898:
                   1899:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]);
                   1900:        return(1);
                   1901: }
                   1902:
                   1903:
                   1904: /* ARGSUSED */
                   1905: static int
                   1906: termp_ic_pre(DECL_ARGS)
                   1907: {
                   1908:
                   1909:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD]);
                   1910:        return(1);
                   1911: }
                   1912:
                   1913:
                   1914: /* ARGSUSED */
                   1915: static int
                   1916: termp_in_pre(DECL_ARGS)
                   1917: {
                   1918:
                   1919:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_INCLUDE]);
                   1920:        term_word(p, "#include");
                   1921:        term_word(p, "<");
                   1922:        p->flags |= TERMP_NOSPACE;
                   1923:        return(1);
                   1924: }
                   1925:
                   1926:
                   1927: /* ARGSUSED */
                   1928: static void
                   1929: termp_in_post(DECL_ARGS)
                   1930: {
                   1931:
                   1932:        p->flags |= TERMP_NOSPACE;
                   1933:        term_word(p, ">");
                   1934:
                   1935:        term_newln(p);
                   1936:        if (SEC_SYNOPSIS != node->sec)
                   1937:                return;
                   1938:        if (node->next && MDOC_In != node->next->tok)
                   1939:                term_vspace(p);
                   1940: }
                   1941:
                   1942:
                   1943: /* ARGSUSED */
                   1944: static int
                   1945: termp_at_pre(DECL_ARGS)
                   1946: {
                   1947:        const char      *att;
                   1948:
                   1949:        att = NULL;
                   1950:
                   1951:        if (node->child)
                   1952:                att = mdoc_a2att(node->child->string);
                   1953:        if (NULL == att)
                   1954:                att = "AT&T UNIX";
                   1955:
                   1956:        term_word(p, att);
                   1957:        return(0);
                   1958: }
                   1959:
                   1960:
                   1961: /* ARGSUSED */
                   1962: static int
                   1963: termp_brq_pre(DECL_ARGS)
                   1964: {
                   1965:
                   1966:        if (MDOC_BODY != node->type)
                   1967:                return(1);
                   1968:        term_word(p, "\\(lC");
                   1969:        p->flags |= TERMP_NOSPACE;
                   1970:        return(1);
                   1971: }
                   1972:
                   1973:
                   1974: /* ARGSUSED */
                   1975: static void
                   1976: termp_brq_post(DECL_ARGS)
                   1977: {
                   1978:
                   1979:        if (MDOC_BODY != node->type)
                   1980:                return;
                   1981:        p->flags |= TERMP_NOSPACE;
                   1982:        term_word(p, "\\(rC");
                   1983: }
                   1984:
                   1985:
                   1986: /* ARGSUSED */
                   1987: static int
                   1988: termp_bq_pre(DECL_ARGS)
                   1989: {
                   1990:
                   1991:        if (MDOC_BODY != node->type)
                   1992:                return(1);
                   1993:        term_word(p, "\\(lB");
                   1994:        p->flags |= TERMP_NOSPACE;
                   1995:        return(1);
                   1996: }
                   1997:
                   1998:
                   1999: /* ARGSUSED */
                   2000: static void
                   2001: termp_bq_post(DECL_ARGS)
                   2002: {
                   2003:
                   2004:        if (MDOC_BODY != node->type)
                   2005:                return;
                   2006:        p->flags |= TERMP_NOSPACE;
                   2007:        term_word(p, "\\(rB");
                   2008: }
                   2009:
                   2010:
                   2011: /* ARGSUSED */
                   2012: static int
                   2013: termp_pq_pre(DECL_ARGS)
                   2014: {
                   2015:
                   2016:        if (MDOC_BODY != node->type)
                   2017:                return(1);
                   2018:        term_word(p, "\\&(");
                   2019:        p->flags |= TERMP_NOSPACE;
                   2020:        return(1);
                   2021: }
                   2022:
                   2023:
                   2024: /* ARGSUSED */
                   2025: static void
                   2026: termp_pq_post(DECL_ARGS)
                   2027: {
                   2028:
                   2029:        if (MDOC_BODY != node->type)
                   2030:                return;
                   2031:        term_word(p, ")");
                   2032: }
                   2033:
                   2034:
                   2035: /* ARGSUSED */
                   2036: static int
                   2037: termp_fo_pre(DECL_ARGS)
                   2038: {
                   2039:        const struct mdoc_node *n;
                   2040:
                   2041:        if (MDOC_BODY == node->type) {
                   2042:                term_word(p, "(");
                   2043:                p->flags |= TERMP_NOSPACE;
                   2044:                return(1);
                   2045:        } else if (MDOC_HEAD != node->type)
                   2046:                return(1);
                   2047:
                   2048:        /* XXX - groff shows only first parameter */
                   2049:
                   2050:        p->flags |= ttypes[TTYPE_FUNC_NAME];
                   2051:        for (n = node->child; n; n = n->next) {
                   2052:                if (MDOC_TEXT != n->type)
                   2053:                        errx(1, "expected text line argument");
                   2054:                term_word(p, n->string);
                   2055:        }
                   2056:        p->flags &= ~ttypes[TTYPE_FUNC_NAME];
                   2057:
                   2058:        return(0);
                   2059: }
                   2060:
                   2061:
                   2062: /* ARGSUSED */
                   2063: static void
                   2064: termp_fo_post(DECL_ARGS)
                   2065: {
                   2066:
                   2067:        if (MDOC_BODY != node->type)
                   2068:                return;
                   2069:        p->flags |= TERMP_NOSPACE;
                   2070:        term_word(p, ")");
                   2071:        p->flags |= TERMP_NOSPACE;
                   2072:        term_word(p, ";");
                   2073:        term_newln(p);
                   2074: }
                   2075:
                   2076:
                   2077: /* ARGSUSED */
                   2078: static int
                   2079: termp_bf_pre(DECL_ARGS)
                   2080: {
                   2081:        const struct mdoc_node  *n;
                   2082:
                   2083:        if (MDOC_HEAD == node->type) {
                   2084:                return(0);
                   2085:        } else if (MDOC_BLOCK != node->type)
                   2086:                return(1);
                   2087:
                   2088:        if (NULL == (n = node->head->child)) {
                   2089:                if (arg_hasattr(MDOC_Emphasis, node))
                   2090:                        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
                   2091:                else if (arg_hasattr(MDOC_Symbolic, node))
                   2092:                        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
                   2093:
                   2094:                return(1);
                   2095:        }
                   2096:
                   2097:        if (MDOC_TEXT != n->type)
                   2098:                errx(1, "expected text line arguments");
                   2099:
                   2100:        if (0 == strcmp("Em", n->string))
                   2101:                TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
                   2102:        else if (0 == strcmp("Sy", n->string))
                   2103:                TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
                   2104:
                   2105:        return(1);
                   2106: }
                   2107:
                   2108:
                   2109: /* ARGSUSED */
                   2110: static int
                   2111: termp_sy_pre(DECL_ARGS)
                   2112: {
                   2113:
                   2114:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
                   2115:        return(1);
                   2116: }
                   2117:
                   2118:
                   2119: /* ARGSUSED */
                   2120: static int
                   2121: termp_ms_pre(DECL_ARGS)
                   2122: {
                   2123:
                   2124:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMBOL]);
                   2125:        return(1);
                   2126: }
                   2127:
                   2128:
                   2129:
                   2130: /* ARGSUSED */
                   2131: static int
                   2132: termp_sm_pre(DECL_ARGS)
                   2133: {
                   2134:
                   2135:        if (NULL == node->child || MDOC_TEXT != node->child->type)
                   2136:                errx(1, "expected boolean line argument");
                   2137:
                   2138:        if (0 == strcmp("on", node->child->string)) {
                   2139:                p->flags &= ~TERMP_NONOSPACE;
                   2140:                p->flags &= ~TERMP_NOSPACE;
                   2141:        } else
                   2142:                p->flags |= TERMP_NONOSPACE;
                   2143:
                   2144:        return(0);
                   2145: }
                   2146:
                   2147:
                   2148: /* ARGSUSED */
                   2149: static int
                   2150: termp_ap_pre(DECL_ARGS)
                   2151: {
                   2152:
                   2153:        p->flags |= TERMP_NOSPACE;
                   2154:        term_word(p, "\\(aq");
                   2155:        p->flags |= TERMP_NOSPACE;
                   2156:        return(1);
                   2157: }
                   2158:
                   2159:
                   2160: /* ARGSUSED */
                   2161: static int
                   2162: termp__j_pre(DECL_ARGS)
                   2163: {
                   2164:
                   2165:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_REF_JOURNAL]);
                   2166:        return(1);
                   2167: }
                   2168:
                   2169:
                   2170: /* ARGSUSED */
                   2171: static int
                   2172: termp__t_pre(DECL_ARGS)
                   2173: {
                   2174:
                   2175:        term_word(p, "\"");
                   2176:        p->flags |= TERMP_NOSPACE;
                   2177:        return(1);
                   2178: }
                   2179:
                   2180:
                   2181: /* ARGSUSED */
                   2182: static void
                   2183: termp__t_post(DECL_ARGS)
                   2184: {
                   2185:
                   2186:        p->flags |= TERMP_NOSPACE;
                   2187:        term_word(p, "\"");
                   2188:        termp____post(p, pair, meta, node);
                   2189: }
                   2190:
                   2191:
                   2192: /* ARGSUSED */
                   2193: static void
                   2194: termp____post(DECL_ARGS)
                   2195: {
                   2196:
                   2197:        p->flags |= TERMP_NOSPACE;
                   2198:        term_word(p, node->next ? "," : ".");
                   2199: }
                   2200:
                   2201:
                   2202: /* ARGSUSED */
                   2203: static int
                   2204: termp_lk_pre(DECL_ARGS)
                   2205: {
                   2206:        const struct mdoc_node *n;
                   2207:
                   2208:        if (NULL == (n = node->child))
                   2209:                errx(1, "expected line argument");
                   2210:
                   2211:        p->flags |= ttypes[TTYPE_LINK_ANCHOR];
                   2212:        term_word(p, n->string);
                   2213:        p->flags &= ~ttypes[TTYPE_LINK_ANCHOR];
                   2214:        p->flags |= TERMP_NOSPACE;
                   2215:        term_word(p, ":");
                   2216:
                   2217:        p->flags |= ttypes[TTYPE_LINK_TEXT];
                   2218:        for ( ; n; n = n->next) {
                   2219:                term_word(p, n->string);
                   2220:        }
                   2221:        p->flags &= ~ttypes[TTYPE_LINK_TEXT];
                   2222:
                   2223:        return(0);
                   2224: }
                   2225:
                   2226:
                   2227: /* ARGSUSED */
                   2228: static int
                   2229: termp_mt_pre(DECL_ARGS)
                   2230: {
                   2231:
                   2232:        TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK_ANCHOR]);
                   2233:        return(1);
                   2234: }
                   2235:
                   2236: