EgtGeneral 1.5d4 :

- aggiunto param. bSkipEmptyLine a Init di Scanner
- aggiunto a TSC comando EXEC con sottocomandi SKIP, DO e STOP.
This commit is contained in:
Dario Sassi
2014-04-21 21:53:35 +00:00
parent 230352742d
commit d8f3704d20
4 changed files with 66 additions and 7 deletions
+53 -4
View File
@@ -44,6 +44,7 @@ CmdParser::CmdParser( void)
m_ExecMgr.Insert( "RESET", &CmdParser::ExecuteReset) ;
m_ExecMgr.Insert( "RUN", &CmdParser::ExecuteRun) ;
m_ExecMgr.Insert( "SET", &CmdParser::ExecuteSet) ;
m_ExecMgr.Insert( "EXEC", &CmdParser::ExecuteExec) ;
}
//----------------------------------------------------------------------------
@@ -129,17 +130,25 @@ CmdParser::Run( const std::string& sCmdFile, bool bIsolated)
}
// interpretazione dei comandi del file
while ( bOk && TheScanner.GetLine( sLine)) {
m_nCurrLine = 0 ;
m_nExec = DO ;
while ( bOk && m_nExec != STOP && TheScanner.GetLine( sLine)) {
// assegno numero linea corrente
m_nCurrLine = TheScanner.GetCurrLineNbr() ;
// elimino gli spazi all'inizio e alla fine
Trim( sLine) ;
// separo comando e parametri
SplitFirst( sLine, "(", sCmd, sParams) ;
ToUpper( sCmd) ;
// elimino dai parametri tutto quanto dopo ultima parentesi chiusa
SplitLast( sParams, ")", sParams, sDummy) ;
// se da saltare e non è comando che fa riprendere esecuzione, vado al prossimo
if ( m_nExec == SKIP && sCmd != "EXEC.DO")
continue ;
// deve esserci un comando e deve essere eseguito correttamente
if ( sCmd.empty() || ! ExecCommand( sCmd, sParams)) {
bOk = false ;
sOut = GetInitSpaces() + "Error on line (" + ToString( TheScanner.GetCurrLineNbr()) + ") : " + sLine ;
sOut = GetInitSpaces() + "Error on line (" + ToString( m_nCurrLine) + ") : " + sLine ;
LOG_ERROR( GetEGnLogger(), sOut.c_str())
}
}
@@ -177,6 +186,7 @@ CmdParser::ExecLine( const string& sCmdLine, bool bIsolated)
// separo comando e parametri
string sCmd, sParams ;
SplitFirst( sLine, "(", sCmd, sParams) ;
ToUpper( sCmd) ;
// elimino dai parametri tutto quanto dopo ultima parentesi chiusa
string sDummy ;
SplitLast( sParams, ")", sParams, sDummy) ;
@@ -301,9 +311,7 @@ CmdParser::ExecCommand( const string& sCmd, const string& sParams)
string sCmd1, sCmd2 ;
SplitFirst( sCmd, ".", sCmd1, sCmd2) ;
Trim( sCmd1) ;
ToUpper( sCmd1) ;
Trim( sCmd2) ;
ToUpper( sCmd2) ;
// divido i parametri
STRVECTOR vsParams ;
@@ -382,6 +390,47 @@ CmdParser::ExecuteDir( const string& sCmd2, const STRVECTOR& vsParams)
return false ;
}
//----------------------------------------------------------------------------
bool
CmdParser::ExecuteExec( const string& sCmd2, const STRVECTOR& vsParams)
{
if ( sCmd2 == "SKIP") {
// nessun parametro
if ( vsParams.size() != 0)
return false ;
// imposto il flag di esecuzione
m_nExec = SKIP ;
// emetto log
string sOut = GetInitSpaces() + "Skip on line (" + ToString( m_nCurrLine) + ")" ;
LOG_INFO( GetEGnLogger(), sOut.c_str())
return true ;
}
else if ( sCmd2 == "DO") {
// nessun parametro
if ( vsParams.size() != 0)
return false ;
// imposto il flag di stop
m_nExec = DO ;
// emetto log
string sOut = GetInitSpaces() + "Do on line (" + ToString( m_nCurrLine) + ")" ;
LOG_INFO( GetEGnLogger(), sOut.c_str())
return true ;
}
else if ( sCmd2 == "STOP") {
// nessun parametro
if ( vsParams.size() != 0)
return false ;
// imposto il flag di stop
m_nExec = STOP ;
// emetto log
string sOut = GetInitSpaces() + "Stop on line (" + ToString( m_nCurrLine) + ")" ;
LOG_INFO( GetEGnLogger(), sOut.c_str())
return true ;
}
return false ;
}
//----------------------------------------------------------------------------
bool
CmdParser::ExecuteFile( const string& sCmd2, const STRVECTOR& vsParams)
+6
View File
@@ -44,6 +44,7 @@ class CmdParser : public ICmdParser
bool ExecCommand( const std::string& sCmd, const std::string& sParams) ;
bool ExecuteCounter( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteDir( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteExec( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteFile( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecutePause( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteReset( const std::string& sCmd2, const STRVECTOR& vsParams) ;
@@ -55,10 +56,15 @@ class CmdParser : public ICmdParser
typedef std::list<ICmdExecutor*> PCmdExecList ;
typedef std::unordered_map<std::string, int> NameMap ;
private :
enum Exec{ SKIP = 1, DO = 2, STOP = 3} ;
private :
PCmdExecList m_CmdExecList ;
NameMap m_NameMap ;
ExecManager<CmdParser> m_ExecMgr ;
int m_nLev ;
Exec m_nExec ;
int m_nCurrLine ;
PerformanceCounter m_Counter ;
} ;
BIN
View File
Binary file not shown.
+7 -3
View File
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------
// EgalTech 2013-2014
//----------------------------------------------------------------------------
// File : Scan.cpp Data : 06.03.14 Versione : 1.5c1
// File : Scan.cpp Data : 17.04.14 Versione : 1.5d
// Contenuto : Implementazione della classe Scanner.
// Scansione di file di testo con codifica UTF-8 (anche con BOM)
// e quindi anche ASCII.
@@ -9,6 +9,7 @@
//
// Modifiche : 30.09.13 DS Creazione modulo.
// 06.03.14 DS Aggiunta UngetLine.
// 17.04.14 DS Aggiunto parametro bSkipEmptyLine a Init.
//
//----------------------------------------------------------------------------
@@ -23,7 +24,7 @@ using namespace std ;
//----------------------------------------------------------------------------
bool
Scanner::Init( const std::string& sFile, const char* szRemInit)
Scanner::Init( const std::string& sFile, const char* szRemInit, bool bSkipEmptyLine)
{
// apertura del file di ingresso
m_InFile.open( stringtoW( sFile), ios::in) ;
@@ -42,6 +43,9 @@ Scanner::Init( const std::string& sFile, const char* szRemInit)
else
m_sRemInit = "//" ;
// assegno flag per saltare linee vuote
m_bSkipEmptyLine = bSkipEmptyLine ;
return ( ! m_InFile.fail()) ;
}
@@ -79,7 +83,7 @@ Scanner::GetLine( string& sLine)
TrimUtf8Bom( sLine) ;
Trim( sLine) ;
m_nLineNbr ++ ;
} while ( sLine.empty() || sLine.find( m_sRemInit) == 0) ;
} while ( ( m_bSkipEmptyLine && sLine.empty()) || sLine.find( m_sRemInit) == 0) ;
m_nDeltaLineUnget = m_nLineNbr - nOldLineNbr ;
}
return true ;