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

Annotation of mandoc/mdoc_html.c, Revision 1.21

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

CVSweb