pspp-output: Add new --nth-commands option.
[pspp] / src / output / csv.c
index 65566c4e3a624a2ba5b02589438b019e52624e0c..1c6662793fc3fafd5c40f83d3a668f700e32bc8d 100644 (file)
@@ -227,7 +227,8 @@ csv_submit (struct output_driver *driver,
 
               if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
                 csv_output_field (csv, "");
-              else if (!(cell.options & TAB_MARKUP) && !cell.n_footnotes)
+              else if (!(cell.options & TAB_MARKUP) && !cell.n_footnotes
+                       && !cell.n_subscripts && !cell.superscript)
                 csv_output_field (csv, cell.text);
               else
                 {
@@ -242,12 +243,16 @@ csv_submit (struct output_driver *driver,
                   else
                     ds_put_cstr (&s, cell.text);
 
+                  if (cell.n_subscripts)
+                    for (size_t i = 0; i < cell.n_subscripts; i++)
+                      ds_put_format (&s, "%c%s",
+                                     i ? ',' : '_', cell.subscripts[i]);
+                  if (cell.superscript)
+                    ds_put_format (&s, "^%s", cell.superscript);
                   csv_format_footnotes (cell.footnotes, cell.n_footnotes, &s);
                   csv_output_field (csv, ds_cstr (&s));
                   ds_destroy (&s);
                 }
-
-              table_cell_free (&cell);
             }
           putc ('\n', csv->file);
         }
@@ -263,13 +268,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);
         }