From e5cc5ac2e82f6dd1939b35b138489d1a1e3d3bae Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sun, 25 Sep 2011 13:35:42 +0000 Subject: [PATCH] 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 --- src/support/ForkedCalls.cpp | 22 ++----------------- src/support/Systemcall.cpp | 42 +++++-------------------------------- src/support/filetools.cpp | 20 ++++++++++++++++++ src/support/filetools.h | 6 ++++++ 4 files changed, 33 insertions(+), 57 deletions(-) diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp index dede9fac3f..7a3c141542 100644 --- a/src/support/ForkedCalls.cpp +++ b/src/support/ForkedCalls.cpp @@ -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 #include #include @@ -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) diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp index 47f5e73cd2..7588d4aa3e 100644 --- a/src/support/Systemcall.cpp +++ b/src/support/Systemcall.cpp @@ -14,7 +14,6 @@ #include #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_); } } diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 7f70140774..828abea13f 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -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) { diff --git a/src/support/filetools.h b/src/support/filetools.h index 001c0f3ddc..48ebbd6046 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -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. -- 2.39.2