EgtGeneral : aggiunto interprete di comandi Tsc.
This commit is contained in:
+122
@@ -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 <iostream>
|
||||
#include "/EgtDev/Include/EgnStringUtils.h"
|
||||
#include "CmdParser.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ICmdParser*
|
||||
CreateCmdParser( void)
|
||||
{
|
||||
return static_cast<ICmdParser*> ( 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 ;
|
||||
}
|
||||
Reference in New Issue
Block a user