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

Annotation of mandoc/mdoc_html.c, Revision 1.16

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

CVSweb