E
Eric Boutin
Hi all ! I'm currently writing a function that evaluate if there is a
diffence beetween 2 streams (istringstream and ifstream).
The problem is, it doesn't work. It *always* finds a difference at the
9th line because the first 8 lines are skipped, however, the is no
difference at all beetween the two streams, the only difference is that
after skipping the 8th first lines, one of the stream don't go forward
therefore a difference is found. Here's the function
//returns true if it find a difference
bool diff(string currzone, string zonefilename, ostream& verbose) {
istringstream iss(currzone); //The Current Zone File
ifstream ifs(zonefilename.c_str()); //The Old Zone File
string buff1, buff2;
//ignore the first 8 lines
for(int i=1; i<8; i++) {
getline(iss, buff1);
getline(ifs, buff2);
verbose << "Ignored from curr zone : " << buff1 << endl;
verbose << "ignored from old zone : " << buff2 <<endl;
}
while(true) {
if((getline(iss, buff1).eof() == true) && (getline(ifs,buff2).eof() == true)) {
//everythings ok
verbose << "Both file ends at same time, no diff" << endl;
return false;}
if(buff1 != buff2) {
//difference found
verbose << "Difference found :\n New Line : " << buff1
<< "\n Old Line : " << buff2 <<endl;
return true;
} else {
verbose << "Identic Lines : "<< endl << buff1 << endl << buff2 << endl;
}
}
//Shouldn't come up here
return true;
}
and the output produce when ostream& verbose = cout;
Ignored from curr zone : $ttl 38400
ignored from old zone : $ttl 38400
Ignored from curr zone : local. IN SOA enterprise. root.localhost. (
ignored from old zone : local. IN SOA enterprise. root.localhost. (
Ignored from curr zone : 2004211516 ;Serial Number
ignored from old zone : 2004211516 ;Serial Number
Ignored from curr zone : 10800 ; refresh
ignored from old zone : 10800 ; refresh
Ignored from curr zone : 3600 ; retry
ignored from old zone : 3600 ; retry
Ignored from curr zone : 604800 ; expire
ignored from old zone : 604800 ; expire
Ignored from curr zone : 3600 ) ; minimum
ignored from old zone : 3600 ) ; minimum
Difference found :
New Line : local. IN NS enterprise.
Old Line : 3600 ) ; minimum
We can notice the "old line" "forget" to go forward.. I really don't know
what's wrong
(thoses who works in DNS area will notice it's a BIND zone file..)
I really really don't know what's wrong and I really appreciate your help !
thanks a lot !
by the way.. English is not my main langage so excuse my errors.. thanks !
if it can help (that's why it's at the end since I'm not so shure it can
help but I just provides it) Here's the zone file produced by this program
(the same one that's read)
$ttl 38400
local. IN SOA enterprise. root.localhost. (
2004211516 ;Serial Number
10800 ; refresh
3600 ; retry
604800 ; expire
3600 ) ; minimum
local. IN NS enterprise.
josee.local. IN A 192.168.0.102
enterprise.local. IN A 192.168.0.101
deepspace9.local. IN A 192.168.0.100
diffence beetween 2 streams (istringstream and ifstream).
The problem is, it doesn't work. It *always* finds a difference at the
9th line because the first 8 lines are skipped, however, the is no
difference at all beetween the two streams, the only difference is that
after skipping the 8th first lines, one of the stream don't go forward
therefore a difference is found. Here's the function
//returns true if it find a difference
bool diff(string currzone, string zonefilename, ostream& verbose) {
istringstream iss(currzone); //The Current Zone File
ifstream ifs(zonefilename.c_str()); //The Old Zone File
string buff1, buff2;
//ignore the first 8 lines
for(int i=1; i<8; i++) {
getline(iss, buff1);
getline(ifs, buff2);
verbose << "Ignored from curr zone : " << buff1 << endl;
verbose << "ignored from old zone : " << buff2 <<endl;
}
while(true) {
if((getline(iss, buff1).eof() == true) && (getline(ifs,buff2).eof() == true)) {
//everythings ok
verbose << "Both file ends at same time, no diff" << endl;
return false;}
if(buff1 != buff2) {
//difference found
verbose << "Difference found :\n New Line : " << buff1
<< "\n Old Line : " << buff2 <<endl;
return true;
} else {
verbose << "Identic Lines : "<< endl << buff1 << endl << buff2 << endl;
}
}
//Shouldn't come up here
return true;
}
and the output produce when ostream& verbose = cout;
Ignored from curr zone : $ttl 38400
ignored from old zone : $ttl 38400
Ignored from curr zone : local. IN SOA enterprise. root.localhost. (
ignored from old zone : local. IN SOA enterprise. root.localhost. (
Ignored from curr zone : 2004211516 ;Serial Number
ignored from old zone : 2004211516 ;Serial Number
Ignored from curr zone : 10800 ; refresh
ignored from old zone : 10800 ; refresh
Ignored from curr zone : 3600 ; retry
ignored from old zone : 3600 ; retry
Ignored from curr zone : 604800 ; expire
ignored from old zone : 604800 ; expire
Ignored from curr zone : 3600 ) ; minimum
ignored from old zone : 3600 ) ; minimum
Difference found :
New Line : local. IN NS enterprise.
Old Line : 3600 ) ; minimum
We can notice the "old line" "forget" to go forward.. I really don't know
what's wrong
(thoses who works in DNS area will notice it's a BIND zone file..)
I really really don't know what's wrong and I really appreciate your help !
thanks a lot !
by the way.. English is not my main langage so excuse my errors.. thanks !
if it can help (that's why it's at the end since I'm not so shure it can
help but I just provides it) Here's the zone file produced by this program
(the same one that's read)
$ttl 38400
local. IN SOA enterprise. root.localhost. (
2004211516 ;Serial Number
10800 ; refresh
3600 ; retry
604800 ; expire
3600 ) ; minimum
local. IN NS enterprise.
josee.local. IN A 192.168.0.102
enterprise.local. IN A 192.168.0.101
deepspace9.local. IN A 192.168.0.100