]> git.lyx.org Git - features.git/commitdiff
insetexternal: Do not run update command if result file exists and is up to
authorDekel Tsur <dekelts@tau.ac.il>
Fri, 2 Nov 2001 16:18:07 +0000 (16:18 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Fri, 2 Nov 2001 16:18:07 +0000 (16:18 +0000)
date.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2959 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/ChangeLog
src/insets/ExternalTemplate.C
src/insets/ExternalTemplate.h
src/insets/insetexternal.C
src/insets/insetexternal.h

index a4b2e950f9a2093120b7382ac9c182ee94b85e3b..59fd244c3f8cde59837d62336f5464ee84b0dbaf 100644 (file)
@@ -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
index 5e8252b4bc63ff3be3985187ce9acaf2d3abfe66..da8fdf5063f879f9019d771be22a28b16f66e301 100644 (file)
@@ -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:
index d289e7f6564284e1fdd6c31764b0930eb40f50b1..1b2831753df76046cd3d2d780ca91174b1f7a95d 100644 (file)
@@ -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
index 6fb09380e78dcadac45ccc82176c20a941545ecf..1b44579265aa4f760311c489f7747b1515876919 100644 (file)
@@ -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());
index 66f932fdaafa4daf7077eb0335e19608ac036b7c..e6fb0e946140bc0ea3eedfa3665a462060ea2fd2 100644 (file)
@@ -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;