render: Render table_items instead of tables.
[pspp] / src / output / csv.c
index 9be53c8b0f0c92716fc0fe397e23289f7c0a0847..bd61c51a62e63175b66cacd3dc69a6a5e24dd08d 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009, 2010, 2012, 2013 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2012, 2013, 2014 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -147,6 +147,20 @@ csv_output_field (struct csv_driver *csv, const char *field)
     fputs (field, csv->file);
 }
 
+static void PRINTF_FORMAT (2, 3)
+csv_output_field_format (struct csv_driver *csv, const char *format, ...)
+{
+  va_list args;
+  char *s;
+
+  va_start (args, format);
+  s = xvasprintf (format, args);
+  va_end (args);
+
+  csv_output_field (csv, s);
+  free (s);
+}
+
 static void
 csv_put_field (struct csv_driver *csv, struct string *s, const char *field)
 {
@@ -172,10 +186,18 @@ csv_put_field (struct csv_driver *csv, struct string *s, const char *field)
 
 static void
 csv_output_subtable (struct csv_driver *csv, struct string *s,
-                     const struct table *t)
+                     const struct table_item *item)
 {
+  const struct table *t = table_item_get_table (item);
+  const char *caption = table_item_get_caption (item);
   int y, x;
 
+  if (csv->captions && caption != NULL)
+    {
+      csv_output_field_format (csv, "Table: %s", caption);
+      putc ('\n', csv->file);
+    }
+
   for (y = 0; y < table_nr (t); y++)
     {
       if (y > 0)
@@ -219,24 +241,6 @@ csv_output_subtable (struct csv_driver *csv, struct string *s,
     }
 }
 
-static void
-csv_output_field_format (struct csv_driver *csv, const char *format, ...)
-  PRINTF_FORMAT (2, 3);
-
-static void
-csv_output_field_format (struct csv_driver *csv, const char *format, ...)
-{
-  va_list args;
-  char *s;
-
-  va_start (args, format);
-  s = xvasprintf (format, args);
-  va_end (args);
-
-  csv_output_field (csv, s);
-  free (s);
-}
-
 static void
 csv_put_separator (struct csv_driver *csv)
 {