2017-02-19 17:41:20 +00:00
|
|
|
/* $Id: tbl_html.c,v 1.20 2017/02/05 18:15:39 schwarze Exp $ */
|
2012-10-18 09:55:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
2017-01-21 13:01:39 +00:00
|
|
|
* Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
|
2012-10-18 09:55:16 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
2014-12-02 07:34:06 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "mandoc.h"
|
|
|
|
#include "out.h"
|
|
|
|
#include "html.h"
|
|
|
|
|
|
|
|
static void html_tblopen(struct html *, const struct tbl_span *);
|
|
|
|
static size_t html_tbl_len(size_t, void *);
|
|
|
|
static size_t html_tbl_strlen(const char *, void *);
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
static size_t
|
|
|
|
html_tbl_len(size_t sz, void *arg)
|
|
|
|
{
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
return sz;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
html_tbl_strlen(const char *p, void *arg)
|
|
|
|
{
|
|
|
|
|
2016-01-15 23:08:59 +00:00
|
|
|
return strlen(p);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
html_tblopen(struct html *h, const struct tbl_span *sp)
|
|
|
|
{
|
2017-02-19 17:41:20 +00:00
|
|
|
struct tag *t;
|
2015-03-02 16:45:41 +00:00
|
|
|
int ic;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (h->tbl.cols == NULL) {
|
2012-10-18 09:55:16 +00:00
|
|
|
h->tbl.len = html_tbl_len;
|
|
|
|
h->tbl.slen = html_tbl_strlen;
|
2014-12-02 07:34:06 +00:00
|
|
|
tblcalc(&h->tbl, sp, 0);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(NULL == h->tblt);
|
2017-01-21 13:01:39 +00:00
|
|
|
h->tblt = print_otag(h, TAG_TABLE, "c", "tbl");
|
|
|
|
|
2017-02-19 17:41:20 +00:00
|
|
|
t = print_otag(h, TAG_COLGROUP, "");
|
2017-01-21 13:01:39 +00:00
|
|
|
for (ic = 0; ic < sp->opts->cols; ic++)
|
|
|
|
print_otag(h, TAG_COL, "shw", h->tbl.cols[ic].width);
|
2017-02-19 17:41:20 +00:00
|
|
|
print_tagq(h, t);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_tblclose(struct html *h)
|
|
|
|
{
|
|
|
|
|
|
|
|
assert(h->tblt);
|
|
|
|
print_tagq(h, h->tblt);
|
|
|
|
h->tblt = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_tbl(struct html *h, const struct tbl_span *sp)
|
|
|
|
{
|
|
|
|
const struct tbl_dat *dp;
|
|
|
|
struct tag *tt;
|
2015-03-02 16:45:41 +00:00
|
|
|
int ic;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* Inhibit printing of spaces: we do padding ourselves. */
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (h->tblt == NULL)
|
2012-10-18 09:55:16 +00:00
|
|
|
html_tblopen(h, sp);
|
|
|
|
|
|
|
|
assert(h->tblt);
|
|
|
|
|
|
|
|
h->flags |= HTML_NONOSPACE;
|
|
|
|
h->flags |= HTML_NOSPACE;
|
|
|
|
|
2017-01-21 13:01:39 +00:00
|
|
|
tt = print_otag(h, TAG_TR, "");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
switch (sp->pos) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case TBL_SPAN_HORIZ:
|
|
|
|
case TBL_SPAN_DHORIZ:
|
2017-01-21 13:01:39 +00:00
|
|
|
print_otag(h, TAG_TD, "?", "colspan", "0");
|
2012-10-18 09:55:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dp = sp->first;
|
2015-03-02 16:45:41 +00:00
|
|
|
for (ic = 0; ic < sp->opts->cols; ic++) {
|
2012-10-18 09:55:16 +00:00
|
|
|
print_stagq(h, tt);
|
2017-01-21 13:01:39 +00:00
|
|
|
print_otag(h, TAG_TD, "");
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (dp == NULL || dp->layout->col > ic)
|
|
|
|
continue;
|
|
|
|
if (dp->layout->pos != TBL_CELL_DOWN)
|
|
|
|
if (dp->string != NULL)
|
2014-01-31 19:59:03 +00:00
|
|
|
print_text(h, dp->string);
|
|
|
|
dp = dp->next;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_tagq(h, tt);
|
|
|
|
|
|
|
|
h->flags &= ~HTML_NONOSPACE;
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (sp->next == NULL) {
|
2012-10-18 09:55:16 +00:00
|
|
|
assert(h->tbl.cols);
|
|
|
|
free(h->tbl.cols);
|
|
|
|
h->tbl.cols = NULL;
|
|
|
|
print_tblclose(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|