1999-09-27 18:44:28 +00:00
|
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
2000-03-09 03:36:48 +00:00
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* This file is Copyright 1996-2001
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "DepTable.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
#include "support/filetools.h"
|
1999-11-04 01:40:20 +00:00
|
|
|
|
#include <fstream>
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
1999-11-08 13:54:04 +00:00
|
|
|
|
using std::make_pair;
|
|
|
|
|
using std::ofstream;
|
|
|
|
|
using std::ifstream;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void DepTable::insert(string const & fi,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool upd,
|
|
|
|
|
unsigned long one,
|
|
|
|
|
unsigned long two)
|
|
|
|
|
{
|
|
|
|
|
// not quite sure if this is the correct place for MakeAbsPath
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string f = MakeAbsPath(fi);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (deplist.find(f) == deplist.end()) {
|
|
|
|
|
if (upd) {
|
|
|
|
|
one = two;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
two = lyx::sum(f);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
|
|
|
|
deplist[f] = make_pair(one, two);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DepTable::update()
|
|
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
|
for (DepList::iterator itr = deplist.begin();
|
1999-11-04 01:40:20 +00:00
|
|
|
|
itr != deplist.end();
|
|
|
|
|
++itr) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
unsigned long const one = (*itr).second.second;
|
|
|
|
|
unsigned long const two = lyx::sum((*itr).first);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
(*itr).second = make_pair(one, two);
|
2000-01-25 12:35:27 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::DEPEND)) {
|
|
|
|
|
lyxerr << "Update dep: " << (*itr).first << " "
|
|
|
|
|
<< one << " " << two;
|
|
|
|
|
if (one != two)
|
|
|
|
|
lyxerr << " +";
|
|
|
|
|
lyxerr << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
|
bool DepTable::sumchange() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
for (DepList::const_iterator cit = deplist.begin();
|
|
|
|
|
cit != deplist.end();
|
|
|
|
|
++cit) {
|
|
|
|
|
if ((*cit).second.first != (*cit).second.second) return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
|
bool DepTable::haschanged(string const & f) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
// not quite sure if this is the correct place for MakeAbsPath
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string fil = MakeAbsPath(f);
|
1999-11-04 01:40:20 +00:00
|
|
|
|
DepList::const_iterator cit = deplist.find(fil);
|
|
|
|
|
if (cit != deplist.end()) {
|
|
|
|
|
if ((*cit).second.first != (*cit).second.second
|
|
|
|
|
&& (*cit).second.second != 0)
|
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
|
bool DepTable::extchanged(string const & ext) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
for (DepList::const_iterator cit = deplist.begin();
|
|
|
|
|
cit != deplist.end();
|
|
|
|
|
++cit) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (suffixIs((*cit).first, ext)) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if ((*cit).second.first != (*cit).second.second)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
|
bool DepTable::exist(string const & fil) const
|
|
|
|
|
{
|
|
|
|
|
DepList::const_iterator cit = deplist.find(fil);
|
|
|
|
|
if (cit != deplist.end()) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DepTable::remove_files_with_extension(string const & suf)
|
|
|
|
|
{
|
|
|
|
|
DepList tmp;
|
2000-11-15 03:22:08 +00:00
|
|
|
|
// we want const_iterator (Lgb)
|
|
|
|
|
for (DepList::iterator cit = deplist.begin();
|
1999-11-26 06:57:35 +00:00
|
|
|
|
cit != deplist.end(); ++cit) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (!suffixIs((*cit).first, suf))
|
1999-11-26 06:57:35 +00:00
|
|
|
|
tmp[(*cit).first] = (*cit).second;
|
|
|
|
|
}
|
|
|
|
|
deplist.swap(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DepTable::write(string const & f) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
ofstream ofs(f.c_str());
|
|
|
|
|
for (DepList::const_iterator cit = deplist.begin();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
cit != deplist.end(); ++cit) {
|
2000-01-25 12:35:27 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::DEPEND)) {
|
1999-11-04 01:40:20 +00:00
|
|
|
|
lyxerr << "Write dep: "
|
|
|
|
|
<< (*cit).first << " "
|
|
|
|
|
<< (*cit).second.first << " "
|
|
|
|
|
<< (*cit).second.second << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
|
ofs << (*cit).first << " "
|
|
|
|
|
<< (*cit).second.first << " "
|
|
|
|
|
<< (*cit).second.second << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
|
|
|
|
|
|
void DepTable::read(string const & f)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
ifstream ifs(f.c_str());
|
|
|
|
|
string nome;
|
|
|
|
|
unsigned long one = 0;
|
|
|
|
|
unsigned long two = 0;
|
|
|
|
|
while(ifs >> nome >> one >> two) {
|
2000-01-25 12:35:27 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::DEPEND)) {
|
|
|
|
|
lyxerr << "Read dep: "
|
1999-11-04 01:40:20 +00:00
|
|
|
|
<< nome << " "
|
|
|
|
|
<< one << " "
|
|
|
|
|
<< two << endl;
|
|
|
|
|
}
|
|
|
|
|
deplist[nome] = make_pair(one, two);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|