# HG changeset patch # User John W. Eaton # Date 1408444853 14400 # Node ID 9ef10e6a5987d840c4656d5f34825c0ee4e3535d # Parent 8c648c3a2c8f22000baee343baf060c079acee69 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. diff -r 8c648c3a2c8f -r 9ef10e6a5987 NEWS --- a/NEWS Mon Aug 18 20:46:07 2014 -0700 +++ b/NEWS Tue Aug 19 06:40:53 2014 -0400 @@ -54,6 +54,10 @@ To unlink properties use 'clear hlink' where hlink is the variable containing the linkprop object. + ** The new warning ID "Octave:data-file-in-path" replaces the three + previous separate warning IDs "Octave:fopen-file-in-path", + "Octave:load-file-in-path", and "Octave:md5sum-file-in-path". + ** Other new functions added in 4.2: bandwidth isbanded javachk diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/corefcn/file-io.cc Tue Aug 19 06:40:53 2014 -0400 @@ -500,23 +500,8 @@ file_stat fs (fname); - if (! (md & std::ios::out - || octave_env::absolute_pathname (fname) - || octave_env::rooted_relative_pathname (fname))) - { - if (! fs.exists ()) - { - std::string tmp - = octave_env::make_absolute (load_path::find_file (fname)); - - if (! tmp.empty ()) - { - warning_with_id ("Octave:fopen-file-in-path", - "fopen: file found in load path"); - fname = tmp; - } - } - } + if (! (md & std::ios::out)) + fname = find_data_file_in_load_path ("fopen", fname); if (! fs.is_dir ()) { diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/corefcn/gripes.cc --- a/libinterp/corefcn/gripes.cc Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/corefcn/gripes.cc Tue Aug 19 06:40:53 2014 -0400 @@ -245,3 +245,11 @@ error ("%s: support for %s was disabled when %s was built", func.c_str (), feature.c_str (), pkg.c_str ()); } + +void +gripe_data_file_in_path (const std::string& fcn, const std::string& file) +{ + warning_with_id ("Octave:data-file-in-path", + "%s: '%s' found by searching load path", + fcn.c_str (), file.c_str ()); +} diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/corefcn/gripes.h --- a/libinterp/corefcn/gripes.h Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/corefcn/gripes.h Tue Aug 19 06:40:53 2014 -0400 @@ -131,4 +131,8 @@ extern OCTINTERP_API void gripe_disabled_feature (const std::string& func, const std::string& feature, const std::string& pkg="Octave"); + +extern OCTINTERP_API void +gripe_data_file_in_path (const std::string& fcn, const std::string& file); + #endif diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/corefcn/load-save.cc --- a/libinterp/corefcn/load-save.cc Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/corefcn/load-save.cc Tue Aug 19 06:40:53 2014 -0400 @@ -498,33 +498,7 @@ std::string find_file_to_load (const std::string& name, const std::string& orig_name) { - std::string fname = name; - - 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); - - if (! (fs.exists () && fs.is_reg ())) - { - // Not directly found; search load path. - - std::string tmp - = octave_env::make_absolute (load_path::find_file (fname)); - - if (! tmp.empty ()) - { - warning_with_id ("Octave:load-file-in-path", - "load: file found in load path: %s", - tmp.c_str ()); - fname = tmp; - } - } - } + std::string fname = find_data_file_in_load_path ("load", name, true); size_t dot_pos = fname.rfind ("."); size_t sep_pos = fname.find_last_of (file_ops::dir_sep_chars ()); diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/corefcn/md5sum.cc --- a/libinterp/corefcn/md5sum.cc Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/corefcn/md5sum.cc Tue Aug 19 06:40:53 2014 -0400 @@ -31,10 +31,10 @@ #include "defun.h" #include "file-stat.h" #include "file-ops.h" -#include "gripes.h" #include "load-path.h" #include "oct-env.h" #include "oct-md5.h" +#include "utils.h" DEFUN (md5sum, args, , "-*- texinfo -*-\n\ @@ -64,22 +64,11 @@ retval = oct_md5 (str); else { - file_stat fs (str); - - if (! fs.exists ()) - { - std::string tmp - = octave_env::make_absolute (load_path::find_file (str)); + std::string fname = file_ops::tilde_expand (str); - if (! tmp.empty ()) - { - warning_with_id ("Octave:md5sum-file-in-path", - "md5sum: file found in load path"); - str = tmp; - } - } + fname = find_data_file_in_load_path ("md5sum", fname); - retval = oct_md5_file (str); + retval = oct_md5_file (fname); } } } diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/corefcn/utils.cc --- a/libinterp/corefcn/utils.cc Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/corefcn/utils.cc Tue Aug 19 06:40:53 2014 -0400 @@ -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. diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/corefcn/utils.h --- a/libinterp/corefcn/utils.h Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/corefcn/utils.h Tue Aug 19 06:40:53 2014 -0400 @@ -66,6 +66,11 @@ extern OCTINTERP_API std::string file_in_path (const std::string&, const std::string&); +extern OCTINTERP_API std::string +find_data_file_in_load_path (const std::string& fcn, + const std::string& file, + bool require_regular_file = false); + extern OCTINTERP_API std::string contents_file_in_path (const std::string&); extern OCTINTERP_API std::string fcn_file_in_path (const std::string&); diff -r 8c648c3a2c8f -r 9ef10e6a5987 libinterp/octave.cc --- a/libinterp/octave.cc Mon Aug 18 20:46:07 2014 -0700 +++ b/libinterp/octave.cc Tue Aug 19 06:40:53 2014 -0400 @@ -494,9 +494,8 @@ Fstruct_levels_to_print (octave_value (0)); disable_warning ("Octave:abbreviated-property-match"); - disable_warning ("Octave:fopen-file-in-path"); + disable_warning ("Octave:data-file-in-path"); disable_warning ("Octave:function-name-clash"); - disable_warning ("Octave:load-file-in-path"); disable_warning ("Octave:possible-matlab-short-circuit-operator"); }