+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
// We have to have dummy default commands for security reasons!
ExternalTemplate::ExternalTemplate()
- : viewCommand("true"), editCommand("true")
{}
ExternalTemplate::FormatTemplate::FormatTemplate()
- : updateCommand("true") {}
+{}
ExternalTemplateManager::ExternalTemplateManager()
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
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:
enum FormatTags {
FO_PRODUCT = 1,
FO_UPDATECMD,
+ FO_UPDATERESULT,
FO_REQUIREMENT,
FO_PREAMBLE,
FO_END
{ "preamble", FO_PREAMBLE },
{ "product", FO_PRODUCT },
{ "requirement", FO_REQUIREMENT },
- { "updatecommand", FO_UPDATECMD }
+ { "updatecommand", FO_UPDATECMD },
+ { "updateresult", FO_UPDATERESULT }
};
pushpophelper pph(lex, formattags, FO_END);
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:
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
#include "support/syscall.h"
#include "gettext.h"
#include "debug.h"
+#include "support/FileInfo.h"
using std::endl;
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)
}
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());
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());
/// 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;