]> git.lyx.org Git - features.git/commitdiff
Manage the setting of the latex environment for Systemcall and ForkedCall
authorEnrico Forestieri <forenr@lyx.org>
Sun, 25 Sep 2011 13:35:42 +0000 (13:35 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 25 Sep 2011 13:35:42 +0000 (13:35 +0000)
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
src/support/Systemcall.cpp
src/support/filetools.cpp
src/support/filetools.h

index dede9fac3fed7bf376fb6077a39d63feeb769d03..7a3c141542dbef181408736370d5cbf994f73391 100644 (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)
index 47f5e73cd20d58f457a113eaa4cb810b7898e9d6..7588d4aa3eb784dd3315602a0ae559ea7a71deba 100644 (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_);
        }
 }
 
index 7f701407748113ec65d9a3b5075a5bfe3dd45222..828abea13f0806b828b35a62a590ebe974ee9fc9 100644 (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)
 {
index 001c0f3ddc1476e80fb99677868fd82cfee7d097..48ebbd6046c5c174034b408cecdd415b7f95ab35 100644 (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.