changeset 27395:4164895adf79

move octave_change_to_directory to octave namespace and make extern * dirfns.cc (octave_change_to_directory): Define in octave namespace as change_to_directory. * dirfns.h, (change_to_directory): Provide extern declaration.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Sep 2019 18:31:33 -0400
parents 489c74ac36da
children 930c0fbc003b
files libinterp/corefcn/dirfns.cc libinterp/corefcn/dirfns.h
diffstat 2 files changed, 31 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/dirfns.cc	Wed Sep 11 18:23:46 2019 -0400
+++ b/libinterp/corefcn/dirfns.cc	Wed Sep 11 18:31:33 2019 -0400
@@ -65,36 +65,38 @@
 // directory tree.
 static bool Vconfirm_recursive_rmdir = true;
 
-// The time we last time we changed directories.
-octave::sys::time Vlast_chdir_time = 0.0;
-
-static int
-octave_change_to_directory (const std::string& newdir)
+namespace octave
 {
-  std::string xdir = octave::sys::file_ops::tilde_expand (newdir);
+  // The time we last time we changed directories.
+  sys::time Vlast_chdir_time = 0.0;
 
-  int cd_ok = octave::sys::env::chdir (xdir);
+  int change_to_directory (const std::string& newdir)
+  {
+    std::string xdir = octave::sys::file_ops::tilde_expand (newdir);
 
-  if (! cd_ok)
-    error ("%s: %s", newdir.c_str (), std::strerror (errno));
+    int cd_ok = octave::sys::env::chdir (xdir);
 
-  Vlast_chdir_time.stamp ();
+    if (! cd_ok)
+      error ("%s: %s", newdir.c_str (), std::strerror (errno));
+
+    Vlast_chdir_time.stamp ();
 
-  // FIXME: should these actions be handled as a list of functions
-  // to call so users can add their own chdir handlers?
+    // FIXME: should these actions be handled as a list of functions
+    // to call so users can add their own chdir handlers?
 
-  octave::interpreter& interp
-    = octave::__get_interpreter__ ("octave_change_to_directory");
+    octave::interpreter& interp
+      = octave::__get_interpreter__ ("octave_change_to_directory");
 
-  octave::load_path& lp = interp.get_load_path ();
+    octave::load_path& lp = interp.get_load_path ();
 
-  lp.update ();
+    lp.update ();
 
-  octave::event_manager& evmgr = interp.get_event_manager ();
+    octave::event_manager& evmgr = interp.get_event_manager ();
 
-  evmgr.change_directory (octave::sys::env::get_current_directory ());
+    evmgr.change_directory (octave::sys::env::get_current_directory ());
 
-  return cd_ok;
+    return cd_ok;
+  }
 }
 
 DEFUN (cd, args, nargout,
@@ -143,14 +145,14 @@
       std::string dirname = args(0).xstring_value ("cd: DIR must be a string");
 
       if (! dirname.empty ())
-        octave_change_to_directory (dirname);
+        octave::change_to_directory (dirname);
     }
   else if (nargout == 0)
     {
       std::string home_dir = octave::sys::env::get_home_directory ();
 
       if (! home_dir.empty ())
-        octave_change_to_directory (home_dir);
+        octave::change_to_directory (home_dir);
     }
 
   return retval;
--- a/libinterp/corefcn/dirfns.h	Wed Sep 11 18:23:46 2019 -0400
+++ b/libinterp/corefcn/dirfns.h	Wed Sep 11 18:31:33 2019 -0400
@@ -31,7 +31,13 @@
 
 #include "oct-time.h"
 
-// The time we last time we changed directories.
-extern octave::sys::time Vlast_chdir_time;
+namespace octave
+{
+  // FIXME: this function should be a method in the interpreter class.
+  extern int change_to_directory (const std::string& newdir);
+
+  // The time we last time we changed directories.
+  extern sys::time Vlast_chdir_time;
+}
 
 #endif