X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fhtml.c;h=989476ecaadd394b0133bdae7040966b16bec08d;hb=5805214e9bb9e2a4705ada8cdf5f5d0f1814db0e;hp=307f6c223d83bb3fea6040da6e7f04d8d30ada13;hpb=0d95a6ff1dff86f7d1578a8bf20a964c7a00b6c3;p=pspp diff --git a/src/output/html.c b/src/output/html.c index 307f6c223d..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,8 +424,7 @@ 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); } @@ -429,8 +438,7 @@ html_put_table_item_layers (struct html_driver *html, fputs ("
\n", html->file); const struct table_item_layer *layer = &layers->layers[i]; - escape_string (html->file, layer->content, strlen (layer->content), - " ", "
"); + escape_string (html->file, layer->content, " ", "
"); html_put_footnote_markers (html, layer->footnotes, layer->n_footnotes); } } @@ -456,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) @@ -569,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 . */ @@ -587,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); }