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

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