Mercurial > hg > octave-nkf
changeset 4097:596f88296519
[project @ 2002-10-09 20:26:27 by jwe]
author | jwe |
---|---|
date | Wed, 09 Oct 2002 20:26:27 +0000 |
parents | 66d7394f5822 |
children | 8496ae60db8a |
files | liboctave/ChangeLog liboctave/file-ops.cc liboctave/file-ops.h liboctave/oct-env.cc liboctave/oct-env.h src/ChangeLog src/octave.cc |
diffstat | 7 files changed, 96 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,23 @@ +2002-10-09 John W. Eaton <jwe@bevo.che.wisc.edu> + + * oct-env.h (octave_env::current_directory): Now mutable. + (octave_env:do_getcwd): Now const. + + * file-ops.h, file-ops.cc (file_ops::is_dir_sep): New function. + (OCTAVE_DIR_SEP_CHAR, OCTAVE_DIR_SEP_STR, OCTAVE_DIR_SEP_CHARS, + OCTAVE_CURRENT_DIR_STR): New macros. + * oct-env.cc (is_dir_sep): Delete. + (octave_env::do_base_pathname): Look for OCTAVE_DIR_SEP_CHARS, not '/'. + (octave_env::do_set_program_name): Likewise. + (octave_env::do_polite_directory_format): Use file_ops::is_dir_sep + instead of checking for '/'. + (octave_env::pathname_backup): Likewise. + (octave_env::do_absolute_pathname): Likewise. + (octave_env::do_make_absolute): Likewise. + If dot_path is empty, use getcwd to set current_dir. + (octave_env::do_get_home_directory): Use OCTAVE_DIR_SEP_STR + instead of "/". + 2002-10-07 Paul Kienzle <pkienzle@users.sf.net> * lo-cutils.c: On non-Posix Windows systems, include winsock.h.
--- a/liboctave/file-ops.cc +++ b/liboctave/file-ops.cc @@ -620,6 +620,16 @@ return status; } +bool +file_ops::is_dir_sep (char c) +{ +#if defined (__WIN32__) + return (c == '/' || c == '\\'); +#else + return (c == '/'); +#endif +} + /* ;;; Local Variables: *** ;;; mode: C++ ***
--- a/liboctave/file-ops.h +++ b/liboctave/file-ops.h @@ -76,8 +76,18 @@ static int unlink (const std::string&); static int unlink (const std::string&, std::string&); + + static bool is_dir_sep (char); }; +#define OCTAVE_DIR_SEP_CHAR '/' +#define OCTAVE_DIR_SEP_STR "/" +#if defined (__WIN32__) +#define OCTAVE_DIR_SEP_CHARS "/\\" +#else +#define OCTAVE_DIR_SEP_CHARS OCTAVE_DIR_SEP_STR +#endif + #endif /*
--- a/liboctave/oct-env.cc +++ b/liboctave/oct-env.cc @@ -52,6 +52,7 @@ #include <unistd.h> #endif +#include "file-ops.h" #include "lo-error.h" #include "lo-sysdep.h" #include "lo-utils.h" @@ -200,7 +201,7 @@ { program_invocation_name = s; - size_t pos = program_invocation_name.rfind ('/'); + size_t pos = program_invocation_name.find_last_of (OCTAVE_DIR_SEP_CHARS); program_name = (pos == NPOS) ? program_invocation_name : program_invocation_name.substr (pos+1); @@ -219,7 +220,7 @@ size_t len = home_dir.length (); if (len > 1 && home_dir == name.substr (0, len) - && (name.length () == len || name[len] == '/')) + && (name.length () == len || file_ops::is_dir_sep (name[len]))) { retval = "~"; retval.append (name.substr (len)); @@ -230,16 +231,6 @@ return retval; } -static inline bool -is_dir_sep (char c) -{ -#if defined (__CYGWIN__) - return (c == '/' || c == '\\'); -#else - return (c == '/'); -#endif -} - bool octave_env::do_absolute_pathname (const std::string& s) const { @@ -248,12 +239,15 @@ if (len == 0) return false; - if (s[0] == '/') +#if defined (__CYGWIN__) || ! defined (__WIN32__) + if (file_ops::is_dir_sep (s[0])) return true; +#endif #if defined (__WIN32__) if ((len == 2 && isalpha (s[0]) && s[1] == ':') - || (len > 2 && isalpha (s[0]) && s[1] == ':' && is_dir_sep (s[2]))) + || (len > 2 && isalpha (s[0]) && s[1] == ':' + && file_ops::is_dir_sep (s[2]))) return true; #endif @@ -261,7 +255,8 @@ } // Return the `basename' of the pathname in STRING (the stuff after -// the last '/'). If STRING is not a full pathname, simply return it. +// the last directory separator). If STRING is not a full pathname, +// simply return it. std::string octave_env::do_base_pathname (const std::string& s) const @@ -269,7 +264,7 @@ if (! do_absolute_pathname (s)) return s; - size_t pos = s.rfind ('/'); + size_t pos = s.find_last_of (OCTAVE_DIR_SEP_CHARS); if (pos == NPOS) return s; @@ -278,7 +273,7 @@ } // Turn STRING (a pathname) into an absolute pathname, assuming that -// DOT_PATH contains the symbolic location of '.'. +// DOT_PATH contains the symbolic location of the current directory. std::string octave_env::do_make_absolute (const std::string& s, @@ -292,15 +287,17 @@ if (dot_path.empty () || s.empty () || do_absolute_pathname (s)) return s; - std::string current_path = dot_path; + std::string current_dir = dot_path; - if (current_path.empty ()) - current_path = "./"; + if (current_dir.empty ()) + current_dir = do_getcwd (); - size_t pos = current_path.length () - 1; + size_t pos = current_dir.length () - 1; - if (current_path[pos] != '/') - current_path.append ("/"); + if (! file_ops::is_dir_sep (current_dir[pos])) + current_dir.append (OCTAVE_DIR_SEP_STR); + + // XXX FIXME XXX -- this is probably not correct for all systems. size_t i = 0; size_t slen = s.length (); @@ -310,48 +307,49 @@ if (s[i] == '.') { if (i + 1 == slen) - return current_path; + return current_dir; - if (s[i+1] == '/') + if (file_ops::is_dir_sep (s[i+1])) { i += 2; continue; } - if (s[i+1] == '.' && (i + 2 == slen || s[i+2] == '/')) + if (s[i+1] == '.' + && (i + 2 == slen || file_ops::is_dir_sep (s[i+2]))) { i += 2; if (i != slen) i++; - pathname_backup (current_path, 1); + pathname_backup (current_dir, 1); continue; } } - size_t tmp = s.find ('/', i); + size_t tmp = s.find_first_of (OCTAVE_DIR_SEP_CHARS, i); if (tmp == NPOS) { - current_path.append (s, i, tmp-i); + current_dir.append (s, i, tmp-i); break; } else { - current_path.append (s, i, tmp-i+1); + current_dir.append (s, i, tmp-i+1); i = tmp + 1; } } - return current_path; + return current_dir; } -// Return a consed string which is the current working directory. +// Return a string which is the current working directory. std::string -octave_env::do_getcwd () +octave_env::do_getcwd () const { if (! follow_symbolic_links) current_directory = ""; @@ -374,7 +372,7 @@ { octave_passwd pw = octave_passwd::getpwuid (octave_syscalls::getuid ()); - hd = pw ? pw.dir () : std::string ("/"); + hd = pw ? pw.dir () : std::string (OCTAVE_DIR_SEP_STR); } return hd; @@ -442,13 +440,13 @@ else tmp = do_make_absolute (newdir, current_directory); - // Get rid of trailing `/'. + // Get rid of trailing directory separator. size_t len = tmp.length (); if (len > 1) { - if (is_dir_sep (tmp[--len])) + if (file_ops::is_dir_sep (tmp[--len])) tmp.resize (len); } @@ -476,10 +474,10 @@ while (n--) { - while (path[i] == '/' && i > 0) + while (file_ops::is_dir_sep (path[i]) && i > 0) i--; - while (path[i] != '/' && i > 0) + while (! file_ops::is_dir_sep (path[i]) && i > 0) i--; i++;
--- a/liboctave/oct-env.h +++ b/liboctave/oct-env.h @@ -40,7 +40,8 @@ static std::string base_pathname (const std::string& s); - static std::string make_absolute (const std::string& s, const std::string& dot_path); + static std::string make_absolute (const std::string& s, + const std::string& dot_path); static std::string getcwd (void); @@ -72,9 +73,10 @@ 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); + std::string do_getcwd (void) const; std::string do_get_home_directory (void) const; @@ -114,7 +116,7 @@ bool verbatim_pwd; // Where are we? - std::string current_directory; + mutable std::string current_directory; // Etc. mutable std::string program_name;
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2002-10-09 John W. Eaton <jwe@bevo.che.wisc.edu> + + * octave.cc (execute_startup_files): + Use octave_env::getcwd instead of "./". + Use OCTAVE_DIR_SEP_STR instead of "/". + (initialize_pathsearch): Use OCTAVE_DIR_SEP_STR instead of /. + (main): Look for OCTAVE_DIR_SEP_CHARS, not '/'. + 2002-10-08 John W. Eaton <jwe@bevo.che.wisc.edu> * Makefile.in (gendoc): Use $(BUILD_CXX), not $(CXX).
--- a/src/octave.cc +++ b/src/octave.cc @@ -43,6 +43,7 @@ #include "cmd-edit.h" #include "f77-fcn.h" +#include "file-ops.h" #include "file-stat.h" #include "lo-error.h" #include "oct-env.h" @@ -190,7 +191,8 @@ odb = octave_env::getenv ("OCTAVE_DB_DIR"); if (odb.empty ()) - odb = Vdata_dir + std::string ("/octave:") + Vlibexec_dir + std::string ("/octave"); + odb = Vdata_dir + OCTAVE_DIR_SEP_STR + "octave:" + + Vlibexec_dir + OCTAVE_DIR_SEP_STR + "octave"; octave_original_texmfdbs = octave_env::getenv ("TEXMFDBS"); @@ -240,8 +242,8 @@ std::string home_dir = octave_env::get_home_directory (); - std::string home_rc = home_dir + "/" + initfile; - std::string local_rc = std::string ("./") + initfile; + std::string home_rc = home_dir + OCTAVE_DIR_SEP_STR + initfile; + std::string local_rc = octave_env::getcwd () + initfile; if (! home_dir.empty ()) { @@ -536,7 +538,7 @@ bind_builtin_variable ("program_invocation_name", curr_fcn_file_name); - size_t pos = curr_fcn_file_name.rfind ('/'); + size_t pos = curr_fcn_file_name.find_last_of (OCTAVE_DIR_SEP_CHARS); std::string tmp = (pos != NPOS) ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name;