From: Dekel Tsur Date: Fri, 2 Nov 2001 16:18:07 +0000 (+0000) Subject: insetexternal: Do not run update command if result file exists and is up to X-Git-Tag: 1.6.10~20406 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=743bb400616283262119244449746baea98adc1b;p=features.git 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 --- diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index a4b2e950f9..59fd244c3f 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ +2001-11-02 Dekel Tsur + + * 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 * insetexternal.C (doSubstitution): Fix filepath ($$FPath in diff --git a/src/insets/ExternalTemplate.C b/src/insets/ExternalTemplate.C index 5e8252b4bc..da8fdf5063 100644 --- a/src/insets/ExternalTemplate.C +++ b/src/insets/ExternalTemplate.C @@ -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: diff --git a/src/insets/ExternalTemplate.h b/src/insets/ExternalTemplate.h index d289e7f656..1b2831753d 100644 --- a/src/insets/ExternalTemplate.h +++ b/src/insets/ExternalTemplate.h @@ -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 diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 6fb09380e7..1b44579265 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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()); diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 66f932fdaa..e6fb0e9461 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -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;