1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
5 * Copyright 1995 Matthias Ettrich
6 * Copyright 1995-2001 The LyX Team.
8 * This file is Copyright 1996-2001
11 * ======================================================
17 #pragma implementation
23 #include "support/lyxlib.h"
24 #include "support/filetools.h"
25 #include "support/lstrings.h"
27 #include <sys/types.h>
38 void DepTable::insert(string const & fi,
43 // not quite sure if this is the correct place for MakeAbsPath
44 string f = MakeAbsPath(fi);
45 if (deplist.find(f) == deplist.end()) {
51 stat(fi.c_str(), &f_info);
52 mtime = f_info.st_mtime;
59 deplist[f] = make_pair(one, two);
67 void DepTable::update()
69 for (DepList::iterator itr = deplist.begin();
72 unsigned long const one = itr->second.second;
73 unsigned long two = one;
74 long mtime = itr->second.mtime;
76 stat(itr->first.c_str(), &f_info);
78 if (mtime != f_info.st_mtime) {
79 two = lyx::sum(itr->first);
80 mtime = f_info.st_mtime;
84 itr->second = make_pair(one, two);
93 if (lyxerr.debugging(Debug::DEPEND)) {
94 lyxerr << "Update dep: " << itr->first << " "
104 bool DepTable::sumchange() const
106 for (DepList::const_iterator cit = deplist.begin();
107 cit != deplist.end();
109 if ((*cit).second.first != cit->second.second) return true;
115 bool DepTable::haschanged(string const & f) const
117 // not quite sure if this is the correct place for MakeAbsPath
118 string fil = MakeAbsPath(f);
119 DepList::const_iterator cit = deplist.find(fil);
120 if (cit != deplist.end()) {
121 if (cit->second.first != cit->second.second
122 && cit->second.second != 0)
129 bool DepTable::extchanged(string const & ext) const
131 for (DepList::const_iterator cit = deplist.begin();
132 cit != deplist.end();
134 if (suffixIs(cit->first, ext)) {
135 if (cit->second.first != cit->second.second)
143 bool DepTable::exist(string const & fil) const
145 DepList::const_iterator cit = deplist.find(fil);
146 if (cit != deplist.end()) return true;
151 void DepTable::remove_files_with_extension(string const & suf)
154 // we want const_iterator (Lgb)
155 for (DepList::iterator cit = deplist.begin();
156 cit != deplist.end(); ++cit) {
157 if (!suffixIs(cit->first, suf))
158 tmp[cit->first] = cit->second;
164 void DepTable::write(string const & f) const
166 ofstream ofs(f.c_str());
167 for (DepList::const_iterator cit = deplist.begin();
168 cit != deplist.end(); ++cit) {
169 if (lyxerr.debugging(Debug::DEPEND)) {
170 lyxerr << "Write dep: "
172 << cit->second.first << " "
173 << cit->second.second << " "
174 << cit->second.mtime << endl;
176 ofs << cit->first << " "
177 << cit->second.first << " "
178 << cit->second.second << " "
179 << cit->second.mtime << endl;
184 void DepTable::read(string const & f)
186 ifstream ifs(f.c_str());
188 unsigned long one = 0;
189 unsigned long two = 0;
190 unsigned long mtime = 0;
192 while (ifs >> nome >> one >> two >> mtime) {
193 if (lyxerr.debugging(Debug::DEPEND)) {
194 lyxerr << "Read dep: "
205 deplist[nome] = make_pair(one, two);