table: Make table_collect_footnotes() not return NULL footnotes.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 11 Oct 2019 05:09:13 +0000 (05:09 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 29 Dec 2019 05:28:10 +0000 (05:28 +0000)
This simplifies the callers a bit.

src/output/csv.c
src/output/html.c
src/output/render.c
src/output/table.c

index 65566c4e3a624a2ba5b02589438b019e52624e0c..9c70a4515899dcda1570cecbdd8a297e00698ee8 100644 (file)
@@ -263,13 +263,12 @@ csv_submit (struct output_driver *driver,
           fputs ("\nFootnotes:\n", csv->file);
 
           for (size_t i = 0; i < n_footnotes; i++)
-            if (f[i])
-              {
-                csv_output_field (csv, f[i]->marker);
-                fputs (csv->separator, csv->file);
-                csv_output_field (csv, f[i]->content);
-                putc ('\n', csv->file);
-              }
+            {
+              csv_output_field (csv, f[i]->marker);
+              fputs (csv->separator, csv->file);
+              csv_output_field (csv, f[i]->content);
+              putc ('\n', csv->file);
+            }
 
           free (f);
         }
index 1027dea501037e5e74655ecb0a4d76b7c2357280..806e6320145dbfbdd4efc4229bc0a033393a0c95 100644 (file)
@@ -438,16 +438,15 @@ 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 ("<SUP>", html->file);
-        escape_string (html->file, f[i]->marker, strlen (f[i]->marker),
-                       " ", "<BR>");
-        fputs ("</SUP> ", html->file);
-        escape_string (html->file, f[i]->content, strlen (f[i]->content),
-                       " ", "<BR>");
-      }
+    {
+      put_tfoot (html, t, &tfoot);
+      fputs ("<SUP>", html->file);
+      escape_string (html->file, f[i]->marker, strlen (f[i]->marker),
+                     " ", "<BR>");
+      fputs ("</SUP> ", html->file);
+      escape_string (html->file, f[i]->content, strlen (f[i]->content),
+                     " ", "<BR>");
+    }
   free (f);
   if (tfoot)
     fputs ("</TD></TR></TFOOT>\n", html->file);
index 4c98ad0fd9e6335334d7a4607847a2445b57ba53..636568f4eedd6bcf0f53b78b6b8cb8932e75fe33 100644 (file)
@@ -1517,16 +1517,15 @@ add_footnote_page (struct render_pager *p, const struct table_item *item)
   struct tab_table *t = tab_create (2, n_footnotes);
 
   for (size_t i = 0; i < n_footnotes; i++)
-    if (f[i])
-      {
-        tab_text_format (t, 0, i, TAB_LEFT, "%s.", f[i]->marker);
-        tab_text (t, 1, i, TAB_LEFT, f[i]->content);
-        if (f[i]->style)
-          {
-            tab_add_style (t, 0, i, f[i]->style);
-            tab_add_style (t, 1, i, f[i]->style);
-          }
-      }
+    {
+      tab_text_format (t, 0, i, TAB_LEFT, "%s.", f[i]->marker);
+      tab_text (t, 1, i, TAB_LEFT, f[i]->content);
+      if (f[i]->style)
+        {
+          tab_add_style (t, 0, i, f[i]->style);
+          tab_add_style (t, 1, i, f[i]->style);
+        }
+    }
   render_pager_add_table (p, &t->table, 0);
 
   free (f);
index 8f717ead5679359b4f5c8529811e7b731d9c307d..86b7bc474fef918462bdb2a7ca982d64ff9a221a 100644 (file)
@@ -294,8 +294,13 @@ table_collect_footnotes (const struct table_item *item,
     footnotes = add_footnotes (caption->footnotes, caption->n_footnotes,
                                footnotes, &allocated, &n);
 
+  size_t n_nonnull = 0;
+  for (size_t i = 0; i < n; i++)
+    if (footnotes[i])
+      footnotes[n_nonnull++] = footnotes[i];
+
   *footnotesp = footnotes;
-  return n;
+  return n_nonnull;
 }
 \f
 /* Returns a table that contains a single cell, whose contents are the