Mercurial > octave
changeset 21732:6a1eded90355
use namespace for system env class
* oct-env.h, oct-env.cc: Put env class in octave::sys namespace.
Change all uses.
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc Wed May 18 14:09:17 2016 -0400 +++ b/libgui/src/files-dock-widget.cc Wed May 18 14:58:29 2016 -0400 @@ -823,7 +823,7 @@ void files_dock_widget::popdownmenu_home (bool) { - QString dir = QString::fromStdString (octave_env::get_home_directory ()); + QString dir = QString::fromStdString (octave::sys::env::get_home_directory ()); if (dir.isEmpty ()) dir = QDir::homePath ();
--- a/libgui/src/octave-gui.cc Wed May 18 14:09:17 2016 -0400 +++ b/libgui/src/octave-gui.cc Wed May 18 14:58:29 2016 -0400 @@ -107,7 +107,7 @@ { octave_thread_manager::block_interrupt_signal (); - std::string show_gui_msgs = octave_env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); + std::string show_gui_msgs = octave::sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); // Installing our handler suppresses the messages. if (show_gui_msgs.empty ()) @@ -163,9 +163,9 @@ // We provide specific terminal capabilities, so ensure that TERM is // always set appropriately #if defined (__WIN32__) && ! defined (__CYGWIN__) - octave_env::putenv ("TERM", "cygwin"); + octave::sys::env::putenv ("TERM", "cygwin"); #else - octave_env::putenv ("TERM", "xterm"); + octave::sys::env::putenv ("TERM", "xterm"); #endif // shortcut manager
--- a/libgui/src/octave-qt-link.cc Wed May 18 14:09:17 2016 -0400 +++ b/libgui/src/octave-qt-link.cc Wed May 18 14:58:29 2016 -0400 @@ -589,7 +589,7 @@ bool ok = false; bool addpath_option = true; - std::string curr_dir = octave_env::get_current_directory (); + std::string curr_dir = octave::sys::env::get_current_directory (); if (same_file (curr_dir, dir)) ok = true; @@ -600,7 +600,7 @@ // get base name, allowing "@class/method.m" (bug #41514) std::string base_file = (file.length () > dir.length ()) ? file.substr (dir.length () + 1) - : octave_env::base_pathname (file); + : octave::sys::env::base_pathname (file); std::string lp_file = load_path::find_file (base_file);
--- a/libgui/src/resource-manager.cc Wed May 18 14:09:17 2016 -0400 +++ b/libgui/src/resource-manager.cc Wed May 18 14:58:29 2016 -0400 @@ -50,7 +50,7 @@ static QString default_qt_settings_file (void) { - std::string dsf = octave_env::getenv ("OCTAVE_DEFAULT_QT_SETTINGS"); + std::string dsf = octave::sys::env::getenv ("OCTAVE_DEFAULT_QT_SETTINGS"); if (dsf.empty ()) dsf = Voct_etc_dir + file_ops::dir_sep_str () + "default-qt-settings"; @@ -85,7 +85,7 @@ resource_manager::get_gui_translation_dir (void) { // get environment variable for the locale dir (e.g. from run-octave) - std::string dldir = octave_env::getenv ("OCTAVE_LOCALE_DIR"); + std::string dldir = octave::sys::env::getenv ("OCTAVE_LOCALE_DIR"); if (dldir.empty ()) dldir = Voct_locale_dir; // env-var empty, load the default location return QString::fromStdString (dldir);
--- a/libinterp/corefcn/__magick_read__.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/__magick_read__.cc Wed May 18 14:58:29 2016 -0400 @@ -707,7 +707,7 @@ const std::string locale (static_locale); const std::string program_name - = octave_env::get_program_invocation_name (); + = octave::sys::env::get_program_invocation_name (); Magick::InitializeMagick (program_name.c_str ()); // Restore locale from before GraphicsMagick initialisation
--- a/libinterp/corefcn/defaults.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/defaults.cc Wed May 18 14:58:29 2016 -0400 @@ -124,7 +124,7 @@ static void set_octave_home (void) { - std::string oh = octave_env::getenv ("OCTAVE_HOME"); + std::string oh = octave::sys::env::getenv ("OCTAVE_HOME"); Voctave_home = oh.empty () ? std::string (OCTAVE_PREFIX) : oh; } @@ -255,7 +255,7 @@ std::string tpath = path_arg; if (tpath.empty ()) - tpath = octave_env::getenv ("OCTAVE_EXEC_PATH"); + tpath = octave::sys::env::getenv ("OCTAVE_EXEC_PATH"); if (tpath.empty ()) tpath = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str () @@ -280,12 +280,12 @@ // This is static so that even if set_exec_path is called more than // once, shell_path is the original PATH from the environment, // before we start modifying it. - static std::string shell_path = octave_env::getenv ("PATH"); + static std::string shell_path = octave::sys::env::getenv ("PATH"); if (! shell_path.empty ()) tpath = shell_path + dir_path::path_sep_str () + tpath; - octave_env::putenv ("PATH", tpath); + octave::sys::env::putenv ("PATH", tpath); } void @@ -296,7 +296,7 @@ std::string tpath = path; if (tpath.empty ()) - tpath = octave_env::getenv ("OCTAVE_IMAGE_PATH"); + tpath = octave::sys::env::getenv ("OCTAVE_IMAGE_PATH"); if (! tpath.empty ()) VIMAGE_PATH += dir_path::path_sep_str () + tpath; @@ -314,7 +314,7 @@ { std::string def_file = subst_octave_home (OCTAVE_DOC_CACHE_FILE); - std::string env_file = octave_env::getenv ("OCTAVE_DOC_CACHE_FILE"); + std::string env_file = octave::sys::env::getenv ("OCTAVE_DOC_CACHE_FILE"); Vdoc_cache_file = env_file.empty () ? def_file : env_file; } @@ -327,7 +327,7 @@ { std::string def_file = subst_octave_home (OCTAVE_TEXI_MACROS_FILE); - std::string env_file = octave_env::getenv ("OCTAVE_TEXI_MACROS_FILE"); + std::string env_file = octave::sys::env::getenv ("OCTAVE_TEXI_MACROS_FILE"); Vtexi_macros_file = env_file.empty () ? def_file : env_file; } @@ -340,7 +340,7 @@ { std::string std_info_file = subst_octave_home (OCTAVE_INFOFILE); - std::string oct_info_file = octave_env::getenv ("OCTAVE_INFO_FILE"); + std::string oct_info_file = octave::sys::env::getenv ("OCTAVE_INFO_FILE"); Vinfo_file = oct_info_file.empty () ? std_info_file : oct_info_file; } @@ -351,7 +351,7 @@ { if (Vinfo_program.empty ()) { - std::string oct_info_prog = octave_env::getenv ("OCTAVE_INFO_PROGRAM"); + std::string oct_info_prog = octave::sys::env::getenv ("OCTAVE_INFO_PROGRAM"); if (oct_info_prog.empty ()) Vinfo_program = "info"; @@ -365,7 +365,7 @@ { VEDITOR = "emacs"; - std::string env_editor = octave_env::getenv ("EDITOR"); + std::string env_editor = octave::sys::env::getenv ("EDITOR"); if (! env_editor.empty ()) VEDITOR = env_editor; @@ -374,7 +374,7 @@ static void set_local_site_defaults_file (void) { - std::string lsf = octave_env::getenv ("OCTAVE_SITE_INITFILE"); + std::string lsf = octave::sys::env::getenv ("OCTAVE_SITE_INITFILE"); if (lsf.empty ()) { @@ -389,7 +389,7 @@ static void set_site_defaults_file (void) { - std::string sf = octave_env::getenv ("OCTAVE_VERSION_INITFILE"); + std::string sf = octave::sys::env::getenv ("OCTAVE_VERSION_INITFILE"); if (sf.empty ()) { @@ -405,7 +405,7 @@ { if (Vbuilt_in_docstrings_file.empty ()) { - std::string df = octave_env::getenv ("OCTAVE_BUILT_IN_DOCSTRINGS_FILE"); + std::string df = octave::sys::env::getenv ("OCTAVE_BUILT_IN_DOCSTRINGS_FILE"); if (df.empty ()) Vbuilt_in_docstrings_file
--- a/libinterp/corefcn/dirfns.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/dirfns.cc Wed May 18 14:58:29 2016 -0400 @@ -73,7 +73,7 @@ { std::string xdir = file_ops::tilde_expand (newdir); - int cd_ok = octave_env::chdir (xdir); + int cd_ok = octave::sys::env::chdir (xdir); if (! cd_ok) error ("%s: %s", newdir.c_str (), gnulib::strerror (errno)); @@ -85,7 +85,7 @@ load_path::update (); - octave_link::change_directory (octave_env::get_current_directory ()); + octave_link::change_directory (octave::sys::env::get_current_directory ()); return cd_ok; } @@ -128,7 +128,7 @@ octave_value_list retval; if (nargout > 0) - retval = octave_value (octave_env::get_current_directory ()); + retval = octave_value (octave::sys::env::get_current_directory ()); if (nargin == 1) { @@ -139,7 +139,7 @@ } else { - std::string home_dir = octave_env::get_home_directory (); + std::string home_dir = octave::sys::env::get_home_directory (); if (! home_dir.empty ()) octave_change_to_directory (home_dir); @@ -158,7 +158,7 @@ @seealso{cd, dir, ls, mkdir, rmdir}\n\ @end deftypefn") { - return ovl (octave_env::get_current_directory ()); + return ovl (octave::sys::env::get_current_directory ()); } DEFUN (readdir, args, ,
--- a/libinterp/corefcn/help.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/help.cc Wed May 18 14:58:29 2016 -0400 @@ -1247,7 +1247,7 @@ else file = load_path::find_file (name); - file = octave_env::make_absolute (file); + file = octave::sys::env::make_absolute (file); }
--- a/libinterp/corefcn/load-path.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/load-path.cc Wed May 18 14:58:29 2016 -0400 @@ -63,7 +63,7 @@ { try { - std::string abs_name = octave_env::make_absolute (dir_name); + std::string abs_name = octave::sys::env::make_absolute (dir_name); abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); @@ -133,7 +133,7 @@ void load_path::dir_info::initialize (void) { - is_relative = ! octave_env::absolute_pathname (dir_name); + is_relative = ! octave::sys::env::absolute_pathname (dir_name); dir_time_last_checked = octave::sys::time (static_cast<time_t> (0)); @@ -151,7 +151,7 @@ try { - std::string abs_name = octave_env::make_absolute (dir_name); + std::string abs_name = octave::sys::env::make_absolute (dir_name); // FIXME: nothing is ever removed from this cache of // directory information, so there could be some resource @@ -593,7 +593,7 @@ std::string tpath = load_path::command_line_path; if (tpath.empty ()) - tpath = octave_env::getenv ("OCTAVE_PATH"); + tpath = octave::sys::env::getenv ("OCTAVE_PATH"); std::string xpath; @@ -1325,8 +1325,8 @@ { std::string retval; - if (octave_env::absolute_pathname (file) - || octave_env::rooted_relative_pathname (file)) + if (octave::sys::env::absolute_pathname (file) + || octave::sys::env::rooted_relative_pathname (file)) { file_stat fs (file); @@ -1386,8 +1386,8 @@ std::string retval; if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos - && (octave_env::absolute_pathname (dir) - || octave_env::rooted_relative_pathname (dir))) + && (octave::sys::env::absolute_pathname (dir) + || octave::sys::env::rooted_relative_pathname (dir))) { file_stat fs (dir); @@ -1400,7 +1400,7 @@ p != dir_info_list.end (); p++) { - std::string dname = octave_env::make_absolute (p->dir_name); + std::string dname = octave::sys::env::make_absolute (p->dir_name); size_t dname_len = dname.length (); @@ -1433,8 +1433,8 @@ std::list<std::string> retlist; if (dir.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos - && (octave_env::absolute_pathname (dir) - || octave_env::rooted_relative_pathname (dir))) + && (octave::sys::env::absolute_pathname (dir) + || octave::sys::env::rooted_relative_pathname (dir))) { file_stat fs (dir); @@ -1447,7 +1447,7 @@ p != dir_info_list.end (); p++) { - std::string dname = octave_env::make_absolute (p->dir_name); + std::string dname = octave::sys::env::make_absolute (p->dir_name); size_t dname_len = dname.length (); @@ -1493,8 +1493,8 @@ if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) { - if (octave_env::absolute_pathname (file) - || octave_env::rooted_relative_pathname (file)) + if (octave::sys::env::absolute_pathname (file) + || octave::sys::env::rooted_relative_pathname (file)) { file_stat fs (file); @@ -1572,8 +1572,8 @@ if (file.find_first_of (file_ops::dir_sep_chars ()) != std::string::npos) { - if (octave_env::absolute_pathname (file) - || octave_env::rooted_relative_pathname (file)) + if (octave::sys::env::absolute_pathname (file) + || octave::sys::env::rooted_relative_pathname (file)) { file_stat fs (file);
--- a/libinterp/corefcn/load-save.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/load-save.cc Wed May 18 14:58:29 2016 -0400 @@ -115,9 +115,9 @@ return std::string ("# Created by Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") - + octave_env::get_user_name () + + octave::sys::env::get_user_name () + std::string ("@") - + octave_env::get_host_name () + + octave::sys::env::get_host_name () + std::string (">"); }
--- a/libinterp/corefcn/ls-mat5.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/ls-mat5.cc Wed May 18 14:58:29 2016 -0400 @@ -907,7 +907,7 @@ dir_path p (load_path::system_path ()); str = - octave_env::make_absolute (p.find_first_of (names)); + octave::sys::env::make_absolute (p.find_first_of (names)); size_t xpos = str.find_last_of (file_ops::dir_sep_chars ());
--- a/libinterp/corefcn/oct-hist.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/oct-hist.cc Wed May 18 14:58:29 2016 -0400 @@ -77,13 +77,13 @@ { std::string file; - std::string env_file = octave_env::getenv ("OCTAVE_HISTFILE"); + std::string env_file = octave::sys::env::getenv ("OCTAVE_HISTFILE"); if (! env_file.empty ()) file = env_file; if (file.empty ()) - file = file_ops::concat (octave_env::get_home_directory (), + file = file_ops::concat (octave::sys::env::get_home_directory (), ".octave_hist"); return file; @@ -94,7 +94,7 @@ { int size = 1000; - std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); + std::string env_size = octave::sys::env::getenv ("OCTAVE_HISTSIZE"); if (! env_size.empty ()) { @@ -112,9 +112,9 @@ { return std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") - + octave_env::get_user_name () + + octave::sys::env::get_user_name () + std::string ("@") - + octave_env::get_host_name () + + octave::sys::env::get_host_name () + std::string (">"); } @@ -536,7 +536,7 @@ command_history::initialize (read_history_file, default_history_file (), default_history_size (), - octave_env::getenv ("OCTAVE_HISTCONTROL")); + octave::sys::env::getenv ("OCTAVE_HISTCONTROL")); octave_link::set_history (command_history::list ()); }
--- a/libinterp/corefcn/pager.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/pager.cc Wed May 18 14:58:29 2016 -0400 @@ -60,7 +60,7 @@ static std::string default_pager (void) { - std::string pager_binary = octave_env::getenv ("PAGER"); + std::string pager_binary = octave::sys::env::getenv ("PAGER"); #if defined (OCTAVE_DEFAULT_PAGER) if (pager_binary.empty ())
--- a/libinterp/corefcn/symtab.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/symtab.cc Wed May 18 14:58:29 2016 -0400 @@ -249,7 +249,7 @@ { int nm_len = nm.length (); - if (octave_env::absolute_pathname (nm) + if (octave::sys::env::absolute_pathname (nm) && ((nm_len > 4 && (nm.substr (nm_len-4) == ".oct" || nm.substr (nm_len-4) == ".mex"))
--- a/libinterp/corefcn/syscalls.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/syscalls.cc Wed May 18 14:58:29 2016 -0400 @@ -1003,7 +1003,7 @@ if (args.length () != 0) print_usage (); - return ovl (octave_env::get_host_name ()); + return ovl (octave::sys::env::get_host_name ()); } DEFUN (uname, args, ,
--- a/libinterp/corefcn/sysdep.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/sysdep.cc Wed May 18 14:58:29 2016 -0400 @@ -156,7 +156,7 @@ size_t pos = bin_dir.rfind ("\\bin\\"); if (pos != std::string::npos) - octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); + octave::sys::env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); } } @@ -576,10 +576,10 @@ if (retval.empty () || retval == "\\") { - retval = octave_env::getenv ("TEMP"); + retval = octave::sys::env::getenv ("TEMP"); if (retval.empty ()) - retval = octave_env::getenv ("TMP"); + retval = octave::sys::env::getenv ("TMP"); if (retval.empty ()) retval = "c:\\temp"; @@ -635,7 +635,7 @@ std::string name = args(0).string_value (); - return ovl (octave_env::getenv (name)); + return ovl (octave::sys::env::getenv (name)); } /* @@ -665,7 +665,7 @@ ? args(1).xstring_value ("setenv: VALUE must be a string") : ""); - octave_env::putenv (var, val); + octave::sys::env::putenv (var, val); return ovl (); } @@ -927,7 +927,7 @@ @seealso{getenv}\n\ @end deftypefn") { - return ovl (octave_env::get_home_directory ()); + return ovl (octave::sys::env::get_home_directory ()); } /*
--- a/libinterp/corefcn/urlwrite.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/urlwrite.cc Wed May 18 14:58:29 2016 -0400 @@ -387,7 +387,7 @@ if (nargout > 0) { if (curl.good ()) - retval = ovl (octave_env::make_absolute (filename), true, ""); + retval = ovl (octave::sys::env::make_absolute (filename), true, ""); else retval = ovl ("", false, curl.lasterror ()); }
--- a/libinterp/corefcn/utils.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/corefcn/utils.cc Wed May 18 14:58:29 2016 -0400 @@ -255,7 +255,7 @@ { dir_path p (path); - return octave_env::make_absolute (p.find_first_of (names)); + return octave::sys::env::make_absolute (p.find_first_of (names)); } // Find all locations of the given file in the path. @@ -270,7 +270,7 @@ octave_idx_type len = sv.numel (); for (octave_idx_type i = 0; i < len; i++) - sv[i] = octave_env::make_absolute (sv[i]); + sv[i] = octave::sys::env::make_absolute (sv[i]); return sv; } @@ -283,7 +283,7 @@ string_vector retval (len); for (octave_idx_type i = 0; i < len; i++) - retval[i] = octave_env::make_absolute (sv[i]); + retval[i] = octave::sys::env::make_absolute (sv[i]); return retval; } @@ -319,7 +319,7 @@ error ("file_in_loadpath: FILE argument must not be empty"); if (nargin == 1) - return ovl (octave_env::make_absolute (load_path::find_first_of (names))); + return ovl (octave::sys::env::make_absolute (load_path::find_first_of (names))); else { std::string opt = args(1).xstring_value ("file_in_loadpath: optional second argument must be a string"); @@ -432,7 +432,7 @@ if (! suffix.empty ()) nm.append (suffix); - return octave_env::make_absolute (load_path::find_file (nm)); + return octave::sys::env::make_absolute (load_path::find_file (nm)); } std::string @@ -442,8 +442,8 @@ { std::string fname = file; - if (! (octave_env::absolute_pathname (fname) - || octave_env::rooted_relative_pathname (fname))) + if (! (octave::sys::env::absolute_pathname (fname) + || octave::sys::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, @@ -457,7 +457,7 @@ { // Not directly found; search load path. std::string tmp - = octave_env::make_absolute (load_path::find_file (fname)); + = octave::sys::env::make_absolute (load_path::find_file (fname)); if (! tmp.empty ()) { @@ -483,7 +483,7 @@ if (len > 0) { - if (octave_env::absolute_pathname (name)) + if (octave::sys::env::absolute_pathname (name)) { file_stat fs (name); @@ -522,7 +522,7 @@ file_stat fs (tcontents); if (fs.exists ()) - retval = octave_env::make_absolute (tcontents); + retval = octave::sys::env::make_absolute (tcontents); } return retval; @@ -541,7 +541,7 @@ if (len > 0) { - if (octave_env::absolute_pathname (name)) + if (octave::sys::env::absolute_pathname (name)) { file_stat fs (name); @@ -570,7 +570,7 @@ if (len > 0) { - if (octave_env::absolute_pathname (name)) + if (octave::sys::env::absolute_pathname (name)) { file_stat fs (name); @@ -903,7 +903,7 @@ print_usage (); return ovl (args(0).is_string () - && octave_env::absolute_pathname (args(0).string_value ())); + && octave::sys::env::absolute_pathname (args(0).string_value ())); } /* @@ -924,7 +924,7 @@ print_usage (); return ovl (args(0).is_string () - && octave_env::rooted_relative_pathname (args(0).string_value ())); + && octave::sys::env::rooted_relative_pathname (args(0).string_value ())); } /* @@ -949,7 +949,7 @@ std::string nm = args(0).xstring_value ("make_absolute_filename: FILE argument must be a filename"); - return ovl (octave_env::make_absolute (nm)); + return ovl (octave::sys::env::make_absolute (nm)); } /*
--- a/libinterp/dldfcn/__init_fltk__.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/dldfcn/__init_fltk__.cc Wed May 18 14:58:29 2016 -0400 @@ -841,7 +841,7 @@ #if defined (HAVE_X_WINDOWS) std::string show_gui_msgs - = octave_env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); + = octave::sys::env::getenv ("OCTAVE_SHOW_GUI_MESSAGES"); // Installing our handler suppresses the messages. if (show_gui_msgs.empty ())
--- a/libinterp/dldfcn/__init_gnuplot__.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/dldfcn/__init_gnuplot__.cc Wed May 18 14:58:29 2016 -0400 @@ -170,7 +170,7 @@ have_gnuplot_binary (void) { const std::string exeext = octave::build_env::EXEEXT; - const std::string path = octave_env::getenv ("PATH"); + const std::string path = octave::sys::env::getenv ("PATH"); octave_value_list tmp = feval ("gnuplot_binary", octave_value_list ()); std::string gnuplot_binary = tmp(0).string_value ();
--- a/libinterp/octave-value/ov-fcn-handle.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/octave-value/ov-fcn-handle.cc Wed May 18 14:58:29 2016 -0400 @@ -294,7 +294,7 @@ dir_path p (load_path::system_path ()); - str = octave_env::make_absolute (p.find_first_of (names)); + str = octave::sys::env::make_absolute (p.find_first_of (names)); size_t xpos = str.find_last_of (file_ops::dir_sep_chars ());
--- a/libinterp/octave-value/ov-java.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/octave-value/ov-java.cc Wed May 18 14:58:29 2016 -0400 @@ -363,7 +363,7 @@ if (java_dir.empty ()) { - java_dir = octave_env::getenv ("OCTAVE_JAVA_DIR"); + java_dir = octave::sys::env::getenv ("OCTAVE_JAVA_DIR"); if (java_dir.empty ()) java_dir = Vfcn_file_dir + file_ops::dir_sep_str () + "java"; @@ -446,8 +446,8 @@ // 2) User's home directory // 3) Octave installation directory where octave.jar resides - std::string cwd = octave_env::get_current_directory (); - std::string home_dir = octave_env::get_home_directory (); + std::string cwd = octave::sys::env::get_current_directory (); + std::string home_dir = octave::sys::env::get_home_directory (); // The filename is "javaclasspath.txt", but historically // has been "classpath.txt" so both are supported. @@ -559,7 +559,7 @@ key = "software\\javasoft\\java runtime environment"; - value = octave_env::getenv ("JAVA_VERSION"); + value = octave::sys::env::getenv ("JAVA_VERSION"); if (value.empty ()) { value = "Currentversion"; @@ -588,10 +588,10 @@ { jvm_bin_path = (jvm_bin_path + std::string ("\\bin")); - old_cwd = octave_env::get_current_directory (); + old_cwd = octave::sys::env::get_current_directory (); set_dll_directory (jvm_bin_path); - octave_env::chdir (jvm_bin_path); + octave::sys::env::chdir (jvm_bin_path); } } @@ -621,7 +621,7 @@ set_dll_directory (); if (! old_cwd.empty ()) - octave_env::chdir (old_cwd); + octave::sys::env::chdir (old_cwd); #endif
--- a/libinterp/octave.cc Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/octave.cc Wed May 18 14:58:29 2016 -0400 @@ -379,14 +379,14 @@ bool home_rc_already_executed = false; - std::string initfile = octave_env::getenv ("OCTAVE_INITFILE"); + std::string initfile = octave::sys::env::getenv ("OCTAVE_INITFILE"); if (initfile.empty ()) initfile = ".octaverc"; - std::string home_dir = octave_env::get_home_directory (); + std::string home_dir = octave::sys::env::get_home_directory (); - std::string home_rc = octave_env::make_absolute (initfile, home_dir); + std::string home_rc = octave::sys::env::make_absolute (initfile, home_dir); std::string local_rc; @@ -403,7 +403,7 @@ // We want to check for curr_dir after executing home_rc // because doing that may change the working directory. - local_rc = octave_env::make_absolute (initfile); + local_rc = octave::sys::env::make_absolute (initfile); home_rc_already_executed = same_file (home_rc, local_rc); } @@ -412,7 +412,7 @@ if (! home_rc_already_executed) { if (local_rc.empty ()) - local_rc = octave_env::make_absolute (initfile); + local_rc = octave::sys::env::make_absolute (initfile); safe_source_file (local_rc, context, verbose, require_file); } @@ -781,15 +781,15 @@ // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting setlocale (LC_NUMERIC, "C"); setlocale (LC_TIME, "C"); - octave_env::putenv ("LC_NUMERIC", "C"); - octave_env::putenv ("LC_TIME", "C"); + octave::sys::env::putenv ("LC_NUMERIC", "C"); + octave::sys::env::putenv ("LC_TIME", "C"); octave_embedded = embedded; - octave_env::set_program_name (argv[0]); + octave::sys::env::set_program_name (argv[0]); - octave_program_invocation_name = octave_env::get_program_invocation_name (); - octave_program_name = octave_env::get_program_name (); + octave_program_invocation_name = octave::sys::env::get_program_invocation_name (); + octave_program_name = octave::sys::env::get_program_name (); octave_thread::init ();
--- a/libinterp/parse-tree/oct-parse.in.yy Wed May 18 14:09:17 2016 -0400 +++ b/libinterp/parse-tree/oct-parse.in.yy Wed May 18 14:58:29 2016 -0400 @@ -4247,7 +4247,7 @@ || (file_len > 4 && file.substr (file_len-4) == ".mex") || (file_len > 2 && file.substr (file_len-2) == ".m")) { - file = octave_env::base_pathname (file); + file = octave::sys::env::base_pathname (file); file = file.substr (0, file.find_last_of ('.')); size_t pos = file.find_last_of (file_ops::dir_sep_str ()); @@ -4346,7 +4346,7 @@ || (nm_len > 4 && nm.substr (nm_len-4) == ".mex") || (nm_len > 2 && nm.substr (nm_len-2) == ".m")) { - nm = octave_env::base_pathname (file); + nm = octave::sys::env::base_pathname (file); nm = nm.substr (0, nm.find_last_of ('.')); size_t pos = nm.find_last_of (file_ops::dir_sep_str ()); @@ -4354,9 +4354,9 @@ nm = nm.substr (pos+1); } - relative_lookup = ! octave_env::absolute_pathname (file); - - file = octave_env::make_absolute (file); + relative_lookup = ! octave::sys::env::absolute_pathname (file); + + file = octave::sys::env::make_absolute (file); int len = file.length (); @@ -4481,7 +4481,7 @@ std::string nm = argv[2]; - if (! octave_env::absolute_pathname (nm)) + if (! octave::sys::env::absolute_pathname (nm)) { octave_user_code *fcn = octave_call_stack::caller_user_code (); @@ -4493,7 +4493,7 @@ if (! fname.empty ()) { - fname = octave_env::make_absolute (fname); + fname = octave::sys::env::make_absolute (fname); fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); file_stat fs (fname + nm); @@ -4568,7 +4568,7 @@ std::string file_full_name = file_ops::tilde_expand (file_name); - file_full_name = octave_env::make_absolute (file_full_name); + file_full_name = octave::sys::env::make_absolute (file_full_name); unwind_protect frame; @@ -5484,7 +5484,7 @@ std::string file = args(0).xstring_value ("__parse_file__: expecting filename as argument"); - std::string full_file = octave_env::make_absolute (file); + std::string full_file = octave::sys::env::make_absolute (file); size_t file_len = file.length (); @@ -5492,7 +5492,7 @@ || (file_len > 4 && file.substr (file_len-4) == ".mex") || (file_len > 2 && file.substr (file_len-2) == ".m")) { - file = octave_env::base_pathname (file); + file = octave::sys::env::base_pathname (file); file = file.substr (0, file.find_last_of ('.')); size_t pos = file.find_last_of (file_ops::dir_sep_str ());
--- a/liboctave/system/file-ops.cc Wed May 18 14:09:17 2016 -0400 +++ b/liboctave/system/file-ops.cc Wed May 18 14:58:29 2016 -0400 @@ -231,7 +231,7 @@ // any preexpansion hook. if (f_len == 1 || file_ops::is_dir_sep (filename[1])) - return octave_env::get_home_directory () + filename.substr (1); + return octave::sys::env::get_home_directory () + filename.substr (1); std::string username = isolate_tilde_prefix (filename); @@ -685,9 +685,9 @@ // get dir path to use for template std::string templatename; if (dir.empty ()) - templatename = octave_env::get_temp_directory (); + templatename = octave::sys::env::get_temp_directory (); else if (! file_stat (dir, false).is_dir ()) - templatename = octave_env::get_temp_directory (); + templatename = octave::sys::env::get_temp_directory (); else templatename = dir;
--- a/liboctave/system/oct-env.cc Wed May 18 14:09:17 2016 -0400 +++ b/liboctave/system/oct-env.cc Wed May 18 14:58:29 2016 -0400 @@ -26,13 +26,13 @@ from GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc. - octave_env::do_absolute_pathname - octave_env::do_base_pathname - octave_env::do_chdir - octave_env::do_getcwd - octave_env::do_make_absolute - octave_env::do_polite_directory_format - octave_env::pathname_backup + octave::sys::env::do_absolute_pathname + octave::sys:env::do_base_pathname + octave::sys:env::do_chdir + octave::sys:env::do_getcwd + octave::sys:env::do_make_absolute + octave::sys:env::do_polite_directory_format + octave::sys:env::pathname_backup */ @@ -60,543 +60,551 @@ #include "oct-syscalls.h" #include "singleton-cleanup.h" -octave_env::octave_env (void) - : follow_symbolic_links (true), verbatim_pwd (true), - current_directory (), prog_name (), prog_invocation_name (), - user_name (), host_name () +namespace +octave { - // Get a real value for the current directory. - do_getcwd (); + namespace + sys + { + env::env (void) + : follow_symbolic_links (true), verbatim_pwd (true), + current_directory (), prog_name (), prog_invocation_name (), + user_name (), host_name () + { + // Get a real value for the current directory. + do_getcwd (); + + // Etc. + do_get_user_name (); - // Etc. - do_get_user_name (); + do_get_host_name (); + } + + env *env::instance = 0; - do_get_host_name (); -} + bool + env::instance_ok (void) + { + bool retval = true; + + if (! instance) + { + instance = new env (); -octave_env *octave_env::instance = 0; + if (instance) + singleton_cleanup_list::add (cleanup_instance); + } -bool -octave_env::instance_ok (void) -{ - bool retval = true; + if (! instance) + (*current_liboctave_error_handler) + ("unable to create current working directory object!"); + + return retval; + } - if (! instance) + std::string + env::polite_directory_format (const std::string& name) + { + return (instance_ok ()) + ? instance->do_polite_directory_format (name) : ""; + } + + bool + env::absolute_pathname (const std::string& s) { - instance = new octave_env (); + return (instance_ok ()) + ? instance->do_absolute_pathname (s) : false; + } - if (instance) - singleton_cleanup_list::add (cleanup_instance); + bool + env::rooted_relative_pathname (const std::string& s) + { + return (instance_ok ()) + ? instance->do_rooted_relative_pathname (s) : false; } - if (! instance) - (*current_liboctave_error_handler) - ("unable to create current working directory object!"); - - return retval; -} + std::string + env::base_pathname (const std::string& s) + { + return (instance_ok ()) + ? instance->do_base_pathname (s) : ""; + } -std::string -octave_env::polite_directory_format (const std::string& name) -{ - return (instance_ok ()) - ? instance->do_polite_directory_format (name) : ""; -} - -bool -octave_env::absolute_pathname (const std::string& s) -{ - return (instance_ok ()) - ? instance->do_absolute_pathname (s) : false; -} + std::string + env::make_absolute (const std::string& s, const std::string& dot_path) + { + return (instance_ok ()) + ? instance->do_make_absolute (s, dot_path) : ""; + } -bool -octave_env::rooted_relative_pathname (const std::string& s) -{ - return (instance_ok ()) - ? instance->do_rooted_relative_pathname (s) : false; -} - -std::string -octave_env::base_pathname (const std::string& s) -{ - return (instance_ok ()) - ? instance->do_base_pathname (s) : ""; -} + std::string + env::get_current_directory () + { + return (instance_ok ()) + ? instance->do_getcwd () : ""; + } -std::string -octave_env::make_absolute (const std::string& s, const std::string& dot_path) -{ - return (instance_ok ()) - ? instance->do_make_absolute (s, dot_path) : ""; -} + std::string + env::get_home_directory () + { + return (instance_ok ()) + ? instance->do_get_home_directory () : ""; + } -std::string -octave_env::get_current_directory () -{ - return (instance_ok ()) - ? instance->do_getcwd () : ""; -} + std::string + env::get_temp_directory () + { + return (instance_ok ()) + ? instance->do_get_temp_directory () : ""; + } -std::string -octave_env::get_home_directory () -{ - return (instance_ok ()) - ? instance->do_get_home_directory () : ""; -} + std::string + env::get_program_name (void) + { + return (instance_ok ()) + ? instance->prog_name : ""; + } -std::string -octave_env::get_temp_directory () -{ - return (instance_ok ()) - ? instance->do_get_temp_directory () : ""; -} - -std::string -octave_env::get_program_name (void) -{ - return (instance_ok ()) - ? instance->prog_name : ""; -} + std::string + env::get_program_invocation_name (void) + { + return (instance_ok ()) + ? instance->prog_invocation_name : ""; + } -std::string -octave_env::get_program_invocation_name (void) -{ - return (instance_ok ()) - ? instance->prog_invocation_name : ""; -} - -void -octave_env::set_program_name (const std::string& s) -{ - if (instance_ok ()) - instance->do_set_program_name (s); -} + void + env::set_program_name (const std::string& s) + { + if (instance_ok ()) + instance->do_set_program_name (s); + } -std::string -octave_env::get_user_name (void) -{ - return (instance_ok ()) - ? instance->do_get_user_name () : ""; -} + std::string + env::get_user_name (void) + { + return (instance_ok ()) + ? instance->do_get_user_name () : ""; + } -std::string -octave_env::get_host_name (void) -{ - return (instance_ok ()) - ? instance->do_get_host_name () : ""; -} + std::string + env::get_host_name (void) + { + return (instance_ok ()) + ? instance->do_get_host_name () : ""; + } -std::string -octave_env::do_get_temp_directory (void) const -{ - std::string tempd; + std::string + env::do_get_temp_directory (void) const + { + std::string tempd; #if defined (__MINGW32__) || defined (_MSC_VER) - tempd = do_getenv ("TEMP"); + tempd = do_getenv ("TEMP"); - if (tempd.empty ()) - tempd = do_getenv ("TMP"); + if (tempd.empty ()) + tempd = do_getenv ("TMP"); - #if defined (P_tmpdir) - if (tempd.empty ()) - tempd = P_tmpdir; - #endif +#if defined (P_tmpdir) + if (tempd.empty ()) + tempd = P_tmpdir; +#endif - // Some versions of MinGW and MSVC either don't define P_tmpdir, or - // define it to a single backslash. In such cases just use C:\temp. - if (tempd.empty () || tempd == "\\") - tempd = "c:\\temp"; + // Some versions of MinGW and MSVC either don't define P_tmpdir, or + // define it to a single backslash. In such cases just use C:\temp. + if (tempd.empty () || tempd == "\\") + tempd = "c:\\temp"; #else - tempd = do_getenv ("TMP"); + tempd = do_getenv ("TMP"); - #if defined (P_tmpdir) - if (tempd.empty ()) - tempd = P_tmpdir; - #else - if (tempd.empty ()) - tempd = "/tmp"; - #endif +#if defined (P_tmpdir) + if (tempd.empty ()) + tempd = P_tmpdir; +#else + if (tempd.empty ()) + tempd = "/tmp"; +#endif #endif - return tempd; -} + return tempd; + } -// FIXME: this leaves no way to distinguish between a -// variable that is not set and one that is set to the empty string. -// Is this a problem? + // FIXME: this leaves no way to distinguish between a + // variable that is not set and one that is set to the empty string. + // Is this a problem? -std::string -octave_env::getenv (const std::string& name) -{ - return (instance_ok ()) - ? instance->do_getenv (name) : ""; -} + std::string + env::getenv (const std::string& name) + { + return (instance_ok ()) + ? instance->do_getenv (name) : ""; + } -void -octave_env::putenv (const std::string& name, const std::string& value) -{ - octave_putenv (name, value); -} + void + env::putenv (const std::string& name, const std::string& value) + { + octave_putenv (name, value); + } -bool -octave_env::have_x11_display (void) -{ - std::string display = getenv ("DISPLAY"); + bool + env::have_x11_display (void) + { + std::string display = getenv ("DISPLAY"); - return ! display.empty (); -} + return ! display.empty (); + } -bool -octave_env::chdir (const std::string& newdir) -{ - return (instance_ok ()) - ? instance->do_chdir (newdir) : false; -} + bool + env::chdir (const std::string& newdir) + { + return (instance_ok ()) + ? instance->do_chdir (newdir) : false; + } -void -octave_env::do_set_program_name (const std::string& s) const -{ - static bool initialized = false; - - if (! initialized) + void + env::do_set_program_name (const std::string& s) const { - // The string passed to gnulib's ::set_program_name function must - // exist for the duration of the program so allocate a copy here - // instead of passing S.c_str () which only exists as long as the - // string object S. + static bool initialized = false; - // For gnulib. - ::set_program_name (strsave (s.c_str ())); + if (! initialized) + { + // The string passed to gnulib's ::set_program_name function must + // exist for the duration of the program so allocate a copy here + // instead of passing S.c_str () which only exists as long as the + // string object S. + + // For gnulib. + ::set_program_name (strsave (s.c_str ())); - // Let gnulib strip off things like the "lt-" prefix from libtool. - prog_invocation_name = program_name; + // Let gnulib strip off things like the "lt-" prefix from libtool. + prog_invocation_name = program_name; - size_t pos - = prog_invocation_name.find_last_of (file_ops::dir_sep_chars ()); + size_t pos + = prog_invocation_name.find_last_of (file_ops::dir_sep_chars ()); - // Also keep a shortened version of the program name. - prog_name = (pos == std::string::npos - ? prog_invocation_name - : prog_invocation_name.substr (pos+1)); + // Also keep a shortened version of the program name. + prog_name = (pos == std::string::npos + ? prog_invocation_name + : prog_invocation_name.substr (pos+1)); - initialized = true; + initialized = true; + } } -} -// Return a pretty pathname. If the first part of the pathname is the -// same as $HOME, then replace that with '~'. + // Return a pretty pathname. If the first part of the pathname is the + // same as $HOME, then replace that with '~'. -std::string -octave_env::do_polite_directory_format (const std::string& name) const -{ - std::string retval; + std::string + env::do_polite_directory_format (const std::string& name) const + { + std::string retval; - std::string home_dir = do_get_home_directory (); + std::string home_dir = do_get_home_directory (); - size_t len = home_dir.length (); + size_t len = home_dir.length (); - if (len > 1 && home_dir == name.substr (0, len) - && (name.length () == len || file_ops::is_dir_sep (name[len]))) - { - retval = "~"; - retval.append (name.substr (len)); - } - else - retval = name; + if (len > 1 && home_dir == name.substr (0, len) + && (name.length () == len || file_ops::is_dir_sep (name[len]))) + { + retval = "~"; + retval.append (name.substr (len)); + } + else + retval = name; - return retval; -} + return retval; + } -bool -octave_env::do_absolute_pathname (const std::string& s) const -{ - size_t len = s.length (); + bool + env::do_absolute_pathname (const std::string& s) const + { + size_t len = s.length (); - if (len == 0) - return false; + if (len == 0) + return false; - if (file_ops::is_dir_sep (s[0])) - return true; + if (file_ops::is_dir_sep (s[0])) + return true; #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) - if ((len == 2 && isalpha (s[0]) && s[1] == ':') - || (len > 2 && isalpha (s[0]) && s[1] == ':' - && file_ops::is_dir_sep (s[2]))) - return true; + if ((len == 2 && isalpha (s[0]) && s[1] == ':') + || (len > 2 && isalpha (s[0]) && s[1] == ':' + && file_ops::is_dir_sep (s[2]))) + return true; #endif - return false; -} + return false; + } -bool -octave_env::do_rooted_relative_pathname (const std::string& s) const -{ - size_t len = s.length (); + bool + env::do_rooted_relative_pathname (const std::string& s) const + { + size_t len = s.length (); + + if (len == 0) + return false; - if (len == 0) - return false; + if (len == 1 && s[0] == '.') + return true; + + if (len > 1 && s[0] == '.' && file_ops::is_dir_sep (s[1])) + return true; - if (len == 1 && s[0] == '.') - return true; + if (len == 2 && s[0] == '.' && s[1] == '.') + return true; - if (len > 1 && s[0] == '.' && file_ops::is_dir_sep (s[1])) - return true; + if (len > 2 && s[0] == '.' && s[1] == '.' && file_ops::is_dir_sep (s[2])) + return true; - if (len == 2 && s[0] == '.' && s[1] == '.') - return true; + return false; + } - if (len > 2 && s[0] == '.' && s[1] == '.' && file_ops::is_dir_sep (s[2])) - return true; - - return false; -} + // Return the 'basename' of the pathname in STRING (the stuff after + // the last directory separator). If STRING is not a full pathname, + // simply return it. -// Return the 'basename' of the pathname in STRING (the stuff after -// the last directory separator). If STRING is not a full pathname, -// simply return it. + std::string + env::do_base_pathname (const std::string& s) const + { + if (! (do_absolute_pathname (s) || do_rooted_relative_pathname (s))) + return s; + + size_t pos = s.find_last_of (file_ops::dir_sep_chars ()); -std::string -octave_env::do_base_pathname (const std::string& s) const -{ - if (! (do_absolute_pathname (s) || do_rooted_relative_pathname (s))) - return s; + if (pos == std::string::npos) + return s; + else + return s.substr (pos+1); + } - size_t pos = s.find_last_of (file_ops::dir_sep_chars ()); + // Turn STRING (a pathname) into an absolute pathname, assuming that + // DOT_PATH contains the symbolic location of the current directory. - if (pos == std::string::npos) - return s; - else - return s.substr (pos+1); -} + std::string + env::do_make_absolute (const std::string& s, + const std::string& dot_path) const + { + if (dot_path.empty () || s.empty () || do_absolute_pathname (s)) + return s; -// Turn STRING (a pathname) into an absolute pathname, assuming that -// DOT_PATH contains the symbolic location of the current directory. + std::string current_dir = dot_path; -std::string -octave_env::do_make_absolute (const std::string& s, - const std::string& dot_path) const -{ - if (dot_path.empty () || s.empty () || do_absolute_pathname (s)) - return s; + if (current_dir.empty ()) + current_dir = do_getcwd (); + + size_t pos = current_dir.length () - 1; - std::string current_dir = dot_path; + if (! file_ops::is_dir_sep (current_dir[pos])) + current_dir.append (file_ops::dir_sep_str ()); - if (current_dir.empty ()) - current_dir = do_getcwd (); + // FIXME: this is probably not correct for all systems. + + size_t i = 0; + size_t slen = s.length (); - size_t pos = current_dir.length () - 1; - - if (! file_ops::is_dir_sep (current_dir[pos])) - current_dir.append (file_ops::dir_sep_str ()); + while (i < slen) + { + if (s[i] == '.') + { + if (i + 1 == slen) + return current_dir; - // FIXME: this is probably not correct for all systems. - - size_t i = 0; - size_t slen = s.length (); + if (file_ops::is_dir_sep (s[i+1])) + { + i += 2; + continue; + } - while (i < slen) - { - if (s[i] == '.') - { - if (i + 1 == slen) - return current_dir; + if (s[i+1] == '.' + && (i + 2 == slen || file_ops::is_dir_sep (s[i+2]))) + { + i += 2; - if (file_ops::is_dir_sep (s[i+1])) - { - i += 2; - continue; + if (i != slen) + i++; + + pathname_backup (current_dir, 1); + + continue; + } } - if (s[i+1] == '.' - && (i + 2 == slen || file_ops::is_dir_sep (s[i+2]))) - { - i += 2; + size_t tmp = s.find_first_of (file_ops::dir_sep_chars (), i); - if (i != slen) - i++; - - pathname_backup (current_dir, 1); - - continue; + if (tmp == std::string::npos) + { + current_dir.append (s, i, tmp-i); + break; + } + else + { + current_dir.append (s, i, tmp-i+1); + i = tmp + 1; } } - size_t tmp = s.find_first_of (file_ops::dir_sep_chars (), i); - - if (tmp == std::string::npos) - { - current_dir.append (s, i, tmp-i); - break; - } - else - { - current_dir.append (s, i, tmp-i+1); - i = tmp + 1; - } + return current_dir; } - return current_dir; -} - -// Return a string which is the current working directory. + // Return a string which is the current working directory. -std::string -octave_env::do_getcwd () const -{ - if (! follow_symbolic_links) - current_directory = ""; + std::string + env::do_getcwd () const + { + if (! follow_symbolic_links) + current_directory = ""; + + if (verbatim_pwd || current_directory.empty ()) + current_directory = ::octave_getcwd (); - if (verbatim_pwd || current_directory.empty ()) - current_directory = ::octave_getcwd (); - - return current_directory; -} + return current_directory; + } -// This value is not cached because it can change while Octave is -// running. + // This value is not cached because it can change while Octave is + // running. -std::string -octave_env::do_get_home_directory (void) const -{ - std::string hd = do_getenv ("HOME"); + std::string + env::do_get_home_directory (void) const + { + std::string hd = do_getenv ("HOME"); #if defined (__MINGW32__) || defined (_MSC_VER) - // Maybe we are started directly from cmd.exe. - if (hd.empty ()) - { - std::string drv = do_getenv ("HOMEDRIVE"); - if (drv.empty ()) - hd = do_getenv ("HOMEPATH"); - else - hd = drv + do_getenv ("HOMEPATH"); - } + // Maybe we are started directly from cmd.exe. + if (hd.empty ()) + { + std::string drv = do_getenv ("HOMEDRIVE"); + if (drv.empty ()) + hd = do_getenv ("HOMEPATH"); + else + hd = drv + do_getenv ("HOMEPATH"); + } #endif - if (hd.empty ()) - { - octave::sys::password pw = octave::sys::password::getpwuid (octave::sys::getuid ()); + if (hd.empty ()) + { + octave::sys::password pw = octave::sys::password::getpwuid (octave::sys::getuid ()); - hd = pw ? pw.dir () : std::string (file_ops::dir_sep_str ()); + hd = pw ? pw.dir () : std::string (file_ops::dir_sep_str ()); + } + + return hd; } - return hd; -} + std::string + env::do_get_user_name (void) const + { + if (user_name.empty ()) + { + octave::sys::password pw = octave::sys::password::getpwuid (octave::sys::getuid ()); -std::string -octave_env::do_get_user_name (void) const -{ - if (user_name.empty ()) - { - octave::sys::password pw = octave::sys::password::getpwuid (octave::sys::getuid ()); + user_name = pw ? pw.name () : std::string ("unknown"); + } - user_name = pw ? pw.name () : std::string ("unknown"); + return user_name; } - return user_name; -} + std::string + env::do_get_host_name (void) const + { + if (host_name.empty ()) + { + char hostname[1024]; -std::string -octave_env::do_get_host_name (void) const -{ - if (host_name.empty ()) - { - char hostname[1024]; + int status = gnulib::gethostname (hostname, 1023); - int status = gnulib::gethostname (hostname, 1023); + host_name = (status < 0) ? "unknown" : hostname; + } - host_name = (status < 0) ? "unknown" : hostname; + return host_name; } - return host_name; -} + std::string + env::do_getenv (const std::string& name) const + { + char *value = ::getenv (name.c_str ()); + + return value ? value : ""; + } -std::string -octave_env::do_getenv (const std::string& name) const -{ - char *value = ::getenv (name.c_str ()); + // Do the work of changing to the directory NEWDIR. Handle symbolic + // link following, etc. + + bool + env::do_chdir (const std::string& newdir) + { + bool retval = false; - return value ? value : ""; -} + std::string tmp; + + if (follow_symbolic_links) + { + if (current_directory.empty ()) + do_getcwd (); -// Do the work of changing to the directory NEWDIR. Handle symbolic -// link following, etc. + if (current_directory.empty ()) + tmp = newdir; + else + tmp = do_make_absolute (newdir, current_directory); -bool -octave_env::do_chdir (const std::string& newdir) -{ - bool retval = false; + // Get rid of trailing directory separator. + + size_t len = tmp.length (); - std::string tmp; + if (len > 1) + { + if (file_ops::is_dir_sep (tmp[--len])) + tmp.resize (len); + } - if (follow_symbolic_links) - { - if (current_directory.empty ()) - do_getcwd (); - - if (current_directory.empty ()) - tmp = newdir; + if (! ::octave_chdir (tmp)) + { + current_directory = tmp; + retval = true; + } + } else - tmp = do_make_absolute (newdir, current_directory); + retval = (! ::octave_chdir (newdir)); - // Get rid of trailing directory separator. + return retval; + } + + // Remove the last N directories from PATH. - size_t len = tmp.length (); + void + env::pathname_backup (std::string& path, int n) const + { + if (path.empty ()) + return; + + size_t i = path.length () - 1; - if (len > 1) + while (n--) { - if (file_ops::is_dir_sep (tmp[--len])) - tmp.resize (len); + while (file_ops::is_dir_sep (path[i]) && i > 0) + i--; + + while (! file_ops::is_dir_sep (path[i]) && i > 0) + i--; + + i++; } - if (! ::octave_chdir (tmp)) - { - current_directory = tmp; - retval = true; - } - } - else - retval = (! ::octave_chdir (newdir)); - - return retval; -} - -// Remove the last N directories from PATH. - -void -octave_env::pathname_backup (std::string& path, int n) const -{ - if (path.empty ()) - return; - - size_t i = path.length () - 1; - - while (n--) - { - while (file_ops::is_dir_sep (path[i]) && i > 0) - i--; - - while (! file_ops::is_dir_sep (path[i]) && i > 0) - i--; - - i++; + path.resize (i); } - path.resize (i); -} + void + env::error (int err_num) const + { + (*current_liboctave_error_handler) ("%s", gnulib::strerror (err_num)); + } -void -octave_env::error (int err_num) const -{ - (*current_liboctave_error_handler) ("%s", gnulib::strerror (err_num)); + void + env::error (const std::string& s) const + { + (*current_liboctave_error_handler) ("%s", s.c_str ()); + } + } } - -void -octave_env::error (const std::string& s) const -{ - (*current_liboctave_error_handler) ("%s", s.c_str ()); -}
--- a/liboctave/system/oct-env.h Wed May 18 14:09:17 2016 -0400 +++ b/liboctave/system/oct-env.h Wed May 18 14:58:29 2016 -0400 @@ -27,122 +27,137 @@ #include <string> -class -OCTAVE_API -octave_env +namespace +octave { -protected: - - octave_env (void); - -public: + namespace + sys + { + class + OCTAVE_API + env + { + protected: - static std::string polite_directory_format (const std::string& name); + env (void); - static bool absolute_pathname (const std::string& s); + public: - static bool rooted_relative_pathname (const std::string& s); + static std::string polite_directory_format (const std::string& name); - static std::string base_pathname (const std::string& s); + static bool absolute_pathname (const std::string& s); - static std::string - make_absolute (const std::string& s, - const std::string& dot_path = get_current_directory ()); + static bool rooted_relative_pathname (const std::string& s); + + static std::string base_pathname (const std::string& s); - static std::string get_current_directory (void); + static std::string + make_absolute (const std::string& s, + const std::string& dot_path = get_current_directory ()); - static std::string get_home_directory (void); - - static std::string get_temp_directory (void); + static std::string get_current_directory (void); - static std::string get_program_name (void); + static std::string get_home_directory (void); - static std::string get_program_invocation_name (void); + static std::string get_temp_directory (void); - static std::string get_user_name (void); + static std::string get_program_name (void); - static std::string get_host_name (void); + static std::string get_program_invocation_name (void); - static std::string getenv (const std::string& name); + static std::string get_user_name (void); - static void putenv (const std::string& name, const std::string& value); + static std::string get_host_name (void); - static bool have_x11_display (void); + static std::string getenv (const std::string& name); + + static void putenv (const std::string& name, const std::string& value); - static bool chdir (const std::string& newdir); + static bool have_x11_display (void); - static void set_program_name (const std::string& s); + static bool chdir (const std::string& newdir); -private: + static void set_program_name (const std::string& s); - static bool instance_ok (void); + private: + + static bool instance_ok (void); - std::string do_polite_directory_format (const std::string& name) const; + std::string do_polite_directory_format (const std::string& name) const; - bool do_absolute_pathname (const std::string& s) const; + bool do_absolute_pathname (const std::string& s) const; - bool do_rooted_relative_pathname (const std::string& s) const; + bool do_rooted_relative_pathname (const std::string& s) const; - std::string do_base_pathname (const std::string& s) const; + std::string do_base_pathname (const std::string& s) const; - std::string do_make_absolute (const std::string& s, - const std::string& dot_path) const; + std::string do_make_absolute (const std::string& s, + const std::string& dot_path) const; - std::string do_getcwd (void) const; + std::string do_getcwd (void) const; - std::string do_get_home_directory (void) const; + std::string do_get_home_directory (void) const; - std::string do_get_temp_directory (void) const; + std::string do_get_temp_directory (void) const; - std::string do_get_user_name (void) const; + std::string do_get_user_name (void) const; - std::string do_get_host_name (void) const; + std::string do_get_host_name (void) const; - std::string do_getenv (const std::string& name) const; + std::string do_getenv (const std::string& name) const; - void do_putenv (const std::string& name, const std::string& value) const; + void do_putenv (const std::string& name, const std::string& value) const; - bool do_chdir (const std::string& newdir); + bool do_chdir (const std::string& newdir); - void do_set_program_name (const std::string& s) const; + void do_set_program_name (const std::string& s) const; - void pathname_backup (std::string& path, int n) const; + void pathname_backup (std::string& path, int n) const; - void error (int) const; + void error (int) const; - void error (const std::string&) const; + void error (const std::string&) const; - // No copying! + // No copying! - octave_env (const octave_env&); + env (const env&); - octave_env& operator = (const octave_env&); + env& operator = (const env&); - // The real thing. - static octave_env *instance; + // The real thing. + static env *instance; - static void cleanup_instance (void) { delete instance; instance = 0; } + static void cleanup_instance (void) { delete instance; instance = 0; } + + // TRUE means follow symbolic links that point to directories just + // as if they are real directories. + bool follow_symbolic_links; - // TRUE means follow symbolic links that point to directories just - // as if they are real directories. - bool follow_symbolic_links; + // TRUE means that pwd always give verbatim directory, regardless + // of symbolic link following. + bool verbatim_pwd; - // TRUE means that pwd always give verbatim directory, regardless - // of symbolic link following. - bool verbatim_pwd; + // Where are we? + mutable std::string current_directory; - // Where are we? - mutable std::string current_directory; + // Etc. + mutable std::string prog_name; - // Etc. - mutable std::string prog_name; + mutable std::string prog_invocation_name; + + mutable std::string user_name; - mutable std::string prog_invocation_name; + mutable std::string host_name; + }; + } +} - mutable std::string user_name; +#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) - mutable std::string host_name; -}; +OCTAVE_DEPRECATED ("use octave::sys::env instead") +typedef octave::sys::env octave_env; #endif + +#endif
--- a/liboctave/util/cmd-edit.cc Wed May 18 14:09:17 2016 -0400 +++ b/liboctave/util/cmd-edit.cc Wed May 18 14:58:29 2016 -0400 @@ -235,7 +235,7 @@ // FIXME: need interface to rl_add_defun, rl_initialize, and // a function to set rl_terminal_name - std::string term = octave_env::getenv ("TERM"); + std::string term = octave::sys::env::getenv ("TERM"); octave_rl_set_terminal_name (term.c_str ()); @@ -1636,7 +1636,7 @@ case 'h': { - tmpstr = octave_env::get_host_name (); + tmpstr = octave::sys::env::get_host_name (); size_t pos = tmpstr.find ('.'); @@ -1648,7 +1648,7 @@ case 'H': { - tmpstr = octave_env::get_host_name (); + tmpstr = octave::sys::env::get_host_name (); break; } @@ -1669,15 +1669,15 @@ case 's': { - tmpstr = octave_env::get_program_name (); - tmpstr = octave_env::base_pathname (tmpstr); + tmpstr = octave::sys::env::get_program_name (); + tmpstr = octave::sys::env::base_pathname (tmpstr); break; } case 'u': { - tmpstr = octave_env::get_user_name (); + tmpstr = octave::sys::env::get_user_name (); break; } @@ -1687,14 +1687,14 @@ { try { - tmpstr = octave_env::get_current_directory (); + tmpstr = octave::sys::env::get_current_directory (); } catch (const octave_execution_exception&) { tmpstr = ""; } - std::string home_dir = octave_env::get_home_directory (); + std::string home_dir = octave::sys::env::get_home_directory (); if (c == 'W' && (home_dir.empty () || tmpstr != home_dir)) { @@ -1707,7 +1707,7 @@ } } else - tmpstr = octave_env::polite_directory_format (tmpstr); + tmpstr = octave::sys::env::polite_directory_format (tmpstr); break; }
--- a/liboctave/util/kpse.cc Wed May 18 14:09:17 2016 -0400 +++ b/liboctave/util/kpse.cc Wed May 18 14:58:29 2016 -0400 @@ -516,7 +516,7 @@ { std::string ret; - std::string tmp = octave_env::getenv (var); + std::string tmp = octave::sys::env::getenv (var); if (! tmp.empty ()) ret = kpse_var_expand (tmp); @@ -1200,7 +1200,7 @@ } else if (name.length () == 1) { - expansion = octave_env::get_home_directory (); + expansion = octave::sys::env::get_home_directory (); if (expansion.empty ()) expansion = "."; @@ -1211,7 +1211,7 @@ else if (IS_DIR_SEP (name[1])) { unsigned c = 1; - std::string home = octave_env::get_home_directory (); + std::string home = octave::sys::env::get_home_directory (); if (home.empty ()) home = "."; @@ -1292,7 +1292,7 @@ kpse_expand_kpse_dot (const std::string& path) { std::string ret; - std::string kpse_dot = octave_env::getenv ("KPSE_DOT"); + std::string kpse_dot = octave::sys::env::getenv ("KPSE_DOT"); if (kpse_dot.empty ()) return path; @@ -2553,7 +2553,7 @@ else { /* Check for an environment variable. */ - std::string value = octave_env::getenv (var); + std::string value = octave::sys::env::getenv (var); if (! value.empty ()) {
--- a/liboctave/util/pathsearch.cc Wed May 18 14:09:17 2016 -0400 +++ b/liboctave/util/pathsearch.cc Wed May 18 14:58:29 2016 -0400 @@ -145,7 +145,7 @@ if (! octave_kpathsea_initialized) { - std::string val = octave_env::getenv ("KPATHSEA_DEBUG"); + std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG"); if (! val.empty ()) kpathsea_debug |= atoi (val.c_str ());