1 /* $Id: tbl_html.c,v 1.20 2017/02/05 18:15:39 schwarze Exp $ */
3 * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
20 #include <sys/types.h>
31 static void html_tblopen(struct html *, const struct tbl_span *);
32 static size_t html_tbl_len(size_t, void *);
33 static size_t html_tbl_strlen(const char *, void *);
37 html_tbl_len(size_t sz, void *arg)
44 html_tbl_strlen(const char *p, void *arg)
51 html_tblopen(struct html *h, const struct tbl_span *sp)
56 if (h->tbl.cols == NULL) {
57 h->tbl.len = html_tbl_len;
58 h->tbl.slen = html_tbl_strlen;
59 tblcalc(&h->tbl, sp, 0);
62 assert(NULL == h->tblt);
63 h->tblt = print_otag(h, TAG_TABLE, "c", "tbl");
65 t = print_otag(h, TAG_COLGROUP, "");
66 for (ic = 0; ic < sp->opts->cols; ic++)
67 print_otag(h, TAG_COL, "shw", h->tbl.cols[ic].width);
72 print_tblclose(struct html *h)
76 print_tagq(h, h->tblt);
81 print_tbl(struct html *h, const struct tbl_span *sp)
83 const struct tbl_dat *dp;
87 /* Inhibit printing of spaces: we do padding ourselves. */
94 h->flags |= HTML_NONOSPACE;
95 h->flags |= HTML_NOSPACE;
97 tt = print_otag(h, TAG_TR, "");
101 case TBL_SPAN_DHORIZ:
102 print_otag(h, TAG_TD, "?", "colspan", "0");
106 for (ic = 0; ic < sp->opts->cols; ic++) {
108 print_otag(h, TAG_TD, "");
110 if (dp == NULL || dp->layout->col > ic)
112 if (dp->layout->pos != TBL_CELL_DOWN)
113 if (dp->string != NULL)
114 print_text(h, dp->string);
122 h->flags &= ~HTML_NONOSPACE;
124 if (sp->next == NULL) {