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

Annotation of mandoc/mdoc_html.c, Revision 1.20

1.20    ! kristaps    1: /*     $Id: mdoc_html.c,v 1.19 2009/10/03 19:02:45 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>
1.7       kristaps   18: #include <sys/param.h>
1.1       kristaps   19: #include <sys/queue.h>
                     20:
                     21: #include <assert.h>
                     22: #include <ctype.h>
                     23: #include <err.h>
                     24: #include <stdio.h>
                     25: #include <stdlib.h>
                     26: #include <string.h>
                     27: #include <unistd.h>
                     28:
                     29: #include "html.h"
                     30: #include "mdoc.h"
                     31:
                     32: #define        INDENT           5
                     33: #define        HALFINDENT       3
                     34:
                     35: #define        MDOC_ARGS         const struct mdoc_meta *m, \
                     36:                          const struct mdoc_node *n, \
                     37:                          struct html *h
                     38:
                     39: struct htmlmdoc {
                     40:        int             (*pre)(MDOC_ARGS);
                     41:        void            (*post)(MDOC_ARGS);
                     42: };
                     43:
                     44: static void              print_mdoc(MDOC_ARGS);
                     45: static void              print_mdoc_head(MDOC_ARGS);
                     46: static void              print_mdoc_node(MDOC_ARGS);
                     47: static void              print_mdoc_nodelist(MDOC_ARGS);
                     48:
                     49: static int               a2width(const char *);
                     50: static int               a2offs(const char *);
                     51: static int               a2list(const struct mdoc_node *);
                     52:
                     53: static void              mdoc_root_post(MDOC_ARGS);
                     54: static int               mdoc_root_pre(MDOC_ARGS);
                     55: static int               mdoc_tbl_pre(MDOC_ARGS, int);
                     56: static int               mdoc_tbl_block_pre(MDOC_ARGS, int, int, int, int);
                     57: static int               mdoc_tbl_body_pre(MDOC_ARGS, int, int);
                     58: static int               mdoc_tbl_head_pre(MDOC_ARGS, int, int);
                     59:
1.10      kristaps   60: static void              mdoc__x_post(MDOC_ARGS);
                     61: static int               mdoc__x_pre(MDOC_ARGS);
1.1       kristaps   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 */
1.10      kristaps  174:        {mdoc__x_pre, mdoc__x_post}, /* %A */
                    175:        {mdoc__x_pre, mdoc__x_post}, /* %B */
                    176:        {mdoc__x_pre, mdoc__x_post}, /* %D */
                    177:        {mdoc__x_pre, mdoc__x_post}, /* %I */
                    178:        {mdoc__x_pre, mdoc__x_post}, /* %J */
                    179:        {mdoc__x_pre, mdoc__x_post}, /* %N */
                    180:        {mdoc__x_pre, mdoc__x_post}, /* %O */
                    181:        {mdoc__x_pre, mdoc__x_post}, /* %P */
                    182:        {mdoc__x_pre, mdoc__x_post}, /* %R */
                    183:        {mdoc__x_pre, mdoc__x_post}, /* %T */
                    184:        {mdoc__x_pre, mdoc__x_post}, /* %V */
1.1       kristaps  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 */
1.10      kristaps  246:        {mdoc__x_pre, mdoc__x_post}, /* %C */
1.2       kristaps  247:        {NULL, NULL}, /* Es */  /* TODO */
                    248:        {NULL, NULL}, /* En */  /* TODO */
1.1       kristaps  249:        {mdoc_xx_pre, NULL}, /* Dx */
1.10      kristaps  250:        {mdoc__x_pre, mdoc__x_post}, /* %Q */
1.1       kristaps  251:        {mdoc_sp_pre, NULL}, /* br */
                    252:        {mdoc_sp_pre, NULL}, /* sp */
                    253: };
                    254:
                    255:
                    256: void
                    257: html_mdoc(void *arg, const struct mdoc *m)
                    258: {
                    259:        struct html     *h;
                    260:        struct tag      *t;
                    261:
                    262:        h = (struct html *)arg;
                    263:
                    264:        print_gen_doctype(h);
                    265:        t = print_otag(h, TAG_HTML, 0, NULL);
                    266:        print_mdoc(mdoc_meta(m), mdoc_node(m), h);
                    267:        print_tagq(h, t);
                    268:
                    269:        printf("\n");
                    270: }
                    271:
                    272:
                    273: static int
                    274: a2list(const struct mdoc_node *n)
                    275: {
                    276:        int              i;
                    277:
                    278:        assert(MDOC_BLOCK == n->type && MDOC_Bl == n->tok);
                    279:        assert(n->args);
                    280:
                    281:        for (i = 0; i < (int)n->args->argc; i++)
                    282:                switch (n->args->argv[i].arg) {
                    283:                case (MDOC_Enum):
                    284:                        /* FALLTHROUGH */
                    285:                case (MDOC_Dash):
                    286:                        /* FALLTHROUGH */
                    287:                case (MDOC_Hyphen):
                    288:                        /* FALLTHROUGH */
                    289:                case (MDOC_Bullet):
                    290:                        /* FALLTHROUGH */
                    291:                case (MDOC_Tag):
                    292:                        /* FALLTHROUGH */
                    293:                case (MDOC_Hang):
                    294:                        /* FALLTHROUGH */
                    295:                case (MDOC_Inset):
                    296:                        /* FALLTHROUGH */
                    297:                case (MDOC_Diag):
                    298:                        /* FALLTHROUGH */
                    299:                case (MDOC_Item):
                    300:                        /* FALLTHROUGH */
                    301:                case (MDOC_Column):
                    302:                        /* FALLTHROUGH */
                    303:                case (MDOC_Ohang):
                    304:                        return(n->args->argv[i].arg);
                    305:                default:
                    306:                        break;
                    307:                }
                    308:
                    309:        abort();
                    310:        /* NOTREACHED */
                    311: }
                    312:
                    313:
                    314: static int
                    315: a2width(const char *p)
                    316: {
                    317:        int              i, len;
                    318:
                    319:        if (0 == (len = (int)strlen(p)))
                    320:                return(0);
                    321:        for (i = 0; i < len - 1; i++)
                    322:                if ( ! isdigit((u_char)p[i]))
                    323:                        break;
                    324:
                    325:        if (i == len - 1)
                    326:                if ('n' == p[len - 1] || 'm' == p[len - 1])
                    327:                        return(atoi(p) + 2);
                    328:
                    329:        return(len + 2);
                    330: }
                    331:
                    332:
                    333: static int
                    334: a2offs(const char *p)
                    335: {
                    336:        int              len, i;
                    337:
                    338:        if (0 == strcmp(p, "left"))
                    339:                return(0);
                    340:        if (0 == strcmp(p, "indent"))
                    341:                return(INDENT + 1);
                    342:        if (0 == strcmp(p, "indent-two"))
                    343:                return((INDENT + 1) * 2);
                    344:
                    345:        if (0 == (len = (int)strlen(p)))
                    346:                return(0);
                    347:
                    348:        for (i = 0; i < len - 1; i++)
                    349:                if ( ! isdigit((u_char)p[i]))
                    350:                        break;
                    351:
                    352:        if (i == len - 1)
                    353:                if ('n' == p[len - 1] || 'm' == p[len - 1])
                    354:                        return(atoi(p));
                    355:
                    356:        return(len);
                    357: }
                    358:
                    359:
                    360: static void
                    361: print_mdoc(MDOC_ARGS)
                    362: {
                    363:        struct tag      *t;
                    364:        struct htmlpair  tag;
                    365:
                    366:        t = print_otag(h, TAG_HEAD, 0, NULL);
                    367:        print_mdoc_head(m, n, h);
                    368:        print_tagq(h, t);
                    369:
                    370:        t = print_otag(h, TAG_BODY, 0, NULL);
                    371:
                    372:        tag.key = ATTR_CLASS;
                    373:        tag.val = "body";
                    374:        print_otag(h, TAG_DIV, 1, &tag);
                    375:
                    376:        print_mdoc_nodelist(m, n, h);
                    377:        print_tagq(h, t);
                    378: }
                    379:
                    380:
                    381: /* ARGSUSED */
                    382: static void
                    383: print_mdoc_head(MDOC_ARGS)
                    384: {
                    385:
                    386:        print_gen_head(h);
1.20    ! kristaps  387:        bufinit(h);
        !           388:        buffmt(h, "%s(%d)", m->title, m->msec);
1.1       kristaps  389:
                    390:        if (m->arch) {
1.20    ! kristaps  391:                bufcat(h, " (");
        !           392:                bufcat(h, m->arch);
        !           393:                bufcat(h, ")");
1.1       kristaps  394:        }
                    395:
                    396:        print_otag(h, TAG_TITLE, 0, NULL);
1.20    ! kristaps  397:        print_text(h, h->buf);
1.1       kristaps  398: }
                    399:
                    400:
                    401: static void
                    402: print_mdoc_nodelist(MDOC_ARGS)
                    403: {
                    404:
                    405:        print_mdoc_node(m, n, h);
                    406:        if (n->next)
                    407:                print_mdoc_nodelist(m, n->next, h);
                    408: }
                    409:
                    410:
                    411: static void
                    412: print_mdoc_node(MDOC_ARGS)
                    413: {
                    414:        int              child;
                    415:        struct tag      *t;
                    416:
                    417:        child = 1;
                    418:        t = SLIST_FIRST(&h->tags);
                    419:
1.16      kristaps  420:        bufinit(h);
1.1       kristaps  421:
                    422:        switch (n->type) {
                    423:        case (MDOC_ROOT):
                    424:                child = mdoc_root_pre(m, n, h);
                    425:                break;
                    426:        case (MDOC_TEXT):
                    427:                print_text(h, n->string);
                    428:                break;
                    429:        default:
                    430:                if (mdocs[n->tok].pre)
                    431:                        child = (*mdocs[n->tok].pre)(m, n, h);
                    432:                break;
                    433:        }
                    434:
                    435:        if (child && n->child)
                    436:                print_mdoc_nodelist(m, n->child, h);
                    437:
                    438:        print_stagq(h, t);
                    439:
1.16      kristaps  440:        bufinit(h);
1.1       kristaps  441:
                    442:        switch (n->type) {
                    443:        case (MDOC_ROOT):
                    444:                mdoc_root_post(m, n, h);
                    445:                break;
                    446:        case (MDOC_TEXT):
                    447:                break;
                    448:        default:
                    449:                if (mdocs[n->tok].post)
                    450:                        (*mdocs[n->tok].post)(m, n, h);
                    451:                break;
                    452:        }
                    453: }
                    454:
                    455:
                    456: /* ARGSUSED */
                    457: static void
                    458: mdoc_root_post(MDOC_ARGS)
                    459: {
                    460:        struct tm        tm;
                    461:        struct htmlpair  tag[2];
                    462:        struct tag      *t, *tt;
                    463:        char             b[BUFSIZ];
                    464:
                    465:        (void)localtime_r(&m->date, &tm);
                    466:
                    467:        if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", &tm))
                    468:                err(EXIT_FAILURE, "strftime");
                    469:
                    470:        tag[0].key = ATTR_CLASS;
                    471:        tag[0].val = "footer";
                    472:        tag[1].key = ATTR_STYLE;
                    473:        tag[1].val = "width: 100%;";
                    474:        t = print_otag(h, TAG_TABLE, 2, tag);
                    475:        tt = print_otag(h, TAG_TR, 0, NULL);
                    476:
                    477:        tag[0].key = ATTR_STYLE;
                    478:        tag[0].val = "width: 50%;";
                    479:        print_otag(h, TAG_TD, 1, tag);
                    480:        print_text(h, b);
                    481:        print_stagq(h, tt);
                    482:
                    483:        tag[0].key = ATTR_STYLE;
                    484:        tag[0].val = "width: 50%; text-align: right;";
                    485:        print_otag(h, TAG_TD, 1, tag);
                    486:        print_text(h, m->os);
                    487:        print_tagq(h, t);
                    488: }
                    489:
                    490:
                    491: /* ARGSUSED */
                    492: static int
                    493: mdoc_root_pre(MDOC_ARGS)
                    494: {
                    495:        struct htmlpair  tag[2];
                    496:        struct tag      *t, *tt;
                    497:        char             b[BUFSIZ], title[BUFSIZ];
                    498:
                    499:        (void)strlcpy(b, m->vol, BUFSIZ);
                    500:
                    501:        if (m->arch) {
                    502:                (void)strlcat(b, " (", BUFSIZ);
                    503:                (void)strlcat(b, m->arch, BUFSIZ);
                    504:                (void)strlcat(b, ")", BUFSIZ);
                    505:        }
                    506:
                    507:        (void)snprintf(title, BUFSIZ - 1,
                    508:                        "%s(%d)", m->title, m->msec);
                    509:
                    510:        tag[0].key = ATTR_CLASS;
                    511:        tag[0].val = "header";
                    512:        tag[1].key = ATTR_STYLE;
                    513:        tag[1].val = "width: 100%;";
                    514:        t = print_otag(h, TAG_TABLE, 2, tag);
                    515:        tt = print_otag(h, TAG_TR, 0, NULL);
                    516:
                    517:        tag[0].key = ATTR_STYLE;
1.11      kristaps  518:        tag[0].val = "width: 10%;";
1.1       kristaps  519:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  520:        print_text(h, title);
1.1       kristaps  521:        print_stagq(h, tt);
                    522:
                    523:        tag[0].key = ATTR_STYLE;
1.11      kristaps  524:        tag[0].val = "width: 80%; white-space: nowrap; text-align: center;";
1.1       kristaps  525:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  526:        print_text(h, b);
1.1       kristaps  527:        print_stagq(h, tt);
                    528:
                    529:        tag[0].key = ATTR_STYLE;
1.11      kristaps  530:        tag[0].val = "width: 10%; text-align: right;";
1.1       kristaps  531:        print_otag(h, TAG_TD, 1, tag);
1.2       kristaps  532:        print_text(h, title);
1.1       kristaps  533:        print_tagq(h, t);
                    534:
                    535:        return(1);
                    536: }
                    537:
                    538:
                    539: /* ARGSUSED */
                    540: static int
                    541: mdoc_sh_pre(MDOC_ARGS)
                    542: {
                    543:        struct htmlpair          tag[2];
                    544:        const struct mdoc_node  *nn;
                    545:
                    546:        if (MDOC_HEAD == n->type) {
                    547:                tag[0].key = ATTR_CLASS;
                    548:                tag[0].val = "sec-head";
                    549:                print_otag(h, TAG_DIV, 1, tag);
                    550:                print_otag(h, TAG_SPAN, 1, tag);
                    551:
                    552:                for (nn = n->child; nn; nn = nn->next) {
1.16      kristaps  553:                        bufcat(h, nn->string);
1.1       kristaps  554:                        if (nn->next)
1.16      kristaps  555:                                bufncat(h, " ", 1);
1.1       kristaps  556:                }
                    557:                tag[0].key = ATTR_NAME;
1.16      kristaps  558:                tag[0].val = h->buf;
1.1       kristaps  559:                print_otag(h, TAG_A, 1, tag);
                    560:                return(1);
                    561:        } else if (MDOC_BLOCK == n->type) {
                    562:                tag[0].key = ATTR_CLASS;
                    563:                tag[0].val = "sec-block";
                    564:
                    565:                if (n->prev && NULL == n->prev->body->child) {
                    566:                        print_otag(h, TAG_DIV, 1, tag);
                    567:                        return(1);
                    568:                }
                    569:
1.16      kristaps  570:                bufcat(h, "margin-top: 1em;");
1.1       kristaps  571:                if (NULL == n->next)
1.16      kristaps  572:                        bufcat(h, "margin-bottom: 1em;");
1.1       kristaps  573:
                    574:                tag[1].key = ATTR_STYLE;
1.16      kristaps  575:                tag[1].val = h->buf;
1.1       kristaps  576:
                    577:                print_otag(h, TAG_DIV, 2, tag);
                    578:                return(1);
                    579:        }
                    580:
1.16      kristaps  581:        buffmt(h, "margin-left: %dem;", INDENT);
1.1       kristaps  582:
                    583:        tag[0].key = ATTR_CLASS;
                    584:        tag[0].val = "sec-body";
                    585:        tag[1].key = ATTR_STYLE;
1.16      kristaps  586:        tag[1].val = h->buf;
1.1       kristaps  587:
                    588:        print_otag(h, TAG_DIV, 2, tag);
                    589:        return(1);
                    590: }
                    591:
                    592:
                    593: /* ARGSUSED */
                    594: static int
                    595: mdoc_ss_pre(MDOC_ARGS)
                    596: {
                    597:        struct htmlpair          tag[2];
                    598:        int                      i;
                    599:        const struct mdoc_node  *nn;
                    600:
                    601:        i = 0;
                    602:
                    603:        if (MDOC_BODY == n->type) {
                    604:                tag[i].key = ATTR_CLASS;
                    605:                tag[i++].val = "ssec-body";
                    606:                if (n->parent->next && n->child) {
1.16      kristaps  607:                        bufcat(h, "margin-bottom: 1em;");
1.1       kristaps  608:                        tag[i].key = ATTR_STYLE;
1.16      kristaps  609:                        tag[i++].val = h->buf;
1.1       kristaps  610:                }
                    611:                print_otag(h, TAG_DIV, i, tag);
                    612:                return(1);
                    613:        } else if (MDOC_BLOCK == n->type) {
                    614:                tag[i].key = ATTR_CLASS;
                    615:                tag[i++].val = "ssec-block";
                    616:                if (n->prev) {
1.16      kristaps  617:                        bufcat(h, "margin-top: 1em;");
1.1       kristaps  618:                        tag[i].key = ATTR_STYLE;
1.16      kristaps  619:                        tag[i++].val = h->buf;
1.1       kristaps  620:                }
                    621:                print_otag(h, TAG_DIV, i, tag);
                    622:                return(1);
                    623:        }
                    624:
1.16      kristaps  625:        buffmt(h, "margin-left: -%dem;", INDENT - HALFINDENT);
1.1       kristaps  626:
                    627:        tag[0].key = ATTR_CLASS;
                    628:        tag[0].val = "ssec-head";
                    629:        tag[1].key = ATTR_STYLE;
1.16      kristaps  630:        tag[1].val = h->buf;
1.1       kristaps  631:
                    632:        print_otag(h, TAG_DIV, 2, tag);
                    633:        print_otag(h, TAG_SPAN, 1, tag);
                    634:
1.16      kristaps  635:        bufinit(h);
1.1       kristaps  636:        for (nn = n->child; nn; nn = nn->next) {
1.16      kristaps  637:                bufcat(h, nn->string);
1.1       kristaps  638:                if (nn->next)
1.16      kristaps  639:                        bufcat(h, " ");
1.1       kristaps  640:        }
                    641:        tag[0].key = ATTR_NAME;
1.16      kristaps  642:        tag[0].val = h->buf;
1.1       kristaps  643:        print_otag(h, TAG_A, 1, tag);
                    644:
                    645:        return(1);
                    646: }
                    647:
                    648:
                    649: /* ARGSUSED */
                    650: static int
                    651: mdoc_fl_pre(MDOC_ARGS)
                    652: {
                    653:        struct htmlpair  tag;
                    654:
                    655:        tag.key = ATTR_CLASS;
                    656:        tag.val = "flag";
                    657:
                    658:        print_otag(h, TAG_SPAN, 1, &tag);
                    659:        if (MDOC_Fl == n->tok) {
                    660:                print_text(h, "\\-");
                    661:                h->flags |= HTML_NOSPACE;
                    662:        }
                    663:        return(1);
                    664: }
                    665:
                    666:
                    667: /* ARGSUSED */
                    668: static int
                    669: mdoc_nd_pre(MDOC_ARGS)
                    670: {
                    671:        struct htmlpair  tag;
                    672:
                    673:        if (MDOC_BODY != n->type)
                    674:                return(1);
                    675:
                    676:        /* XXX - this can contain block elements! */
                    677:        print_text(h, "\\(em");
                    678:        tag.key = ATTR_CLASS;
                    679:        tag.val = "desc-body";
                    680:        print_otag(h, TAG_SPAN, 1, &tag);
                    681:        return(1);
                    682: }
                    683:
                    684:
                    685: /* ARGSUSED */
                    686: static int
                    687: mdoc_op_pre(MDOC_ARGS)
                    688: {
                    689:        struct htmlpair  tag;
                    690:
                    691:        if (MDOC_BODY != n->type)
                    692:                return(1);
                    693:
                    694:        /* XXX - this can contain block elements! */
                    695:        print_text(h, "\\(lB");
                    696:        h->flags |= HTML_NOSPACE;
                    697:        tag.key = ATTR_CLASS;
                    698:        tag.val = "opt";
                    699:        print_otag(h, TAG_SPAN, 1, &tag);
                    700:        return(1);
                    701: }
                    702:
                    703:
                    704: /* ARGSUSED */
                    705: static void
                    706: mdoc_op_post(MDOC_ARGS)
                    707: {
                    708:
                    709:        if (MDOC_BODY != n->type)
                    710:                return;
                    711:        h->flags |= HTML_NOSPACE;
                    712:        print_text(h, "\\(rB");
                    713: }
                    714:
                    715:
                    716: static int
                    717: mdoc_nm_pre(MDOC_ARGS)
                    718: {
                    719:        struct htmlpair tag;
                    720:
                    721:        if ( ! (HTML_NEWLINE & h->flags))
                    722:                if (SEC_SYNOPSIS == n->sec) {
                    723:                        tag.key = ATTR_STYLE;
                    724:                        tag.val = "clear: both;";
                    725:                        print_otag(h, TAG_BR, 1, &tag);
                    726:                }
                    727:
                    728:        tag.key = ATTR_CLASS;
                    729:        tag.val = "name";
                    730:
                    731:        print_otag(h, TAG_SPAN, 1, &tag);
                    732:        if (NULL == n->child)
                    733:                print_text(h, m->name);
                    734:
                    735:        return(1);
                    736: }
                    737:
                    738:
                    739: /* ARGSUSED */
                    740: static int
                    741: mdoc_xr_pre(MDOC_ARGS)
                    742: {
                    743:        struct htmlpair          tag[2];
                    744:        const struct mdoc_node  *nn;
1.17      kristaps  745:        int                      i;
                    746:
                    747:        i = 0;
                    748:        tag[i].key = ATTR_CLASS;
                    749:        tag[i++].val = "link-man";
1.1       kristaps  750:
1.17      kristaps  751:        if (h->base_man) {
                    752:                buffmt_man(h, n->child->string, n->child->next ?
                    753:                                n->child->next->string : NULL);
                    754:                tag[i].key = ATTR_HREF;
                    755:                tag[i++].val = h->buf;
                    756:        }
1.1       kristaps  757:
1.17      kristaps  758:        print_otag(h, TAG_A, i, tag);
1.1       kristaps  759:
                    760:        nn = n->child;
                    761:        print_text(h, nn->string);
1.16      kristaps  762:
1.1       kristaps  763:        if (NULL == (nn = nn->next))
                    764:                return(0);
                    765:
                    766:        h->flags |= HTML_NOSPACE;
                    767:        print_text(h, "(");
                    768:        h->flags |= HTML_NOSPACE;
                    769:        print_text(h, nn->string);
                    770:        h->flags |= HTML_NOSPACE;
                    771:        print_text(h, ")");
                    772:
                    773:        return(0);
                    774: }
                    775:
                    776:
                    777: /* ARGSUSED */
                    778: static int
                    779: mdoc_ns_pre(MDOC_ARGS)
                    780: {
                    781:
                    782:        h->flags |= HTML_NOSPACE;
                    783:        return(1);
                    784: }
                    785:
                    786:
                    787: /* ARGSUSED */
                    788: static int
                    789: mdoc_ar_pre(MDOC_ARGS)
                    790: {
                    791:        struct htmlpair tag;
                    792:
                    793:        tag.key = ATTR_CLASS;
                    794:        tag.val = "arg";
                    795:
                    796:        print_otag(h, TAG_SPAN, 1, &tag);
                    797:        return(1);
                    798: }
                    799:
                    800:
                    801: /* ARGSUSED */
                    802: static int
                    803: mdoc_xx_pre(MDOC_ARGS)
                    804: {
                    805:        const char      *pp;
                    806:        struct htmlpair  tag;
                    807:
                    808:        switch (n->tok) {
                    809:        case (MDOC_Bsx):
                    810:                pp = "BSDI BSD/OS";
                    811:                break;
                    812:        case (MDOC_Dx):
                    813:                pp = "DragonFlyBSD";
                    814:                break;
                    815:        case (MDOC_Fx):
                    816:                pp = "FreeBSD";
                    817:                break;
                    818:        case (MDOC_Nx):
                    819:                pp = "NetBSD";
                    820:                break;
                    821:        case (MDOC_Ox):
                    822:                pp = "OpenBSD";
                    823:                break;
                    824:        case (MDOC_Ux):
                    825:                pp = "UNIX";
                    826:                break;
                    827:        default:
                    828:                return(1);
                    829:        }
                    830:
                    831:        tag.key = ATTR_CLASS;
                    832:        tag.val = "unix";
                    833:
                    834:        print_otag(h, TAG_SPAN, 1, &tag);
                    835:        print_text(h, pp);
                    836:        return(1);
                    837: }
                    838:
                    839:
                    840: /* ARGSUSED */
                    841: static int
1.4       kristaps  842: mdoc_bx_pre(MDOC_ARGS)
                    843: {
                    844:        const struct mdoc_node  *nn;
                    845:        struct htmlpair          tag;
                    846:
                    847:        tag.key = ATTR_CLASS;
                    848:        tag.val = "unix";
                    849:
                    850:        print_otag(h, TAG_SPAN, 1, &tag);
                    851:
                    852:        for (nn = n->child; nn; nn = nn->next)
                    853:                print_mdoc_node(m, nn, h);
                    854:
                    855:        if (n->child)
                    856:                h->flags |= HTML_NOSPACE;
                    857:
                    858:        print_text(h, "BSD");
                    859:        return(0);
                    860: }
                    861:
                    862:
                    863: /* ARGSUSED */
                    864: static int
1.1       kristaps  865: mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int c)
                    866: {
1.14      kristaps  867:        struct htmlpair          tag;
                    868:        const struct mdoc_node  *nn;
1.1       kristaps  869:
                    870:        switch (t) {
                    871:        case (MDOC_Column):
                    872:                /* FALLTHROUGH */
                    873:        case (MDOC_Item):
                    874:                /* FALLTHROUGH */
                    875:        case (MDOC_Ohang):
1.16      kristaps  876:                buffmt(h, "margin-left: %dem; clear: both;", o);
1.1       kristaps  877:                break;
                    878:        default:
1.16      kristaps  879:                buffmt(h, "margin-left: %dem; clear: both;", w + o);
1.1       kristaps  880:                break;
                    881:        }
                    882:
                    883:        if ( ! c && MDOC_Column != t) {
1.14      kristaps  884:                for (nn = n; nn; nn = nn->parent) {
                    885:                        if (MDOC_BLOCK != nn->type)
                    886:                                continue;
                    887:                        switch (nn->tok) {
                    888:                        case (MDOC_Ss):
                    889:                                /* FALLTHROUGH */
                    890:                        case (MDOC_Sh):
                    891:                                c = 1;
                    892:                                break;
                    893:                        default:
                    894:                                break;
                    895:                        }
                    896:                        if (nn->prev)
                    897:                                break;
                    898:                }
                    899:                if (MDOC_Diag == t && n->prev)
                    900:                        if (NULL == n->prev->body->child)
                    901:                                c = 1;
                    902:                if ( ! c)
1.16      kristaps  903:                        bufcat(h, "padding-top: 1em;");
1.1       kristaps  904:        }
                    905:
                    906:        tag.key = ATTR_STYLE;
1.16      kristaps  907:        tag.val = h->buf;
1.1       kristaps  908:        print_otag(h, TAG_DIV, 1, &tag);
                    909:        return(1);
                    910: }
                    911:
                    912:
                    913: /* ARGSUSED */
                    914: static int
                    915: mdoc_tbl_body_pre(MDOC_ARGS, int t, int w)
                    916: {
                    917:
                    918:        print_otag(h, TAG_DIV, 0, NULL);
                    919:        return(1);
                    920: }
                    921:
                    922:
                    923: /* ARGSUSED */
                    924: static int
                    925: mdoc_tbl_head_pre(MDOC_ARGS, int t, int w)
                    926: {
                    927:        struct htmlpair  tag;
                    928:        struct ord      *ord;
                    929:        char             nbuf[BUFSIZ];
                    930:
                    931:        switch (t) {
                    932:        case (MDOC_Item):
                    933:                /* FALLTHROUGH */
                    934:        case (MDOC_Ohang):
                    935:                print_otag(h, TAG_DIV, 0, NULL);
                    936:                break;
                    937:        case (MDOC_Column):
1.16      kristaps  938:                buffmt(h, "min-width: %dem;", w);
                    939:                bufcat(h, "clear: none;");
1.1       kristaps  940:                if (n->next && MDOC_HEAD == n->next->type)
1.16      kristaps  941:                        bufcat(h, "float: left;");
1.1       kristaps  942:                tag.key = ATTR_STYLE;
1.16      kristaps  943:                tag.val = h->buf;
1.1       kristaps  944:                print_otag(h, TAG_DIV, 1, &tag);
                    945:                break;
                    946:        default:
1.16      kristaps  947:                buffmt(h, "margin-left: -%dem; min-width: %dem;",
1.4       kristaps  948:                                w, w ? w - 1 : 0);
1.16      kristaps  949:                bufcat(h, "clear: left;");
1.2       kristaps  950:                if (n->next && n->next->child)
1.16      kristaps  951:                        bufcat(h, "float: left;");
                    952:                bufcat(h, "padding-right: 1em;");
1.1       kristaps  953:                tag.key = ATTR_STYLE;
1.16      kristaps  954:                tag.val = h->buf;
1.1       kristaps  955:                print_otag(h, TAG_DIV, 1, &tag);
                    956:                break;
                    957:        }
                    958:
                    959:        switch (t) {
                    960:        case (MDOC_Diag):
                    961:                tag.key = ATTR_CLASS;
                    962:                tag.val = "diag";
                    963:                print_otag(h, TAG_SPAN, 1, &tag);
                    964:                break;
                    965:        case (MDOC_Enum):
                    966:                ord = SLIST_FIRST(&h->ords);
                    967:                assert(ord);
                    968:                nbuf[BUFSIZ - 1] = 0;
                    969:                (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
                    970:                print_text(h, nbuf);
                    971:                return(0);
                    972:        case (MDOC_Dash):
                    973:                print_text(h, "\\(en");
                    974:                return(0);
                    975:        case (MDOC_Hyphen):
1.4       kristaps  976:                print_text(h, "\\(hy");
1.1       kristaps  977:                return(0);
                    978:        case (MDOC_Bullet):
                    979:                print_text(h, "\\(bu");
                    980:                return(0);
                    981:        default:
                    982:                break;
                    983:        }
                    984:
                    985:        return(1);
                    986: }
                    987:
                    988:
                    989: static int
                    990: mdoc_tbl_pre(MDOC_ARGS, int type)
                    991: {
                    992:        int                      i, w, o, c, wp;
                    993:        const struct mdoc_node  *bl, *nn;
                    994:
                    995:        bl = n->parent->parent;
                    996:        if (MDOC_BLOCK != n->type)
                    997:                bl = bl->parent;
                    998:
                    999:        assert(bl->args);
                   1000:
                   1001:        w = o = c = 0;
                   1002:        wp = -1;
                   1003:
                   1004:        for (i = 0; i < (int)bl->args->argc; i++)
                   1005:                if (MDOC_Width == bl->args->argv[i].arg) {
                   1006:                        assert(bl->args->argv[i].sz);
                   1007:                        wp = i;
                   1008:                        w = a2width(bl->args->argv[i].value[0]);
                   1009:                } else if (MDOC_Offset == bl->args->argv[i].arg) {
                   1010:                        assert(bl->args->argv[i].sz);
                   1011:                        o = a2offs(bl->args->argv[i].value[0]);
                   1012:                } else if (MDOC_Compact == bl->args->argv[i].arg)
                   1013:                        c = 1;
                   1014:
                   1015:        if (MDOC_HEAD == n->type && MDOC_Column == type) {
                   1016:                nn = n->parent->child;
                   1017:                assert(nn && MDOC_HEAD == nn->type);
                   1018:                for (i = 0; nn && nn != n; nn = nn->next, i++)
                   1019:                        /* Counter... */ ;
                   1020:                assert(nn);
                   1021:                if (wp >= 0 && i < (int)bl->args[wp].argv->sz)
                   1022:                        w = a2width(bl->args->argv[wp].value[i]);
                   1023:        }
                   1024:
                   1025:        switch (type) {
                   1026:        case (MDOC_Enum):
                   1027:                /* FALLTHROUGH */
                   1028:        case (MDOC_Dash):
                   1029:                /* FALLTHROUGH */
                   1030:        case (MDOC_Hyphen):
                   1031:                /* FALLTHROUGH */
                   1032:        case (MDOC_Bullet):
                   1033:                if (w < 4)
                   1034:                        w = 4;
                   1035:                break;
                   1036:        case (MDOC_Inset):
                   1037:                /* FALLTHROUGH */
                   1038:        case (MDOC_Diag):
                   1039:                w = 1;
                   1040:                break;
                   1041:        default:
                   1042:                if (0 == w)
                   1043:                        w = 10;
                   1044:                break;
                   1045:        }
                   1046:
                   1047:        switch (n->type) {
                   1048:        case (MDOC_BLOCK):
                   1049:                break;
                   1050:        case (MDOC_HEAD):
                   1051:                return(mdoc_tbl_head_pre(m, n, h, type, w));
                   1052:        case (MDOC_BODY):
                   1053:                return(mdoc_tbl_body_pre(m, n, h, type, w));
                   1054:        default:
                   1055:                abort();
                   1056:                /* NOTREACHED */
                   1057:        }
                   1058:
                   1059:        return(mdoc_tbl_block_pre(m, n, h, type, w, o, c));
                   1060: }
                   1061:
                   1062:
                   1063: /* ARGSUSED */
                   1064: static int
                   1065: mdoc_bl_pre(MDOC_ARGS)
                   1066: {
                   1067:        struct ord      *ord;
                   1068:
                   1069:        if (MDOC_BLOCK != n->type)
                   1070:                return(1);
                   1071:        if (MDOC_Enum != a2list(n))
                   1072:                return(1);
                   1073:
1.14      kristaps 1074:        /* Allocate an -enum on the stack of indices. */
                   1075:
1.1       kristaps 1076:        ord = malloc(sizeof(struct ord));
                   1077:        if (NULL == ord)
                   1078:                err(EXIT_FAILURE, "malloc");
                   1079:        ord->cookie = n;
                   1080:        ord->pos = 1;
                   1081:        SLIST_INSERT_HEAD(&h->ords, ord, entry);
                   1082:
                   1083:        return(1);
                   1084: }
                   1085:
                   1086:
                   1087: /* ARGSUSED */
                   1088: static void
                   1089: mdoc_bl_post(MDOC_ARGS)
                   1090: {
                   1091:        struct ord      *ord;
                   1092:
                   1093:        if (MDOC_BLOCK != n->type)
                   1094:                return;
                   1095:        if (MDOC_Enum != a2list(n))
                   1096:                return;
                   1097:
                   1098:        ord = SLIST_FIRST(&h->ords);
                   1099:        assert(ord);
                   1100:        SLIST_REMOVE_HEAD(&h->ords, entry);
                   1101:        free(ord);
                   1102: }
                   1103:
                   1104:
                   1105: static int
                   1106: mdoc_it_pre(MDOC_ARGS)
                   1107: {
                   1108:        int              type;
                   1109:
                   1110:        if (MDOC_BLOCK == n->type)
                   1111:                type = a2list(n->parent->parent);
                   1112:        else
                   1113:                type = a2list(n->parent->parent->parent);
                   1114:
                   1115:        return(mdoc_tbl_pre(m, n, h, type));
                   1116: }
                   1117:
                   1118:
                   1119: /* ARGSUSED */
                   1120: static int
                   1121: mdoc_ex_pre(MDOC_ARGS)
                   1122: {
                   1123:        const struct mdoc_node  *nn;
                   1124:        struct tag              *t;
                   1125:        struct htmlpair          tag;
                   1126:
                   1127:        print_text(h, "The");
                   1128:
                   1129:        tag.key = ATTR_CLASS;
                   1130:        tag.val = "utility";
                   1131:
                   1132:        for (nn = n->child; nn; nn = nn->next) {
                   1133:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1134:                print_text(h, nn->string);
                   1135:                print_tagq(h, t);
                   1136:
                   1137:                h->flags |= HTML_NOSPACE;
                   1138:
                   1139:                if (nn->next && NULL == nn->next->next)
                   1140:                        print_text(h, ", and");
                   1141:                else if (nn->next)
                   1142:                        print_text(h, ",");
                   1143:                else
                   1144:                        h->flags &= ~HTML_NOSPACE;
                   1145:        }
                   1146:
                   1147:        if (n->child->next)
                   1148:                print_text(h, "utilities exit");
                   1149:        else
                   1150:                print_text(h, "utility exits");
                   1151:
                   1152:                print_text(h, "0 on success, and >0 if an error occurs.");
                   1153:        return(0);
                   1154: }
                   1155:
                   1156:
                   1157: /* ARGSUSED */
                   1158: static int
                   1159: mdoc_dq_pre(MDOC_ARGS)
                   1160: {
                   1161:
                   1162:        if (MDOC_BODY != n->type)
                   1163:                return(1);
                   1164:        print_text(h, "\\(lq");
                   1165:        h->flags |= HTML_NOSPACE;
                   1166:        return(1);
                   1167: }
                   1168:
                   1169:
                   1170: /* ARGSUSED */
                   1171: static void
                   1172: mdoc_dq_post(MDOC_ARGS)
                   1173: {
                   1174:
                   1175:        if (MDOC_BODY != n->type)
                   1176:                return;
                   1177:        h->flags |= HTML_NOSPACE;
                   1178:        print_text(h, "\\(rq");
                   1179: }
                   1180:
                   1181:
                   1182: /* ARGSUSED */
                   1183: static int
                   1184: mdoc_pq_pre(MDOC_ARGS)
                   1185: {
                   1186:
                   1187:        if (MDOC_BODY != n->type)
                   1188:                return(1);
                   1189:        print_text(h, "\\&(");
                   1190:        h->flags |= HTML_NOSPACE;
                   1191:        return(1);
                   1192: }
                   1193:
                   1194:
                   1195: /* ARGSUSED */
                   1196: static void
                   1197: mdoc_pq_post(MDOC_ARGS)
                   1198: {
                   1199:
                   1200:        if (MDOC_BODY != n->type)
                   1201:                return;
                   1202:        print_text(h, ")");
                   1203: }
                   1204:
                   1205:
                   1206: /* ARGSUSED */
                   1207: static int
                   1208: mdoc_sq_pre(MDOC_ARGS)
                   1209: {
                   1210:
                   1211:        if (MDOC_BODY != n->type)
                   1212:                return(1);
                   1213:        print_text(h, "\\(oq");
                   1214:        h->flags |= HTML_NOSPACE;
                   1215:        return(1);
                   1216: }
                   1217:
                   1218:
                   1219: /* ARGSUSED */
                   1220: static void
                   1221: mdoc_sq_post(MDOC_ARGS)
                   1222: {
                   1223:
                   1224:        if (MDOC_BODY != n->type)
                   1225:                return;
                   1226:        h->flags |= HTML_NOSPACE;
                   1227:        print_text(h, "\\(aq");
                   1228: }
                   1229:
                   1230:
                   1231: /* ARGSUSED */
                   1232: static int
                   1233: mdoc_em_pre(MDOC_ARGS)
                   1234: {
                   1235:        struct htmlpair tag;
                   1236:
                   1237:        tag.key = ATTR_CLASS;
                   1238:        tag.val = "emph";
                   1239:
                   1240:        print_otag(h, TAG_SPAN, 1, &tag);
                   1241:        return(1);
                   1242: }
                   1243:
                   1244:
                   1245: /* ARGSUSED */
                   1246: static int
                   1247: mdoc_d1_pre(MDOC_ARGS)
                   1248: {
                   1249:        struct htmlpair tag[2];
                   1250:
                   1251:        if (MDOC_BLOCK != n->type)
                   1252:                return(1);
                   1253:
1.16      kristaps 1254:        buffmt(h, "margin-left: %dem;", INDENT);
1.1       kristaps 1255:
                   1256:        tag[0].key = ATTR_CLASS;
1.5       kristaps 1257:        tag[0].val = "lit";
1.1       kristaps 1258:        tag[1].key = ATTR_STYLE;
1.16      kristaps 1259:        tag[1].val = h->buf;
1.1       kristaps 1260:
                   1261:        print_otag(h, TAG_DIV, 2, tag);
                   1262:        return(1);
                   1263: }
                   1264:
                   1265:
                   1266: /* ARGSUSED */
                   1267: static int
                   1268: mdoc_sx_pre(MDOC_ARGS)
                   1269: {
1.18      kristaps 1270:        struct htmlpair          tag[2];
1.1       kristaps 1271:        const struct mdoc_node  *nn;
                   1272:
1.16      kristaps 1273:        bufcat(h, "#");
1.1       kristaps 1274:        for (nn = n->child; nn; nn = nn->next) {
1.16      kristaps 1275:                bufcat(h, nn->string);
1.1       kristaps 1276:                if (nn->next)
1.16      kristaps 1277:                        bufcat(h, " ");
1.1       kristaps 1278:        }
                   1279:
                   1280:        tag[0].key = ATTR_HREF;
1.16      kristaps 1281:        tag[0].val = h->buf;
1.1       kristaps 1282:        tag[1].key = ATTR_CLASS;
                   1283:        tag[1].val = "link-sec";
                   1284:
1.18      kristaps 1285:        print_otag(h, TAG_A, 2, tag);
1.1       kristaps 1286:        return(1);
                   1287: }
                   1288:
                   1289:
                   1290: /* ARGSUSED */
                   1291: static int
                   1292: mdoc_aq_pre(MDOC_ARGS)
                   1293: {
                   1294:
                   1295:        if (MDOC_BODY != n->type)
                   1296:                return(1);
                   1297:        print_text(h, "\\(la");
                   1298:        h->flags |= HTML_NOSPACE;
                   1299:        return(1);
                   1300: }
                   1301:
                   1302:
                   1303: /* ARGSUSED */
                   1304: static void
                   1305: mdoc_aq_post(MDOC_ARGS)
                   1306: {
                   1307:
                   1308:        if (MDOC_BODY != n->type)
                   1309:                return;
                   1310:        h->flags |= HTML_NOSPACE;
                   1311:        print_text(h, "\\(ra");
                   1312: }
                   1313:
                   1314:
                   1315: /* ARGSUSED */
                   1316: static int
                   1317: mdoc_bd_pre(MDOC_ARGS)
                   1318: {
                   1319:        struct htmlpair          tag[2];
                   1320:        int                      t, c, o, i;
1.14      kristaps 1321:        const struct mdoc_node  *bl, *nn;
1.1       kristaps 1322:
                   1323:        if (MDOC_BLOCK == n->type)
                   1324:                bl = n;
                   1325:        else if (MDOC_HEAD == n->type)
                   1326:                return(0);
                   1327:        else
                   1328:                bl = n->parent;
                   1329:
                   1330:        t = o = c = 0;
                   1331:
                   1332:        for (i = 0; i < (int)bl->args->argc; i++)
                   1333:                switch (bl->args->argv[i].arg) {
                   1334:                case (MDOC_Offset):
                   1335:                        assert(bl->args->argv[i].sz);
1.13      kristaps 1336:                        o = a2offs(bl->args->argv[i].value[0]);
1.1       kristaps 1337:                        break;
                   1338:                case (MDOC_Compact):
                   1339:                        c = 1;
                   1340:                        break;
                   1341:                case (MDOC_Ragged):
                   1342:                        /* FALLTHROUGH */
                   1343:                case (MDOC_Filled):
                   1344:                        /* FALLTHROUGH */
                   1345:                case (MDOC_Unfilled):
                   1346:                        /* FALLTHROUGH */
                   1347:                case (MDOC_Literal):
                   1348:                        t = bl->args->argv[i].arg;
                   1349:                        break;
                   1350:                }
                   1351:
                   1352:        if (MDOC_BLOCK == n->type) {
                   1353:                if (o)
1.16      kristaps 1354:                        buffmt(h, "margin-left: %dem;", o);
1.14      kristaps 1355:                if ( ! c) {
                   1356:                        for (nn = n; nn; nn = nn->parent) {
                   1357:                                if (MDOC_BLOCK != nn->type)
                   1358:                                        continue;
                   1359:                                switch (nn->tok) {
                   1360:                                case (MDOC_Ss):
                   1361:                                        /* FALLTHROUGH */
                   1362:                                case (MDOC_Sh):
                   1363:                                        c = 1;
                   1364:                                        break;
                   1365:                                default:
                   1366:                                        break;
                   1367:                                }
                   1368:                                if (nn->prev)
                   1369:                                        break;
                   1370:                        }
                   1371:                        if ( ! c)
1.16      kristaps 1372:                                bufcat(h, "margin-top: 1em;");
1.14      kristaps 1373:                }
1.1       kristaps 1374:                tag[0].key = ATTR_STYLE;
1.16      kristaps 1375:                tag[0].val = h->buf;
1.1       kristaps 1376:                print_otag(h, TAG_DIV, 1, tag);
                   1377:                return(1);
                   1378:        }
                   1379:
1.14      kristaps 1380:        if (MDOC_Unfilled != t && MDOC_Literal != t)
1.1       kristaps 1381:                return(1);
                   1382:
1.16      kristaps 1383:        bufcat(h, "white-space: pre;");
1.1       kristaps 1384:        tag[0].key = ATTR_STYLE;
1.16      kristaps 1385:        tag[0].val = h->buf;
1.1       kristaps 1386:        tag[1].key = ATTR_CLASS;
1.5       kristaps 1387:        tag[1].val = "lit";
1.1       kristaps 1388:
                   1389:        print_otag(h, TAG_DIV, 2, tag);
                   1390:
1.14      kristaps 1391:        for (nn = n->child; nn; nn = nn->next) {
                   1392:                print_mdoc_node(m, nn, h);
                   1393:                if (NULL == nn->next)
                   1394:                        continue;
                   1395:                if (nn->prev && nn->prev->line < nn->line)
1.1       kristaps 1396:                        print_text(h, "\n");
                   1397:        }
                   1398:
                   1399:        return(0);
                   1400: }
                   1401:
                   1402:
                   1403: /* ARGSUSED */
                   1404: static int
                   1405: mdoc_pa_pre(MDOC_ARGS)
                   1406: {
                   1407:        struct htmlpair tag;
                   1408:
                   1409:        tag.key = ATTR_CLASS;
                   1410:        tag.val = "file";
                   1411:
                   1412:        print_otag(h, TAG_SPAN, 1, &tag);
                   1413:        return(1);
                   1414: }
                   1415:
                   1416:
                   1417: /* ARGSUSED */
                   1418: static int
                   1419: mdoc_ad_pre(MDOC_ARGS)
                   1420: {
                   1421:        struct htmlpair tag;
                   1422:
                   1423:        tag.key = ATTR_CLASS;
                   1424:        tag.val = "addr";
                   1425:        print_otag(h, TAG_SPAN, 1, &tag);
                   1426:        return(1);
                   1427: }
                   1428:
                   1429:
                   1430: /* ARGSUSED */
                   1431: static int
                   1432: mdoc_an_pre(MDOC_ARGS)
                   1433: {
                   1434:        struct htmlpair tag;
                   1435:
1.19      kristaps 1436:        /* TODO: -split and -nosplit (see termp_an_pre()). */
                   1437:
1.1       kristaps 1438:        tag.key = ATTR_CLASS;
                   1439:        tag.val = "author";
                   1440:        print_otag(h, TAG_SPAN, 1, &tag);
                   1441:        return(1);
                   1442: }
                   1443:
                   1444:
                   1445: /* ARGSUSED */
                   1446: static int
                   1447: mdoc_cd_pre(MDOC_ARGS)
                   1448: {
                   1449:        struct htmlpair tag;
                   1450:
                   1451:        tag.key = ATTR_CLASS;
                   1452:        tag.val = "config";
                   1453:        print_otag(h, TAG_SPAN, 1, &tag);
                   1454:        return(1);
                   1455: }
                   1456:
                   1457:
                   1458: /* ARGSUSED */
                   1459: static int
                   1460: mdoc_dv_pre(MDOC_ARGS)
                   1461: {
                   1462:        struct htmlpair tag;
                   1463:
                   1464:        tag.key = ATTR_CLASS;
                   1465:        tag.val = "define";
                   1466:        print_otag(h, TAG_SPAN, 1, &tag);
                   1467:        return(1);
                   1468: }
                   1469:
                   1470:
                   1471: /* ARGSUSED */
                   1472: static int
                   1473: mdoc_ev_pre(MDOC_ARGS)
                   1474: {
                   1475:        struct htmlpair tag;
                   1476:
                   1477:        tag.key = ATTR_CLASS;
                   1478:        tag.val = "env";
                   1479:        print_otag(h, TAG_SPAN, 1, &tag);
                   1480:        return(1);
                   1481: }
                   1482:
                   1483:
                   1484: /* ARGSUSED */
                   1485: static int
                   1486: mdoc_er_pre(MDOC_ARGS)
                   1487: {
                   1488:        struct htmlpair tag;
                   1489:
                   1490:        tag.key = ATTR_CLASS;
                   1491:        tag.val = "errno";
                   1492:        print_otag(h, TAG_SPAN, 1, &tag);
                   1493:        return(1);
                   1494: }
                   1495:
                   1496:
                   1497: /* ARGSUSED */
                   1498: static int
                   1499: mdoc_fa_pre(MDOC_ARGS)
                   1500: {
                   1501:        const struct mdoc_node  *nn;
                   1502:        struct htmlpair          tag;
                   1503:        struct tag              *t;
                   1504:
                   1505:        tag.key = ATTR_CLASS;
                   1506:        tag.val = "farg";
                   1507:
                   1508:        if (n->parent->tok != MDOC_Fo) {
                   1509:                print_otag(h, TAG_SPAN, 1, &tag);
                   1510:                return(1);
                   1511:        }
                   1512:
                   1513:        for (nn = n->child; nn; nn = nn->next) {
                   1514:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1515:                print_text(h, nn->string);
                   1516:                print_tagq(h, t);
                   1517:                if (nn->next)
                   1518:                        print_text(h, ",");
                   1519:        }
                   1520:
                   1521:        if (n->child && n->next && n->next->tok == MDOC_Fa)
                   1522:                print_text(h, ",");
                   1523:
                   1524:        return(0);
                   1525: }
                   1526:
                   1527:
                   1528: /* ARGSUSED */
                   1529: static int
                   1530: mdoc_fd_pre(MDOC_ARGS)
                   1531: {
                   1532:        struct htmlpair tag;
                   1533:
                   1534:        if (SEC_SYNOPSIS == n->sec) {
                   1535:                if (n->next && MDOC_Fd != n->next->tok) {
                   1536:                        tag.key = ATTR_STYLE;
                   1537:                        tag.val = "margin-bottom: 1em;";
                   1538:                        print_otag(h, TAG_DIV, 1, &tag);
                   1539:                } else
                   1540:                        print_otag(h, TAG_DIV, 0, NULL);
                   1541:        }
                   1542:
                   1543:        tag.key = ATTR_CLASS;
                   1544:        tag.val = "macro";
                   1545:        print_otag(h, TAG_SPAN, 1, &tag);
                   1546:        return(1);
                   1547: }
                   1548:
                   1549:
                   1550: /* ARGSUSED */
                   1551: static int
                   1552: mdoc_vt_pre(MDOC_ARGS)
                   1553: {
                   1554:        struct htmlpair tag;
                   1555:
                   1556:        if (SEC_SYNOPSIS == n->sec) {
                   1557:                if (n->next && MDOC_Vt != n->next->tok) {
                   1558:                        tag.key = ATTR_STYLE;
                   1559:                        tag.val = "margin-bottom: 1em;";
                   1560:                        print_otag(h, TAG_DIV, 1, &tag);
                   1561:                } else
                   1562:                        print_otag(h, TAG_DIV, 0, NULL);
                   1563:        }
                   1564:
                   1565:        tag.key = ATTR_CLASS;
                   1566:        tag.val = "type";
                   1567:        print_otag(h, TAG_SPAN, 1, &tag);
                   1568:        return(1);
                   1569: }
                   1570:
1.2       kristaps 1571:
1.1       kristaps 1572: /* ARGSUSED */
                   1573: static int
                   1574: mdoc_ft_pre(MDOC_ARGS)
                   1575: {
                   1576:        struct htmlpair tag;
                   1577:
                   1578:        if (SEC_SYNOPSIS == n->sec) {
                   1579:                if (n->prev && MDOC_Fo == n->prev->tok) {
                   1580:                        tag.key = ATTR_STYLE;
1.4       kristaps 1581:                        tag.val = "margin-top: 1em;";
1.1       kristaps 1582:                        print_otag(h, TAG_DIV, 1, &tag);
                   1583:                } else
                   1584:                        print_otag(h, TAG_DIV, 0, NULL);
                   1585:        }
                   1586:
                   1587:        tag.key = ATTR_CLASS;
1.7       kristaps 1588:        tag.val = "ftype";
1.1       kristaps 1589:        print_otag(h, TAG_SPAN, 1, &tag);
                   1590:        return(1);
                   1591: }
                   1592:
                   1593:
                   1594: /* ARGSUSED */
                   1595: static int
                   1596: mdoc_fn_pre(MDOC_ARGS)
                   1597: {
                   1598:        struct tag              *t;
1.15      kristaps 1599:        struct htmlpair          tag[2];
1.1       kristaps 1600:        const struct mdoc_node  *nn;
1.7       kristaps 1601:        char                     nbuf[BUFSIZ];
                   1602:        const char              *sp, *ep;
1.15      kristaps 1603:        int                      sz, i;
1.1       kristaps 1604:
                   1605:        if (SEC_SYNOPSIS == n->sec) {
1.16      kristaps 1606:                bufcat(h, "margin-left: 6em;");
                   1607:                bufcat(h, "text-indent: -6em;");
1.15      kristaps 1608:                if (n->next)
1.16      kristaps 1609:                        bufcat(h, "margin-bottom: 1em;");
1.15      kristaps 1610:                tag[0].key = ATTR_STYLE;
1.16      kristaps 1611:                tag[0].val = h->buf;
1.15      kristaps 1612:                print_otag(h, TAG_DIV, 1, tag);
1.1       kristaps 1613:        }
                   1614:
1.7       kristaps 1615:        /* Split apart into type and name. */
                   1616:        assert(n->child->string);
                   1617:        sp = n->child->string;
1.19      kristaps 1618:
                   1619:        if ((ep = strchr(sp, ' '))) {
                   1620:                tag[0].key = ATTR_CLASS;
                   1621:                tag[0].val = "ftype";
                   1622:
                   1623:                t = print_otag(h, TAG_SPAN, 1, tag);
                   1624:
                   1625:                while (ep) {
                   1626:                        sz = MIN((int)(ep - sp), BUFSIZ - 1);
                   1627:                        (void)memcpy(nbuf, sp, (size_t)sz);
                   1628:                        nbuf[sz] = '\0';
                   1629:                        print_text(h, nbuf);
                   1630:                        sp = ++ep;
                   1631:                        ep = strchr(sp, ' ');
                   1632:                }
                   1633:                print_tagq(h, t);
1.7       kristaps 1634:        }
1.1       kristaps 1635:
1.15      kristaps 1636:        tag[0].key = ATTR_CLASS;
                   1637:        tag[0].val = "fname";
                   1638:        t = print_otag(h, TAG_SPAN, 1, tag);
1.7       kristaps 1639:
                   1640:        if (sp) {
                   1641:                (void)strlcpy(nbuf, sp, BUFSIZ);
                   1642:                print_text(h, nbuf);
                   1643:        }
                   1644:
1.1       kristaps 1645:        print_tagq(h, t);
                   1646:
                   1647:        h->flags |= HTML_NOSPACE;
                   1648:        print_text(h, "(");
                   1649:
                   1650:        for (nn = n->child->next; nn; nn = nn->next) {
1.15      kristaps 1651:                i = 0;
                   1652:                tag[i].key = ATTR_CLASS;
                   1653:                tag[i++].val = "farg";
                   1654:                if (SEC_SYNOPSIS == n->sec) {
                   1655:                        tag[i].key = ATTR_STYLE;
                   1656:                        tag[i++].val = "white-space: nowrap;";
                   1657:                }
                   1658:
                   1659:                t = print_otag(h, TAG_SPAN, i, tag);
1.1       kristaps 1660:                print_text(h, nn->string);
                   1661:                print_tagq(h, t);
                   1662:                if (nn->next)
                   1663:                        print_text(h, ",");
                   1664:        }
                   1665:
                   1666:        print_text(h, ")");
                   1667:
                   1668:        if (SEC_SYNOPSIS == n->sec)
                   1669:                print_text(h, ";");
                   1670:
                   1671:        return(0);
                   1672: }
                   1673:
                   1674:
                   1675: /* ARGSUSED */
                   1676: static int
                   1677: mdoc_sp_pre(MDOC_ARGS)
                   1678: {
                   1679:        int             len;
                   1680:        struct htmlpair tag;
                   1681:
                   1682:        switch (n->tok) {
                   1683:        case (MDOC_sp):
                   1684:                len = n->child ? atoi(n->child->string) : 1;
                   1685:                break;
                   1686:        case (MDOC_br):
                   1687:                len = 0;
                   1688:                break;
                   1689:        default:
                   1690:                len = 1;
                   1691:                break;
                   1692:        }
                   1693:
1.16      kristaps 1694:        buffmt(h, "height: %dem", len);
1.1       kristaps 1695:        tag.key = ATTR_STYLE;
1.16      kristaps 1696:        tag.val = h->buf;
1.1       kristaps 1697:        print_otag(h, TAG_DIV, 1, &tag);
                   1698:        return(1);
                   1699:
                   1700: }
1.2       kristaps 1701:
                   1702:
                   1703: /* ARGSUSED */
                   1704: static int
                   1705: mdoc_brq_pre(MDOC_ARGS)
                   1706: {
                   1707:
                   1708:        if (MDOC_BODY != n->type)
                   1709:                return(1);
                   1710:        print_text(h, "\\(lC");
                   1711:        h->flags |= HTML_NOSPACE;
                   1712:        return(1);
                   1713: }
                   1714:
                   1715:
                   1716: /* ARGSUSED */
                   1717: static void
                   1718: mdoc_brq_post(MDOC_ARGS)
                   1719: {
                   1720:
                   1721:        if (MDOC_BODY != n->type)
                   1722:                return;
                   1723:        h->flags |= HTML_NOSPACE;
                   1724:        print_text(h, "\\(rC");
                   1725: }
                   1726:
                   1727:
                   1728: /* ARGSUSED */
                   1729: static int
                   1730: mdoc_lk_pre(MDOC_ARGS)
                   1731: {
                   1732:        const struct mdoc_node  *nn;
                   1733:        struct htmlpair          tag[2];
                   1734:
                   1735:        nn = n->child;
                   1736:
                   1737:        tag[0].key = ATTR_CLASS;
                   1738:        tag[0].val = "link-ext";
                   1739:        tag[1].key = ATTR_HREF;
                   1740:        tag[1].val = nn->string;
                   1741:
                   1742:        print_otag(h, TAG_A, 2, tag);
                   1743:
                   1744:        if (NULL == nn->next)
                   1745:                return(1);
                   1746:
                   1747:        for (nn = nn->next; nn; nn = nn->next)
                   1748:                print_text(h, nn->string);
                   1749:
                   1750:        return(0);
                   1751: }
                   1752:
                   1753:
                   1754: /* ARGSUSED */
                   1755: static int
                   1756: mdoc_mt_pre(MDOC_ARGS)
                   1757: {
                   1758:        struct htmlpair          tag[2];
                   1759:        struct tag              *t;
                   1760:        const struct mdoc_node  *nn;
                   1761:
                   1762:        tag[0].key = ATTR_CLASS;
                   1763:        tag[0].val = "link-mail";
                   1764:
                   1765:        for (nn = n->child; nn; nn = nn->next) {
1.16      kristaps 1766:                bufinit(h);
                   1767:                bufcat(h, "mailto:");
                   1768:                bufcat(h, nn->string);
1.2       kristaps 1769:
                   1770:                tag[1].key = ATTR_HREF;
1.16      kristaps 1771:                tag[1].val = h->buf;
1.2       kristaps 1772:
                   1773:                t = print_otag(h, TAG_A, 2, tag);
                   1774:                print_text(h, nn->string);
                   1775:                print_tagq(h, t);
                   1776:        }
                   1777:
                   1778:        return(0);
                   1779: }
1.4       kristaps 1780:
                   1781:
                   1782: /* ARGSUSED */
                   1783: static int
                   1784: mdoc_fo_pre(MDOC_ARGS)
                   1785: {
                   1786:        struct htmlpair tag;
                   1787:
                   1788:        if (MDOC_BODY == n->type) {
                   1789:                h->flags |= HTML_NOSPACE;
                   1790:                print_text(h, "(");
                   1791:                h->flags |= HTML_NOSPACE;
                   1792:                return(1);
                   1793:        } else if (MDOC_BLOCK == n->type)
                   1794:                return(1);
                   1795:
                   1796:        tag.key = ATTR_CLASS;
                   1797:        tag.val = "fname";
                   1798:        print_otag(h, TAG_SPAN, 1, &tag);
                   1799:        return(1);
                   1800: }
                   1801:
                   1802:
                   1803: /* ARGSUSED */
                   1804: static void
                   1805: mdoc_fo_post(MDOC_ARGS)
                   1806: {
                   1807:        if (MDOC_BODY != n->type)
                   1808:                return;
                   1809:        h->flags |= HTML_NOSPACE;
                   1810:        print_text(h, ")");
                   1811:        h->flags |= HTML_NOSPACE;
                   1812:        print_text(h, ";");
                   1813: }
                   1814:
                   1815:
                   1816: /* ARGSUSED */
                   1817: static int
                   1818: mdoc_in_pre(MDOC_ARGS)
                   1819: {
                   1820:        const struct mdoc_node  *nn;
1.17      kristaps 1821:        struct htmlpair          tag[2];
                   1822:        struct tag              *t;
                   1823:        int                      i;
1.4       kristaps 1824:
                   1825:        if (SEC_SYNOPSIS == n->sec) {
                   1826:                if (n->next && MDOC_In != n->next->tok) {
1.17      kristaps 1827:                        tag[0].key = ATTR_STYLE;
                   1828:                        tag[0].val = "margin-bottom: 1em;";
                   1829:                        print_otag(h, TAG_DIV, 1, tag);
1.4       kristaps 1830:                } else
                   1831:                        print_otag(h, TAG_DIV, 0, NULL);
                   1832:        }
                   1833:
1.17      kristaps 1834:        tag[0].key = ATTR_CLASS;
                   1835:        tag[0].val = "includes";
1.4       kristaps 1836:
1.17      kristaps 1837:        print_otag(h, TAG_SPAN, 1, tag);
1.4       kristaps 1838:
                   1839:        if (SEC_SYNOPSIS == n->sec)
                   1840:                print_text(h, "#include");
                   1841:
                   1842:        print_text(h, "<");
                   1843:        h->flags |= HTML_NOSPACE;
                   1844:
                   1845:        /* XXX -- see warning in termp_in_post(). */
                   1846:
1.17      kristaps 1847:        for (nn = n->child; nn; nn = nn->next) {
                   1848:                assert(MDOC_TEXT == nn->type);
                   1849:                i = 0;
                   1850:                tag[i].key = ATTR_CLASS;
                   1851:                tag[i++].val = "link-includes";
                   1852:                if (h->base_includes) {
                   1853:                        buffmt_includes(h, nn->string);
                   1854:                        tag[i].key = ATTR_HREF;
                   1855:                        tag[i++].val = h->buf;
                   1856:                }
                   1857:                t = print_otag(h, TAG_A, i, tag);
1.4       kristaps 1858:                print_mdoc_node(m, nn, h);
1.17      kristaps 1859:                print_tagq(h, t);
                   1860:        }
1.4       kristaps 1861:
                   1862:        h->flags |= HTML_NOSPACE;
                   1863:        print_text(h, ">");
                   1864:
                   1865:        return(0);
                   1866: }
                   1867:
                   1868:
                   1869: /* ARGSUSED */
                   1870: static int
                   1871: mdoc_ic_pre(MDOC_ARGS)
                   1872: {
                   1873:        struct htmlpair tag;
                   1874:
                   1875:        tag.key = ATTR_CLASS;
                   1876:        tag.val = "cmd";
                   1877:
                   1878:        print_otag(h, TAG_SPAN, 1, &tag);
                   1879:        return(1);
                   1880: }
                   1881:
                   1882:
                   1883: /* ARGSUSED */
                   1884: static int
                   1885: mdoc_rv_pre(MDOC_ARGS)
                   1886: {
                   1887:        const struct mdoc_node  *nn;
                   1888:        struct htmlpair          tag;
                   1889:        struct tag              *t;
                   1890:
                   1891:        print_otag(h, TAG_DIV, 0, NULL);
                   1892:
                   1893:        print_text(h, "The");
                   1894:
                   1895:        for (nn = n->child; nn; nn = nn->next) {
                   1896:                tag.key = ATTR_CLASS;
                   1897:                tag.val = "fname";
                   1898:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1899:                print_text(h, nn->string);
                   1900:                print_tagq(h, t);
                   1901:
                   1902:                h->flags |= HTML_NOSPACE;
                   1903:                if (nn->next && NULL == nn->next->next)
                   1904:                        print_text(h, "(), and");
                   1905:                else if (nn->next)
                   1906:                        print_text(h, "(),");
                   1907:                else
                   1908:                        print_text(h, "()");
                   1909:        }
                   1910:
                   1911:        if (n->child->next)
                   1912:                print_text(h, "functions return");
                   1913:        else
                   1914:                print_text(h, "function returns");
                   1915:
                   1916:                print_text(h, "the value 0 if successful; otherwise the value "
                   1917:                        "-1 is returned and the global variable");
                   1918:
                   1919:        tag.key = ATTR_CLASS;
                   1920:        tag.val = "var";
                   1921:        t = print_otag(h, TAG_SPAN, 1, &tag);
                   1922:        print_text(h, "errno");
                   1923:        print_tagq(h, t);
                   1924:                print_text(h, "is set to indicate the error.");
                   1925:        return(0);
                   1926: }
                   1927:
                   1928:
                   1929: /* ARGSUSED */
                   1930: static int
                   1931: mdoc_va_pre(MDOC_ARGS)
                   1932: {
                   1933:        struct htmlpair tag;
                   1934:
                   1935:        tag.key = ATTR_CLASS;
                   1936:        tag.val = "var";
                   1937:        print_otag(h, TAG_SPAN, 1, &tag);
                   1938:        return(1);
                   1939: }
                   1940:
                   1941:
                   1942: /* ARGSUSED */
                   1943: static int
                   1944: mdoc_bq_pre(MDOC_ARGS)
                   1945: {
                   1946:
                   1947:        if (MDOC_BODY != n->type)
                   1948:                return(1);
                   1949:        print_text(h, "\\(lB");
                   1950:        h->flags |= HTML_NOSPACE;
                   1951:        return(1);
                   1952: }
                   1953:
                   1954:
                   1955: /* ARGSUSED */
                   1956: static void
                   1957: mdoc_bq_post(MDOC_ARGS)
                   1958: {
                   1959:
                   1960:        if (MDOC_BODY != n->type)
                   1961:                return;
                   1962:        h->flags |= HTML_NOSPACE;
                   1963:        print_text(h, "\\(rB");
                   1964: }
1.5       kristaps 1965:
                   1966:
                   1967: /* ARGSUSED */
                   1968: static int
                   1969: mdoc_ap_pre(MDOC_ARGS)
                   1970: {
                   1971:
                   1972:        h->flags |= HTML_NOSPACE;
                   1973:        print_text(h, "\\(aq");
                   1974:        h->flags |= HTML_NOSPACE;
                   1975:        return(1);
                   1976: }
                   1977:
                   1978:
                   1979: /* ARGSUSED */
                   1980: static int
                   1981: mdoc_bf_pre(MDOC_ARGS)
                   1982: {
                   1983:        int             i;
                   1984:        struct htmlpair tag[2];
                   1985:
                   1986:        if (MDOC_HEAD == n->type)
                   1987:                return(0);
                   1988:        else if (MDOC_BLOCK != n->type)
                   1989:                return(1);
                   1990:
                   1991:        tag[0].key = ATTR_CLASS;
                   1992:        tag[0].val = NULL;
                   1993:
                   1994:        if (n->head->child) {
                   1995:                if ( ! strcmp("Em", n->head->child->string))
                   1996:                        tag[0].val = "emph";
                   1997:                else if ( ! strcmp("Sy", n->head->child->string))
                   1998:                        tag[0].val = "symb";
                   1999:                else if ( ! strcmp("Li", n->head->child->string))
                   2000:                        tag[0].val = "lit";
                   2001:        } else {
                   2002:                assert(n->args);
                   2003:                for (i = 0; i < (int)n->args->argc; i++)
                   2004:                        switch (n->args->argv[i].arg) {
                   2005:                        case (MDOC_Symbolic):
                   2006:                                tag[0].val = "symb";
                   2007:                                break;
                   2008:                        case (MDOC_Literal):
                   2009:                                tag[0].val = "lit";
                   2010:                                break;
                   2011:                        case (MDOC_Emphasis):
                   2012:                                tag[0].val = "emph";
                   2013:                                break;
                   2014:                        default:
                   2015:                                break;
                   2016:                        }
                   2017:        }
                   2018:
                   2019:        /* FIXME: div's have spaces stripped--we want them. */
                   2020:
                   2021:        assert(tag[0].val);
                   2022:        tag[1].key = ATTR_STYLE;
                   2023:        tag[1].val = "display: inline; margin-right: 1em;";
                   2024:        print_otag(h, TAG_DIV, 2, tag);
                   2025:        return(1);
                   2026: }
                   2027:
                   2028:
                   2029: /* ARGSUSED */
                   2030: static int
                   2031: mdoc_ms_pre(MDOC_ARGS)
                   2032: {
                   2033:        struct htmlpair tag;
                   2034:
                   2035:        tag.key = ATTR_CLASS;
                   2036:        tag.val = "symb";
                   2037:        print_otag(h, TAG_SPAN, 1, &tag);
                   2038:        return(1);
                   2039: }
                   2040:
                   2041:
                   2042: /* ARGSUSED */
                   2043: static int
                   2044: mdoc_pf_pre(MDOC_ARGS)
                   2045: {
                   2046:
                   2047:        h->flags |= HTML_IGNDELIM;
                   2048:        return(1);
                   2049: }
                   2050:
                   2051:
                   2052: /* ARGSUSED */
                   2053: static void
                   2054: mdoc_pf_post(MDOC_ARGS)
                   2055: {
                   2056:
                   2057:        h->flags &= ~HTML_IGNDELIM;
                   2058:        h->flags |= HTML_NOSPACE;
                   2059: }
                   2060:
                   2061:
                   2062: /* ARGSUSED */
                   2063: static int
                   2064: mdoc_rs_pre(MDOC_ARGS)
                   2065: {
1.8       kristaps 2066:        struct htmlpair tag;
1.5       kristaps 2067:
                   2068:        if (MDOC_BLOCK != n->type)
                   2069:                return(1);
                   2070:
1.8       kristaps 2071:        if (n->prev && SEC_SEE_ALSO == n->sec) {
                   2072:                tag.key = ATTR_STYLE;
                   2073:                tag.val = "margin-top: 1em;";
                   2074:                print_otag(h, TAG_DIV, 1, &tag);
1.5       kristaps 2075:        }
                   2076:
1.8       kristaps 2077:        tag.key = ATTR_CLASS;
                   2078:        tag.val = "ref";
                   2079:        print_otag(h, TAG_SPAN, 1, &tag);
1.5       kristaps 2080:        return(1);
                   2081: }
1.6       kristaps 2082:
                   2083:
                   2084:
                   2085: /* ARGSUSED */
                   2086: static int
                   2087: mdoc_li_pre(MDOC_ARGS)
                   2088: {
                   2089:        struct htmlpair tag;
                   2090:
                   2091:        tag.key = ATTR_CLASS;
                   2092:        tag.val = "lit";
                   2093:
                   2094:        print_otag(h, TAG_SPAN, 1, &tag);
                   2095:        return(1);
                   2096: }
                   2097:
                   2098:
                   2099: /* ARGSUSED */
                   2100: static int
                   2101: mdoc_sy_pre(MDOC_ARGS)
                   2102: {
                   2103:        struct htmlpair tag;
                   2104:
                   2105:        tag.key = ATTR_CLASS;
                   2106:        tag.val = "symb";
                   2107:
                   2108:        print_otag(h, TAG_SPAN, 1, &tag);
                   2109:        return(1);
                   2110: }
                   2111:
                   2112:
                   2113: /* ARGSUSED */
                   2114: static int
                   2115: mdoc_bt_pre(MDOC_ARGS)
                   2116: {
                   2117:
                   2118:        print_text(h, "is currently in beta test.");
                   2119:        return(0);
                   2120: }
                   2121:
                   2122:
                   2123: /* ARGSUSED */
                   2124: static int
                   2125: mdoc_ud_pre(MDOC_ARGS)
                   2126: {
                   2127:
                   2128:        print_text(h, "currently under development.");
                   2129:        return(0);
                   2130: }
                   2131:
                   2132:
                   2133: /* ARGSUSED */
                   2134: static int
                   2135: mdoc_lb_pre(MDOC_ARGS)
                   2136: {
                   2137:        struct htmlpair tag;
                   2138:
                   2139:        tag.key = ATTR_CLASS;
                   2140:        tag.val = "lib";
                   2141:
                   2142:        if (SEC_SYNOPSIS == n->sec)
                   2143:                print_otag(h, TAG_DIV, 0, NULL);
                   2144:
                   2145:        print_otag(h, TAG_SPAN, 1, &tag);
                   2146:        return(1);
                   2147: }
1.10      kristaps 2148:
                   2149:
                   2150: /* ARGSUSED */
                   2151: static int
                   2152: mdoc__x_pre(MDOC_ARGS)
                   2153: {
                   2154:        struct htmlpair tag;
                   2155:
                   2156:        tag.key = ATTR_CLASS;
                   2157:
                   2158:        switch (n->tok) {
                   2159:        case(MDOC__A):
                   2160:                tag.val = "ref-auth";
                   2161:                break;
                   2162:        case(MDOC__B):
                   2163:                tag.val = "ref-book";
                   2164:                break;
                   2165:        case(MDOC__C):
                   2166:                tag.val = "ref-city";
                   2167:                break;
                   2168:        case(MDOC__D):
                   2169:                tag.val = "ref-date";
                   2170:                break;
                   2171:        case(MDOC__I):
                   2172:                tag.val = "ref-issue";
                   2173:                break;
                   2174:        case(MDOC__J):
                   2175:                tag.val = "ref-jrnl";
                   2176:                break;
                   2177:        case(MDOC__N):
                   2178:                tag.val = "ref-num";
                   2179:                break;
                   2180:        case(MDOC__O):
                   2181:                tag.val = "ref-opt";
                   2182:                break;
                   2183:        case(MDOC__P):
                   2184:                tag.val = "ref-page";
                   2185:                break;
                   2186:        case(MDOC__Q):
                   2187:                tag.val = "ref-corp";
                   2188:                break;
                   2189:        case(MDOC__R):
                   2190:                tag.val = "ref-rep";
                   2191:                break;
                   2192:        case(MDOC__T):
                   2193:                print_text(h, "\\(lq");
                   2194:                h->flags |= HTML_NOSPACE;
                   2195:                tag.val = "ref-title";
                   2196:                break;
                   2197:        case(MDOC__V):
                   2198:                tag.val = "ref-vol";
                   2199:                break;
                   2200:        default:
                   2201:                abort();
                   2202:                /* NOTREACHED */
                   2203:        }
                   2204:
                   2205:        print_otag(h, TAG_SPAN, 1, &tag);
                   2206:        return(1);
                   2207: }
                   2208:
                   2209:
                   2210: /* ARGSUSED */
                   2211: static void
                   2212: mdoc__x_post(MDOC_ARGS)
                   2213: {
                   2214:
                   2215:        h->flags |= HTML_NOSPACE;
                   2216:        switch (n->tok) {
                   2217:        case (MDOC__T):
                   2218:                print_text(h, "\\(rq");
                   2219:                h->flags |= HTML_NOSPACE;
                   2220:                break;
                   2221:        default:
                   2222:                break;
                   2223:        }
                   2224:        print_text(h, n->next ? "," : ".");
                   2225: }

CVSweb