|
From: Daniel J S. <dan...@ie...> - 2006-03-05 19:56:59
|
Ethan Merritt wrote:
Well, the patch Ethan created is in the right area of datafile.c. In order to have the
Can't open data file "xxx"
take precedence over
Unsupported file type
I'd say it means rearranging the options string interpretation code and the code that opens the file in "df_open". That is simply the way it has traditionally been, I guess. Check options first then attempt opening file.
An easy change, but there needs to be care with one thing. If the file is opened first, then checked for options, any error in the options will leave an open file hanging around.
An alternative might be to move just this chunk of code:
#ifdef HAVE_SYS_STAT_H
struct stat statbuf;
if ((stat(df_filename, &statbuf) > -1) &&
!S_ISREG(statbuf.st_mode) && !S_ISFIFO(statbuf.st_mode)) {
os_error(name_token, "\"%s\" is not a regular file or pipe",
df_filename);
}
#endif /* HAVE_SYS_STAT_H */
which I think sort of checks the existence of the file without really opening it. And replace it with
#ifdef HAVE_SYS_STAT_H
struct stat statbuf;
if ((stat(df_filename, &statbuf) > -1) &&
!S_ISREG(statbuf.st_mode) && !S_ISFIFO(statbuf.st_mode)) {
os_error(name_token, "\"%s\" is not a regular file or pipe",
df_filename);
}
#else
if (<open fails>)
error("Can't open data file "xxx"");
else
close_file();
#endif /* HAVE_SYS_STAT_H */
Would that kind of thing work? That would mean if there is no "stat()" then the file would be opened and closed for checking existence (also check for emptiness?), then after options are checked opened again for reading.
Or would you prefer opening and keeping track of the file pointer and doing a "close" before each instance of "error()"?
Dan
> --- gnuplot/src/datafile.c 2006-01-27 08:36:48.000000000 -0800
> +++ gnuplot-cvs/src/datafile.c 2006-03-03 15:19:13.000000000 -0800
> @@ -1275,7 +1275,9 @@
> if ((data_fp = loadpath_fopen(df_filename, df_binary ? "rb" : "r")) ==
> #endif
> (FILE *) NULL) {
> - os_error(name_token, "can't read data file \"%s\"", df_filename);
> + /* os_error(name_token, "can't read data file \"%s\"", df_filename); */
> + int_warn(name_token, "Skipping unreadable file \"%s\"", df_filename);
> + return -1;
> }
> }
> /*}}} */
> --- gnuplot/src/plot2d.c 2005-11-28 11:02:56.000000000 -0800
> +++ gnuplot-cvs/src/plot2d.c 2006-03-03 15:33:24.000000000 -0800
> @@ -1787,6 +1787,11 @@
> ++line_num;
> }
> if (this_plot->plot_type == DATA) {
> + if (specs < 0) {
> + /* Error check to handle missing or unreadable file */
> + this_plot->plot_type = NODATA;
> + goto SKIPPED_EMPTY_FILE;
> + }
> /* actually get the data now */
> if (get_data(this_plot) == 0) {
> /* EAM 2005 - warn, but keep going */
> --- gnuplot/src/plot3d.c 2006-01-12 11:55:14.000000000 -0800
> +++ gnuplot-cvs/src/plot3d.c 2006-03-03 15:32:54.000000000 -0800
> @@ -1560,6 +1560,9 @@
> struct surface_points *first_dataset = this_plot;
> /* pointer to the plot of the first dataset (surface) in the file */
> int this_token = this_plot->token;
> + /* Error check to handle unreadable or missing data file */
> + if (specs < 0)
> + df_eof = 1;
> while (!df_eof) {
> this_plot = *tp_3d_ptr;
> assert(this_plot != NULL);
>
>
--
Dan Sebald
phone: 608 256 7718
email: daniel DOT sebald AT ieee DOT org
URL: http://webpages DOT charter DOT net/dsebald/
|