+ ds_put_cstr (s, field);
+}
+
+static void
+csv_output_subtable (struct csv_driver *csv, struct string *s,
+ const struct table *t)
+{
+ int y, x;
+
+ for (y = 0; y < table_nr (t); y++)
+ {
+ if (y > 0)
+ ds_put_byte (s, '\n');
+
+ for (x = 0; x < table_nc (t); x++)
+ {
+ struct table_cell cell;
+
+ table_get_cell (t, x, y, &cell);
+
+ if (x > 0)
+ ds_put_cstr (s, csv->separator);
+
+ if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
+ csv_put_field (csv, s, "");
+ else if (cell.n_contents == 1 && cell.contents[0].text != NULL)
+ csv_put_field (csv, s, cell.contents[0].text);
+ else
+ {
+ struct string s2;
+ size_t i;
+
+ ds_init_empty (&s2);
+ for (i = 0; i < cell.n_contents; i++)
+ {
+ if (i > 0)
+ ds_put_cstr (&s2, "\n\n");
+
+ if (cell.contents[i].text != NULL)
+ ds_put_cstr (&s2, cell.contents[i].text);
+ else
+ csv_output_subtable (csv, &s2, cell.contents[i].table);
+ }
+ csv_put_field (csv, s, ds_cstr (&s2));
+ ds_destroy (&s2);
+ }
+
+ table_cell_free (&cell);
+ }
+ }