Manage the setting of the latex environment for Systemcall and ForkedCall

in a central place.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39758 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2011-09-25 13:35:42 +00:00
parent 7cea4a8507
commit e5cc5ac2e8
4 changed files with 33 additions and 57 deletions

View File

@ -15,7 +15,6 @@
#include "support/ForkedCalls.h"
#include "support/debug.h"
#include "support/environment.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
@ -24,8 +23,6 @@
#include "support/bind.h"
#include "LyXRC.h"
#include <cerrno>
#include <queue>
#include <sstream>
@ -274,23 +271,8 @@ int ForkedProcess::waitForChild()
/////////////////////////////////////////////////////////////////////
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)

View File

@ -14,7 +14,6 @@
#include <config.h>
#include "support/debug.h"
#include "support/environment.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
@ -101,24 +100,8 @@ ProgressInterface* ProgressInterface::instance()
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()) {
@ -129,7 +112,8 @@ int Systemcall::startscript(Starttype how, string const & what,
command = "start /min " + command;
break;
}
}
} else if (os::shell() == os::CMD_EXE)
command = subst(command, "cmd /d /c ", "");
return ::system(command.c_str());
}
@ -288,24 +272,8 @@ void SystemcallPrivate::startProcess(QString const & cmd, string const & path)
{
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_);
}
}

View File

@ -578,6 +578,26 @@ string const replaceEnvironmentPath(string const & path)
}
// 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)
{

View File

@ -247,6 +247,12 @@ std::string const onlyFileName(std::string const & fname);
*/
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.