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

Annotation of src/usr.bin/mandoc/mdoc_html.c, Revision 1.45

1.45    ! schwarze    1: /*     $Id: mdoc_html.c,v 1.44 2010/12/29 00:47:31 schwarze Exp $ */
1.1       schwarze    2: /*
1.25      schwarze    3:  * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       schwarze    4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      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.
                     16:  */
                     17: #include <sys/types.h>
                     18:
                     19: #include <assert.h>
                     20: #include <ctype.h>
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: #include <string.h>
                     24: #include <unistd.h>
                     25:
1.17      schwarze   26: #include "mandoc.h"
1.1       schwarze   27: #include "out.h"
                     28: #include "html.h"
                     29: #include "mdoc.h"
                     30: #include "main.h"
                     31:
                     32: #define        INDENT           5
                     33: #define        HALFINDENT       3
                     34:
                     35: #define        MDOC_ARGS         const struct mdoc_meta *m, \
                     36:                          const struct mdoc_node *n, \
                     37:                          struct html *h
                     38:
1.6       schwarze   39: #ifndef MIN
                     40: #define        MIN(a,b)        ((/*CONSTCOND*/(a)<(b))?(a):(b))
                     41: #endif
                     42:
1.1       schwarze   43: struct htmlmdoc {
                     44:        int             (*pre)(MDOC_ARGS);
                     45:        void            (*post)(MDOC_ARGS);
                     46: };
                     47:
                     48: static void              print_mdoc(MDOC_ARGS);
                     49: static void              print_mdoc_head(MDOC_ARGS);
                     50: static void              print_mdoc_node(MDOC_ARGS);
                     51: static void              print_mdoc_nodelist(MDOC_ARGS);
1.21      schwarze   52: static void              synopsis_pre(struct html *,
                     53:                                const struct mdoc_node *);
1.1       schwarze   54:
                     55: static void              a2width(const char *, struct roffsu *);
                     56: static void              a2offs(const char *, struct roffsu *);
                     57:
                     58: static void              mdoc_root_post(MDOC_ARGS);
                     59: static int               mdoc_root_pre(MDOC_ARGS);
                     60:
                     61: static void              mdoc__x_post(MDOC_ARGS);
                     62: static int               mdoc__x_pre(MDOC_ARGS);
                     63: static int               mdoc_ad_pre(MDOC_ARGS);
                     64: static int               mdoc_an_pre(MDOC_ARGS);
                     65: static int               mdoc_ap_pre(MDOC_ARGS);
                     66: static int               mdoc_ar_pre(MDOC_ARGS);
                     67: static int               mdoc_bd_pre(MDOC_ARGS);
                     68: static int               mdoc_bf_pre(MDOC_ARGS);
1.25      schwarze   69: static void              mdoc_bk_post(MDOC_ARGS);
                     70: static int               mdoc_bk_pre(MDOC_ARGS);
1.1       schwarze   71: static int               mdoc_bl_pre(MDOC_ARGS);
                     72: static int               mdoc_bt_pre(MDOC_ARGS);
                     73: static int               mdoc_bx_pre(MDOC_ARGS);
                     74: static int               mdoc_cd_pre(MDOC_ARGS);
                     75: static int               mdoc_d1_pre(MDOC_ARGS);
                     76: static int               mdoc_dv_pre(MDOC_ARGS);
                     77: static int               mdoc_fa_pre(MDOC_ARGS);
                     78: static int               mdoc_fd_pre(MDOC_ARGS);
                     79: static int               mdoc_fl_pre(MDOC_ARGS);
                     80: static int               mdoc_fn_pre(MDOC_ARGS);
                     81: static int               mdoc_ft_pre(MDOC_ARGS);
                     82: static int               mdoc_em_pre(MDOC_ARGS);
                     83: static int               mdoc_er_pre(MDOC_ARGS);
                     84: static int               mdoc_ev_pre(MDOC_ARGS);
                     85: static int               mdoc_ex_pre(MDOC_ARGS);
                     86: static void              mdoc_fo_post(MDOC_ARGS);
                     87: static int               mdoc_fo_pre(MDOC_ARGS);
                     88: static int               mdoc_ic_pre(MDOC_ARGS);
1.34      schwarze   89: static int               mdoc_igndelim_pre(MDOC_ARGS);
1.1       schwarze   90: static int               mdoc_in_pre(MDOC_ARGS);
                     91: static int               mdoc_it_pre(MDOC_ARGS);
                     92: static int               mdoc_lb_pre(MDOC_ARGS);
                     93: static int               mdoc_li_pre(MDOC_ARGS);
                     94: static int               mdoc_lk_pre(MDOC_ARGS);
                     95: static int               mdoc_mt_pre(MDOC_ARGS);
                     96: static int               mdoc_ms_pre(MDOC_ARGS);
                     97: static int               mdoc_nd_pre(MDOC_ARGS);
                     98: static int               mdoc_nm_pre(MDOC_ARGS);
                     99: static int               mdoc_ns_pre(MDOC_ARGS);
                    100: static int               mdoc_pa_pre(MDOC_ARGS);
                    101: static void              mdoc_pf_post(MDOC_ARGS);
1.40      schwarze  102: static int               mdoc_pp_pre(MDOC_ARGS);
1.32      schwarze  103: static void              mdoc_quote_post(MDOC_ARGS);
                    104: static int               mdoc_quote_pre(MDOC_ARGS);
1.1       schwarze  105: static int               mdoc_rs_pre(MDOC_ARGS);
                    106: static int               mdoc_rv_pre(MDOC_ARGS);
                    107: static int               mdoc_sh_pre(MDOC_ARGS);
1.26      schwarze  108: static int               mdoc_sm_pre(MDOC_ARGS);
1.1       schwarze  109: static int               mdoc_sp_pre(MDOC_ARGS);
                    110: static int               mdoc_ss_pre(MDOC_ARGS);
                    111: static int               mdoc_sx_pre(MDOC_ARGS);
                    112: static int               mdoc_sy_pre(MDOC_ARGS);
                    113: static int               mdoc_ud_pre(MDOC_ARGS);
                    114: static int               mdoc_va_pre(MDOC_ARGS);
                    115: static int               mdoc_vt_pre(MDOC_ARGS);
                    116: static int               mdoc_xr_pre(MDOC_ARGS);
                    117: static int               mdoc_xx_pre(MDOC_ARGS);
                    118:
                    119: static const struct htmlmdoc mdocs[MDOC_MAX] = {
                    120:        {mdoc_ap_pre, NULL}, /* Ap */
                    121:        {NULL, NULL}, /* Dd */
                    122:        {NULL, NULL}, /* Dt */
                    123:        {NULL, NULL}, /* Os */
                    124:        {mdoc_sh_pre, NULL }, /* Sh */
                    125:        {mdoc_ss_pre, NULL }, /* Ss */
1.40      schwarze  126:        {mdoc_pp_pre, NULL}, /* Pp */
1.1       schwarze  127:        {mdoc_d1_pre, NULL}, /* D1 */
                    128:        {mdoc_d1_pre, NULL}, /* Dl */
                    129:        {mdoc_bd_pre, NULL}, /* Bd */
                    130:        {NULL, NULL}, /* Ed */
1.40      schwarze  131:        {mdoc_bl_pre, NULL}, /* Bl */
1.1       schwarze  132:        {NULL, NULL}, /* El */
                    133:        {mdoc_it_pre, NULL}, /* It */
                    134:        {mdoc_ad_pre, NULL}, /* Ad */
                    135:        {mdoc_an_pre, NULL}, /* An */
                    136:        {mdoc_ar_pre, NULL}, /* Ar */
                    137:        {mdoc_cd_pre, NULL}, /* Cd */
                    138:        {mdoc_fl_pre, NULL}, /* Cm */
                    139:        {mdoc_dv_pre, NULL}, /* Dv */
                    140:        {mdoc_er_pre, NULL}, /* Er */
                    141:        {mdoc_ev_pre, NULL}, /* Ev */
                    142:        {mdoc_ex_pre, NULL}, /* Ex */
                    143:        {mdoc_fa_pre, NULL}, /* Fa */
1.21      schwarze  144:        {mdoc_fd_pre, NULL}, /* Fd */
1.1       schwarze  145:        {mdoc_fl_pre, NULL}, /* Fl */
                    146:        {mdoc_fn_pre, NULL}, /* Fn */
                    147:        {mdoc_ft_pre, NULL}, /* Ft */
                    148:        {mdoc_ic_pre, NULL}, /* Ic */
                    149:        {mdoc_in_pre, NULL}, /* In */
                    150:        {mdoc_li_pre, NULL}, /* Li */
                    151:        {mdoc_nd_pre, NULL}, /* Nd */
                    152:        {mdoc_nm_pre, NULL}, /* Nm */
1.32      schwarze  153:        {mdoc_quote_pre, mdoc_quote_post}, /* Op */
1.1       schwarze  154:        {NULL, NULL}, /* Ot */
                    155:        {mdoc_pa_pre, NULL}, /* Pa */
                    156:        {mdoc_rv_pre, NULL}, /* Rv */
                    157:        {NULL, NULL}, /* St */
                    158:        {mdoc_va_pre, NULL}, /* Va */
                    159:        {mdoc_vt_pre, NULL}, /* Vt */
                    160:        {mdoc_xr_pre, NULL}, /* Xr */
                    161:        {mdoc__x_pre, mdoc__x_post}, /* %A */
                    162:        {mdoc__x_pre, mdoc__x_post}, /* %B */
                    163:        {mdoc__x_pre, mdoc__x_post}, /* %D */
                    164:        {mdoc__x_pre, mdoc__x_post}, /* %I */
                    165:        {mdoc__x_pre, mdoc__x_post}, /* %J */
                    166:        {mdoc__x_pre, mdoc__x_post}, /* %N */
                    167:        {mdoc__x_pre, mdoc__x_post}, /* %O */
                    168:        {mdoc__x_pre, mdoc__x_post}, /* %P */
                    169:        {mdoc__x_pre, mdoc__x_post}, /* %R */
                    170:        {mdoc__x_pre, mdoc__x_post}, /* %T */
                    171:        {mdoc__x_pre, mdoc__x_post}, /* %V */
                    172:        {NULL, NULL}, /* Ac */
1.32      schwarze  173:        {mdoc_quote_pre, mdoc_quote_post}, /* Ao */
                    174:        {mdoc_quote_pre, mdoc_quote_post}, /* Aq */
1.1       schwarze  175:        {NULL, NULL}, /* At */
                    176:        {NULL, NULL}, /* Bc */
                    177:        {mdoc_bf_pre, NULL}, /* Bf */
1.32      schwarze  178:        {mdoc_quote_pre, mdoc_quote_post}, /* Bo */
                    179:        {mdoc_quote_pre, mdoc_quote_post}, /* Bq */
1.1       schwarze  180:        {mdoc_xx_pre, NULL}, /* Bsx */
                    181:        {mdoc_bx_pre, NULL}, /* Bx */
                    182:        {NULL, NULL}, /* Db */
                    183:        {NULL, NULL}, /* Dc */
1.32      schwarze  184:        {mdoc_quote_pre, mdoc_quote_post}, /* Do */
                    185:        {mdoc_quote_pre, mdoc_quote_post}, /* Dq */
1.11      schwarze  186:        {NULL, NULL}, /* Ec */ /* FIXME: no space */
1.1       schwarze  187:        {NULL, NULL}, /* Ef */
                    188:        {mdoc_em_pre, NULL}, /* Em */
                    189:        {NULL, NULL}, /* Eo */
                    190:        {mdoc_xx_pre, NULL}, /* Fx */
1.26      schwarze  191:        {mdoc_ms_pre, NULL}, /* Ms */
1.34      schwarze  192:        {mdoc_igndelim_pre, NULL}, /* No */
1.1       schwarze  193:        {mdoc_ns_pre, NULL}, /* Ns */
                    194:        {mdoc_xx_pre, NULL}, /* Nx */
                    195:        {mdoc_xx_pre, NULL}, /* Ox */
                    196:        {NULL, NULL}, /* Pc */
1.34      schwarze  197:        {mdoc_igndelim_pre, mdoc_pf_post}, /* Pf */
1.32      schwarze  198:        {mdoc_quote_pre, mdoc_quote_post}, /* Po */
                    199:        {mdoc_quote_pre, mdoc_quote_post}, /* Pq */
1.1       schwarze  200:        {NULL, NULL}, /* Qc */
1.32      schwarze  201:        {mdoc_quote_pre, mdoc_quote_post}, /* Ql */
                    202:        {mdoc_quote_pre, mdoc_quote_post}, /* Qo */
                    203:        {mdoc_quote_pre, mdoc_quote_post}, /* Qq */
1.1       schwarze  204:        {NULL, NULL}, /* Re */
                    205:        {mdoc_rs_pre, NULL}, /* Rs */
                    206:        {NULL, NULL}, /* Sc */
1.32      schwarze  207:        {mdoc_quote_pre, mdoc_quote_post}, /* So */
                    208:        {mdoc_quote_pre, mdoc_quote_post}, /* Sq */
1.26      schwarze  209:        {mdoc_sm_pre, NULL}, /* Sm */
1.1       schwarze  210:        {mdoc_sx_pre, NULL}, /* Sx */
                    211:        {mdoc_sy_pre, NULL}, /* Sy */
                    212:        {NULL, NULL}, /* Tn */
                    213:        {mdoc_xx_pre, NULL}, /* Ux */
                    214:        {NULL, NULL}, /* Xc */
                    215:        {NULL, NULL}, /* Xo */
                    216:        {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
                    217:        {NULL, NULL}, /* Fc */
1.32      schwarze  218:        {mdoc_quote_pre, mdoc_quote_post}, /* Oo */
1.1       schwarze  219:        {NULL, NULL}, /* Oc */
1.25      schwarze  220:        {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
1.1       schwarze  221:        {NULL, NULL}, /* Ek */
                    222:        {mdoc_bt_pre, NULL}, /* Bt */
                    223:        {NULL, NULL}, /* Hf */
                    224:        {NULL, NULL}, /* Fr */
                    225:        {mdoc_ud_pre, NULL}, /* Ud */
                    226:        {mdoc_lb_pre, NULL}, /* Lb */
1.40      schwarze  227:        {mdoc_pp_pre, NULL}, /* Lp */
1.1       schwarze  228:        {mdoc_lk_pre, NULL}, /* Lk */
                    229:        {mdoc_mt_pre, NULL}, /* Mt */
1.32      schwarze  230:        {mdoc_quote_pre, mdoc_quote_post}, /* Brq */
                    231:        {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
1.1       schwarze  232:        {NULL, NULL}, /* Brc */
                    233:        {mdoc__x_pre, mdoc__x_post}, /* %C */
                    234:        {NULL, NULL}, /* Es */  /* TODO */
                    235:        {NULL, NULL}, /* En */  /* TODO */
                    236:        {mdoc_xx_pre, NULL}, /* Dx */
                    237:        {mdoc__x_pre, mdoc__x_post}, /* %Q */
                    238:        {mdoc_sp_pre, NULL}, /* br */
                    239:        {mdoc_sp_pre, NULL}, /* sp */
1.2       schwarze  240:        {mdoc__x_pre, mdoc__x_post}, /* %U */
1.20      schwarze  241:        {NULL, NULL}, /* Ta */
1.1       schwarze  242: };
                    243:
1.40      schwarze  244: static const char * const lists[LIST_MAX] = {
                    245:        NULL,
                    246:        "list-bul",
                    247:        "list-col",
                    248:        "list-dash",
                    249:        "list-diag",
                    250:        "list-enum",
                    251:        "list-hang",
                    252:        "list-hyph",
                    253:        "list-inset",
                    254:        "list-item",
                    255:        "list-ohang",
                    256:        "list-tag"
                    257: };
1.1       schwarze  258:
                    259: void
                    260: html_mdoc(void *arg, const struct mdoc *m)
                    261: {
                    262:        struct html     *h;
                    263:        struct tag      *t;
                    264:
                    265:        h = (struct html *)arg;
                    266:
1.7       schwarze  267:        print_gen_decls(h);
1.1       schwarze  268:        t = print_otag(h, TAG_HTML, 0, NULL);
                    269:        print_mdoc(mdoc_meta(m), mdoc_node(m), h);
                    270:        print_tagq(h, t);
                    271:
                    272:        printf("\n");
                    273: }
                    274:
                    275:
                    276: /*
                    277:  * Calculate the scaling unit passed in a `-width' argument.  This uses
                    278:  * either a native scaling unit (e.g., 1i, 2m) or the string length of
                    279:  * the value.
                    280:  */
                    281: static void
                    282: a2width(const char *p, struct roffsu *su)
                    283: {
                    284:
                    285:        if ( ! a2roffsu(p, su, SCALE_MAX)) {
1.40      schwarze  286:                su->unit = SCALE_BU;
1.1       schwarze  287:                su->scale = (int)strlen(p);
                    288:        }
                    289: }
                    290:
                    291:
                    292: /*
1.21      schwarze  293:  * See the same function in mdoc_term.c for documentation.
                    294:  */
                    295: static void
                    296: synopsis_pre(struct html *h, const struct mdoc_node *n)
                    297: {
                    298:
1.23      schwarze  299:        if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1.21      schwarze  300:                return;
                    301:
                    302:        if (n->prev->tok == n->tok &&
                    303:                        MDOC_Fo != n->tok &&
                    304:                        MDOC_Ft != n->tok &&
                    305:                        MDOC_Fn != n->tok) {
1.40      schwarze  306:                print_otag(h, TAG_BR, 0, NULL);
1.21      schwarze  307:                return;
                    308:        }
                    309:
                    310:        switch (n->prev->tok) {
                    311:        case (MDOC_Fd):
                    312:                /* FALLTHROUGH */
                    313:        case (MDOC_Fn):
                    314:                /* FALLTHROUGH */
                    315:        case (MDOC_Fo):
                    316:                /* FALLTHROUGH */
                    317:        case (MDOC_In):
                    318:                /* FALLTHROUGH */
                    319:        case (MDOC_Vt):
1.40      schwarze  320:                print_otag(h, TAG_P, 0, NULL);
1.21      schwarze  321:                break;
                    322:        case (MDOC_Ft):
                    323:                if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1.40      schwarze  324:                        print_otag(h, TAG_P, 0, NULL);
1.21      schwarze  325:                        break;
                    326:                }
                    327:                /* FALLTHROUGH */
                    328:        default:
1.40      schwarze  329:                print_otag(h, TAG_BR, 0, NULL);
1.21      schwarze  330:                break;
                    331:        }
                    332: }
                    333:
                    334:
                    335: /*
1.1       schwarze  336:  * Calculate the scaling unit passed in an `-offset' argument.  This
                    337:  * uses either a native scaling unit (e.g., 1i, 2m), one of a set of
                    338:  * predefined strings (indent, etc.), or the string length of the value.
                    339:  */
                    340: static void
                    341: a2offs(const char *p, struct roffsu *su)
                    342: {
                    343:
                    344:        /* FIXME: "right"? */
                    345:
                    346:        if (0 == strcmp(p, "left"))
                    347:                SCALE_HS_INIT(su, 0);
                    348:        else if (0 == strcmp(p, "indent"))
                    349:                SCALE_HS_INIT(su, INDENT);
                    350:        else if (0 == strcmp(p, "indent-two"))
                    351:                SCALE_HS_INIT(su, INDENT * 2);
                    352:        else if ( ! a2roffsu(p, su, SCALE_MAX)) {
1.40      schwarze  353:                su->unit = SCALE_BU;
1.1       schwarze  354:                su->scale = (int)strlen(p);
                    355:        }
                    356: }
                    357:
                    358:
                    359: static void
                    360: print_mdoc(MDOC_ARGS)
                    361: {
                    362:        struct tag      *t;
                    363:
                    364:        t = print_otag(h, TAG_HEAD, 0, NULL);
                    365:        print_mdoc_head(m, n, h);
                    366:        print_tagq(h, t);
                    367:
                    368:        t = print_otag(h, TAG_BODY, 0, NULL);
                    369:        print_mdoc_nodelist(m, n, h);
                    370:        print_tagq(h, t);
                    371: }
                    372:
                    373:
                    374: /* ARGSUSED */
                    375: static void
                    376: print_mdoc_head(MDOC_ARGS)
                    377: {
                    378:
                    379:        print_gen_head(h);
                    380:        bufinit(h);
1.15      schwarze  381:        buffmt(h, "%s(%s)", m->title, m->msec);
1.1       schwarze  382:
                    383:        if (m->arch) {
                    384:                bufcat(h, " (");
                    385:                bufcat(h, m->arch);
                    386:                bufcat(h, ")");
                    387:        }
                    388:
                    389:        print_otag(h, TAG_TITLE, 0, NULL);
                    390:        print_text(h, h->buf);
                    391: }
                    392:
                    393:
                    394: static void
                    395: print_mdoc_nodelist(MDOC_ARGS)
                    396: {
                    397:
                    398:        print_mdoc_node(m, n, h);
                    399:        if (n->next)
                    400:                print_mdoc_nodelist(m, n->next, h);
                    401: }
                    402:
                    403:
                    404: static void
                    405: print_mdoc_node(MDOC_ARGS)
                    406: {
                    407:        int              child;
                    408:        struct tag      *t;
                    409:
                    410:        child = 1;
1.2       schwarze  411:        t = h->tags.head;
1.1       schwarze  412:
                    413:        bufinit(h);
                    414:        switch (n->type) {
                    415:        case (MDOC_ROOT):
                    416:                child = mdoc_root_pre(m, n, h);
                    417:                break;
                    418:        case (MDOC_TEXT):
                    419:                print_text(h, n->string);
1.5       schwarze  420:                return;
1.45    ! schwarze  421:        case (MDOC_TBL):
        !           422:                print_tbl(h, n->span);
        !           423:                break;
1.1       schwarze  424:        default:
1.25      schwarze  425:                if (mdocs[n->tok].pre && ENDBODY_NOT == n->end)
1.1       schwarze  426:                        child = (*mdocs[n->tok].pre)(m, n, h);
                    427:                break;
                    428:        }
                    429:
1.25      schwarze  430:        if (HTML_KEEP & h->flags) {
                    431:                if (n->prev && n->prev->line != n->line) {
                    432:                        h->flags &= ~HTML_KEEP;
                    433:                        h->flags |= HTML_PREKEEP;
                    434:                } else if (NULL == n->prev) {
                    435:                        if (n->parent && n->parent->line != n->line) {
                    436:                                h->flags &= ~HTML_KEEP;
                    437:                                h->flags |= HTML_PREKEEP;
                    438:                        }
                    439:                }
                    440:        }
                    441:
1.1       schwarze  442:        if (child && n->child)
                    443:                print_mdoc_nodelist(m, n->child, h);
                    444:
                    445:        print_stagq(h, t);
                    446:
                    447:        bufinit(h);
                    448:        switch (n->type) {
                    449:        case (MDOC_ROOT):
                    450:                mdoc_root_post(m, n, h);
1.45    ! schwarze  451:                break;
        !           452:        case (MDOC_TBL):
1.1       schwarze  453:                break;
                    454:        default:
1.25      schwarze  455:                if (mdocs[n->tok].post && ENDBODY_NOT == n->end)
1.1       schwarze  456:                        (*mdocs[n->tok].post)(m, n, h);
                    457:                break;
                    458:        }
                    459: }
                    460:
                    461: /* ARGSUSED */
                    462: static void
                    463: mdoc_root_post(MDOC_ARGS)
                    464: {
1.42      schwarze  465:        struct htmlpair  tag[3];
1.1       schwarze  466:        struct tag      *t, *tt;
1.2       schwarze  467:        char             b[DATESIZ];
                    468:
                    469:        time2a(m->date, b, DATESIZ);
1.1       schwarze  470:
1.42      schwarze  471:        PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
                    472:        PAIR_CLASS_INIT(&tag[1], "foot");
                    473:        if (NULL == h->style) {
1.43      schwarze  474:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    475:                t = print_otag(h, TAG_TABLE, 3, tag);
1.42      schwarze  476:                PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
                    477:                print_otag(h, TAG_COL, 1, tag);
                    478:                print_otag(h, TAG_COL, 1, tag);
                    479:        } else
                    480:                t = print_otag(h, TAG_TABLE, 2, tag);
                    481:
                    482:        t = print_otag(h, TAG_TBODY, 0, NULL);
1.3       schwarze  483:
1.1       schwarze  484:        tt = print_otag(h, TAG_TR, 0, NULL);
                    485:
1.40      schwarze  486:        PAIR_CLASS_INIT(&tag[0], "foot-date");
1.1       schwarze  487:        print_otag(h, TAG_TD, 1, tag);
1.40      schwarze  488:
1.1       schwarze  489:        print_text(h, b);
                    490:        print_stagq(h, tt);
                    491:
1.40      schwarze  492:        PAIR_CLASS_INIT(&tag[0], "foot-os");
1.42      schwarze  493:        if (NULL == h->style) {
                    494:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    495:                print_otag(h, TAG_TD, 2, tag);
                    496:        } else
                    497:                print_otag(h, TAG_TD, 1, tag);
1.40      schwarze  498:
1.1       schwarze  499:        print_text(h, m->os);
                    500:        print_tagq(h, t);
                    501: }
                    502:
                    503:
                    504: /* ARGSUSED */
                    505: static int
                    506: mdoc_root_pre(MDOC_ARGS)
                    507: {
1.3       schwarze  508:        struct htmlpair  tag[3];
1.1       schwarze  509:        struct tag      *t, *tt;
                    510:        char             b[BUFSIZ], title[BUFSIZ];
                    511:
1.40      schwarze  512:        strlcpy(b, m->vol, BUFSIZ);
1.1       schwarze  513:
                    514:        if (m->arch) {
1.40      schwarze  515:                strlcat(b, " (", BUFSIZ);
                    516:                strlcat(b, m->arch, BUFSIZ);
                    517:                strlcat(b, ")", BUFSIZ);
1.1       schwarze  518:        }
                    519:
1.40      schwarze  520:        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.1       schwarze  521:
1.42      schwarze  522:        PAIR_SUMMARY_INIT(&tag[0], "Document Header");
                    523:        PAIR_CLASS_INIT(&tag[1], "head");
                    524:        if (NULL == h->style) {
                    525:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    526:                t = print_otag(h, TAG_TABLE, 3, tag);
                    527:                PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
                    528:                print_otag(h, TAG_COL, 1, tag);
                    529:                print_otag(h, TAG_COL, 1, tag);
                    530:                print_otag(h, TAG_COL, 1, tag);
                    531:        } else
                    532:                t = print_otag(h, TAG_TABLE, 2, tag);
                    533:
                    534:        print_otag(h, TAG_TBODY, 0, NULL);
1.3       schwarze  535:
1.1       schwarze  536:        tt = print_otag(h, TAG_TR, 0, NULL);
                    537:
1.40      schwarze  538:        PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.1       schwarze  539:        print_otag(h, TAG_TD, 1, tag);
1.40      schwarze  540:
1.1       schwarze  541:        print_text(h, title);
                    542:        print_stagq(h, tt);
                    543:
1.40      schwarze  544:        PAIR_CLASS_INIT(&tag[0], "head-vol");
1.42      schwarze  545:        if (NULL == h->style) {
                    546:                PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
                    547:                print_otag(h, TAG_TD, 2, tag);
                    548:        } else
                    549:                print_otag(h, TAG_TD, 1, tag);
1.40      schwarze  550:
1.1       schwarze  551:        print_text(h, b);
                    552:        print_stagq(h, tt);
                    553:
1.40      schwarze  554:        PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.42      schwarze  555:        if (NULL == h->style) {
                    556:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    557:                print_otag(h, TAG_TD, 2, tag);
                    558:        } else
                    559:                print_otag(h, TAG_TD, 1, tag);
1.40      schwarze  560:
1.1       schwarze  561:        print_text(h, title);
                    562:        print_tagq(h, t);
                    563:        return(1);
                    564: }
                    565:
                    566:
                    567: /* ARGSUSED */
                    568: static int
                    569: mdoc_sh_pre(MDOC_ARGS)
                    570: {
1.40      schwarze  571:        struct htmlpair  tag;
                    572:        char             buf[BUFSIZ];
1.1       schwarze  573:
1.40      schwarze  574:        if (MDOC_BLOCK == n->type) {
                    575:                PAIR_CLASS_INIT(&tag, "section");
                    576:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  577:                return(1);
1.40      schwarze  578:        } else if (MDOC_BODY == n->type)
1.1       schwarze  579:                return(1);
                    580:
1.3       schwarze  581:        buf[0] = '\0';
1.40      schwarze  582:        for (n = n->child; n; n = n->next) {
                    583:                html_idcat(buf, n->string, BUFSIZ);
                    584:                if (n->next)
1.3       schwarze  585:                        html_idcat(buf, " ", BUFSIZ);
1.1       schwarze  586:        }
                    587:
1.40      schwarze  588:        PAIR_ID_INIT(&tag, buf);
                    589:        print_otag(h, TAG_H1, 1, &tag);
1.1       schwarze  590:        return(1);
                    591: }
                    592:
                    593:
                    594: /* ARGSUSED */
                    595: static int
                    596: mdoc_ss_pre(MDOC_ARGS)
                    597: {
1.40      schwarze  598:        struct htmlpair  tag;
                    599:        char             buf[BUFSIZ];
1.1       schwarze  600:
1.40      schwarze  601:        if (MDOC_BLOCK == n->type) {
                    602:                PAIR_CLASS_INIT(&tag, "subsection");
                    603:                print_otag(h, TAG_DIV, 1, &tag);
1.1       schwarze  604:                return(1);
1.40      schwarze  605:        } else if (MDOC_BODY == n->type)
1.1       schwarze  606:                return(1);
                    607:
1.3       schwarze  608:        buf[0] = '\0';
1.40      schwarze  609:        for (n = n->child; n; n = n->next) {
                    610:                html_idcat(buf, n->string, BUFSIZ);
                    611:                if (n->next)
1.3       schwarze  612:                        html_idcat(buf, " ", BUFSIZ);
1.1       schwarze  613:        }
                    614:
1.40      schwarze  615:        PAIR_ID_INIT(&tag, buf);
                    616:        print_otag(h, TAG_H2, 1, &tag);
1.1       schwarze  617:        return(1);
                    618: }
                    619:
                    620:
                    621: /* ARGSUSED */
                    622: static int
                    623: mdoc_fl_pre(MDOC_ARGS)
                    624: {
                    625:        struct htmlpair  tag;
                    626:
                    627:        PAIR_CLASS_INIT(&tag, "flag");
1.42      schwarze  628:        print_otag(h, TAG_B, 1, &tag);
1.6       schwarze  629:
                    630:        /* `Cm' has no leading hyphen. */
                    631:
                    632:        if (MDOC_Cm == n->tok)
                    633:                return(1);
                    634:
                    635:        print_text(h, "\\-");
                    636:
                    637:        if (n->child)
1.1       schwarze  638:                h->flags |= HTML_NOSPACE;
1.11      schwarze  639:        else if (n->next && n->next->line == n->line)
                    640:                h->flags |= HTML_NOSPACE;
1.6       schwarze  641:
1.1       schwarze  642:        return(1);
                    643: }
                    644:
                    645:
                    646: /* ARGSUSED */
                    647: static int
                    648: mdoc_nd_pre(MDOC_ARGS)
                    649: {
                    650:        struct htmlpair  tag;
                    651:
                    652:        if (MDOC_BODY != n->type)
                    653:                return(1);
                    654:
                    655:        /* XXX: this tag in theory can contain block elements. */
                    656:
                    657:        print_text(h, "\\(em");
1.40      schwarze  658:        PAIR_CLASS_INIT(&tag, "desc");
1.1       schwarze  659:        print_otag(h, TAG_SPAN, 1, &tag);
                    660:        return(1);
                    661: }
                    662:
                    663:
                    664: static int
                    665: mdoc_nm_pre(MDOC_ARGS)
                    666: {
1.25      schwarze  667:        struct htmlpair  tag;
                    668:        struct roffsu    su;
1.40      schwarze  669:        size_t           len;
1.25      schwarze  670:
1.40      schwarze  671:        switch (n->type) {
                    672:        case (MDOC_ELEM):
1.25      schwarze  673:                synopsis_pre(h, n);
                    674:                PAIR_CLASS_INIT(&tag, "name");
1.42      schwarze  675:                print_otag(h, TAG_B, 1, &tag);
1.40      schwarze  676:                if (NULL == n->child && m->name)
1.25      schwarze  677:                        print_text(h, m->name);
1.40      schwarze  678:                return(1);
                    679:        case (MDOC_HEAD):
                    680:                print_otag(h, TAG_TD, 0, NULL);
                    681:                if (NULL == n->child && m->name)
                    682:                        print_text(h, m->name);
                    683:                return(1);
                    684:        case (MDOC_BODY):
                    685:                print_otag(h, TAG_TD, 0, NULL);
                    686:                return(1);
                    687:        default:
                    688:                break;
                    689:        }
1.25      schwarze  690:
1.40      schwarze  691:        synopsis_pre(h, n);
                    692:        PAIR_CLASS_INIT(&tag, "synopsis");
                    693:        print_otag(h, TAG_TABLE, 1, &tag);
1.25      schwarze  694:
1.40      schwarze  695:        for (len = 0, n = n->child; n; n = n->next)
                    696:                if (MDOC_TEXT == n->type)
                    697:                        len += strlen(n->string);
1.25      schwarze  698:
1.40      schwarze  699:        if (0 == len && m->name)
                    700:                len = strlen(m->name);
1.1       schwarze  701:
1.40      schwarze  702:        SCALE_HS_INIT(&su, (double)len);
                    703:        bufcat_su(h, "width", &su);
                    704:        PAIR_STYLE_INIT(&tag, h);
                    705:        print_otag(h, TAG_COL, 1, &tag);
                    706:        print_otag(h, TAG_COL, 0, NULL);
                    707:        print_otag(h, TAG_TBODY, 0, NULL);
                    708:        print_otag(h, TAG_TR, 0, NULL);
1.1       schwarze  709:        return(1);
                    710: }
                    711:
                    712:
                    713: /* ARGSUSED */
                    714: static int
                    715: mdoc_xr_pre(MDOC_ARGS)
                    716: {
                    717:        struct htmlpair          tag[2];
                    718:        const struct mdoc_node  *nn;
1.9       schwarze  719:
                    720:        if (NULL == n->child)
                    721:                return(0);
1.1       schwarze  722:
                    723:        PAIR_CLASS_INIT(&tag[0], "link-man");
                    724:
                    725:        if (h->base_man) {
                    726:                buffmt_man(h, n->child->string,
                    727:                                n->child->next ?
                    728:                                n->child->next->string : NULL);
1.11      schwarze  729:                PAIR_HREF_INIT(&tag[1], h->buf);
1.1       schwarze  730:                print_otag(h, TAG_A, 2, tag);
                    731:        } else
                    732:                print_otag(h, TAG_A, 1, tag);
                    733:
                    734:        nn = n->child;
                    735:        print_text(h, nn->string);
                    736:
                    737:        if (NULL == (nn = nn->next))
                    738:                return(0);
                    739:
                    740:        h->flags |= HTML_NOSPACE;
                    741:        print_text(h, "(");
                    742:        h->flags |= HTML_NOSPACE;
                    743:        print_text(h, nn->string);
                    744:        h->flags |= HTML_NOSPACE;
                    745:        print_text(h, ")");
                    746:        return(0);
                    747: }
                    748:
                    749:
                    750: /* ARGSUSED */
                    751: static int
                    752: mdoc_ns_pre(MDOC_ARGS)
                    753: {
                    754:
                    755:        h->flags |= HTML_NOSPACE;
                    756:        return(1);
                    757: }
                    758:
                    759:
                    760: /* ARGSUSED */
                    761: static int
                    762: mdoc_ar_pre(MDOC_ARGS)
                    763: {
                    764:        struct htmlpair tag;
                    765:
                    766:        PAIR_CLASS_INIT(&tag, "arg");
1.42      schwarze  767:        print_otag(h, TAG_I, 1, &tag);
1.1       schwarze  768:        return(1);
                    769: }
                    770:
                    771:
                    772: /* ARGSUSED */
                    773: static int
                    774: mdoc_xx_pre(MDOC_ARGS)
                    775: {
                    776:        const char      *pp;
                    777:        struct htmlpair  tag;
                    778:
                    779:        switch (n->tok) {
                    780:        case (MDOC_Bsx):
1.37      schwarze  781:                pp = "BSD/OS";
1.1       schwarze  782:                break;
                    783:        case (MDOC_Dx):
1.4       schwarze  784:                pp = "DragonFly";
1.1       schwarze  785:                break;
                    786:        case (MDOC_Fx):
                    787:                pp = "FreeBSD";
                    788:                break;
                    789:        case (MDOC_Nx):
                    790:                pp = "NetBSD";
                    791:                break;
                    792:        case (MDOC_Ox):
                    793:                pp = "OpenBSD";
                    794:                break;
                    795:        case (MDOC_Ux):
                    796:                pp = "UNIX";
                    797:                break;
                    798:        default:
                    799:                return(1);
                    800:        }
                    801:
                    802:        PAIR_CLASS_INIT(&tag, "unix");
                    803:        print_otag(h, TAG_SPAN, 1, &tag);
                    804:        print_text(h, pp);
                    805:        return(1);
                    806: }
                    807:
                    808:
                    809: /* ARGSUSED */
                    810: static int
                    811: mdoc_bx_pre(MDOC_ARGS)
                    812: {
                    813:        const struct mdoc_node  *nn;
                    814:        struct htmlpair          tag;
                    815:
                    816:        PAIR_CLASS_INIT(&tag, "unix");
                    817:        print_otag(h, TAG_SPAN, 1, &tag);
                    818:
                    819:        for (nn = n->child; nn; nn = nn->next)
                    820:                print_mdoc_node(m, nn, h);
                    821:
                    822:        if (n->child)
                    823:                h->flags |= HTML_NOSPACE;
                    824:
                    825:        print_text(h, "BSD");
                    826:        return(0);
                    827: }
                    828:
                    829: static int
1.40      schwarze  830: mdoc_it_pre(MDOC_ARGS)
1.1       schwarze  831: {
1.40      schwarze  832:        struct roffsu    su;
                    833:        enum mdoc_list   type;
                    834:        struct htmlpair  tag[2];
                    835:        const struct mdoc_node *bl;
1.1       schwarze  836:
1.40      schwarze  837:        bl = n->parent;
                    838:        while (bl && MDOC_Bl != bl->tok)
                    839:                bl = bl->parent;
1.1       schwarze  840:
1.40      schwarze  841:        assert(bl);
1.1       schwarze  842:
1.44      schwarze  843:        type = bl->norm->Bl.type;
1.1       schwarze  844:
1.40      schwarze  845:        assert(lists[type]);
                    846:        PAIR_CLASS_INIT(&tag[0], lists[type]);
1.1       schwarze  847:
1.40      schwarze  848:        if (MDOC_HEAD == n->type) {
                    849:                switch (type) {
                    850:                case(LIST_bullet):
                    851:                        /* FALLTHROUGH */
                    852:                case(LIST_dash):
                    853:                        /* FALLTHROUGH */
                    854:                case(LIST_item):
                    855:                        /* FALLTHROUGH */
                    856:                case(LIST_hyphen):
                    857:                        /* FALLTHROUGH */
                    858:                case(LIST_enum):
                    859:                        return(0);
                    860:                case(LIST_diag):
                    861:                        /* FALLTHROUGH */
                    862:                case(LIST_hang):
                    863:                        /* FALLTHROUGH */
                    864:                case(LIST_inset):
                    865:                        /* FALLTHROUGH */
                    866:                case(LIST_ohang):
                    867:                        /* FALLTHROUGH */
                    868:                case(LIST_tag):
1.44      schwarze  869:                        SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40      schwarze  870:                        bufcat_su(h, "margin-top", &su);
                    871:                        PAIR_STYLE_INIT(&tag[1], h);
                    872:                        print_otag(h, TAG_DT, 2, tag);
1.42      schwarze  873:                        if (LIST_diag != type)
                    874:                                break;
                    875:                        PAIR_CLASS_INIT(&tag[0], "diag");
                    876:                        print_otag(h, TAG_B, 1, tag);
1.40      schwarze  877:                        break;
                    878:                case(LIST_column):
                    879:                        break;
                    880:                default:
                    881:                        break;
                    882:                }
                    883:        } else if (MDOC_BODY == n->type) {
                    884:                switch (type) {
                    885:                case(LIST_bullet):
                    886:                        /* FALLTHROUGH */
                    887:                case(LIST_hyphen):
                    888:                        /* FALLTHROUGH */
                    889:                case(LIST_dash):
                    890:                        /* FALLTHROUGH */
                    891:                case(LIST_enum):
                    892:                        /* FALLTHROUGH */
                    893:                case(LIST_item):
1.44      schwarze  894:                        SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40      schwarze  895:                        bufcat_su(h, "margin-top", &su);
                    896:                        PAIR_STYLE_INIT(&tag[1], h);
                    897:                        print_otag(h, TAG_LI, 2, tag);
                    898:                        break;
                    899:                case(LIST_diag):
                    900:                        /* FALLTHROUGH */
                    901:                case(LIST_hang):
                    902:                        /* FALLTHROUGH */
                    903:                case(LIST_inset):
                    904:                        /* FALLTHROUGH */
                    905:                case(LIST_ohang):
                    906:                        /* FALLTHROUGH */
                    907:                case(LIST_tag):
1.44      schwarze  908:                        if (NULL == bl->norm->Bl.width) {
1.40      schwarze  909:                                print_otag(h, TAG_DD, 1, tag);
                    910:                                break;
                    911:                        }
1.44      schwarze  912:                        a2width(bl->norm->Bl.width, &su);
1.40      schwarze  913:                        bufcat_su(h, "margin-left", &su);
                    914:                        PAIR_STYLE_INIT(&tag[1], h);
                    915:                        print_otag(h, TAG_DD, 2, tag);
                    916:                        break;
                    917:                case(LIST_column):
1.44      schwarze  918:                        SCALE_VS_INIT(&su, ! bl->norm->Bl.comp);
1.40      schwarze  919:                        bufcat_su(h, "margin-top", &su);
                    920:                        PAIR_STYLE_INIT(&tag[1], h);
                    921:                        print_otag(h, TAG_TD, 2, tag);
                    922:                        break;
                    923:                default:
                    924:                        break;
                    925:                }
                    926:        } else {
                    927:                switch (type) {
                    928:                case (LIST_column):
                    929:                        print_otag(h, TAG_TR, 1, tag);
                    930:                        break;
                    931:                default:
1.1       schwarze  932:                        break;
1.40      schwarze  933:                }
1.1       schwarze  934:        }
                    935:
                    936:        return(1);
                    937: }
                    938:
                    939: /* ARGSUSED */
                    940: static int
1.40      schwarze  941: mdoc_bl_pre(MDOC_ARGS)
1.1       schwarze  942: {
1.40      schwarze  943:        size_t           i;
                    944:        struct htmlpair  tag[3];
1.1       schwarze  945:        struct roffsu    su;
1.42      schwarze  946:        char             buf[BUFSIZ];
1.1       schwarze  947:
1.40      schwarze  948:        if (MDOC_BODY == n->type) {
1.44      schwarze  949:                if (LIST_column == n->norm->Bl.type)
1.40      schwarze  950:                        print_otag(h, TAG_TBODY, 0, NULL);
                    951:                return(1);
1.1       schwarze  952:        }
                    953:
1.40      schwarze  954:        if (MDOC_HEAD == n->type) {
1.44      schwarze  955:                if (LIST_column != n->norm->Bl.type)
1.40      schwarze  956:                        return(0);
1.1       schwarze  957:
1.40      schwarze  958:                /*
                    959:                 * For each column, print out the <COL> tag with our
                    960:                 * suggested width.  The last column gets min-width, as
                    961:                 * in terminal mode it auto-sizes to the width of the
                    962:                 * screen and we want to preserve that behaviour.
                    963:                 */
1.1       schwarze  964:
1.44      schwarze  965:                for (i = 0; i < n->norm->Bl.ncols; i++) {
                    966:                        a2width(n->norm->Bl.cols[i], &su);
1.40      schwarze  967:                        bufinit(h);
1.44      schwarze  968:                        if (i < n->norm->Bl.ncols - 1)
1.40      schwarze  969:                                bufcat_su(h, "width", &su);
                    970:                        else
                    971:                                bufcat_su(h, "min-width", &su);
                    972:                        PAIR_STYLE_INIT(&tag[0], h);
                    973:                        print_otag(h, TAG_COL, 1, tag);
                    974:                }
1.1       schwarze  975:
1.4       schwarze  976:                return(0);
1.1       schwarze  977:        }
                    978:
1.40      schwarze  979:        SCALE_VS_INIT(&su, 0);
                    980:        bufcat_su(h, "margin-top", &su);
                    981:        bufcat_su(h, "margin-bottom", &su);
                    982:        PAIR_STYLE_INIT(&tag[0], h);
1.1       schwarze  983:
1.44      schwarze  984:        assert(lists[n->norm->Bl.type]);
1.42      schwarze  985:        strlcpy(buf, "list ", BUFSIZ);
1.44      schwarze  986:        strlcat(buf, lists[n->norm->Bl.type], BUFSIZ);
1.42      schwarze  987:        PAIR_INIT(&tag[1], ATTR_CLASS, buf);
1.1       schwarze  988:
1.40      schwarze  989:        /* Set the block's left-hand margin. */
1.1       schwarze  990:
1.44      schwarze  991:        if (n->norm->Bl.offs) {
                    992:                a2offs(n->norm->Bl.offs, &su);
1.40      schwarze  993:                bufcat_su(h, "margin-left", &su);
                    994:        }
1.1       schwarze  995:
1.44      schwarze  996:        switch (n->norm->Bl.type) {
1.40      schwarze  997:        case(LIST_bullet):
1.1       schwarze  998:                /* FALLTHROUGH */
1.40      schwarze  999:        case(LIST_dash):
1.1       schwarze 1000:                /* FALLTHROUGH */
1.40      schwarze 1001:        case(LIST_hyphen):
1.1       schwarze 1002:                /* FALLTHROUGH */
1.40      schwarze 1003:        case(LIST_item):
1.42      schwarze 1004:                print_otag(h, TAG_UL, 2, tag);
1.1       schwarze 1005:                break;
1.40      schwarze 1006:        case(LIST_enum):
1.42      schwarze 1007:                print_otag(h, TAG_OL, 2, tag);
1.1       schwarze 1008:                break;
1.40      schwarze 1009:        case(LIST_diag):
                   1010:                /* FALLTHROUGH */
                   1011:        case(LIST_hang):
1.4       schwarze 1012:                /* FALLTHROUGH */
1.40      schwarze 1013:        case(LIST_inset):
1.1       schwarze 1014:                /* FALLTHROUGH */
1.40      schwarze 1015:        case(LIST_ohang):
1.1       schwarze 1016:                /* FALLTHROUGH */
1.40      schwarze 1017:        case(LIST_tag):
1.42      schwarze 1018:                print_otag(h, TAG_DL, 2, tag);
1.40      schwarze 1019:                break;
                   1020:        case(LIST_column):
1.42      schwarze 1021:                print_otag(h, TAG_TABLE, 2, tag);
1.1       schwarze 1022:                break;
                   1023:        default:
1.40      schwarze 1024:                abort();
                   1025:                /* NOTREACHED */
1.1       schwarze 1026:        }
                   1027:
                   1028:        return(1);
                   1029: }
                   1030:
                   1031: /* ARGSUSED */
                   1032: static int
                   1033: mdoc_ex_pre(MDOC_ARGS)
                   1034: {
                   1035:        const struct mdoc_node  *nn;
                   1036:        struct tag              *t;
                   1037:        struct htmlpair          tag;
                   1038:
1.40      schwarze 1039:        if (n->prev)
                   1040:                print_otag(h, TAG_BR, 0, NULL);
                   1041:
1.1       schwarze 1042:        PAIR_CLASS_INIT(&tag, "utility");
                   1043:
                   1044:        print_text(h, "The");
                   1045:        for (nn = n->child; nn; nn = nn->next) {
1.42      schwarze 1046:                t = print_otag(h, TAG_B, 1, &tag);
1.1       schwarze 1047:                print_text(h, nn->string);
                   1048:                print_tagq(h, t);
                   1049:
                   1050:                h->flags |= HTML_NOSPACE;
                   1051:
                   1052:                if (nn->next && NULL == nn->next->next)
                   1053:                        print_text(h, ", and");
                   1054:                else if (nn->next)
                   1055:                        print_text(h, ",");
                   1056:                else
                   1057:                        h->flags &= ~HTML_NOSPACE;
                   1058:        }
                   1059:
1.17      schwarze 1060:        if (n->child && n->child->next)
1.1       schwarze 1061:                print_text(h, "utilities exit");
                   1062:        else
                   1063:                print_text(h, "utility exits");
                   1064:
                   1065:                print_text(h, "0 on success, and >0 if an error occurs.");
                   1066:        return(0);
                   1067: }
                   1068:
                   1069:
                   1070: /* ARGSUSED */
                   1071: static int
                   1072: mdoc_em_pre(MDOC_ARGS)
                   1073: {
                   1074:        struct htmlpair tag;
                   1075:
                   1076:        PAIR_CLASS_INIT(&tag, "emph");
                   1077:        print_otag(h, TAG_SPAN, 1, &tag);
                   1078:        return(1);
                   1079: }
                   1080:
                   1081:
                   1082: /* ARGSUSED */
                   1083: static int
                   1084: mdoc_d1_pre(MDOC_ARGS)
                   1085: {
                   1086:        struct htmlpair  tag[2];
                   1087:        struct roffsu    su;
                   1088:
                   1089:        if (MDOC_BLOCK != n->type)
                   1090:                return(1);
                   1091:
1.40      schwarze 1092:        SCALE_VS_INIT(&su, 0);
                   1093:        bufcat_su(h, "margin-top", &su);
                   1094:        bufcat_su(h, "margin-bottom", &su);
                   1095:        PAIR_STYLE_INIT(&tag[0], h);
                   1096:        print_otag(h, TAG_BLOCKQUOTE, 1, tag);
                   1097:
                   1098:        /* BLOCKQUOTE needs a block body. */
1.1       schwarze 1099:
1.43      schwarze 1100:        PAIR_CLASS_INIT(&tag[0], "display");
                   1101:        print_otag(h, TAG_DIV, 1, tag);
                   1102:
                   1103:        if (MDOC_Dl == n->tok) {
                   1104:                PAIR_CLASS_INIT(&tag[0], "lit");
                   1105:                print_otag(h, TAG_CODE, 1, tag);
                   1106:        }
1.40      schwarze 1107:
1.1       schwarze 1108:        return(1);
                   1109: }
                   1110:
                   1111:
                   1112: /* ARGSUSED */
                   1113: static int
                   1114: mdoc_sx_pre(MDOC_ARGS)
                   1115: {
                   1116:        struct htmlpair          tag[2];
                   1117:        const struct mdoc_node  *nn;
                   1118:        char                     buf[BUFSIZ];
                   1119:
1.3       schwarze 1120:        strlcpy(buf, "#", BUFSIZ);
1.1       schwarze 1121:        for (nn = n->child; nn; nn = nn->next) {
1.3       schwarze 1122:                html_idcat(buf, nn->string, BUFSIZ);
1.1       schwarze 1123:                if (nn->next)
1.3       schwarze 1124:                        html_idcat(buf, " ", BUFSIZ);
1.1       schwarze 1125:        }
                   1126:
                   1127:        PAIR_CLASS_INIT(&tag[0], "link-sec");
1.11      schwarze 1128:        PAIR_HREF_INIT(&tag[1], buf);
1.1       schwarze 1129:
1.42      schwarze 1130:        print_otag(h, TAG_I, 1, tag);
1.1       schwarze 1131:        print_otag(h, TAG_A, 2, tag);
                   1132:        return(1);
                   1133: }
                   1134:
                   1135:
                   1136: /* ARGSUSED */
                   1137: static int
                   1138: mdoc_bd_pre(MDOC_ARGS)
                   1139: {
                   1140:        struct htmlpair          tag[2];
1.22      schwarze 1141:        int                      comp;
                   1142:        const struct mdoc_node  *nn;
1.1       schwarze 1143:        struct roffsu            su;
                   1144:
1.22      schwarze 1145:        if (MDOC_HEAD == n->type)
1.1       schwarze 1146:                return(0);
                   1147:
                   1148:        if (MDOC_BLOCK == n->type) {
1.44      schwarze 1149:                comp = n->norm->Bd.comp;
1.1       schwarze 1150:                for (nn = n; nn && ! comp; nn = nn->parent) {
                   1151:                        if (MDOC_BLOCK != nn->type)
                   1152:                                continue;
                   1153:                        if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                   1154:                                comp = 1;
                   1155:                        if (nn->prev)
                   1156:                                break;
                   1157:                }
1.40      schwarze 1158:                if ( ! comp)
                   1159:                        print_otag(h, TAG_P, 0, NULL);
1.1       schwarze 1160:                return(1);
                   1161:        }
                   1162:
1.40      schwarze 1163:        SCALE_HS_INIT(&su, 0);
1.44      schwarze 1164:        if (n->norm->Bd.offs)
                   1165:                a2offs(n->norm->Bd.offs, &su);
1.40      schwarze 1166:
                   1167:        bufcat_su(h, "margin-left", &su);
                   1168:        PAIR_STYLE_INIT(&tag[0], h);
                   1169:
1.44      schwarze 1170:        if (DISP_unfilled != n->norm->Bd.type &&
                   1171:                        DISP_literal != n->norm->Bd.type) {
1.40      schwarze 1172:                PAIR_CLASS_INIT(&tag[1], "display");
                   1173:                print_otag(h, TAG_DIV, 2, tag);
1.1       schwarze 1174:                return(1);
1.40      schwarze 1175:        }
1.1       schwarze 1176:
1.40      schwarze 1177:        PAIR_CLASS_INIT(&tag[1], "lit display");
                   1178:        print_otag(h, TAG_PRE, 2, tag);
1.1       schwarze 1179:
                   1180:        for (nn = n->child; nn; nn = nn->next) {
                   1181:                print_mdoc_node(m, nn, h);
1.33      schwarze 1182:                /*
                   1183:                 * If the printed node flushes its own line, then we
                   1184:                 * needn't do it here as well.  This is hacky, but the
                   1185:                 * notion of selective eoln whitespace is pretty dumb
                   1186:                 * anyway, so don't sweat it.
                   1187:                 */
                   1188:                switch (nn->tok) {
1.36      schwarze 1189:                case (MDOC_Sm):
                   1190:                        /* FALLTHROUGH */
1.33      schwarze 1191:                case (MDOC_br):
                   1192:                        /* FALLTHROUGH */
                   1193:                case (MDOC_sp):
                   1194:                        /* FALLTHROUGH */
                   1195:                case (MDOC_Bl):
1.39      schwarze 1196:                        /* FALLTHROUGH */
                   1197:                case (MDOC_D1):
                   1198:                        /* FALLTHROUGH */
                   1199:                case (MDOC_Dl):
1.33      schwarze 1200:                        /* FALLTHROUGH */
                   1201:                case (MDOC_Lp):
                   1202:                        /* FALLTHROUGH */
                   1203:                case (MDOC_Pp):
                   1204:                        continue;
                   1205:                default:
                   1206:                        break;
                   1207:                }
1.28      schwarze 1208:                if (nn->next && nn->next->line == nn->line)
                   1209:                        continue;
1.40      schwarze 1210:                else if (nn->next)
                   1211:                        print_text(h, "\n");
                   1212:
1.28      schwarze 1213:                h->flags |= HTML_NOSPACE;
1.1       schwarze 1214:        }
                   1215:
                   1216:        return(0);
                   1217: }
                   1218:
                   1219:
                   1220: /* ARGSUSED */
                   1221: static int
                   1222: mdoc_pa_pre(MDOC_ARGS)
                   1223: {
                   1224:        struct htmlpair tag;
                   1225:
                   1226:        PAIR_CLASS_INIT(&tag, "file");
1.42      schwarze 1227:        print_otag(h, TAG_I, 1, &tag);
1.1       schwarze 1228:        return(1);
                   1229: }
                   1230:
                   1231:
                   1232: /* ARGSUSED */
                   1233: static int
                   1234: mdoc_ad_pre(MDOC_ARGS)
                   1235: {
                   1236:        struct htmlpair tag;
                   1237:
                   1238:        PAIR_CLASS_INIT(&tag, "addr");
1.42      schwarze 1239:        print_otag(h, TAG_I, 1, &tag);
1.1       schwarze 1240:        return(1);
                   1241: }
                   1242:
                   1243:
                   1244: /* ARGSUSED */
                   1245: static int
                   1246: mdoc_an_pre(MDOC_ARGS)
                   1247: {
                   1248:        struct htmlpair tag;
                   1249:
                   1250:        /* TODO: -split and -nosplit (see termp_an_pre()). */
                   1251:
                   1252:        PAIR_CLASS_INIT(&tag, "author");
                   1253:        print_otag(h, TAG_SPAN, 1, &tag);
                   1254:        return(1);
                   1255: }
                   1256:
                   1257:
                   1258: /* ARGSUSED */
                   1259: static int
                   1260: mdoc_cd_pre(MDOC_ARGS)
                   1261: {
                   1262:        struct htmlpair tag;
                   1263:
1.21      schwarze 1264:        synopsis_pre(h, n);
1.1       schwarze 1265:        PAIR_CLASS_INIT(&tag, "config");
1.42      schwarze 1266:        print_otag(h, TAG_B, 1, &tag);
1.1       schwarze 1267:        return(1);
                   1268: }
                   1269:
                   1270:
                   1271: /* ARGSUSED */
                   1272: static int
                   1273: mdoc_dv_pre(MDOC_ARGS)
                   1274: {
                   1275:        struct htmlpair tag;
                   1276:
                   1277:        PAIR_CLASS_INIT(&tag, "define");
                   1278:        print_otag(h, TAG_SPAN, 1, &tag);
                   1279:        return(1);
                   1280: }
                   1281:
                   1282:
                   1283: /* ARGSUSED */
                   1284: static int
                   1285: mdoc_ev_pre(MDOC_ARGS)
                   1286: {
                   1287:        struct htmlpair tag;
                   1288:
                   1289:        PAIR_CLASS_INIT(&tag, "env");
                   1290:        print_otag(h, TAG_SPAN, 1, &tag);
                   1291:        return(1);
                   1292: }
                   1293:
                   1294:
                   1295: /* ARGSUSED */
                   1296: static int
                   1297: mdoc_er_pre(MDOC_ARGS)
                   1298: {
                   1299:        struct htmlpair tag;
                   1300:
                   1301:        PAIR_CLASS_INIT(&tag, "errno");
                   1302:        print_otag(h, TAG_SPAN, 1, &tag);
                   1303:        return(1);
                   1304: }
                   1305:
                   1306:
                   1307: /* ARGSUSED */
                   1308: static int
                   1309: mdoc_fa_pre(MDOC_ARGS)
                   1310: {
                   1311:        const struct mdoc_node  *nn;
                   1312:        struct htmlpair          tag;
                   1313:        struct tag              *t;
                   1314:
                   1315:        PAIR_CLASS_INIT(&tag, "farg");
                   1316:        if (n->parent->tok != MDOC_Fo) {
1.42      schwarze 1317:                print_otag(h, TAG_I, 1, &tag);
1.1       schwarze 1318:                return(1);
                   1319:        }
                   1320:
                   1321:        for (nn = n->child; nn; nn = nn->next) {
1.42      schwarze 1322:                t = print_otag(h, TAG_I, 1, &tag);
1.1       schwarze 1323:                print_text(h, nn->string);
                   1324:                print_tagq(h, t);
                   1325:                if (nn->next)
                   1326:                        print_text(h, ",");
                   1327:        }
                   1328:
                   1329:        if (n->child && n->next && n->next->tok == MDOC_Fa)
                   1330:                print_text(h, ",");
                   1331:
                   1332:        return(0);
                   1333: }
                   1334:
                   1335:
                   1336: /* ARGSUSED */
                   1337: static int
                   1338: mdoc_fd_pre(MDOC_ARGS)
                   1339: {
                   1340:        struct htmlpair  tag;
                   1341:
1.21      schwarze 1342:        synopsis_pre(h, n);
                   1343:
1.1       schwarze 1344:        PAIR_CLASS_INIT(&tag, "macro");
1.42      schwarze 1345:        print_otag(h, TAG_B, 1, &tag);
1.1       schwarze 1346:        return(1);
                   1347: }
                   1348:
                   1349:
                   1350: /* ARGSUSED */
                   1351: static int
                   1352: mdoc_vt_pre(MDOC_ARGS)
                   1353: {
                   1354:        struct htmlpair  tag;
                   1355:
1.21      schwarze 1356:        if (MDOC_BLOCK == n->type) {
                   1357:                synopsis_pre(h, n);
1.7       schwarze 1358:                return(1);
1.21      schwarze 1359:        } else if (MDOC_ELEM == n->type) {
                   1360:                synopsis_pre(h, n);
1.7       schwarze 1361:        } else if (MDOC_HEAD == n->type)
                   1362:                return(0);
1.1       schwarze 1363:
                   1364:        PAIR_CLASS_INIT(&tag, "type");
                   1365:        print_otag(h, TAG_SPAN, 1, &tag);
                   1366:        return(1);
                   1367: }
                   1368:
                   1369:
                   1370: /* ARGSUSED */
                   1371: static int
                   1372: mdoc_ft_pre(MDOC_ARGS)
                   1373: {
                   1374:        struct htmlpair  tag;
                   1375:
1.21      schwarze 1376:        synopsis_pre(h, n);
1.1       schwarze 1377:        PAIR_CLASS_INIT(&tag, "ftype");
1.42      schwarze 1378:        print_otag(h, TAG_I, 1, &tag);
1.1       schwarze 1379:        return(1);
                   1380: }
                   1381:
                   1382:
                   1383: /* ARGSUSED */
                   1384: static int
                   1385: mdoc_fn_pre(MDOC_ARGS)
                   1386: {
                   1387:        struct tag              *t;
                   1388:        struct htmlpair          tag[2];
                   1389:        const struct mdoc_node  *nn;
                   1390:        char                     nbuf[BUFSIZ];
                   1391:        const char              *sp, *ep;
                   1392:        int                      sz, i;
                   1393:
1.21      schwarze 1394:        synopsis_pre(h, n);
1.1       schwarze 1395:
                   1396:        /* Split apart into type and name. */
                   1397:        assert(n->child->string);
                   1398:        sp = n->child->string;
                   1399:
                   1400:        ep = strchr(sp, ' ');
                   1401:        if (NULL != ep) {
                   1402:                PAIR_CLASS_INIT(&tag[0], "ftype");
1.42      schwarze 1403:                t = print_otag(h, TAG_I, 1, tag);
1.1       schwarze 1404:
                   1405:                while (ep) {
                   1406:                        sz = MIN((int)(ep - sp), BUFSIZ - 1);
                   1407:                        (void)memcpy(nbuf, sp, (size_t)sz);
                   1408:                        nbuf[sz] = '\0';
                   1409:                        print_text(h, nbuf);
                   1410:                        sp = ++ep;
                   1411:                        ep = strchr(sp, ' ');
                   1412:                }
                   1413:                print_tagq(h, t);
                   1414:        }
                   1415:
                   1416:        PAIR_CLASS_INIT(&tag[0], "fname");
1.11      schwarze 1417:
                   1418:        /*
                   1419:         * FIXME: only refer to IDs that we know exist.
                   1420:         */
                   1421:
                   1422: #if 0
1.23      schwarze 1423:        if (MDOC_SYNPRETTY & n->flags) {
1.11      schwarze 1424:                nbuf[0] = '\0';
                   1425:                html_idcat(nbuf, sp, BUFSIZ);
                   1426:                PAIR_ID_INIT(&tag[1], nbuf);
                   1427:        } else {
                   1428:                strlcpy(nbuf, "#", BUFSIZ);
                   1429:                html_idcat(nbuf, sp, BUFSIZ);
                   1430:                PAIR_HREF_INIT(&tag[1], nbuf);
                   1431:        }
                   1432: #endif
                   1433:
1.42      schwarze 1434:        t = print_otag(h, TAG_B, 1, tag);
1.1       schwarze 1435:
                   1436:        if (sp) {
1.11      schwarze 1437:                strlcpy(nbuf, sp, BUFSIZ);
1.1       schwarze 1438:                print_text(h, nbuf);
                   1439:        }
                   1440:
                   1441:        print_tagq(h, t);
                   1442:
                   1443:        h->flags |= HTML_NOSPACE;
                   1444:        print_text(h, "(");
                   1445:
                   1446:        bufinit(h);
                   1447:        PAIR_CLASS_INIT(&tag[0], "farg");
                   1448:        bufcat_style(h, "white-space", "nowrap");
                   1449:        PAIR_STYLE_INIT(&tag[1], h);
                   1450:
                   1451:        for (nn = n->child->next; nn; nn = nn->next) {
                   1452:                i = 1;
1.23      schwarze 1453:                if (MDOC_SYNPRETTY & n->flags)
1.1       schwarze 1454:                        i = 2;
1.42      schwarze 1455:                t = print_otag(h, TAG_I, i, tag);
1.1       schwarze 1456:                print_text(h, nn->string);
                   1457:                print_tagq(h, t);
                   1458:                if (nn->next)
                   1459:                        print_text(h, ",");
                   1460:        }
                   1461:
                   1462:        print_text(h, ")");
1.23      schwarze 1463:        if (MDOC_SYNPRETTY & n->flags)
1.1       schwarze 1464:                print_text(h, ";");
                   1465:
                   1466:        return(0);
                   1467: }
                   1468:
                   1469:
                   1470: /* ARGSUSED */
                   1471: static int
1.26      schwarze 1472: mdoc_sm_pre(MDOC_ARGS)
                   1473: {
                   1474:
                   1475:        assert(n->child && MDOC_TEXT == n->child->type);
                   1476:        if (0 == strcmp("on", n->child->string)) {
1.36      schwarze 1477:                /*
                   1478:                 * FIXME: no p->col to check.  Thus, if we have
                   1479:                 *  .Bd -literal
                   1480:                 *  .Sm off
                   1481:                 *  1 2
                   1482:                 *  .Sm on
                   1483:                 *  3
                   1484:                 *  .Ed
                   1485:                 * the "3" is preceded by a space.
                   1486:                 */
1.26      schwarze 1487:                h->flags &= ~HTML_NOSPACE;
                   1488:                h->flags &= ~HTML_NONOSPACE;
                   1489:        } else
                   1490:                h->flags |= HTML_NONOSPACE;
                   1491:
                   1492:        return(0);
                   1493: }
                   1494:
1.40      schwarze 1495: /* ARGSUSED */
                   1496: static int
                   1497: mdoc_pp_pre(MDOC_ARGS)
                   1498: {
                   1499:
                   1500:        print_otag(h, TAG_P, 0, NULL);
                   1501:        return(0);
                   1502:
                   1503: }
1.26      schwarze 1504:
                   1505: /* ARGSUSED */
                   1506: static int
1.1       schwarze 1507: mdoc_sp_pre(MDOC_ARGS)
                   1508: {
1.40      schwarze 1509:        struct roffsu    su;
1.1       schwarze 1510:        struct htmlpair  tag;
                   1511:
1.40      schwarze 1512:        SCALE_VS_INIT(&su, 1);
                   1513:
                   1514:        if (MDOC_sp == n->tok) {
                   1515:                if (n->child)
                   1516:                        a2roffsu(n->child->string, &su, SCALE_VS);
                   1517:        } else
                   1518:                su.scale = 0;
1.1       schwarze 1519:
                   1520:        bufcat_su(h, "height", &su);
                   1521:        PAIR_STYLE_INIT(&tag, h);
                   1522:        print_otag(h, TAG_DIV, 1, &tag);
1.40      schwarze 1523:
1.3       schwarze 1524:        /* So the div isn't empty: */
                   1525:        print_text(h, "\\~");
                   1526:
                   1527:        return(0);
1.1       schwarze 1528:
                   1529: }
                   1530:
                   1531: /* ARGSUSED */
                   1532: static int
                   1533: mdoc_lk_pre(MDOC_ARGS)
                   1534: {
                   1535:        const struct mdoc_node  *nn;
                   1536:        struct htmlpair          tag[2];
                   1537:
                   1538:        nn = n->child;
                   1539:
                   1540:        PAIR_CLASS_INIT(&tag[0], "link-ext");
1.11      schwarze 1541:        PAIR_HREF_INIT(&tag[1], nn->string);
1.1       schwarze 1542:        print_otag(h, TAG_A, 2, tag);
                   1543:
1.38      schwarze 1544:        if (NULL == nn || NULL == nn->next)
1.2       schwarze 1545:                return(1);
                   1546:
1.1       schwarze 1547:        for (nn = nn->next; nn; nn = nn->next)
                   1548:                print_text(h, nn->string);
                   1549:
                   1550:        return(0);
                   1551: }
                   1552:
                   1553:
                   1554: /* ARGSUSED */
                   1555: static int
                   1556: mdoc_mt_pre(MDOC_ARGS)
                   1557: {
                   1558:        struct htmlpair          tag[2];
                   1559:        struct tag              *t;
                   1560:        const struct mdoc_node  *nn;
                   1561:
                   1562:        PAIR_CLASS_INIT(&tag[0], "link-mail");
                   1563:
                   1564:        for (nn = n->child; nn; nn = nn->next) {
                   1565:                bufinit(h);
                   1566:                bufcat(h, "mailto:");
                   1567:                bufcat(h, nn->string);
1.10      schwarze 1568:                PAIR_HREF_INIT(&tag[1], h->buf);
1.1       schwarze 1569:                t = print_otag(h, TAG_A, 2, tag);
                   1570:                print_text(h, nn->string);
                   1571:                print_tagq(h, t);
                   1572:        }
                   1573:
                   1574:        return(0);
                   1575: }
                   1576:
                   1577:
                   1578: /* ARGSUSED */
                   1579: static int
                   1580: mdoc_fo_pre(MDOC_ARGS)
                   1581: {
1.20      schwarze 1582:        struct htmlpair  tag;
                   1583:        struct tag      *t;
1.1       schwarze 1584:
                   1585:        if (MDOC_BODY == n->type) {
                   1586:                h->flags |= HTML_NOSPACE;
                   1587:                print_text(h, "(");
                   1588:                h->flags |= HTML_NOSPACE;
                   1589:                return(1);
1.20      schwarze 1590:        } else if (MDOC_BLOCK == n->type) {
1.21      schwarze 1591:                synopsis_pre(h, n);
1.1       schwarze 1592:                return(1);
1.11      schwarze 1593:        }
1.1       schwarze 1594:
1.20      schwarze 1595:        /* XXX: we drop non-initial arguments as per groff. */
                   1596:
                   1597:        assert(n->child);
                   1598:        assert(n->child->string);
                   1599:
1.1       schwarze 1600:        PAIR_CLASS_INIT(&tag, "fname");
1.43      schwarze 1601:        t = print_otag(h, TAG_B, 1, &tag);
1.20      schwarze 1602:        print_text(h, n->child->string);
                   1603:        print_tagq(h, t);
                   1604:        return(0);
1.1       schwarze 1605: }
                   1606:
                   1607:
                   1608: /* ARGSUSED */
                   1609: static void
                   1610: mdoc_fo_post(MDOC_ARGS)
                   1611: {
1.21      schwarze 1612:
1.1       schwarze 1613:        if (MDOC_BODY != n->type)
                   1614:                return;
                   1615:        print_text(h, ")");
                   1616:        print_text(h, ";");
                   1617: }
                   1618:
                   1619:
                   1620: /* ARGSUSED */
                   1621: static int
                   1622: mdoc_in_pre(MDOC_ARGS)
                   1623: {
                   1624:        const struct mdoc_node  *nn;
                   1625:        struct tag              *t;
                   1626:        struct htmlpair          tag[2];
                   1627:        int                      i;
                   1628:
1.21      schwarze 1629:        synopsis_pre(h, n);
                   1630:
1.1       schwarze 1631:        PAIR_CLASS_INIT(&tag[0], "includes");
1.42      schwarze 1632:        print_otag(h, TAG_B, 1, tag);
1.1       schwarze 1633:
1.23      schwarze 1634:        if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags)
1.1       schwarze 1635:                print_text(h, "#include");
                   1636:
                   1637:        print_text(h, "<");
                   1638:        h->flags |= HTML_NOSPACE;
                   1639:
                   1640:        for (nn = n->child; nn; nn = nn->next) {
                   1641:                PAIR_CLASS_INIT(&tag[0], "link-includes");
                   1642:                i = 1;
1.3       schwarze 1643:                bufinit(h);
1.1       schwarze 1644:                if (h->base_includes) {
                   1645:                        buffmt_includes(h, nn->string);
1.11      schwarze 1646:                        PAIR_HREF_INIT(&tag[i], h->buf);
                   1647:                        i++;
1.1       schwarze 1648:                }
                   1649:                t = print_otag(h, TAG_A, i, tag);
                   1650:                print_mdoc_node(m, nn, h);
                   1651:                print_tagq(h, t);
                   1652:        }
                   1653:
                   1654:        h->flags |= HTML_NOSPACE;
                   1655:        print_text(h, ">");
1.20      schwarze 1656:
1.1       schwarze 1657:        return(0);
                   1658: }
                   1659:
                   1660:
                   1661: /* ARGSUSED */
                   1662: static int
                   1663: mdoc_ic_pre(MDOC_ARGS)
                   1664: {
                   1665:        struct htmlpair tag;
                   1666:
                   1667:        PAIR_CLASS_INIT(&tag, "cmd");
1.42      schwarze 1668:        print_otag(h, TAG_B, 1, &tag);
1.1       schwarze 1669:        return(1);
                   1670: }
                   1671:
                   1672:
                   1673: /* ARGSUSED */
                   1674: static int
                   1675: mdoc_rv_pre(MDOC_ARGS)
                   1676: {
                   1677:        const struct mdoc_node  *nn;
                   1678:        struct htmlpair          tag;
                   1679:        struct tag              *t;
                   1680:
1.40      schwarze 1681:        if (n->prev)
                   1682:                print_otag(h, TAG_BR, 0, NULL);
                   1683:
1.1       schwarze 1684:        print_text(h, "The");
                   1685:
                   1686:        for (nn = n->child; nn; nn = nn->next) {
                   1687:                PAIR_CLASS_INIT(&tag, "fname");
1.43      schwarze 1688:                t = print_otag(h, TAG_B, 1, &tag);
1.1       schwarze 1689:                print_text(h, nn->string);
                   1690:                print_tagq(h, t);
                   1691:
                   1692:                h->flags |= HTML_NOSPACE;
                   1693:                if (nn->next && NULL == nn->next->next)
                   1694:                        print_text(h, "(), and");
                   1695:                else if (nn->next)
                   1696:                        print_text(h, "(),");
                   1697:                else
                   1698:                        print_text(h, "()");
                   1699:        }
                   1700:
1.17      schwarze 1701:        if (n->child && n->child->next)
1.1       schwarze 1702:                print_text(h, "functions return");
                   1703:        else
                   1704:                print_text(h, "function returns");
                   1705:
                   1706:                print_text(h, "the value 0 if successful; otherwise the value "
                   1707:                        "-1 is returned and the global variable");
                   1708:
                   1709:        PAIR_CLASS_INIT(&tag, "var");
1.42      schwarze 1710:        t = print_otag(h, TAG_B, 1, &tag);
1.1       schwarze 1711:        print_text(h, "errno");
                   1712:        print_tagq(h, t);
                   1713:                print_text(h, "is set to indicate the error.");
                   1714:        return(0);
                   1715: }
                   1716:
                   1717:
                   1718: /* ARGSUSED */
                   1719: static int
                   1720: mdoc_va_pre(MDOC_ARGS)
                   1721: {
                   1722:        struct htmlpair tag;
                   1723:
                   1724:        PAIR_CLASS_INIT(&tag, "var");
1.42      schwarze 1725:        print_otag(h, TAG_B, 1, &tag);
1.1       schwarze 1726:        return(1);
                   1727: }
                   1728:
                   1729:
                   1730: /* ARGSUSED */
                   1731: static int
                   1732: mdoc_ap_pre(MDOC_ARGS)
                   1733: {
                   1734:
                   1735:        h->flags |= HTML_NOSPACE;
                   1736:        print_text(h, "\\(aq");
                   1737:        h->flags |= HTML_NOSPACE;
                   1738:        return(1);
                   1739: }
                   1740:
                   1741:
                   1742: /* ARGSUSED */
                   1743: static int
                   1744: mdoc_bf_pre(MDOC_ARGS)
                   1745: {
                   1746:        struct htmlpair  tag[2];
                   1747:        struct roffsu    su;
                   1748:
                   1749:        if (MDOC_HEAD == n->type)
                   1750:                return(0);
1.25      schwarze 1751:        else if (MDOC_BODY != n->type)
1.1       schwarze 1752:                return(1);
                   1753:
1.44      schwarze 1754:        if (FONT_Em == n->norm->Bf.font)
1.25      schwarze 1755:                PAIR_CLASS_INIT(&tag[0], "emph");
1.44      schwarze 1756:        else if (FONT_Sy == n->norm->Bf.font)
1.25      schwarze 1757:                PAIR_CLASS_INIT(&tag[0], "symb");
1.44      schwarze 1758:        else if (FONT_Li == n->norm->Bf.font)
1.25      schwarze 1759:                PAIR_CLASS_INIT(&tag[0], "lit");
                   1760:        else
                   1761:                PAIR_CLASS_INIT(&tag[0], "none");
1.1       schwarze 1762:
1.25      schwarze 1763:        /*
                   1764:         * We want this to be inline-formatted, but needs to be div to
                   1765:         * accept block children.
                   1766:         */
1.1       schwarze 1767:        bufcat_style(h, "display", "inline");
                   1768:        SCALE_HS_INIT(&su, 1);
1.25      schwarze 1769:        /* Needs a left-margin for spacing. */
                   1770:        bufcat_su(h, "margin-left", &su);
1.1       schwarze 1771:        PAIR_STYLE_INIT(&tag[1], h);
                   1772:        print_otag(h, TAG_DIV, 2, tag);
                   1773:        return(1);
                   1774: }
                   1775:
                   1776:
                   1777: /* ARGSUSED */
                   1778: static int
                   1779: mdoc_ms_pre(MDOC_ARGS)
                   1780: {
                   1781:        struct htmlpair tag;
                   1782:
                   1783:        PAIR_CLASS_INIT(&tag, "symb");
                   1784:        print_otag(h, TAG_SPAN, 1, &tag);
                   1785:        return(1);
                   1786: }
                   1787:
                   1788:
                   1789: /* ARGSUSED */
                   1790: static int
1.34      schwarze 1791: mdoc_igndelim_pre(MDOC_ARGS)
1.1       schwarze 1792: {
                   1793:
                   1794:        h->flags |= HTML_IGNDELIM;
                   1795:        return(1);
                   1796: }
                   1797:
                   1798:
                   1799: /* ARGSUSED */
                   1800: static void
                   1801: mdoc_pf_post(MDOC_ARGS)
                   1802: {
                   1803:
                   1804:        h->flags |= HTML_NOSPACE;
                   1805: }
                   1806:
                   1807:
                   1808: /* ARGSUSED */
                   1809: static int
                   1810: mdoc_rs_pre(MDOC_ARGS)
                   1811: {
                   1812:        struct htmlpair  tag;
                   1813:
                   1814:        if (MDOC_BLOCK != n->type)
                   1815:                return(1);
                   1816:
1.40      schwarze 1817:        if (n->prev && SEC_SEE_ALSO == n->sec)
                   1818:                print_otag(h, TAG_P, 0, NULL);
1.1       schwarze 1819:
                   1820:        PAIR_CLASS_INIT(&tag, "ref");
                   1821:        print_otag(h, TAG_SPAN, 1, &tag);
                   1822:        return(1);
                   1823: }
                   1824:
                   1825:
                   1826:
                   1827: /* ARGSUSED */
                   1828: static int
                   1829: mdoc_li_pre(MDOC_ARGS)
                   1830: {
                   1831:        struct htmlpair tag;
                   1832:
                   1833:        PAIR_CLASS_INIT(&tag, "lit");
                   1834:        print_otag(h, TAG_SPAN, 1, &tag);
                   1835:        return(1);
                   1836: }
                   1837:
                   1838:
                   1839: /* ARGSUSED */
                   1840: static int
                   1841: mdoc_sy_pre(MDOC_ARGS)
                   1842: {
                   1843:        struct htmlpair tag;
                   1844:
                   1845:        PAIR_CLASS_INIT(&tag, "symb");
                   1846:        print_otag(h, TAG_SPAN, 1, &tag);
                   1847:        return(1);
                   1848: }
                   1849:
                   1850:
                   1851: /* ARGSUSED */
                   1852: static int
                   1853: mdoc_bt_pre(MDOC_ARGS)
                   1854: {
                   1855:
                   1856:        print_text(h, "is currently in beta test.");
                   1857:        return(0);
                   1858: }
                   1859:
                   1860:
                   1861: /* ARGSUSED */
                   1862: static int
                   1863: mdoc_ud_pre(MDOC_ARGS)
                   1864: {
                   1865:
                   1866:        print_text(h, "currently under development.");
                   1867:        return(0);
                   1868: }
                   1869:
                   1870:
                   1871: /* ARGSUSED */
                   1872: static int
                   1873: mdoc_lb_pre(MDOC_ARGS)
                   1874: {
                   1875:        struct htmlpair tag;
                   1876:
1.40      schwarze 1877:        if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags && n->prev)
                   1878:                print_otag(h, TAG_BR, 0, NULL);
                   1879:
1.1       schwarze 1880:        PAIR_CLASS_INIT(&tag, "lib");
                   1881:        print_otag(h, TAG_SPAN, 1, &tag);
                   1882:        return(1);
                   1883: }
                   1884:
                   1885:
                   1886: /* ARGSUSED */
                   1887: static int
                   1888: mdoc__x_pre(MDOC_ARGS)
                   1889: {
1.2       schwarze 1890:        struct htmlpair tag[2];
1.42      schwarze 1891:        enum htmltag    t;
                   1892:
                   1893:        t = TAG_SPAN;
1.1       schwarze 1894:
                   1895:        switch (n->tok) {
                   1896:        case(MDOC__A):
1.2       schwarze 1897:                PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.30      schwarze 1898:                if (n->prev && MDOC__A == n->prev->tok)
                   1899:                        if (NULL == n->next || MDOC__A != n->next->tok)
                   1900:                                print_text(h, "and");
1.1       schwarze 1901:                break;
                   1902:        case(MDOC__B):
1.2       schwarze 1903:                PAIR_CLASS_INIT(&tag[0], "ref-book");
1.42      schwarze 1904:                t = TAG_I;
1.1       schwarze 1905:                break;
                   1906:        case(MDOC__C):
1.2       schwarze 1907:                PAIR_CLASS_INIT(&tag[0], "ref-city");
1.1       schwarze 1908:                break;
                   1909:        case(MDOC__D):
1.2       schwarze 1910:                PAIR_CLASS_INIT(&tag[0], "ref-date");
1.1       schwarze 1911:                break;
                   1912:        case(MDOC__I):
1.2       schwarze 1913:                PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.42      schwarze 1914:                t = TAG_I;
1.1       schwarze 1915:                break;
                   1916:        case(MDOC__J):
1.2       schwarze 1917:                PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.42      schwarze 1918:                t = TAG_I;
1.1       schwarze 1919:                break;
                   1920:        case(MDOC__N):
1.2       schwarze 1921:                PAIR_CLASS_INIT(&tag[0], "ref-num");
1.1       schwarze 1922:                break;
                   1923:        case(MDOC__O):
1.2       schwarze 1924:                PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.1       schwarze 1925:                break;
                   1926:        case(MDOC__P):
1.2       schwarze 1927:                PAIR_CLASS_INIT(&tag[0], "ref-page");
1.1       schwarze 1928:                break;
                   1929:        case(MDOC__Q):
1.2       schwarze 1930:                PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.1       schwarze 1931:                break;
                   1932:        case(MDOC__R):
1.2       schwarze 1933:                PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.1       schwarze 1934:                break;
                   1935:        case(MDOC__T):
1.2       schwarze 1936:                PAIR_CLASS_INIT(&tag[0], "ref-title");
1.1       schwarze 1937:                break;
1.2       schwarze 1938:        case(MDOC__U):
                   1939:                PAIR_CLASS_INIT(&tag[0], "link-ref");
                   1940:                break;
1.1       schwarze 1941:        case(MDOC__V):
1.2       schwarze 1942:                PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.1       schwarze 1943:                break;
                   1944:        default:
                   1945:                abort();
                   1946:                /* NOTREACHED */
                   1947:        }
                   1948:
1.2       schwarze 1949:        if (MDOC__U != n->tok) {
1.42      schwarze 1950:                print_otag(h, t, 1, tag);
1.2       schwarze 1951:                return(1);
                   1952:        }
                   1953:
                   1954:        PAIR_HREF_INIT(&tag[1], n->child->string);
                   1955:        print_otag(h, TAG_A, 2, tag);
1.30      schwarze 1956:
1.1       schwarze 1957:        return(1);
                   1958: }
                   1959:
                   1960:
                   1961: /* ARGSUSED */
                   1962: static void
                   1963: mdoc__x_post(MDOC_ARGS)
                   1964: {
1.30      schwarze 1965:
                   1966:        if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
                   1967:                if (NULL == n->next->next || MDOC__A != n->next->next->tok)
                   1968:                        if (NULL == n->prev || MDOC__A != n->prev->tok)
                   1969:                                return;
1.1       schwarze 1970:
1.12      schwarze 1971:        /* TODO: %U */
                   1972:
1.31      schwarze 1973:        if (NULL == n->parent || MDOC_Rs != n->parent->tok)
                   1974:                return;
                   1975:
1.1       schwarze 1976:        print_text(h, n->next ? "," : ".");
1.25      schwarze 1977: }
                   1978:
                   1979:
                   1980: /* ARGSUSED */
                   1981: static int
                   1982: mdoc_bk_pre(MDOC_ARGS)
                   1983: {
                   1984:
                   1985:        switch (n->type) {
                   1986:        case (MDOC_BLOCK):
                   1987:                break;
                   1988:        case (MDOC_HEAD):
                   1989:                return(0);
                   1990:        case (MDOC_BODY):
1.41      schwarze 1991:                if (n->parent->args || 0 == n->prev->nchild)
                   1992:                        h->flags |= HTML_PREKEEP;
1.25      schwarze 1993:                break;
                   1994:        default:
                   1995:                abort();
                   1996:                /* NOTREACHED */
                   1997:        }
                   1998:
                   1999:        return(1);
                   2000: }
                   2001:
                   2002:
                   2003: /* ARGSUSED */
                   2004: static void
                   2005: mdoc_bk_post(MDOC_ARGS)
                   2006: {
                   2007:
                   2008:        if (MDOC_BODY == n->type)
                   2009:                h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
1.1       schwarze 2010: }
1.32      schwarze 2011:
                   2012:
                   2013: /* ARGSUSED */
                   2014: static int
                   2015: mdoc_quote_pre(MDOC_ARGS)
                   2016: {
                   2017:        struct htmlpair tag;
                   2018:
                   2019:        if (MDOC_BODY != n->type)
                   2020:                return(1);
                   2021:
                   2022:        switch (n->tok) {
                   2023:        case (MDOC_Ao):
                   2024:                /* FALLTHROUGH */
                   2025:        case (MDOC_Aq):
                   2026:                print_text(h, "\\(la");
                   2027:                break;
                   2028:        case (MDOC_Bro):
                   2029:                /* FALLTHROUGH */
                   2030:        case (MDOC_Brq):
                   2031:                print_text(h, "\\(lC");
                   2032:                break;
                   2033:        case (MDOC_Bo):
                   2034:                /* FALLTHROUGH */
                   2035:        case (MDOC_Bq):
                   2036:                print_text(h, "\\(lB");
                   2037:                break;
                   2038:        case (MDOC_Oo):
                   2039:                /* FALLTHROUGH */
                   2040:        case (MDOC_Op):
                   2041:                print_text(h, "\\(lB");
1.36      schwarze 2042:                h->flags |= HTML_NOSPACE;
1.32      schwarze 2043:                PAIR_CLASS_INIT(&tag, "opt");
                   2044:                print_otag(h, TAG_SPAN, 1, &tag);
                   2045:                break;
                   2046:        case (MDOC_Do):
                   2047:                /* FALLTHROUGH */
                   2048:        case (MDOC_Dq):
                   2049:                /* FALLTHROUGH */
                   2050:        case (MDOC_Qo):
                   2051:                /* FALLTHROUGH */
                   2052:        case (MDOC_Qq):
                   2053:                print_text(h, "\\(lq");
                   2054:                break;
                   2055:        case (MDOC_Po):
                   2056:                /* FALLTHROUGH */
                   2057:        case (MDOC_Pq):
                   2058:                print_text(h, "(");
                   2059:                break;
                   2060:        case (MDOC_Ql):
                   2061:                /* FALLTHROUGH */
                   2062:        case (MDOC_So):
                   2063:                /* FALLTHROUGH */
                   2064:        case (MDOC_Sq):
                   2065:                print_text(h, "\\(oq");
                   2066:                break;
                   2067:        default:
                   2068:                abort();
                   2069:                /* NOTREACHED */
                   2070:        }
                   2071:
                   2072:        h->flags |= HTML_NOSPACE;
                   2073:        return(1);
                   2074: }
                   2075:
                   2076:
                   2077: /* ARGSUSED */
                   2078: static void
                   2079: mdoc_quote_post(MDOC_ARGS)
                   2080: {
                   2081:
                   2082:        if (MDOC_BODY != n->type)
                   2083:                return;
                   2084:
                   2085:        h->flags |= HTML_NOSPACE;
                   2086:
                   2087:        switch (n->tok) {
                   2088:        case (MDOC_Ao):
                   2089:                /* FALLTHROUGH */
                   2090:        case (MDOC_Aq):
                   2091:                print_text(h, "\\(ra");
                   2092:                break;
                   2093:        case (MDOC_Bro):
                   2094:                /* FALLTHROUGH */
                   2095:        case (MDOC_Brq):
                   2096:                print_text(h, "\\(rC");
                   2097:                break;
                   2098:        case (MDOC_Oo):
                   2099:                /* FALLTHROUGH */
                   2100:        case (MDOC_Op):
                   2101:                /* FALLTHROUGH */
                   2102:        case (MDOC_Bo):
                   2103:                /* FALLTHROUGH */
                   2104:        case (MDOC_Bq):
                   2105:                print_text(h, "\\(rB");
                   2106:                break;
                   2107:        case (MDOC_Qo):
                   2108:                /* FALLTHROUGH */
                   2109:        case (MDOC_Qq):
                   2110:                /* FALLTHROUGH */
                   2111:        case (MDOC_Do):
                   2112:                /* FALLTHROUGH */
                   2113:        case (MDOC_Dq):
                   2114:                print_text(h, "\\(rq");
                   2115:                break;
                   2116:        case (MDOC_Po):
                   2117:                /* FALLTHROUGH */
                   2118:        case (MDOC_Pq):
                   2119:                print_text(h, ")");
                   2120:                break;
                   2121:        case (MDOC_Ql):
                   2122:                /* FALLTHROUGH */
                   2123:        case (MDOC_So):
                   2124:                /* FALLTHROUGH */
                   2125:        case (MDOC_Sq):
                   2126:                print_text(h, "\\(aq");
                   2127:                break;
                   2128:        default:
                   2129:                abort();
                   2130:                /* NOTREACHED */
                   2131:        }
                   2132: }
                   2133:
                   2134: