]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.C
fix compiler warnings about unused parameter
[lyx.git] / src / support / filetools.C
index 8ba5c0f5951346373b53e01620f05a1a9d885962..7a8448df49dda1c3233fc3685ea566999977ab1a 100644 (file)
@@ -165,16 +165,16 @@ bool isFileReadable(FileName const & filename)
 
 //returns true: dir writeable
 //       false: not writeable
-bool isDirWriteable(string const & path)
+bool isDirWriteable(FileName const & path)
 {
        lyxerr[Debug::FILES] << "isDirWriteable: " << path << endl;
 
-       string const tmpfl = tempName(path, "lyxwritetest");
+       FileName const tmpfl(tempName(path, "lyxwritetest"));
 
        if (tmpfl.empty())
                return false;
 
-       unlink(FileName(tmpfl));
+       unlink(tmpfl);
        return true;
 }
 
@@ -218,10 +218,10 @@ FileName const fileOpenSearch(string const & path, string const & name,
 
 
 /// Returns a vector of all files in directory dir having extension ext.
-vector<string> const dirList(FileName const & dir, string const & ext)
+vector<FileName> const dirList(FileName const & dir, string const & ext)
 {
        // EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
-       vector<string> dirlist;
+       vector<FileName> dirlist;
 
        string const encoded_dir = dir.toFilesystemEncoding();
        if (!(fs::exists(encoded_dir) && fs::is_directory(encoded_dir))) {
@@ -240,10 +240,9 @@ vector<string> const dirList(FileName const & dir, string const & ext)
        fs::directory_iterator end;
        for (; dit != end; ++dit) {
                string const & fil = dit->leaf();
-               if (suffixIs(fil, extension)) {
-                       // FIXME UNICODE: We need to convert from filesystem encoding to utf8
-                       dirlist.push_back(fil);
-               }
+               if (suffixIs(fil, extension))
+                       dirlist.push_back(FileName::fromFilesystemEncoding(
+                                       encoded_dir + '/' + fil));
        }
        return dirlist;
 }
@@ -377,20 +376,20 @@ FileName const createTmpDir(FileName const & tempdir, string const & mask)
                << "createTmpDir: tempdir=`" << tempdir << "'\n"
                << "createTmpDir:    mask=`" << mask << '\'' << endl;
 
-       string const tmpfl = tempName(tempdir.absFilename(), mask);
+       FileName const tmpfl(tempName(tempdir, mask));
        // lyx::tempName actually creates a file to make sure that it
        // stays unique. So we have to delete it before we can create
        // a dir with the same name. Note also that we are not thread
        // safe because of the gap between unlink and mkdir. (Lgb)
-       unlink(FileName(tmpfl));
+       unlink(tmpfl);
 
-       if (tmpfl.empty() || mkdir(FileName(tmpfl), 0700)) {
+       if (tmpfl.empty() || mkdir(tmpfl, 0700)) {
                lyxerr << "LyX could not create the temporary directory '"
                       << tmpfl << "'" << endl;
                return FileName();
        }
 
-       return FileName(tmpfl);
+       return tmpfl;
 }
 
 } // namespace anon
@@ -430,7 +429,7 @@ FileName const createLyXTmpDir(FileName const & deflt)
 {
        if (!deflt.empty() && deflt.absFilename() != "/tmp") {
                if (mkdir(deflt, 0777)) {
-                       if (isDirWriteable(deflt.absFilename())) {
+                       if (isDirWriteable(deflt)) {
                                // deflt could not be created because it
                                // did exist already, so let's create our own
                                // dir inside deflt.
@@ -471,11 +470,11 @@ string const onlyPath(string const & filename)
 // Convert relative path into absolute path based on a basepath.
 // If relpath is absolute, just use that.
 // If basepath is empty, use CWD as base.
-string const makeAbsPath(string const & relPath, string const & basePath)
+FileName const makeAbsPath(string const & relPath, string const & basePath)
 {
        // checks for already absolute path
        if (os::is_absolute_path(relPath))
-               return relPath;
+               return FileName(relPath);
 
        // Copies given paths
        string tempRel = os::internal_path(relPath);
@@ -487,7 +486,7 @@ string const makeAbsPath(string const & relPath, string const & basePath)
        if (os::is_absolute_path(basePath))
                tempBase = basePath;
        else
-               tempBase = addPath(getcwd(), basePath);
+               tempBase = addPath(getcwd().absFilename(), basePath);
 
        // Handle /./ at the end of the path
        while (suffixIs(tempBase, "/./"))
@@ -525,7 +524,7 @@ string const makeAbsPath(string const & relPath, string const & basePath)
        }
 
        // returns absolute path
-       return os::internal_path(tempBase);
+       return FileName(os::internal_path(tempBase));
 }
 
 
@@ -585,13 +584,13 @@ string const expandPath(string const & path)
        rTemp = split(rTemp, temp, '/');
 
        if (temp == ".")
-               return getcwd() + '/' + rTemp;
+               return getcwd().absFilename() + '/' + rTemp;
 
        if (temp == "~")
                return package().home_dir() + '/' + rTemp;
 
        if (temp == "..")
-               return makeAbsPath(copy);
+               return makeAbsPath(copy).absFilename();
 
        // Don't know how to handle this
        return copy;
@@ -1000,7 +999,7 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
                str = subst(str, home, "~");
 
        if (str.length() <= threshold)
-               return lyx::from_utf8(os::external_path(str));
+               return from_utf8(os::external_path(str));
 
        string const prefix = ".../";
        string temp;
@@ -1021,7 +1020,7 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
                str = head + "..." + tail;
        }
 
-       return lyx::from_utf8(os::external_path(prefix + str));
+       return from_utf8(os::external_path(prefix + str));
 }
 
 
@@ -1036,7 +1035,7 @@ bool readLink(string const & file, string & link, bool resolve)
                return false;
        linkbuffer[nRead] = '\0'; // terminator
        if (resolve)
-               link = makeAbsPath(linkbuffer, onlyPath(file));
+               link = makeAbsPath(linkbuffer, onlyPath(file)).absFilename();
        else
                link = linkbuffer;
        return true;
@@ -1136,10 +1135,11 @@ FileName const findtexfile(string const & fil, string const & /*format*/)
        cmd_ret const c = runCommand(kpsecmd);
 
        lyxerr[Debug::LATEX] << "kpse status = " << c.first << '\n'
-                << "kpse result = `" << rtrim(c.second, "\n")
+                << "kpse result = `" << rtrim(c.second, "\n\r")
                 << '\'' << endl;
        if (c.first != -1)
-               return FileName(os::internal_path(rtrim(c.second, "\n\r")));
+               return FileName(os::internal_path(rtrim(to_utf8(from_filesystem8bit(c.second)),
+                                                       "\n\r")));
        else
                return FileName();
 }