mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
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:
parent
3b3d28cf8e
commit
8b66f9cedf
@ -403,7 +403,6 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
command = subst(command, token_from, "");
|
command = subst(command, token_from, "");
|
||||||
command = subst(command, token_latex_encoding, buffer ?
|
command = subst(command, token_latex_encoding, buffer ?
|
||||||
buffer->params().encoding().latexName() : string());
|
buffer->params().encoding().latexName() : string());
|
||||||
command = libScriptSearch(command);
|
|
||||||
LYXERR(Debug::FILES, "Running " << command);
|
LYXERR(Debug::FILES, "Running " << command);
|
||||||
if (!runLaTeX(*buffer, command, runparams, errorList))
|
if (!runLaTeX(*buffer, command, runparams, errorList))
|
||||||
return false;
|
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_path, quoteName(onlyPath(orig_from.absFileName())));
|
||||||
command = subst(command, token_orig_from, quoteName(onlyFileName(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 = subst(command, token_encoding, buffer ? buffer->params().encoding().iconvName() : string());
|
||||||
command = libScriptSearch(command);
|
|
||||||
|
|
||||||
if (!conv.parselog.empty())
|
if (!conv.parselog.empty())
|
||||||
command += " 2> " + quoteName(infile2 + ".out");
|
command += " 2> " + quoteName(infile2 + ".out");
|
||||||
@ -495,8 +493,7 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
|
|
||||||
if (!conv.parselog.empty()) {
|
if (!conv.parselog.empty()) {
|
||||||
string const logfile = infile2 + ".log";
|
string const logfile = infile2 + ".log";
|
||||||
string const script = libScriptSearch(conv.parselog);
|
string const command2 = conv.parselog +
|
||||||
string const command2 = script +
|
|
||||||
" < " + quoteName(infile2 + ".out") +
|
" < " + quoteName(infile2 + ".out") +
|
||||||
" > " + quoteName(logfile);
|
" > " + quoteName(logfile);
|
||||||
one.startscript(Systemcall::Wait,
|
one.startscript(Systemcall::Wait,
|
||||||
|
@ -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" &&
|
if (format_name == "dvi" &&
|
||||||
!lyxrc.view_dvi_paper_option.empty()) {
|
!lyxrc.view_dvi_paper_option.empty()) {
|
||||||
|
@ -59,7 +59,7 @@ bool SpecialisedMover::do_copy(FileName const & from, FileName const & to,
|
|||||||
if (command_.empty())
|
if (command_.empty())
|
||||||
return Mover::do_copy(from, to, latex);
|
return Mover::do_copy(from, to, latex);
|
||||||
|
|
||||||
string command = libScriptSearch(command_);
|
string command = command_;
|
||||||
command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
|
command = subst(command, "$$i", quoteName(from.toFilesystemEncoding()));
|
||||||
command = subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
|
command = subst(command, "$$o", quoteName(to.toFilesystemEncoding()));
|
||||||
command = subst(command, "$$l", quoteName(latex));
|
command = subst(command, "$$l", quoteName(latex));
|
||||||
|
@ -324,8 +324,7 @@ static void build_script(string const & from_file,
|
|||||||
|
|
||||||
ostringstream os;
|
ostringstream os;
|
||||||
os << os::python() << ' '
|
os << os::python() << ' '
|
||||||
<< libScriptSearch("$$s/scripts/convertDefault.py",
|
<< "$$s/scripts/convertDefault.py" << ' ';
|
||||||
quote_python) << ' ';
|
|
||||||
if (!from_format.empty())
|
if (!from_format.empty())
|
||||||
os << strip_digit(from_format) << ':';
|
os << strip_digit(from_format) << ':';
|
||||||
// The extra " quotes around infile and outfile are needed
|
// 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_base, "' + '\"' + infile_base + '\"' + '");
|
||||||
command = subst(command, token_to, "' + '\"' + outfile + '\"' + '");
|
command = subst(command, token_to, "' + '\"' + outfile + '\"' + '");
|
||||||
command = subst(command, token_todir, "' + '\"' + outdir + '\"' + '");
|
command = subst(command, token_todir, "' + '\"' + outdir + '\"' + '");
|
||||||
command = libScriptSearch(command, quote_python);
|
|
||||||
|
|
||||||
build_conversion_command(command, script);
|
build_conversion_command(command, script);
|
||||||
}
|
}
|
||||||
|
@ -615,7 +615,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
|
|||||||
if (buffer_.params().bufferFormat() == "lilypond-book")
|
if (buffer_.params().bufferFormat() == "lilypond-book")
|
||||||
cs << " --lilypond";
|
cs << " --lilypond";
|
||||||
|
|
||||||
string const command = libScriptSearch(cs.str());
|
string const command = cs.str();
|
||||||
|
|
||||||
if (wait) {
|
if (wait) {
|
||||||
ForkedCall call(buffer_.filePath());
|
ForkedCall call(buffer_.filePath());
|
||||||
|
@ -282,7 +282,7 @@ int ForkedCall::startScript(Starttype wait, string const & what)
|
|||||||
return retval_;
|
return retval_;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_ = trim(what);
|
command_ = libScriptSearch(trim(what));
|
||||||
signal_.reset();
|
signal_.reset();
|
||||||
return run(Wait);
|
return run(Wait);
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ int ForkedCall::startScript(Starttype wait, string const & what)
|
|||||||
|
|
||||||
int ForkedCall::startScript(string const & what, SignalTypePtr signal)
|
int ForkedCall::startScript(string const & what, SignalTypePtr signal)
|
||||||
{
|
{
|
||||||
command_ = trim(what);
|
command_ = libScriptSearch(trim(what));
|
||||||
signal_ = signal;
|
signal_ = signal;
|
||||||
|
|
||||||
return run(DontWait);
|
return run(DontWait);
|
||||||
|
@ -158,7 +158,8 @@ public:
|
|||||||
|
|
||||||
/** Start the child process.
|
/** 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
|
* There are two startScript commands available. They differ in that
|
||||||
* the second receives a signal that is executed on completion of
|
* the second receives a signal that is executed on completion of
|
||||||
|
@ -105,11 +105,12 @@ int Systemcall::startscript(Starttype how, string const & what,
|
|||||||
{
|
{
|
||||||
string const python_call = "python -tt";
|
string const python_call = "python -tt";
|
||||||
string command = to_filesystem8bit(from_utf8(latexEnvCmdPrefix(path)));
|
string command = to_filesystem8bit(from_utf8(latexEnvCmdPrefix(path)));
|
||||||
|
string what_ss = libScriptSearch(what);
|
||||||
|
|
||||||
if (prefixIs(what, python_call))
|
if (prefixIs(what_ss, python_call))
|
||||||
command += os::python() + what.substr(python_call.length());
|
command += os::python() + what_ss.substr(python_call.length());
|
||||||
else
|
else
|
||||||
command += what;
|
command += what_ss;
|
||||||
|
|
||||||
if (how == DontWait) {
|
if (how == DontWait) {
|
||||||
switch (os::shell()) {
|
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,
|
int Systemcall::startscript(Starttype how, string const & what,
|
||||||
string const & path, bool process_events)
|
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 infile;
|
||||||
string outfile;
|
string outfile;
|
||||||
string errfile;
|
string errfile;
|
||||||
QString const cmd = QString::fromLocal8Bit(
|
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);
|
SystemcallPrivate d(infile, outfile, errfile);
|
||||||
|
|
||||||
|
@ -40,10 +40,12 @@ public:
|
|||||||
|
|
||||||
/** Start child process.
|
/** Start child process.
|
||||||
* The string "what" contains a commandline with arguments separated
|
* 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
|
* contains the path to be prepended to the TEXINPUTS environment
|
||||||
* variable and encoded in utf-8. Unset "process_events" in case
|
* variable and encoded in the path to be prepended to the TEXINPUTS
|
||||||
* UI should be blocked while processing the external command.
|
* 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,
|
int startscript(Starttype how, std::string const & what,
|
||||||
std::string const & path = empty_string(),
|
std::string const & path = empty_string(),
|
||||||
|
@ -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/";
|
static string const token_scriptpath = "$$s/";
|
||||||
|
|
||||||
@ -361,6 +361,11 @@ string const libScriptSearch(string const & command_in, quote_style style)
|
|||||||
// Replace "$$s/" with ""
|
// Replace "$$s/" with ""
|
||||||
command.erase(pos1, 4);
|
command.erase(pos1, 4);
|
||||||
} else {
|
} 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".
|
// Replace "$$s/foo/some_script" with "<path to>/some_script".
|
||||||
string::size_type const size_replace = size_script + 4;
|
string::size_type const size_replace = size_script + 4;
|
||||||
command.replace(pos1, size_replace, quoteName(script, style));
|
command.replace(pos1, size_replace, quoteName(script, style));
|
||||||
|
@ -125,8 +125,7 @@ enum quote_style {
|
|||||||
* command will still fail, but the error message will make some sort of
|
* command will still fail, but the error message will make some sort of
|
||||||
* sense ;-)
|
* sense ;-)
|
||||||
*/
|
*/
|
||||||
std::string const libScriptSearch(std::string const & command,
|
std::string const libScriptSearch(std::string const & command);
|
||||||
quote_style style = quote_shell);
|
|
||||||
|
|
||||||
enum latex_path_extension {
|
enum latex_path_extension {
|
||||||
PROTECT_EXTENSION,
|
PROTECT_EXTENSION,
|
||||||
|
Loading…
Reference in New Issue
Block a user