mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
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.
This commit is contained in:
parent
8b66f9cedf
commit
1821c6d8a3
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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(),
|
||||
|
@ -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".
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user