Mercurial > hg > octave-nkf
diff libinterp/corefcn/utils.cc @ 19222:9ef10e6a5987
make "file found in path" warnings consistent
* gripes.h, gripes.cc (gripe_data_file_in_path): New function.
* utils.h, utils.cc (find_data_file_in_path): New function. Use
gripe_data_file_in_path to warn.
* file-io.cc (do_stream_open): Call find_data_file_in_path to search
path for file.
* load-save.cc (find_file_to_load): Likewise.
* md5sum.cc (Fmd5sum): Likewise.
* octave.cc (maximum_braindamage): Disable new
Octave:data-file-in-path warning ID instead of
Octave:fopen-file-in-path and Octave:load-file-in-path.
* NEWS: Note change.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 19 Aug 2014 06:40:53 -0400 |
parents | 9ac2357f19bc |
children | 4990d5988cf5 |
line wrap: on
line diff
--- a/libinterp/corefcn/utils.cc +++ b/libinterp/corefcn/utils.cc @@ -452,6 +452,44 @@ return octave_env::make_absolute (load_path::find_file (nm)); } +std::string +find_data_file_in_load_path (const std::string& fcn, + const std::string& file, + bool require_regular_file) +{ + std::string fname = file; + + if (! (octave_env::absolute_pathname (fname) + || octave_env::rooted_relative_pathname (fname))) + { + // Load path will also search "." first, but we don't want to + // issue a warning if the file is found in the current directory, + // so do an explicit check for that. + + file_stat fs (fname); + + bool local_file_ok + = fs.exists () && (fs.is_reg () || ! require_regular_file); + + if (! local_file_ok) + { + // Not directly found; search load path. + + std::string tmp + = octave_env::make_absolute (load_path::find_file (fname)); + + if (! tmp.empty ()) + { + gripe_data_file_in_path (fcn, tmp); + + fname = tmp; + } + } + } + + return fname; +} + // See if there is an function file in the path. If so, return the // full path to the file.