]> git.lyx.org Git - lyx.git/blob - src/DepTable.C
Various fixes, removed "default" language, inserted new lyxrc tag
[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         for (DepList::const_iterator cit = deplist.begin();
117              cit != deplist.end(); ++cit) {
118                 if (!suffixIs((*cit).first, suf))
119                         tmp[(*cit).first] = (*cit).second;
120         }
121         deplist.swap(tmp);
122 }
123
124
125 void DepTable::write(string const & f) const
126 {
127         ofstream ofs(f.c_str());
128         for (DepList::const_iterator cit = deplist.begin();
129              cit != deplist.end(); ++cit) {
130                 if (lyxerr.debugging(Debug::DEPEND)) {
131                         lyxerr << "Write dep: "
132                                << (*cit).first << " "
133                                << (*cit).second.first << " "
134                                << (*cit).second.second << endl;
135                 }
136                 ofs << (*cit).first << " "
137                     << (*cit).second.first << " "
138                     << (*cit).second.second << endl;
139         }
140 }
141
142
143 void DepTable::read(string const & f)
144 {
145         ifstream ifs(f.c_str());
146         string nome;
147         unsigned long one = 0;
148         unsigned long two = 0;
149         while(ifs >> nome >> one >> two) {
150                 if (lyxerr.debugging(Debug::DEPEND)) {
151                         lyxerr << "Read dep: "
152                                << nome << " "
153                                << one << " "
154                                << two << endl;
155                 }
156                 deplist[nome] = make_pair(one, two);
157         }
158 }