]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.cpp
add onoff support for "inset-modify changetype xxx" in include inset
[lyx.git] / src / support / filetools.cpp
index 7214668bf7a1a5fa7c6f299cf8da0f8eaf62d40b..810694ec785c74ea8ce2fb7bcfea02bfc63790ba 100644 (file)
@@ -8,11 +8,11 @@
  * \author Ivan Schreter
  * \author Dirk Niggemann
  * \author Asger Alstrup
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Jean-Marc Lasgouttes
  * \author Angus Leeming
  * \author John Levon
- * \author Herbert Voß
+ * \author Herbert Voß
  *
  * Full author contact details are available in file CREDITS.
  *
@@ -23,7 +23,6 @@
 
 #include "support/filetools.h"
 
-#include "support/convert.h"
 #include "support/debug.h"
 #include "support/environment.h"
 #include "support/gettext.h"
@@ -51,6 +50,8 @@
 
 using namespace std;
 
+#define USE_QPROCESS
+
 namespace lyx {
 namespace support {
 
@@ -136,9 +137,13 @@ string const quoteName(string const & name, quote_style style)
                // filenames to child processes if possible. We store them in
                // a python script instead, where we don't have these
                // limitations.
+#ifndef USE_QPROCESS
                return (os::shell() == os::UNIX) ?
                        '\'' + name + '\'':
                        '"' + name + '"';
+#else
+               return '"' + name + '"';
+#endif
        case quote_python:
                return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
                     + "\"";
@@ -321,17 +326,11 @@ static FileName createTmpDir(FileName const & tempdir, string const & mask)
        LYXERR(Debug::FILES, "createTmpDir: tempdir=`" << tempdir << "'\n"
                << "createTmpDir:    mask=`" << mask << '\'');
 
-       FileName const tmpfl = FileName::tempName(tempdir.absFilename()
-               + "/" + mask);
-       // FileName::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)
-       tmpfl.removeFile();
+       FileName const tmpfl = FileName::tempName(tempdir, mask);
 
        if (tmpfl.empty() || !tmpfl.createDirectory(0700)) {
-               lyxerr << "LyX could not create the temporary directory '"
-                      << tmpfl << "'" << endl;
+               LYXERR0("LyX could not create temporary directory in " << tempdir
+                       << "'");
                return FileName();
        }
 
@@ -341,8 +340,8 @@ static FileName createTmpDir(FileName const & tempdir, string const & mask)
 
 FileName const createLyXTmpDir(FileName const & deflt)
 {
-       if (deflt.empty() || deflt.absFilename() == "/tmp")
-               return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
+       if (deflt.empty() || deflt == package().system_temp_dir())
+               return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
 
        if (deflt.createDirectory(0777)) 
                return deflt;
@@ -354,7 +353,7 @@ FileName const createLyXTmpDir(FileName const & deflt)
                return createTmpDir(deflt, "lyx_tmpdir");
        } else {
                // some other error occured.
-               return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
+               return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
        }
 }
 
@@ -381,10 +380,9 @@ string const onlyPath(string const & filename)
 // FIXME It might be nice if the code didn't simply assume that.
 FileName const makeAbsPath(string const & relPath, string const & basePath)
 {
-       FileName relative_path(relPath);
        // checks for already absolute path
-       if (relative_path.isAbsolute())
-               return relative_path;
+       if (FileName::isAbsolute(relPath))
+               return FileName(relPath);
 
        // Copies given paths
        string tempRel = os::internal_path(relPath);
@@ -393,8 +391,7 @@ FileName const makeAbsPath(string const & relPath, string const & basePath)
 
        string tempBase;
 
-       FileName base_path(basePath);
-       if (base_path.isAbsolute())
+       if (FileName::isAbsolute(basePath))
                tempBase = basePath;
        else
                tempBase = addPath(FileName::getcwd().absFilename(), basePath);
@@ -494,8 +491,7 @@ string const expandPath(string const & path)
 {
        // checks for already absolute path
        string rTemp = replaceEnvironmentPath(path);
-       FileName abs_path(rTemp);
-       if (abs_path.isAbsolute())
+       if (FileName::isAbsolute(rTemp))
                return rTemp;
 
        string temp;
@@ -532,16 +528,23 @@ string const replaceEnvironmentPath(string const & path)
        static boost::regex envvar_br_re("(.*)" + envvar_br + "(.*)");
        static boost::regex envvar_re("(.*)" + envvar + "(.*)");
        boost::smatch what;
-
-       string result = path;
+       string result;
+       string remaining = path;
        while (1) {
-               regex_match(result, what, envvar_br_re);
+               regex_match(remaining, what, envvar_br_re);
                if (!what[0].matched) {
-                       regex_match(result, what, envvar_re);
-                       if (!what[0].matched)
+                       regex_match(remaining, what, envvar_re);
+                       if (!what[0].matched) {
+                               result += remaining;
                                break;
+                       }
                }
-               result = what.str(1) + getEnv(what.str(2)) + what.str(3);
+               string env_var = getEnv(what.str(2));
+               if (!env_var.empty())
+                       result += what.str(1) + env_var;
+               else
+                       result += what.str(1) + "$" + what.str(2);
+               remaining = what.str(3);
        }
        return result;
 }
@@ -843,18 +846,6 @@ FileName const findtexfile(string const & fil, string const & /*format*/)
 }
 
 
-void removeAutosaveFile(string const & filename)
-{
-       string a = onlyPath(filename);
-       a += '#';
-       a += onlyFilename(filename);
-       a += '#';
-       FileName const autosave(a);
-       if (autosave.exists())
-               autosave.removeFile();
-}
-
-
 void readBB_lyxerrMessage(FileName const & file, bool & zipped,
        string const & message)
 {