]> git.lyx.org Git - features.git/commitdiff
Centralize substitution of python commands
authorScott Kostyshak <skostysh@lyx.org>
Mon, 3 Feb 2014 15:57:52 +0000 (10:57 -0500)
committerScott Kostyshak <skostysh@lyx.org>
Wed, 14 May 2014 19:45:20 +0000 (15:45 -0400)
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.

src/support/ForkedCalls.cpp
src/support/ForkedCalls.h
src/support/Systemcall.cpp
src/support/Systemcall.h
src/support/filetools.cpp
src/support/filetools.h

index ed48764c06c929a67e01536245602f828792163d..00dca3e8587648d3666999e2ca693e70a47bb81d 100644 (file)
@@ -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);
index 19589803dd0a9d74205b7a6cf197a95d844f5939..772939890b4bfa139b576bdf59e2f4493cb6130c 100644 (file)
@@ -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
index 945d96fb6e7915e7025752ef66c12b641ee4194f..dc76b3d44c13c31e0a768b06be8739c1c381fc3b 100644 (file)
@@ -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;
index 173387b71e26c77b1afd81c30b4a319e4e1ea8b3..5b0750d17b3e9e5e0e4a220f530f82655fc91088 100644 (file)
@@ -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(),
index fd04c6a98414e701920683503048745ad97aed20..19d970146490d92e9e51b64f842764522156dd49 100644 (file)
@@ -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".
index c13b5b3fc4eb0d3724ae0a61f2c540a966b55a3e..fbc14f86a8d376c3d3539efbfb817fcf778274ea 100644 (file)
@@ -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,