X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fhtml.c;h=989476ecaadd394b0133bdae7040966b16bec08d;hb=b2b06e8496c000431a28acb82fe87e1f8954e04f;hp=1027dea501037e5e74655ecb0a4d76b7c2357280;hpb=b8d97ba13fa4e3c78d3a0bc87803219c88e581ea;p=pspp diff --git a/src/output/html.c b/src/output/html.c index 1027dea501..989476ecaa 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); @@ -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); } } @@ -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) { @@ -438,16 +462,11 @@ html_output_table (struct html_driver *html, const struct table_item *item) size_t n_footnotes = table_collect_footnotes (item, &f); for (size_t i = 0; i < n_footnotes; i++) - if (f[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), - " ", "
"); - } + { + put_tfoot (html, t, &tfoot); + escape_tag (html->file, "SUP", f[i]->marker, " ", "
"); + escape_string (html->file, f[i]->content, " ", "
"); + } free (f); if (tfoot) fputs ("\n", html->file); @@ -455,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); @@ -464,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); } @@ -554,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 . */ @@ -572,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); }