[BACK]Return to tbl_html.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Annotation of src/usr.bin/mandoc/tbl_html.c, Revision 1.14

1.14    ! schwarze    1: /*     $OpenBSD: tbl_html.c,v 1.13 2015/10/12 00:07:27 schwarze Exp $ */
1.1       schwarze    2: /*
1.5       schwarze    3:  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
1.14    ! schwarze    4:  * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
1.1       schwarze    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:  */
1.8       schwarze   18: #include <sys/types.h>
                     19:
1.1       schwarze   20: #include <assert.h>
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: #include <string.h>
                     24:
                     25: #include "mandoc.h"
                     26: #include "out.h"
                     27: #include "html.h"
                     28:
1.4       schwarze   29: static void     html_tblopen(struct html *, const struct tbl_span *);
1.2       schwarze   30: static size_t   html_tbl_len(size_t, void *);
                     31: static size_t   html_tbl_strlen(const char *, void *);
                     32:
1.7       schwarze   33:
1.2       schwarze   34: static size_t
                     35: html_tbl_len(size_t sz, void *arg)
                     36: {
1.7       schwarze   37:
1.12      schwarze   38:        return sz;
1.2       schwarze   39: }
                     40:
                     41: static size_t
                     42: html_tbl_strlen(const char *p, void *arg)
                     43: {
                     44:
1.12      schwarze   45:        return strlen(p);
1.2       schwarze   46: }
                     47:
1.4       schwarze   48: static void
                     49: html_tblopen(struct html *h, const struct tbl_span *sp)
                     50: {
1.10      schwarze   51:        int              ic;
1.4       schwarze   52:
1.11      schwarze   53:        if (h->tbl.cols == NULL) {
1.4       schwarze   54:                h->tbl.len = html_tbl_len;
                     55:                h->tbl.slen = html_tbl_strlen;
1.8       schwarze   56:                tblcalc(&h->tbl, sp, 0);
1.4       schwarze   57:        }
                     58:
                     59:        assert(NULL == h->tblt);
1.14    ! schwarze   60:        h->tblt = print_otag(h, TAG_TABLE, "c", "tbl");
1.4       schwarze   61:
1.14    ! schwarze   62:        for (ic = 0; ic < sp->opts->cols; ic++)
        !            63:                print_otag(h, TAG_COL, "shw", h->tbl.cols[ic].width);
1.4       schwarze   64:
1.14    ! schwarze   65:        print_otag(h, TAG_TBODY, "");
1.4       schwarze   66: }
                     67:
                     68: void
                     69: print_tblclose(struct html *h)
                     70: {
                     71:
                     72:        assert(h->tblt);
                     73:        print_tagq(h, h->tblt);
                     74:        h->tblt = NULL;
                     75: }
                     76:
1.1       schwarze   77: void
                     78: print_tbl(struct html *h, const struct tbl_span *sp)
                     79: {
                     80:        const struct tbl_dat *dp;
1.2       schwarze   81:        struct tag      *tt;
1.10      schwarze   82:        int              ic;
1.2       schwarze   83:
                     84:        /* Inhibit printing of spaces: we do padding ourselves. */
                     85:
1.9       schwarze   86:        if (h->tblt == NULL)
1.4       schwarze   87:                html_tblopen(h, sp);
                     88:
                     89:        assert(h->tblt);
                     90:
1.2       schwarze   91:        h->flags |= HTML_NONOSPACE;
                     92:        h->flags |= HTML_NOSPACE;
                     93:
1.14    ! schwarze   94:        tt = print_otag(h, TAG_TR, "");
1.1       schwarze   95:
                     96:        switch (sp->pos) {
1.7       schwarze   97:        case TBL_SPAN_HORIZ:
                     98:        case TBL_SPAN_DHORIZ:
1.14    ! schwarze   99:                print_otag(h, TAG_TD, "?", "colspan", "0");
1.2       schwarze  100:                break;
1.1       schwarze  101:        default:
1.2       schwarze  102:                dp = sp->first;
1.10      schwarze  103:                for (ic = 0; ic < sp->opts->cols; ic++) {
1.4       schwarze  104:                        print_stagq(h, tt);
1.14    ! schwarze  105:                        print_otag(h, TAG_TD, "");
1.4       schwarze  106:
1.10      schwarze  107:                        if (dp == NULL || dp->layout->col > ic)
                    108:                                continue;
1.9       schwarze  109:                        if (dp->layout->pos != TBL_CELL_DOWN)
                    110:                                if (dp->string != NULL)
1.6       schwarze  111:                                        print_text(h, dp->string);
                    112:                        dp = dp->next;
1.2       schwarze  113:                }
1.1       schwarze  114:                break;
                    115:        }
                    116:
1.4       schwarze  117:        print_tagq(h, tt);
                    118:
1.2       schwarze  119:        h->flags &= ~HTML_NONOSPACE;
1.1       schwarze  120:
1.11      schwarze  121:        if (sp->next == NULL) {
1.2       schwarze  122:                assert(h->tbl.cols);
                    123:                free(h->tbl.cols);
                    124:                h->tbl.cols = NULL;
1.4       schwarze  125:                print_tblclose(h);
1.1       schwarze  126:        }
1.4       schwarze  127:
1.1       schwarze  128: }