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

Annotation of mandoc/tbl_html.c, Revision 1.4

1.4     ! kristaps    1: /*     $Id: tbl_html.c,v 1.3 2011/01/05 13:00:11 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 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: #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.4     ! kristaps   30: static size_t   html_tbl_len(size_t, void *);
        !            31: static size_t   html_tbl_strlen(const char *, void *);
        !            32:
        !            33: /* ARGSUSED */
        !            34: static size_t
        !            35: html_tbl_len(size_t sz, void *arg)
        !            36: {
        !            37:
        !            38:        return(sz);
        !            39: }
        !            40:
        !            41: /* ARGSUSED */
        !            42: static size_t
        !            43: html_tbl_strlen(const char *p, void *arg)
        !            44: {
        !            45:
        !            46:        return(strlen(p));
        !            47: }
        !            48:
1.1       kristaps   49: void
                     50: print_tbl(struct html *h, const struct tbl_span *sp)
                     51: {
                     52:        const struct tbl_head *hp;
                     53:        const struct tbl_dat *dp;
1.3       kristaps   54:        struct tag      *tt;
                     55:        struct htmlpair  tag;
1.4     ! kristaps   56:        struct roffsu    su;
        !            57:        struct roffcol  *col;
1.1       kristaps   58:
                     59:        switch (sp->pos) {
                     60:        case (TBL_SPAN_HORIZ):
                     61:                /* FALLTHROUGH */
                     62:        case (TBL_SPAN_DHORIZ):
                     63:                return;
                     64:        default:
                     65:                break;
                     66:        }
                     67:
                     68:        /* Inhibit printing of spaces: we do padding ourselves. */
                     69:
                     70:        h->flags |= HTML_NONOSPACE;
                     71:        h->flags |= HTML_NOSPACE;
                     72:
1.4     ! kristaps   73:        /* First pass: calculate widths. */
        !            74:
        !            75:        if (TBL_SPAN_FIRST & sp->flags) {
        !            76:                h->tbl.len = html_tbl_len;
        !            77:                h->tbl.slen = html_tbl_strlen;
        !            78:                tblcalc(&h->tbl, sp);
        !            79:        }
        !            80:
1.3       kristaps   81:        PAIR_CLASS_INIT(&tag, "tbl");
                     82:
                     83:        print_otag(h, TAG_TABLE, 1, &tag);
1.1       kristaps   84:        print_otag(h, TAG_TR, 0, NULL);
                     85:
                     86:        dp = sp->first;
                     87:        for (hp = sp->head; hp; hp = hp->next) {
                     88:                switch (hp->pos) {
                     89:                case (TBL_HEAD_VERT):
                     90:                        /* FALLTHROUGH */
                     91:                case (TBL_HEAD_DVERT):
                     92:                        continue;
                     93:                case (TBL_HEAD_DATA):
                     94:                        break;
                     95:                }
1.4     ! kristaps   96:
        !            97:                /*
        !            98:                 * For the time being, use the simplest possible table
        !            99:                 * styling: setting the widths of data columns.
        !           100:                 */
        !           101:
        !           102:                col = &h->tbl.cols[hp->ident];
        !           103:                SCALE_HS_INIT(&su, col->width);
        !           104:                bufcat_su(h, "width", &su);
        !           105:                PAIR_STYLE_INIT(&tag, h);
        !           106:                tt = print_otag(h, TAG_TD, 1, &tag);
1.1       kristaps  107:                if (dp) {
1.2       kristaps  108:                        if (dp->string)
                    109:                                print_text(h, dp->string);
1.1       kristaps  110:                        dp = dp->next;
                    111:                }
                    112:                print_tagq(h, tt);
                    113:        }
                    114:        h->flags &= ~HTML_NONOSPACE;
1.4     ! kristaps  115:
        !           116:        /* Close out column specifiers on the last span. */
        !           117:
        !           118:        if (TBL_SPAN_LAST & sp->flags) {
        !           119:                assert(h->tbl.cols);
        !           120:                free(h->tbl.cols);
        !           121:                h->tbl.cols = NULL;
        !           122:        }
1.1       kristaps  123: }

CVSweb