[BACK]Return to man_html.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/man_html.c, Revision 1.55

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

CVSweb