commit 8b66f9cedf5c32026c66d1a8ac0276adcb864c8e
Author: Scott Kostyshak <[email protected]>
Date:   Thu Jan 30 22:59:33 2014 -0500

    Centralize replacement of "$$s"
    
    Now the replacement is done in startScript(). In addition to making
    the code cleaner and more consistent, this commit fixes a bug where
    "$$s" was not replaced when "latex=" was specified in the extra flags
    of a converter.
    
    Note that the temporary fix at 731b8610 is reverted with this commit.

diff --git a/src/Converter.cpp b/src/Converter.cpp
index a3df839..8085b15 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -403,7 +403,6 @@ bool Converters::convert(Buffer const * buffer,
                        command = subst(command, token_from, "");
                        command = subst(command, token_latex_encoding, buffer ?
                                buffer->params().encoding().latexName() : 
string());
-                       command = libScriptSearch(command);
                        LYXERR(Debug::FILES, "Running " << command);
                        if (!runLaTeX(*buffer, command, runparams, errorList))
                                return false;
@@ -451,7 +450,6 @@ bool Converters::convert(Buffer const * buffer,
                        command = subst(command, token_orig_path, 
quoteName(onlyPath(orig_from.absFileName())));
                        command = subst(command, token_orig_from, 
quoteName(onlyFileName(orig_from.absFileName())));
                        command = subst(command, token_encoding, buffer ? 
buffer->params().encoding().iconvName() : string());
-                       command = libScriptSearch(command);
 
                        if (!conv.parselog.empty())
                                command += " 2> " + quoteName(infile2 + ".out");
@@ -495,8 +493,7 @@ bool Converters::convert(Buffer const * buffer,
   
                                if (!conv.parselog.empty()) {
                                        string const logfile =  infile2 + 
".log";
-                                       string const script = 
libScriptSearch(conv.parselog);
-                                       string const command2 = script +
+                                       string const command2 = conv.parselog +
                                                " < " + quoteName(infile2 + 
".out") +
                                                " > " + quoteName(logfile);
                                        one.startscript(Systemcall::Wait,
diff --git a/src/Format.cpp b/src/Format.cpp
index c9e1381..4045d80 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -646,7 +646,7 @@ bool Formats::view(Buffer const & buffer, FileName const & 
filename,
                }
        }
 
-       string command = libScriptSearch(format->viewer());
+       string command = format->viewer();
 
        if (format_name == "dvi" &&
            !lyxrc.view_dvi_paper_option.empty()) {
diff --git a/src/Mover.cpp b/src/Mover.cpp
index 13ee2c8..a901d98 100644
--- a/src/Mover.cpp
+++ b/src/Mover.cpp
@@ -59,7 +59,7 @@ bool SpecialisedMover::do_copy(FileName const & from, 
FileName const & to,
        if (command_.empty())
                return Mover::do_copy(from, to, latex);
 
-       string command = libScriptSearch(command_);
+       string command = command_;
        command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
        command = subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
        command = subst(command, "$$l", quoteName(latex));
diff --git a/src/graphics/GraphicsConverter.cpp 
b/src/graphics/GraphicsConverter.cpp
index 4930f0d..98580bd 100644
--- a/src/graphics/GraphicsConverter.cpp
+++ b/src/graphics/GraphicsConverter.cpp
@@ -324,8 +324,7 @@ static void build_script(string const & from_file,
 
                ostringstream os;
                os << os::python() << ' '
-                  << libScriptSearch("$$s/scripts/convertDefault.py",
-                                     quote_python) << ' ';
+                  << "$$s/scripts/convertDefault.py" << ' ';
                if (!from_format.empty())
                        os << strip_digit(from_format) << ':';
                // The extra " quotes around infile and outfile are needed
@@ -387,7 +386,6 @@ static void build_script(string const & from_file,
                command = subst(command, token_base,  "' + '\"' + infile_base + 
'\"' + '");
                command = subst(command, token_to,    "' + '\"' + outfile + 
'\"' + '");
                command = subst(command, token_todir, "' + '\"' + outdir + '\"' 
+ '");
-               command = libScriptSearch(command, quote_python);
 
                build_conversion_command(command, script);
        }
diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index a88b6e4..1c17226 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -615,7 +615,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
        if (buffer_.params().bufferFormat() == "lilypond-book")
                cs << " --lilypond";
 
-       string const command = libScriptSearch(cs.str());
+       string const command = cs.str();
 
        if (wait) {
                ForkedCall call(buffer_.filePath());
diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp
index d77248e..ed48764 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_ = trim(what);
+       command_ = libScriptSearch(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_ = trim(what);
+       command_ = libScriptSearch(trim(what));
        signal_  = signal;
 
        return run(DontWait);
diff --git a/src/support/ForkedCalls.h b/src/support/ForkedCalls.h
index 529f5c6..1958980 100644
--- a/src/support/ForkedCalls.h
+++ b/src/support/ForkedCalls.h
@@ -158,7 +158,8 @@ public:
 
        /** Start the child process.
         *
-        *  The command "what" is passed to execvp() for execution.
+        *  The command "what" is passed to execvp() for execution. "$$s" is
+        *  replaced accordingly by libScriptSearch().
         *
         *  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 2d04fd6..945d96f 100644
--- a/src/support/Systemcall.cpp
+++ b/src/support/Systemcall.cpp
@@ -105,11 +105,12 @@ int Systemcall::startscript(Starttype how, string const & 
what,
 {
        string const python_call = "python -tt";
        string command = to_filesystem8bit(from_utf8(latexEnvCmdPrefix(path)));
+       string what_ss = libScriptSearch(what);
 
-       if (prefixIs(what, python_call))
-               command += os::python() + what.substr(python_call.length());
+       if (prefixIs(what_ss, python_call))
+               command += os::python() + what_ss.substr(python_call.length());
        else
-               command += what;
+               command += what_ss;
 
        if (how == DontWait) {
                switch (os::shell()) {
@@ -240,13 +241,14 @@ string const parsecmd(string const & incmd, string & 
infile, string & outfile,
 int Systemcall::startscript(Starttype how, string const & what,
                            string const & path, bool process_events)
 {
-       LYXERR(Debug::INFO,"Running: " << what);
+       string const what_ss = libScriptSearch(what);
+       LYXERR(Debug::INFO,"Running: " << what_ss);
 
        string infile;
        string outfile;
        string errfile;
        QString const cmd = QString::fromLocal8Bit(
-                       parsecmd(what, infile, outfile, errfile).c_str());
+                       parsecmd(what_ss, infile, outfile, errfile).c_str());
 
        SystemcallPrivate d(infile, outfile, errfile);
 
diff --git a/src/support/Systemcall.h b/src/support/Systemcall.h
index 1d4c753..173387b 100644
--- a/src/support/Systemcall.h
+++ b/src/support/Systemcall.h
@@ -40,10 +40,12 @@ public:
 
        /** Start child process.
         *  The string "what" contains a commandline with arguments separated
-        *  by spaces and encoded in the filesystem encoding. The string "path"
+        *  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 utf-8. Unset "process_events" in case
-        *  UI should be blocked while processing the external command.
+        *  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 d241fcc..fd04c6a 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -337,7 +337,7 @@ FileName const imageLibFileSearch(string & dir, string 
const & name,
 }
 
 
-string const libScriptSearch(string const & command_in, quote_style style)
+string const libScriptSearch(string const & command_in)
 {
        static string const token_scriptpath = "$$s/";
 
@@ -361,6 +361,11 @@ string const libScriptSearch(string const & command_in, 
quote_style style)
                // Replace "$$s/" with ""
                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()))
+                       style = quote_python;
+
                // Replace "$$s/foo/some_script" with "<path to>/some_script".
                string::size_type const size_replace = size_script + 4;
                command.replace(pos1, size_replace, quoteName(script, style));
diff --git a/src/support/filetools.h b/src/support/filetools.h
index 58d1154..c13b5b3 100644
--- a/src/support/filetools.h
+++ b/src/support/filetools.h
@@ -125,8 +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,
-               quote_style style = quote_shell);
+std::string const libScriptSearch(std::string const & command);
 
 enum latex_path_extension {
        PROTECT_EXTENSION,

Reply via email to