[BACK]Return to mdoc_html.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/mdoc_html.c, Revision 1.27

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