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

Annotation of mandoc/man_html.c, Revision 1.137

1.137   ! schwarze    1: /*     $Id: man_html.c,v 1.136 2017/04/24 23:06:18 schwarze Exp $ */
1.1       kristaps    2: /*
1.104     kristaps    3:  * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
1.122     schwarze    4:  * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
1.1       kristaps    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
1.113     schwarze   10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.1       kristaps   11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.113     schwarze   12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.1       kristaps   13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
1.25      kristaps   18: #include "config.h"
                     19:
1.1       kristaps   20: #include <sys/types.h>
                     21:
1.5       kristaps   22: #include <assert.h>
                     23: #include <ctype.h>
1.2       kristaps   24: #include <stdio.h>
1.1       kristaps   25: #include <stdlib.h>
1.4       kristaps   26: #include <string.h>
1.1       kristaps   27:
1.94      schwarze   28: #include "mandoc_aux.h"
1.113     schwarze   29: #include "roff.h"
1.105     schwarze   30: #include "man.h"
1.7       kristaps   31: #include "out.h"
1.1       kristaps   32: #include "html.h"
1.10      kristaps   33: #include "main.h"
1.1       kristaps   34:
1.13      kristaps   35: /* FIXME: have PD set the default vspace width. */
1.6       kristaps   36:
                     37: #define        INDENT            5
1.4       kristaps   38:
1.115     schwarze   39: #define        MAN_ARGS          const struct roff_meta *man, \
1.114     schwarze   40:                          const struct roff_node *n, \
1.3       kristaps   41:                          struct html *h
                     42:
                     43: struct htmlman {
                     44:        int             (*pre)(MAN_ARGS);
                     45:        int             (*post)(MAN_ARGS);
                     46: };
                     47:
1.93      schwarze   48: static void              print_bvspace(struct html *,
1.114     schwarze   49:                                const struct roff_node *);
1.3       kristaps   50: static void              print_man_head(MAN_ARGS);
1.4       kristaps   51: static void              print_man_nodelist(MAN_ARGS);
                     52: static void              print_man_node(MAN_ARGS);
1.132     schwarze   53: static int               fillmode(struct html *, int);
1.114     schwarze   54: static int               a2width(const struct roff_node *,
1.7       kristaps   55:                                struct roffsu *);
1.8       kristaps   56: static int               man_B_pre(MAN_ARGS);
1.6       kristaps   57: static int               man_HP_pre(MAN_ARGS);
1.86      kristaps   58: static int               man_IP_pre(MAN_ARGS);
1.8       kristaps   59: static int               man_I_pre(MAN_ARGS);
1.86      kristaps   60: static int               man_OP_pre(MAN_ARGS);
1.4       kristaps   61: static int               man_PP_pre(MAN_ARGS);
1.9       kristaps   62: static int               man_RS_pre(MAN_ARGS);
1.4       kristaps   63: static int               man_SH_pre(MAN_ARGS);
1.8       kristaps   64: static int               man_SM_pre(MAN_ARGS);
1.4       kristaps   65: static int               man_SS_pre(MAN_ARGS);
1.90      schwarze   66: static int               man_UR_pre(MAN_ARGS);
1.86      kristaps   67: static int               man_alt_pre(MAN_ARGS);
                     68: static int               man_br_pre(MAN_ARGS);
                     69: static int               man_ign_pre(MAN_ARGS);
                     70: static int               man_in_pre(MAN_ARGS);
                     71: static void              man_root_post(MAN_ARGS);
                     72: static void              man_root_pre(MAN_ARGS);
1.4       kristaps   73:
1.136     schwarze   74: static const struct htmlman __mans[MAN_MAX - MAN_TH] = {
1.3       kristaps   75:        { NULL, NULL }, /* TH */
1.4       kristaps   76:        { man_SH_pre, NULL }, /* SH */
                     77:        { man_SS_pre, NULL }, /* SS */
1.6       kristaps   78:        { man_IP_pre, NULL }, /* TP */
1.4       kristaps   79:        { man_PP_pre, NULL }, /* LP */
                     80:        { man_PP_pre, NULL }, /* PP */
                     81:        { man_PP_pre, NULL }, /* P */
1.5       kristaps   82:        { man_IP_pre, NULL }, /* IP */
1.93      schwarze   83:        { man_HP_pre, NULL }, /* HP */
1.8       kristaps   84:        { man_SM_pre, NULL }, /* SM */
1.56      kristaps   85:        { man_SM_pre, NULL }, /* SB */
1.8       kristaps   86:        { man_alt_pre, NULL }, /* BI */
                     87:        { man_alt_pre, NULL }, /* IB */
                     88:        { man_alt_pre, NULL }, /* BR */
                     89:        { man_alt_pre, NULL }, /* RB */
1.3       kristaps   90:        { NULL, NULL }, /* R */
1.8       kristaps   91:        { man_B_pre, NULL }, /* B */
                     92:        { man_I_pre, NULL }, /* I */
                     93:        { man_alt_pre, NULL }, /* IR */
                     94:        { man_alt_pre, NULL }, /* RI */
1.4       kristaps   95:        { man_br_pre, NULL }, /* sp */
1.132     schwarze   96:        { NULL, NULL }, /* nf */
                     97:        { NULL, NULL }, /* fi */
1.3       kristaps   98:        { NULL, NULL }, /* RE */
1.9       kristaps   99:        { man_RS_pre, NULL }, /* RS */
1.8       kristaps  100:        { man_ign_pre, NULL }, /* DT */
                    101:        { man_ign_pre, NULL }, /* UC */
1.13      kristaps  102:        { man_ign_pre, NULL }, /* PD */
1.34      joerg     103:        { man_ign_pre, NULL }, /* AT */
1.45      kristaps  104:        { man_in_pre, NULL }, /* in */
1.51      kristaps  105:        { man_ign_pre, NULL }, /* ft */
1.86      kristaps  106:        { man_OP_pre, NULL }, /* OP */
1.132     schwarze  107:        { NULL, NULL }, /* EX */
                    108:        { NULL, NULL }, /* EE */
1.90      schwarze  109:        { man_UR_pre, NULL }, /* UR */
                    110:        { NULL, NULL }, /* UE */
1.92      schwarze  111:        { man_ign_pre, NULL }, /* ll */
1.3       kristaps  112: };
1.136     schwarze  113: static const struct htmlman *const mans = __mans - MAN_TH;
1.3       kristaps  114:
1.93      schwarze  115:
1.74      kristaps  116: /*
                    117:  * Printing leading vertical space before a block.
                    118:  * This is used for the paragraph macros.
                    119:  * The rules are pretty simple, since there's very little nesting going
                    120:  * on here.  Basically, if we're the first within another block (SS/SH),
                    121:  * then don't emit vertical space.  If we are (RS), then do.  If not the
                    122:  * first, print it.
                    123:  */
                    124: static void
1.114     schwarze  125: print_bvspace(struct html *h, const struct roff_node *n)
1.74      kristaps  126: {
                    127:
                    128:        if (n->body && n->body->child)
1.113     schwarze  129:                if (n->body->child->type == ROFFT_TBL)
1.74      kristaps  130:                        return;
                    131:
1.113     schwarze  132:        if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
1.74      kristaps  133:                if (NULL == n->prev)
                    134:                        return;
                    135:
1.103     kristaps  136:        print_paragraph(h);
1.74      kristaps  137: }
1.1       kristaps  138:
                    139: void
1.116     schwarze  140: html_man(void *arg, const struct roff_man *man)
1.1       kristaps  141: {
1.117     schwarze  142:        struct html     *h;
1.126     schwarze  143:        struct tag      *t;
1.82      kristaps  144:
1.117     schwarze  145:        h = (struct html *)arg;
1.3       kristaps  146:
1.126     schwarze  147:        if ((h->oflags & HTML_FRAGMENT) == 0) {
1.82      kristaps  148:                print_gen_decls(h);
1.126     schwarze  149:                print_otag(h, TAG_HTML, "");
                    150:                t = print_otag(h, TAG_HEAD, "");
1.132     schwarze  151:                print_man_head(&man->meta, man->first, h);
1.126     schwarze  152:                print_tagq(h, t);
1.122     schwarze  153:                print_otag(h, TAG_BODY, "");
1.126     schwarze  154:        }
1.53      kristaps  155:
1.132     schwarze  156:        man_root_pre(&man->meta, man->first, h);
1.127     schwarze  157:        t = print_otag(h, TAG_DIV, "c", "manual-text");
1.132     schwarze  158:        print_man_nodelist(&man->meta, man->first->child, h);
1.127     schwarze  159:        print_tagq(h, t);
1.132     schwarze  160:        man_root_post(&man->meta, man->first, h);
1.126     schwarze  161:        print_tagq(h, NULL);
1.3       kristaps  162: }
                    163:
                    164: static void
                    165: print_man_head(MAN_ARGS)
                    166: {
1.123     schwarze  167:        char    *cp;
1.3       kristaps  168:
                    169:        print_gen_head(h);
1.123     schwarze  170:        mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
1.122     schwarze  171:        print_otag(h, TAG_TITLE, "");
1.123     schwarze  172:        print_text(h, cp);
                    173:        free(cp);
1.1       kristaps  174: }
1.4       kristaps  175:
                    176: static void
                    177: print_man_nodelist(MAN_ARGS)
                    178: {
                    179:
1.110     schwarze  180:        while (n != NULL) {
1.132     schwarze  181:                print_man_node(man, n, h);
1.110     schwarze  182:                n = n->next;
                    183:        }
1.4       kristaps  184: }
                    185:
                    186: static void
                    187: print_man_node(MAN_ARGS)
                    188: {
1.132     schwarze  189:        static int       want_fillmode = MAN_fi;
                    190:        static int       save_fillmode;
                    191:
                    192:        struct tag      *t;
1.4       kristaps  193:        int              child;
                    194:
1.132     schwarze  195:        /*
                    196:         * Handle fill mode switch requests up front,
                    197:         * they would just cause trouble in the subsequent code.
                    198:         */
                    199:
                    200:        switch (n->tok) {
                    201:        case MAN_nf:
                    202:        case MAN_EX:
                    203:                want_fillmode = MAN_nf;
                    204:                return;
                    205:        case MAN_fi:
                    206:        case MAN_EE:
                    207:                want_fillmode = MAN_fi;
                    208:                if (fillmode(h, 0) == MAN_fi)
                    209:                        print_otag(h, TAG_BR, "");
                    210:                return;
                    211:        default:
                    212:                break;
                    213:        }
                    214:
                    215:        /* Set up fill mode for the upcoming node. */
1.4       kristaps  216:
                    217:        switch (n->type) {
1.132     schwarze  218:        case ROFFT_BLOCK:
                    219:                save_fillmode = 0;
                    220:                /* Some block macros suspend or cancel .nf. */
                    221:                switch (n->tok) {
                    222:                case MAN_TP:  /* Tagged paragraphs              */
                    223:                case MAN_IP:  /* temporarily disable .nf        */
                    224:                case MAN_HP:  /* for the head.                  */
                    225:                        save_fillmode = want_fillmode;
                    226:                        /* FALLTHROUGH */
                    227:                case MAN_SH:  /* Section headers                */
                    228:                case MAN_SS:  /* permanently cancel .nf.        */
                    229:                        want_fillmode = MAN_fi;
                    230:                        /* FALLTHROUGH */
                    231:                case MAN_PP:  /* These have no head.            */
                    232:                case MAN_LP:  /* They will simply               */
                    233:                case MAN_P:   /* reopen .nf in the body.        */
                    234:                case MAN_RS:
                    235:                case MAN_UR:
                    236:                        fillmode(h, MAN_fi);
                    237:                        break;
                    238:                default:
                    239:                        break;
                    240:                }
                    241:                break;
                    242:        case ROFFT_TBL:
                    243:                fillmode(h, MAN_fi);
                    244:                break;
                    245:        case ROFFT_ELEM:
                    246:                /*
                    247:                 * Some in-line macros produce tags and/or text
                    248:                 * in the handler, so they require fill mode to be
                    249:                 * configured up front just like for text nodes.
                    250:                 * For the others, keep the traditional approach
                    251:                 * of doing the same, for now.
                    252:                 */
                    253:                fillmode(h, want_fillmode);
                    254:                break;
1.113     schwarze  255:        case ROFFT_TEXT:
1.132     schwarze  256:                if (fillmode(h, want_fillmode) == MAN_fi &&
                    257:                    want_fillmode == MAN_fi &&
1.130     schwarze  258:                    n->flags & NODE_LINE && *n->string == ' ')
1.122     schwarze  259:                        print_otag(h, TAG_BR, "");
1.132     schwarze  260:                if (*n->string != '\0')
                    261:                        break;
                    262:                print_paragraph(h);
                    263:                return;
                    264:        default:
                    265:                break;
                    266:        }
                    267:
                    268:        /* Produce output for this node. */
                    269:
                    270:        child = 1;
                    271:        switch (n->type) {
                    272:        case ROFFT_TEXT:
                    273:                t = h->tag;
1.4       kristaps  274:                print_text(h, n->string);
1.130     schwarze  275:                break;
1.113     schwarze  276:        case ROFFT_EQN:
1.132     schwarze  277:                t = h->tag;
1.80      kristaps  278:                print_eqn(h, n->eqn);
1.69      kristaps  279:                break;
1.113     schwarze  280:        case ROFFT_TBL:
1.66      kristaps  281:                /*
                    282:                 * This will take care of initialising all of the table
                    283:                 * state data for the first table, then tearing it down
                    284:                 * for the last one.
                    285:                 */
1.60      kristaps  286:                print_tbl(h, n->span);
1.64      kristaps  287:                return;
1.4       kristaps  288:        default:
1.93      schwarze  289:                /*
1.21      kristaps  290:                 * Close out scope of font prior to opening a macro
1.66      kristaps  291:                 * scope.
1.21      kristaps  292:                 */
1.57      kristaps  293:                if (HTMLFONT_NONE != h->metac) {
                    294:                        h->metal = h->metac;
                    295:                        h->metac = HTMLFONT_NONE;
1.66      kristaps  296:                }
                    297:
                    298:                /*
                    299:                 * Close out the current table, if it's open, and unset
                    300:                 * the "meta" table state.  This will be reopened on the
                    301:                 * next table element.
                    302:                 */
1.132     schwarze  303:                if (h->tblt)
1.66      kristaps  304:                        print_tblclose(h);
1.132     schwarze  305:
                    306:                t = h->tag;
1.137   ! schwarze  307:                if (n->tok < ROFF_MAX) {
        !           308:                        switch(n->tok) {
        !           309:                        case ROFF_br:
        !           310:                                man_br_pre(man, n, h);
        !           311:                                break;
        !           312:                        default:
        !           313:                                abort();
        !           314:                        }
        !           315:                        break;
        !           316:                }
        !           317:
        !           318:                assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
1.4       kristaps  319:                if (mans[n->tok].pre)
1.132     schwarze  320:                        child = (*mans[n->tok].pre)(man, n, h);
                    321:
                    322:                /* Some block macros resume .nf in the body. */
                    323:                if (save_fillmode && n->type == ROFFT_BODY)
                    324:                        want_fillmode = save_fillmode;
                    325:
1.4       kristaps  326:                break;
                    327:        }
                    328:
1.21      kristaps  329:        if (child && n->child)
1.132     schwarze  330:                print_man_nodelist(man, n->child, h);
1.21      kristaps  331:
1.24      kristaps  332:        /* This will automatically close out any font scope. */
1.132     schwarze  333:        print_stagq(h, t);
                    334:
                    335:        if (fillmode(h, 0) == MAN_nf &&
                    336:            n->next != NULL && n->next->flags & NODE_LINE)
                    337:                print_endline(h);
                    338: }
                    339:
                    340: /*
                    341:  * MAN_nf switches to no-fill mode, MAN_fi to fill mode.
                    342:  * Other arguments do not switch.
                    343:  * The old mode is returned.
                    344:  */
                    345: static int
                    346: fillmode(struct html *h, int want)
                    347: {
                    348:        struct tag      *pre;
                    349:        int              had;
1.4       kristaps  350:
1.132     schwarze  351:        for (pre = h->tag; pre != NULL; pre = pre->next)
                    352:                if (pre->tag == TAG_PRE)
                    353:                        break;
                    354:
                    355:        had = pre == NULL ? MAN_fi : MAN_nf;
1.130     schwarze  356:
1.132     schwarze  357:        if (want && want != had) {
                    358:                if (want == MAN_nf)
                    359:                        print_otag(h, TAG_PRE, "");
                    360:                else
                    361:                        print_tagq(h, pre);
                    362:        }
                    363:        return had;
1.4       kristaps  364: }
                    365:
1.5       kristaps  366: static int
1.114     schwarze  367: a2width(const struct roff_node *n, struct roffsu *su)
1.5       kristaps  368: {
                    369:
1.113     schwarze  370:        if (n->type != ROFFT_TEXT)
1.119     schwarze  371:                return 0;
1.107     schwarze  372:        if (a2roffsu(n->string, su, SCALE_EN))
1.119     schwarze  373:                return 1;
1.5       kristaps  374:
1.119     schwarze  375:        return 0;
1.5       kristaps  376: }
                    377:
1.65      kristaps  378: static void
1.4       kristaps  379: man_root_pre(MAN_ARGS)
                    380: {
                    381:        struct tag      *t, *tt;
1.94      schwarze  382:        char            *title;
1.4       kristaps  383:
1.89      schwarze  384:        assert(man->title);
                    385:        assert(man->msec);
1.94      schwarze  386:        mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.4       kristaps  387:
1.122     schwarze  388:        t = print_otag(h, TAG_TABLE, "c", "head");
                    389:        tt = print_otag(h, TAG_TR, "");
1.4       kristaps  390:
1.122     schwarze  391:        print_otag(h, TAG_TD, "c", "head-ltitle");
1.4       kristaps  392:        print_text(h, title);
                    393:        print_stagq(h, tt);
                    394:
1.122     schwarze  395:        print_otag(h, TAG_TD, "c", "head-vol");
1.95      schwarze  396:        if (NULL != man->vol)
                    397:                print_text(h, man->vol);
1.4       kristaps  398:        print_stagq(h, tt);
                    399:
1.122     schwarze  400:        print_otag(h, TAG_TD, "c", "head-rtitle");
1.4       kristaps  401:        print_text(h, title);
                    402:        print_tagq(h, t);
1.94      schwarze  403:        free(title);
1.4       kristaps  404: }
                    405:
                    406: static void
                    407: man_root_post(MAN_ARGS)
                    408: {
                    409:        struct tag      *t, *tt;
                    410:
1.122     schwarze  411:        t = print_otag(h, TAG_TABLE, "c", "foot");
                    412:        tt = print_otag(h, TAG_TR, "");
1.55      kristaps  413:
1.122     schwarze  414:        print_otag(h, TAG_TD, "c", "foot-date");
1.89      schwarze  415:        print_text(h, man->date);
1.4       kristaps  416:        print_stagq(h, tt);
                    417:
1.122     schwarze  418:        print_otag(h, TAG_TD, "c", "foot-os");
1.115     schwarze  419:        if (man->os)
                    420:                print_text(h, man->os);
1.4       kristaps  421:        print_tagq(h, t);
                    422: }
                    423:
                    424:
                    425: static int
                    426: man_br_pre(MAN_ARGS)
                    427: {
1.7       kristaps  428:        struct roffsu    su;
1.4       kristaps  429:
1.7       kristaps  430:        SCALE_VS_INIT(&su, 1);
                    431:
1.49      kristaps  432:        if (MAN_sp == n->tok) {
1.75      kristaps  433:                if (NULL != (n = n->child))
                    434:                        if ( ! a2roffsu(n->string, &su, SCALE_VS))
1.108     schwarze  435:                                su.scale = 1.0;
1.49      kristaps  436:        } else
1.96      schwarze  437:                su.scale = 0.0;
1.4       kristaps  438:
1.122     schwarze  439:        print_otag(h, TAG_DIV, "suh", &su);
1.24      kristaps  440:
1.16      kristaps  441:        /* So the div isn't empty: */
                    442:        print_text(h, "\\~");
                    443:
1.119     schwarze  444:        return 0;
1.4       kristaps  445: }
                    446:
                    447: static int
                    448: man_SH_pre(MAN_ARGS)
                    449: {
1.134     schwarze  450:        char    *id;
                    451:
                    452:        if (n->type == ROFFT_HEAD) {
                    453:                id = html_make_id(n);
                    454:                print_otag(h, TAG_H1, "cTi", "Sh", id);
1.135     schwarze  455:                if (id != NULL)
                    456:                        print_otag(h, TAG_A, "chR", "selflink", id);
1.134     schwarze  457:                free(id);
                    458:        }
1.119     schwarze  459:        return 1;
1.4       kristaps  460: }
                    461:
                    462: static int
1.8       kristaps  463: man_alt_pre(MAN_ARGS)
                    464: {
1.114     schwarze  465:        const struct roff_node  *nn;
1.130     schwarze  466:        int              i;
1.57      kristaps  467:        enum htmltag     fp;
                    468:        struct tag      *t;
1.8       kristaps  469:
                    470:        for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
                    471:                switch (n->tok) {
1.93      schwarze  472:                case MAN_BI:
1.57      kristaps  473:                        fp = i % 2 ? TAG_I : TAG_B;
1.8       kristaps  474:                        break;
1.93      schwarze  475:                case MAN_IB:
1.57      kristaps  476:                        fp = i % 2 ? TAG_B : TAG_I;
1.8       kristaps  477:                        break;
1.93      schwarze  478:                case MAN_RI:
1.57      kristaps  479:                        fp = i % 2 ? TAG_I : TAG_MAX;
1.8       kristaps  480:                        break;
1.93      schwarze  481:                case MAN_IR:
1.57      kristaps  482:                        fp = i % 2 ? TAG_MAX : TAG_I;
1.8       kristaps  483:                        break;
1.93      schwarze  484:                case MAN_BR:
1.57      kristaps  485:                        fp = i % 2 ? TAG_MAX : TAG_B;
1.8       kristaps  486:                        break;
1.93      schwarze  487:                case MAN_RB:
1.57      kristaps  488:                        fp = i % 2 ? TAG_B : TAG_MAX;
1.8       kristaps  489:                        break;
                    490:                default:
                    491:                        abort();
                    492:                }
                    493:
                    494:                if (i)
                    495:                        h->flags |= HTML_NOSPACE;
                    496:
1.130     schwarze  497:                if (fp != TAG_MAX)
1.122     schwarze  498:                        t = print_otag(h, fp, "");
1.57      kristaps  499:
1.130     schwarze  500:                print_text(h, nn->string);
1.57      kristaps  501:
1.130     schwarze  502:                if (fp != TAG_MAX)
1.57      kristaps  503:                        print_tagq(h, t);
1.8       kristaps  504:        }
1.119     schwarze  505:        return 0;
1.8       kristaps  506: }
                    507:
                    508: static int
1.56      kristaps  509: man_SM_pre(MAN_ARGS)
1.8       kristaps  510: {
1.122     schwarze  511:        print_otag(h, TAG_SMALL, "");
1.56      kristaps  512:        if (MAN_SB == n->tok)
1.122     schwarze  513:                print_otag(h, TAG_B, "");
1.119     schwarze  514:        return 1;
1.8       kristaps  515: }
                    516:
                    517: static int
1.4       kristaps  518: man_SS_pre(MAN_ARGS)
                    519: {
1.134     schwarze  520:        char    *id;
                    521:
                    522:        if (n->type == ROFFT_HEAD) {
                    523:                id = html_make_id(n);
                    524:                print_otag(h, TAG_H2, "cTi", "Ss", id);
1.135     schwarze  525:                if (id != NULL)
                    526:                        print_otag(h, TAG_A, "chR", "selflink", id);
1.134     schwarze  527:                free(id);
                    528:        }
1.119     schwarze  529:        return 1;
1.4       kristaps  530: }
                    531:
                    532: static int
                    533: man_PP_pre(MAN_ARGS)
                    534: {
                    535:
1.113     schwarze  536:        if (n->type == ROFFT_HEAD)
1.119     schwarze  537:                return 0;
1.113     schwarze  538:        else if (n->type == ROFFT_BLOCK)
1.74      kristaps  539:                print_bvspace(h, n);
1.47      kristaps  540:
1.119     schwarze  541:        return 1;
1.5       kristaps  542: }
                    543:
                    544: static int
                    545: man_IP_pre(MAN_ARGS)
                    546: {
1.114     schwarze  547:        const struct roff_node  *nn;
1.5       kristaps  548:
1.113     schwarze  549:        if (n->type == ROFFT_BODY) {
1.129     schwarze  550:                print_otag(h, TAG_DD, "c", "It-tag");
1.119     schwarze  551:                return 1;
1.113     schwarze  552:        } else if (n->type != ROFFT_HEAD) {
1.129     schwarze  553:                print_otag(h, TAG_DL, "c", "Bl-tag");
1.119     schwarze  554:                return 1;
1.6       kristaps  555:        }
                    556:
1.78      kristaps  557:        /* FIXME: width specification. */
                    558:
1.129     schwarze  559:        print_otag(h, TAG_DT, "c", "It-tag");
1.6       kristaps  560:
1.59      schwarze  561:        /* For IP, only print the first header element. */
1.7       kristaps  562:
1.59      schwarze  563:        if (MAN_IP == n->tok && n->child)
1.132     schwarze  564:                print_man_node(man, n->child, h);
1.27      kristaps  565:
1.59      schwarze  566:        /* For TP, only print next-line header elements. */
1.6       kristaps  567:
1.91      schwarze  568:        if (MAN_TP == n->tok) {
                    569:                nn = n->child;
1.121     schwarze  570:                while (NULL != nn && 0 == (NODE_LINE & nn->flags))
1.91      schwarze  571:                        nn = nn->next;
                    572:                while (NULL != nn) {
1.132     schwarze  573:                        print_man_node(man, nn, h);
1.91      schwarze  574:                        nn = nn->next;
                    575:                }
                    576:        }
1.6       kristaps  577:
1.119     schwarze  578:        return 0;
1.6       kristaps  579: }
                    580:
                    581: static int
                    582: man_HP_pre(MAN_ARGS)
                    583: {
1.122     schwarze  584:        struct roffsu    sum, sui;
1.114     schwarze  585:        const struct roff_node *np;
1.6       kristaps  586:
1.113     schwarze  587:        if (n->type == ROFFT_HEAD)
1.119     schwarze  588:                return 0;
1.113     schwarze  589:        else if (n->type != ROFFT_BLOCK)
1.119     schwarze  590:                return 1;
1.72      kristaps  591:
1.77      kristaps  592:        np = n->head->child;
1.6       kristaps  593:
1.122     schwarze  594:        if (np == NULL || !a2width(np, &sum))
                    595:                SCALE_HS_INIT(&sum, INDENT);
1.6       kristaps  596:
1.122     schwarze  597:        sui.unit = sum.unit;
                    598:        sui.scale = -sum.scale;
1.5       kristaps  599:
1.77      kristaps  600:        print_bvspace(h, n);
1.127     schwarze  601:        print_otag(h, TAG_DIV, "csului", "Pp", &sum, &sui);
1.119     schwarze  602:        return 1;
1.4       kristaps  603: }
1.86      kristaps  604:
                    605: static int
                    606: man_OP_pre(MAN_ARGS)
                    607: {
                    608:        struct tag      *tt;
                    609:
                    610:        print_text(h, "[");
                    611:        h->flags |= HTML_NOSPACE;
1.128     schwarze  612:        tt = print_otag(h, TAG_SPAN, "c", "Op");
1.86      kristaps  613:
                    614:        if (NULL != (n = n->child)) {
1.122     schwarze  615:                print_otag(h, TAG_B, "");
1.86      kristaps  616:                print_text(h, n->string);
                    617:        }
                    618:
                    619:        print_stagq(h, tt);
                    620:
                    621:        if (NULL != n && NULL != n->next) {
1.122     schwarze  622:                print_otag(h, TAG_I, "");
1.86      kristaps  623:                print_text(h, n->next->string);
                    624:        }
                    625:
                    626:        print_stagq(h, tt);
                    627:        h->flags |= HTML_NOSPACE;
                    628:        print_text(h, "]");
1.119     schwarze  629:        return 0;
1.86      kristaps  630: }
                    631:
1.8       kristaps  632: static int
                    633: man_B_pre(MAN_ARGS)
                    634: {
1.122     schwarze  635:        print_otag(h, TAG_B, "");
1.119     schwarze  636:        return 1;
1.8       kristaps  637: }
                    638:
                    639: static int
                    640: man_I_pre(MAN_ARGS)
                    641: {
1.122     schwarze  642:        print_otag(h, TAG_I, "");
1.119     schwarze  643:        return 1;
1.45      kristaps  644: }
                    645:
                    646: static int
                    647: man_in_pre(MAN_ARGS)
                    648: {
1.122     schwarze  649:        print_otag(h, TAG_BR, "");
1.119     schwarze  650:        return 0;
1.8       kristaps  651: }
                    652:
                    653: static int
                    654: man_ign_pre(MAN_ARGS)
                    655: {
                    656:
1.119     schwarze  657:        return 0;
1.8       kristaps  658: }
1.9       kristaps  659:
                    660: static int
                    661: man_RS_pre(MAN_ARGS)
                    662: {
                    663:        struct roffsu    su;
                    664:
1.113     schwarze  665:        if (n->type == ROFFT_HEAD)
1.119     schwarze  666:                return 0;
1.113     schwarze  667:        else if (n->type == ROFFT_BODY)
1.119     schwarze  668:                return 1;
1.9       kristaps  669:
                    670:        SCALE_HS_INIT(&su, INDENT);
1.56      kristaps  671:        if (n->head->child)
1.9       kristaps  672:                a2width(n->head->child, &su);
                    673:
1.122     schwarze  674:        print_otag(h, TAG_DIV, "sul", &su);
1.119     schwarze  675:        return 1;
1.90      schwarze  676: }
                    677:
                    678: static int
                    679: man_UR_pre(MAN_ARGS)
                    680: {
                    681:        n = n->child;
1.113     schwarze  682:        assert(n->type == ROFFT_HEAD);
1.120     schwarze  683:        if (n->child != NULL) {
1.113     schwarze  684:                assert(n->child->type == ROFFT_TEXT);
1.134     schwarze  685:                print_otag(h, TAG_A, "cTh", "Lk", n->child->string);
1.90      schwarze  686:        }
                    687:
1.113     schwarze  688:        assert(n->next->type == ROFFT_BODY);
1.120     schwarze  689:        if (n->next->child != NULL)
1.90      schwarze  690:                n = n->next;
                    691:
1.132     schwarze  692:        print_man_nodelist(man, n->child, h);
1.90      schwarze  693:
1.119     schwarze  694:        return 0;
1.9       kristaps  695: }

CVSweb