* \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.
*
#include "support/filetools.h"
-#include "support/convert.h"
#include "support/debug.h"
#include "support/environment.h"
#include "support/gettext.h"
#include <QDir>
-#include <boost/assert.hpp>
+#include "support/lassert.h"
#include <boost/regex.hpp>
#include <fcntl.h>
using namespace std;
+#define USE_QPROCESS
+
namespace lyx {
namespace support {
{
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.
+ // This does not work on native Windows for filenames
+ // containing the following characters < > : " / \ | ? *
+ // Moreover, it can't be made to work, as, according to
+ // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
+ // those are reserved characters, and thus are forbidden.
+ // Please, also note that the command-line parser in
+ // ForkedCall::generateChild cannot deal with filenames
+ // containing " or ', 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.
+#ifndef USE_QPROCESS
return (os::shell() == os::UNIX) ?
- '\'' + name + '\'':
+ '\'' + subst(name, "'", "\'\\\'\'") + '\'' :
'"' + name + '"';
+#else
+ // According to the QProcess parser, a single double
+ // quote is represented by three consecutive ones.
+ // Here we simply escape the double quote and let our
+ // simple parser in Systemcall.cpp do the substitution.
+ return '"' + subst(name, "\"", "\\\"") + '"';
+#endif
case quote_python:
return "\"" + subst(subst(name, "\\", "\\\\"), "\"", "\\\"")
+ "\"";
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();
}
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;
return createTmpDir(deflt, "lyx_tmpdir");
} else {
// some other error occured.
- return createTmpDir(FileName("/tmp"), "lyx_tmpdir");
+ return createTmpDir(package().system_temp_dir(), "lyx_tmpdir");
}
}
// 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);
string tempBase;
- FileName base_path(basePath);
- if (base_path.isAbsolute())
+ if (FileName::isAbsolute(basePath))
tempBase = basePath;
else
tempBase = addPath(FileName::getcwd().absFilename(), basePath);
{
// 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;
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;
}
string const ext = getExtension(zipped_file);
if (ext == "gz" || ext == "z" || ext == "Z")
return changeExtension(zipped_file, string());
- return "unzipped_" + zipped_file;
+ return onlyPath(zipped_file) + "unzipped_" + onlyFilename(zipped_file);
}
if (absfile.exists())
return absfile;
- // No we try to find it using kpsewhich.
+ // Now we try to find it using kpsewhich.
// It seems from the kpsewhich manual page that it is safe to use
// kpsewhich without --format: "When the --format option is not
// given, the search path used when looking for a file is inferred
}
-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)
{