work toward getting rid of struct table in table_item
[pspp] / src / output / pivot-table.c
index afa306e30ff9607ffca429ade31a88c29a353b73..96dd9d2413abaac75fd58a251a2aa41ef46c8a96 100644 (file)
@@ -370,7 +370,8 @@ pivot_axis_iterator_next (size_t *indexes, const struct pivot_axis *axis)
           if (axis->dimensions[i]->n_leaves == 0)
             return NULL;
 
-      return xcalloc (axis->n_dimensions, sizeof *indexes);
+      size_t size = axis->n_dimensions * sizeof *indexes;
+      return xzalloc (MAX (size, 1));
     }
 
   for (size_t i = 0; i < axis->n_dimensions; i++)
@@ -993,6 +994,25 @@ pivot_table_is_empty (const struct pivot_table *table)
   return hmap_is_empty (&table->cells);
 }
 
+size_t *
+pivot_table_next_display_layer (const struct pivot_table *pt, size_t *indexes,
+                                bool print)
+{
+  const struct pivot_axis *layer_axis = &pt->axes[PIVOT_AXIS_LAYER];
+  if (print && pt->look->print_all_layers)
+    return pivot_axis_iterator_next (indexes, layer_axis);
+  else if (!indexes)
+    {
+      size_t size = layer_axis->n_dimensions * sizeof *pt->current_layer;
+      return xmemdup (pt->current_layer, MAX (size, 1));
+    }
+  else
+    {
+      free (indexes);
+      return NULL;
+    }
+}
+
 static unsigned int
 pivot_cell_hash_indexes (const size_t *indexes, size_t n_idx)
 {