"); escape_string (html->file, s, " ", "\n"); break; case TEXT_ITEM_LOG: print_title_tag (html->file, "pre", s); /* should be
"); fprintf (html->file, "
*/
break;
case TEXT_ITEM_EJECT_PAGE:
/* Nothing to do. */
break;
}
}
else if (is_message_item (output_item))
{
const struct message_item *message_item = to_message_item (output_item);
char *s = msg_to_string (message_item_get_msg (message_item));
print_title_tag (html->file, "p", s);
free (s);
}
}
/* Write TEXT to file F, escaping characters as necessary for HTML. Spaces are
replaced by SPACE, which should be " " or " " New-lines are replaced by
NEWLINE, which might be "
" or "\n" or something else appropriate. */
static void
escape_string (FILE *file, const char *text,
const char *space, const char *newline)
{
for (;;)
{
char c = *text++;
switch (c)
{
case 0:
return;
case '\n':
fputs (newline, file);
break;
case '&':
fputs ("&", file);
break;
case '<':
fputs ("<", file);
break;
case '>':
fputs (">", file);
break;
case ' ':
fputs (space, file);
break;
case '"':
fputs (""", file);
break;
default:
putc (c, file);
break;
}
}
}
static void
escape_tag (FILE *file, const char *tag,
const char *text, const char *space, const char *newline)
{
if (!text || !*text)
return;
fprintf (file, "<%s>", tag);
escape_string (file, text, space, newline);
fprintf (file, "%s>", tag);
}
static const char *
border_to_css (int border)
{
switch (border)
{
case TABLE_STROKE_NONE:
return NULL;
case TABLE_STROKE_SOLID:
return "solid";
case TABLE_STROKE_DASHED:
return "dashed";
case TABLE_STROKE_THICK:
return "thick solid";
case TABLE_STROKE_THIN:
return "thin solid";
case TABLE_STROKE_DOUBLE:
return "double";
default:
return NULL;
}
}
struct css_style
{
FILE *file;
int n_styles;
};
static struct css_style *
style_start (FILE *file)
{
struct css_style *cs = XMALLOC (struct css_style);
cs->file = file;
cs->n_styles = 0;
fputs (" style=\"", file);
return cs;
}
static void
style_end (struct css_style *cs)
{
fputs ("\"", cs->file);
free (cs);
}
static void
put_style (struct css_style *st, const char *name, const char *value)
{
if (st->n_styles++ > 0)
fputs ("; ", st->file);
fprintf (st->file, "%s: %s", name, value);
}
static void
put_border (struct css_style *st, int style, const char *border_name)
{
const char *css = border_to_css (style);
if (css)
{
if (st->n_styles++ > 0)
fputs ("; ", st->file);
fprintf (st->file, "border-%s: %s", border_name, css);
}
}
static void
put_tfoot (struct html_driver *html, const struct table *t, bool *tfoot)
{
if (!*tfoot)
{
fputs ("\n", html->file);
fputs ("\n", html->file);
fprintf (html->file, " \n", table_nc (t));
*tfoot = true;
}
else
fputs ("\n
", html->file);
}
static void
html_put_footnote_markers (struct html_driver *html,
const struct footnote **footnotes,
size_t n_footnotes)
{
if (n_footnotes > 0)
{
fputs ("", html->file);
for (size_t i = 0; i < n_footnotes; i++)
{
const struct footnote *f = footnotes[i];
if (i > 0)
putc (',', html->file);
escape_string (html->file, f->marker, " ", "
");
}
fputs ("", html->file);
}
}
static void
html_put_table_item_text (struct html_driver *html,
const struct table_item_text *text)
{
escape_string (html->file, text->content, " ", "
");
html_put_footnote_markers (html, text->footnotes, text->n_footnotes);
}
static void
html_put_table_item_layers (struct html_driver *html,
const struct table_item_layers *layers)
{
for (size_t i = 0; i < layers->n_layers; i++)
{
if (i)
fputs ("
\n", html->file);
const struct table_item_layer *layer = &layers->layers[i];
escape_string (html->file, layer->content, " ", "
");
html_put_footnote_markers (html, layer->footnotes, layer->n_footnotes);
}
}
static void
html_output_table (struct html_driver *html, const struct table_item *item)
{
const struct table *t = table_item_get_table (item);
bool tfoot = false;
int y;
fputs ("\n", html->file);
const struct table_item_text *caption = table_item_get_caption (item);
if (caption)
{
put_tfoot (html, t, &tfoot);
html_put_table_item_text (html, caption);
}
const struct footnote **f;
size_t n_footnotes = table_collect_footnotes (item, &f);
for (size_t i = 0; i < n_footnotes; i++)
{
put_tfoot (html, t, &tfoot);
escape_tag (html->file, "sup", f[i]->marker, " ", "
\n\n", html->file);
}
struct output_driver_factory html_driver_factory =
{ "html", "pspp.html", html_create };
static const struct output_driver_class html_driver_class =
{
"html",
html_destroy,
html_submit,
NULL,
};
");
escape_string (html->file, f[i]->content, " ", "
");
}
free (f);
if (tfoot)
{
fputs ("\n", html->file);
fputs ("\n", html->file);
fputs ("\n", html->file);
}
const struct table_item_text *title = table_item_get_title (item);
const struct table_item_layers *layers = table_item_get_layers (item);
if (title || layers)
{
fputs ("
\n", html->file);
if (layers)
html_put_table_item_layers (html, layers);
fputs ("\n", html->file);
for (x = 0; x < table_nc (t);)
{
struct table_cell cell;
const char *tag;
table_get_cell (t, x, y, &cell);
if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
goto next_1;
/* output \n", html->file);
}
fputs ("\n", html->file);
fputs (" or tag. */
bool is_header = (y < table_ht (t)
|| y >= table_nr (t) - table_hb (t)
|| x < table_hl (t)
|| x >= table_nc (t) - table_hr (t));
tag = is_header ? "th" : "td";
fprintf (html->file, "<%s", tag);
struct css_style *style = style_start (html->file);
enum table_halign halign = table_halign_interpret (
cell.style->cell_style.halign, cell.options & TAB_NUMERIC);
switch (halign)
{
case TABLE_HALIGN_RIGHT:
put_style (style, "text-align", "right");
break;
case TABLE_HALIGN_CENTER:
put_style (style, "text-align", "center");
break;
default:
/* Do nothing */
break;
}
if (cell.style->cell_style.valign != TABLE_VALIGN_TOP)
{
put_style (style, "vertical-align",
(cell.style->cell_style.valign == TABLE_VALIGN_BOTTOM
? "bottom" : "middle"));
}
int colspan = table_cell_colspan (&cell);
int rowspan = table_cell_rowspan (&cell);
if (html->borders)
{
/* Cell borders. */
struct cell_color color;
int top = table_get_rule (t, TABLE_VERT, x, y, &color);
put_border (style, top, "top");
if (y + rowspan == table_nr (t))
{
int bottom = table_get_rule (t, TABLE_VERT, x, y + rowspan,
&color);
put_border (style, bottom, "bottom");
}
int left = table_get_rule (t, TABLE_HORZ, x, y, &color);
put_border (style, left, "left");
if (x + colspan == table_nc (t))
{
int right = table_get_rule (t, TABLE_HORZ, x + colspan, y,
&color);
put_border (style, right, "right");
}
}
style_end (style);
if (colspan > 1)
fprintf (html->file, " colspan=\"%d\"", colspan);
if (rowspan > 1)
fprintf (html->file, " rowspan=\"%d\"", rowspan);
putc ('>', html->file);
/* Output cell contents. */
const char *s = cell.text;
if (cell.options & TAB_FIX)
escape_tag (html->file, "tt", s, " ", " or . */
fprintf (html->file, "%s>\n", tag);
next_1:
x = cell.d[TABLE_HORZ][1];
}
fputs ("
");
else
{
s += strspn (s, CC_SPACES);
escape_string (html->file, s, " ", "
");
}
if (cell.n_subscripts)
{
fputs ("", html->file);
for (size_t i = 0; i < cell.n_subscripts; i++)
{
if (i)
putc (',', html->file);
escape_string (html->file, cell.subscripts[i],
" ", "
");
}
fputs ("", html->file);
}
if (cell.superscript)
escape_tag (html->file, "sup", cell.superscript, " ", "
");
html_put_footnote_markers (html, cell.footnotes, cell.n_footnotes);
/* output