Program: bbtk
Module: $RCSfile: bbtkInterpreter.cxx,v $ $
Language: C++
- Date: $Date: 2008/03/18 12:51:26 $
- Version: $Revision: 1.46 $
+ Date: $Date: 2008/03/19 14:58:13 $
+ Version: $Revision: 1.47 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/**
*
*/
- void Interpreter::InterpretFile( const std::string& filename )
+ Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename )
{
bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
- // std::cout << "==========================================Entree InterpretFile ["<<filename<<"] try SwitchToFile "<<std::endl;
+
bool exm = mCommandLine;
mCommandLine = false;
+ ExitStatus status = OK;
+
try
{
SwitchToFile(filename);
-
-/*
- for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
- {
- std::cout << "A=== [" << (*it) << "]" << std::endl;
- }
-*/
bool insideComment = false; // for multiline comment
while (mFile.size()>0)
{
-/*
- for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
- {
- std::cout << "B=== [" << (*it) << "]" << std::endl;
- }
-*/
-
- //while ((mFile.size()>0) && !mFile.back()->eof() )
- //{
-// std::cout << "mFile.size() "<< mFile.size() << " mFileName.back() [" << mFileName.back() << "]" << std::endl;
- while (!mFile.back()->eof()) {
- mLine.back()++;
- char buf[500];
- mFile.back()->getline(buf,500);
- std::string str(buf);
-// std::cout << " in InterpretFile mFile.back()->getline [" << str << "]" << std::endl;
- int size=str.length();
- if ( str[ size-1 ]==13 )
+ while (!mFile.back()->eof()) {
+ mLine.back()++;
+ char buf[500];
+ mFile.back()->getline(buf,500);
+ std::string str(buf);
+ int size=str.length();
+ if ( str[ size-1 ]==13 )
{
- str.erase(size-1,1);
+ str.erase(size-1,1);
}
-
- InterpretLine(str, insideComment);
-
+
+ InterpretLine(str, insideComment);
+
}//while
- //if (mFile.size()>0)
CloseCurrentFile();
}
}
catch (QuitException e)
{
+ status = QUIT;
}
catch (bbtk::Exception e)
{
std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
std::cerr << "* LINE : "<<mLine.back()<<std::endl;
}
+ status = ERROR;
}
catch (std::exception& e)
{
if (mFileName.size()) {
std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
std::cerr << "* LINE : "<<mLine.back()<<std::endl;
- }
+ }
+ status = ERROR;
}
catch (...)
{
- std::cout << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
+ std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
if (mFileName.size()) {
- std::cout << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- std::cout << "* LINE : "<<mLine.back()<<std::endl;
+ std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ std::cerr << "* LINE : "<<mLine.back()<<std::endl;
}
+ status = ERROR;
}
CloseAllFiles();
bbtkDecTab("Interpreter",9);
mCommandLine = exm;
+
+ return status;
}
//=======================================================================
/**
*
*/
- void Interpreter::InterpretBuffer( std::stringstream* buffer )
+ Interpreter::ExitStatus
+ Interpreter::InterpretBuffer( std::stringstream* buffer )
{
bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretBuffer()"<<std::endl);
- // std::cout << "==========================================Entree InterpretFile ["<<filename<<"] try SwitchToFile "<<std::endl;
+
bool exm = mCommandLine;
mCommandLine = false;
+ ExitStatus status = OK;
+
try
{
SwitchToStream(buffer);
-
-/*
- for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
- {
- std::cout << "A=== [" << (*it) << "]" << std::endl;
- }
-*/
bool insideComment = false; // for multiline comment
while (mFile.size()>0)
{
-/*
- for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
- {
- std::cout << "B=== [" << (*it) << "]" << std::endl;
- }
-*/
-
- //while ((mFile.size()>0) && !mFile.back()->eof() )
- //{
-// std::cout << "mFile.size() "<< mFile.size() << " mFileName.back() [" << mFileName.back() << "]" << std::endl;
- while (!mFile.back()->eof()) {
- mLine.back()++;
- char buf[500];
- mFile.back()->getline(buf,500);
- std::string str(buf);
-// std::cout << " in InterpretFile mFile.back()->getline [" << str << "]" << std::endl;
- int size=str.length();
- if ( str[ size-1 ]==13 )
+ while (!mFile.back()->eof()) {
+ mLine.back()++;
+ char buf[500];
+ mFile.back()->getline(buf,500);
+ std::string str(buf);
+
+ int size=str.length();
+ if ( str[ size-1 ]==13 )
{
- str.erase(size-1,1);
+ str.erase(size-1,1);
}
-
- InterpretLine(str, insideComment);
-
- }//while
- //if (mFile.size()>0)
- CloseCurrentFile();
+
+ InterpretLine(str, insideComment);
+
+ }//while
+
+ CloseCurrentFile();
}
}
catch (QuitException e)
- {
- // std::cout << "**QuitException caught**"<<std::endl;
- }
+ {
+ status = QUIT;
+ }
catch (bbtk::Exception e)
- {
- std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
- if (mFileName.size()) {
- std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- std::cerr << "* LINE : "<<mLine.back()<<std::endl;
- }
- }
+ {
+ std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
+ if (mFileName.size())
+ {
+ std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ std::cerr << "* LINE : "<<mLine.back()<<std::endl;
+ }
+ status = ERROR;
+ }
catch (std::exception& e)
- {
- std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
- if (mFileName.size()) {
- std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- std::cerr << "* LINE : "<<mLine.back()<<std::endl;
- }
+ {
+ std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
+ if (mFileName.size())
+ {
+ std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ std::cerr << "* LINE : "<<mLine.back()<<std::endl;
+ }
+ status = ERROR;
}
catch (...)
- {
- std::cout << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
- if (mFileName.size()) {
- std::cout << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
- std::cout << "* LINE : "<<mLine.back()<<std::endl;
- }
- }
-
+ {
+ std::cerr
+ << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
+ if (mFileName.size())
+ {
+ std::cerr << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
+ std::cerr << "* LINE : "<<mLine.back()<<std::endl;
+ }
+ status = ERROR;
+ }
+
CloseAllFiles();
bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
bbtkDecTab("Interpreter",9);
-
+
mCommandLine = exm;
+ return status;
}
//=======================================================================
+ //=======================================================================
+ /// Runs the interpretation of a command
+ Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
+ {
+ bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
+
+ ExitStatus status = OK;
+ try
+ {
+ bool insideComment = false;
+ InterpretLine(line, insideComment);
+ }
+ catch (QuitException e)
+ {
+ status = QUIT;
+ }
+ catch (bbtk::Exception e)
+ {
+ std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
+ status = ERROR;
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
+ status = ERROR;
+ }
+ catch (...)
+ {
+ std::cerr
+ << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
+ status = ERROR;
+ }
+
+
+ bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretLine()"
+ <<std::endl);
+ bbtkDecTab("Interpreter",9);
+
+ return status;
+ }
+
//=======================================================================
/**
}
catch (QuitException e)
{
+ bbtkMessage("Interpreter",1,"Interpreter : Quit"<<std::endl);
again = false;
}
catch (bbtk::Exception e)