[BACK]Return to tbl_html.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/tbl_html.c, Revision 1.10

1.10    ! schwarze    1: /*     $Id: tbl_html.c,v 1.9 2011/09/18 14:14:15 schwarze Exp $ */
1.1       kristaps    2: /*
1.9       schwarze    3:  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.1       kristaps    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: #ifdef HAVE_CONFIG_H
                     18: #include "config.h"
                     19: #endif
                     20:
                     21: #include <assert.h>
                     22: #include <stdio.h>
                     23: #include <stdlib.h>
                     24: #include <string.h>
                     25:
                     26: #include "mandoc.h"
                     27: #include "out.h"
                     28: #include "html.h"
                     29:
1.7       kristaps   30: static void     html_tblopen(struct html *, const struct tbl_span *);
1.4       kristaps   31: static size_t   html_tbl_len(size_t, void *);
                     32: static size_t   html_tbl_strlen(const char *, void *);
                     33:
                     34: /* ARGSUSED */
                     35: static size_t
                     36: html_tbl_len(size_t sz, void *arg)
                     37: {
                     38:
                     39:        return(sz);
                     40: }
                     41:
                     42: /* ARGSUSED */
                     43: static size_t
                     44: html_tbl_strlen(const char *p, void *arg)
                     45: {
                     46:
                     47:        return(strlen(p));
                     48: }
                     49:
1.7       kristaps   50: static void
                     51: html_tblopen(struct html *h, const struct tbl_span *sp)
                     52: {
                     53:        const struct tbl_head *hp;
                     54:        struct htmlpair  tag;
                     55:        struct roffsu    su;
                     56:        struct roffcol  *col;
                     57:
                     58:        if (TBL_SPAN_FIRST & sp->flags) {
                     59:                h->tbl.len = html_tbl_len;
                     60:                h->tbl.slen = html_tbl_strlen;
                     61:                tblcalc(&h->tbl, sp);
                     62:        }
                     63:
                     64:        assert(NULL == h->tblt);
                     65:        PAIR_CLASS_INIT(&tag, "tbl");
                     66:        h->tblt = print_otag(h, TAG_TABLE, 1, &tag);
                     67:
                     68:        for (hp = sp->head; hp; hp = hp->next) {
                     69:                bufinit(h);
                     70:                col = &h->tbl.cols[hp->ident];
                     71:                SCALE_HS_INIT(&su, col->width);
                     72:                bufcat_su(h, "width", &su);
                     73:                PAIR_STYLE_INIT(&tag, h);
                     74:                print_otag(h, TAG_COL, 1, &tag);
                     75:        }
                     76:
                     77:        print_otag(h, TAG_TBODY, 0, NULL);
                     78: }
                     79:
                     80: void
                     81: print_tblclose(struct html *h)
                     82: {
                     83:
                     84:        assert(h->tblt);
                     85:        print_tagq(h, h->tblt);
                     86:        h->tblt = NULL;
                     87: }
                     88:
1.1       kristaps   89: void
                     90: print_tbl(struct html *h, const struct tbl_span *sp)
                     91: {
                     92:        const struct tbl_head *hp;
                     93:        const struct tbl_dat *dp;
1.7       kristaps   94:        struct htmlpair  tag;
1.3       kristaps   95:        struct tag      *tt;
1.1       kristaps   96:
                     97:        /* Inhibit printing of spaces: we do padding ourselves. */
                     98:
1.7       kristaps   99:        if (NULL == h->tblt)
                    100:                html_tblopen(h, sp);
                    101:
                    102:        assert(h->tblt);
                    103:
1.1       kristaps  104:        h->flags |= HTML_NONOSPACE;
                    105:        h->flags |= HTML_NOSPACE;
                    106:
1.7       kristaps  107:        tt = print_otag(h, TAG_TR, 0, NULL);
1.4       kristaps  108:
1.5       kristaps  109:        switch (sp->pos) {
                    110:        case (TBL_SPAN_HORIZ):
                    111:                /* FALLTHROUGH */
                    112:        case (TBL_SPAN_DHORIZ):
1.7       kristaps  113:                PAIR_INIT(&tag, ATTR_COLSPAN, "0");
                    114:                print_otag(h, TAG_TD, 1, &tag);
1.5       kristaps  115:                break;
                    116:        default:
                    117:                dp = sp->first;
                    118:                for (hp = sp->head; hp; hp = hp->next) {
1.7       kristaps  119:                        print_stagq(h, tt);
                    120:                        print_otag(h, TAG_TD, 0, NULL);
                    121:
1.10    ! schwarze  122:                        if (NULL == dp)
1.7       kristaps  123:                                break;
1.10    ! schwarze  124:                        if (TBL_CELL_DOWN != dp->layout->pos)
        !           125:                                if (dp->string)
        !           126:                                        print_text(h, dp->string);
        !           127:                        dp = dp->next;
1.1       kristaps  128:                }
1.5       kristaps  129:                break;
                    130:        }
1.4       kristaps  131:
1.7       kristaps  132:        print_tagq(h, tt);
                    133:
1.1       kristaps  134:        h->flags &= ~HTML_NONOSPACE;
1.4       kristaps  135:
                    136:        if (TBL_SPAN_LAST & sp->flags) {
                    137:                assert(h->tbl.cols);
                    138:                free(h->tbl.cols);
                    139:                h->tbl.cols = NULL;
1.7       kristaps  140:                print_tblclose(h);
1.4       kristaps  141:        }
1.7       kristaps  142:
1.1       kristaps  143: }

CVSweb