diff --git a/CmdParser.cpp b/CmdParser.cpp new file mode 100644 index 0000000..f922d25 --- /dev/null +++ b/CmdParser.cpp @@ -0,0 +1,122 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : CmdParser.cpp Data : 25.11.13 Versione : 1.3a1 +// Contenuto : Implementazione della classe CCmdParser. +// +// +// +// Modifiche : 19.01.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include +#include "/EgtDev/Include/EgnStringUtils.h" +#include "CmdParser.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +ICmdParser* +CreateCmdParser( void) +{ + return static_cast ( new CmdParser) ; +} + +//---------------------------------------------------------------------------- +CmdParser::CmdParser( void) +{ + m_pTheExecutor = nullptr ; +} + +//---------------------------------------------------------------------------- +CmdParser::~CmdParser( void) +{ +} + +//---------------------------------------------------------------------------- +bool +CmdParser::Initialize( wstring sCmdFile, ICmdExecutor* pCmdExec) +{ + // inizializzo lo scanner + if ( ! m_TheScanner.Initialize( sCmdFile)) + return false ; + + // verifico la validità dell'esecutore + if ( pCmdExec == nullptr) + return false ; + + // salvo il riferimento al documento + m_pTheExecutor = pCmdExec ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +CmdParser::Run( void) +{ + bool bOk ; + string sLine ; + string sCmd ; + string sParams ; + string sDummy ; + + + // log di inizio file + cout << "--- Start : " << m_TheScanner.GetFilePath() << endl ; + + // interpretazione dei comandi del file + bOk = true ; + while ( bOk && m_TheScanner.GetLine( sLine)) { + // elimino gli spazi all'inizio e alla fine + Trim( sLine) ; + // separo comando e parametri + SplitFirst( sLine, "(", sCmd, sParams) ; + // elimino dai parametri tutto quanto dopo ultima parentesi chiusa + SplitLast( sParams, ")", sParams, sDummy) ; + // deve esserci un comando e deve essere eseguito correttamente + if ( sCmd.empty() || ! ExecCommand( sCmd, sParams)) { + bOk = false ; + cout << "Error on line (" << m_TheScanner.GetCurrLineNbr() << ") : " << sLine << endl ; + } + } + + // log di fine file + if ( bOk) + cout << "--- End" << endl ; + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +CmdParser::ExecCommand( const string& sCmd, const string& sParams) +{ + string sCmd1 ; + string sCmd2 ; + STRVECTOR vsParams ; + STRVECTOR::iterator Iter ; + + + // divido il comando e lo normalizzo + SplitFirst( sCmd, ".", sCmd1, sCmd2) ; + Trim( sCmd1) ; + ToUpper( sCmd1) ; + Trim( sCmd2) ; + ToUpper( sCmd2) ; + + // divido i parametri + Tokenize( sParams, ",", "(", ")", vsParams) ; + for ( Iter = vsParams.begin() ; Iter != vsParams.end() ; Iter++) + Trim( (*Iter)) ; + + // eseguo il comando con i suoi parametri + if ( m_pTheExecutor != nullptr) + return m_pTheExecutor->Execute( sCmd1, sCmd2, vsParams) ; + else + return false ; +} \ No newline at end of file diff --git a/CmdParser.h b/CmdParser.h new file mode 100644 index 0000000..a6dd131 --- /dev/null +++ b/CmdParser.h @@ -0,0 +1,34 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : CmdParser.h Data : 25.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della classe CmdParser. +// +// +// +// Modifiche : 19.01.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EgnCmdParser.h" +#include "CmdScanner.h" + +//---------------------------------------------------------------------------- +class CmdParser : public ICmdParser +{ + public : + CmdParser( void) ; + ~CmdParser( void) ; + bool Initialize( std::wstring sCmdFile, ICmdExecutor* pCmdExec) ; + bool Run( void) ; + + private : + bool ExecCommand( const std::string& sCmd, const std::string& sParams) ; + + private : + CmdScanner m_TheScanner ; + ICmdExecutor* m_pTheExecutor ; +} ; diff --git a/CmdScanner.cpp b/CmdScanner.cpp new file mode 100644 index 0000000..d977441 --- /dev/null +++ b/CmdScanner.cpp @@ -0,0 +1,82 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : CmdScanner.cpp Data : 25.11.13 Versione : 1.3a1 +// Contenuto : Implementazione della classe CmdScanner. +// Scansione di file di testo con codifica UTF-8 (anche con BOM) +// e quindi anche ASCII. +// +// +// Modifiche : 19.01.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "/EgtDev/Include/EgnStringUtils.h" +#include "/EgtDev/Include/EgnStringConverter.h" +#include "CmdScanner.h" + +using namespace std ; + + +//---------------------------------------------------------------------------- +CmdScanner::CmdScanner( void) +{ + m_nLineNbr = 0 ; +} + +//---------------------------------------------------------------------------- +CmdScanner::~CmdScanner( void) +{ + Terminate() ; +} + +//---------------------------------------------------------------------------- +bool +CmdScanner::Initialize( wstring sCmdFile) +{ + // se già aperto, lo chiudo + Terminate() ; + + // apertura del file di ingresso + m_CmdFile.open( sCmdFile, ios::in) ; + + // reset numero linea corrente + m_nLineNbr = 0 ; + + // salvo path file + m_sFName = wstringtoA( sCmdFile) ; + + return ( ! m_CmdFile.fail()) ; +} + +//---------------------------------------------------------------------------- +bool +CmdScanner::Terminate( void) +{ + if ( m_CmdFile.is_open()) + m_CmdFile.close() ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +CmdScanner::GetLine( string& sLine) +{ + if ( ! m_CmdFile.is_open()) + return false ; + + do { + if ( ! getline( m_CmdFile, sLine)) + return false ; + if ( m_nLineNbr == 0) + TrimUtf8Bom( sLine) ; + TrimLeft( sLine) ; + m_nLineNbr ++ ; + } while ( sLine.empty() || sLine.find( "//") == 0) ; + + return true ; +} diff --git a/CmdScanner.h b/CmdScanner.h new file mode 100644 index 0000000..3cbf454 --- /dev/null +++ b/CmdScanner.h @@ -0,0 +1,36 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : CmdScanner.h Data : 25.11.13 Versione : 1.3a1 +// Contenuto : Dichiarazione della classe CmdScanner. +// +// +// +// Modifiche : 19.01.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include +#include + +//---------------------------------------------------------------------------- +class CmdScanner +{ + public : + CmdScanner( void) ; + ~CmdScanner( void) ; + bool Initialize( std::wstring sCmdFile) ; + bool Terminate( void) ; + bool GetLine( std::string& sLine) ; + int GetCurrLineNbr( void) { return m_nLineNbr ; } + const std::string& GetFilePath( void) + { return m_sFName ; } + + private : + std::string m_sFName ; + std::ifstream m_CmdFile ; + int m_nLineNbr ; +} ; diff --git a/EgtGeneral.vcxproj b/EgtGeneral.vcxproj index cbae498..fc98536 100644 --- a/EgtGeneral.vcxproj +++ b/EgtGeneral.vcxproj @@ -96,13 +96,22 @@ copy $(TargetPath) \EgtProg\Dll + + + + + + + + + false diff --git a/EgtGeneral.vcxproj.filters b/EgtGeneral.vcxproj.filters index d3640d6..b07ce03 100644 --- a/EgtGeneral.vcxproj.filters +++ b/EgtGeneral.vcxproj.filters @@ -30,6 +30,27 @@ File di intestazione + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + @@ -44,6 +65,12 @@ File di origine + + File di origine + + + File di origine +