From: Ben Pfaff Date: Tue, 29 Dec 2020 07:33:30 +0000 (-0800) Subject: table-provider: Remove "const" from struct table_cell members. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=240ecae8130528a997cc10cffa7f7e9f61689cb2;p=pspp table-provider: Remove "const" from struct table_cell members. Until now, this struct has been used only in one particular place, where the "const" is easy to handle. In an upcoming commit, it will be used more widely, making the const-ness impractical to maintain, so this commit removes it. --- diff --git a/src/output/csv.c b/src/output/csv.c index e5b47a06ef..6ff61382d2 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -175,7 +175,7 @@ csv_output_lines (struct csv_driver *csv, const char *text_) } static void -csv_format_footnotes (const struct footnote **f, size_t n, struct string *s) +csv_format_footnotes (struct footnote **f, size_t n, struct string *s) { for (size_t i = 0; i < n; i++) ds_put_format (s, "[%s]", f[i]->marker); @@ -260,7 +260,7 @@ csv_submit (struct output_driver *driver, csv_output_table_item_text (csv, table_item_get_caption (table_item), "Caption"); - const struct footnote **f; + struct footnote **f; size_t n_footnotes = table_collect_footnotes (table_item, &f); if (n_footnotes) { diff --git a/src/output/html.c b/src/output/html.c index 9a803d1ab0..31fa063f51 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -485,7 +485,7 @@ put_tfoot (struct html_driver *html, const struct table *t, bool *tfoot) static void html_put_footnote_markers (struct html_driver *html, - const struct footnote **footnotes, + struct footnote **footnotes, size_t n_footnotes) { if (n_footnotes > 0) @@ -576,7 +576,7 @@ html_output_table (struct html_driver *html, const struct table_item *item) put_tfoot (html, t, &tfoot); html_put_table_item_text (html, caption); } - const struct footnote **f; + struct footnote **f; size_t n_footnotes = table_collect_footnotes (item, &f); for (size_t i = 0; i < n_footnotes; i++) diff --git a/src/output/render.c b/src/output/render.c index 21fd53dc91..41daea37e0 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -1518,7 +1518,7 @@ render_pager_start_page (struct render_pager *p) static void add_footnote_page (struct render_pager *p, const struct table_item *item) { - const struct footnote **f; + struct footnote **f; size_t n_footnotes = table_collect_footnotes (item, &f); if (!n_footnotes) return; diff --git a/src/output/table-item.h b/src/output/table-item.h index e4c40ab228..d1c30b668d 100644 --- a/src/output/table-item.h +++ b/src/output/table-item.h @@ -33,7 +33,7 @@ struct table_item_text { char *content; - const struct footnote **footnotes; + struct footnote **footnotes; size_t n_footnotes; struct table_area_style *style; }; @@ -45,7 +45,7 @@ void table_item_text_destroy (struct table_item_text *); struct table_item_layer { char *content; - const struct footnote **footnotes; + struct footnote **footnotes; size_t n_footnotes; }; diff --git a/src/output/table-provider.h b/src/output/table-provider.h index 8cac97a6d9..2b14c98d1c 100644 --- a/src/output/table-provider.h +++ b/src/output/table-provider.h @@ -57,11 +57,14 @@ struct table_cell char *text; /* A paragraph of text. */ char **subscripts; size_t n_subscripts; - const struct footnote **footnotes; + struct footnote **footnotes; size_t n_footnotes; - const struct table_area_style *style; + struct table_area_style *style; }; +struct table_cell *table_cell_clone (const struct table_cell *); +void table_cell_destroy (struct table_cell *); + void table_cell_format_footnote_markers (const struct table_cell *, struct string *); @@ -94,7 +97,6 @@ table_cell_is_joined (const struct table_cell *cell) void table_get_cell (const struct table *, int x, int y, struct table_cell *); int table_get_rule (const struct table *, enum table_axis, int x, int y, struct cell_color *); -size_t table_collect_footnotes (const struct table_item *, - const struct footnote ***); +size_t table_collect_footnotes (const struct table_item *, struct footnote ***); #endif /* output/table-provider.h */ diff --git a/src/output/table.c b/src/output/table.c index 5087441224..d910f8a8ba 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -103,13 +103,13 @@ table_cell_format_footnote_markers (const struct table_cell *cell, } } -static const struct footnote ** -add_footnotes (const struct footnote **refs, size_t n_refs, - const struct footnote **footnotes, size_t *allocated, size_t *n) +static struct footnote ** +add_footnotes (struct footnote **refs, size_t n_refs, + struct footnote **footnotes, size_t *allocated, size_t *n) { for (size_t i = 0; i < n_refs; i++) { - const struct footnote *f = refs[i]; + struct footnote *f = refs[i]; if (f->idx >= *allocated) { size_t new_allocated = (f->idx + 1) * 2; @@ -126,9 +126,9 @@ add_footnotes (const struct footnote **refs, size_t n_refs, size_t table_collect_footnotes (const struct table_item *item, - const struct footnote ***footnotesp) + struct footnote ***footnotesp) { - const struct footnote **footnotes = NULL; + struct footnote **footnotes = NULL; size_t allocated = 0; size_t n = 0; @@ -661,8 +661,7 @@ table_create_footnote (struct table *table, size_t idx, const char *content, /* Attaches a reference to footnote F to the cell at column X, row Y in TABLE. */ void -table_add_footnote (struct table *table, int x, int y, - const struct footnote *f) +table_add_footnote (struct table *table, int x, int y, struct footnote *f) { assert (f->style); @@ -680,7 +679,7 @@ table_add_footnote (struct table *table, int x, int y, TABLE->container or have a lifetime that will outlive TABLE. */ void table_add_style (struct table *table, int x, int y, - const struct table_area_style *style) + struct table_area_style *style) { get_joined_cell (table, x, y)->style = style; } @@ -707,7 +706,7 @@ table_get_cell (const struct table *t, int x, int y, struct table_cell *cell) unsigned short opt = t->ct[index]; const void *cc = t->cc[index]; - const struct table_area_style *style + struct table_area_style *style = t->styles[(opt & TAB_STYLE_MASK) >> TAB_STYLE_SHIFT]; if (opt & TAB_JOIN) { diff --git a/src/output/table.h b/src/output/table.h index 07c88874c8..ec4335a5d4 100644 --- a/src/output/table.h +++ b/src/output/table.h @@ -276,11 +276,9 @@ struct footnote *table_create_footnote (struct table *, size_t idx, const char *content, const char *marker, struct table_area_style *); -void table_add_footnote (struct table *, int x, int y, - const struct footnote *); +void table_add_footnote (struct table *, int x, int y, struct footnote *); -void table_add_style (struct table *, int x, int y, - const struct table_area_style *); +void table_add_style (struct table *, int x, int y, struct table_area_style *); bool table_cell_is_empty (const struct table *, int c, int r); diff --git a/src/output/tex.c b/src/output/tex.c index bd1bbc0aba..15540cd1e2 100644 --- a/src/output/tex.c +++ b/src/output/tex.c @@ -378,8 +378,8 @@ tex_submit (struct output_driver *driver, static void tex_put_footnote_markers (struct tex_driver *tex, - const struct footnote **footnotes, - size_t n_footnotes) + struct footnote **footnotes, + size_t n_footnotes) { if (n_footnotes > 0) shipout (&tex->token_list, "$^{"); @@ -418,7 +418,7 @@ tex_output_table (struct tex_driver *tex, const struct table_item *item) tex_escape_string (tex, caption->content, false); shipout (&tex->token_list, "}\n\n"); } - const struct footnote **f; + struct footnote **f; size_t n_footnotes = table_collect_footnotes (item, &f); const struct table_item_text *title = table_item_get_title (item); diff --git a/tests/output/render-test.c b/tests/output/render-test.c index 0e07f87dc1..d9ca79603a 100644 --- a/tests/output/render-test.c +++ b/tests/output/render-test.c @@ -473,7 +473,9 @@ read_table (FILE *stream) { table_joint_text (tab, c, r, c + cs - 1, r + rs - 1, 0, content); - table_add_style (tab, c, r, style); + table_add_style (tab, c, r, + CONST_CAST (struct table_area_style *, + style)); } else {