111 lines
3.4 KiB
C++
111 lines
3.4 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2013
|
|
//----------------------------------------------------------------------------
|
|
// File : FileCompare.cpp Data : 11.12.13 Versione : 1.4a5
|
|
// Contenuto : Funzioni per confronto tra due file (di testo).
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 11.12.13 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "/EgtDEv/Include/EgnFileCompare.h"
|
|
#include "/EgtDEv/Include/EGnStringConverter.h"
|
|
#include "/EgtDEv/Include/EGnScan.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
TextFileCompare( const string& sFile1, const string& sFile2, const string& sRemIni, const string& sFileO)
|
|
{
|
|
bool bOk1 ;
|
|
bool bOk2 ;
|
|
int nDiff ;
|
|
string sLine1 ;
|
|
string sLine2 ;
|
|
string sLine1S ;
|
|
string sLine2S ;
|
|
ofstream ofOut ;
|
|
Scanner scFile1 ;
|
|
Scanner scFile2 ;
|
|
|
|
|
|
// apro il file per le differenze in append
|
|
ofOut.open( stringtoW( sFileO), ios_base::out | ios_base::app) ;
|
|
if ( ! ofOut.good())
|
|
return false ;
|
|
|
|
// emetto intestazione differenze
|
|
ofOut << "Compare " << sFile1 << " to " << sFile2 << " :" << endl ;
|
|
|
|
// apro il primo file
|
|
if ( ! scFile1.Init( sFile1, sRemIni.c_str())) {
|
|
ofOut << " Missing first file !!!" << endl ;
|
|
ofOut.close() ;
|
|
return false ;
|
|
}
|
|
|
|
// apro il secondo file
|
|
if ( ! scFile2.Init( sFile2, sRemIni.c_str())) {
|
|
ofOut << " Missing second file !!!" << endl ;
|
|
ofOut.close() ;
|
|
return false ;
|
|
}
|
|
|
|
// ciclo sulle linee dei due file
|
|
nDiff = 0 ;
|
|
bOk1 = scFile1.GetLine( sLine1) ;
|
|
bOk2 = scFile2.GetLine( sLine2) ;
|
|
while ( bOk1 || bOk2) {
|
|
// se linee diverse
|
|
if ( sLine1.compare( sLine2) != 0) {
|
|
nDiff ++ ;
|
|
// emetto differenze
|
|
ofOut << " Diff :" << endl ;
|
|
ofOut << " F1(" << scFile1.GetCurrLineNbr() << "):" << sLine1 << endl ;
|
|
ofOut << " F2(" << scFile2.GetCurrLineNbr() << "):" << sLine2 << endl ;
|
|
// provo a caricare le linee successive
|
|
bOk1 = scFile1.GetLine( sLine1S) ;
|
|
bOk2 = scFile2.GetLine( sLine2S) ;
|
|
// se la 1 corrente coincide con la 2 successiva
|
|
if ( sLine1.compare( sLine2S) == 0) {
|
|
// mi porto avanti con il file 2
|
|
sLine1 = sLine1S ;
|
|
bOk2 = scFile2.GetLine( sLine2) ;
|
|
}
|
|
// se la 2 corrente coincide con la 1 successiva
|
|
else if ( sLine2.compare( sLine1S) == 0) {
|
|
// mi porto avanti con il file 1
|
|
bOk1 = scFile1.GetLine( sLine1) ;
|
|
sLine2 = sLine2S ;
|
|
}
|
|
// altrimenti, continuo in sincronismo
|
|
else {
|
|
sLine1 = sLine1S ;
|
|
sLine2 = sLine2S ;
|
|
}
|
|
}
|
|
// passo alle linee successive
|
|
else {
|
|
bOk1 = scFile1.GetLine( sLine1) ;
|
|
bOk2 = scFile2.GetLine( sLine2) ;
|
|
}
|
|
}
|
|
|
|
// emetto riassunto differenze
|
|
if ( nDiff == 0)
|
|
ofOut << " Same content" << endl ;
|
|
else
|
|
ofOut << " Found " << nDiff << " differences !!!" << endl ;
|
|
|
|
// chiudo il file di uscita
|
|
ofOut.close() ;
|
|
|
|
return true ;
|
|
}
|