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

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