mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
insetexternal: Do not run update command if result file exists and is up to
date. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2959 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
15a971fec2
commit
743bb40061
@ -1,3 +1,10 @@
|
||||
2001-11-02 Dekel Tsur <dekelts@tau.ac.il>
|
||||
|
||||
* insetexternal.C (updateExternal): Do not run update command if
|
||||
result file exists and is up to date.
|
||||
|
||||
* ExternalTemplate.C (readFormat): Support the updateresult token.
|
||||
|
||||
2001-10-31 Kayvan A. Sylvan <kayvan@sylvan.com>
|
||||
|
||||
* insetexternal.C (doSubstitution): Fix filepath ($$FPath in
|
||||
|
@ -34,12 +34,11 @@ extern string user_lyxdir;
|
||||
// We have to have dummy default commands for security reasons!
|
||||
|
||||
ExternalTemplate::ExternalTemplate()
|
||||
: viewCommand("true"), editCommand("true")
|
||||
{}
|
||||
|
||||
|
||||
ExternalTemplate::FormatTemplate::FormatTemplate()
|
||||
: updateCommand("true") {}
|
||||
{}
|
||||
|
||||
|
||||
ExternalTemplateManager::ExternalTemplateManager()
|
||||
@ -85,6 +84,7 @@ public:
|
||||
ost << "\tFormat " << vt.first << "\n"
|
||||
<< "\t\tProduct " << ft.product << "\n"
|
||||
<< "\t\tUpdateCommand " << ft.updateCommand << "\n"
|
||||
<< "\t\tUpdateResult " << ft.updateResult << "\n"
|
||||
<< "\t\tRequirement " << ft.requirement << "\n"
|
||||
<< "\t\tPreamble\n"
|
||||
<< ft.preamble
|
||||
@ -227,17 +227,11 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
|
||||
case TO_VIEWCMD:
|
||||
lex.next(true);
|
||||
viewCommand = lex.getString();
|
||||
// For security reasons, a command may not be empty!
|
||||
if (viewCommand.empty())
|
||||
viewCommand = "true";
|
||||
break;
|
||||
|
||||
case TO_EDITCMD:
|
||||
lex.next(true);
|
||||
editCommand = lex.getString();
|
||||
// For security reasons, a command may not be empty!
|
||||
if (editCommand.empty())
|
||||
editCommand = "true";
|
||||
break;
|
||||
|
||||
case TO_AUTOMATIC:
|
||||
@ -268,6 +262,7 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
|
||||
enum FormatTags {
|
||||
FO_PRODUCT = 1,
|
||||
FO_UPDATECMD,
|
||||
FO_UPDATERESULT,
|
||||
FO_REQUIREMENT,
|
||||
FO_PREAMBLE,
|
||||
FO_END
|
||||
@ -278,7 +273,8 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
|
||||
{ "preamble", FO_PREAMBLE },
|
||||
{ "product", FO_PRODUCT },
|
||||
{ "requirement", FO_REQUIREMENT },
|
||||
{ "updatecommand", FO_UPDATECMD }
|
||||
{ "updatecommand", FO_UPDATECMD },
|
||||
{ "updateresult", FO_UPDATERESULT }
|
||||
};
|
||||
|
||||
pushpophelper pph(lex, formattags, FO_END);
|
||||
@ -293,9 +289,11 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
|
||||
case FO_UPDATECMD:
|
||||
lex.next(true);
|
||||
updateCommand = lex.getString();
|
||||
// For security reasons, a command may not be empty!
|
||||
if (updateCommand.empty())
|
||||
updateCommand = "true";
|
||||
break;
|
||||
|
||||
case FO_UPDATERESULT:
|
||||
lex.next(true);
|
||||
updateResult = lex.getString();
|
||||
break;
|
||||
|
||||
case FO_REQUIREMENT:
|
||||
|
@ -45,6 +45,8 @@ struct ExternalTemplate {
|
||||
string product;
|
||||
/// The shell command to produce a resulting file
|
||||
string updateCommand;
|
||||
/// The filename of the resulting file
|
||||
string updateResult;
|
||||
/// What features does this external inset require?
|
||||
string requirement;
|
||||
/// What should be inserted into the preamble
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "support/syscall.h"
|
||||
#include "gettext.h"
|
||||
#include "debug.h"
|
||||
#include "support/FileInfo.h"
|
||||
|
||||
using std::endl;
|
||||
|
||||
@ -140,12 +141,7 @@ int InsetExternal::write(string const & format,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (et.automaticProduction) {
|
||||
executeCommand(doSubstitution(buf,
|
||||
cit->second.updateCommand),
|
||||
buf);
|
||||
}
|
||||
|
||||
updateExternal(format, buf);
|
||||
os << doSubstitution(buf, cit->second.product);
|
||||
return 0; // CHECK (FIXME check what ? - jbl)
|
||||
}
|
||||
@ -273,25 +269,47 @@ string const InsetExternal::doSubstitution(Buffer const * buffer,
|
||||
|
||||
|
||||
void InsetExternal::updateExternal() const
|
||||
{
|
||||
updateExternal("LaTeX", view_->buffer());
|
||||
}
|
||||
|
||||
void InsetExternal::updateExternal(string const & format,
|
||||
Buffer const * buf) const
|
||||
{
|
||||
ExternalTemplate const & et = params_.templ;
|
||||
ExternalTemplate::Formats::const_iterator cit =
|
||||
et.formats.find("LaTeX");
|
||||
if (cit == et.formats.end())
|
||||
et.formats.find(format);
|
||||
|
||||
if (cit == et.formats.end() ||
|
||||
cit->second.updateCommand.empty() ||
|
||||
!et.automaticProduction)
|
||||
return;
|
||||
|
||||
executeCommand(doSubstitution(view_->buffer(),
|
||||
cit->second.updateCommand),
|
||||
view_->buffer());
|
||||
if (!cit->second.updateResult.empty()) {
|
||||
string const resultfile = doSubstitution(buf,
|
||||
cit->second.updateResult);
|
||||
FileInfo fi(params_.filename);
|
||||
FileInfo fi2(resultfile);
|
||||
if (fi2.exist() && fi.exist() &&
|
||||
::difftime(fi2.getModificationTime(),
|
||||
fi.getModificationTime()) >= 0) {
|
||||
lyxerr[Debug::FILES] << resultfile
|
||||
<< " is up to date" << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
executeCommand(doSubstitution(buf, cit->second.updateCommand), buf);
|
||||
}
|
||||
|
||||
|
||||
void InsetExternal::viewExternal() const
|
||||
{
|
||||
ExternalTemplate const & et = params_.templ;
|
||||
if (et.automaticProduction)
|
||||
updateExternal();
|
||||
if (et.viewCommand.empty())
|
||||
return;
|
||||
|
||||
updateExternal();
|
||||
executeCommand(doSubstitution(view_->buffer(),
|
||||
et.viewCommand),
|
||||
view_->buffer());
|
||||
@ -301,9 +319,10 @@ void InsetExternal::viewExternal() const
|
||||
void InsetExternal::editExternal() const
|
||||
{
|
||||
ExternalTemplate const & et = params_.templ;
|
||||
if (et.automaticProduction)
|
||||
updateExternal();
|
||||
if (et.editCommand.empty())
|
||||
return;
|
||||
|
||||
updateExternal();
|
||||
executeCommand(doSubstitution(view_->buffer(),
|
||||
et.editCommand),
|
||||
view_->buffer());
|
||||
|
@ -86,9 +86,12 @@ public:
|
||||
/// set the parameters from a Params structure
|
||||
virtual void setFromParams(Params const &);
|
||||
|
||||
/// update the file represented by the template
|
||||
///
|
||||
void updateExternal() const;
|
||||
|
||||
/// update the file represented by the template
|
||||
void updateExternal(string const &, Buffer const *) const;
|
||||
|
||||
/// edit file of this template
|
||||
void editExternal() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user