Mercurial > octave
changeset 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 | e69da2dae19c |
children | a0d49e55acae |
files | libgui/src/main-window.cc libinterp/corefcn/dirfns.cc libinterp/corefcn/dirfns.h libinterp/corefcn/fcn-info.cc libinterp/corefcn/help.cc libinterp/corefcn/input.cc libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h libinterp/corefcn/load-path.cc libinterp/corefcn/module.mk libinterp/corefcn/utils.cc libinterp/corefcn/variables.cc libinterp/parse-tree/oct-parse.yy |
diffstat | 13 files changed, 45 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libgui/src/main-window.cc Fri Sep 13 16:22:34 2019 -0400 @@ -989,11 +989,11 @@ if (fileInfo.exists () && fileInfo.isDir ()) { emit interpreter_event - ([xdir] (void) + ([xdir] (interpreter& interp) { // INTERPRETER THREAD - Fcd (ovl (xdir.toStdString ())); + interp.chdir (xdir.toStdString ()); }); } }
--- a/libinterp/corefcn/dirfns.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/dirfns.cc Fri Sep 13 16:22:34 2019 -0400 @@ -44,7 +44,6 @@ #include "Cell.h" #include "defun.h" #include "dir-ops.h" -#include "dirfns.h" #include "error.h" #include "errwarn.h" #include "event-manager.h" @@ -55,7 +54,6 @@ #include "pager.h" #include "procstream.h" #include "sysdep.h" -#include "interpreter-private.h" #include "interpreter.h" #include "unwind-prot.h" #include "utils.h" @@ -65,42 +63,8 @@ // directory tree. static bool Vconfirm_recursive_rmdir = true; -namespace octave -{ - // The time we last time we changed directories. - sys::time Vlast_chdir_time = 0.0; - - int change_to_directory (const std::string& newdir) - { - std::string xdir = octave::sys::file_ops::tilde_expand (newdir); - - int cd_ok = octave::sys::env::chdir (xdir); - - 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? - - octave::interpreter& interp - = octave::__get_interpreter__ ("octave_change_to_directory"); - - octave::load_path& lp = interp.get_load_path (); - - lp.update (); - - octave::event_manager& evmgr = interp.get_event_manager (); - - evmgr.change_directory (octave::sys::env::get_current_directory ()); - - return cd_ok; - } -} - -DEFUN (cd, args, nargout, - doc: /* -*- texinfo -*- +DEFMETHOD (cd, interp, args, nargout, + doc: /* -*- texinfo -*- @deftypefn {} {} cd @var{dir} @deftypefnx {} {} cd @deftypefnx {} {@var{old_dir} =} cd @@ -145,14 +109,14 @@ std::string dirname = args(0).xstring_value ("cd: DIR must be a string"); if (! dirname.empty ()) - octave::change_to_directory (dirname); + interp.chdir (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); + interp.chdir (home_dir); } return retval;
--- a/libinterp/corefcn/dirfns.h Thu Sep 12 16:55:53 2019 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - -Copyright (C) 1994-2019 John W. Eaton - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -#if ! defined (octave_dirfns_h) -#define octave_dirfns_h 1 - -#include "octave-config.h" - -#include <ctime> - -#include <string> - -#include "oct-time.h" - -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
--- a/libinterp/corefcn/fcn-info.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/fcn-info.cc Fri Sep 13 16:22:34 2019 -0400 @@ -30,7 +30,6 @@ #include "oct-env.h" #include "defun.h" -#include "dirfns.h" #include "fcn-info.h" #include "interpreter-private.h" #include "interpreter.h"
--- a/libinterp/corefcn/help.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/help.cc Fri Sep 13 16:22:34 2019 -0400 @@ -46,7 +46,6 @@ #include "builtin-defun-decls.h" #include "defaults.h" #include "defun.h" -#include "dirfns.h" #include "error.h" #include "errwarn.h" #include "help.h"
--- a/libinterp/corefcn/input.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/input.cc Fri Sep 13 16:22:34 2019 -0400 @@ -45,7 +45,6 @@ #include "builtin-defun-decls.h" #include "defun.h" -#include "dirfns.h" #include "error.h" #include "errwarn.h" #include "event-manager.h"
--- 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 ();
--- a/libinterp/corefcn/interpreter.h Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/interpreter.h Fri Sep 13 16:22:34 2019 -0400 @@ -29,6 +29,7 @@ #include <string> #include "child-list.h" +#include "oct-time.h" #include "quit.h" #include "str-vec.h" @@ -62,11 +63,16 @@ // TRUE means we've processed all the init code and we are good to go. extern OCTINTERP_API bool octave_initialized; +#include "oct-time.h" + namespace octave { class profiler; class child_list; + // The time we last time we changed directories. + extern sys::time Vlast_chdir_time; + // The application object contains a pointer to the current // interpreter and the interpreter contains a pointer back to the // application context so we need a forward declaration for one (or @@ -255,6 +261,13 @@ return *m_gh_manager; } + // Any Octave code that needs to change the current directory should + // call this function instead of calling the system chdir function + // directly so that the load-path and GUI may be notified of the + // change. + + int chdir (const std::string& dir); + void mlock (void); void munlock (const std::string& nm);
--- a/libinterp/corefcn/load-path.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/load-path.cc Fri Sep 13 16:22:34 2019 -0400 @@ -35,7 +35,6 @@ #include "defaults.h" #include "defun.h" -#include "dirfns.h" #include "input.h" #include "interpreter-private.h" #include "interpreter.h" @@ -450,7 +449,7 @@ switch (action) { case 1: - change_to_directory (dir); + m_interpreter.chdir (dir); ok = true; break;
--- a/libinterp/corefcn/module.mk Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/module.mk Fri Sep 13 16:22:34 2019 -0400 @@ -27,7 +27,6 @@ %reldir%/defun-dld.h \ %reldir%/defun-int.h \ %reldir%/defun.h \ - %reldir%/dirfns.h \ %reldir%/display.h \ %reldir%/dynamic-ld.h \ %reldir%/environment.h \
--- a/libinterp/corefcn/utils.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/utils.cc Fri Sep 13 16:22:34 2019 -0400 @@ -50,7 +50,6 @@ #include "Cell.h" #include "defun.h" -#include "dirfns.h" #include "error.h" #include "errwarn.h" #include "graphics.h"
--- a/libinterp/corefcn/variables.cc Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/corefcn/variables.cc Fri Sep 13 16:22:34 2019 -0400 @@ -42,7 +42,6 @@ #include "Cell.h" #include "defun.h" -#include "dirfns.h" #include "error.h" #include "errwarn.h" #include "event-manager.h"
--- a/libinterp/parse-tree/oct-parse.yy Thu Sep 12 16:55:53 2019 +0200 +++ b/libinterp/parse-tree/oct-parse.yy Fri Sep 13 16:22:34 2019 -0400 @@ -55,7 +55,6 @@ #include "Cell.h" #include "builtin-defun-decls.h" #include "defun.h" -#include "dirfns.h" #include "dynamic-ld.h" #include "error.h" #include "input.h"