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

1.7     ! schwarze    1: /*     $Id: mdoc_html.c,v 1.6 2010/01/02 02:42:06 schwarze Exp $ */
1.1       schwarze    2: /*
                      3:  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
                     17: #include <sys/types.h>
                     18:
                     19: #include <assert.h>
                     20: #include <ctype.h>
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: #include <string.h>
                     24: #include <unistd.h>
                     25:
                     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 */
                    199:        {NULL, NULL}, /* Ec */
                    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);
                    386:        buffmt(h, "%s(%d)", m->title, m->msec);
                    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,
                    508:                        "%s(%d)", m->title, m->msec);
                    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:
                    588:        /*
                    589:         * TODO: make sure there are no duplicates, as HTML does not
                    590:         * allow for multiple `id' tags of the same name.
                    591:         */
                    592:
                    593:        PAIR_CLASS_INIT(&tag[0], "sec-head");
                    594:        tag[1].key = ATTR_ID;
1.3       schwarze  595:        tag[1].val = buf;
1.1       schwarze  596:        print_otag(h, TAG_DIV, 2, tag);
                    597:        return(1);
                    598: }
                    599:
                    600:
                    601: /* ARGSUSED */
                    602: static int
                    603: mdoc_ss_pre(MDOC_ARGS)
                    604: {
                    605:        struct htmlpair          tag[3];
                    606:        const struct mdoc_node  *nn;
1.3       schwarze  607:        char                     buf[BUFSIZ];
1.1       schwarze  608:        struct roffsu            su;
                    609:
                    610:        SCALE_VS_INIT(&su, 1);
                    611:
                    612:        if (MDOC_BODY == n->type) {
                    613:                PAIR_CLASS_INIT(&tag[0], "ssec-body");
                    614:                if (n->parent->next && n->child) {
                    615:                        bufcat_su(h, "margin-bottom", &su);
                    616:                        PAIR_STYLE_INIT(&tag[1], h);
                    617:                        print_otag(h, TAG_DIV, 2, tag);
                    618:                } else
                    619:                        print_otag(h, TAG_DIV, 1, tag);
                    620:                return(1);
                    621:        } else if (MDOC_BLOCK == n->type) {
                    622:                PAIR_CLASS_INIT(&tag[0], "ssec-block");
                    623:                if (n->prev) {
                    624:                        bufcat_su(h, "margin-top", &su);
                    625:                        PAIR_STYLE_INIT(&tag[1], h);
                    626:                        print_otag(h, TAG_DIV, 2, tag);
                    627:                } else
                    628:                        print_otag(h, TAG_DIV, 1, tag);
                    629:                return(1);
                    630:        }
                    631:
                    632:        /* TODO: see note in mdoc_sh_pre() about duplicates. */
                    633:
1.3       schwarze  634:        buf[0] = '\0';
1.1       schwarze  635:        for (nn = n->child; nn; nn = nn->next) {
1.3       schwarze  636:                html_idcat(buf, nn->string, BUFSIZ);
1.1       schwarze  637:                if (nn->next)
1.3       schwarze  638:                        html_idcat(buf, " ", BUFSIZ);
1.1       schwarze  639:        }
                    640:
                    641:        SCALE_HS_INIT(&su, INDENT - HALFINDENT);
                    642:        su.scale = -su.scale;
                    643:        bufcat_su(h, "margin-left", &su);
                    644:
                    645:        PAIR_CLASS_INIT(&tag[0], "ssec-head");
                    646:        PAIR_STYLE_INIT(&tag[1], h);
                    647:        tag[2].key = ATTR_ID;
1.3       schwarze  648:        tag[2].val = buf;
1.1       schwarze  649:        print_otag(h, TAG_DIV, 3, tag);
                    650:        return(1);
                    651: }
                    652:
                    653:
                    654: /* ARGSUSED */
                    655: static int
                    656: mdoc_fl_pre(MDOC_ARGS)
                    657: {
                    658:        struct htmlpair  tag;
                    659:
                    660:        PAIR_CLASS_INIT(&tag, "flag");
                    661:        print_otag(h, TAG_SPAN, 1, &tag);
1.6       schwarze  662:
                    663:        /* `Cm' has no leading hyphen. */
                    664:
                    665:        if (MDOC_Cm == n->tok)
                    666:                return(1);
                    667:
                    668:        print_text(h, "\\-");
                    669:
                    670:        /* A blank `Fl' should incur a subsequent space. */
                    671:
                    672:        if (n->child)
1.1       schwarze  673:                h->flags |= HTML_NOSPACE;
1.6       schwarze  674:
1.1       schwarze  675:        return(1);
                    676: }
                    677:
                    678:
                    679: /* ARGSUSED */
                    680: static int
                    681: mdoc_nd_pre(MDOC_ARGS)
                    682: {
                    683:        struct htmlpair  tag;
                    684:
                    685:        if (MDOC_BODY != n->type)
                    686:                return(1);
                    687:
                    688:        /* XXX: this tag in theory can contain block elements. */
                    689:
                    690:        print_text(h, "\\(em");
                    691:        PAIR_CLASS_INIT(&tag, "desc-body");
                    692:        print_otag(h, TAG_SPAN, 1, &tag);
                    693:        return(1);
                    694: }
                    695:
                    696:
                    697: /* ARGSUSED */
                    698: static int
                    699: mdoc_op_pre(MDOC_ARGS)
                    700: {
                    701:        struct htmlpair  tag;
                    702:
                    703:        if (MDOC_BODY != n->type)
                    704:                return(1);
                    705:
                    706:        /* XXX: this tag in theory can contain block elements. */
                    707:
                    708:        print_text(h, "\\(lB");
                    709:        h->flags |= HTML_NOSPACE;
                    710:        PAIR_CLASS_INIT(&tag, "opt");
                    711:        print_otag(h, TAG_SPAN, 1, &tag);
                    712:        return(1);
                    713: }
                    714:
                    715:
                    716: /* ARGSUSED */
                    717: static void
                    718: mdoc_op_post(MDOC_ARGS)
                    719: {
                    720:
                    721:        if (MDOC_BODY != n->type)
                    722:                return;
                    723:        h->flags |= HTML_NOSPACE;
                    724:        print_text(h, "\\(rB");
                    725: }
                    726:
                    727:
                    728: static int
                    729: mdoc_nm_pre(MDOC_ARGS)
                    730: {
                    731:        struct htmlpair tag;
                    732:
1.5       schwarze  733:        if (SEC_SYNOPSIS == n->sec && n->prev) {
                    734:                bufcat_style(h, "clear", "both");
                    735:                PAIR_STYLE_INIT(&tag, h);
                    736:                print_otag(h, TAG_BR, 1, &tag);
                    737:        }
1.1       schwarze  738:
                    739:        PAIR_CLASS_INIT(&tag, "name");
                    740:        print_otag(h, TAG_SPAN, 1, &tag);
                    741:        if (NULL == n->child)
                    742:                print_text(h, m->name);
                    743:
                    744:        return(1);
                    745: }
                    746:
                    747:
                    748: /* ARGSUSED */
                    749: static int
                    750: mdoc_xr_pre(MDOC_ARGS)
                    751: {
                    752:        struct htmlpair          tag[2];
                    753:        const struct mdoc_node  *nn;
                    754:
                    755:        PAIR_CLASS_INIT(&tag[0], "link-man");
                    756:
                    757:        if (h->base_man) {
                    758:                buffmt_man(h, n->child->string,
                    759:                                n->child->next ?
                    760:                                n->child->next->string : NULL);
                    761:                tag[1].key = ATTR_HREF;
                    762:                tag[1].val = h->buf;
                    763:                print_otag(h, TAG_A, 2, tag);
                    764:        } else
                    765:                print_otag(h, TAG_A, 1, tag);
                    766:
                    767:        nn = n->child;
                    768:        print_text(h, nn->string);
                    769:
                    770:        if (NULL == (nn = nn->next))
                    771:                return(0);
                    772:
                    773:        h->flags |= HTML_NOSPACE;
                    774:        print_text(h, "(");
                    775:        h->flags |= HTML_NOSPACE;
                    776:        print_text(h, nn->string);
                    777:        h->flags |= HTML_NOSPACE;
                    778:        print_text(h, ")");
                    779:        return(0);
                    780: }
                    781:
                    782:
                    783: /* ARGSUSED */
                    784: static int
                    785: mdoc_ns_pre(MDOC_ARGS)
                    786: {
                    787:
                    788:        h->flags |= HTML_NOSPACE;
                    789:        return(1);
                    790: }
                    791:
                    792:
                    793: /* ARGSUSED */
                    794: static int
                    795: mdoc_ar_pre(MDOC_ARGS)
                    796: {
                    797:        struct htmlpair tag;
                    798:
                    799:        PAIR_CLASS_INIT(&tag, "arg");
                    800:        print_otag(h, TAG_SPAN, 1, &tag);
                    801:        return(1);
                    802: }
                    803:
                    804:
                    805: /* ARGSUSED */
                    806: static int
                    807: mdoc_xx_pre(MDOC_ARGS)
                    808: {
                    809:        const char      *pp;
                    810:        struct htmlpair  tag;
                    811:
                    812:        switch (n->tok) {
                    813:        case (MDOC_Bsx):
                    814:                pp = "BSDI BSD/OS";
                    815:                break;
                    816:        case (MDOC_Dx):
1.4       schwarze  817:                pp = "DragonFly";
1.1       schwarze  818:                break;
                    819:        case (MDOC_Fx):
                    820:                pp = "FreeBSD";
                    821:                break;
                    822:        case (MDOC_Nx):
                    823:                pp = "NetBSD";
                    824:                break;
                    825:        case (MDOC_Ox):
                    826:                pp = "OpenBSD";
                    827:                break;
                    828:        case (MDOC_Ux):
                    829:                pp = "UNIX";
                    830:                break;
                    831:        default:
                    832:                return(1);
                    833:        }
                    834:
                    835:        PAIR_CLASS_INIT(&tag, "unix");
                    836:        print_otag(h, TAG_SPAN, 1, &tag);
                    837:        print_text(h, pp);
                    838:        return(1);
                    839: }
                    840:
                    841:
                    842: /* ARGSUSED */
                    843: static int
                    844: mdoc_bx_pre(MDOC_ARGS)
                    845: {
                    846:        const struct mdoc_node  *nn;
                    847:        struct htmlpair          tag;
                    848:
                    849:        PAIR_CLASS_INIT(&tag, "unix");
                    850:        print_otag(h, TAG_SPAN, 1, &tag);
                    851:
                    852:        for (nn = n->child; nn; nn = nn->next)
                    853:                print_mdoc_node(m, nn, h);
                    854:
                    855:        if (n->child)
                    856:                h->flags |= HTML_NOSPACE;
                    857:
                    858:        print_text(h, "BSD");
                    859:        return(0);
                    860: }
                    861:
                    862:
                    863: /* ARGSUSED */
                    864: static int
                    865: mdoc_it_block_pre(MDOC_ARGS, int type, int comp,
                    866:                struct roffsu *offs, struct roffsu *width)
                    867: {
                    868:        struct htmlpair          tag;
                    869:        const struct mdoc_node  *nn;
                    870:        struct roffsu            su;
                    871:
                    872:        nn = n->parent->parent;
                    873:        assert(nn->args);
                    874:
                    875:        /* XXX: see notes in mdoc_it_pre(). */
                    876:
                    877:        if (MDOC_Column == type) {
                    878:                /* Don't width-pad on the left. */
                    879:                SCALE_HS_INIT(width, 0);
                    880:                /* Also disallow non-compact. */
                    881:                comp = 1;
                    882:        }
                    883:        if (MDOC_Diag == type)
                    884:                /* Mandate non-compact with empty prior. */
                    885:                if (n->prev && NULL == n->prev->body->child)
                    886:                        comp = 1;
                    887:
                    888:        bufcat_style(h, "clear", "both");
                    889:        if (offs->scale > 0)
                    890:                bufcat_su(h, "margin-left", offs);
                    891:        if (width->scale > 0)
                    892:                bufcat_su(h, "padding-left", width);
                    893:
                    894:        PAIR_STYLE_INIT(&tag, h);
                    895:
                    896:        /* Mandate compact following `Ss' and `Sh' starts. */
                    897:
                    898:        for (nn = n; nn && ! comp; nn = nn->parent) {
                    899:                if (MDOC_BLOCK != nn->type)
                    900:                        continue;
                    901:                if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                    902:                        comp = 1;
                    903:                if (nn->prev)
                    904:                        break;
                    905:        }
                    906:
                    907:        if ( ! comp) {
                    908:                SCALE_VS_INIT(&su, 1);
                    909:                bufcat_su(h, "padding-top", &su);
                    910:        }
                    911:
                    912:        PAIR_STYLE_INIT(&tag, h);
                    913:        print_otag(h, TAG_DIV, 1, &tag);
                    914:        return(1);
                    915: }
                    916:
                    917:
                    918: /* ARGSUSED */
                    919: static int
                    920: mdoc_it_body_pre(MDOC_ARGS, int type)
                    921: {
                    922:        struct htmlpair  tag;
                    923:        struct roffsu    su;
                    924:
                    925:        switch (type) {
                    926:        case (MDOC_Item):
                    927:                /* FALLTHROUGH */
                    928:        case (MDOC_Ohang):
                    929:                /* FALLTHROUGH */
                    930:        case (MDOC_Column):
                    931:                break;
                    932:        default:
                    933:                /*
                    934:                 * XXX: this tricks CSS into aligning the bodies with
                    935:                 * the right-padding in the head.
                    936:                 */
                    937:                SCALE_HS_INIT(&su, 2);
                    938:                bufcat_su(h, "margin-left", &su);
                    939:                PAIR_STYLE_INIT(&tag, h);
                    940:                print_otag(h, TAG_DIV, 1, &tag);
                    941:                break;
                    942:        }
                    943:
                    944:        return(1);
                    945: }
                    946:
                    947:
                    948: /* ARGSUSED */
                    949: static int
                    950: mdoc_it_head_pre(MDOC_ARGS, int type, struct roffsu *width)
                    951: {
                    952:        struct htmlpair  tag;
                    953:        struct ord      *ord;
                    954:        char             nbuf[BUFSIZ];
                    955:
                    956:        switch (type) {
                    957:        case (MDOC_Item):
1.4       schwarze  958:                return(0);
1.1       schwarze  959:        case (MDOC_Ohang):
1.4       schwarze  960:                print_otag(h, TAG_DIV, 0, &tag);
                    961:                return(1);
1.1       schwarze  962:        case (MDOC_Column):
                    963:                bufcat_su(h, "min-width", width);
                    964:                bufcat_style(h, "clear", "none");
                    965:                if (n->next && MDOC_HEAD == n->next->type)
                    966:                        bufcat_style(h, "float", "left");
                    967:                PAIR_STYLE_INIT(&tag, h);
                    968:                print_otag(h, TAG_DIV, 1, &tag);
                    969:                break;
                    970:        default:
                    971:                bufcat_su(h, "min-width", width);
                    972:                SCALE_INVERT(width);
                    973:                bufcat_su(h, "margin-left", width);
                    974:                if (n->next && n->next->child)
                    975:                        bufcat_style(h, "float", "left");
                    976:
                    977:                /* XXX: buffer if we run into body. */
                    978:                SCALE_HS_INIT(width, 1);
                    979:                bufcat_su(h, "margin-right", width);
                    980:                PAIR_STYLE_INIT(&tag, h);
                    981:                print_otag(h, TAG_DIV, 1, &tag);
                    982:                break;
                    983:        }
                    984:
                    985:        switch (type) {
                    986:        case (MDOC_Diag):
                    987:                PAIR_CLASS_INIT(&tag, "diag");
                    988:                print_otag(h, TAG_SPAN, 1, &tag);
                    989:                break;
                    990:        case (MDOC_Enum):
1.2       schwarze  991:                ord = h->ords.head;
1.1       schwarze  992:                assert(ord);
                    993:                nbuf[BUFSIZ - 1] = 0;
                    994:                (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
                    995:                print_text(h, nbuf);
                    996:                return(0);
                    997:        case (MDOC_Dash):
                    998:                print_text(h, "\\(en");
                    999:                return(0);
                   1000:        case (MDOC_Hyphen):
                   1001:                print_text(h, "\\(hy");
                   1002:                return(0);
                   1003:        case (MDOC_Bullet):
                   1004:                print_text(h, "\\(bu");
                   1005:                return(0);
                   1006:        default:
                   1007:                break;
                   1008:        }
                   1009:
                   1010:        return(1);
                   1011: }
                   1012:
                   1013:
                   1014: static int
                   1015: mdoc_it_pre(MDOC_ARGS)
                   1016: {
                   1017:        int                      i, type, wp, comp;
                   1018:        const struct mdoc_node  *bl, *nn;
                   1019:        struct roffsu            width, offs;
                   1020:
                   1021:        /*
                   1022:         * XXX: be very careful in changing anything, here.  Lists in
                   1023:         * mandoc have many peculiarities; furthermore, they don't
                   1024:         * translate well into HTML and require a bit of mangling.
                   1025:         */
                   1026:
                   1027:        bl = n->parent->parent;
                   1028:        if (MDOC_BLOCK != n->type)
                   1029:                bl = bl->parent;
                   1030:
                   1031:        type = a2list(bl);
                   1032:
                   1033:        /* Set default width and offset. */
                   1034:
                   1035:        SCALE_HS_INIT(&offs, 0);
                   1036:
                   1037:        switch (type) {
                   1038:        case (MDOC_Enum):
                   1039:                /* FALLTHROUGH */
                   1040:        case (MDOC_Dash):
                   1041:                /* FALLTHROUGH */
                   1042:        case (MDOC_Hyphen):
                   1043:                /* FALLTHROUGH */
                   1044:        case (MDOC_Bullet):
                   1045:                SCALE_HS_INIT(&width, 2);
                   1046:                break;
                   1047:        default:
                   1048:                SCALE_HS_INIT(&width, INDENT);
                   1049:                break;
                   1050:        }
                   1051:
                   1052:        /* Get width, offset, and compact arguments. */
                   1053:
                   1054:        for (wp = -1, comp = i = 0; i < (int)bl->args->argc; i++)
                   1055:                switch (bl->args->argv[i].arg) {
                   1056:                case (MDOC_Column):
                   1057:                        wp = i; /* Save for later. */
                   1058:                        break;
                   1059:                case (MDOC_Width):
                   1060:                        a2width(bl->args->argv[i].value[0], &width);
                   1061:                        break;
                   1062:                case (MDOC_Offset):
                   1063:                        a2offs(bl->args->argv[i].value[0], &offs);
                   1064:                        break;
                   1065:                case (MDOC_Compact):
                   1066:                        comp = 1;
                   1067:                        break;
                   1068:                default:
                   1069:                        break;
                   1070:                }
                   1071:
                   1072:        /* Override width in some cases. */
                   1073:
                   1074:        switch (type) {
1.4       schwarze 1075:        case (MDOC_Ohang):
                   1076:                /* FALLTHROUGH */
1.1       schwarze 1077:        case (MDOC_Item):
                   1078:                /* FALLTHROUGH */
                   1079:        case (MDOC_Inset):
                   1080:                /* FALLTHROUGH */
                   1081:        case (MDOC_Diag):
                   1082:                SCALE_HS_INIT(&width, 0);
                   1083:                break;
                   1084:        default:
                   1085:                if (0 == width.scale)
                   1086:                        SCALE_HS_INIT(&width, INDENT);
                   1087:                break;
                   1088:        }
                   1089:
                   1090:        /* Flip to body/block processing. */
                   1091:
                   1092:        if (MDOC_BODY == n->type)
                   1093:                return(mdoc_it_body_pre(m, n, h, type));
                   1094:        if (MDOC_BLOCK == n->type)
                   1095:                return(mdoc_it_block_pre(m, n, h, type, comp,
                   1096:                                        &offs, &width));
                   1097:
                   1098:        /* Override column widths. */
                   1099:
                   1100:        if (MDOC_Column == type) {
                   1101:                nn = n->parent->child;
                   1102:                for (i = 0; nn && nn != n; nn = nn->next, i++)
                   1103:                        /* Counter... */ ;
                   1104:                if (i < (int)bl->args->argv[wp].sz)
                   1105:                        a2width(bl->args->argv[wp].value[i], &width);
                   1106:        }
                   1107:
                   1108:        return(mdoc_it_head_pre(m, n, h, type, &width));
                   1109: }
                   1110:
                   1111:
                   1112: /* ARGSUSED */
                   1113: static int
                   1114: mdoc_bl_pre(MDOC_ARGS)
                   1115: {
                   1116:        struct ord      *ord;
                   1117:
                   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:
                   1288:        SCALE_VS_INIT(&su, INDENT - 2);
                   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:
                   1305:        /* FIXME: duplicates? */
                   1306:
1.3       schwarze 1307:        strlcpy(buf, "#", BUFSIZ);
1.1       schwarze 1308:        for (nn = n->child; nn; nn = nn->next) {
1.3       schwarze 1309:                html_idcat(buf, nn->string, BUFSIZ);
1.1       schwarze 1310:                if (nn->next)
1.3       schwarze 1311:                        html_idcat(buf, " ", BUFSIZ);
1.1       schwarze 1312:        }
                   1313:
                   1314:        PAIR_CLASS_INIT(&tag[0], "link-sec");
                   1315:        tag[1].key = ATTR_HREF;
                   1316:        tag[1].val = buf;
                   1317:
                   1318:        print_otag(h, TAG_A, 2, tag);
                   1319:        return(1);
                   1320: }
                   1321:
                   1322:
                   1323: /* ARGSUSED */
                   1324: static int
                   1325: mdoc_aq_pre(MDOC_ARGS)
                   1326: {
                   1327:
                   1328:        if (MDOC_BODY != n->type)
                   1329:                return(1);
                   1330:        print_text(h, "\\(la");
                   1331:        h->flags |= HTML_NOSPACE;
                   1332:        return(1);
                   1333: }
                   1334:
                   1335:
                   1336: /* ARGSUSED */
                   1337: static void
                   1338: mdoc_aq_post(MDOC_ARGS)
                   1339: {
                   1340:
                   1341:        if (MDOC_BODY != n->type)
                   1342:                return;
                   1343:        h->flags |= HTML_NOSPACE;
                   1344:        print_text(h, "\\(ra");
                   1345: }
                   1346:
                   1347:
                   1348: /* ARGSUSED */
                   1349: static int
                   1350: mdoc_bd_pre(MDOC_ARGS)
                   1351: {
                   1352:        struct htmlpair          tag[2];
                   1353:        int                      type, comp, i;
                   1354:        const struct mdoc_node  *bl, *nn;
                   1355:        struct roffsu            su;
                   1356:
                   1357:        if (MDOC_BLOCK == n->type)
                   1358:                bl = n;
                   1359:        else if (MDOC_HEAD == n->type)
                   1360:                return(0);
                   1361:        else
                   1362:                bl = n->parent;
                   1363:
                   1364:        SCALE_VS_INIT(&su, 0);
                   1365:
                   1366:        type = comp = 0;
                   1367:        for (i = 0; i < (int)bl->args->argc; i++)
                   1368:                switch (bl->args->argv[i].arg) {
                   1369:                case (MDOC_Offset):
                   1370:                        a2offs(bl->args->argv[i].value[0], &su);
                   1371:                        break;
                   1372:                case (MDOC_Compact):
                   1373:                        comp = 1;
                   1374:                        break;
                   1375:                case (MDOC_Centred):
                   1376:                        /* FALLTHROUGH */
                   1377:                case (MDOC_Ragged):
                   1378:                        /* FALLTHROUGH */
                   1379:                case (MDOC_Filled):
                   1380:                        /* FALLTHROUGH */
                   1381:                case (MDOC_Unfilled):
                   1382:                        /* FALLTHROUGH */
                   1383:                case (MDOC_Literal):
                   1384:                        type = bl->args->argv[i].arg;
                   1385:                        break;
                   1386:                default:
                   1387:                        break;
                   1388:                }
                   1389:
                   1390:        /* FIXME: -centered, etc. formatting. */
                   1391:
                   1392:        if (MDOC_BLOCK == n->type) {
                   1393:                bufcat_su(h, "margin-left", &su);
                   1394:                for (nn = n; nn && ! comp; nn = nn->parent) {
                   1395:                        if (MDOC_BLOCK != nn->type)
                   1396:                                continue;
                   1397:                        if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
                   1398:                                comp = 1;
                   1399:                        if (nn->prev)
                   1400:                                break;
                   1401:                }
                   1402:                if (comp) {
                   1403:                        print_otag(h, TAG_DIV, 0, tag);
                   1404:                        return(1);
                   1405:                }
                   1406:                SCALE_VS_INIT(&su, 1);
                   1407:                bufcat_su(h, "margin-top", &su);
                   1408:                PAIR_STYLE_INIT(&tag[0], h);
                   1409:                print_otag(h, TAG_DIV, 1, tag);
                   1410:                return(1);
                   1411:        }
                   1412:
                   1413:        if (MDOC_Unfilled != type && MDOC_Literal != type)
                   1414:                return(1);
                   1415:
                   1416:        PAIR_CLASS_INIT(&tag[0], "lit");
                   1417:        bufcat_style(h, "white-space", "pre");
                   1418:        PAIR_STYLE_INIT(&tag[1], h);
                   1419:        print_otag(h, TAG_DIV, 2, tag);
                   1420:
                   1421:        for (nn = n->child; nn; nn = nn->next) {
                   1422:                h->flags |= HTML_NOSPACE;
                   1423:                print_mdoc_node(m, nn, h);
                   1424:                if (NULL == nn->next)
                   1425:                        continue;
                   1426:                if (nn->prev && nn->prev->line < nn->line)
                   1427:                        print_text(h, "\n");
                   1428:                else if (NULL == nn->prev)
                   1429:                        print_text(h, "\n");
                   1430:        }
                   1431:
                   1432:        return(0);
                   1433: }
                   1434:
                   1435:
                   1436: /* ARGSUSED */
                   1437: static int
                   1438: mdoc_pa_pre(MDOC_ARGS)
                   1439: {
                   1440:        struct htmlpair tag;
                   1441:
                   1442:        PAIR_CLASS_INIT(&tag, "file");
                   1443:        print_otag(h, TAG_SPAN, 1, &tag);
                   1444:        return(1);
                   1445: }
                   1446:
                   1447:
                   1448: /* ARGSUSED */
                   1449: static int
                   1450: mdoc_ad_pre(MDOC_ARGS)
                   1451: {
                   1452:        struct htmlpair tag;
                   1453:
                   1454:        PAIR_CLASS_INIT(&tag, "addr");
                   1455:        print_otag(h, TAG_SPAN, 1, &tag);
                   1456:        return(1);
                   1457: }
                   1458:
                   1459:
                   1460: /* ARGSUSED */
                   1461: static int
                   1462: mdoc_an_pre(MDOC_ARGS)
                   1463: {
                   1464:        struct htmlpair tag;
                   1465:
                   1466:        /* TODO: -split and -nosplit (see termp_an_pre()). */
                   1467:
                   1468:        PAIR_CLASS_INIT(&tag, "author");
                   1469:        print_otag(h, TAG_SPAN, 1, &tag);
                   1470:        return(1);
                   1471: }
                   1472:
                   1473:
                   1474: /* ARGSUSED */
                   1475: static int
                   1476: mdoc_cd_pre(MDOC_ARGS)
                   1477: {
                   1478:        struct htmlpair tag;
                   1479:
                   1480:        print_otag(h, TAG_DIV, 0, NULL);
                   1481:        PAIR_CLASS_INIT(&tag, "config");
                   1482:        print_otag(h, TAG_SPAN, 1, &tag);
                   1483:        return(1);
                   1484: }
                   1485:
                   1486:
                   1487: /* ARGSUSED */
                   1488: static int
                   1489: mdoc_dv_pre(MDOC_ARGS)
                   1490: {
                   1491:        struct htmlpair tag;
                   1492:
                   1493:        PAIR_CLASS_INIT(&tag, "define");
                   1494:        print_otag(h, TAG_SPAN, 1, &tag);
                   1495:        return(1);
                   1496: }
                   1497:
                   1498:
                   1499: /* ARGSUSED */
                   1500: static int
                   1501: mdoc_ev_pre(MDOC_ARGS)
                   1502: {
                   1503:        struct htmlpair tag;
                   1504:
                   1505:        PAIR_CLASS_INIT(&tag, "env");
                   1506:        print_otag(h, TAG_SPAN, 1, &tag);
                   1507:        return(1);
                   1508: }
                   1509:
                   1510:
                   1511: /* ARGSUSED */
                   1512: static int
                   1513: mdoc_er_pre(MDOC_ARGS)
                   1514: {
                   1515:        struct htmlpair tag;
                   1516:
                   1517:        PAIR_CLASS_INIT(&tag, "errno");
                   1518:        print_otag(h, TAG_SPAN, 1, &tag);
                   1519:        return(1);
                   1520: }
                   1521:
                   1522:
                   1523: /* ARGSUSED */
                   1524: static int
                   1525: mdoc_fa_pre(MDOC_ARGS)
                   1526: {
                   1527:        const struct mdoc_node  *nn;
                   1528:        struct htmlpair          tag;
                   1529:        struct tag              *t;
                   1530:
                   1531:        PAIR_CLASS_INIT(&tag, "farg");
                   1532:        if (n->parent->tok != MDOC_Fo) {
                   1533:                print_otag(h, TAG_SPAN, 1, &tag);
                   1534:                return(1);
                   1535:        }
                   1536:
                   1537:        for (nn = n->child; nn; nn = nn->next) {
                   1538:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1539:                print_text(h, nn->string);
                   1540:                print_tagq(h, t);
                   1541:                if (nn->next)
                   1542:                        print_text(h, ",");
                   1543:        }
                   1544:
                   1545:        if (n->child && n->next && n->next->tok == MDOC_Fa)
                   1546:                print_text(h, ",");
                   1547:
                   1548:        return(0);
                   1549: }
                   1550:
                   1551:
                   1552: /* ARGSUSED */
                   1553: static int
                   1554: mdoc_fd_pre(MDOC_ARGS)
                   1555: {
                   1556:        struct htmlpair  tag;
                   1557:        struct roffsu    su;
                   1558:
                   1559:        if (SEC_SYNOPSIS == n->sec) {
                   1560:                if (n->next && MDOC_Fd != n->next->tok) {
                   1561:                        SCALE_VS_INIT(&su, 1);
                   1562:                        bufcat_su(h, "margin-bottom", &su);
                   1563:                        PAIR_STYLE_INIT(&tag, h);
                   1564:                        print_otag(h, TAG_DIV, 1, &tag);
                   1565:                } else
                   1566:                        print_otag(h, TAG_DIV, 0, NULL);
                   1567:        }
                   1568:
                   1569:        PAIR_CLASS_INIT(&tag, "macro");
                   1570:        print_otag(h, TAG_SPAN, 1, &tag);
                   1571:        return(1);
                   1572: }
                   1573:
                   1574:
                   1575: /* ARGSUSED */
                   1576: static int
                   1577: mdoc_vt_pre(MDOC_ARGS)
                   1578: {
                   1579:        struct htmlpair  tag;
                   1580:        struct roffsu    su;
                   1581:
1.7     ! schwarze 1582:        if (MDOC_BLOCK == n->type) {
1.6       schwarze 1583:                if (n->prev && MDOC_Vt != n->prev->tok) {
1.1       schwarze 1584:                        SCALE_VS_INIT(&su, 1);
1.6       schwarze 1585:                        bufcat_su(h, "margin-top", &su);
1.1       schwarze 1586:                        PAIR_STYLE_INIT(&tag, h);
                   1587:                        print_otag(h, TAG_DIV, 1, &tag);
                   1588:                } else
                   1589:                        print_otag(h, TAG_DIV, 0, NULL);
1.7     ! schwarze 1590:
        !          1591:                return(1);
        !          1592:        } else if (MDOC_HEAD == n->type)
        !          1593:                return(0);
1.1       schwarze 1594:
                   1595:        PAIR_CLASS_INIT(&tag, "type");
                   1596:        print_otag(h, TAG_SPAN, 1, &tag);
                   1597:        return(1);
                   1598: }
                   1599:
                   1600:
                   1601: /* ARGSUSED */
                   1602: static int
                   1603: mdoc_ft_pre(MDOC_ARGS)
                   1604: {
                   1605:        struct htmlpair  tag;
                   1606:        struct roffsu    su;
                   1607:
                   1608:        if (SEC_SYNOPSIS == n->sec) {
                   1609:                if (n->prev && MDOC_Fo == n->prev->tok) {
                   1610:                        SCALE_VS_INIT(&su, 1);
                   1611:                        bufcat_su(h, "margin-top", &su);
                   1612:                        PAIR_STYLE_INIT(&tag, h);
                   1613:                        print_otag(h, TAG_DIV, 1, &tag);
                   1614:                } else
                   1615:                        print_otag(h, TAG_DIV, 0, NULL);
                   1616:        }
                   1617:
                   1618:        PAIR_CLASS_INIT(&tag, "ftype");
                   1619:        print_otag(h, TAG_SPAN, 1, &tag);
                   1620:        return(1);
                   1621: }
                   1622:
                   1623:
                   1624: /* ARGSUSED */
                   1625: static int
                   1626: mdoc_fn_pre(MDOC_ARGS)
                   1627: {
                   1628:        struct tag              *t;
                   1629:        struct htmlpair          tag[2];
                   1630:        const struct mdoc_node  *nn;
                   1631:        char                     nbuf[BUFSIZ];
                   1632:        const char              *sp, *ep;
                   1633:        int                      sz, i;
                   1634:        struct roffsu            su;
                   1635:
                   1636:        if (SEC_SYNOPSIS == n->sec) {
                   1637:                SCALE_HS_INIT(&su, INDENT);
                   1638:                bufcat_su(h, "margin-left", &su);
                   1639:                su.scale = -su.scale;
                   1640:                bufcat_su(h, "text-indent", &su);
                   1641:                if (n->next) {
                   1642:                        SCALE_VS_INIT(&su, 1);
                   1643:                        bufcat_su(h, "margin-bottom", &su);
                   1644:                }
                   1645:                PAIR_STYLE_INIT(&tag[0], h);
                   1646:                print_otag(h, TAG_DIV, 1, tag);
                   1647:        }
                   1648:
                   1649:        /* Split apart into type and name. */
                   1650:        assert(n->child->string);
                   1651:        sp = n->child->string;
                   1652:
                   1653:        ep = strchr(sp, ' ');
                   1654:        if (NULL != ep) {
                   1655:                PAIR_CLASS_INIT(&tag[0], "ftype");
                   1656:                t = print_otag(h, TAG_SPAN, 1, tag);
                   1657:
                   1658:                while (ep) {
                   1659:                        sz = MIN((int)(ep - sp), BUFSIZ - 1);
                   1660:                        (void)memcpy(nbuf, sp, (size_t)sz);
                   1661:                        nbuf[sz] = '\0';
                   1662:                        print_text(h, nbuf);
                   1663:                        sp = ++ep;
                   1664:                        ep = strchr(sp, ' ');
                   1665:                }
                   1666:                print_tagq(h, t);
                   1667:        }
                   1668:
                   1669:        PAIR_CLASS_INIT(&tag[0], "fname");
                   1670:        t = print_otag(h, TAG_SPAN, 1, tag);
                   1671:
                   1672:        if (sp) {
                   1673:                (void)strlcpy(nbuf, sp, BUFSIZ);
                   1674:                print_text(h, nbuf);
                   1675:        }
                   1676:
                   1677:        print_tagq(h, t);
                   1678:
                   1679:        h->flags |= HTML_NOSPACE;
                   1680:        print_text(h, "(");
                   1681:
                   1682:        bufinit(h);
                   1683:        PAIR_CLASS_INIT(&tag[0], "farg");
                   1684:        bufcat_style(h, "white-space", "nowrap");
                   1685:        PAIR_STYLE_INIT(&tag[1], h);
                   1686:
                   1687:        for (nn = n->child->next; nn; nn = nn->next) {
                   1688:                i = 1;
                   1689:                if (SEC_SYNOPSIS == n->sec)
                   1690:                        i = 2;
                   1691:                t = print_otag(h, TAG_SPAN, i, tag);
                   1692:                print_text(h, nn->string);
                   1693:                print_tagq(h, t);
                   1694:                if (nn->next)
                   1695:                        print_text(h, ",");
                   1696:        }
                   1697:
                   1698:        print_text(h, ")");
                   1699:        if (SEC_SYNOPSIS == n->sec)
                   1700:                print_text(h, ";");
                   1701:
                   1702:        return(0);
                   1703: }
                   1704:
                   1705:
                   1706: /* ARGSUSED */
                   1707: static int
                   1708: mdoc_sp_pre(MDOC_ARGS)
                   1709: {
                   1710:        int              len;
                   1711:        struct htmlpair  tag;
                   1712:        struct roffsu    su;
                   1713:
                   1714:        switch (n->tok) {
                   1715:        case (MDOC_sp):
                   1716:                /* FIXME: can this have a scaling indicator? */
                   1717:                len = n->child ? atoi(n->child->string) : 1;
                   1718:                break;
                   1719:        case (MDOC_br):
                   1720:                len = 0;
                   1721:                break;
                   1722:        default:
                   1723:                len = 1;
                   1724:                break;
                   1725:        }
                   1726:
                   1727:        SCALE_VS_INIT(&su, len);
                   1728:        bufcat_su(h, "height", &su);
                   1729:        PAIR_STYLE_INIT(&tag, h);
                   1730:        print_otag(h, TAG_DIV, 1, &tag);
1.3       schwarze 1731:        /* So the div isn't empty: */
                   1732:        print_text(h, "\\~");
                   1733:
                   1734:        return(0);
1.1       schwarze 1735:
                   1736: }
                   1737:
                   1738:
                   1739: /* ARGSUSED */
                   1740: static int
                   1741: mdoc_brq_pre(MDOC_ARGS)
                   1742: {
                   1743:
                   1744:        if (MDOC_BODY != n->type)
                   1745:                return(1);
                   1746:        print_text(h, "\\(lC");
                   1747:        h->flags |= HTML_NOSPACE;
                   1748:        return(1);
                   1749: }
                   1750:
                   1751:
                   1752: /* ARGSUSED */
                   1753: static void
                   1754: mdoc_brq_post(MDOC_ARGS)
                   1755: {
                   1756:
                   1757:        if (MDOC_BODY != n->type)
                   1758:                return;
                   1759:        h->flags |= HTML_NOSPACE;
                   1760:        print_text(h, "\\(rC");
                   1761: }
                   1762:
                   1763:
                   1764: /* ARGSUSED */
                   1765: static int
                   1766: mdoc_lk_pre(MDOC_ARGS)
                   1767: {
                   1768:        const struct mdoc_node  *nn;
                   1769:        struct htmlpair          tag[2];
                   1770:
                   1771:        nn = n->child;
                   1772:
                   1773:        PAIR_CLASS_INIT(&tag[0], "link-ext");
                   1774:        tag[1].key = ATTR_HREF;
                   1775:        tag[1].val = nn->string;
                   1776:        print_otag(h, TAG_A, 2, tag);
                   1777:
1.2       schwarze 1778:        if (NULL == nn->next)
                   1779:                return(1);
                   1780:
1.1       schwarze 1781:        for (nn = nn->next; nn; nn = nn->next)
                   1782:                print_text(h, nn->string);
                   1783:
                   1784:        return(0);
                   1785: }
                   1786:
                   1787:
                   1788: /* ARGSUSED */
                   1789: static int
                   1790: mdoc_mt_pre(MDOC_ARGS)
                   1791: {
                   1792:        struct htmlpair          tag[2];
                   1793:        struct tag              *t;
                   1794:        const struct mdoc_node  *nn;
                   1795:
                   1796:        PAIR_CLASS_INIT(&tag[0], "link-mail");
                   1797:
                   1798:        for (nn = n->child; nn; nn = nn->next) {
                   1799:                bufinit(h);
                   1800:                bufcat(h, "mailto:");
                   1801:                bufcat(h, nn->string);
                   1802:                PAIR_STYLE_INIT(&tag[1], h);
                   1803:                t = print_otag(h, TAG_A, 2, tag);
                   1804:                print_text(h, nn->string);
                   1805:                print_tagq(h, t);
                   1806:        }
                   1807:
                   1808:        return(0);
                   1809: }
                   1810:
                   1811:
                   1812: /* ARGSUSED */
                   1813: static int
                   1814: mdoc_fo_pre(MDOC_ARGS)
                   1815: {
                   1816:        struct htmlpair tag;
                   1817:
                   1818:        if (MDOC_BODY == n->type) {
                   1819:                h->flags |= HTML_NOSPACE;
                   1820:                print_text(h, "(");
                   1821:                h->flags |= HTML_NOSPACE;
                   1822:                return(1);
                   1823:        } else if (MDOC_BLOCK == n->type)
                   1824:                return(1);
                   1825:
                   1826:        PAIR_CLASS_INIT(&tag, "fname");
                   1827:        print_otag(h, TAG_SPAN, 1, &tag);
                   1828:        return(1);
                   1829: }
                   1830:
                   1831:
                   1832: /* ARGSUSED */
                   1833: static void
                   1834: mdoc_fo_post(MDOC_ARGS)
                   1835: {
                   1836:        if (MDOC_BODY != n->type)
                   1837:                return;
                   1838:        h->flags |= HTML_NOSPACE;
                   1839:        print_text(h, ")");
                   1840:        h->flags |= HTML_NOSPACE;
                   1841:        print_text(h, ";");
                   1842: }
                   1843:
                   1844:
                   1845: /* ARGSUSED */
                   1846: static int
                   1847: mdoc_in_pre(MDOC_ARGS)
                   1848: {
                   1849:        const struct mdoc_node  *nn;
                   1850:        struct tag              *t;
                   1851:        struct htmlpair          tag[2];
                   1852:        int                      i;
                   1853:        struct roffsu            su;
                   1854:
                   1855:        if (SEC_SYNOPSIS == n->sec) {
                   1856:                if (n->next && MDOC_In != n->next->tok) {
                   1857:                        SCALE_VS_INIT(&su, 1);
                   1858:                        bufcat_su(h, "margin-bottom", &su);
                   1859:                        PAIR_STYLE_INIT(&tag[0], h);
                   1860:                        print_otag(h, TAG_DIV, 1, tag);
                   1861:                } else
                   1862:                        print_otag(h, TAG_DIV, 0, NULL);
                   1863:        }
                   1864:
                   1865:        /* FIXME: there's a buffer bug in here somewhere. */
                   1866:
                   1867:        PAIR_CLASS_INIT(&tag[0], "includes");
                   1868:        print_otag(h, TAG_SPAN, 1, tag);
                   1869:
                   1870:        if (SEC_SYNOPSIS == n->sec)
                   1871:                print_text(h, "#include");
                   1872:
                   1873:        print_text(h, "<");
                   1874:        h->flags |= HTML_NOSPACE;
                   1875:
                   1876:        /* XXX -- see warning in termp_in_post(). */
                   1877:
                   1878:        for (nn = n->child; nn; nn = nn->next) {
                   1879:                PAIR_CLASS_INIT(&tag[0], "link-includes");
                   1880:                i = 1;
1.3       schwarze 1881:                bufinit(h);
1.1       schwarze 1882:                if (h->base_includes) {
                   1883:                        buffmt_includes(h, nn->string);
                   1884:                        tag[i].key = ATTR_HREF;
                   1885:                        tag[i++].val = h->buf;
                   1886:                }
                   1887:                t = print_otag(h, TAG_A, i, tag);
                   1888:                print_mdoc_node(m, nn, h);
                   1889:                print_tagq(h, t);
                   1890:        }
                   1891:
                   1892:        h->flags |= HTML_NOSPACE;
                   1893:        print_text(h, ">");
                   1894:
                   1895:        return(0);
                   1896: }
                   1897:
                   1898:
                   1899: /* ARGSUSED */
                   1900: static int
                   1901: mdoc_ic_pre(MDOC_ARGS)
                   1902: {
                   1903:        struct htmlpair tag;
                   1904:
                   1905:        PAIR_CLASS_INIT(&tag, "cmd");
                   1906:        print_otag(h, TAG_SPAN, 1, &tag);
                   1907:        return(1);
                   1908: }
                   1909:
                   1910:
                   1911: /* ARGSUSED */
                   1912: static int
                   1913: mdoc_rv_pre(MDOC_ARGS)
                   1914: {
                   1915:        const struct mdoc_node  *nn;
                   1916:        struct htmlpair          tag;
                   1917:        struct tag              *t;
                   1918:
                   1919:        print_otag(h, TAG_DIV, 0, NULL);
                   1920:        print_text(h, "The");
                   1921:
                   1922:        for (nn = n->child; nn; nn = nn->next) {
                   1923:                PAIR_CLASS_INIT(&tag, "fname");
                   1924:                t = print_otag(h, TAG_SPAN, 1, &tag);
                   1925:                print_text(h, nn->string);
                   1926:                print_tagq(h, t);
                   1927:
                   1928:                h->flags |= HTML_NOSPACE;
                   1929:                if (nn->next && NULL == nn->next->next)
                   1930:                        print_text(h, "(), and");
                   1931:                else if (nn->next)
                   1932:                        print_text(h, "(),");
                   1933:                else
                   1934:                        print_text(h, "()");
                   1935:        }
                   1936:
                   1937:        if (n->child->next)
                   1938:                print_text(h, "functions return");
                   1939:        else
                   1940:                print_text(h, "function returns");
                   1941:
                   1942:                print_text(h, "the value 0 if successful; otherwise the value "
                   1943:                        "-1 is returned and the global variable");
                   1944:
                   1945:        PAIR_CLASS_INIT(&tag, "var");
                   1946:        t = print_otag(h, TAG_SPAN, 1, &tag);
                   1947:        print_text(h, "errno");
                   1948:        print_tagq(h, t);
                   1949:                print_text(h, "is set to indicate the error.");
                   1950:        return(0);
                   1951: }
                   1952:
                   1953:
                   1954: /* ARGSUSED */
                   1955: static int
                   1956: mdoc_va_pre(MDOC_ARGS)
                   1957: {
                   1958:        struct htmlpair tag;
                   1959:
                   1960:        PAIR_CLASS_INIT(&tag, "var");
                   1961:        print_otag(h, TAG_SPAN, 1, &tag);
                   1962:        return(1);
                   1963: }
                   1964:
                   1965:
                   1966: /* ARGSUSED */
                   1967: static int
                   1968: mdoc_bq_pre(MDOC_ARGS)
                   1969: {
                   1970:
                   1971:        if (MDOC_BODY != n->type)
                   1972:                return(1);
                   1973:        print_text(h, "\\(lB");
                   1974:        h->flags |= HTML_NOSPACE;
                   1975:        return(1);
                   1976: }
                   1977:
                   1978:
                   1979: /* ARGSUSED */
                   1980: static void
                   1981: mdoc_bq_post(MDOC_ARGS)
                   1982: {
                   1983:
                   1984:        if (MDOC_BODY != n->type)
                   1985:                return;
                   1986:        h->flags |= HTML_NOSPACE;
                   1987:        print_text(h, "\\(rB");
                   1988: }
                   1989:
                   1990:
                   1991: /* ARGSUSED */
                   1992: static int
                   1993: mdoc_ap_pre(MDOC_ARGS)
                   1994: {
                   1995:
                   1996:        h->flags |= HTML_NOSPACE;
                   1997:        print_text(h, "\\(aq");
                   1998:        h->flags |= HTML_NOSPACE;
                   1999:        return(1);
                   2000: }
                   2001:
                   2002:
                   2003: /* ARGSUSED */
                   2004: static int
                   2005: mdoc_bf_pre(MDOC_ARGS)
                   2006: {
                   2007:        int              i;
                   2008:        struct htmlpair  tag[2];
                   2009:        struct roffsu    su;
                   2010:
                   2011:        if (MDOC_HEAD == n->type)
                   2012:                return(0);
                   2013:        else if (MDOC_BLOCK != n->type)
                   2014:                return(1);
                   2015:
                   2016:        PAIR_CLASS_INIT(&tag[0], "lit");
                   2017:
                   2018:        if (n->head->child) {
                   2019:                if ( ! strcmp("Em", n->head->child->string))
                   2020:                        PAIR_CLASS_INIT(&tag[0], "emph");
                   2021:                else if ( ! strcmp("Sy", n->head->child->string))
                   2022:                        PAIR_CLASS_INIT(&tag[0], "symb");
                   2023:                else if ( ! strcmp("Li", n->head->child->string))
                   2024:                        PAIR_CLASS_INIT(&tag[0], "lit");
                   2025:        } else {
                   2026:                assert(n->args);
                   2027:                for (i = 0; i < (int)n->args->argc; i++)
                   2028:                        switch (n->args->argv[i].arg) {
                   2029:                        case (MDOC_Symbolic):
                   2030:                                PAIR_CLASS_INIT(&tag[0], "symb");
                   2031:                                break;
                   2032:                        case (MDOC_Literal):
                   2033:                                PAIR_CLASS_INIT(&tag[0], "lit");
                   2034:                                break;
                   2035:                        case (MDOC_Emphasis):
                   2036:                                PAIR_CLASS_INIT(&tag[0], "emph");
                   2037:                                break;
                   2038:                        default:
                   2039:                                break;
                   2040:                        }
                   2041:        }
                   2042:
                   2043:        /* FIXME: div's have spaces stripped--we want them. */
                   2044:
                   2045:        bufcat_style(h, "display", "inline");
                   2046:        SCALE_HS_INIT(&su, 1);
                   2047:        bufcat_su(h, "margin-right", &su);
                   2048:        PAIR_STYLE_INIT(&tag[1], h);
                   2049:        print_otag(h, TAG_DIV, 2, tag);
                   2050:        return(1);
                   2051: }
                   2052:
                   2053:
                   2054: /* ARGSUSED */
                   2055: static int
                   2056: mdoc_ms_pre(MDOC_ARGS)
                   2057: {
                   2058:        struct htmlpair tag;
                   2059:
                   2060:        PAIR_CLASS_INIT(&tag, "symb");
                   2061:        print_otag(h, TAG_SPAN, 1, &tag);
                   2062:        return(1);
                   2063: }
                   2064:
                   2065:
                   2066: /* ARGSUSED */
                   2067: static int
                   2068: mdoc_pf_pre(MDOC_ARGS)
                   2069: {
                   2070:
                   2071:        h->flags |= HTML_IGNDELIM;
                   2072:        return(1);
                   2073: }
                   2074:
                   2075:
                   2076: /* ARGSUSED */
                   2077: static void
                   2078: mdoc_pf_post(MDOC_ARGS)
                   2079: {
                   2080:
                   2081:        h->flags &= ~HTML_IGNDELIM;
                   2082:        h->flags |= HTML_NOSPACE;
                   2083: }
                   2084:
                   2085:
                   2086: /* ARGSUSED */
                   2087: static int
                   2088: mdoc_rs_pre(MDOC_ARGS)
                   2089: {
                   2090:        struct htmlpair  tag;
                   2091:        struct roffsu    su;
                   2092:
                   2093:        if (MDOC_BLOCK != n->type)
                   2094:                return(1);
                   2095:
                   2096:        if (n->prev && SEC_SEE_ALSO == n->sec) {
                   2097:                SCALE_VS_INIT(&su, 1);
                   2098:                bufcat_su(h, "margin-top", &su);
                   2099:                PAIR_STYLE_INIT(&tag, h);
                   2100:                print_otag(h, TAG_DIV, 1, &tag);
                   2101:        }
                   2102:
                   2103:        PAIR_CLASS_INIT(&tag, "ref");
                   2104:        print_otag(h, TAG_SPAN, 1, &tag);
                   2105:        return(1);
                   2106: }
                   2107:
                   2108:
                   2109:
                   2110: /* ARGSUSED */
                   2111: static int
                   2112: mdoc_li_pre(MDOC_ARGS)
                   2113: {
                   2114:        struct htmlpair tag;
                   2115:
                   2116:        PAIR_CLASS_INIT(&tag, "lit");
                   2117:        print_otag(h, TAG_SPAN, 1, &tag);
                   2118:        return(1);
                   2119: }
                   2120:
                   2121:
                   2122: /* ARGSUSED */
                   2123: static int
                   2124: mdoc_sy_pre(MDOC_ARGS)
                   2125: {
                   2126:        struct htmlpair tag;
                   2127:
                   2128:        PAIR_CLASS_INIT(&tag, "symb");
                   2129:        print_otag(h, TAG_SPAN, 1, &tag);
                   2130:        return(1);
                   2131: }
                   2132:
                   2133:
                   2134: /* ARGSUSED */
                   2135: static int
                   2136: mdoc_bt_pre(MDOC_ARGS)
                   2137: {
                   2138:
                   2139:        print_text(h, "is currently in beta test.");
                   2140:        return(0);
                   2141: }
                   2142:
                   2143:
                   2144: /* ARGSUSED */
                   2145: static int
                   2146: mdoc_ud_pre(MDOC_ARGS)
                   2147: {
                   2148:
                   2149:        print_text(h, "currently under development.");
                   2150:        return(0);
                   2151: }
                   2152:
                   2153:
                   2154: /* ARGSUSED */
                   2155: static int
                   2156: mdoc_lb_pre(MDOC_ARGS)
                   2157: {
                   2158:        struct htmlpair tag;
                   2159:
                   2160:        if (SEC_SYNOPSIS == n->sec)
                   2161:                print_otag(h, TAG_DIV, 0, NULL);
                   2162:        PAIR_CLASS_INIT(&tag, "lib");
                   2163:        print_otag(h, TAG_SPAN, 1, &tag);
                   2164:        return(1);
                   2165: }
                   2166:
                   2167:
                   2168: /* ARGSUSED */
                   2169: static int
                   2170: mdoc__x_pre(MDOC_ARGS)
                   2171: {
1.2       schwarze 2172:        struct htmlpair tag[2];
1.1       schwarze 2173:
                   2174:        switch (n->tok) {
                   2175:        case(MDOC__A):
1.2       schwarze 2176:                PAIR_CLASS_INIT(&tag[0], "ref-auth");
1.1       schwarze 2177:                break;
                   2178:        case(MDOC__B):
1.2       schwarze 2179:                PAIR_CLASS_INIT(&tag[0], "ref-book");
1.1       schwarze 2180:                break;
                   2181:        case(MDOC__C):
1.2       schwarze 2182:                PAIR_CLASS_INIT(&tag[0], "ref-city");
1.1       schwarze 2183:                break;
                   2184:        case(MDOC__D):
1.2       schwarze 2185:                PAIR_CLASS_INIT(&tag[0], "ref-date");
1.1       schwarze 2186:                break;
                   2187:        case(MDOC__I):
1.2       schwarze 2188:                PAIR_CLASS_INIT(&tag[0], "ref-issue");
1.1       schwarze 2189:                break;
                   2190:        case(MDOC__J):
1.2       schwarze 2191:                PAIR_CLASS_INIT(&tag[0], "ref-jrnl");
1.1       schwarze 2192:                break;
                   2193:        case(MDOC__N):
1.2       schwarze 2194:                PAIR_CLASS_INIT(&tag[0], "ref-num");
1.1       schwarze 2195:                break;
                   2196:        case(MDOC__O):
1.2       schwarze 2197:                PAIR_CLASS_INIT(&tag[0], "ref-opt");
1.1       schwarze 2198:                break;
                   2199:        case(MDOC__P):
1.2       schwarze 2200:                PAIR_CLASS_INIT(&tag[0], "ref-page");
1.1       schwarze 2201:                break;
                   2202:        case(MDOC__Q):
1.2       schwarze 2203:                PAIR_CLASS_INIT(&tag[0], "ref-corp");
1.1       schwarze 2204:                break;
                   2205:        case(MDOC__R):
1.2       schwarze 2206:                PAIR_CLASS_INIT(&tag[0], "ref-rep");
1.1       schwarze 2207:                break;
                   2208:        case(MDOC__T):
1.2       schwarze 2209:                PAIR_CLASS_INIT(&tag[0], "ref-title");
1.1       schwarze 2210:                print_text(h, "\\(lq");
                   2211:                h->flags |= HTML_NOSPACE;
                   2212:                break;
1.2       schwarze 2213:        case(MDOC__U):
                   2214:                PAIR_CLASS_INIT(&tag[0], "link-ref");
                   2215:                break;
1.1       schwarze 2216:        case(MDOC__V):
1.2       schwarze 2217:                PAIR_CLASS_INIT(&tag[0], "ref-vol");
1.1       schwarze 2218:                break;
                   2219:        default:
                   2220:                abort();
                   2221:                /* NOTREACHED */
                   2222:        }
                   2223:
1.2       schwarze 2224:        if (MDOC__U != n->tok) {
                   2225:                print_otag(h, TAG_SPAN, 1, tag);
                   2226:                return(1);
                   2227:        }
                   2228:
                   2229:        PAIR_HREF_INIT(&tag[1], n->child->string);
                   2230:        print_otag(h, TAG_A, 2, tag);
1.1       schwarze 2231:        return(1);
                   2232: }
                   2233:
                   2234:
                   2235: /* ARGSUSED */
                   2236: static void
                   2237: mdoc__x_post(MDOC_ARGS)
                   2238: {
                   2239:
                   2240:        h->flags |= HTML_NOSPACE;
                   2241:        switch (n->tok) {
                   2242:        case (MDOC__T):
                   2243:                print_text(h, "\\(rq");
                   2244:                h->flags |= HTML_NOSPACE;
                   2245:                break;
                   2246:        default:
                   2247:                break;
                   2248:        }
                   2249:        print_text(h, n->next ? "," : ".");
                   2250: }