]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.C
hopefully fix tex2lyx linking.
[lyx.git] / src / support / filetools.C
index 4c69d085328a88cd2f5165bbda9faa5ffaed7c6e..c2d5453aef8b5463eee9c1dcf48a33fbf28d8c98 100644 (file)
@@ -133,11 +133,26 @@ string const makeLatexName(string const & file)
 }
 
 
-string const quoteName(string const & name)
+string const quoteName(string const & name, quote_style style)
 {
-       return (os::shell() == os::UNIX) ?
-               '\'' + name + '\'':
-               '"' + name + '"';
+       switch(style) {
+       case quote_shell:
+               // This does not work for filenames containing " (windows)
+               // or ' (all other OSes). This can't be changed easily, since
+               // we would need to adapt the command line parser in
+               // Forkedcall::generateChild. Therefore we don't pass user
+               // filenames to child processes if possible. We store them in
+               // a python script instead, where we don't have these
+               // limitations.
+               return (os::shell() == os::UNIX) ?
+                       '\'' + name + '\'':
+                       '"' + name + '"';
+       case quote_python:
+               return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
+                    + "\"";
+       }
+       // shut up stupid compiler
+       return string();
 }
 
 
@@ -196,13 +211,6 @@ string const fileOpenSearch(string const & path, string const & name,
                        notfound = false;
                }
        }
-#ifdef __EMX__
-       if (ext.empty() && notfound) {
-               real_file = fileOpenSearch(path, name, "exe");
-               if (notfound)
-                       real_file = fileOpenSearch(path, name, "cmd");
-       }
-#endif
        return real_file;
 }
 
@@ -320,7 +328,7 @@ string const i18nLibFileSearch(string const & dir, string const & name,
 }
 
 
-string const libScriptSearch(string const & command_in)
+string const libScriptSearch(string const & command_in, quote_style style)
 {
        static string const token_scriptpath = "$$s/";
 
@@ -346,7 +354,7 @@ string const libScriptSearch(string const & command_in)
        } else {
                // Replace "$$s/foo/some_script" with "<path to>/some_script".
                string::size_type const size_replace = size_script + 4;
-               command.replace(pos1, size_replace, quoteName(script));
+               command.replace(pos1, size_replace, quoteName(script, style));
        }
 
        return command;
@@ -382,11 +390,12 @@ string const createTmpDir(string const & tempdir, string const & mask)
 
 bool destroyDir(string const & tmpdir)
 {
-
-#ifdef __EMX__
-       Path p(user_lyxdir());
-#endif
-       return fs::remove_all(tmpdir) > 0;
+       try {
+               return fs::remove_all(tmpdir) > 0;
+       } catch (fs::filesystem_error const & fe){
+               lyxerr << "Could not delete " << tmpdir << ". (" << fe.what() << ")" << std::endl;
+               return false;
+       }
 }
 
 
@@ -413,9 +422,6 @@ string const createLyXTmpDir(string const & deflt)
 {
        if (!deflt.empty() && deflt != "/tmp") {
                if (mkdir(deflt, 0777)) {
-#ifdef __EMX__
-                       Path p(package().user_support());
-#endif
                        if (isDirWriteable(deflt)) {
                                // deflt could not be created because it
                                // did exist already, so let's create our own
@@ -428,9 +434,6 @@ string const createLyXTmpDir(string const & deflt)
                } else
                        return deflt;
        } else {
-#ifdef __EMX__
-               Path p(package().user_support());
-#endif
                return createTmpDir("/tmp", "lyx_tmpdir");
        }
 }
@@ -494,19 +497,11 @@ string const makeAbsPath(string const & relPath, string const & basePath)
                if (temp == "..") {
                        // Remove one level of TempBase
                        string::difference_type i = tempBase.length() - 2;
-#ifndef __EMX__
                        if (i < 0)
                                i = 0;
                        while (i > 0 && tempBase[i] != '/')
                                --i;
                        if (i > 0)
-#else
-                       if (i < 2)
-                               i = 2;
-                       while (i > 2 && tempBase[i] != '/')
-                               --i;
-                       if (i > 2)
-#endif
                                tempBase.erase(i, string::npos);
                        else
                                tempBase += '/';
@@ -980,7 +975,7 @@ string const unzipFile(string const & zipped_file, string const & unzipped_file)
 }
 
 
-string const makeDisplayPath(string const & path, unsigned int threshold)
+docstring const makeDisplayPath(string const & path, unsigned int threshold)
 {
        string str = path;
        string const home = package().home_dir();
@@ -990,7 +985,7 @@ string const makeDisplayPath(string const & path, unsigned int threshold)
                str = subst(str, home, "~");
 
        if (str.length() <= threshold)
-               return os::external_path(str);
+               return lyx::from_utf8(os::external_path(str));
 
        string const prefix = ".../";
        string temp;
@@ -1011,7 +1006,7 @@ string const makeDisplayPath(string const & path, unsigned int threshold)
                str = head + "..." + tail;
        }
 
-       return os::external_path(prefix + str);
+       return lyx::from_utf8(os::external_path(prefix + str));
 }