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

Annotation of mandoc/man_html.c, Revision 1.147

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

CVSweb