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

Annotation of src/usr.bin/mandoc/man_html.c, Revision 1.18

1.18    ! schwarze    1: /*     $Id: man_html.c,v 1.17 2010/07/13 01:09:13 schwarze Exp $ */
1.1       schwarze    2: /*
1.17      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:
1.14      schwarze   25: #include "mandoc.h"
1.1       schwarze   26: #include "out.h"
                     27: #include "html.h"
                     28: #include "man.h"
                     29: #include "main.h"
                     30:
                     31: /* TODO: preserve ident widths. */
1.2       schwarze   32: /* FIXME: have PD set the default vspace width. */
1.1       schwarze   33:
                     34: #define        INDENT            5
                     35: #define        HALFINDENT        3
                     36:
                     37: #define        MAN_ARGS          const struct man_meta *m, \
                     38:                          const struct man_node *n, \
1.18    ! schwarze   39:                          struct mhtml *mh, \
1.1       schwarze   40:                          struct html *h
                     41:
1.18    ! schwarze   42: struct mhtml {
        !            43:        int               fl;
        !            44: #define        MANH_LITERAL     (1 << 0) /* literal context */
        !            45: };
        !            46:
1.1       schwarze   47: struct htmlman {
                     48:        int             (*pre)(MAN_ARGS);
                     49:        int             (*post)(MAN_ARGS);
                     50: };
                     51:
                     52: static void              print_man(MAN_ARGS);
                     53: static void              print_man_head(MAN_ARGS);
                     54: static void              print_man_nodelist(MAN_ARGS);
                     55: static void              print_man_node(MAN_ARGS);
                     56:
                     57: static int               a2width(const struct man_node *,
                     58:                                struct roffsu *);
                     59:
                     60: static int               man_alt_pre(MAN_ARGS);
                     61: static int               man_br_pre(MAN_ARGS);
                     62: static int               man_ign_pre(MAN_ARGS);
1.18    ! schwarze   63: static int               man_in_pre(MAN_ARGS);
        !            64: static int               man_literal_pre(MAN_ARGS);
1.1       schwarze   65: static void              man_root_post(MAN_ARGS);
                     66: static int               man_root_pre(MAN_ARGS);
                     67: static int               man_B_pre(MAN_ARGS);
                     68: static int               man_HP_pre(MAN_ARGS);
                     69: static int               man_I_pre(MAN_ARGS);
                     70: static int               man_IP_pre(MAN_ARGS);
                     71: static int               man_PP_pre(MAN_ARGS);
                     72: static int               man_RS_pre(MAN_ARGS);
                     73: static int               man_SB_pre(MAN_ARGS);
                     74: static int               man_SH_pre(MAN_ARGS);
                     75: static int               man_SM_pre(MAN_ARGS);
                     76: static int               man_SS_pre(MAN_ARGS);
                     77:
                     78: static const struct htmlman mans[MAN_MAX] = {
                     79:        { man_br_pre, NULL }, /* br */
                     80:        { NULL, NULL }, /* TH */
                     81:        { man_SH_pre, NULL }, /* SH */
                     82:        { man_SS_pre, NULL }, /* SS */
                     83:        { man_IP_pre, NULL }, /* TP */
                     84:        { man_PP_pre, NULL }, /* LP */
                     85:        { man_PP_pre, NULL }, /* PP */
                     86:        { man_PP_pre, NULL }, /* P */
                     87:        { man_IP_pre, NULL }, /* IP */
                     88:        { man_HP_pre, NULL }, /* HP */
                     89:        { man_SM_pre, NULL }, /* SM */
                     90:        { man_SB_pre, NULL }, /* SB */
                     91:        { man_alt_pre, NULL }, /* BI */
                     92:        { man_alt_pre, NULL }, /* IB */
                     93:        { man_alt_pre, NULL }, /* BR */
                     94:        { man_alt_pre, NULL }, /* RB */
                     95:        { NULL, NULL }, /* R */
                     96:        { man_B_pre, NULL }, /* B */
                     97:        { man_I_pre, NULL }, /* I */
                     98:        { man_alt_pre, NULL }, /* IR */
                     99:        { man_alt_pre, NULL }, /* RI */
                    100:        { NULL, NULL }, /* na */
                    101:        { NULL, NULL }, /* i */
                    102:        { man_br_pre, NULL }, /* sp */
1.18    ! schwarze  103:        { man_literal_pre, NULL }, /* nf */
        !           104:        { man_literal_pre, NULL }, /* fi */
1.1       schwarze  105:        { NULL, NULL }, /* r */
                    106:        { NULL, NULL }, /* RE */
                    107:        { man_RS_pre, NULL }, /* RS */
                    108:        { man_ign_pre, NULL }, /* DT */
                    109:        { man_ign_pre, NULL }, /* UC */
1.2       schwarze  110:        { man_ign_pre, NULL }, /* PD */
1.6       schwarze  111:        { man_br_pre, NULL }, /* Sp */
1.18    ! schwarze  112:        { man_literal_pre, NULL }, /* Vb */
        !           113:        { man_literal_pre, NULL }, /* Ve */
1.13      schwarze  114:        { man_ign_pre, NULL }, /* AT */
1.18    ! schwarze  115:        { man_in_pre, NULL }, /* in */
1.1       schwarze  116: };
                    117:
                    118:
                    119: void
                    120: html_man(void *arg, const struct man *m)
                    121: {
                    122:        struct html     *h;
                    123:        struct tag      *t;
1.18    ! schwarze  124:        struct mhtml     mh;
1.1       schwarze  125:
                    126:        h = (struct html *)arg;
                    127:
1.5       schwarze  128:        print_gen_decls(h);
1.1       schwarze  129:
1.18    ! schwarze  130:        memset(&mh, 0, sizeof(struct mhtml));
        !           131:
1.1       schwarze  132:        t = print_otag(h, TAG_HTML, 0, NULL);
1.18    ! schwarze  133:        print_man(man_meta(m), man_node(m), &mh, h);
1.1       schwarze  134:        print_tagq(h, t);
                    135:
                    136:        printf("\n");
                    137: }
                    138:
                    139:
                    140: static void
                    141: print_man(MAN_ARGS)
                    142: {
                    143:        struct tag      *t;
                    144:        struct htmlpair  tag;
                    145:
                    146:        t = print_otag(h, TAG_HEAD, 0, NULL);
                    147:
1.18    ! schwarze  148:        print_man_head(m, n, mh, h);
1.1       schwarze  149:        print_tagq(h, t);
                    150:        t = print_otag(h, TAG_BODY, 0, NULL);
                    151:
                    152:        tag.key = ATTR_CLASS;
                    153:        tag.val = "body";
                    154:        print_otag(h, TAG_DIV, 1, &tag);
                    155:
1.18    ! schwarze  156:        print_man_nodelist(m, n, mh, h);
1.1       schwarze  157:
                    158:        print_tagq(h, t);
                    159: }
                    160:
                    161:
                    162: /* ARGSUSED */
                    163: static void
                    164: print_man_head(MAN_ARGS)
                    165: {
                    166:
                    167:        print_gen_head(h);
                    168:        bufinit(h);
1.10      schwarze  169:        buffmt(h, "%s(%s)", m->title, m->msec);
1.1       schwarze  170:
                    171:        print_otag(h, TAG_TITLE, 0, NULL);
                    172:        print_text(h, h->buf);
                    173: }
                    174:
                    175:
                    176: static void
                    177: print_man_nodelist(MAN_ARGS)
                    178: {
                    179:
1.18    ! schwarze  180:        print_man_node(m, n, mh, h);
1.1       schwarze  181:        if (n->next)
1.18    ! schwarze  182:                print_man_nodelist(m, n->next, mh, h);
1.1       schwarze  183: }
                    184:
                    185:
                    186: static void
                    187: print_man_node(MAN_ARGS)
                    188: {
                    189:        int              child;
                    190:        struct tag      *t;
                    191:
                    192:        child = 1;
1.2       schwarze  193:        t = h->tags.head;
1.1       schwarze  194:
                    195:        bufinit(h);
                    196:
1.7       schwarze  197:        /*
                    198:         * FIXME: embedded elements within next-line scopes (e.g., `br'
                    199:         * within an empty `B') will cause formatting to be forgotten
                    200:         * due to scope closing out.
                    201:         */
                    202:
1.1       schwarze  203:        switch (n->type) {
                    204:        case (MAN_ROOT):
1.18    ! schwarze  205:                child = man_root_pre(m, n, mh, h);
1.1       schwarze  206:                break;
                    207:        case (MAN_TEXT):
                    208:                print_text(h, n->string);
1.18    ! schwarze  209:
        !           210:                if (MANH_LITERAL & mh->fl)
        !           211:                        print_otag(h, TAG_BR, 0, NULL);
        !           212:
1.4       schwarze  213:                return;
1.1       schwarze  214:        default:
1.4       schwarze  215:                /*
                    216:                 * Close out scope of font prior to opening a macro
                    217:                 * scope.  Assert that the metafont is on the top of the
                    218:                 * stack (it's never nested).
                    219:                 */
                    220:                if (h->metaf) {
                    221:                        assert(h->metaf == t);
                    222:                        print_tagq(h, h->metaf);
                    223:                        assert(NULL == h->metaf);
                    224:                        t = h->tags.head;
                    225:                }
1.1       schwarze  226:                if (mans[n->tok].pre)
1.18    ! schwarze  227:                        child = (*mans[n->tok].pre)(m, n, mh, h);
1.1       schwarze  228:                break;
                    229:        }
                    230:
                    231:        if (child && n->child)
1.18    ! schwarze  232:                print_man_nodelist(m, n->child, mh, h);
1.1       schwarze  233:
1.4       schwarze  234:        /* This will automatically close out any font scope. */
1.1       schwarze  235:        print_stagq(h, t);
                    236:
                    237:        bufinit(h);
                    238:
                    239:        switch (n->type) {
                    240:        case (MAN_ROOT):
1.18    ! schwarze  241:                man_root_post(m, n, mh, h);
1.1       schwarze  242:                break;
                    243:        case (MAN_TEXT):
                    244:                break;
                    245:        default:
                    246:                if (mans[n->tok].post)
1.18    ! schwarze  247:                        (*mans[n->tok].post)(m, n, mh, h);
1.1       schwarze  248:                break;
                    249:        }
                    250: }
                    251:
                    252:
                    253: static int
                    254: a2width(const struct man_node *n, struct roffsu *su)
                    255: {
                    256:
                    257:        if (MAN_TEXT != n->type)
                    258:                return(0);
                    259:        if (a2roffsu(n->string, su, SCALE_BU))
                    260:                return(1);
                    261:
                    262:        return(0);
                    263: }
                    264:
                    265:
                    266: /* ARGSUSED */
                    267: static int
                    268: man_root_pre(MAN_ARGS)
                    269: {
1.3       schwarze  270:        struct htmlpair  tag[3];
1.1       schwarze  271:        struct tag      *t, *tt;
                    272:        char             b[BUFSIZ], title[BUFSIZ];
                    273:
                    274:        b[0] = 0;
                    275:        if (m->vol)
                    276:                (void)strlcat(b, m->vol, BUFSIZ);
                    277:
1.10      schwarze  278:        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.1       schwarze  279:
                    280:        PAIR_CLASS_INIT(&tag[0], "header");
                    281:        bufcat_style(h, "width", "100%");
                    282:        PAIR_STYLE_INIT(&tag[1], h);
1.3       schwarze  283:        PAIR_SUMMARY_INIT(&tag[2], "header");
                    284:
                    285:        t = print_otag(h, TAG_TABLE, 3, tag);
1.1       schwarze  286:        tt = print_otag(h, TAG_TR, 0, NULL);
                    287:
                    288:        bufinit(h);
                    289:        bufcat_style(h, "width", "10%");
                    290:        PAIR_STYLE_INIT(&tag[0], h);
                    291:        print_otag(h, TAG_TD, 1, tag);
                    292:        print_text(h, title);
                    293:        print_stagq(h, tt);
                    294:
                    295:        bufinit(h);
                    296:        bufcat_style(h, "width", "80%");
                    297:        bufcat_style(h, "white-space", "nowrap");
                    298:        bufcat_style(h, "text-align", "center");
                    299:        PAIR_STYLE_INIT(&tag[0], h);
                    300:        print_otag(h, TAG_TD, 1, tag);
                    301:        print_text(h, b);
                    302:        print_stagq(h, tt);
                    303:
                    304:        bufinit(h);
                    305:        bufcat_style(h, "width", "10%");
                    306:        bufcat_style(h, "text-align", "right");
                    307:        PAIR_STYLE_INIT(&tag[0], h);
                    308:        print_otag(h, TAG_TD, 1, tag);
                    309:        print_text(h, title);
                    310:        print_tagq(h, t);
                    311:        return(1);
                    312: }
                    313:
                    314:
                    315: /* ARGSUSED */
                    316: static void
                    317: man_root_post(MAN_ARGS)
                    318: {
1.3       schwarze  319:        struct htmlpair  tag[3];
1.1       schwarze  320:        struct tag      *t, *tt;
1.2       schwarze  321:        char             b[DATESIZ];
1.1       schwarze  322:
1.15      schwarze  323:        if (m->rawdate)
                    324:                strlcpy(b, m->rawdate, DATESIZ);
                    325:        else
                    326:                time2a(m->date, b, DATESIZ);
1.1       schwarze  327:
                    328:        PAIR_CLASS_INIT(&tag[0], "footer");
                    329:        bufcat_style(h, "width", "100%");
                    330:        PAIR_STYLE_INIT(&tag[1], h);
1.3       schwarze  331:        PAIR_SUMMARY_INIT(&tag[2], "footer");
                    332:
                    333:        t = print_otag(h, TAG_TABLE, 3, tag);
1.1       schwarze  334:        tt = print_otag(h, TAG_TR, 0, NULL);
                    335:
                    336:        bufinit(h);
                    337:        bufcat_style(h, "width", "50%");
                    338:        PAIR_STYLE_INIT(&tag[0], h);
                    339:        print_otag(h, TAG_TD, 1, tag);
                    340:        print_text(h, b);
                    341:        print_stagq(h, tt);
                    342:
                    343:        bufinit(h);
                    344:        bufcat_style(h, "width", "50%");
                    345:        bufcat_style(h, "text-align", "right");
                    346:        PAIR_STYLE_INIT(&tag[0], h);
                    347:        print_otag(h, TAG_TD, 1, tag);
                    348:        if (m->source)
                    349:                print_text(h, m->source);
                    350:        print_tagq(h, t);
                    351: }
                    352:
                    353:
                    354:
                    355: /* ARGSUSED */
                    356: static int
                    357: man_br_pre(MAN_ARGS)
                    358: {
                    359:        struct roffsu    su;
                    360:        struct htmlpair  tag;
                    361:
                    362:        SCALE_VS_INIT(&su, 1);
                    363:
1.8       schwarze  364:        switch (n->tok) {
                    365:        case (MAN_Sp):
                    366:                SCALE_VS_INIT(&su, 0.5);
                    367:                break;
                    368:        case (MAN_sp):
                    369:                if (n->child)
                    370:                        a2roffsu(n->child->string, &su, SCALE_VS);
                    371:                break;
                    372:        default:
1.1       schwarze  373:                su.scale = 0;
1.8       schwarze  374:                break;
                    375:        }
1.1       schwarze  376:
                    377:        bufcat_su(h, "height", &su);
                    378:        PAIR_STYLE_INIT(&tag, h);
                    379:        print_otag(h, TAG_DIV, 1, &tag);
1.4       schwarze  380:
1.3       schwarze  381:        /* So the div isn't empty: */
                    382:        print_text(h, "\\~");
                    383:
1.1       schwarze  384:        return(0);
                    385: }
                    386:
                    387:
                    388: /* ARGSUSED */
                    389: static int
                    390: man_SH_pre(MAN_ARGS)
                    391: {
                    392:        struct htmlpair  tag[2];
                    393:        struct roffsu    su;
                    394:
                    395:        if (MAN_BODY == n->type) {
                    396:                SCALE_HS_INIT(&su, INDENT);
                    397:                bufcat_su(h, "margin-left", &su);
                    398:                PAIR_CLASS_INIT(&tag[0], "sec-body");
                    399:                PAIR_STYLE_INIT(&tag[1], h);
                    400:                print_otag(h, TAG_DIV, 2, tag);
                    401:                return(1);
                    402:        } else if (MAN_BLOCK == n->type) {
                    403:                PAIR_CLASS_INIT(&tag[0], "sec-block");
                    404:                if (n->prev && MAN_SH == n->prev->tok)
                    405:                        if (NULL == n->prev->body->child) {
                    406:                                print_otag(h, TAG_DIV, 1, tag);
                    407:                                return(1);
                    408:                        }
                    409:
                    410:                SCALE_VS_INIT(&su, 1);
                    411:                bufcat_su(h, "margin-top", &su);
                    412:                if (NULL == n->next)
                    413:                        bufcat_su(h, "margin-bottom", &su);
                    414:                PAIR_STYLE_INIT(&tag[1], h);
                    415:                print_otag(h, TAG_DIV, 2, tag);
                    416:                return(1);
                    417:        }
                    418:
                    419:        PAIR_CLASS_INIT(&tag[0], "sec-head");
                    420:        print_otag(h, TAG_DIV, 1, tag);
                    421:        return(1);
                    422: }
                    423:
                    424:
                    425: /* ARGSUSED */
                    426: static int
                    427: man_alt_pre(MAN_ARGS)
                    428: {
                    429:        const struct man_node   *nn;
                    430:        struct tag              *t;
                    431:        int                      i;
1.4       schwarze  432:        enum htmlfont            fp;
1.1       schwarze  433:
                    434:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
                    435:                switch (n->tok) {
                    436:                case (MAN_BI):
1.4       schwarze  437:                        fp = i % 2 ? HTMLFONT_ITALIC : HTMLFONT_BOLD;
1.1       schwarze  438:                        break;
                    439:                case (MAN_IB):
1.4       schwarze  440:                        fp = i % 2 ? HTMLFONT_BOLD : HTMLFONT_ITALIC;
1.1       schwarze  441:                        break;
                    442:                case (MAN_RI):
1.4       schwarze  443:                        fp = i % 2 ? HTMLFONT_ITALIC : HTMLFONT_NONE;
1.1       schwarze  444:                        break;
                    445:                case (MAN_IR):
1.4       schwarze  446:                        fp = i % 2 ? HTMLFONT_NONE : HTMLFONT_ITALIC;
1.1       schwarze  447:                        break;
                    448:                case (MAN_BR):
1.4       schwarze  449:                        fp = i % 2 ? HTMLFONT_NONE : HTMLFONT_BOLD;
1.1       schwarze  450:                        break;
                    451:                case (MAN_RB):
1.4       schwarze  452:                        fp = i % 2 ? HTMLFONT_BOLD : HTMLFONT_NONE;
1.1       schwarze  453:                        break;
                    454:                default:
                    455:                        abort();
                    456:                        /* NOTREACHED */
                    457:                }
                    458:
                    459:                if (i)
                    460:                        h->flags |= HTML_NOSPACE;
                    461:
1.4       schwarze  462:                /*
                    463:                 * Open and close the scope with each argument, so that
                    464:                 * internal \f escapes, which are common, are also
                    465:                 * closed out with the scope.
                    466:                 */
                    467:                t = print_ofont(h, fp);
1.18    ! schwarze  468:                print_man_node(m, nn, mh, h);
1.4       schwarze  469:                print_tagq(h, t);
1.1       schwarze  470:        }
                    471:
                    472:        return(0);
                    473: }
                    474:
                    475:
                    476: /* ARGSUSED */
                    477: static int
                    478: man_SB_pre(MAN_ARGS)
                    479: {
                    480:        struct htmlpair  tag;
                    481:
1.4       schwarze  482:        /* FIXME: print_ofont(). */
1.1       schwarze  483:        PAIR_CLASS_INIT(&tag, "small bold");
                    484:        print_otag(h, TAG_SPAN, 1, &tag);
                    485:        return(1);
                    486: }
                    487:
                    488:
                    489: /* ARGSUSED */
                    490: static int
                    491: man_SM_pre(MAN_ARGS)
                    492: {
                    493:        struct htmlpair  tag;
                    494:
                    495:        PAIR_CLASS_INIT(&tag, "small");
                    496:        print_otag(h, TAG_SPAN, 1, &tag);
                    497:        return(1);
                    498: }
                    499:
                    500:
                    501: /* ARGSUSED */
                    502: static int
                    503: man_SS_pre(MAN_ARGS)
                    504: {
                    505:        struct htmlpair  tag[3];
                    506:        struct roffsu    su;
                    507:
                    508:        SCALE_VS_INIT(&su, 1);
                    509:
                    510:        if (MAN_BODY == n->type) {
                    511:                PAIR_CLASS_INIT(&tag[0], "ssec-body");
                    512:                if (n->parent->next && n->child) {
                    513:                        bufcat_su(h, "margin-bottom", &su);
                    514:                        PAIR_STYLE_INIT(&tag[1], h);
                    515:                        print_otag(h, TAG_DIV, 2, tag);
                    516:                        return(1);
                    517:                }
                    518:
                    519:                print_otag(h, TAG_DIV, 1, tag);
                    520:                return(1);
                    521:        } else if (MAN_BLOCK == n->type) {
                    522:                PAIR_CLASS_INIT(&tag[0], "ssec-block");
                    523:                if (n->prev && MAN_SS == n->prev->tok)
                    524:                        if (n->prev->body->child) {
                    525:                                bufcat_su(h, "margin-top", &su);
                    526:                                PAIR_STYLE_INIT(&tag[1], h);
                    527:                                print_otag(h, TAG_DIV, 2, tag);
                    528:                                return(1);
                    529:                        }
                    530:
                    531:                print_otag(h, TAG_DIV, 1, tag);
                    532:                return(1);
                    533:        }
                    534:
                    535:        SCALE_HS_INIT(&su, INDENT - HALFINDENT);
                    536:        bufcat_su(h, "margin-left", &su);
                    537:        PAIR_CLASS_INIT(&tag[0], "ssec-head");
                    538:        PAIR_STYLE_INIT(&tag[1], h);
                    539:        print_otag(h, TAG_DIV, 2, tag);
                    540:        return(1);
                    541: }
                    542:
                    543:
                    544: /* ARGSUSED */
                    545: static int
                    546: man_PP_pre(MAN_ARGS)
                    547: {
                    548:        struct htmlpair  tag;
                    549:        struct roffsu    su;
                    550:        int              i;
                    551:
                    552:        if (MAN_BLOCK != n->type)
                    553:                return(1);
                    554:
                    555:        i = 0;
                    556:
1.4       schwarze  557:        if (MAN_ROOT == n->parent->type) {
1.1       schwarze  558:                SCALE_HS_INIT(&su, INDENT);
                    559:                bufcat_su(h, "margin-left", &su);
1.4       schwarze  560:                i = 1;
1.1       schwarze  561:        }
1.4       schwarze  562:        if (n->prev) {
1.1       schwarze  563:                SCALE_VS_INIT(&su, 1);
1.4       schwarze  564:                bufcat_su(h, "margin-top", &su);
                    565:                i = 1;
1.1       schwarze  566:        }
                    567:
                    568:        PAIR_STYLE_INIT(&tag, h);
1.4       schwarze  569:        print_otag(h, TAG_DIV, i, &tag);
1.1       schwarze  570:        return(1);
                    571: }
                    572:
                    573:
                    574: /* ARGSUSED */
                    575: static int
                    576: man_IP_pre(MAN_ARGS)
                    577: {
                    578:        struct roffsu            su;
                    579:        struct htmlpair          tag;
                    580:        const struct man_node   *nn;
                    581:        int                      width;
                    582:
                    583:        /*
                    584:         * This scattering of 1-BU margins and pads is to make sure that
                    585:         * when text overruns its box, the subsequent text isn't flush
                    586:         * up against it.  However, the rest of the right-hand box must
                    587:         * also be adjusted in consideration of this 1-BU space.
                    588:         */
                    589:
                    590:        if (MAN_BODY == n->type) {
                    591:                SCALE_HS_INIT(&su, INDENT);
                    592:                bufcat_su(h, "margin-left", &su);
                    593:                PAIR_STYLE_INIT(&tag, h);
                    594:                print_otag(h, TAG_DIV, 1, &tag);
                    595:                return(1);
                    596:        }
                    597:
                    598:        nn = MAN_BLOCK == n->type ?
                    599:                n->head->child : n->parent->head->child;
                    600:
                    601:        SCALE_HS_INIT(&su, INDENT);
                    602:        width = 0;
                    603:
1.7       schwarze  604:        /* Width is the last token. */
                    605:
1.1       schwarze  606:        if (MAN_IP == n->tok && NULL != nn)
                    607:                if (NULL != (nn = nn->next)) {
                    608:                        for ( ; nn->next; nn = nn->next)
                    609:                                /* Do nothing. */ ;
                    610:                        width = a2width(nn, &su);
                    611:                }
                    612:
1.7       schwarze  613:        /* Width is the first token. */
                    614:
                    615:        if (MAN_TP == n->tok && NULL != nn) {
                    616:                /* Skip past non-text children. */
                    617:                while (nn && MAN_TEXT != nn->type)
                    618:                        nn = nn->next;
                    619:                if (nn)
                    620:                        width = a2width(nn, &su);
                    621:        }
1.1       schwarze  622:
                    623:        if (MAN_BLOCK == n->type) {
                    624:                bufcat_su(h, "margin-left", &su);
                    625:                SCALE_VS_INIT(&su, 1);
                    626:                bufcat_su(h, "margin-top", &su);
                    627:                bufcat_style(h, "clear", "both");
                    628:                PAIR_STYLE_INIT(&tag, h);
                    629:                print_otag(h, TAG_DIV, 1, &tag);
                    630:                return(1);
                    631:        }
                    632:
                    633:        bufcat_su(h, "min-width", &su);
                    634:        SCALE_INVERT(&su);
                    635:        bufcat_su(h, "margin-left", &su);
                    636:        SCALE_HS_INIT(&su, 1);
                    637:        bufcat_su(h, "margin-right", &su);
                    638:        bufcat_style(h, "clear", "left");
                    639:
                    640:        if (n->next && n->next->child)
                    641:                bufcat_style(h, "float", "left");
                    642:
                    643:        PAIR_STYLE_INIT(&tag, h);
                    644:        print_otag(h, TAG_DIV, 1, &tag);
                    645:
1.7       schwarze  646:        /*
                    647:         * Without a length string, we can print all of our children.
                    648:         */
1.1       schwarze  649:
                    650:        if ( ! width)
                    651:                return(1);
1.7       schwarze  652:
                    653:        /*
                    654:         * When a length has been specified, we need to carefully print
                    655:         * our child context:  IP gets all children printed but the last
                    656:         * (the width), while TP gets all children printed but the first
                    657:         * (the width).
                    658:         */
1.1       schwarze  659:
                    660:        if (MAN_IP == n->tok)
                    661:                for (nn = n->child; nn->next; nn = nn->next)
1.18    ! schwarze  662:                        print_man_node(m, nn, mh, h);
1.1       schwarze  663:        if (MAN_TP == n->tok)
                    664:                for (nn = n->child->next; nn; nn = nn->next)
1.18    ! schwarze  665:                        print_man_node(m, nn, mh, h);
1.1       schwarze  666:
                    667:        return(0);
                    668: }
                    669:
                    670:
                    671: /* ARGSUSED */
                    672: static int
                    673: man_HP_pre(MAN_ARGS)
                    674: {
                    675:        const struct man_node   *nn;
                    676:        struct htmlpair          tag;
                    677:        struct roffsu            su;
                    678:
                    679:        if (MAN_HEAD == n->type)
                    680:                return(0);
                    681:
                    682:        nn = MAN_BLOCK == n->type ?
                    683:                n->head->child : n->parent->head->child;
                    684:
                    685:        SCALE_HS_INIT(&su, INDENT);
                    686:
                    687:        if (NULL != nn)
                    688:                (void)a2width(nn, &su);
                    689:
                    690:        if (MAN_BLOCK == n->type) {
                    691:                bufcat_su(h, "margin-left", &su);
                    692:                SCALE_VS_INIT(&su, 1);
                    693:                bufcat_su(h, "margin-top", &su);
                    694:                bufcat_style(h, "clear", "both");
                    695:                PAIR_STYLE_INIT(&tag, h);
                    696:                print_otag(h, TAG_DIV, 1, &tag);
                    697:                return(1);
                    698:        }
                    699:
                    700:        bufcat_su(h, "margin-left", &su);
                    701:        SCALE_INVERT(&su);
                    702:        bufcat_su(h, "text-indent", &su);
                    703:
                    704:        PAIR_STYLE_INIT(&tag, h);
                    705:        print_otag(h, TAG_DIV, 1, &tag);
                    706:        return(1);
                    707: }
                    708:
                    709:
                    710: /* ARGSUSED */
                    711: static int
                    712: man_B_pre(MAN_ARGS)
                    713: {
                    714:
1.4       schwarze  715:        print_ofont(h, HTMLFONT_BOLD);
1.1       schwarze  716:        return(1);
                    717: }
                    718:
                    719:
                    720: /* ARGSUSED */
                    721: static int
                    722: man_I_pre(MAN_ARGS)
                    723: {
1.4       schwarze  724:
                    725:        print_ofont(h, HTMLFONT_ITALIC);
1.1       schwarze  726:        return(1);
1.18    ! schwarze  727: }
        !           728:
        !           729:
        !           730: /* ARGSUSED */
        !           731: static int
        !           732: man_literal_pre(MAN_ARGS)
        !           733: {
        !           734:
        !           735:        switch (n->tok) {
        !           736:        case (MAN_nf):
        !           737:                /* FALLTHROUGH */
        !           738:        case (MAN_Vb):
        !           739:                print_otag(h, TAG_BR, 0, NULL);
        !           740:                mh->fl |= MANH_LITERAL;
        !           741:                return(MAN_Vb != n->tok);
        !           742:        default:
        !           743:                mh->fl &= ~MANH_LITERAL;
        !           744:                break;
        !           745:        }
        !           746:
        !           747:        return(1);
        !           748: }
        !           749:
        !           750:
        !           751: /* ARGSUSED */
        !           752: static int
        !           753: man_in_pre(MAN_ARGS)
        !           754: {
        !           755:
        !           756:        print_otag(h, TAG_BR, 0, NULL);
        !           757:        return(0);
1.1       schwarze  758: }
                    759:
                    760:
                    761: /* ARGSUSED */
                    762: static int
                    763: man_ign_pre(MAN_ARGS)
                    764: {
                    765:
                    766:        return(0);
                    767: }
                    768:
                    769:
                    770: /* ARGSUSED */
                    771: static int
                    772: man_RS_pre(MAN_ARGS)
                    773: {
                    774:        struct htmlpair  tag;
                    775:        struct roffsu    su;
                    776:
                    777:        if (MAN_HEAD == n->type)
                    778:                return(0);
                    779:        else if (MAN_BODY == n->type)
                    780:                return(1);
                    781:
                    782:        SCALE_HS_INIT(&su, INDENT);
                    783:        bufcat_su(h, "margin-left", &su);
                    784:
                    785:        if (n->head->child) {
                    786:                SCALE_VS_INIT(&su, 1);
                    787:                a2width(n->head->child, &su);
                    788:                bufcat_su(h, "margin-top", &su);
                    789:        }
                    790:
                    791:        PAIR_STYLE_INIT(&tag, h);
                    792:        print_otag(h, TAG_DIV, 1, &tag);
                    793:        return(1);
                    794: }