From: Ben Pfaff Date: Sat, 24 Nov 2012 20:03:42 +0000 (-0800) Subject: output: Make default output file name depend on the format. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b51bc9abbb6ed4a34cf396883d1dc8479b1e554;p=pspp output: Make default output file name depend on the format. 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. --- diff --git a/doc/invoking.texi b/doc/invoking.texi index f327b1cc5e..24259a5808 100644 --- a/doc/invoking.texi +++ b/doc/invoking.texi @@ -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 diff --git a/src/output/ascii.c b/src/output/ascii.c index 1688fd1bf1..9614e6aef8 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -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 = { diff --git a/src/output/cairo.c b/src/output/cairo.c index 954ae30f54..cd8f0b0e99 100644 --- a/src/output/cairo.c +++ b/src/output/cairo.c @@ -922,9 +922,12 @@ xr_draw_title (struct xr_driver *xr, const char *title, xr_draw_cell (xr, &cell, bb, bb); } -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 = { diff --git a/src/output/csv.c b/src/output/csv.c index c8619a9a7d..b57eb7c2d0 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -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 = { diff --git a/src/output/driver-provider.h b/src/output/driver-provider.h index df31637379..012a304e36 100644 --- a/src/output/driver-provider.h +++ b/src/output/driver-provider.h @@ -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. diff --git a/src/output/driver.c b/src/output/driver.c index acc58cf999..f656845527 100644 --- a/src/output/driver.c +++ b/src/output/driver.c @@ -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) { diff --git a/src/output/html.c b/src/output/html.c index 77d4195f30..29a44721d4 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -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 ("\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 = { diff --git a/src/output/odt.c b/src/output/odt.c index 686e7149c3..a02506c1e9 100644 --- a/src/output/odt.c +++ b/src/output/odt.c @@ -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 = {