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

Annotation of mandoc/mdoc_html.c, Revision 1.6

1.6     ! kristaps    1: /*     $Id: mdoc_html.c,v 1.5 2009/09/24 09:50:31 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #include <sys/types.h>
                     18: #include <sys/queue.h>
                     19:
                     20: #include <assert.h>
                     21: #include <ctype.h>
                     22: #include <err.h>
                     23: #include <stdio.h>
                     24: #include <stdlib.h>
                     25: #include <string.h>
                     26: #include <unistd.h>
                     27:
                     28: #include "html.h"
                     29: #include "mdoc.h"
                     30:
                     31: #define        INDENT           5
                     32: #define        HALFINDENT       3
                     33:
                     34: #define        MDOC_ARGS         const struct mdoc_meta *m, \
                     35:                          const struct mdoc_node *n, \
                     36:                          struct html *h
                     37: #define        MAN_ARGS          const struct man_meta *m, \
                     38:                          const struct man_node *n, \
                     39:                          struct html *h
                     40:
                     41: struct htmlmdoc {
                     42:        int             (*pre)(MDOC_ARGS);
                     43:        void            (*post)(MDOC_ARGS);
                     44: };
                     45:
                     46: static void              print_mdoc(MDOC_ARGS);
                     47: static void              print_mdoc_head(MDOC_ARGS);
                     48: static void              print_mdoc_node(MDOC_ARGS);
                     49: static void              print_mdoc_nodelist(MDOC_ARGS);
                     50:
                     51: static int               a2width(const char *);
                     52: static int               a2offs(const char *);
                     53: static int               a2list(const struct mdoc_node *);
                     54:
                     55: static void              mdoc_root_post(MDOC_ARGS);
                     56: static int               mdoc_root_pre(MDOC_ARGS);
                     57: static int               mdoc_tbl_pre(MDOC_ARGS, int);
                     58: static int               mdoc_tbl_block_pre(MDOC_ARGS, int, int, int, int);
                     59: static int               mdoc_tbl_body_pre(MDOC_ARGS, int, int);
                     60: static int               mdoc_tbl_head_pre(MDOC_ARGS, int, int);
                     61:
                     62: static int               mdoc_ad_pre(MDOC_ARGS);
                     63: static int               mdoc_an_pre(MDOC_ARGS);
1.5       kristaps   64: static int               mdoc_ap_pre(MDOC_ARGS);
1.1       kristaps   65: static void              mdoc_aq_post(MDOC_ARGS);
                     66: static int               mdoc_aq_pre(MDOC_ARGS);
                     67: static int               mdoc_ar_pre(MDOC_ARGS);
                     68: static int               mdoc_bd_pre(MDOC_ARGS);
1.5       kristaps   69: static int               mdoc_bf_pre(MDOC_ARGS);
1.1       kristaps   70: static void              mdoc_bl_post(MDOC_ARGS);
                     71: static int               mdoc_bl_pre(MDOC_ARGS);
1.4       kristaps   72: static void              mdoc_bq_post(MDOC_ARGS);
                     73: static int               mdoc_bq_pre(MDOC_ARGS);
1.2       kristaps   74: static void              mdoc_brq_post(MDOC_ARGS);
                     75: static int               mdoc_brq_pre(MDOC_ARGS);
1.6     ! kristaps   76: static int               mdoc_bt_pre(MDOC_ARGS);
1.4       kristaps   77: static int               mdoc_bx_pre(MDOC_ARGS);
1.1       kristaps   78: static int               mdoc_cd_pre(MDOC_ARGS);
                     79: static int               mdoc_d1_pre(MDOC_ARGS);
                     80: static void              mdoc_dq_post(MDOC_ARGS);
                     81: static int               mdoc_dq_pre(MDOC_ARGS);
                     82: static int               mdoc_dv_pre(MDOC_ARGS);
                     83: static int               mdoc_fa_pre(MDOC_ARGS);
                     84: static int               mdoc_fd_pre(MDOC_ARGS);
                     85: static int               mdoc_fl_pre(MDOC_ARGS);
                     86: static int               mdoc_fn_pre(MDOC_ARGS);
                     87: static int               mdoc_ft_pre(MDOC_ARGS);
                     88: static int               mdoc_em_pre(MDOC_ARGS);
                     89: static int               mdoc_er_pre(MDOC_ARGS);
                     90: static int               mdoc_ev_pre(MDOC_ARGS);
                     91: static int               mdoc_ex_pre(MDOC_ARGS);
1.4       kristaps   92: static void              mdoc_fo_post(MDOC_ARGS);
                     93: static int               mdoc_fo_pre(MDOC_ARGS);
                     94: static int               mdoc_ic_pre(MDOC_ARGS);
                     95: static int               mdoc_in_pre(MDOC_ARGS);
1.1       kristaps   96: static int               mdoc_it_pre(MDOC_ARGS);
1.6     ! kristaps   97: static int               mdoc_lb_pre(MDOC_ARGS);
        !            98: static int               mdoc_li_pre(MDOC_ARGS);
1.2       kristaps   99: static int               mdoc_lk_pre(MDOC_ARGS);
                    100: static int               mdoc_mt_pre(MDOC_ARGS);
1.5       kristaps  101: static int               mdoc_ms_pre(MDOC_ARGS);
1.1       kristaps  102: static int               mdoc_nd_pre(MDOC_ARGS);
                    103: static int               mdoc_nm_pre(MDOC_ARGS);
                    104: static int               mdoc_ns_pre(MDOC_ARGS);
                    105: static void              mdoc_op_post(MDOC_ARGS);
                    106: static int               mdoc_op_pre(MDOC_ARGS);
                    107: static int               mdoc_pa_pre(MDOC_ARGS);
1.5       kristaps  108: static void              mdoc_pf_post(MDOC_ARGS);
                    109: static int               mdoc_pf_pre(MDOC_ARGS);
1.1       kristaps  110: static void              mdoc_pq_post(MDOC_ARGS);
                    111: static int               mdoc_pq_pre(MDOC_ARGS);
1.5       kristaps  112: static int               mdoc_rs_pre(MDOC_ARGS);
1.4       kristaps  113: static int               mdoc_rv_pre(MDOC_ARGS);
1.1       kristaps  114: static int               mdoc_sh_pre(MDOC_ARGS);
                    115: static int               mdoc_sp_pre(MDOC_ARGS);
                    116: static void              mdoc_sq_post(MDOC_ARGS);
                    117: static int               mdoc_sq_pre(MDOC_ARGS);
                    118: static int               mdoc_ss_pre(MDOC_ARGS);
                    119: static int               mdoc_sx_pre(MDOC_ARGS);
1.6     ! kristaps  120: static int               mdoc_sy_pre(MDOC_ARGS);
        !           121: static int               mdoc_ud_pre(MDOC_ARGS);
1.4       kristaps  122: static int               mdoc_va_pre(MDOC_ARGS);
1.1       kristaps  123: static int               mdoc_vt_pre(MDOC_ARGS);
                    124: static int               mdoc_xr_pre(MDOC_ARGS);
                    125: static int               mdoc_xx_pre(MDOC_ARGS);
                    126:
                    127: #ifdef __linux__
                    128: extern size_t            strlcpy(char *, const char *, size_t);
                    129: extern size_t            strlcat(char *, const char *, size_t);
                    130: #endif
                    131:
                    132: static const struct htmlmdoc mdocs[MDOC_MAX] = {
1.5       kristaps  133:        {mdoc_ap_pre, NULL}, /* Ap */
1.1       kristaps  134:        {NULL, NULL}, /* Dd */
                    135:        {NULL, NULL}, /* Dt */
                    136:        {NULL, NULL}, /* Os */
                    137:        {mdoc_sh_pre, NULL }, /* Sh */
                    138:        {mdoc_ss_pre, NULL }, /* Ss */
                    139:        {mdoc_sp_pre, NULL}, /* Pp */
                    140:        {mdoc_d1_pre, NULL}, /* D1 */
                    141:        {mdoc_d1_pre, NULL}, /* Dl */
                    142:        {mdoc_bd_pre, NULL}, /* Bd */
                    143:        {NULL, NULL}, /* Ed */
                    144:        {mdoc_bl_pre, mdoc_bl_post}, /* Bl */
                    145:        {NULL, NULL}, /* El */
                    146:        {mdoc_it_pre, NULL}, /* It */
                    147:        {mdoc_ad_pre, NULL}, /* Ad */
                    148:        {mdoc_an_pre, NULL}, /* An */
                    149:        {mdoc_ar_pre, NULL}, /* Ar */
                    150:        {mdoc_cd_pre, NULL}, /* Cd */
                    151:        {mdoc_fl_pre, NULL}, /* Cm */
                    152:        {mdoc_dv_pre, NULL}, /* Dv */
                    153:        {mdoc_er_pre, NULL}, /* Er */
                    154:        {mdoc_ev_pre, NULL}, /* Ev */
                    155:        {mdoc_ex_pre, NULL}, /* Ex */
                    156:        {mdoc_fa_pre, NULL}, /* Fa */
                    157:        {mdoc_fd_pre, NULL}, /* Fd */
                    158:        {mdoc_fl_pre, NULL}, /* Fl */
                    159:        {mdoc_fn_pre, NULL}, /* Fn */
                    160:        {mdoc_ft_pre, NULL}, /* Ft */
1.4       kristaps  161:        {mdoc_ic_pre, NULL}, /* Ic */
                    162:        {mdoc_in_pre, NULL}, /* In */
1.6     ! kristaps  163:        {mdoc_li_pre, NULL}, /* Li */
1.1       kristaps  164:        {mdoc_nd_pre, NULL}, /* Nd */
                    165:        {mdoc_nm_pre, NULL}, /* Nm */
                    166:        {mdoc_op_pre, mdoc_op_post}, /* Op */
                    167:        {NULL, NULL}, /* Ot */
                    168:        {mdoc_pa_pre, NULL}, /* Pa */
1.4       kristaps  169:        {mdoc_rv_pre, NULL}, /* Rv */
1.1       kristaps  170:        {NULL, NULL}, /* St */
1.4       kristaps  171:        {mdoc_va_pre, NULL}, /* Va */
1.1       kristaps  172:        {mdoc_vt_pre, NULL}, /* Vt */
                    173:        {mdoc_xr_pre, NULL}, /* Xr */
                    174:        {NULL, NULL}, /* %A */
                    175:        {NULL, NULL}, /* %B */
                    176:        {NULL, NULL}, /* %D */
                    177:        {NULL, NULL}, /* %I */
                    178:        {NULL, NULL}, /* %J */
                    179:        {NULL, NULL}, /* %N */
                    180:        {NULL, NULL}, /* %O */
                    181:        {NULL, NULL}, /* %P */
                    182:        {NULL, NULL}, /* %R */
                    183:        {NULL, NULL}, /* %T */
                    184:        {NULL, NULL}, /* %V */
                    185:        {NULL, NULL}, /* Ac */
                    186:        {mdoc_aq_pre, mdoc_aq_post}, /* Ao */
                    187:        {mdoc_aq_pre, mdoc_aq_post}, /* Aq */
                    188:        {NULL, NULL}, /* At */
                    189:        {NULL, NULL}, /* Bc */
1.5       kristaps  190:        {mdoc_bf_pre, NULL}, /* Bf */
1.4       kristaps  191:        {mdoc_bq_pre, mdoc_bq_post}, /* Bo */
                    192:        {mdoc_bq_pre, mdoc_bq_post}, /* Bq */
1.1       kristaps  193:        {mdoc_xx_pre, NULL}, /* Bsx */
1.4       kristaps  194:        {mdoc_bx_pre, NULL}, /* Bx */
1.1       kristaps  195:        {NULL, NULL}, /* Db */
                    196:        {NULL, NULL}, /* Dc */
1.4       kristaps  197:        {mdoc_dq_pre, mdoc_dq_post}, /* Do */
1.1       kristaps  198:        {mdoc_dq_pre, mdoc_dq_post}, /* Dq */
                    199:        {NULL, NULL}, /* Ec */
                    200:        {NULL, NULL}, /* Ef */
                    201:        {mdoc_em_pre, NULL}, /* Em */
                    202:        {NULL, NULL}, /* Eo */
                    203:        {mdoc_xx_pre, NULL}, /* Fx */
1.5       kristaps  204:        {mdoc_ms_pre, NULL}, /* Ms */ /* FIXME: convert to symbol? */
1.1       kristaps  205:        {NULL, NULL}, /* No */
                    206:        {mdoc_ns_pre, NULL}, /* Ns */
                    207:        {mdoc_xx_pre, NULL}, /* Nx */
                    208:        {mdoc_xx_pre, NULL}, /* Ox */
                    209:        {NULL, NULL}, /* Pc */
1.5       kristaps  210:        {mdoc_pf_pre, mdoc_pf_post}, /* Pf */
1.1       kristaps  211:        {mdoc_pq_pre, mdoc_pq_post}, /* Po */
                    212:        {mdoc_pq_pre, mdoc_pq_post}, /* Pq */
                    213:        {NULL, NULL}, /* Qc */
1.4       kristaps  214:        {mdoc_sq_pre, mdoc_sq_post}, /* Ql */
1.5       kristaps  215:        {mdoc_dq_pre, mdoc_dq_post}, /* Qo */
                    216:        {mdoc_dq_pre, mdoc_dq_post}, /* Qq */
1.1       kristaps  217:        {NULL, NULL}, /* Re */
1.5       kristaps  218:        {mdoc_rs_pre, NULL}, /* Rs */
1.1       kristaps  219:        {NULL, NULL}, /* Sc */
                    220:        {mdoc_sq_pre, mdoc_sq_post}, /* So */
                    221:        {mdoc_sq_pre, mdoc_sq_post}, /* Sq */
1.6     ! kristaps  222:        {NULL, NULL}, /* Sm */ /* FIXME - no idea. */
1.1       kristaps  223:        {mdoc_sx_pre, NULL}, /* Sx */
1.6     ! kristaps  224:        {mdoc_sy_pre, NULL}, /* Sy */
1.1       kristaps  225:        {NULL, NULL}, /* Tn */
                    226:        {mdoc_xx_pre, NULL}, /* Ux */
                    227:        {NULL, NULL}, /* Xc */
                    228:        {NULL, NULL}, /* Xo */
1.4       kristaps  229:        {mdoc_fo_pre, mdoc_fo_post}, /* Fo */
1.1       kristaps  230:        {NULL, NULL}, /* Fc */
1.4       kristaps  231:        {mdoc_op_pre, mdoc_op_post}, /* Oo */
1.1       kristaps  232:        {NULL, NULL}, /* Oc */
                    233:        {NULL, NULL}, /* Bk */
                    234:        {NULL, NULL}, /* Ek */
1.6     ! kristaps  235:        {mdoc_bt_pre, NULL}, /* Bt */
1.1       kristaps  236:        {NULL, NULL}, /* Hf */
                    237:        {NULL, NULL}, /* Fr */
1.6     ! kristaps  238:        {mdoc_ud_pre, NULL}, /* Ud */
        !           239:        {mdoc_lb_pre, NULL}, /* Lb */
1.1       kristaps  240:        {mdoc_sp_pre, NULL}, /* Lp */
1.2       kristaps  241:        {mdoc_lk_pre, NULL}, /* Lk */
                    242:        {mdoc_mt_pre, NULL}, /* Mt */
                    243:        {mdoc_brq_pre, mdoc_brq_post}, /* Brq */
                    244:        {mdoc_brq_pre, mdoc_brq_post}, /* Bro */
1.1       kristaps  245:        {NULL, NULL}, /* Brc */
                    246:        {NULL, NULL}, /* %C */
1.2       kristaps  247:        {NULL, NULL}, /* Es */  /* TODO */
                    248:        {NULL, NULL}, /* En */  /* TODO */
1.1       kristaps  249:        {mdoc_xx_pre, NULL}, /* Dx */
                    250:        {NULL, NULL}, /* %Q */
                    251:        {mdoc_sp_pre, NULL}, /* br */
                    252:        {mdoc_sp_pre, NULL}, /* sp */
                    253: };
                    254:
                    255: static char              buf[BUFSIZ]; /* XXX */
                    256:
                    257: #define        bufcat(x)         (void)strlcat(buf, (x), BUFSIZ)
                    258: #define        bufinit()         buf[0] = 0
                    259: #define        buffmt(...)       (void)snprintf(buf, BUFSIZ - 1, __VA_ARGS__)
                    260:
                    261: void
                    262: html_mdoc(void *arg, const struct mdoc *m)
                    263: {
                    264:        struct html     *h;
                    265:        struct tag      *t;
                    266:
                    267:        h = (struct html *)arg;
                    268:
                    269:        print_gen_doctype(h);
                    270:        t = print_otag(h, TAG_HTML, 0, NULL);
                    271:        print_mdoc(mdoc_meta(m), mdoc_node(m), h);
                    272:        print_tagq(h, t);
                    273:
                    274:        printf("\n");
                    275: }
                    276:
                    277:
                    278: static int
                    279: a2list(const struct mdoc_node *n)
                    280: {
                    281:        int              i;
                    282:
                    283:        assert(MDOC_BLOCK == n->type && MDOC_Bl == n->tok);
                    284:        assert(n->args);
                    285:
                    286:        for (i = 0; i < (int)n->args->argc; i++)
                    287:                switch (n->args->argv[i].arg) {
                    288:                case (MDOC_Enum):
                    289:                        /* FALLTHROUGH */
                    290:                case (MDOC_Dash):
                    291:                        /* FALLTHROUGH */
                    292:                case (MDOC_Hyphen):
                    293:                        /* FALLTHROUGH */
                    294:                case (MDOC_Bullet):
                    295:                        /* FALLTHROUGH */
                    296:                case (MDOC_Tag):
                    297:                        /* FALLTHROUGH */
                    298:                case (MDOC_Hang):
                    299:                        /* FALLTHROUGH */
                    300:                case (MDOC_Inset):
                    301:                        /* FALLTHROUGH */
                    302:                case (MDOC_Diag):
                    303:                        /* FALLTHROUGH */
                    304:                case (MDOC_Item):
                    305:                        /* FALLTHROUGH */
                    306:                case (MDOC_Column):
                    307:                        /* FALLTHROUGH */
                    308:                case (MDOC_Ohang):
                    309:                        return(n->args->argv[i].arg);
                    310:                default:
                    311:                        break;
                    312:                }
                    313:
                    314:        abort();
                    315:        /* NOTREACHED */
                    316: }
                    317:
                    318:
                    319: static int
                    320: a2width(const char *p)
                    321: {
                    322:        int              i, len;
                    323:
                    324:        if (0 == (len = (int)strlen(p)))
                    325:                return(0);
                    326:        for (i = 0; i < len - 1; i++)
                    327:                if ( ! isdigit((u_char)p[i]))
                    328:                        break;
                    329:
                    330:        if (i == len - 1)
                    331:                if ('n' == p[len - 1] || 'm' == p[len - 1])
                    332:                        return(atoi(p) + 2);
                    333:
                    334:        return(len + 2);
                    335: }
                    336:
                    337:
                    338: static int
                    339: a2offs(const char *p)
                    340: {
                    341:        int              len, i;
                    342:
                    343:        if (0 == strcmp(p, "left"))
                    344:                return(0);
                    345:        if (0 == strcmp(p, "indent"))
                    346:                return(INDENT + 1);
                    347:        if (0 == strcmp(p, "indent-two"))
                    348:                return((INDENT + 1) * 2);
                    349:
                    350:        if (0 == (len = (int)strlen(p)))
                    351:                return(0);
                    352:
                    353:        for (i = 0; i < len - 1; i++)
                    354:                if ( ! isdigit((u_char)p[i]))
                    355:                        break;
                    356:
                    357:        if (i == len - 1)
                    358:                if ('n' == p[len - 1] || 'm' == p[len - 1])
                    359:                        return(atoi(p));
                    360:
                    361:        return(len);
                    362: }
                    363:
                    364:
                    365: static void
                    366: print_mdoc(MDOC_ARGS)
                    367: {
                    368:        struct tag      *t;
                    369:        struct htmlpair  tag;
                    370:
                    371:        t = print_otag(h, TAG_HEAD, 0, NULL);
                    372:        print_mdoc_head(m, n, h);
                    373:        print_tagq(h, t);
                    374:
                    375:        t = print_otag(h, TAG_BODY, 0, NULL);
                    376:
                    377:        tag.key = ATTR_CLASS;
                    378:        tag.val = "body";
                    379:        print_otag(h, TAG_DIV, 1, &tag);
                    380:
                    381:        print_mdoc_nodelist(m, n, h);
                    382:        print_tagq(h, t);
                    383: }
                    384:
                    385:
                    386: /* ARGSUSED */
                    387: static void
                    388: print_mdoc_head(MDOC_ARGS)
                    389: {
                    390:        char            b[BUFSIZ];
                    391:
                    392:        print_gen_head(h);
                    393:
                    394:        (void)snprintf(b, BUFSIZ - 1,
                    395:                        "%s(%d)", m->title, m->msec);
                    396:
                    397:        if (m->arch) {
                    398:                (void)strlcat(b, " (", BUFSIZ);
                    399:                (void)strlcat(b, m->arch, BUFSIZ);
                    400:                (void)strlcat(b, ")", BUFSIZ);
                    401:        }
                    402:
                    403:        print_otag(h, TAG_TITLE, 0, NULL);
                    404:        print_text(h, b);
                    405: }
                    406:
                    407:
                    408: static void
                    409: print_mdoc_nodelist(MDOC_ARGS)
                    410: {
                    411:
                    412:        print_mdoc_node(m, n, h);
                    413:        if (n->next)
                    414:                print_mdoc_nodelist(m, n->next, h);
                    415: }
                    416:
                    417:
                    418: static void
                    419: print_mdoc_node(MDOC_ARGS)
                    420: {
                    421:        int              child;
                    422:        struct tag      *t;
                    423:
                    424:        child = 1;
                    425:        t = SLIST_FIRST(&h->tags);
                    426:
                    427:        bufinit();
                    428:
                    429:        switch (n->type) {
                    430:        case (MDOC_ROOT):
                    431:                child = mdoc_root_pre(m, n, h);
                    432:                break;
                    433:        case (MDOC_TEXT):
                    434:                print_text(h, n->string);
                    435:                break;
                    436:        default:
                    437:                if (mdocs[n->tok].pre)
                    438:                        child = (*mdocs[n->tok].pre)(m, n, h);
                    439:                break;
                    440:        }
                    441:
                    442:        if (child && n->child)
                    443:                print_mdoc_nodelist(m, n->child, h);
                    444:
                    445:        print_stagq(h, t);
                    446:
                    447:        bufinit();
                    448:
                    449:        switch (n->type) {
                    450:        case (MDOC_ROOT):
                    451:                mdoc_root_post(m, n, h);
                    452:                break;
                    453:        case (MDOC_TEXT):
                    454:                break;
                    455:        default:
                    456:                if (mdocs[n->tok].post)
                    457:                        (*mdocs[n->tok].post)(m, n, h);
                    458:                break;
                    459:        }
                    460: }
                    461:
                    462:
                    463: /* ARGSUSED */
                    464: static void
                    465: mdoc_root_post(MDOC_ARGS)
                    466: {
                    467:        struct tm        tm;
                    468:        struct htmlpair  tag[2];
                    469:        struct tag      *t, *tt;
                    470:        char             b[BUFSIZ];
                    471:
                    472:        (void)localtime_r(&m->date, &tm);
                    473:
                    474:        if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", &tm))
                    475:                err(EXIT_FAILURE, "strftime");
                    476:
                    477:        tag[0].key = ATTR_CLASS;
                    478:        tag[0].val = "footer";
                    479:        tag[1].key = ATTR_STYLE;
                    480:        tag[1].val = "width: 100%;";
                    481:        t = print_otag(h, TAG_TABLE, 2, tag);
                    482:        tt = print_otag(h, TAG_TR, 0, NULL);
                    483:
                    484:        tag[0].key = ATTR_STYLE;
                    485:        tag[0].val = "width: 50%;";
                    486:        print_otag(h, TAG_TD, 1, tag);
                    487:        print_text(h, b);
                    488:        print_stagq(h, tt);
                    489:
                    490:        tag[0].key = ATTR_STYLE;
                    491:        tag[0].val = "width: 50%; text-align: right;";
                    492:        print_otag(h, TAG_TD, 1, tag);
                    493:        print_text(h, m->os);
                    494:        print_tagq(h, t);
                    495: }
                    496:
                    497:
                    498: /* ARGSUSED */
                    499: static int
                    500: mdoc_root_pre(MDOC_ARGS)
                    501: {
                    502:        struct htmlpair  tag[2];
                    503:        struct tag      *t, *tt;
                    504:        char             b[BUFSIZ], title[BUFSIZ];
                    505:
                    506:        (void)strlcpy(b, m->vol, BUFSIZ);
                    507:
                    508:        if (m->arch) {
                    509:                (void)strlcat(b, " (", BUFSIZ);
                    510:                (void)strlcat(b, m->arch, BUFSIZ);
                    511:                (void)strlcat(b, ")", BUFSIZ);
                    512:        }
                    513:
                    514:        (void)snprintf(title, BUFSIZ - 1,
                    515:                        "%s(%d)", m->title, m->msec);
                    516:
                    517:        tag[0].key = ATTR_CLASS;
                    518:        tag[0].val = "header";
                    519:        tag[1].key = ATTR_STYLE;
                    520:        tag[1].val = "width: 100%;";
                    521:        t = print_otag(h, TAG_TABLE, 2, tag);
                    522:        tt = print_otag(h, TAG_TR, 0, NULL);
                    523:
                    524:        tag[0].key = ATTR_STYLE;
                    525:        tag[0].val = "width: 33%;";
                    526:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  527:        print_text(h, title);
1.1       kristaps  528:        print_stagq(h, tt);
                    529:
                    530:        tag[0].key = ATTR_STYLE;
                    531:        tag[0].val = "width: 33%; text-align: center;";
                    532:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  533:        print_text(h, b);
1.1       kristaps  534:        print_stagq(h, tt);
                    535:
                    536:        tag[0].key = ATTR_STYLE;
                    537:        tag[0].val = "width: 33%; text-align: right;";
                    538:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  539:        print_text(h, title);
1.1       kristaps  540:        print_tagq(h, t);
                    541:
                    542:        return(1);
                    543: }
                    544:
                    545:
                    546: /* ARGSUSED */
                    547: static int
                    548: mdoc_sh_pre(MDOC_ARGS)
                    549: {
                    550:        struct htmlpair          tag[2];
                    551:        const struct mdoc_node  *nn;
                    552:
                    553:        if (MDOC_HEAD == n->type) {
                    554:                tag[0].key = ATTR_CLASS;
                    555:                tag[0].val = "sec-head";
                    556:                print_otag(h, TAG_DIV, 1, tag);
                    557:                print_otag(h, TAG_SPAN, 1, tag);
                    558:
                    559:                for (nn = n->child; nn; nn = nn->next) {
                    560:                        bufcat(nn->string);
                    561:                        if (nn->next)
                    562:                                bufcat(" ");
                    563:                }
                    564:                tag[0].key = ATTR_NAME;
                    565:                tag[0].val = buf;
                    566:                print_otag(h, TAG_A, 1, tag);
                    567:                return(1);
                    568:        } else if (MDOC_BLOCK == n->type) {
                    569:                tag[0].key = ATTR_CLASS;
                    570:                tag[0].val = "sec-block";
                    571:
                    572:                if (n->prev && NULL == n->prev->body->child) {
                    573:                        print_otag(h, TAG_DIV, 1, tag);
                    574:                        return(1);
                    575:                }
                    576:
                    577:                bufcat("margin-top: 1em;");
                    578:                if (NULL == n->next)
                    579:                        bufcat("margin-bottom: 1em;");
                    580:
                    581:                tag[1].key = ATTR_STYLE;
                    582:                tag[1].val = buf;
                    583:
                    584:                print_otag(h, TAG_DIV, 2, tag);
                    585:                return(1);
                    586:        }
                    587:
                    588:        buffmt("margin-left: %dem;", INDENT);
                    589:
                    590:        tag[0].key = ATTR_CLASS;
                    591:        tag[0].val = "sec-body";
                    592:        tag[1].key = ATTR_STYLE;
                    593:        tag[1].val = buf;
                    594:
                    595:        print_otag(h, TAG_DIV, 2, tag);
                    596:        return(1);
                    597: }
                    598:
                    599:
                    600: /* ARGSUSED */
                    601: static int
                    602: mdoc_ss_pre(MDOC_ARGS)
                    603: {
                    604:        struct htmlpair          tag[2];
                    605:        int                      i;
                    606:        const struct mdoc_node  *nn;
                    607:
                    608:        i = 0;
                    609:
                    610:        if (MDOC_BODY == n->type) {
                    611:                tag[i].key = ATTR_CLASS;
                    612:                tag[i++].val = "ssec-body";
                    613:                if (n->parent->next && n->child) {
                    614:                        bufcat("margin-bottom: 1em;");
                    615:                        tag[i].key = ATTR_STYLE;
                    616:                        tag[i++].val = buf;
                    617:                }
                    618:                print_otag(h, TAG_DIV, i, tag);
                    619:                return(1);
                    620:        } else if (MDOC_BLOCK == n->type) {
                    621:                tag[i].key = ATTR_CLASS;
                    622:                tag[i++].val = "ssec-block";
                    623:                if (n->prev) {
                    624:                        bufcat("margin-top: 1em;");
                    625:                        tag[i].key = ATTR_STYLE;
                    626:                        tag[i++].val = buf;
                    627:                }
                    628:                print_otag(h, TAG_DIV, i, tag);
                    629:                return(1);
                    630:        }
                    631:
                    632:        buffmt("margin-left: -%dem;", INDENT - HALFINDENT);
                    633:
                    634:        tag[0].key = ATTR_CLASS;
                    635:        tag[0].val = "ssec-head";
                    636:        tag[1].key = ATTR_STYLE;
                    637:        tag[1].val = buf;
                    638:
                    639:        print_otag(h, TAG_DIV, 2, tag);
                    640:        print_otag(h, TAG_SPAN, 1, tag);
                    641:
                    642:        bufinit();
                    643:        for (nn = n->child; nn; nn = nn->next) {
                    644:                bufcat(nn->string);
                    645:                if (nn->next)
                    646:                        bufcat(" ");
                    647:        }
                    648:        tag[0].key = ATTR_NAME;
                    649:        tag[0].val = buf;
                    650:        print_otag(h, TAG_A, 1, tag);
                    651:
                    652:        return(1);
                    653: }
                    654:
                    655:
                    656: /* ARGSUSED */
                    657: static int
                    658: mdoc_fl_pre(MDOC_ARGS)
                    659: {
                    660:        struct htmlpair  tag;
                    661:
                    662:        tag.key = ATTR_CLASS;
                    663:        tag.val = "flag";
                    664:
                    665:        print_otag(h, TAG_SPAN, 1, &tag);
                    666:        if (MDOC_Fl == n->tok) {
                    667:                print_text(h, "\\-");
                    668:                h->flags |= HTML_NOSPACE;
                    669:        }
                    670:        return(1);
                    671: }
                    672:
                    673:
                    674: /* ARGSUSED */
                    675: static int
                    676: mdoc_nd_pre(MDOC_ARGS)
                    677: {
                    678:        struct htmlpair  tag;
                    679:
                    680:        if (MDOC_BODY != n->type)
                    681:                return(1);
                    682:
                    683:        /* XXX - this can contain block elements! */
                    684:        print_text(h, "\\(em");
                    685:        tag.key = ATTR_CLASS;
                    686:        tag.val = "desc-body";
                    687:        print_otag(h, TAG_SPAN, 1, &tag);
                    688:        return(1);
                    689: }
                    690:
                    691:
                    692: /* ARGSUSED */
                    693: static int
                    694: mdoc_op_pre(MDOC_ARGS)
                    695: {
                    696:        struct htmlpair  tag;
                    697:
                    698:        if (MDOC_BODY != n->type)
                    699:                return(1);
                    700:
                    701:        /* XXX - this can contain block elements! */
                    702:        print_text(h, "\\(lB");
                    703:        h->flags |= HTML_NOSPACE;
                    704:        tag.key = ATTR_CLASS;
                    705:        tag.val = "opt";
                    706:        print_otag(h, TAG_SPAN, 1, &tag);
                    707:        return(1);
                    708: }
                    709:
                    710:
                    711: /* ARGSUSED */
                    712: static void
                    713: mdoc_op_post(MDOC_ARGS)
                    714: {
                    715:
                    716:        if (MDOC_BODY != n->type)
                    717:                return;
                    718:        h->flags |= HTML_NOSPACE;
                    719:        print_text(h, "\\(rB");
                    720: }
                    721:
                    722:
                    723: static int
                    724: mdoc_nm_pre(MDOC_ARGS)
                    725: {
                    726:        struct htmlpair tag;
                    727:
                    728:        if ( ! (HTML_NEWLINE & h->flags))
                    729:                if (SEC_SYNOPSIS == n->sec) {
                    730:                        tag.key = ATTR_STYLE;
                    731:                        tag.val = "clear: both;";
                    732:                        print_otag(h, TAG_BR, 1, &tag);
                    733:                }
                    734:
                    735:        tag.key = ATTR_CLASS;
                    736:        tag.val = "name";
                    737:
                    738:        print_otag(h, TAG_SPAN, 1, &tag);
                    739:        if (NULL == n->child)
                    740:                print_text(h, m->name);
                    741:
                    742:        return(1);
                    743: }
                    744:
                    745:
                    746: /* ARGSUSED */
                    747: static int
                    748: mdoc_xr_pre(MDOC_ARGS)
                    749: {
                    750:        struct htmlpair          tag[2];
                    751:        const char              *name, *sec;
                    752:        const struct mdoc_node  *nn;
                    753:
                    754:        nn = n->child;
                    755:        name = nn && nn->string ? nn->string : "";
                    756:        nn = nn ? nn->next : NULL;
                    757:        sec = nn && nn->string ? nn->string : "";
                    758:
                    759:        buffmt("%s%s%s.html", name, name && sec ? "." : "", sec);
                    760:
                    761:        tag[0].key = ATTR_CLASS;
                    762:        tag[0].val = "link-man";
                    763:        tag[1].key = ATTR_HREF;
                    764:        tag[1].val = buf;
                    765:        print_otag(h, TAG_A, 2, tag);
                    766:
                    767:        nn = n->child;
                    768:        print_text(h, nn->string);
                    769:        if (NULL == (nn = nn->next))
                    770:                return(0);
                    771:
                    772:        h->flags |= HTML_NOSPACE;
                    773:        print_text(h, "(");
                    774:        h->flags |= HTML_NOSPACE;
                    775:        print_text(h, nn->string);
                    776:        h->flags |= HTML_NOSPACE;
                    777:        print_text(h, ")");
                    778:
                    779:        return(0);
                    780: }
                    781:
                    782:
                    783: /* ARGSUSED */
                    784: static int
                    785: mdoc_ns_pre(MDOC_ARGS)
                    786: {
                    787:
                    788:        h->flags |= HTML_NOSPACE;
                    789:        return(1);
                    790: }
                    791:
                    792:
                    793: /* ARGSUSED */
                    794: static int
                    795: mdoc_ar_pre(MDOC_ARGS)
                    796: {
                    797:        struct htmlpair tag;
                    798:
                    799:        tag.key = ATTR_CLASS;
                    800:        tag.val = "arg";
                    801:
                    802:        print_otag(h, TAG_SPAN, 1, &tag);
                    803:        return(1);
                    804: }
                    805:
                    806:
                    807: /* ARGSUSED */
                    808: static int
                    809: mdoc_xx_pre(MDOC_ARGS)
                    810: {
                    811:        const char      *pp;
                    812:        struct htmlpair  tag;
                    813:
                    814:        switch (n->tok) {
                    815:        case (MDOC_Bsx):
                    816:                pp = "BSDI BSD/OS";
                    817:                break;
                    818:        case (MDOC_Dx):
                    819:                pp = "DragonFlyBSD";
                    820:                break;
                    821:        case (MDOC_Fx):
                    822:                pp = "FreeBSD";
                    823:                break;
                    824:        case (MDOC_Nx):
                    825:                pp = "NetBSD";
                    826:                break;
                    827:        case (MDOC_Ox):
                    828:                pp = "OpenBSD";
                    829:                break;
                    830:        case (MDOC_Ux):
                    831:                pp = "UNIX";
                    832:                break;
                    833:        default:
                    834:                return(1);
                    835:        }
                    836:
                    837:        tag.key = ATTR_CLASS;
                    838:        tag.val = "unix";
                    839:
                    840:        print_otag(h, TAG_SPAN, 1, &tag);
                    841:        print_text(h, pp);
                    842:        return(1);
                    843: }
                    844:
                    845:
                    846: /* ARGSUSED */
                    847: static int
1.4       kristaps  848: mdoc_bx_pre(MDOC_ARGS)
                    849: {
                    850:        const struct mdoc_node  *nn;
                    851:        struct htmlpair          tag;
                    852:
                    853:        tag.key = ATTR_CLASS;
                    854:        tag.val = "unix";
                    855:
                    856:        print_otag(h, TAG_SPAN, 1, &tag);
                    857:
                    858:        for (nn = n->child; nn; nn = nn->next)
                    859:                print_mdoc_node(m, nn, h);
                    860:
                    861:        if (n->child)
                    862:                h->flags |= HTML_NOSPACE;
                    863:
                    864:        print_text(h, "BSD");
                    865:        return(0);
                    866: }
                    867:
                    868:
                    869: /* ARGSUSED */
                    870: static int
1.1       kristaps  871: mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int c)
                    872: {
                    873:        struct htmlpair  tag;
                    874:
                    875:        switch (t) {
                    876:        case (MDOC_Column):
                    877:                /* FALLTHROUGH */
                    878:        case (MDOC_Item):
                    879:                /* FALLTHROUGH */
                    880:        case (MDOC_Ohang):
                    881:                buffmt("margin-left: %dem; clear: both;", o);
                    882:                break;
                    883:        default:
                    884:                buffmt("margin-left: %dem; clear: both;", w + o);
                    885:                break;
                    886:        }
                    887:
                    888:        if ( ! c && MDOC_Column != t) {
                    889:               if (n->prev && n->prev->body->child)
                    890:                       bufcat("padding-top: 1em;");
                    891:               else if (NULL == n->prev)
                    892:                       bufcat("padding-top: 1em;");
                    893:        }
                    894:
                    895:        tag.key = ATTR_STYLE;
                    896:        tag.val = buf;
                    897:        print_otag(h, TAG_DIV, 1, &tag);
                    898:        return(1);
                    899: }
                    900:
                    901:
                    902: /* ARGSUSED */
                    903: static int
                    904: mdoc_tbl_body_pre(MDOC_ARGS, int t, int w)
                    905: {
                    906:
                    907:        print_otag(h, TAG_DIV, 0, NULL);
                    908:        return(1);
                    909: }
                    910:
                    911:
                    912: /* ARGSUSED */
                    913: static int
                    914: mdoc_tbl_head_pre(MDOC_ARGS, int t, int w)
                    915: {
                    916:        struct htmlpair  tag;
                    917:        struct ord      *ord;
                    918:        char             nbuf[BUFSIZ];
                    919:
                    920:        switch (t) {
                    921:        case (MDOC_Item):
                    922:                /* FALLTHROUGH */
                    923:        case (MDOC_Ohang):
                    924:                print_otag(h, TAG_DIV, 0, NULL);
                    925:                break;
                    926:        case (MDOC_Column):
                    927:                buffmt("min-width: %dem;", w);
                    928:                bufcat("clear: none;");
                    929:                if (n->next && MDOC_HEAD == n->next->type)
                    930:                        bufcat("float: left;");
                    931:                tag.key = ATTR_STYLE;
                    932:                tag.val = buf;
                    933:                print_otag(h, TAG_DIV, 1, &tag);
                    934:                break;
                    935:        default:
1.4       kristaps  936:                buffmt("margin-left: -%dem; min-width: %dem;",
                    937:                                w, w ? w - 1 : 0);
1.1       kristaps  938:                bufcat("clear: left;");
1.2       kristaps  939:                if (n->next && n->next->child)
                    940:                        bufcat("float: left;");
1.1       kristaps  941:                bufcat("padding-right: 1em;");
                    942:                tag.key = ATTR_STYLE;
                    943:                tag.val = buf;
                    944:                print_otag(h, TAG_DIV, 1, &tag);
                    945:                break;
                    946:        }
                    947:
                    948:        switch (t) {
                    949:        case (MDOC_Diag):
                    950:                tag.key = ATTR_CLASS;
                    951:                tag.val = "diag";
                    952:                print_otag(h, TAG_SPAN, 1, &tag);
                    953:                break;
                    954:        case (MDOC_Enum):
                    955:                ord = SLIST_FIRST(&h->ords);
                    956:                assert(ord);
                    957:                nbuf[BUFSIZ - 1] = 0;
                    958:                (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
                    959:                print_text(h, nbuf);
                    960:                return(0);
                    961:        case (MDOC_Dash):
                    962:                print_text(h, "\\(en");
                    963:                return(0);
                    964:        case (MDOC_Hyphen):
1.4       kristaps  965:                print_text(h, "\\(hy");
1.1       kristaps  966:                return(0);
                    967:        case (MDOC_Bullet):
                    968:                print_text(h, "\\(bu");
                    969:                return(0);
                    970:        default:
                    971:                break;
                    972:        }
                    973:
                    974:        return(1);
                    975: }
                    976:
                    977:
                    978: static int
                    979: mdoc_tbl_pre(MDOC_ARGS, int type)
                    980: {
                    981:        int                      i, w, o, c, wp;
                    982:        const struct mdoc_node  *bl, *nn;
                    983:
                    984:        bl = n->parent->parent;
                    985:        if (MDOC_BLOCK != n->type)
                    986:                bl = bl->parent;
                    987:
                    988:        /* FIXME: fmt_vspace() equivalent. */
                    989:
                    990:        assert(bl->args);
                    991:
                    992:        w = o = c = 0;
                    993:        wp = -1;
                    994:
                    995:        for (i = 0; i < (int)bl->args->argc; i++)
                    996:                if (MDOC_Width == bl->args->argv[i].arg) {
                    997:                        assert(bl->args->argv[i].sz);
                    998:                        wp = i;
                    999:                        w = a2width(bl->args->argv[i].value[0]);
                   1000:                } else if (MDOC_Offset == bl->args->argv[i].arg) {
                   1001:                        assert(bl->args->argv[i].sz);
                   1002:                        o = a2offs(bl->args->argv[i].value[0]);
                   1003:                } else if (MDOC_Compact == bl->args->argv[i].arg)
                   1004:                        c = 1;
                   1005:
                   1006:        if (MDOC_HEAD == n->type && MDOC_Column == type) {
                   1007:                nn = n->parent->child;
                   1008:                assert(nn && MDOC_HEAD == nn->type);
                   1009:                for (i = 0; nn && nn != n; nn = nn->next, i++)
                   1010:                        /* Counter... */ ;
                   1011:                assert(nn);
                   1012:                if (wp >= 0 && i < (int)bl->args[wp].argv->sz)
                   1013:                        w = a2width(bl->args->argv[wp].value[i]);
                   1014:        }
                   1015:
                   1016:        switch (type) {
                   1017:        case (MDOC_Enum):
                   1018:                /* FALLTHROUGH */
                   1019:        case (MDOC_Dash):
                   1020:                /* FALLTHROUGH */
                   1021:        case (MDOC_Hyphen):
                   1022:                /* FALLTHROUGH */
                   1023:        case (MDOC_Bullet):
                   1024:                if (w < 4)
                   1025:                        w = 4;
                   1026:                break;
                   1027:        case (MDOC_Inset):
                   1028:                /* FALLTHROUGH */
                   1029:        case (MDOC_Diag):
                   1030:                w = 1;
                   1031:                break;
                   1032:        default:
                   1033:                if (0 == w)
                   1034:                        w = 10;
                   1035:                break;
                   1036:        }
                   1037:
                   1038:        switch (n->type) {
                   1039:        case (MDOC_BLOCK):
                   1040:                break;
                   1041:        case (MDOC_HEAD):
                   1042:                return(mdoc_tbl_head_pre(m, n, h, type, w));
                   1043:        case (MDOC_BODY):
                   1044:                return(mdoc_tbl_body_pre(m, n, h, type, w));
                   1045:        default:
                   1046:                abort();
                   1047:                /* NOTREACHED */
                   1048:        }
                   1049:
                   1050:        return(mdoc_tbl_block_pre(m, n, h, type, w, o, c));
                   1051: }
                   1052:
                   1053:
                   1054: /* ARGSUSED */
                   1055: static int
                   1056: mdoc_bl_pre(MDOC_ARGS)
                   1057: {
                   1058:        struct ord      *ord;
                   1059:
                   1060:        if (MDOC_BLOCK != n->type)
                   1061:                return(1);
                   1062:        if (MDOC_Enum != a2list(n))
                   1063:                return(1);
                   1064:
                   1065:        ord = malloc(sizeof(struct ord));
                   1066:        if (NULL == ord)
                   1067:                err(EXIT_FAILURE, "malloc");
                   1068:        ord->cookie = n;
                   1069:        ord->pos = 1;
                   1070:        SLIST_INSERT_HEAD(&h->ords, ord, entry);
                   1071:
                   1072:        return(1);
                   1073: }
                   1074:
                   1075:
                   1076: /* ARGSUSED */
                   1077: static void
                   1078: mdoc_bl_post(MDOC_ARGS)
                   1079: {
                   1080:        struct ord      *ord;
                   1081:
                   1082:        if (MDOC_BLOCK != n->type)
                   1083:                return;
                   1084:        if (MDOC_Enum != a2list(n))
                   1085:                return;
                   1086:
                   1087:        ord = SLIST_FIRST(&h->ords);
                   1088:        assert(ord);
                   1089:        SLIST_REMOVE_HEAD(&h->ords, entry);
                   1090:        free(ord);
                   1091: }
                   1092:
                   1093:
                   1094: static int
                   1095: mdoc_it_pre(MDOC_ARGS)
                   1096: {
                   1097:        int              type;
                   1098:
                   1099:        if (MDOC_BLOCK == n->type)
                   1100:                type = a2list(n->parent->parent);
                   1101:        else
                   1102:                type = a2list(n->parent->parent->parent);
                   1103:
                   1104:        return(mdoc_tbl_pre(m, n, h, type));
                   1105: }
                   1106:
                   1107:
                   1108: /* ARGSUSED */
                   1109: static int
                   1110: mdoc_ex_pre(MDOC_ARGS)
                   1111: {
                   1112:        const struct mdoc_node  *nn;
                   1113:        struct tag              *t;
                   1114:        struct htmlpair          tag;
                   1115:
                   1116:        print_text(h, "The");
                   1117:
                   1118:        tag.key = ATTR_CLASS;
                   1119:        tag.val = "utility";
                   1120:
                   1121:        for (nn = n->child; nn; nn = nn->next) {
                   1122:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1123:                print_text(h, nn->string);
                   1124:                print_tagq(h, t);
                   1125:
                   1126:                h->flags |= HTML_NOSPACE;
                   1127:
                   1128:                if (nn->next && NULL == nn->next->next)
                   1129:                        print_text(h, ", and");
                   1130:                else if (nn->next)
                   1131:                        print_text(h, ",");
                   1132:                else
                   1133:                        h->flags &= ~HTML_NOSPACE;
                   1134:        }
                   1135:
                   1136:        if (n->child->next)
                   1137:                print_text(h, "utilities exit");
                   1138:        else
                   1139:                print_text(h, "utility exits");
                   1140:
                   1141:                print_text(h, "0 on success, and >0 if an error occurs.");
                   1142:        return(0);
                   1143: }
                   1144:
                   1145:
                   1146: /* ARGSUSED */
                   1147: static int
                   1148: mdoc_dq_pre(MDOC_ARGS)
                   1149: {
                   1150:
                   1151:        if (MDOC_BODY != n->type)
                   1152:                return(1);
                   1153:        print_text(h, "\\(lq");
                   1154:        h->flags |= HTML_NOSPACE;
                   1155:        return(1);
                   1156: }
                   1157:
                   1158:
                   1159: /* ARGSUSED */
                   1160: static void
                   1161: mdoc_dq_post(MDOC_ARGS)
                   1162: {
                   1163:
                   1164:        if (MDOC_BODY != n->type)
                   1165:                return;
                   1166:        h->flags |= HTML_NOSPACE;
                   1167:        print_text(h, "\\(rq");
                   1168: }
                   1169:
                   1170:
                   1171: /* ARGSUSED */
                   1172: static int
                   1173: mdoc_pq_pre(MDOC_ARGS)
                   1174: {
                   1175:
                   1176:        if (MDOC_BODY != n->type)
                   1177:                return(1);
                   1178:        print_text(h, "\\&(");
                   1179:        h->flags |= HTML_NOSPACE;
                   1180:        return(1);
                   1181: }
                   1182:
                   1183:
                   1184: /* ARGSUSED */
                   1185: static void
                   1186: mdoc_pq_post(MDOC_ARGS)
                   1187: {
                   1188:
                   1189:        if (MDOC_BODY != n->type)
                   1190:                return;
                   1191:        print_text(h, ")");
                   1192: }
                   1193:
                   1194:
                   1195: /* ARGSUSED */
                   1196: static int
                   1197: mdoc_sq_pre(MDOC_ARGS)
                   1198: {
                   1199:
                   1200:        if (MDOC_BODY != n->type)
                   1201:                return(1);
                   1202:        print_text(h, "\\(oq");
                   1203:        h->flags |= HTML_NOSPACE;
                   1204:        return(1);
                   1205: }
                   1206:
                   1207:
                   1208: /* ARGSUSED */
                   1209: static void
                   1210: mdoc_sq_post(MDOC_ARGS)
                   1211: {
                   1212:
                   1213:        if (MDOC_BODY != n->type)
                   1214:                return;
                   1215:        h->flags |= HTML_NOSPACE;
                   1216:        print_text(h, "\\(aq");
                   1217: }
                   1218:
                   1219:
                   1220: /* ARGSUSED */
                   1221: static int
                   1222: mdoc_em_pre(MDOC_ARGS)
                   1223: {
                   1224:        struct htmlpair tag;
                   1225:
                   1226:        tag.key = ATTR_CLASS;
                   1227:        tag.val = "emph";
                   1228:
                   1229:        print_otag(h, TAG_SPAN, 1, &tag);
                   1230:        return(1);
                   1231: }
                   1232:
                   1233:
                   1234: /* ARGSUSED */
                   1235: static int
                   1236: mdoc_d1_pre(MDOC_ARGS)
                   1237: {
                   1238:        struct htmlpair tag[2];
                   1239:
                   1240:        if (MDOC_BLOCK != n->type)
                   1241:                return(1);
                   1242:
                   1243:        buffmt("margin-left: %dem;", INDENT);
                   1244:
                   1245:        tag[0].key = ATTR_CLASS;
1.5       kristaps 1246:        tag[0].val = "lit";
1.1       kristaps 1247:        tag[1].key = ATTR_STYLE;
                   1248:        tag[1].val = buf;
                   1249:
                   1250:        print_otag(h, TAG_DIV, 2, tag);
                   1251:        return(1);
                   1252: }
                   1253:
                   1254:
                   1255: /* ARGSUSED */
                   1256: static int
                   1257: mdoc_sx_pre(MDOC_ARGS)
                   1258: {
                   1259:        struct htmlpair          tag[2];
                   1260:        const struct mdoc_node  *nn;
                   1261:
                   1262:        bufcat("#");
                   1263:        for (nn = n->child; nn; nn = nn->next) {
                   1264:                bufcat(nn->string);
                   1265:                if (nn->next)
                   1266:                        bufcat(" ");
                   1267:        }
                   1268:
                   1269:        tag[0].key = ATTR_HREF;
                   1270:        tag[0].val = buf;
                   1271:        tag[1].key = ATTR_CLASS;
                   1272:        tag[1].val = "link-sec";
                   1273:
                   1274:        print_otag(h, TAG_A, 2, tag);
                   1275:        return(1);
                   1276: }
                   1277:
                   1278:
                   1279: /* ARGSUSED */
                   1280: static int
                   1281: mdoc_aq_pre(MDOC_ARGS)
                   1282: {
                   1283:
                   1284:        if (MDOC_BODY != n->type)
                   1285:                return(1);
                   1286:        print_text(h, "\\(la");
                   1287:        h->flags |= HTML_NOSPACE;
                   1288:        return(1);
                   1289: }
                   1290:
                   1291:
                   1292: /* ARGSUSED */
                   1293: static void
                   1294: mdoc_aq_post(MDOC_ARGS)
                   1295: {
                   1296:
                   1297:        if (MDOC_BODY != n->type)
                   1298:                return;
                   1299:        h->flags |= HTML_NOSPACE;
                   1300:        print_text(h, "\\(ra");
                   1301: }
                   1302:
                   1303:
                   1304: /* ARGSUSED */
                   1305: static int
                   1306: mdoc_bd_pre(MDOC_ARGS)
                   1307: {
                   1308:        struct htmlpair          tag[2];
                   1309:        int                      t, c, o, i;
                   1310:        const struct mdoc_node  *bl;
                   1311:
                   1312:        /* FIXME: fmt_vspace() shit. */
                   1313:
                   1314:        if (MDOC_BLOCK == n->type)
                   1315:                bl = n;
                   1316:        else if (MDOC_HEAD == n->type)
                   1317:                return(0);
                   1318:        else
                   1319:                bl = n->parent;
                   1320:
                   1321:        t = o = c = 0;
                   1322:
                   1323:        for (i = 0; i < (int)bl->args->argc; i++)
                   1324:                switch (bl->args->argv[i].arg) {
                   1325:                case (MDOC_Offset):
                   1326:                        assert(bl->args->argv[i].sz);
                   1327:                        o = a2offs (bl->args->argv[i].value[0]);
                   1328:                        break;
                   1329:                case (MDOC_Compact):
                   1330:                        c = 1;
                   1331:                        break;
                   1332:                case (MDOC_Ragged):
                   1333:                        /* FALLTHROUGH */
                   1334:                case (MDOC_Filled):
                   1335:                        /* FALLTHROUGH */
                   1336:                case (MDOC_Unfilled):
                   1337:                        /* FALLTHROUGH */
                   1338:                case (MDOC_Literal):
                   1339:                        t = bl->args->argv[i].arg;
                   1340:                        break;
                   1341:                }
                   1342:
                   1343:        if (MDOC_BLOCK == n->type) {
                   1344:                if (o)
                   1345:                        buffmt("margin-left: %dem;", o);
                   1346:                bufcat("margin-top: 1em;");
                   1347:                tag[0].key = ATTR_STYLE;
                   1348:                tag[0].val = buf;
                   1349:                print_otag(h, TAG_DIV, 1, tag);
                   1350:                return(1);
                   1351:        }
                   1352:
                   1353:        switch (t) {
                   1354:        case (MDOC_Unfilled):
                   1355:        case (MDOC_Literal):
                   1356:                break;
                   1357:        default:
                   1358:                return(1);
                   1359:        }
                   1360:
                   1361:        bufcat("white-space: pre;");
                   1362:        tag[0].key = ATTR_STYLE;
                   1363:        tag[0].val = buf;
                   1364:        tag[1].key = ATTR_CLASS;
1.5       kristaps 1365:        tag[1].val = "lit";
1.1       kristaps 1366:
                   1367:        print_otag(h, TAG_DIV, 2, tag);
                   1368:
                   1369:        for (n = n->child; n; n = n->next) {
                   1370:                h->flags |= HTML_NOSPACE;
                   1371:                print_mdoc_node(m, n, h);
                   1372:                if (n->next)
                   1373:                        print_text(h, "\n");
                   1374:        }
                   1375:
                   1376:        return(0);
                   1377: }
                   1378:
                   1379:
                   1380: /* ARGSUSED */
                   1381: static int
                   1382: mdoc_pa_pre(MDOC_ARGS)
                   1383: {
                   1384:        struct htmlpair tag;
                   1385:
                   1386:        tag.key = ATTR_CLASS;
                   1387:        tag.val = "file";
                   1388:
                   1389:        print_otag(h, TAG_SPAN, 1, &tag);
                   1390:        return(1);
                   1391: }
                   1392:
                   1393:
                   1394: /* ARGSUSED */
                   1395: static int
                   1396: mdoc_ad_pre(MDOC_ARGS)
                   1397: {
                   1398:        struct htmlpair tag;
                   1399:
                   1400:        tag.key = ATTR_CLASS;
                   1401:        tag.val = "addr";
                   1402:        print_otag(h, TAG_SPAN, 1, &tag);
                   1403:        return(1);
                   1404: }
                   1405:
                   1406:
                   1407: /* ARGSUSED */
                   1408: static int
                   1409: mdoc_an_pre(MDOC_ARGS)
                   1410: {
                   1411:        struct htmlpair tag;
                   1412:
                   1413:        tag.key = ATTR_CLASS;
                   1414:        tag.val = "author";
                   1415:        print_otag(h, TAG_SPAN, 1, &tag);
                   1416:        return(1);
                   1417: }
                   1418:
                   1419:
                   1420: /* ARGSUSED */
                   1421: static int
                   1422: mdoc_cd_pre(MDOC_ARGS)
                   1423: {
                   1424:        struct htmlpair tag;
                   1425:
                   1426:        tag.key = ATTR_CLASS;
                   1427:        tag.val = "config";
                   1428:        print_otag(h, TAG_SPAN, 1, &tag);
                   1429:        return(1);
                   1430: }
                   1431:
                   1432:
                   1433: /* ARGSUSED */
                   1434: static int
                   1435: mdoc_dv_pre(MDOC_ARGS)
                   1436: {
                   1437:        struct htmlpair tag;
                   1438:
                   1439:        tag.key = ATTR_CLASS;
                   1440:        tag.val = "define";
                   1441:        print_otag(h, TAG_SPAN, 1, &tag);
                   1442:        return(1);
                   1443: }
                   1444:
                   1445:
                   1446: /* ARGSUSED */
                   1447: static int
                   1448: mdoc_ev_pre(MDOC_ARGS)
                   1449: {
                   1450:        struct htmlpair tag;
                   1451:
                   1452:        tag.key = ATTR_CLASS;
                   1453:        tag.val = "env";
                   1454:        print_otag(h, TAG_SPAN, 1, &tag);
                   1455:        return(1);
                   1456: }
                   1457:
                   1458:
                   1459: /* ARGSUSED */
                   1460: static int
                   1461: mdoc_er_pre(MDOC_ARGS)
                   1462: {
                   1463:        struct htmlpair tag;
                   1464:
                   1465:        tag.key = ATTR_CLASS;
                   1466:        tag.val = "errno";
                   1467:        print_otag(h, TAG_SPAN, 1, &tag);
                   1468:        return(1);
                   1469: }
                   1470:
                   1471:
                   1472: /* ARGSUSED */
                   1473: static int
                   1474: mdoc_fa_pre(MDOC_ARGS)
                   1475: {
                   1476:        const struct mdoc_node  *nn;
                   1477:        struct htmlpair          tag;
                   1478:        struct tag              *t;
                   1479:
                   1480:        tag.key = ATTR_CLASS;
                   1481:        tag.val = "farg";
                   1482:
                   1483:        if (n->parent->tok != MDOC_Fo) {
                   1484:                print_otag(h, TAG_SPAN, 1, &tag);
                   1485:                return(1);
                   1486:        }
                   1487:
                   1488:        for (nn = n->child; nn; nn = nn->next) {
                   1489:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1490:                print_text(h, nn->string);
                   1491:                print_tagq(h, t);
                   1492:                if (nn->next)
                   1493:                        print_text(h, ",");
                   1494:        }
                   1495:
                   1496:        if (n->child && n->next && n->next->tok == MDOC_Fa)
                   1497:                print_text(h, ",");
                   1498:
                   1499:        return(0);
                   1500: }
                   1501:
                   1502:
                   1503: /* ARGSUSED */
                   1504: static int
                   1505: mdoc_fd_pre(MDOC_ARGS)
                   1506: {
                   1507:        struct htmlpair tag;
                   1508:
                   1509:        if (SEC_SYNOPSIS == n->sec) {
                   1510:                if (n->next && MDOC_Fd != n->next->tok) {
                   1511:                        tag.key = ATTR_STYLE;
                   1512:                        tag.val = "margin-bottom: 1em;";
                   1513:                        print_otag(h, TAG_DIV, 1, &tag);
                   1514:                } else
                   1515:                        print_otag(h, TAG_DIV, 0, NULL);
                   1516:        }
                   1517:
                   1518:        tag.key = ATTR_CLASS;
                   1519:        tag.val = "macro";
                   1520:        print_otag(h, TAG_SPAN, 1, &tag);
                   1521:        return(1);
                   1522: }
                   1523:
                   1524:
                   1525: /* ARGSUSED */
                   1526: static int
                   1527: mdoc_vt_pre(MDOC_ARGS)
                   1528: {
                   1529:        struct htmlpair tag;
                   1530:
                   1531:        if (SEC_SYNOPSIS == n->sec) {
                   1532:                if (n->next && MDOC_Vt != n->next->tok) {
                   1533:                        tag.key = ATTR_STYLE;
                   1534:                        tag.val = "margin-bottom: 1em;";
                   1535:                        print_otag(h, TAG_DIV, 1, &tag);
                   1536:                } else
                   1537:                        print_otag(h, TAG_DIV, 0, NULL);
                   1538:        }
                   1539:
                   1540:        tag.key = ATTR_CLASS;
                   1541:        tag.val = "type";
                   1542:        print_otag(h, TAG_SPAN, 1, &tag);
                   1543:        return(1);
                   1544: }
                   1545:
1.2       kristaps 1546:
1.1       kristaps 1547: /* ARGSUSED */
                   1548: static int
                   1549: mdoc_ft_pre(MDOC_ARGS)
                   1550: {
                   1551:        struct htmlpair tag;
                   1552:
                   1553:        if (SEC_SYNOPSIS == n->sec) {
                   1554:                if (n->prev && MDOC_Fo == n->prev->tok) {
                   1555:                        tag.key = ATTR_STYLE;
1.4       kristaps 1556:                        tag.val = "margin-top: 1em;";
1.1       kristaps 1557:                        print_otag(h, TAG_DIV, 1, &tag);
                   1558:                } else
                   1559:                        print_otag(h, TAG_DIV, 0, NULL);
                   1560:        }
                   1561:
                   1562:        tag.key = ATTR_CLASS;
                   1563:        tag.val = "type";
                   1564:        print_otag(h, TAG_SPAN, 1, &tag);
                   1565:        return(1);
                   1566: }
                   1567:
                   1568:
                   1569: /* ARGSUSED */
                   1570: static int
                   1571: mdoc_fn_pre(MDOC_ARGS)
                   1572: {
                   1573:        struct tag              *t;
                   1574:        struct htmlpair          tag;
                   1575:        const struct mdoc_node  *nn;
                   1576:
                   1577:        if (SEC_SYNOPSIS == n->sec) {
                   1578:                if (n->next) {
                   1579:                        tag.key = ATTR_STYLE;
                   1580:                        tag.val = "margin-bottom: 1em";
                   1581:                        print_otag(h, TAG_DIV, 1, &tag);
                   1582:                } else
                   1583:                        print_otag(h, TAG_DIV, 0, NULL);
                   1584:        }
                   1585:
                   1586:        tag.key = ATTR_CLASS;
                   1587:        tag.val = "type";
                   1588:
1.4       kristaps 1589:        /* FIXME: can be "type funcname" "type varname"... */
                   1590:
1.1       kristaps 1591:        t = print_otag(h, TAG_SPAN, 1, &tag);
                   1592:        print_text(h, n->child->string);
                   1593:        print_tagq(h, t);
                   1594:
                   1595:        h->flags |= HTML_NOSPACE;
                   1596:        print_text(h, "(");
                   1597:
                   1598:        for (nn = n->child->next; nn; nn = nn->next) {
                   1599:                tag.key = ATTR_CLASS;
                   1600:                tag.val = "farg";
                   1601:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1602:                print_text(h, nn->string);
                   1603:                print_tagq(h, t);
                   1604:                if (nn->next)
                   1605:                        print_text(h, ",");
                   1606:        }
                   1607:
                   1608:        print_text(h, ")");
                   1609:
                   1610:        if (SEC_SYNOPSIS == n->sec)
                   1611:                print_text(h, ";");
                   1612:
                   1613:        return(0);
                   1614: }
                   1615:
                   1616:
                   1617: /* ARGSUSED */
                   1618: static int
                   1619: mdoc_sp_pre(MDOC_ARGS)
                   1620: {
                   1621:        int             len;
                   1622:        struct htmlpair tag;
                   1623:
                   1624:        switch (n->tok) {
                   1625:        case (MDOC_sp):
                   1626:                len = n->child ? atoi(n->child->string) : 1;
                   1627:                break;
                   1628:        case (MDOC_br):
                   1629:                len = 0;
                   1630:                break;
                   1631:        default:
                   1632:                len = 1;
                   1633:                break;
                   1634:        }
                   1635:
                   1636:        buffmt("height: %dem", len);
                   1637:        tag.key = ATTR_STYLE;
                   1638:        tag.val = buf;
                   1639:        print_otag(h, TAG_DIV, 1, &tag);
                   1640:        return(1);
                   1641:
                   1642: }
1.2       kristaps 1643:
                   1644:
                   1645: /* ARGSUSED */
                   1646: static int
                   1647: mdoc_brq_pre(MDOC_ARGS)
                   1648: {
                   1649:
                   1650:        if (MDOC_BODY != n->type)
                   1651:                return(1);
                   1652:        print_text(h, "\\(lC");
                   1653:        h->flags |= HTML_NOSPACE;
                   1654:        return(1);
                   1655: }
                   1656:
                   1657:
                   1658: /* ARGSUSED */
                   1659: static void
                   1660: mdoc_brq_post(MDOC_ARGS)
                   1661: {
                   1662:
                   1663:        if (MDOC_BODY != n->type)
                   1664:                return;
                   1665:        h->flags |= HTML_NOSPACE;
                   1666:        print_text(h, "\\(rC");
                   1667: }
                   1668:
                   1669:
                   1670: /* ARGSUSED */
                   1671: static int
                   1672: mdoc_lk_pre(MDOC_ARGS)
                   1673: {
                   1674:        const struct mdoc_node  *nn;
                   1675:        struct htmlpair          tag[2];
                   1676:
                   1677:        nn = n->child;
                   1678:
                   1679:        tag[0].key = ATTR_CLASS;
                   1680:        tag[0].val = "link-ext";
                   1681:        tag[1].key = ATTR_HREF;
                   1682:        tag[1].val = nn->string;
                   1683:
                   1684:        print_otag(h, TAG_A, 2, tag);
                   1685:
                   1686:        if (NULL == nn->next)
                   1687:                return(1);
                   1688:
                   1689:        for (nn = nn->next; nn; nn = nn->next)
                   1690:                print_text(h, nn->string);
                   1691:
                   1692:        return(0);
                   1693: }
                   1694:
                   1695:
                   1696: /* ARGSUSED */
                   1697: static int
                   1698: mdoc_mt_pre(MDOC_ARGS)
                   1699: {
                   1700:        struct htmlpair          tag[2];
                   1701:        struct tag              *t;
                   1702:        const struct mdoc_node  *nn;
                   1703:
                   1704:        tag[0].key = ATTR_CLASS;
                   1705:        tag[0].val = "link-mail";
                   1706:
                   1707:        for (nn = n->child; nn; nn = nn->next) {
                   1708:                bufinit();
                   1709:                bufcat("mailto:");
                   1710:                bufcat(nn->string);
                   1711:
                   1712:                tag[1].key = ATTR_HREF;
                   1713:                tag[1].val = buf;
                   1714:
                   1715:                t = print_otag(h, TAG_A, 2, tag);
                   1716:                print_text(h, nn->string);
                   1717:                print_tagq(h, t);
                   1718:        }
                   1719:
                   1720:        return(0);
                   1721: }
1.4       kristaps 1722:
                   1723:
                   1724: /* ARGSUSED */
                   1725: static int
                   1726: mdoc_fo_pre(MDOC_ARGS)
                   1727: {
                   1728:        struct htmlpair tag;
                   1729:
                   1730:        if (MDOC_BODY == n->type) {
                   1731:                h->flags |= HTML_NOSPACE;
                   1732:                print_text(h, "(");
                   1733:                h->flags |= HTML_NOSPACE;
                   1734:                return(1);
                   1735:        } else if (MDOC_BLOCK == n->type)
                   1736:                return(1);
                   1737:
                   1738:        tag.key = ATTR_CLASS;
                   1739:        tag.val = "fname";
                   1740:        print_otag(h, TAG_SPAN, 1, &tag);
                   1741:        return(1);
                   1742: }
                   1743:
                   1744:
                   1745: /* ARGSUSED */
                   1746: static void
                   1747: mdoc_fo_post(MDOC_ARGS)
                   1748: {
                   1749:        if (MDOC_BODY != n->type)
                   1750:                return;
                   1751:        h->flags |= HTML_NOSPACE;
                   1752:        print_text(h, ")");
                   1753:        h->flags |= HTML_NOSPACE;
                   1754:        print_text(h, ";");
                   1755: }
                   1756:
                   1757:
                   1758: /* ARGSUSED */
                   1759: static int
                   1760: mdoc_in_pre(MDOC_ARGS)
                   1761: {
                   1762:        const struct mdoc_node  *nn;
                   1763:        struct htmlpair          tag;
                   1764:
                   1765:        if (SEC_SYNOPSIS == n->sec) {
                   1766:                if (n->next && MDOC_In != n->next->tok) {
                   1767:                        tag.key = ATTR_STYLE;
                   1768:                        tag.val = "margin-bottom: 1em;";
                   1769:                        print_otag(h, TAG_DIV, 1, &tag);
                   1770:                } else
                   1771:                        print_otag(h, TAG_DIV, 0, NULL);
                   1772:        }
                   1773:
                   1774:        tag.key = ATTR_CLASS;
                   1775:        tag.val = "includes";
                   1776:
                   1777:        print_otag(h, TAG_SPAN, 1, &tag);
                   1778:
                   1779:        if (SEC_SYNOPSIS == n->sec)
                   1780:                print_text(h, "#include");
                   1781:
                   1782:        print_text(h, "<");
                   1783:        h->flags |= HTML_NOSPACE;
                   1784:
                   1785:        /* XXX -- see warning in termp_in_post(). */
                   1786:
                   1787:        for (nn = n->child; nn; nn = nn->next)
                   1788:                print_mdoc_node(m, nn, h);
                   1789:
                   1790:        h->flags |= HTML_NOSPACE;
                   1791:        print_text(h, ">");
                   1792:
                   1793:        return(0);
                   1794: }
                   1795:
                   1796:
                   1797: /* ARGSUSED */
                   1798: static int
                   1799: mdoc_ic_pre(MDOC_ARGS)
                   1800: {
                   1801:        struct htmlpair tag;
                   1802:
                   1803:        tag.key = ATTR_CLASS;
                   1804:        tag.val = "cmd";
                   1805:
                   1806:        print_otag(h, TAG_SPAN, 1, &tag);
                   1807:        return(1);
                   1808: }
                   1809:
                   1810:
                   1811: /* ARGSUSED */
                   1812: static int
                   1813: mdoc_rv_pre(MDOC_ARGS)
                   1814: {
                   1815:        const struct mdoc_node  *nn;
                   1816:        struct htmlpair          tag;
                   1817:        struct tag              *t;
                   1818:
                   1819:        print_otag(h, TAG_DIV, 0, NULL);
                   1820:
                   1821:        print_text(h, "The");
                   1822:
                   1823:        for (nn = n->child; nn; nn = nn->next) {
                   1824:                tag.key = ATTR_CLASS;
                   1825:                tag.val = "fname";
                   1826:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1827:                print_text(h, nn->string);
                   1828:                print_tagq(h, t);
                   1829:
                   1830:                h->flags |= HTML_NOSPACE;
                   1831:                if (nn->next && NULL == nn->next->next)
                   1832:                        print_text(h, "(), and");
                   1833:                else if (nn->next)
                   1834:                        print_text(h, "(),");
                   1835:                else
                   1836:                        print_text(h, "()");
                   1837:        }
                   1838:
                   1839:        if (n->child->next)
                   1840:                print_text(h, "functions return");
                   1841:        else
                   1842:                print_text(h, "function returns");
                   1843:
                   1844:                print_text(h, "the value 0 if successful; otherwise the value "
                   1845:                        "-1 is returned and the global variable");
                   1846:
                   1847:        tag.key = ATTR_CLASS;
                   1848:        tag.val = "var";
                   1849:        t = print_otag(h, TAG_SPAN, 1, &tag);
                   1850:        print_text(h, "errno");
                   1851:        print_tagq(h, t);
                   1852:                print_text(h, "is set to indicate the error.");
                   1853:        return(0);
                   1854: }
                   1855:
                   1856:
                   1857: /* ARGSUSED */
                   1858: static int
                   1859: mdoc_va_pre(MDOC_ARGS)
                   1860: {
                   1861:        struct htmlpair tag;
                   1862:
                   1863:        tag.key = ATTR_CLASS;
                   1864:        tag.val = "var";
                   1865:        print_otag(h, TAG_SPAN, 1, &tag);
                   1866:        return(1);
                   1867: }
                   1868:
                   1869:
                   1870: /* ARGSUSED */
                   1871: static int
                   1872: mdoc_bq_pre(MDOC_ARGS)
                   1873: {
                   1874:
                   1875:        if (MDOC_BODY != n->type)
                   1876:                return(1);
                   1877:        print_text(h, "\\(lB");
                   1878:        h->flags |= HTML_NOSPACE;
                   1879:        return(1);
                   1880: }
                   1881:
                   1882:
                   1883: /* ARGSUSED */
                   1884: static void
                   1885: mdoc_bq_post(MDOC_ARGS)
                   1886: {
                   1887:
                   1888:        if (MDOC_BODY != n->type)
                   1889:                return;
                   1890:        h->flags |= HTML_NOSPACE;
                   1891:        print_text(h, "\\(rB");
                   1892: }
1.5       kristaps 1893:
                   1894:
                   1895: /* ARGSUSED */
                   1896: static int
                   1897: mdoc_ap_pre(MDOC_ARGS)
                   1898: {
                   1899:
                   1900:        h->flags |= HTML_NOSPACE;
                   1901:        print_text(h, "\\(aq");
                   1902:        h->flags |= HTML_NOSPACE;
                   1903:        return(1);
                   1904: }
                   1905:
                   1906:
                   1907: /* ARGSUSED */
                   1908: static int
                   1909: mdoc_bf_pre(MDOC_ARGS)
                   1910: {
                   1911:        int             i;
                   1912:        struct htmlpair tag[2];
                   1913:
                   1914:        if (MDOC_HEAD == n->type)
                   1915:                return(0);
                   1916:        else if (MDOC_BLOCK != n->type)
                   1917:                return(1);
                   1918:
                   1919:        tag[0].key = ATTR_CLASS;
                   1920:        tag[0].val = NULL;
                   1921:
                   1922:        if (n->head->child) {
                   1923:                if ( ! strcmp("Em", n->head->child->string))
                   1924:                        tag[0].val = "emph";
                   1925:                else if ( ! strcmp("Sy", n->head->child->string))
                   1926:                        tag[0].val = "symb";
                   1927:                else if ( ! strcmp("Li", n->head->child->string))
                   1928:                        tag[0].val = "lit";
                   1929:        } else {
                   1930:                assert(n->args);
                   1931:                for (i = 0; i < (int)n->args->argc; i++)
                   1932:                        switch (n->args->argv[i].arg) {
                   1933:                        case (MDOC_Symbolic):
                   1934:                                tag[0].val = "symb";
                   1935:                                break;
                   1936:                        case (MDOC_Literal):
                   1937:                                tag[0].val = "lit";
                   1938:                                break;
                   1939:                        case (MDOC_Emphasis):
                   1940:                                tag[0].val = "emph";
                   1941:                                break;
                   1942:                        default:
                   1943:                                break;
                   1944:                        }
                   1945:        }
                   1946:
                   1947:        /* FIXME: div's have spaces stripped--we want them. */
                   1948:
                   1949:        assert(tag[0].val);
                   1950:        tag[1].key = ATTR_STYLE;
                   1951:        tag[1].val = "display: inline; margin-right: 1em;";
                   1952:        print_otag(h, TAG_DIV, 2, tag);
                   1953:        return(1);
                   1954: }
                   1955:
                   1956:
                   1957: /* ARGSUSED */
                   1958: static int
                   1959: mdoc_ms_pre(MDOC_ARGS)
                   1960: {
                   1961:        struct htmlpair tag;
                   1962:
                   1963:        tag.key = ATTR_CLASS;
                   1964:        tag.val = "symb";
                   1965:        print_otag(h, TAG_SPAN, 1, &tag);
                   1966:        return(1);
                   1967: }
                   1968:
                   1969:
                   1970: /* ARGSUSED */
                   1971: static int
                   1972: mdoc_pf_pre(MDOC_ARGS)
                   1973: {
                   1974:
                   1975:        h->flags |= HTML_IGNDELIM;
                   1976:        return(1);
                   1977: }
                   1978:
                   1979:
                   1980: /* ARGSUSED */
                   1981: static void
                   1982: mdoc_pf_post(MDOC_ARGS)
                   1983: {
                   1984:
                   1985:        h->flags &= ~HTML_IGNDELIM;
                   1986:        h->flags |= HTML_NOSPACE;
                   1987: }
                   1988:
                   1989:
                   1990: /* ARGSUSED */
                   1991: static int
                   1992: mdoc_rs_pre(MDOC_ARGS)
                   1993: {
                   1994:        struct htmlpair tag[2];
                   1995:        int             i;
                   1996:
                   1997:        if (MDOC_BLOCK != n->type)
                   1998:                return(1);
                   1999:
                   2000:        tag[i = 0].key = ATTR_CLASS;
                   2001:        tag[i++].val = "ref";
                   2002:
                   2003:        if (n->prev && SEC_SYNOPSIS == n->sec) {
                   2004:                tag[i].key = ATTR_STYLE;
                   2005:                tag[i++].val = "margin-top: 1em;";
                   2006:        } else if (SEC_SYNOPSIS != n->sec) {
                   2007:                tag[i].key = ATTR_STYLE;
                   2008:                tag[i++].val = "display: inline; margin-right: 1em";
                   2009:        }
                   2010:
                   2011:        /* FIXME: div's have spaces stripped--we want them. */
                   2012:
                   2013:        print_otag(h, TAG_DIV, i, tag);
                   2014:        return(1);
                   2015: }
1.6     ! kristaps 2016:
        !          2017:
        !          2018:
        !          2019: /* ARGSUSED */
        !          2020: static int
        !          2021: mdoc_li_pre(MDOC_ARGS)
        !          2022: {
        !          2023:        struct htmlpair tag;
        !          2024:
        !          2025:        tag.key = ATTR_CLASS;
        !          2026:        tag.val = "lit";
        !          2027:
        !          2028:        print_otag(h, TAG_SPAN, 1, &tag);
        !          2029:        return(1);
        !          2030: }
        !          2031:
        !          2032:
        !          2033: /* ARGSUSED */
        !          2034: static int
        !          2035: mdoc_sy_pre(MDOC_ARGS)
        !          2036: {
        !          2037:        struct htmlpair tag;
        !          2038:
        !          2039:        tag.key = ATTR_CLASS;
        !          2040:        tag.val = "symb";
        !          2041:
        !          2042:        print_otag(h, TAG_SPAN, 1, &tag);
        !          2043:        return(1);
        !          2044: }
        !          2045:
        !          2046:
        !          2047: /* ARGSUSED */
        !          2048: static int
        !          2049: mdoc_bt_pre(MDOC_ARGS)
        !          2050: {
        !          2051:
        !          2052:        print_text(h, "is currently in beta test.");
        !          2053:        return(0);
        !          2054: }
        !          2055:
        !          2056:
        !          2057: /* ARGSUSED */
        !          2058: static int
        !          2059: mdoc_ud_pre(MDOC_ARGS)
        !          2060: {
        !          2061:
        !          2062:        print_text(h, "currently under development.");
        !          2063:        return(0);
        !          2064: }
        !          2065:
        !          2066:
        !          2067: /* ARGSUSED */
        !          2068: static int
        !          2069: mdoc_lb_pre(MDOC_ARGS)
        !          2070: {
        !          2071:        struct htmlpair tag;
        !          2072:
        !          2073:        tag.key = ATTR_CLASS;
        !          2074:        tag.val = "lib";
        !          2075:
        !          2076:        if (SEC_SYNOPSIS == n->sec)
        !          2077:                print_otag(h, TAG_DIV, 0, NULL);
        !          2078:
        !          2079:        print_otag(h, TAG_SPAN, 1, &tag);
        !          2080:        return(1);
        !          2081: }

CVSweb