output: Expand footnote support.
[pspp] / src / output / tab.c
index 78bde01e5dcb1a36de59556dbd7af5140919b8ae..dcd6fe29a2cc5590457dd937d67e73df84062892 100644 (file)
@@ -66,7 +66,7 @@ struct tab_joined_cell
     u;
 
   size_t n_footnotes;
-  char **footnotes;
+  const struct footnote **footnotes;
 };
 
 static const struct table_class tab_table_class;
@@ -99,13 +99,12 @@ tab_create (int nc, int nr)
   memset (t->ct, 0, nc * nr);
 
   t->rh = pool_nmalloc (t->container, nc, nr + 1);
-  memset (t->rh, 0, nc * (nr + 1));
+  memset (t->rh, TAL_0, nc * (nr + 1));
 
   t->rv = pool_nmalloc (t->container, nr, nc + 1);
-  memset (t->fmtmap, 0, sizeof (*t->fmtmap) * n_RC);
-
-  memset (t->rv, TAL_GAP, nr * (nc + 1));
+  memset (t->rv, TAL_0, nr * (nc + 1));
 
+  memset (t->fmtmap, 0, sizeof (*t->fmtmap) * n_RC);
   t->fmtmap[RC_PVALUE] = ugly[RC_PVALUE];
   t->fmtmap[RC_INTEGER] = ugly[RC_INTEGER];
   t->fmtmap[RC_OTHER] = *settings_get_format ();
@@ -204,7 +203,7 @@ tab_realloc (struct tab_table *t, int nc, int nr)
         {
           memset (&t->rh[nc * (tab_nr (t) + 1)], TAL_0,
                   (nr - tab_nr (t)) * nc);
-          memset (&t->rv[(nc + 1) * tab_nr (t)], TAL_GAP,
+          memset (&t->rv[(nc + 1) * tab_nr (t)], TAL_0,
                   (nr - tab_nr (t)) * (nc + 1));
         }
     }
@@ -594,7 +593,10 @@ tab_joint_text (struct tab_table *table, int x1, int y1, int x2, int y2,
                 unsigned opt, const char *text)
 {
   char *s = pool_strdup (table->container, text);
-  add_joined_cell (table, x1, y1, x2, y2, opt)->u.text = s;
+  if (x1 == x2 && y1 == y2)
+    do_tab_text (table, x1, y1, opt, s);
+  else
+    add_joined_cell (table, x1, y1, x2, y2, opt)->u.text = s;
 }
 
 /* Joins cells (X1,X2)-(Y1,Y2) inclusive in TABLE, and sets them
@@ -614,13 +616,24 @@ tab_joint_text_format (struct tab_table *table, int x1, int y1, int x2,
   add_joined_cell (table, x1, y1, x2, y2, opt)->u.text = s;
 }
 
+struct footnote *
+tab_create_footnote (struct tab_table *table, size_t idx, const char *content,
+                     const char *marker)
+{
+  struct footnote *f = pool_alloc (table->container, sizeof *f);
+  f->idx = idx;
+  f->content = pool_strdup (table->container, content);
+  f->marker = pool_strdup (table->container, marker);
+  return f;
+}
+
 void
-tab_footnote (struct tab_table *table, int x, int y, const char *format, ...)
+tab_add_footnote (struct tab_table *table, int x, int y,
+                  const struct footnote *f)
 {
   int index = x + y * table->cf;
   unsigned char opt = table->ct[index];
   struct tab_joined_cell *j;
-  va_list args;
 
   if (opt & TAB_JOIN)
     j = table->cc[index];
@@ -632,13 +645,10 @@ tab_footnote (struct tab_table *table, int x, int y, const char *format, ...)
       j->u.text = text ? text : xstrdup ("");
     }
 
-  j->footnotes = xrealloc (j->footnotes,
-                           (j->n_footnotes + 1) * sizeof *j->footnotes);
+  j->footnotes = pool_realloc (table->container, j->footnotes,
+                               (j->n_footnotes + 1) * sizeof *j->footnotes);
 
-  va_start (args, format);
-  j->footnotes[j->n_footnotes++] =
-    pool_vasprintf (table->container, format, args);
-  va_end (args);
+  j->footnotes[j->n_footnotes++] = f;
 }
 
 bool