]> git.lyx.org Git - lyx.git/blob - src/DepTable.C
Reverted the reverted changes - 1.
[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-2000 The LyX Team.
7  *
8  *           This file is Copyright 1996-2000
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 <fstream>
24
25 using std::make_pair;
26 using std::ofstream;
27 using std::ifstream;
28 using std::endl;
29
30 void DepTable::insert(string const & fi,
31                       bool upd,
32                       unsigned long one,
33                       unsigned long two)
34 {
35         // not quite sure if this is the correct place for MakeAbsPath
36         string f = MakeAbsPath(fi);
37         if (deplist.find(f) == deplist.end()) {
38                 if (upd) {
39                         one = two;
40                         two = lyx::sum(f);
41                 }
42                 deplist[f] = make_pair(one, two);
43         }
44 }
45                 
46
47 void DepTable::update()
48 {
49         for (DepList::iterator itr = deplist.begin();
50             itr != deplist.end();
51             ++itr) {
52                 unsigned long const one = (*itr).second.second;
53                 unsigned long const two = lyx::sum((*itr).first);
54                 (*itr).second = make_pair(one, two);
55                 if (lyxerr.debugging(Debug::DEPEND)) {
56                         lyxerr << "Update dep: " << (*itr).first << " "
57                                << one << " " << two;
58                         if (one != two)
59                                 lyxerr << " +";
60                         lyxerr << endl;
61                 }
62         }
63 }
64
65
66 bool DepTable::sumchange() const
67 {
68         for (DepList::const_iterator cit = deplist.begin();
69              cit != deplist.end();
70              ++cit) {
71                 if ((*cit).second.first != (*cit).second.second) return true;
72         }
73         return false;
74 }
75
76
77 bool DepTable::haschanged(string const & f) const
78 {
79         // not quite sure if this is the correct place for MakeAbsPath
80         string fil = MakeAbsPath(f);
81         DepList::const_iterator cit = deplist.find(fil);
82         if (cit != deplist.end()) {
83                 if ((*cit).second.first != (*cit).second.second
84                     && (*cit).second.second != 0)
85                         return true;
86         }
87         return false;
88 }
89
90
91 bool DepTable::extchanged(string const & ext) const
92 {
93         for (DepList::const_iterator cit = deplist.begin();
94              cit != deplist.end();
95              ++cit) {
96                 if (suffixIs((*cit).first, ext)) {
97                         if ((*cit).second.first != (*cit).second.second)
98                                 return true;
99                 }
100         }
101         return false;
102 }
103
104
105 bool DepTable::exist(string const & fil) const
106 {
107         DepList::const_iterator cit = deplist.find(fil);
108         if (cit != deplist.end()) return true;
109         return false;
110 }
111
112
113 void DepTable::remove_files_with_extension(string const & suf)
114 {
115         DepList tmp;
116         // we want const_iterator (Lgb)
117         for (DepList::iterator cit = deplist.begin();
118              cit != deplist.end(); ++cit) {
119                 if (!suffixIs((*cit).first, suf))
120                         tmp[(*cit).first] = (*cit).second;
121         }
122         deplist.swap(tmp);
123 }
124
125
126 void DepTable::write(string const & f) const
127 {
128         ofstream ofs(f.c_str());
129         for (DepList::const_iterator cit = deplist.begin();
130              cit != deplist.end(); ++cit) {
131                 if (lyxerr.debugging(Debug::DEPEND)) {
132                         lyxerr << "Write dep: "
133                                << (*cit).first << " "
134                                << (*cit).second.first << " "
135                                << (*cit).second.second << endl;
136                 }
137                 ofs << (*cit).first << " "
138                     << (*cit).second.first << " "
139                     << (*cit).second.second << endl;
140         }
141 }
142
143
144 void DepTable::read(string const & f)
145 {
146         ifstream ifs(f.c_str());
147         string nome;
148         unsigned long one = 0;
149         unsigned long two = 0;
150         while(ifs >> nome >> one >> two) {
151                 if (lyxerr.debugging(Debug::DEPEND)) {
152                         lyxerr << "Read dep: "
153                                << nome << " "
154                                << one << " "
155                                << two << endl;
156                 }
157                 deplist[nome] = make_pair(one, two);
158         }
159 }