1 /* $Id: tbl_html.c,v 1.5 2011/01/06 12:31:39 kristaps Exp $ */
3 * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
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.
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.
30 static size_t html_tbl_len(size_t, void *);
31 static size_t html_tbl_strlen(const char *, void *);
35 html_tbl_len(size_t sz, void *arg)
43 html_tbl_strlen(const char *p, void *arg)
50 print_tbl(struct html *h, const struct tbl_span *sp)
52 const struct tbl_head *hp;
53 const struct tbl_dat *dp;
59 /* Inhibit printing of spaces: we do padding ourselves. */
61 h->flags |= HTML_NONOSPACE;
62 h->flags |= HTML_NOSPACE;
64 /* First pass: calculate widths. */
66 if (TBL_SPAN_FIRST & sp->flags) {
67 h->tbl.len = html_tbl_len;
68 h->tbl.slen = html_tbl_strlen;
73 case (TBL_SPAN_HORIZ):
75 case (TBL_SPAN_DHORIZ):
78 PAIR_CLASS_INIT(&tag, "tbl");
79 print_otag(h, TAG_TABLE, 1, &tag);
80 print_otag(h, TAG_TR, 0, NULL);
82 /* Iterate over template headers. */
85 for (hp = sp->head; hp; hp = hp->next) {
89 case (TBL_HEAD_DVERT):
96 * For the time being, use the simplest possible
97 * table styling: setting the widths of data
101 col = &h->tbl.cols[hp->ident];
102 SCALE_HS_INIT(&su, col->width);
103 bufcat_su(h, "width", &su);
104 PAIR_STYLE_INIT(&tag, h);
105 tt = print_otag(h, TAG_TD, 1, &tag);
107 if (dp && dp->string)
108 print_text(h, dp->string);
117 h->flags &= ~HTML_NONOSPACE;
119 /* Close out column specifiers on the last span. */
121 if (TBL_SPAN_LAST & sp->flags) {