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.
This commit is contained in:
Scott Kostyshak 2014-01-30 22:59:33 -05:00
parent 3b3d28cf8e
commit 8b66f9cedf
11 changed files with 28 additions and 24 deletions

View File

@ -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,

View File

@ -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()) {

View File

@ -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));

View File

@ -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);
}

View File

@ -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());

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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(),

View File

@ -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));

View File

@ -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,