projects
/
pspp-builds.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
d6ea5a0
)
csv: Open output file immediately, instead of delaying.
author
Ben Pfaff
<blp@gnu.org>
Thu, 4 Feb 2010 04:13:36 +0000
(20:13 -0800)
committer
Ben Pfaff
<blp@gnu.org>
Sat, 6 Feb 2010 04:14:18 +0000
(20:14 -0800)
src/output/csv.c
patch
|
blob
|
history
diff --git
a/src/output/csv.c
b/src/output/csv.c
index 158c78952233282e4580d1f5814f80f498c27db8..4b99772d42417d04a9ee1a3668ed943531567aa3 100644
(file)
--- a/
src/output/csv.c
+++ b/
src/output/csv.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009
, 2010
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
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
@@
-42,10
+42,9
@@
struct csv_driver
struct output_driver driver;
char *separator; /* Comma or tab. */
struct output_driver driver;
char *separator; /* Comma or tab. */
-
char *file_name; /* Output file name. */
FILE *file; /* Output file. */
char *file_name; /* Output file name. */
FILE *file; /* Output file. */
-
bool reported_error; /* Reported file open error?
*/
+
int n_items; /* Number of items output so far.
*/
};
static struct csv_driver *
};
static struct csv_driver *
@@
-75,8
+74,15
@@
csv_create (const char *name, enum output_device_type device_type,
csv->separator = parse_string (opt (d, o, "separator", ","));
csv->file_name = parse_string (opt (d, o, "output-file", "pspp.csv"));
csv->separator = parse_string (opt (d, o, "separator", ","));
csv->file_name = parse_string (opt (d, o, "output-file", "pspp.csv"));
- csv->file = NULL;
- csv->reported_error = false;
+ csv->file = fn_open (csv->file_name, "w");
+ csv->n_items = 0;
+
+ if (csv->file == NULL)
+ {
+ error (0, errno, _("csv: opening output file \"%s\""), csv->file_name);
+ output_driver_destroy (d);
+ return NULL;
+ }
return d;
}
return d;
}
@@
-142,25
+148,11
@@
csv_output_field_format (FILE *file, const char *format, ...)
free (s);
}
free (s);
}
-static
bool
-csv_
open_file
(struct csv_driver *csv)
+static
void
+csv_
put_separator
(struct csv_driver *csv)
{
{
- if (csv->file == NULL)
- {
- csv->file = fn_open (csv->file_name, "w");
- if (csv->file == NULL)
- {
- if (!csv->reported_error)
- error (0, errno, _("csv: opening output file \"%s\""),
- csv->file_name);
- csv->reported_error = true;
- return false;
- }
- }
- else
+ if (csv->n_items++ > 0)
putc ('\n', csv->file);
putc ('\n', csv->file);
-
- return true;
}
static void
}
static void
@@
-176,8
+168,7
@@
csv_submit (struct output_driver *driver,
const struct table *t = table_item_get_table (table_item);
int x, y;
const struct table *t = table_item_get_table (table_item);
int x, y;
- if (!csv_open_file (csv))
- return;
+ csv_put_separator (csv);
if (caption != NULL)
{
if (caption != NULL)
{
@@
-216,7
+207,7
@@
csv_submit (struct output_driver *driver,
|| type == TEXT_ITEM_SYNTAX)
return;
|| type == TEXT_ITEM_SYNTAX)
return;
- csv_
open_file
(csv);
+ csv_
put_separator
(csv);
switch (type)
{
case TEXT_ITEM_TITLE:
switch (type)
{
case TEXT_ITEM_TITLE: