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

Annotation of mandoc/man_html.c, Revision 1.47

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

CVSweb