]> git.lyx.org Git - lyx.git/blob - src/DepTable.C
selection using the mouse should work now. Note: an x is not a y, nor is
[lyx.git] / src / DepTable.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *           Copyright 1995 Matthias Ettrich
6  *           Copyright 1995-2001 The LyX Team.
7  *
8  *           This file is Copyright 1996-2001
9  *           Lars Gullik Bjønnes
10  *
11  * ====================================================== 
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "DepTable.h"
21 #include "support/lyxlib.h"
22 #include "support/filetools.h"
23 #include "support/lstrings.h"
24 #include <fstream>
25 #include "debug.h"
26
27 using std::make_pair;
28 using std::ofstream;
29 using std::ifstream;
30 using std::endl;
31
32 void DepTable::insert(string const & fi,
33                       bool upd,
34                       unsigned long one,
35                       unsigned long two)
36 {
37         // not quite sure if this is the correct place for MakeAbsPath
38         string f = MakeAbsPath(fi);
39         if (deplist.find(f) == deplist.end()) {
40                 if (upd) {
41                         one = two;
42                         two = lyx::sum(f);
43                 }
44                 deplist[f] = make_pair(one, two);
45         }
46 }
47                 
48
49 void DepTable::update()
50 {
51         for (DepList::iterator itr = deplist.begin();
52             itr != deplist.end();
53             ++itr) {
54                 unsigned long const one = itr->second.second;
55                 unsigned long const two = lyx::sum(itr->first);
56                 itr->second = make_pair(one, two);
57                 if (lyxerr.debugging(Debug::DEPEND)) {
58                         lyxerr << "Update dep: " << itr->first << " "
59                                << one << " " << two;
60                         if (one != two)
61                                 lyxerr << " +";
62                         lyxerr << endl;
63                 }
64         }
65 }
66
67
68 bool DepTable::sumchange() const
69 {
70         for (DepList::const_iterator cit = deplist.begin();
71              cit != deplist.end();
72              ++cit) {
73                 if ((*cit).second.first != cit->second.second) return true;
74         }
75         return false;
76 }
77
78
79 bool DepTable::haschanged(string const & f) const
80 {
81         // not quite sure if this is the correct place for MakeAbsPath
82         string fil = MakeAbsPath(f);
83         DepList::const_iterator cit = deplist.find(fil);
84         if (cit != deplist.end()) {
85                 if (cit->second.first != cit->second.second
86                     && cit->second.second != 0)
87                         return true;
88         }
89         return false;
90 }
91
92
93 bool DepTable::extchanged(string const & ext) const
94 {
95         for (DepList::const_iterator cit = deplist.begin();
96              cit != deplist.end();
97              ++cit) {
98                 if (suffixIs(cit->first, ext)) {
99                         if (cit->second.first != cit->second.second)
100                                 return true;
101                 }
102         }
103         return false;
104 }
105
106
107 bool DepTable::exist(string const & fil) const
108 {
109         DepList::const_iterator cit = deplist.find(fil);
110         if (cit != deplist.end()) return true;
111         return false;
112 }
113
114
115 void DepTable::remove_files_with_extension(string const & suf)
116 {
117         DepList tmp;
118         // we want const_iterator (Lgb)
119         for (DepList::iterator cit = deplist.begin();
120              cit != deplist.end(); ++cit) {
121                 if (!suffixIs(cit->first, suf))
122                         tmp[cit->first] = cit->second;
123         }
124         deplist.swap(tmp);
125 }
126
127
128 void DepTable::write(string const & f) const
129 {
130         ofstream ofs(f.c_str());
131         for (DepList::const_iterator cit = deplist.begin();
132              cit != deplist.end(); ++cit) {
133                 if (lyxerr.debugging(Debug::DEPEND)) {
134                         lyxerr << "Write dep: "
135                                << cit->first << " "
136                                << cit->second.first << " "
137                                << cit->second.second << endl;
138                 }
139                 ofs << cit->first << " "
140                     << cit->second.first << " "
141                     << cit->second.second << endl;
142         }
143 }
144
145
146 void DepTable::read(string const & f)
147 {
148         ifstream ifs(f.c_str());
149         string nome;
150         unsigned long one = 0;
151         unsigned long two = 0;
152         while(ifs >> nome >> one >> two) {
153                 if (lyxerr.debugging(Debug::DEPEND)) {
154                         lyxerr << "Read dep: "
155                                << nome << " "
156                                << one << " "
157                                << two << endl;
158                 }
159                 deplist[nome] = make_pair(one, two);
160         }
161 }