X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fhtml.c;h=635ae5254ee6bece1dc591d21937870063aa6369;hb=ac2fba558fc64d7f1a554e9388d5adfe5ad22f0e;hp=806e6320145dbfbdd4efc4229bc0a033393a0c95;hpb=7b3ea5147198695be27b2646548c11ac92d63129;p=pspp diff --git a/src/output/html.c b/src/output/html.c index 806e632014..635ae5254e 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -66,8 +66,7 @@ struct html_driver static const struct output_driver_class html_driver_class; static void html_output_table (struct html_driver *, const struct table_item *); -static void escape_string (FILE *file, - const char *text, size_t length, +static void escape_string (FILE *file, const char *text, const char *space, const char *newline); static void print_title_tag (FILE *file, const char *name, const char *content); @@ -125,7 +124,7 @@ html_create (struct file_handle *fh, enum settings_output_devices device_type, fputs ("\n", html->file); - if ( html->css) + if (html->css) { fputs ("\n", html->file); @@ -201,7 +200,7 @@ print_title_tag (FILE *file, const char *name, const char *content) if (content != NULL) { fprintf (file, "<%s>", name); - escape_string (file, content, strlen (content), " ", " - "); + escape_string (file, content, " ", " - "); fprintf (file, "\n", name); } } @@ -245,7 +244,7 @@ html_submit (struct output_driver *driver, html->chart_cnt++, &html->fg, &html->bg - ); + ); if (file_name != NULL) { const char *title = chart_item_get_title (chart_item); @@ -275,7 +274,7 @@ html_submit (struct output_driver *driver, case TEXT_ITEM_SYNTAX: fprintf (html->file, "
");
-          escape_string (html->file, s, strlen (s), " ", "
"); + escape_string (html->file, s, " ", "
"); fprintf (html->file, "
\n"); break; @@ -297,20 +296,20 @@ html_submit (struct output_driver *driver, } } -/* Write LENGTH characters in 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. */ +/* 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, size_t length, +escape_string (FILE *file, const char *text, const char *space, const char *newline) { - while (length-- > 0) + for (;;) { char c = *text++; switch (c) { + case 0: + return; case '\n': fputs (newline, file); break; @@ -336,27 +335,39 @@ escape_string (FILE *file, } } +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, "", tag); +} + static const char * border_to_css (int border) { switch (border) { - case TAL_NONE: + case TABLE_STROKE_NONE: return NULL; - case TAL_SOLID: + case TABLE_STROKE_SOLID: return "solid"; - case TAL_DASHED: + case TABLE_STROKE_DASHED: return "dashed"; - case TAL_THICK: + case TABLE_STROKE_THICK: return "thick solid"; - case TAL_THIN: + case TABLE_STROKE_THIN: return "thin solid"; - case TAL_DOUBLE: + case TABLE_STROKE_DOUBLE: return "double"; default: @@ -403,8 +414,7 @@ html_put_footnote_markers (struct html_driver *html, if (i > 0) putc (',', html->file); - escape_string (html->file, f->marker, - strlen (f->marker), " ", "
"); + escape_string (html->file, f->marker, " ", "
"); } fputs ("", html->file); } @@ -414,11 +424,25 @@ static void html_put_table_item_text (struct html_driver *html, const struct table_item_text *text) { - escape_string (html->file, text->content, strlen (text->content), - " ", "
"); + 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) { @@ -440,12 +464,8 @@ html_output_table (struct html_driver *html, const struct table_item *item) for (size_t i = 0; i < n_footnotes; i++) { put_tfoot (html, t, &tfoot); - fputs ("", html->file); - escape_string (html->file, f[i]->marker, strlen (f[i]->marker), - " ", "
"); - fputs ("
", html->file); - escape_string (html->file, f[i]->content, strlen (f[i]->content), - " ", "
"); + escape_tag (html->file, "SUP", f[i]->marker, " ", "
"); + escape_string (html->file, f[i]->content, " ", "
"); } free (f); if (tfoot) @@ -454,7 +474,7 @@ html_output_table (struct html_driver *html, const struct table_item *item) fputs ("\n", html->file); const struct table_item_text *title = table_item_get_title (item); - const struct table_item_text *layers = table_item_get_layers (item); + const struct table_item_layers *layers = table_item_get_layers (item); if (title || layers) { fputs (" ", html->file); @@ -463,7 +483,7 @@ html_output_table (struct html_driver *html, const struct table_item *item) if (title && layers) fputs ("
\n", html->file); if (layers) - html_put_table_item_text (html, layers); + html_put_table_item_layers (html, layers); fputs ("\n", html->file); } @@ -472,7 +492,7 @@ html_output_table (struct html_driver *html, const struct table_item *item) int x; fputs (" \n", html->file); - for (x = 0; x < table_nc (t); ) + for (x = 0; x < table_nc (t);) { struct table_cell cell; const char *tag; @@ -506,7 +526,7 @@ html_output_table (struct html_driver *html, const struct table_item *item) } if (cell.style->cell_style.valign != TABLE_VALIGN_TOP) - fprintf (html->file, " ALIGN=\"%s\"", + fprintf (html->file, " VALIGN=\"%s\"", (cell.style->cell_style.valign == TABLE_VALIGN_BOTTOM ? "BOTTOM" : "MIDDLE")); @@ -553,17 +573,27 @@ html_output_table (struct html_driver *html, const struct table_item *item) /* Output cell contents. */ const char *s = cell.text; if (cell.options & TAB_FIX) - { - fputs ("", html->file); - escape_string (html->file, s, strlen (s), " ", "
"); - fputs ("
", html->file); - } + escape_tag (html->file, "TT", s, " ", "
"); else { s += strspn (s, CC_SPACES); - escape_string (html->file, s, strlen (s), " ", "
"); + 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 or . */ @@ -571,7 +601,6 @@ html_output_table (struct html_driver *html, const struct table_item *item) next_1: x = cell.d[TABLE_HORZ][1]; - table_cell_free (&cell); } fputs (" \n", html->file); }