#include "support/ForkedCalls.h"
#include "support/debug.h"
-#include "support/environment.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/bind.h"
-#include "LyXRC.h"
-
#include <cerrno>
#include <queue>
#include <sstream>
/////////////////////////////////////////////////////////////////////
ForkedCall::ForkedCall(string const & path)
- : cmd_prefix_(empty_string())
-{
- if (path.empty() || lyxrc.texinputs_prefix.empty())
- return;
-
- string const texinputs = os::latex_path_list(
- replaceCurdirPath(path, lyxrc.texinputs_prefix));
- string const sep = string(1, os::path_separator(os::TEXENGINE));
- string const env = getEnv("TEXINPUTS");
-
- if (os::shell() == os::UNIX)
- cmd_prefix_ = "env 'TEXINPUTS=." + sep + texinputs
- + sep + env + "' ";
- else
- cmd_prefix_ = "cmd /d /c set TEXINPUTS=." + sep + texinputs
- + sep + env + " & ";
-}
+ : cmd_prefix_(to_filesystem8bit(from_utf8(latexEnvCmdPrefix(path))))
+{}
int ForkedCall::startScript(Starttype wait, string const & what)
#include <config.h>
#include "support/debug.h"
-#include "support/environment.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
int Systemcall::startscript(Starttype how, string const & what,
std::string const & path, bool /*process_events*/)
{
- string command;
- string const texinputs = os::latex_path_list(
- replaceCurdirPath(path, lyxrc.texinputs_prefix));
- string const sep = string(1, os::path_separator(os::TEXENGINE));
- string const env = getEnv("TEXINPUTS");
-
- switch (os::shell()) {
- case os::UNIX:
- command = path.empty() || lyxrc.texinputs_prefix.empty() ? what
- : "env TEXINPUTS='." + sep + texinputs
- + sep + env + "' " + what;
- break;
- case os::CMD_EXE:
- command = path.empty() || lyxrc.texinputs_prefix.empty() ? what
- : "set TEXINPUTS=." + sep + texinputs
- + sep + env + " & " + what;
- break;
- }
+ string command =
+ to_filesystem8bit(from_utf8(latexEnvCmdPrefix(path))) + what;
if (how == DontWait) {
switch (os::shell()) {
command = "start /min " + command;
break;
}
- }
+ } else if (os::shell() == os::CMD_EXE)
+ command = subst(command, "cmd /d /c ", "");
return ::system(command.c_str());
}
{
cmd_ = cmd;
if (process_) {
- string cmd_prefix;
- if (!path.empty() && !lyxrc.texinputs_prefix.empty()) {
- string const texinputs_prefix = os::latex_path_list(
- replaceCurdirPath(path, lyxrc.texinputs_prefix));
- string const sep = string(1,
- os::path_separator(os::TEXENGINE));
- string const env = getEnv("TEXINPUTS");
- string const texinputs = "." + sep + texinputs_prefix
- + sep + env;
- if (os::shell() == os::UNIX)
- cmd_prefix = "env 'TEXINPUTS="
- + texinputs + "' ";
- else
- cmd_prefix = "cmd /d /c set TEXINPUTS="
- + texinputs + " & ";
- }
state = SystemcallPrivate::Starting;
- process_->start(toqstr(cmd_prefix) + cmd_);
+ process_->start(toqstr(latexEnvCmdPrefix(path)) + cmd_);
}
}
}
+// Return a command prefix for setting the environment of the TeX engine.
+string latexEnvCmdPrefix(string const & path)
+{
+ if (path.empty() || lyxrc.texinputs_prefix.empty())
+ return string();
+
+ string const texinputs_prefix = os::latex_path_list(
+ replaceCurdirPath(path, lyxrc.texinputs_prefix));
+ string const sep = string(1, os::path_separator(os::TEXENGINE));
+ string const texinputs = getEnv("TEXINPUTS");
+
+ if (os::shell() == os::UNIX)
+ return "env 'TEXINPUTS=." + sep + texinputs_prefix
+ + sep + texinputs + "' ";
+ else
+ return "cmd /d /c set TEXINPUTS=." + sep + texinputs_prefix
+ + sep + texinputs + " & ";
+}
+
+
// Replace current directory in all elements of a path list with a given path.
string const replaceCurdirPath(string const & path, string const & pathlist)
{
*/
std::string const replaceEnvironmentPath(std::string const & path);
+/**
+ Return a string to be used as a prefix to a command for setting the
+ environment of the TeX engine with respect to the path \p path.
+ */
+std::string latexEnvCmdPrefix(std::string const & path);
+
/** Replace all references to a current directory (a lonely '.' or
the prefix "./") in \c pathlist with \c path. Also prefixes
all non-absolute paths with \c path.