commit 1821c6d8a32fe9cfac4f705038f19161814f6700
Author: Scott Kostyshak <[email protected]>
Date: Mon Feb 3 10:57:52 2014 -0500
Centralize substitution of python commands
The code for detecting python commands and substituting in the
correct prefix is now merged with what used to be libScriptSearch()
and is now renamed to commandPrep(). This commit does not change
any functionality and just improves organization to reduce the
chance of bugs in the future.
diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp
index ed48764..00dca3e 100644
--- a/src/support/ForkedCalls.cpp
+++ b/src/support/ForkedCalls.cpp
@@ -282,7 +282,7 @@ int ForkedCall::startScript(Starttype wait, string const &
what)
return retval_;
}
- command_ = libScriptSearch(trim(what));
+ command_ = commandPrep(trim(what));
signal_.reset();
return run(Wait);
}
@@ -290,7 +290,7 @@ int ForkedCall::startScript(Starttype wait, string const &
what)
int ForkedCall::startScript(string const & what, SignalTypePtr signal)
{
- command_ = libScriptSearch(trim(what));
+ command_ = commandPrep(trim(what));
signal_ = signal;
return run(DontWait);
diff --git a/src/support/ForkedCalls.h b/src/support/ForkedCalls.h
index 1958980..7729398 100644
--- a/src/support/ForkedCalls.h
+++ b/src/support/ForkedCalls.h
@@ -159,7 +159,7 @@ public:
/** Start the child process.
*
* The command "what" is passed to execvp() for execution. "$$s" is
- * replaced accordingly by libScriptSearch().
+ * replaced accordingly by commandPrep().
*
* There are two startScript commands available. They differ in that
* the second receives a signal that is executed on completion of
diff --git a/src/support/Systemcall.cpp b/src/support/Systemcall.cpp
index 945d96f..dc76b3d 100644
--- a/src/support/Systemcall.cpp
+++ b/src/support/Systemcall.cpp
@@ -103,14 +103,8 @@ ProgressInterface * ProgressInterface::instance()
int Systemcall::startscript(Starttype how, string const & what,
std::string const & path, bool /*process_events*/)
{
- string const python_call = "python -tt";
- string command = to_filesystem8bit(from_utf8(latexEnvCmdPrefix(path)));
- string what_ss = libScriptSearch(what);
-
- if (prefixIs(what_ss, python_call))
- command += os::python() + what_ss.substr(python_call.length());
- else
- command += what_ss;
+ string command = to_filesystem8bit(from_utf8(latexEnvCmdPrefix(path)))
+ + commandPrep(what);
if (how == DontWait) {
switch (os::shell()) {
@@ -241,7 +235,7 @@ string const parsecmd(string const & incmd, string &
infile, string & outfile,
int Systemcall::startscript(Starttype how, string const & what,
string const & path, bool process_events)
{
- string const what_ss = libScriptSearch(what);
+ string const what_ss = commandPrep(what);
LYXERR(Debug::INFO,"Running: " << what_ss);
string infile;
diff --git a/src/support/Systemcall.h b/src/support/Systemcall.h
index 173387b..5b0750d 100644
--- a/src/support/Systemcall.h
+++ b/src/support/Systemcall.h
@@ -41,11 +41,11 @@ public:
/** Start child process.
* The string "what" contains a commandline with arguments separated
* by spaces and encoded in the filesystem encoding. "$$s" will be
- * replaced accordingly by libScriptSearch(). The string "path"
- * contains the path to be prepended to the TEXINPUTS environment
- * variable and encoded in the path to be prepended to the TEXINPUTS
- * environment variable and utf-8. Unset "process_events" in case UI
- * should be blocked while processing the external command.
+ * replaced accordingly by commandPrep(). The string "path" contains
+ * the path to be prepended to the TEXINPUTS environment variable and
+ * encoded in the path to be prepended to the TEXINPUTS environment
+ * variable and utf-8. Unset "process_events" in case UI should be
+ * blocked while processing the external command.
*/
int startscript(Starttype how, std::string const & what,
std::string const & path = empty_string(),
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index fd04c6a..19d9701 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -337,11 +337,15 @@ FileName const imageLibFileSearch(string & dir, string
const & name,
}
-string const libScriptSearch(string const & command_in)
+string const commandPrep(string const & command_in)
{
static string const token_scriptpath = "$$s/";
+ string const python_call = "python -tt";
string command = command_in;
+ if (prefixIs(command_in, python_call))
+ command = os::python() +
command_in.substr(python_call.length());
+
// Find the starting position of "$$s/"
string::size_type const pos1 = command.find(token_scriptpath);
if (pos1 == string::npos)
@@ -362,8 +366,7 @@ string const libScriptSearch(string const & command_in)
command.erase(pos1, 4);
} else {
quote_style style = quote_shell;
- string const python_call = "python -tt";
- if (prefixIs(command, python_call) || prefixIs(command,
os::python()))
+ if (prefixIs(command, os::python()))
style = quote_python;
// Replace "$$s/foo/some_script" with "<path to>/some_script".
diff --git a/src/support/filetools.h b/src/support/filetools.h
index c13b5b3..fbc14f8 100644
--- a/src/support/filetools.h
+++ b/src/support/filetools.h
@@ -125,7 +125,7 @@ enum quote_style {
* command will still fail, but the error message will make some sort of
* sense ;-)
*/
-std::string const libScriptSearch(std::string const & command);
+std::string const commandPrep(std::string const & command);
enum latex_path_extension {
PROTECT_EXTENSION,