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

Annotation of mandoc/man_html.c, Revision 1.159

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

CVSweb