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

Annotation of mandoc/man_html.c, Revision 1.56

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

CVSweb