From 96ee270933fe88672b70eb22045b280bf9ee4d90 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 17 Dec 2007 15:15:37 +0000 Subject: [PATCH] transfer os::is_absolute_path() to FileName::isAbsolute(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22187 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Session.cpp | 8 ++++---- src/support/FileName.cpp | 6 ++++++ src/support/FileName.h | 3 +++ src/support/Package.cpp | 10 ++++++---- src/support/filetools.cpp | 13 ++++++++----- src/support/os.h | 4 ---- src/support/os_cygwin.cpp | 14 +------------- src/support/os_unix.cpp | 6 ------ src/support/os_win32.cpp | 34 ++-------------------------------- 9 files changed, 30 insertions(+), 68 deletions(-) diff --git a/src/Session.cpp b/src/Session.cpp index 05f02230eb..a9b5e86f46 100644 --- a/src/Session.cpp +++ b/src/Session.cpp @@ -163,9 +163,9 @@ void LastFilePosSection::read(istream & is) itmp >> filepos.pos; itmp.ignore(2); // ignore ", " getline(itmp, fname); - if (!absolutePath(fname)) - continue; FileName const file(fname); + if (!file.isAbsolute()) + continue; if (file.exists() && !file.isDirectory() && lastfilepos.size() < num_lastfilepos) lastfilepos[file] = filepos; @@ -240,9 +240,9 @@ void BookmarksSection::read(istream & is) itmp >> pos; itmp.ignore(2); // ignore ", " getline(itmp, fname); - if (!absolutePath(fname)) - continue; FileName const file(fname); + if (!file.isAbsolute()) + continue; // only load valid bookmarks if (file.exists() && !file.isDirectory() && idx <= max_bookmarks) bookmarks[idx] = Bookmark(file, pit, pos, 0, 0); diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index 5e4ea0ec2e..1f7803dec4 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -140,6 +140,12 @@ bool FileName::empty() const } +bool FileName::isAbsolute() const +{ + return d->fi.isAbsolute(); +} + + string FileName::absFilename() const { return fromqstr(d->fi.absoluteFilePath()); diff --git a/src/support/FileName.h b/src/support/FileName.h index 2ded3001c0..bee3a844f1 100644 --- a/src/support/FileName.h +++ b/src/support/FileName.h @@ -55,6 +55,9 @@ public: virtual void erase(); /// Is this filename empty? bool empty() const; + /// Is the filename absolute? + bool isAbsolute() const; + /// get the absolute file name in UTF-8 encoding std::string absFilename() const; /** diff --git a/src/support/Package.cpp b/src/support/Package.cpp index 4c886029a5..774bcc043d 100644 --- a/src/support/Package.cpp +++ b/src/support/Package.cpp @@ -379,8 +379,9 @@ FileName const abs_path_from_command_line(string const & command_line) if (command_line.empty()) return FileName(); - string const path = fix_dir_name(command_line); - return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path); + string const str_path = fix_dir_name(command_line); + FileName path(str_path); + return path.isAbsolute() ? path : makeAbsPath(str_path); } @@ -397,8 +398,9 @@ FileName const get_binary_path(string const & exe) #else string const exe_path = os::internal_path(exe); #endif - if (os::is_absolute_path(exe_path)) - return FileName(exe_path); + FileName exepath(exe_path); + if (exepath.isAbsolute()) + return exepath; // Two possibilities present themselves. // 1. The binary is relative to the CWD. diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 73067ea751..421e016be5 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -395,9 +395,10 @@ string const onlyPath(string const & filename) // If basepath is empty, use CWD as base. FileName const makeAbsPath(string const & relPath, string const & basePath) { + FileName relative_path(relPath); // checks for already absolute path - if (os::is_absolute_path(relPath)) - return FileName(relPath); + if (relative_path.isAbsolute()) + return relative_path; // Copies given paths string tempRel = os::internal_path(relPath); @@ -406,7 +407,8 @@ FileName const makeAbsPath(string const & relPath, string const & basePath) string tempBase; - if (os::is_absolute_path(basePath)) + FileName base_path(basePath); + if (base_path.isAbsolute()) tempBase = basePath; else tempBase = addPath(FileName::getcwd().absFilename(), basePath); @@ -487,7 +489,7 @@ string const onlyFilename(string const & fname) /// Returns true is path is absolute bool absolutePath(string const & path) { - return os::is_absolute_path(path); + return FileName(path).isAbsolute(); } @@ -497,7 +499,8 @@ string const expandPath(string const & path) { // checks for already absolute path string rTemp = replaceEnvironmentPath(path); - if (os::is_absolute_path(rTemp)) + FileName abs_path(rTemp); + if (abs_path.isAbsolute()) return rTemp; string temp; diff --git a/src/support/os.h b/src/support/os.h index 899b948296..2d41dd7626 100644 --- a/src/support/os.h +++ b/src/support/os.h @@ -71,10 +71,6 @@ std::string internal_path_list(std::string const & p); */ std::string latex_path(std::string const & p); -/// Is the path absolute? -/// \p p is encoded in utf8. -bool is_absolute_path(std::string const & p); - /** Returns a string suitable to be passed to popen when * reading a file. */ diff --git a/src/support/os_cygwin.cpp b/src/support/os_cygwin.cpp index cf57336f7d..b498272907 100644 --- a/src/support/os_cygwin.cpp +++ b/src/support/os_cygwin.cpp @@ -187,7 +187,7 @@ string latex_path(string const & p) // on windows_style_tex_paths_), but we use always forward slashes, // since it gets written into a .tex file. - if (windows_style_tex_paths_ && is_absolute_path(p)) { + if (windows_style_tex_paths_ && FileName(p).isAbsolute()) { string dos_path = convert_path(p, PathStyle(windows)); LYXERR(Debug::LATEX, " [" << p << "]->>[" << dos_path << ']'); @@ -198,18 +198,6 @@ string latex_path(string const & p) } -bool is_absolute_path(string const & p) -{ - if (p.empty()) - return false; - - bool isDosPath = (p.length() > 1 && p[1] == ':'); - bool isUnixPath = (p[0] == '/'); - - return isDosPath || isUnixPath; -} - - // returns a string suitable to be passed to popen when // reading a pipe char const * popen_read_mode() diff --git a/src/support/os_unix.cpp b/src/support/os_unix.cpp index 8e61c65649..84c00cfb12 100644 --- a/src/support/os_unix.cpp +++ b/src/support/os_unix.cpp @@ -85,12 +85,6 @@ string latex_path(string const & p) } -bool is_absolute_path(string const & p) -{ - return !p.empty() && p[0] == '/'; -} - - char const * popen_read_mode() { return "r"; diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp index cb84bb7cb9..6f89eafa79 100644 --- a/src/support/os_win32.cpp +++ b/src/support/os_win32.cpp @@ -240,7 +240,8 @@ string latex_path(string const & p) // on windows_style_tex_paths_), but we use always forward slashes, // since it gets written into a .tex file. - if (!windows_style_tex_paths_ && is_absolute_path(p)) { + FileName path(p); + if (!windows_style_tex_paths_ && path.isAbsolute()) { string const drive = p.substr(0, 2); string const cygprefix = cygdrive + "/" + drive.substr(0, 1); string const cygpath = subst(subst(p, '\\', '/'), drive, cygprefix); @@ -252,37 +253,6 @@ string latex_path(string const & p) } -// (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used. -// Therefore an absolute path could be either a pathname starting -// with a slash (Unix) or a pathname starting with a drive letter -// followed by a colon. Because a colon is not valid in pathes in Unix -// and at another location in Win32 testing just for the existance -// of the colon in the 2nd position seems to be enough! -// FIXME: Port to FileName! -bool is_absolute_path(string const & p) -{ - if (p.empty()) - return false; - - if (p[0] == '/') - // Unix style. - return true; - - if (p.length() <= 1) - return false; - - if (p[1] == ':') - // 'X:\' style. - return true; - - if (p[0] == '\\' && p[1] == '\\') - // Network folder style: '\\server\share' - return true; - - return false; -} - - // returns a string suitable to be passed to popen when // reading a pipe char const * popen_read_mode() -- 2.39.2