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

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