EgtGeneral 1.4a5 : Aggiunto confronto tra file di testo. CScan -> Scanner.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// 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 ;
|
||||
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 ;
|
||||
}
|
||||
// passo alle linee successive
|
||||
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 ;
|
||||
}
|
||||
Reference in New Issue
Block a user