]> git.lyx.org Git - features.git/commitdiff
transfer os::is_absolute_path() to FileName::isAbsolute().
authorAbdelrazak Younes <younes@lyx.org>
Mon, 17 Dec 2007 15:15:37 +0000 (15:15 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 17 Dec 2007 15:15:37 +0000 (15:15 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22187 a592a061-630c-0410-9148-cb99ea01b6c8

src/Session.cpp
src/support/FileName.cpp
src/support/FileName.h
src/support/Package.cpp
src/support/filetools.cpp
src/support/os.h
src/support/os_cygwin.cpp
src/support/os_unix.cpp
src/support/os_win32.cpp

index 05f02230ebe40a179ef31a0dbd85e9a5a893f91f..a9b5e86f46af6ac30fcc457dbe85e6d8e9e23996 100644 (file)
@@ -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);
index 5e4ea0ec2ecc4d80df724d53d1047bb283aac80f..1f7803dec4e61fca6b5800951c23bf9250dac145 100644 (file)
@@ -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());
index 2ded3001c0d8e38c24bb8e80af052b51ee4ceb06..bee3a844f1bd062becf720812e0e5bda7ecaf597 100644 (file)
@@ -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;
        /**
index 4c886029a50af679b1d2c4b23560e1923c7d4549..774bcc043de3dc3cdabb785e60c6ea344537b183 100644 (file)
@@ -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.
index 73067ea751f547e9f6099978b75a92c20c1c4e10..421e016be5c191a81c64eb00a6a9c28e2db848d5 100644 (file)
@@ -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;
index 899b9482969eeb3e2b2f76afac3c2631cf9dda47..2d41dd76267a6d2f377ed44c55de3a01ab455453 100644 (file)
@@ -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.
  */
index cf57336f7dd176210c7ab29aff29db71a40779ee..b498272907e958d9c5cd44b6843007b2f655c26b 100644 (file)
@@ -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, "<Path correction for 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()
index 8e61c6564912bdf757ac6764b3e23d9d024ec262..84c00cfb1274310b7436dff087fd4ca537607a62 100644 (file)
@@ -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";
index cb84bb7cb95facb5c631b3d76113e07bbd5e56e8..6f89eafa79989c322f1b0e1eda35b1f1b42e61eb 100644 (file)
@@ -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()