From 7b3ea5147198695be27b2646548c11ac92d63129 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 11 Oct 2019 05:09:13 +0000 Subject: [PATCH] table: Make table_collect_footnotes() not return NULL footnotes. This simplifies the callers a bit. --- src/output/csv.c | 13 ++++++------- src/output/html.c | 19 +++++++++---------- src/output/render.c | 19 +++++++++---------- src/output/table.c | 7 ++++++- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/output/csv.c b/src/output/csv.c index 65566c4e3a..9c70a45158 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -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); } diff --git a/src/output/html.c b/src/output/html.c index 1027dea501..806e632014 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -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 ("", 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); + 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), + " ", "
"); + } free (f); if (tfoot) fputs ("\n", html->file); diff --git a/src/output/render.c b/src/output/render.c index 4c98ad0fd9..636568f4ee 100644 --- a/src/output/render.c +++ b/src/output/render.c @@ -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); diff --git a/src/output/table.c b/src/output/table.c index 8f717ead56..86b7bc474f 100644 --- a/src/output/table.c +++ b/src/output/table.c @@ -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; } /* Returns a table that contains a single cell, whose contents are the -- 2.30.2