]> git.lyx.org Git - features.git/blob - src/DepTable.C
the freespacing patch from Kayvan, draw the math empty delim with onoffdash, asure...
[features.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 using std::make_pair;
25 using std::ofstream;
26 using std::ifstream;
27
28 void DepTable::insert(string const & fi,
29                       bool upd,
30                       unsigned long one,
31                       unsigned long two)
32 {
33         // not quite sure if this is the correct place for MakeAbsPath
34         string f = MakeAbsPath(fi);
35         if (deplist.find(f) == deplist.end()) {
36                 if (upd) {
37                         one = two;
38                         two = lyx::sum(f.c_str());
39                 }
40                 deplist[f] = make_pair(one, two);
41         }
42 }
43                 
44
45 void DepTable::update()
46 {
47         for(DepList::iterator itr = deplist.begin();
48             itr != deplist.end();
49             ++itr) {
50                 unsigned long one = (*itr).second.second;
51                 unsigned long two = lyx::sum((*itr).first.c_str());
52                 (*itr).second = make_pair(one, two);
53                 if (lyxerr.debugging(Debug::DEPEND)) {
54                         lyxerr << "Update dep: " << (*itr).first << " "
55                                << one << " " << two;
56                         if (one != two)
57                                 lyxerr << " +";
58                         lyxerr << endl;
59                 }
60         }
61 }
62
63
64 bool DepTable::sumchange() const
65 {
66         for (DepList::const_iterator cit = deplist.begin();
67              cit != deplist.end();
68              ++cit) {
69                 if ((*cit).second.first != (*cit).second.second) return true;
70         }
71         return false;
72 }
73
74
75 bool DepTable::haschanged(string const & f) const
76 {
77         // not quite sure if this is the correct place for MakeAbsPath
78         string fil = MakeAbsPath(f);
79         DepList::const_iterator cit = deplist.find(fil);
80         if (cit != deplist.end()) {
81                 if ((*cit).second.first != (*cit).second.second
82                     && (*cit).second.second != 0)
83                         return true;
84         }
85         return false;
86 }
87
88
89 bool DepTable::extchanged(string const & ext) const
90 {
91         for (DepList::const_iterator cit = deplist.begin();
92              cit != deplist.end();
93              ++cit) {
94                 if (suffixIs((*cit).first, ext.c_str())) {
95                         if ((*cit).second.first != (*cit).second.second)
96                                 return true;
97                 }
98         }
99         return false;
100 }
101
102
103 bool DepTable::exist(string const & fil) const
104 {
105         DepList::const_iterator cit = deplist.find(fil);
106         if (cit != deplist.end()) return true;
107         return false;
108 }
109
110
111 void DepTable::remove_files_with_extension(string const & suf)
112 {
113         DepList tmp;
114         for (DepList::const_iterator cit = deplist.begin();
115              cit != deplist.end(); ++cit) {
116                 if (!suffixIs((*cit).first, suf.c_str()))
117                         tmp[(*cit).first] = (*cit).second;
118         }
119         deplist.swap(tmp);
120         
121 }
122
123
124 void DepTable::write(string const & f) const
125 {
126         ofstream ofs(f.c_str());
127         for (DepList::const_iterator cit = deplist.begin();
128              cit != deplist.end();
129              ++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 }