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

Annotation of mandoc/man_html.c, Revision 1.72

1.72    ! kristaps    1: /*     $Id: man_html.c,v 1.71 2011/05/17 11:19:45 kristaps Exp $ */
1.1       kristaps    2: /*
1.70      schwarze    3:  * Copyright (c) 2008, 2009, 2010, 2011 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);
1.65      kristaps   70: static void              man_root_pre(MAN_ARGS);
1.8       kristaps   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.67      schwarze  103:        { man_ign_pre, 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);
1.71      kristaps  160:        bufcat_fmt(h, "%s(%s)", m->title, m->msec);
1.3       kristaps  161:        print_otag(h, TAG_TITLE, 0, NULL);
                    162:        print_text(h, h->buf);
1.1       kristaps  163: }
1.4       kristaps  164:
                    165:
                    166: static void
                    167: print_man_nodelist(MAN_ARGS)
                    168: {
                    169:
1.45      kristaps  170:        print_man_node(m, n, mh, h);
1.4       kristaps  171:        if (n->next)
1.45      kristaps  172:                print_man_nodelist(m, n->next, mh, h);
1.4       kristaps  173: }
                    174:
                    175:
                    176: static void
                    177: print_man_node(MAN_ARGS)
                    178: {
                    179:        int              child;
                    180:        struct tag      *t;
1.69      kristaps  181:        struct htmlpair  tag;
1.4       kristaps  182:
                    183:        child = 1;
1.14      kristaps  184:        t = h->tags.head;
1.4       kristaps  185:
                    186:        switch (n->type) {
                    187:        case (MAN_ROOT):
1.65      kristaps  188:                man_root_pre(m, n, mh, h);
1.4       kristaps  189:                break;
                    190:        case (MAN_TEXT):
1.65      kristaps  191:                /*
                    192:                 * If we have a blank line, output a vertical space.
                    193:                 * If we have a space as the first character, break
                    194:                 * before printing the line's data.
                    195:                 */
1.63      kristaps  196:                if ('\0' == *n->string) {
                    197:                        print_otag(h, TAG_P, 0, NULL);
                    198:                        return;
1.64      kristaps  199:                } else if (' ' == *n->string && MAN_LINE & n->flags)
1.63      kristaps  200:                        print_otag(h, TAG_BR, 0, NULL);
                    201:
1.4       kristaps  202:                print_text(h, n->string);
1.63      kristaps  203:
1.65      kristaps  204:                /*
                    205:                 * If we're in a literal context, make sure that words
                    206:                 * togehter on the same line stay together.  This is a
                    207:                 * POST-printing call, so we check the NEXT word.  Since
                    208:                 * -man doesn't have nested macros, we don't need to be
                    209:                 * more specific than this.
                    210:                 */
1.64      kristaps  211:                if (MANH_LITERAL & mh->fl &&
                    212:                                (NULL == n->next ||
                    213:                                 n->next->line > n->line))
1.45      kristaps  214:                        print_otag(h, TAG_BR, 0, NULL);
1.68      kristaps  215:                return;
                    216:        case (MAN_EQN):
1.69      kristaps  217:                PAIR_CLASS_INIT(&tag, "eqn");
                    218:                print_otag(h, TAG_SPAN, 1, &tag);
                    219:                print_text(h, n->eqn->data);
                    220:                break;
1.58      kristaps  221:        case (MAN_TBL):
1.66      kristaps  222:                /*
                    223:                 * This will take care of initialising all of the table
                    224:                 * state data for the first table, then tearing it down
                    225:                 * for the last one.
                    226:                 */
1.60      kristaps  227:                print_tbl(h, n->span);
1.64      kristaps  228:                return;
1.4       kristaps  229:        default:
1.21      kristaps  230:                /*
                    231:                 * Close out scope of font prior to opening a macro
1.66      kristaps  232:                 * scope.
1.21      kristaps  233:                 */
1.57      kristaps  234:                if (HTMLFONT_NONE != h->metac) {
                    235:                        h->metal = h->metac;
                    236:                        h->metac = HTMLFONT_NONE;
1.66      kristaps  237:                }
                    238:
                    239:                /*
                    240:                 * Close out the current table, if it's open, and unset
                    241:                 * the "meta" table state.  This will be reopened on the
                    242:                 * next table element.
                    243:                 */
                    244:                if (h->tblt) {
                    245:                        print_tblclose(h);
                    246:                        t = h->tags.head;
1.20      kristaps  247:                }
1.4       kristaps  248:                if (mans[n->tok].pre)
1.45      kristaps  249:                        child = (*mans[n->tok].pre)(m, n, mh, h);
1.4       kristaps  250:                break;
                    251:        }
                    252:
1.21      kristaps  253:        if (child && n->child)
1.45      kristaps  254:                print_man_nodelist(m, n->child, mh, h);
1.21      kristaps  255:
1.24      kristaps  256:        /* This will automatically close out any font scope. */
1.4       kristaps  257:        print_stagq(h, t);
                    258:
1.61      kristaps  259:        switch (n->type) {
                    260:        case (MAN_ROOT):
1.45      kristaps  261:                man_root_post(m, n, mh, h);
1.69      kristaps  262:                break;
                    263:        case (MAN_EQN):
1.61      kristaps  264:                break;
                    265:        default:
                    266:                if (mans[n->tok].post)
                    267:                        (*mans[n->tok].post)(m, n, mh, h);
                    268:                break;
                    269:        }
1.4       kristaps  270: }
                    271:
                    272:
1.5       kristaps  273: static int
1.7       kristaps  274: a2width(const struct man_node *n, struct roffsu *su)
1.5       kristaps  275: {
                    276:
1.6       kristaps  277:        if (MAN_TEXT != n->type)
1.7       kristaps  278:                return(0);
1.11      kristaps  279:        if (a2roffsu(n->string, su, SCALE_BU))
1.7       kristaps  280:                return(1);
1.5       kristaps  281:
1.7       kristaps  282:        return(0);
1.5       kristaps  283: }
                    284:
                    285:
1.40      kristaps  286: /* ARGSUSED */
1.65      kristaps  287: static void
1.4       kristaps  288: man_root_pre(MAN_ARGS)
                    289: {
1.56      kristaps  290:        struct htmlpair  tag[3];
1.4       kristaps  291:        struct tag      *t, *tt;
                    292:        char             b[BUFSIZ], title[BUFSIZ];
                    293:
                    294:        b[0] = 0;
                    295:        if (m->vol)
                    296:                (void)strlcat(b, m->vol, BUFSIZ);
                    297:
1.31      kristaps  298:        snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec);
1.4       kristaps  299:
1.56      kristaps  300:        PAIR_SUMMARY_INIT(&tag[0], "Document Header");
                    301:        PAIR_CLASS_INIT(&tag[1], "head");
                    302:        if (NULL == h->style) {
                    303:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    304:                t = print_otag(h, TAG_TABLE, 3, tag);
                    305:                PAIR_INIT(&tag[0], ATTR_WIDTH, "30%");
                    306:                print_otag(h, TAG_COL, 1, tag);
                    307:                print_otag(h, TAG_COL, 1, tag);
                    308:                print_otag(h, TAG_COL, 1, tag);
                    309:        } else
                    310:                t = print_otag(h, TAG_TABLE, 2, tag);
                    311:
                    312:        print_otag(h, TAG_TBODY, 0, NULL);
1.15      kristaps  313:
1.4       kristaps  314:        tt = print_otag(h, TAG_TR, 0, NULL);
                    315:
1.55      kristaps  316:        PAIR_CLASS_INIT(&tag[0], "head-ltitle");
1.4       kristaps  317:        print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  318:
1.4       kristaps  319:        print_text(h, title);
                    320:        print_stagq(h, tt);
                    321:
1.55      kristaps  322:        PAIR_CLASS_INIT(&tag[0], "head-vol");
1.56      kristaps  323:        if (NULL == h->style) {
                    324:                PAIR_INIT(&tag[1], ATTR_ALIGN, "center");
                    325:                print_otag(h, TAG_TD, 2, tag);
                    326:        } else
                    327:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  328:
1.4       kristaps  329:        print_text(h, b);
                    330:        print_stagq(h, tt);
                    331:
1.55      kristaps  332:        PAIR_CLASS_INIT(&tag[0], "head-rtitle");
1.56      kristaps  333:        if (NULL == h->style) {
                    334:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    335:                print_otag(h, TAG_TD, 2, tag);
                    336:        } else
                    337:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  338:
1.4       kristaps  339:        print_text(h, title);
                    340:        print_tagq(h, t);
                    341: }
                    342:
                    343:
                    344: /* ARGSUSED */
                    345: static void
                    346: man_root_post(MAN_ARGS)
                    347: {
1.56      kristaps  348:        struct htmlpair  tag[3];
1.4       kristaps  349:        struct tag      *t, *tt;
                    350:
1.56      kristaps  351:        PAIR_SUMMARY_INIT(&tag[0], "Document Footer");
                    352:        PAIR_CLASS_INIT(&tag[1], "foot");
                    353:        if (NULL == h->style) {
                    354:                PAIR_INIT(&tag[2], ATTR_WIDTH, "100%");
                    355:                t = print_otag(h, TAG_TABLE, 3, tag);
                    356:                PAIR_INIT(&tag[0], ATTR_WIDTH, "50%");
                    357:                print_otag(h, TAG_COL, 1, tag);
                    358:                print_otag(h, TAG_COL, 1, tag);
                    359:        } else
                    360:                t = print_otag(h, TAG_TABLE, 2, tag);
1.15      kristaps  361:
1.4       kristaps  362:        tt = print_otag(h, TAG_TR, 0, NULL);
                    363:
1.55      kristaps  364:        PAIR_CLASS_INIT(&tag[0], "foot-date");
1.4       kristaps  365:        print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  366:
1.70      schwarze  367:        print_text(h, m->date);
1.4       kristaps  368:        print_stagq(h, tt);
                    369:
1.55      kristaps  370:        PAIR_CLASS_INIT(&tag[0], "foot-os");
1.56      kristaps  371:        if (NULL == h->style) {
                    372:                PAIR_INIT(&tag[1], ATTR_ALIGN, "right");
                    373:                print_otag(h, TAG_TD, 2, tag);
                    374:        } else
                    375:                print_otag(h, TAG_TD, 1, tag);
1.55      kristaps  376:
1.4       kristaps  377:        if (m->source)
                    378:                print_text(h, m->source);
                    379:        print_tagq(h, t);
                    380: }
                    381:
                    382:
                    383:
                    384: /* ARGSUSED */
                    385: static int
                    386: man_br_pre(MAN_ARGS)
                    387: {
1.7       kristaps  388:        struct roffsu    su;
                    389:        struct htmlpair  tag;
1.4       kristaps  390:
1.7       kristaps  391:        SCALE_VS_INIT(&su, 1);
                    392:
1.49      kristaps  393:        if (MAN_sp == n->tok) {
1.29      kristaps  394:                if (n->child)
                    395:                        a2roffsu(n->child->string, &su, SCALE_VS);
1.49      kristaps  396:        } else
1.7       kristaps  397:                su.scale = 0;
1.4       kristaps  398:
1.72    ! kristaps  399:        bufinit(h);
1.7       kristaps  400:        bufcat_su(h, "height", &su);
                    401:        PAIR_STYLE_INIT(&tag, h);
1.4       kristaps  402:        print_otag(h, TAG_DIV, 1, &tag);
1.24      kristaps  403:
1.16      kristaps  404:        /* So the div isn't empty: */
                    405:        print_text(h, "\\~");
                    406:
1.7       kristaps  407:        return(0);
1.4       kristaps  408: }
                    409:
                    410:
                    411: /* ARGSUSED */
                    412: static int
                    413: man_SH_pre(MAN_ARGS)
                    414: {
1.54      kristaps  415:        struct htmlpair  tag;
1.4       kristaps  416:
1.54      kristaps  417:        if (MAN_BLOCK == n->type) {
                    418:                PAIR_CLASS_INIT(&tag, "section");
                    419:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  420:                return(1);
1.54      kristaps  421:        } else if (MAN_BODY == n->type)
1.4       kristaps  422:                return(1);
                    423:
1.54      kristaps  424:        print_otag(h, TAG_H1, 0, NULL);
1.4       kristaps  425:        return(1);
                    426: }
                    427:
                    428:
                    429: /* ARGSUSED */
                    430: static int
1.8       kristaps  431: man_alt_pre(MAN_ARGS)
                    432: {
                    433:        const struct man_node   *nn;
1.57      kristaps  434:        int              i;
                    435:        enum htmltag     fp;
                    436:        struct tag      *t;
1.8       kristaps  437:
                    438:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
1.57      kristaps  439:                t = NULL;
1.8       kristaps  440:                switch (n->tok) {
                    441:                case (MAN_BI):
1.57      kristaps  442:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  443:                        break;
                    444:                case (MAN_IB):
1.57      kristaps  445:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  446:                        break;
                    447:                case (MAN_RI):
1.57      kristaps  448:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  449:                        break;
                    450:                case (MAN_IR):
1.57      kristaps  451:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  452:                        break;
                    453:                case (MAN_BR):
1.57      kristaps  454:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  455:                        break;
                    456:                case (MAN_RB):
1.57      kristaps  457:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  458:                        break;
                    459:                default:
                    460:                        abort();
                    461:                        /* NOTREACHED */
                    462:                }
                    463:
                    464:                if (i)
                    465:                        h->flags |= HTML_NOSPACE;
                    466:
1.57      kristaps  467:                if (TAG_MAX != fp)
                    468:                        t = print_otag(h, fp, 0, NULL);
                    469:
1.45      kristaps  470:                print_man_node(m, nn, mh, h);
1.57      kristaps  471:
                    472:                if (t)
                    473:                        print_tagq(h, t);
1.8       kristaps  474:        }
                    475:
                    476:        return(0);
                    477: }
                    478:
                    479:
                    480: /* ARGSUSED */
                    481: static int
1.56      kristaps  482: man_SM_pre(MAN_ARGS)
1.8       kristaps  483: {
                    484:
1.57      kristaps  485:        print_otag(h, TAG_SMALL, 0, NULL);
1.56      kristaps  486:        if (MAN_SB == n->tok)
1.57      kristaps  487:                print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  488:        return(1);
                    489: }
                    490:
                    491:
                    492: /* ARGSUSED */
                    493: static int
1.4       kristaps  494: man_SS_pre(MAN_ARGS)
                    495: {
1.54      kristaps  496:        struct htmlpair  tag;
1.4       kristaps  497:
1.54      kristaps  498:        if (MAN_BLOCK == n->type) {
                    499:                PAIR_CLASS_INIT(&tag, "subsection");
                    500:                print_otag(h, TAG_DIV, 1, &tag);
1.4       kristaps  501:                return(1);
1.54      kristaps  502:        } else if (MAN_BODY == n->type)
1.4       kristaps  503:                return(1);
                    504:
1.54      kristaps  505:        print_otag(h, TAG_H2, 0, NULL);
1.4       kristaps  506:        return(1);
                    507: }
                    508:
                    509:
                    510: /* ARGSUSED */
                    511: static int
                    512: man_PP_pre(MAN_ARGS)
                    513: {
                    514:
1.47      kristaps  515:        if (MAN_HEAD == n->type)
                    516:                return(0);
1.56      kristaps  517:        else if (MAN_BODY == n->type && n->prev)
                    518:                print_otag(h, TAG_P, 0, NULL);
1.47      kristaps  519:
1.5       kristaps  520:        return(1);
                    521: }
                    522:
                    523:
                    524: /* ARGSUSED */
                    525: static int
                    526: man_IP_pre(MAN_ARGS)
                    527: {
1.7       kristaps  528:        struct roffsu            su;
1.5       kristaps  529:        struct htmlpair          tag;
                    530:        const struct man_node   *nn;
                    531:
1.7       kristaps  532:        /*
                    533:         * This scattering of 1-BU margins and pads is to make sure that
                    534:         * when text overruns its box, the subsequent text isn't flush
                    535:         * up against it.  However, the rest of the right-hand box must
                    536:         * also be adjusted in consideration of this 1-BU space.
                    537:         */
                    538:
                    539:        if (MAN_BODY == n->type) {
1.56      kristaps  540:                print_otag(h, TAG_TD, 0, NULL);
1.6       kristaps  541:                return(1);
                    542:        }
                    543:
                    544:        nn = MAN_BLOCK == n->type ?
                    545:                n->head->child : n->parent->head->child;
                    546:
1.7       kristaps  547:        SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  548:
1.59      schwarze  549:        /* Width is the second token. */
1.28      kristaps  550:
1.7       kristaps  551:        if (MAN_IP == n->tok && NULL != nn)
1.59      schwarze  552:                if (NULL != (nn = nn->next))
1.62      kristaps  553:                        a2width(nn, &su);
1.5       kristaps  554:
1.28      kristaps  555:        /* Width is the first token. */
                    556:
1.27      kristaps  557:        if (MAN_TP == n->tok && NULL != nn) {
1.28      kristaps  558:                /* Skip past non-text children. */
1.27      kristaps  559:                while (nn && MAN_TEXT != nn->type)
                    560:                        nn = nn->next;
1.28      kristaps  561:                if (nn)
1.62      kristaps  562:                        a2width(nn, &su);
1.27      kristaps  563:        }
1.7       kristaps  564:
1.5       kristaps  565:        if (MAN_BLOCK == n->type) {
1.56      kristaps  566:                print_otag(h, TAG_P, 0, NULL);
                    567:                print_otag(h, TAG_TABLE, 0, NULL);
1.72    ! kristaps  568:                bufinit(h);
1.56      kristaps  569:                bufcat_su(h, "width", &su);
1.7       kristaps  570:                PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  571:                print_otag(h, TAG_COL, 1, &tag);
                    572:                print_otag(h, TAG_COL, 0, NULL);
                    573:                print_otag(h, TAG_TBODY, 0, NULL);
                    574:                print_otag(h, TAG_TR, 0, NULL);
1.5       kristaps  575:                return(1);
1.6       kristaps  576:        }
                    577:
1.56      kristaps  578:        print_otag(h, TAG_TD, 0, NULL);
1.6       kristaps  579:
1.59      schwarze  580:        /* For IP, only print the first header element. */
1.7       kristaps  581:
1.59      schwarze  582:        if (MAN_IP == n->tok && n->child)
                    583:                print_man_node(m, n->child, mh, h);
1.27      kristaps  584:
1.59      schwarze  585:        /* For TP, only print next-line header elements. */
1.6       kristaps  586:
1.7       kristaps  587:        if (MAN_TP == n->tok)
1.59      schwarze  588:                for (nn = n->child; nn; nn = nn->next)
                    589:                        if (nn->line > n->line)
                    590:                                print_man_node(m, nn, mh, h);
1.6       kristaps  591:
                    592:        return(0);
                    593: }
                    594:
                    595:
                    596: /* ARGSUSED */
                    597: static int
                    598: man_HP_pre(MAN_ARGS)
                    599: {
1.56      kristaps  600:        struct htmlpair  tag;
                    601:        struct roffsu    su;
                    602:        const struct man_node *np;
1.6       kristaps  603:
1.72    ! kristaps  604:        bufinit(h);
        !           605:
1.56      kristaps  606:        np = MAN_BLOCK == n->type ?
                    607:                n->head->child :
                    608:                n->parent->head->child;
1.6       kristaps  609:
1.56      kristaps  610:        if (NULL == np || ! a2width(np, &su))
                    611:                SCALE_HS_INIT(&su, INDENT);
1.6       kristaps  612:
1.56      kristaps  613:        if (MAN_HEAD == n->type) {
                    614:                print_otag(h, TAG_TD, 0, NULL);
                    615:                return(0);
                    616:        } else if (MAN_BLOCK == n->type) {
                    617:                print_otag(h, TAG_P, 0, NULL);
                    618:                print_otag(h, TAG_TABLE, 0, NULL);
                    619:                bufcat_su(h, "width", &su);
1.7       kristaps  620:                PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  621:                print_otag(h, TAG_COL, 1, &tag);
                    622:                print_otag(h, TAG_COL, 0, NULL);
                    623:                print_otag(h, TAG_TBODY, 0, NULL);
                    624:                print_otag(h, TAG_TR, 0, NULL);
1.6       kristaps  625:                return(1);
                    626:        }
1.5       kristaps  627:
1.56      kristaps  628:        su.scale = -su.scale;
1.7       kristaps  629:        bufcat_su(h, "text-indent", &su);
                    630:        PAIR_STYLE_INIT(&tag, h);
1.56      kristaps  631:        print_otag(h, TAG_TD, 1, &tag);
1.4       kristaps  632:        return(1);
                    633: }
1.6       kristaps  634:
1.8       kristaps  635:
                    636: /* ARGSUSED */
                    637: static int
                    638: man_B_pre(MAN_ARGS)
                    639: {
                    640:
1.57      kristaps  641:        print_otag(h, TAG_B, 0, NULL);
1.8       kristaps  642:        return(1);
                    643: }
                    644:
                    645:
                    646: /* ARGSUSED */
                    647: static int
                    648: man_I_pre(MAN_ARGS)
                    649: {
1.23      kristaps  650:
1.57      kristaps  651:        print_otag(h, TAG_I, 0, NULL);
1.8       kristaps  652:        return(1);
1.45      kristaps  653: }
                    654:
                    655:
                    656: /* ARGSUSED */
                    657: static int
                    658: man_literal_pre(MAN_ARGS)
                    659: {
                    660:
1.48      kristaps  661:        if (MAN_nf == n->tok) {
1.45      kristaps  662:                print_otag(h, TAG_BR, 0, NULL);
                    663:                mh->fl |= MANH_LITERAL;
1.48      kristaps  664:        } else
1.45      kristaps  665:                mh->fl &= ~MANH_LITERAL;
                    666:
1.67      schwarze  667:        return(0);
1.45      kristaps  668: }
                    669:
                    670:
                    671: /* ARGSUSED */
                    672: static int
                    673: man_in_pre(MAN_ARGS)
                    674: {
                    675:
                    676:        print_otag(h, TAG_BR, 0, NULL);
                    677:        return(0);
1.8       kristaps  678: }
                    679:
                    680:
                    681: /* ARGSUSED */
                    682: static int
                    683: man_ign_pre(MAN_ARGS)
                    684: {
                    685:
                    686:        return(0);
                    687: }
1.9       kristaps  688:
                    689:
                    690: /* ARGSUSED */
                    691: static int
                    692: man_RS_pre(MAN_ARGS)
                    693: {
                    694:        struct htmlpair  tag;
                    695:        struct roffsu    su;
                    696:
                    697:        if (MAN_HEAD == n->type)
                    698:                return(0);
                    699:        else if (MAN_BODY == n->type)
                    700:                return(1);
                    701:
                    702:        SCALE_HS_INIT(&su, INDENT);
1.56      kristaps  703:        if (n->head->child)
1.9       kristaps  704:                a2width(n->head->child, &su);
                    705:
1.72    ! kristaps  706:        bufinit(h);
1.56      kristaps  707:        bufcat_su(h, "margin-left", &su);
1.9       kristaps  708:        PAIR_STYLE_INIT(&tag, h);
                    709:        print_otag(h, TAG_DIV, 1, &tag);
                    710:        return(1);
                    711: }

CVSweb