EgtGeneral 2.1l4 :
- TextFileCompare e BinaryFile ora restituiscono il numero di differenze trovate.
This commit is contained in:
+24
-27
@@ -27,48 +27,42 @@ static string CharToHexString( char cVal) ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
TextFileCompare( const string& sFile1, const string& sFile2, const string& sRemIni, const string& sFileO)
|
||||
TextFileCompare( const string& sFile1, const string& sFile2, const string& sRemIni, const string& sFileO, int& nDiff)
|
||||
{
|
||||
bool bOk1 ;
|
||||
bool bOk2 ;
|
||||
int nDiff ;
|
||||
string sLine1 ;
|
||||
string sLine2 ;
|
||||
string sLine1S ;
|
||||
string sLine2S ;
|
||||
string sLine1T ;
|
||||
string sLine2T ;
|
||||
ofstream ofOut ;
|
||||
Scanner scFile1 ;
|
||||
Scanner scFile2 ;
|
||||
|
||||
|
||||
// apro il file per le differenze in append
|
||||
ofstream ofOut ;
|
||||
ofOut.open( stringtoW( sFileO), ios_base::out | ios_base::app) ;
|
||||
if ( ! ofOut.good())
|
||||
if ( ! ofOut.good()) {
|
||||
nDiff = -3 ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// emetto intestazione differenze
|
||||
ofOut << "Compare (text) " << sFile1 << " to " << sFile2 << " :" << endl ;
|
||||
|
||||
// apro il primo file
|
||||
Scanner scFile1 ;
|
||||
if ( ! scFile1.Init( sFile1, sRemIni.c_str())) {
|
||||
ofOut << " Missing first file !!!" << endl ;
|
||||
ofOut.close() ;
|
||||
nDiff = -1 ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// apro il secondo file
|
||||
Scanner scFile2 ;
|
||||
if ( ! scFile2.Init( sFile2, sRemIni.c_str())) {
|
||||
ofOut << " Missing second file !!!" << endl ;
|
||||
ofOut.close() ;
|
||||
nDiff = -2 ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// ciclo sulle linee dei due file
|
||||
nDiff = 0 ;
|
||||
bOk1 = scFile1.GetLine( sLine1) ;
|
||||
bOk2 = scFile2.GetLine( sLine2) ;
|
||||
string sLine1, sLine2 ;
|
||||
bool bOk1 = scFile1.GetLine( sLine1) ;
|
||||
bool bOk2 = scFile2.GetLine( sLine2) ;
|
||||
while ( bOk1 || bOk2) {
|
||||
// se linee diverse
|
||||
if ( sLine1.compare( sLine2) != 0) {
|
||||
@@ -78,6 +72,7 @@ TextFileCompare( const string& sFile1, const string& sFile2, const string& sRemI
|
||||
ofOut << " F1(" << scFile1.GetCurrLineNbr() << "):" << sLine1 << endl ;
|
||||
ofOut << " F2(" << scFile2.GetCurrLineNbr() << "):" << sLine2 << endl ;
|
||||
// provo a caricare le linee successive
|
||||
string sLine1S, sLine2S ;
|
||||
bOk1 = scFile1.GetLine( sLine1S) ;
|
||||
bOk2 = scFile2.GetLine( sLine2S) ;
|
||||
// se le successive coincidono
|
||||
@@ -103,6 +98,7 @@ TextFileCompare( const string& sFile1, const string& sFile2, const string& sRemI
|
||||
// altrimenti
|
||||
else {
|
||||
// carico le linee ancora successive
|
||||
string sLine1T, sLine2T ;
|
||||
bOk1 = scFile1.GetLine( sLine1T) ;
|
||||
bOk2 = scFile2.GetLine( sLine2T) ;
|
||||
// se la 1 corrente coincide con la 2 terza
|
||||
@@ -151,40 +147,42 @@ TextFileCompare( const string& sFile1, const string& sFile2, const string& sRemI
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
BinaryFileCompare( const string& sFile1, const string& sFile2, const string& sFileO)
|
||||
BinaryFileCompare( const string& sFile1, const string& sFile2, const string& sFileO, int& nDiff)
|
||||
{
|
||||
ifstream ifIn1 ;
|
||||
ifstream ifIn2 ;
|
||||
ofstream ofOut ;
|
||||
|
||||
|
||||
// apro il file per le differenze in append
|
||||
ofstream ofOut ;
|
||||
ofOut.open( stringtoW( sFileO), ios_base::out | ios_base::app) ;
|
||||
if ( ! ofOut.good())
|
||||
if ( ! ofOut.good()) {
|
||||
nDiff = -3 ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// emetto intestazione differenze
|
||||
ofOut << "Compare (binary) " << sFile1 << " to " << sFile2 << " :" << endl ;
|
||||
|
||||
// apro il primo file
|
||||
ifstream ifIn1 ;
|
||||
ifIn1.open( stringtoW( sFile1), ios_base::in | ios_base::binary) ;
|
||||
if ( ! ifIn1.good()) {
|
||||
ofOut << " Missing first file !!!" << endl ;
|
||||
ofOut.close() ;
|
||||
nDiff = -1 ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// apro il secondo file
|
||||
ifstream ifIn2 ;
|
||||
ifIn2.open( stringtoW( sFile2), ios_base::in | ios_base::binary) ;
|
||||
if ( ! ifIn2.good()) {
|
||||
ofOut << " Missing second file !!!" << endl ;
|
||||
ofOut.close() ;
|
||||
ifIn1.close() ;
|
||||
nDiff = -2 ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
// ciclo sui buffer dei due file
|
||||
int nDiff = 0 ;
|
||||
nDiff = 0 ;
|
||||
const int DIM_BUFF = 8192 ;
|
||||
char cBuff1[DIM_BUFF] ;
|
||||
char cBuff2[DIM_BUFF] ;
|
||||
@@ -205,7 +203,6 @@ BinaryFileCompare( const string& sFile1, const string& sFile2, const string& sFi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lettura prossimo blocco
|
||||
nBase += min( nBuff1, nBuff2) ;
|
||||
ifIn1.read( cBuff1, DIM_BUFF) ;
|
||||
|
||||
Reference in New Issue
Block a user