1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
5 * Copyright (C) 1995 Matthias Ettrich
6 * Copyright (C) 1995-1998 The LyX Team.
8 * This file is Copyright (C) 1996-1998
11 * ======================================================
17 #include "support/lyxlib.h"
18 #include "support/filetools.h"
28 DepTable::DepTable(string const & f,
33 // not quite sure if this is the correct place for MakeAbsPath
34 file = MakeAbsPath(f);
35 new_sum = 0; old_sum = 0;
42 new_sum = lyxsum(file.c_str());
44 if (lyxerr.debugging()) {
47 sprintf(tmp1, "%lu", new_sum);
48 sprintf(tmp2, "%lu", old_sum);
49 lyxerr.debug() << "New file inserted in deplog: "
51 << tmp1 << " " << tmp2 << endl;
57 void DepTable::insert(string const & fi,
62 // not quite sure if this is the correct place for MakeAbsPath
63 string f = MakeAbsPath(fi);
64 if (f == file) return; // exist already in the log
66 next->insert(f, upd, one, two);
68 next = new DepTable(f, upd, one, two);
72 void DepTable::update()
76 new_sum = lyxsum(file.c_str());
77 if (lyxerr.debugging()) {
80 sprintf(tmp1, "%lu", new_sum);
81 sprintf(tmp2, "%lu", old_sum);
82 lyxerr.debug() << "update: " << file << " "
83 << tmp1 << " " << tmp2 << endl;
86 if (next) next->update();
90 bool DepTable::sumchange()
95 if (old_sum != new_sum) ret = true;
97 if (!ret && next) ret = next->sumchange();
103 bool DepTable::haschanged(string const & f)
105 // not quite sure if this is the correct place for MakeAbsPath
106 string fil = MakeAbsPath(f);
109 if (!fil.empty() && !file.empty() && fil == file) {
110 if (new_sum != old_sum && new_sum != 0)
113 if (!ret && next) ret = next->haschanged(fil);
118 void DepTable::write(string const&f)
120 FilePtr fp(f, FilePtr::write);
121 if (fp() && next) next->write(fp());
125 void DepTable::read(string const &f)
127 FilePtr fp(f, FilePtr::read);
128 if (fp()) { // file opened
130 unsigned long one = 0;
131 unsigned long two = 0;
132 // scan the file line by line
133 // return true if the two numbers on the line is different
135 while (!feof(fp())) {
136 ret = fscanf(fp(), "%s %lu %lu",
138 if (ret !=3) continue;
139 if (lyxerr.debugging()) {
142 sprintf(tmp1, "%lu", one);
143 sprintf(tmp2, "%lu", two);
144 lyxerr.debug() << "read dep: "
145 << nome << " " << tmp1
146 << " " << tmp2 << endl;
148 insert(string(nome), false, one, two);
154 void DepTable::write(FILE * f)
156 if (lyxerr.debugging()) {
159 sprintf(tmp1, "%lu", new_sum);
160 sprintf(tmp2, "%lu", old_sum);
161 lyxerr << "Write dep: " << file << " "
162 << tmp1 << " " << tmp2 << endl;
164 fprintf(f, "%s %lu %lu\n", file.c_str(),