output: Make default output file name depend on the format.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 24 Nov 2012 20:03:42 +0000 (12:03 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 24 Nov 2012 20:03:42 +0000 (12:03 -0800)
Before this commit, "-O html" caused HTML output to be written to a file
named "-", which is confusing.  After this commit, it is written to a file
named "pspp.html".  Similarly for other output drivers, except that text
and CSV output are still written to stdout by default.

Bug #35030.
Reported by John Darrington.

doc/invoking.texi
src/output/ascii.c
src/output/cairo.c
src/output/csv.c
src/output/driver-provider.h
src/output/driver.c
src/output/html.c
src/output/odt.c

index f327b1cc5ee15916d1b82c7cb27741cbda24a20e..24259a5808e2d0a101fbaf4acc58a1264319c334 100644 (file)
@@ -86,8 +86,9 @@ produce multiple output files, presumably in different formats.
 
 Use @samp{-} as @var{output-file} to write output to standard output.
 
-If no @option{-o} option is used, then @pspp{} writes output to standard
-output in plain text format.
+If no @option{-o} option is used, then @pspp{} writes text and CSV
+output to standard output and other kinds of output to whose name is
+based on the format, e.g.@: @file{pspp.pdf} for PDF output.
 
 @item @option{-O @var{option}=@var{value}}
 Sets an option for the output file configured by a preceding
index 1688fd1bf1217c8e0df48109eb64df2f7a45f1d9..9614e6aef899d88353142f7f1827a7a9ad5462d1 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2011, 2012 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
@@ -593,9 +593,9 @@ ascii_submit (struct output_driver *driver,
 }
 
 const struct output_driver_factory txt_driver_factory =
-  { "txt", ascii_create };
+  { "txt", "-", ascii_create };
 const struct output_driver_factory list_driver_factory =
-  { "list", ascii_create };
+  { "list", "-", ascii_create };
 
 static const struct output_driver_class ascii_driver_class =
   {
index 954ae30f5448b40ecfb3bd0bd5691e9a8f9cd4d7..cd8f0b0e999decb2ae1434463885c045ae827600 100644 (file)
@@ -922,9 +922,12 @@ xr_draw_title (struct xr_driver *xr, const char *title,
   xr_draw_cell (xr, &cell, bb, bb);
 }
 \f
-struct output_driver_factory pdf_driver_factory = { "pdf", xr_pdf_create };
-struct output_driver_factory ps_driver_factory = { "ps", xr_ps_create };
-struct output_driver_factory svg_driver_factory = { "svg", xr_svg_create };
+struct output_driver_factory pdf_driver_factory =
+  { "pdf", "pspp.pdf", xr_pdf_create };
+struct output_driver_factory ps_driver_factory =
+  { "ps", "pspp.ps", xr_ps_create };
+struct output_driver_factory svg_driver_factory =
+  { "svg", "pspp.svg", xr_svg_create };
 
 static const struct output_driver_class cairo_driver_class =
 {
index c8619a9a7d403ebc84ebc55d9c307976a49b734b..b57eb7c2d04eb7cdfb0e478a771d0495288de362 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2012 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
@@ -255,7 +255,7 @@ csv_submit (struct output_driver *driver,
     }
 }
 
-struct output_driver_factory csv_driver_factory = { "csv", csv_create };
+struct output_driver_factory csv_driver_factory = { "csv", "-", csv_create };
 
 static const struct output_driver_class csv_driver_class =
   {
index df31637379b070cf3c5ddf5b90c4f9948f1f4b91..012a304e36ac46cf58dfcb66fc5533cbb8b81af3 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2007, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2012 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
@@ -80,6 +80,12 @@ struct output_driver_factory
     /* The file extension, without the leading dot, e.g. "pdf". */
     const char *extension;
 
+    /* The default file name, including extension.
+
+       If this is "-", that implies that by default output will be directed to
+       stdout. */
+    const char *default_file_name;
+
     /* Creates a new output driver of this class.  NAME and TYPE should be
        passed directly to output_driver_init.  Returns the new output driver if
        successful, otherwise a null pointer.
index acc58cf999cdd7b77d533f54edc9ce17db954550..f656845527f4603937ebd02d6698a37865b041cf 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2011, 2012 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
@@ -294,16 +294,23 @@ output_driver_create (struct string_map *options)
   char *file_name;
   char *format;
 
+  format = string_map_find_and_delete (options, "format");
   file_name = string_map_find_and_delete (options, "output-file");
-  if (file_name == NULL)
-    file_name = xstrdup ("-");
 
-  format = string_map_find_and_delete (options, "format");
   if (format == NULL)
     {
-      const char *extension = strrchr (file_name, '.');
-      format = xstrdup (extension != NULL ? extension + 1 : "");
+      if (file_name != NULL)
+        {
+          const char *extension = strrchr (file_name, '.');
+          format = xstrdup (extension != NULL ? extension + 1 : "");
+        }
+      else
+        format = xstrdup ("txt");
     }
+  f = find_factory (format);
+
+  if (file_name == NULL)
+    file_name = xstrdup (f->default_file_name);
 
   /* XXX should use parse_enum(). */
   device_string = string_map_find_and_delete (options, "device");
@@ -320,7 +327,6 @@ output_driver_create (struct string_map *options)
       device_type = default_device_type (file_name);
     }
 
-  f = find_factory (format);
   driver = f->create (file_name, device_type, options);
   if (driver != NULL)
     {
index 77d4195f30c2a2e5319a8192701736964c2feb51..29a44721d455ae3f0336e1f95d52610e9c5df1c1 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 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
@@ -477,7 +477,8 @@ html_output_table (struct html_driver *html, struct table_item *item)
   fputs ("</TABLE>\n\n", html->file);
 }
 
-struct output_driver_factory html_driver_factory = { "html", html_create };
+struct output_driver_factory html_driver_factory =
+  { "html", "pspp.html", html_create };
 
 static const struct output_driver_class html_driver_class =
   {
index 686e7149c3b68b34002308e1147c3ebbd08eb756..a02506c1e9eeacbae9528aa663e55044e8194055 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2011, 2012 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
@@ -517,7 +517,8 @@ odt_submit (struct output_driver *driver,
     }
 }
 
-struct output_driver_factory odt_driver_factory = { "odt", odt_create };
+struct output_driver_factory odt_driver_factory =
+  { "odt", "pspp.odf", odt_create };
 
 static const struct output_driver_class odt_driver_class =
 {