Mercurial > octave
diff libinterp/corefcn/interpreter.cc @ 27408:9b19eec60931
move change directory function to interpreter class
* interpreter.h, interpreter.cc (interpreter::chdir,
Vlast_chdir_time): Move here from change_directory in dirfns.cc.
Change all uses.
* main-window.cc (main_window::set_current_working_directory):
Use interpreter function directly instead of going through DEFUN
function.
* dirfns.h: Delete. This file no longer declares any functions or
variables. Remove remaining include statements from other files.
* libinterp/corefcn/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 13 Sep 2019 16:22:34 -0400 |
parents | 489c74ac36da |
children | a0d49e55acae |
line wrap: on
line diff
--- a/libinterp/corefcn/interpreter.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/interpreter.cc Fri Sep 13 16:22:34 2019 -0400 @@ -31,6 +31,7 @@ #include "cmd-edit.h" #include "cmd-hist.h" +#include "file-ops.h" #include "file-stat.h" #include "fpucw-wrappers.h" #include "lo-blas-proto.h" @@ -244,6 +245,9 @@ namespace octave { + // The time we last time we changed directories. + sys::time Vlast_chdir_time = 0.0; + // Execute commands from a file and catch potential exceptions in a consistent // way. This function should be called anywhere we might parse and execute // commands from a file before we have entered the main loop in @@ -1143,6 +1147,27 @@ return m_evaluator.get_profiler (); } + int interpreter::chdir (const std::string& dir) + { + std::string xdir = sys::file_ops::tilde_expand (dir); + + int cd_ok = sys::env::chdir (xdir); + + if (! cd_ok) + error ("%s: %s", dir.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? + + m_load_path.update (); + + m_event_manager.change_directory (sys::env::get_current_directory ()); + + return cd_ok; + } + void interpreter::mlock (void) { m_evaluator.mlock ();