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

Annotation of mandoc/tbl_html.c, Revision 1.20

1.20    ! schwarze    1: /*     $Id: tbl_html.c,v 1.19 2017/01/17 01:47:51 schwarze Exp $ */
1.1       kristaps    2: /*
1.9       schwarze    3:  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.19      schwarze    4:  * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
1.1       kristaps    5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18: #include "config.h"
1.12      schwarze   19:
                     20: #include <sys/types.h>
1.1       kristaps   21:
                     22: #include <assert.h>
                     23: #include <stdio.h>
                     24: #include <stdlib.h>
                     25: #include <string.h>
                     26:
                     27: #include "mandoc.h"
                     28: #include "out.h"
                     29: #include "html.h"
                     30:
1.7       kristaps   31: static void     html_tblopen(struct html *, const struct tbl_span *);
1.4       kristaps   32: static size_t   html_tbl_len(size_t, void *);
                     33: static size_t   html_tbl_strlen(const char *, void *);
                     34:
1.11      schwarze   35:
1.4       kristaps   36: static size_t
                     37: html_tbl_len(size_t sz, void *arg)
                     38: {
1.11      schwarze   39:
1.17      schwarze   40:        return sz;
1.4       kristaps   41: }
                     42:
                     43: static size_t
                     44: html_tbl_strlen(const char *p, void *arg)
                     45: {
                     46:
1.17      schwarze   47:        return strlen(p);
1.4       kristaps   48: }
                     49:
1.7       kristaps   50: static void
                     51: html_tblopen(struct html *h, const struct tbl_span *sp)
                     52: {
1.20    ! schwarze   53:        struct tag      *t;
1.15      schwarze   54:        int              ic;
1.7       kristaps   55:
1.16      schwarze   56:        if (h->tbl.cols == NULL) {
1.7       kristaps   57:                h->tbl.len = html_tbl_len;
                     58:                h->tbl.slen = html_tbl_strlen;
1.13      schwarze   59:                tblcalc(&h->tbl, sp, 0);
1.7       kristaps   60:        }
                     61:
                     62:        assert(NULL == h->tblt);
1.19      schwarze   63:        h->tblt = print_otag(h, TAG_TABLE, "c", "tbl");
1.7       kristaps   64:
1.20    ! schwarze   65:        t = print_otag(h, TAG_COLGROUP, "");
1.19      schwarze   66:        for (ic = 0; ic < sp->opts->cols; ic++)
                     67:                print_otag(h, TAG_COL, "shw", h->tbl.cols[ic].width);
1.20    ! schwarze   68:        print_tagq(h, t);
1.7       kristaps   69: }
                     70:
                     71: void
                     72: print_tblclose(struct html *h)
                     73: {
                     74:
                     75:        assert(h->tblt);
                     76:        print_tagq(h, h->tblt);
                     77:        h->tblt = NULL;
                     78: }
                     79:
1.1       kristaps   80: void
                     81: print_tbl(struct html *h, const struct tbl_span *sp)
                     82: {
                     83:        const struct tbl_dat *dp;
1.3       kristaps   84:        struct tag      *tt;
1.15      schwarze   85:        int              ic;
1.1       kristaps   86:
                     87:        /* Inhibit printing of spaces: we do padding ourselves. */
                     88:
1.14      schwarze   89:        if (h->tblt == NULL)
1.7       kristaps   90:                html_tblopen(h, sp);
                     91:
                     92:        assert(h->tblt);
                     93:
1.1       kristaps   94:        h->flags |= HTML_NONOSPACE;
                     95:        h->flags |= HTML_NOSPACE;
                     96:
1.19      schwarze   97:        tt = print_otag(h, TAG_TR, "");
1.4       kristaps   98:
1.5       kristaps   99:        switch (sp->pos) {
1.11      schwarze  100:        case TBL_SPAN_HORIZ:
                    101:        case TBL_SPAN_DHORIZ:
1.19      schwarze  102:                print_otag(h, TAG_TD, "?", "colspan", "0");
1.5       kristaps  103:                break;
                    104:        default:
                    105:                dp = sp->first;
1.15      schwarze  106:                for (ic = 0; ic < sp->opts->cols; ic++) {
1.7       kristaps  107:                        print_stagq(h, tt);
1.19      schwarze  108:                        print_otag(h, TAG_TD, "");
1.7       kristaps  109:
1.15      schwarze  110:                        if (dp == NULL || dp->layout->col > ic)
                    111:                                continue;
1.14      schwarze  112:                        if (dp->layout->pos != TBL_CELL_DOWN)
                    113:                                if (dp->string != NULL)
1.10      schwarze  114:                                        print_text(h, dp->string);
                    115:                        dp = dp->next;
1.1       kristaps  116:                }
1.5       kristaps  117:                break;
                    118:        }
1.4       kristaps  119:
1.7       kristaps  120:        print_tagq(h, tt);
                    121:
1.1       kristaps  122:        h->flags &= ~HTML_NONOSPACE;
1.4       kristaps  123:
1.16      schwarze  124:        if (sp->next == NULL) {
1.4       kristaps  125:                assert(h->tbl.cols);
                    126:                free(h->tbl.cols);
                    127:                h->tbl.cols = NULL;
1.7       kristaps  128:                print_tblclose(h);
1.4       kristaps  129:        }
1.7       kristaps  130:
1.1       kristaps  131: }

CVSweb