|
From: Ethan A M. <merritt@u.washington.edu> - 2006-03-05 22:07:35
|
On Sunday 05 March 2006 12:00 pm, you wrote:
> >> The routine fileexist() is for files only; it makes no sense for pipes.
> >> For pipes, do
> >> if (fileexist('a.dat')) plot '<tr . , a.dat'
> >
> > Sure. But that is only possible if you already know whether it is a
> > pipe or not. What about the case where you want to put the
> > fileexist() test in a loadable routine that is passed the filename
> > string as a parameter?
>
> Then it needs yet another routine pipeexist().
I think you are making these tests way too specific.
Wouldn't it be better to duplicate the code that would actually
be used to open the file while plotting?
Trimmed from lines 1240-1280 of datafile.c:
=========================================================================
/* filename cannot be static array! */
gp_expand_tilde(&df_filename);
/*{{{ open file */
if (*df_filename == '<') {
if ((data_fp = popen(df_filename + 1, "r")) == (FILE *) NULL)
os_error(name_token, "cannot create pipe for data");
} else if (*df_filename == '-' && strlen(df_filename) == 1) {
plotted_data_from_stdin = TRUE;
} else {
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);
}
if (!(data_fp = loadpath_fopen(df_filename, df_binary ? "rb" : "r"))
os_error(name_token, "can't read data file \"%s\"", df_filename);
}
=========================================================================
--
Ethan A Merritt
Biomolecular Structure Center
University of Washington, Seattle 98195-7742
|