[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.20

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