]> git.lyx.org Git - lyx.git/blobdiff - src/DepTable.C
bug 183
[lyx.git] / src / DepTable.C
index 856a07ef429db6ff9dfac61916fb250367c198c6..b8abc816dce3ff46c38993b92153708cd42369e7 100644 (file)
@@ -2,10 +2,10 @@
  * ====================================================== 
  * 
  *           LyX, The Document Processor
- *          Copyright (C) 1995 Matthias Ettrich
- *           Copyright (C) 1995-1998 The LyX Team.
+ *          Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-2001 The LyX Team.
  *
- *           This file is Copyright (C) 1996-1998
+ *           This file is Copyright 1996-2001
  *           Lars Gullik Bjønnes
  *
  * ====================================================== 
 #endif
 
 #include "DepTable.h"
+#include "debug.h"
+
 #include "support/lyxlib.h"
 #include "support/filetools.h"
+#include "support/lstrings.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 #include <fstream>
+
 using std::make_pair;
 using std::ofstream;
 using std::ifstream;
+using std::endl;
 
 void DepTable::insert(string const & fi,
                      bool upd,
@@ -33,26 +43,59 @@ void DepTable::insert(string const & fi,
        // not quite sure if this is the correct place for MakeAbsPath
        string f = MakeAbsPath(fi);
        if (deplist.find(f) == deplist.end()) {
+               long mtime = 0;
                if (upd) {
                        one = two;
-                       two = lyxsum(f.c_str());
+                       two = lyx::sum(f);
+                       struct stat f_info;
+                       stat(fi.c_str(), &f_info);
+                       mtime = f_info.st_mtime;
                }
+               dep_info di;
+               di.first = one;
+               di.second = two;
+               di.mtime = mtime;
+#if 0          
                deplist[f] = make_pair(one, two);
+#else
+               deplist[f] = di;
+#endif
        }
 }
                
 
 void DepTable::update()
 {
-       for(DepList::iterator itr = deplist.begin();
+       for (DepList::iterator itr = deplist.begin();
            itr != deplist.end();
            ++itr) {
-               unsigned long one = (*itr).second.second;
-               unsigned long two = lyxsum((*itr).first.c_str());
-               (*itr).second = make_pair(one, two);
-               if (lyxerr.debugging()) {
-                       lyxerr << "update: " << (*itr).first << " "
-                              << one << " " << two << endl;
+               unsigned long const one = itr->second.second;
+               unsigned long two = one;
+               long mtime = itr->second.mtime;
+               struct stat f_info;
+               stat(itr->first.c_str(), &f_info);
+
+               if (mtime != f_info.st_mtime) {
+                       two = lyx::sum(itr->first);
+                       mtime = f_info.st_mtime;
+               }
+               
+#if 0
+               itr->second = make_pair(one, two);
+#else
+               dep_info di;
+               di.first = one;
+               di.second = two;
+               di.mtime = mtime;
+               
+               itr->second = di;
+#endif
+               if (lyxerr.debugging(Debug::DEPEND)) {
+                       lyxerr << "Update dep: " << itr->first << " "
+                              << one << " " << two;
+                       if (one != two)
+                               lyxerr << " +";
+                       lyxerr << endl;
                }
        }
 }
@@ -63,7 +106,7 @@ bool DepTable::sumchange() const
        for (DepList::const_iterator cit = deplist.begin();
             cit != deplist.end();
             ++cit) {
-               if ((*cit).second.first != (*cit).second.second) return true;
+               if ((*cit).second.first != cit->second.second) return true;
        }
        return false;
 }
@@ -75,8 +118,8 @@ bool DepTable::haschanged(string const & f) const
        string fil = MakeAbsPath(f);
        DepList::const_iterator cit = deplist.find(fil);
        if (cit != deplist.end()) {
-               if ((*cit).second.first != (*cit).second.second
-                   && (*cit).second.second != 0)
+               if (cit->second.first != cit->second.second
+                   && cit->second.second != 0)
                        return true;
        }
        return false;
@@ -88,12 +131,11 @@ bool DepTable::extchanged(string const & ext) const
        for (DepList::const_iterator cit = deplist.begin();
             cit != deplist.end();
             ++cit) {
-               if (suffixIs((*cit).first, ext.c_str())) {
-                       if ((*cit).second.first != (*cit).second.second)
+               if (suffixIs(cit->first, ext)) {
+                       if (cit->second.first != cit->second.second)
                                return true;
                }
        }
-                    
        return false;
 }
 
@@ -109,13 +151,13 @@ bool DepTable::exist(string const & fil) const
 void DepTable::remove_files_with_extension(string const & suf)
 {
        DepList tmp;
-       for (DepList::const_iterator cit = deplist.begin();
+       // we want const_iterator (Lgb)
+       for (DepList::iterator cit = deplist.begin();
             cit != deplist.end(); ++cit) {
-               if (!suffixIs((*cit).first, suf.c_str()))
-                       tmp[(*cit).first] = (*cit).second;
+               if (!suffixIs(cit->first, suf))
+                       tmp[cit->first] = cit->second;
        }
        deplist.swap(tmp);
-       
 }
 
 
@@ -123,17 +165,18 @@ void DepTable::write(string const & f) const
 {
        ofstream ofs(f.c_str());
        for (DepList::const_iterator cit = deplist.begin();
-            cit != deplist.end();
-            ++cit) {
-               if (lyxerr.debugging()) {
+            cit != deplist.end(); ++cit) {
+               if (lyxerr.debugging(Debug::DEPEND)) {
                        lyxerr << "Write dep: "
-                              << (*cit).first << " "
-                              << (*cit).second.first << " "
-                              << (*cit).second.second << endl;
+                              << cit->first << " "
+                              << cit->second.first << " "
+                              << cit->second.second << " "
+                              << cit->second.mtime << endl;
                }
-               ofs << (*cit).first << " "
-                   << (*cit).second.first << " "
-                   << (*cit).second.second << endl;
+               ofs << cit->first << " "
+                   << cit->second.first << " "
+                   << cit->second.second << " "
+                   << cit->second.mtime << endl;
        }
 }
 
@@ -144,13 +187,24 @@ void DepTable::read(string const & f)
        string nome;
        unsigned long one = 0;
        unsigned long two = 0;
-       while(ifs >> nome >> one >> two) {
-               if (lyxerr.debugging()) {
-                       lyxerr << "read dep: "
+       unsigned long mtime = 0;
+       
+       while (ifs >> nome >> one >> two >> mtime) {
+               if (lyxerr.debugging(Debug::DEPEND)) {
+                       lyxerr << "Read dep: "
                               << nome << " "
                               << one << " "
-                              << two << endl;
+                              << two << " "
+                              << mtime << endl;
                }
+               dep_info di;
+               di.first = one;
+               di.second = two;
+               di.mtime = mtime;
+#if 0          
                deplist[nome] = make_pair(one, two);
+#else
+               deplist[nome] = di;
+#endif
        }
 }