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

Annotation of mandoc/man_html.c, Revision 1.136

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

CVSweb