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

Annotation of mandoc/man_html.c, Revision 1.140

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

CVSweb