table-provider: Remove "const" from struct table_cell members.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 29 Dec 2020 07:33:30 +0000 (23:33 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 1 Jan 2021 19:15:05 +0000 (11:15 -0800)
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.

src/output/csv.c
src/output/html.c
src/output/render.c
src/output/table-item.h
src/output/table-provider.h
src/output/table.c
src/output/table.h
src/output/tex.c
tests/output/render-test.c

index e5b47a06ef0b7c0e1c35517d96338062073c0975..6ff61382d2519de749e5f2b98e0eea3eefba3846 100644 (file)
@@ -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)
         {
index 9a803d1ab0814f8ae3507aa2f74d8edb88002dbb..31fa063f519b24b19806ffa11657960e7ca61f21 100644 (file)
@@ -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++)
index 21fd53dc91a565b7c582dc18836490a9c2f4683a..41daea37e002c55580d91d00cb6c44c1fb4e7303 100644 (file)
@@ -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;
index e4c40ab228c5ce959a90c828053cb70f24150528..d1c30b668d603df5b4f2b0be3eaa1074669fc022 100644 (file)
@@ -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;
   };
 
index 8cac97a6d9b8363e2c0c56bdd14be60397db76af..2b14c98d1c29e9838b8550d621c2cd7d6ac229ef 100644 (file)
@@ -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 */
index 2691b79e0dbebee7e2afd4a47188ee3bc8b69d94..090625ff70999d8c6feaec8a176e638537fa2c77 100644 (file)
@@ -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;
 }
@@ -704,7 +703,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)
     {
index 85d063e8b6f730fda5e8957dfdeb9eec1da30385..a212aa4be2e3c7e09425911480daeb95d12648dd 100644 (file)
@@ -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);
 
index bd1bbc0aba8b954970d1bf8766aff61e38f742a0..15540cd1e28a411c617a90a48e4ff1cae60e3b33 100644 (file)
@@ -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);
index 0e07f87dc16f6ef8e3ce9ebf97196ca37c525127..d9ca79603ac0e1ec864c616f7274dde6d810e88c 100644 (file)
@@ -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
               {