X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkInterpreter.cxx;h=8e87d7a4dd0d72222eed7f8549de2ee25639447e;hb=5c4a538667f27876a5259ce1478ff809ad2bee6f;hp=fc5f3f18638104b9d3046cc162c02de60a6c5259;hpb=cc134f89048428aca99fa855a7e1e87c815a3413;p=bbtk.git diff --git a/kernel/src/bbtkInterpreter.cxx b/kernel/src/bbtkInterpreter.cxx index fc5f3f1..8e87d7a 100644 --- a/kernel/src/bbtkInterpreter.cxx +++ b/kernel/src/bbtkInterpreter.cxx @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkInterpreter.cxx,v $ Language: C++ - Date: $Date: 2008/12/12 12:11:21 $ - Version: $Revision: 1.79 $ + Date: $Date: 2009/06/08 14:50:03 $ + Version: $Revision: 1.86 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -39,6 +39,7 @@ #include "bbtkMessageManager.h" #include "bbtkConfigurationFile.h" #include "bbtkUtilities.h" +#include "bbtkAtomicBlackBox.h" #include "bbtkWxBlackBox.h" #include #include @@ -55,7 +56,7 @@ namespace bbtk //======================================================================= Interpreter::Pointer Interpreter::New(const std::string& cpp_file) { - bbtkDebugMessage("Kernel",9,"Interpreter::New('"< Interpreter("< Interpreter(VirtualExec)"< Interpreter::~Interpreter()" < ~Interpreter()" <GetNoErrorMode()) + { + bbtkWarning("ERROR :"<GetNoErrorMode()) + { + std::string file("?"); + int line = 0; + if (mFileName.size()) { + file = mFileName.back(); + line = mLine.back(); + } + bbtkWarning("ERROR '"<GetNoErrorMode()) + { + std::string file("?"); + int line = 0; + if (mFileName.size()) { + file = mFileName.back(); + line = mLine.back(); + } + bbtkWarning("ERROR '"<GetNoErrorMode()) + { + std::string file("?"); + int line = 0; + if (mFileName.size()) { + file = mFileName.back(); + line = mLine.back(); + } + bbtkWarning("UNDEFINED ERROR " + <<"("< Interpreter::InterpretFile(\""<0) - { - 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); - } - try - { - InterpretLine(str, insideComment); - } - CATCH_MACRO; - - }//while !eof - CloseCurrentFile(); - }//while >0 - } // try + mInsideComment = false; + InterpretCurrentStreams(); + } CATCH_MACRO; - CloseAllFiles(); - bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""< Interpreter::InterpretBuffer()"<0) + mInsideComment = false; + InterpretCurrentStreams(); + } + CATCH_MACRO; + + // CloseAllFiles(); + bbtkDebugMessage("interpreter",4,"<== Interpreter::InterpretBuffer()"< Interpreter::InterpretCurrentStreams()"<0) { while (!mFile.back()->eof()) { mLine.back()++; @@ -635,21 +695,16 @@ namespace bbtk } try { - InterpretLine(str, insideComment); + DoInterpretLine(str); } CATCH_MACRO; - }//while + } CloseCurrentFile(); } - } - CATCH_MACRO; - - CloseAllFiles(); - bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"< Interpreter::InterpretLine('"< Interpreter::DoInterpretLine(\"" + < words; SplitLine(line,words); // Empty line if (words.size()<1) { - bbtkDebugDecTab("Interpreter",9); + bbtkDebugDecTab("interpreter",9); return; } // Single line comment : # or // if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') ) { - bbtkDebugDecTab("Interpreter",9); - bbtkMessage("Interpreter",9,"Comment"<SetMessageLevel(words[1],level); + } + return; + } + else + { + bbtkMessage("echo",2,line<(mFile.back()); + if (fs!=0) in_script = true; + file = mFileName.back(); + line = mLine.back(); + } + if (command.code==cBreak) + { + /* + std::cout << "BreakException(" + <Create(words[1],words[2]); break; @@ -800,7 +903,7 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) mVirtualExecuter->SetNoExecMode(true); mThrow = false; } - else if (words[1]=="freeze_no_error ") + else if (words[1]=="freeze_no_error") { mVirtualExecuter->SetNoExecMode(true); mVirtualExecuter->SetNoErrorMode(true); @@ -861,17 +964,6 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) Help(words); break; - case cMessage : - if (words.size()<3) - { - mVirtualExecuter->HelpMessages(); - } - else - { - sscanf(words[2].c_str(),"%d",&level); - mVirtualExecuter->SetMessageLevel(words[1],level); - } - break; case cGraph : Graph(words); @@ -884,8 +976,8 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) case cReset : Reset(); break; - - case cClear : + + case cClear : mVirtualExecuter->Clear(); break; @@ -910,10 +1002,6 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) GetExecuter()->UnLoadPackage(words[1]); break; - case cQuit : - throw QuitException(); - break; - case cDebug : if (words.size()==2) Debug(words[1]); else Debug(""); @@ -935,8 +1023,10 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment ) bbtkInternalError("should not reach here !!!"); } - bbtkDecTab("Interpreter",9); -} + bbtkDebugMessage("interpreter",6,"<== Interpreter::DoInterpretLine(\"" + <& tokens) + void Interpreter::SplitLine ( const std::string& str, std::vector& tokens) { - bbtkDebugMessageInc("Interpreter",9,"Interpreter::SplitLine(\""< Interpreter::SplitLine(\""< quote; @@ -963,7 +1050,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& ++i; if (i!=quote.end()) { - // bbtkDebugMessage("Interpreter",0,"\""<<*i<<"\""<& for (i=tokens.begin(); i!=tokens.end(); ++i) { - bbtkDebugMessage("Interpreter",9,"["<<*i<<"] "); + bbtkDebugMessage("interpreter",9,"--["<<*i<<"]"<& void Interpreter::Reset() { // Cannot close all files if the reset command is read from a file ! - // CloseAllFiles(); + CloseAllFiles(); mFileNameHistory.clear(); this->mVirtualExecuter->Reset(); } @@ -999,7 +1085,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& { if (mVirtualExecuter->GetNoExecMode()) return; - bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<& std::cout << *i; } std::cout << std::endl; - bbtkDebugDecTab("Interpreter",9); + bbtkDebugDecTab("interpreter",9); } */ @@ -1083,8 +1169,8 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // use ./directory/subdir/scrname.bbs // - bbtkDebugMessageInc("Interpreter",9,"Interpreter::SwitchToFile( \"" - < Interpreter::SwitchToFile( \"" + < script_paths; std::string fullPathScriptName; // full path script name @@ -1094,7 +1180,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // The following is *NOT* a debug time message : // It's a user intended message. // Please don't remove it. - bbtkMessage("Interpreter",1, + bbtkMessage("interpreter",1, "look for : [" << name << "]" << std::endl); @@ -1102,7 +1188,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& std::string upath; pkgname = Utilities::ExtractScriptName(name,upath); - bbtkMessage("Interpreter",3, + bbtkMessage("interpreter",3, "package name:[" << pkgname << "] path:[" << upath << "]" << std::endl); bool fullnameGiven = false; @@ -1119,7 +1205,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // ==== no path provided : look in root bbs path if (upath.size()==0) { - // bbtkMessage("Interpreter",1, + // bbtkMessage("interpreter",1, // LG : add all bbs path // script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() ); std::vector::const_iterator i; @@ -1183,7 +1269,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& std::vector::iterator i; for (i=script_paths.begin();i!=script_paths.end();i++) { - bbtkMessage("Interpreter",1, + bbtkMessage("interpreter",1, "--> Looking in '" << *i << "'" << std::endl); Filenames.clear(); @@ -1199,7 +1285,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& if ( (*j).substr(lgr-4, 4) != ".bbp") continue; (*stream) << "include \"" << *j << "\"\n"; - bbtkMessage("Interpreter",2," --> Found '" << *j << "'" << std::endl); + bbtkMessage("interpreter",2," --> Found '" << *j << "'" << std::endl); nbBssFiles++; } // for (std::vector... @@ -1208,12 +1294,12 @@ void Interpreter::SplitLine ( const std::string& str, std::vector& // === Result ... if (nbBssFiles==0) { - bbtkMessage("Interpreter",1, + bbtkMessage("interpreter",1, " --> No .bbp found"<< std::endl); } else { - bbtkMessage("Interpreter",1, + bbtkMessage("interpreter",1, " --> "<& // The following is *NOT* a debug time message : // It's a user intended message. // Please don't remove it. - bbtkMessage("Interpreter",2, + bbtkMessage("interpreter",2, " [" <& // The following is *NOT* a debug time message : // It's a user intended message. // Please don't remove it. - bbtkMessage("Interpreter",2, + bbtkMessage("interpreter",2, " [" <& //======================================================================= void Interpreter::SwitchToStream( std::stringstream* stream ) { - mFile.push_back(stream); + bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToStream()" + < Interpreter::LoadScript(" + <[" << fullPathScriptName + bbtkMessage("interpreter",1," -->[" << fullPathScriptName << "] found" << std::endl); mFile.push_back(s); @@ -1406,25 +1498,23 @@ void Interpreter::SwitchToStream( std::stringstream* stream ) mIncludeFileName.push_back(includeScriptName); mLine.push_back(0); - return; + return; } + //======================================================================= //======================================================================= - /** - * - */ void Interpreter::CloseCurrentFile() { - bbtkDebugMessage("Interpreter",9,"Interpreter::CloseCurrentFile()" + bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseCurrentFile()" < no file left open"< no file left open"<(mFile.back()); if (file!=0) file->close(); @@ -1435,28 +1525,25 @@ void Interpreter::SwitchToStream( std::stringstream* stream ) mIncludeFileName.pop_back(); mLine.pop_back(); - bbtkDebugMessage("Interpreter",9," Remains " + bbtkDebugMessage("interpreter",9," Remains " < Interpreter::CloseAllFiles()" <& words, CommandInfoType& info ) { - bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretCommand(...)"< Interpreter::InterpretCommand(...)"<second; - bbtkDecTab("Interpreter",9); + + bbtkDebugMessage("interpreter",9,"<== Interpreter::InterpretCommand(...)"<& words) { if (words[1]=="packages") { - GetExecuter()->GetFactory()->PrintPackages(true); + GetExecuter()->GetFactory()->PrintHelpListPackages(true); return; } try @@ -1518,7 +1604,7 @@ void Interpreter::Help(const std::vector& words) { try { - GetExecuter()->GetFactory()->HelpPackage(words[1]); + GetExecuter()->GetFactory()->PrintHelpPackage(words[1]); if ( mUser != 0 ) { std::string url = @@ -1535,7 +1621,8 @@ void Interpreter::Help(const std::vector& words) try { std::string package; - GetExecuter()->GetFactory()->HelpBlackBox(words[1],package); + GetExecuter()->GetFactory()->PrintHelpDescriptor(words[1], + package); if ( mUser != 0 ) { std::string url = @@ -1552,7 +1639,7 @@ void Interpreter::Help(const std::vector& words) { try { - GetExecuter()->ShowRelations(words[1],"0","9999"); + GetExecuter()->PrintHelpBlackBox(words[1],"0","9999"); } catch (bbtk::Exception h){ bbtkError("\""<& words) { if ( words[1]=="packages" ) { - GetExecuter()->GetFactory()->PrintPackages(true,true); + GetExecuter()->GetFactory()->PrintHelpListPackages(true,true); return; } try { - GetExecuter()->GetFactory()->HelpPackage(words[1],true); + GetExecuter()->GetFactory()->PrintHelpPackage(words[1],true); } catch (bbtk::Exception f) { @@ -1879,7 +1966,7 @@ void Interpreter::Help(const std::vector& words) //======================================================================= void Interpreter::CommandLineInterpreter() { - bbtkDebugMessageInc("Interpreter",9, + bbtkDebugMessageInc("interpreter",9, "Interpreter::CommandLineInterpreter()"<& words) mCommandLine = true; bool again = true; - bool insideComment = false; // for multiline comment + // bool insideComment = false; // for multiline comment + mInsideComment = false; do { try { std::string line; GetLineFromPrompt(line); - InterpretLine(line, insideComment); + DoInterpretLine(line); //, insideComment); } + /* catch (QuitException e) { - bbtkMessage("Interpreter",1,"Interpreter : Quit"<& words) std::cout << "Good bye !" << std::endl; - bbtkDebugDecTab("Interpreter",9); + bbtkDebugDecTab("interpreter",9); } //======================================================================= @@ -2034,7 +2124,7 @@ void Interpreter::NewGUI(const std::string& boxname, if (workspace==0) { delete s; - bbtkError("Interpreter::CreateGUI : could not access the executer currently defined complex box"); + bbtkError("interpreter::CreateGUI : could not access the executer currently defined complex box"); } @@ -2055,9 +2145,14 @@ void Interpreter::NewGUI(const std::string& boxname, // Get the input descriptor const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first); // If it is a "system" input : skip it +#ifdef USE_WXWIDGETS if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) || ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) ) continue; +#else + if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ) + continue; +#endif bool widok = true; std::string widget,adaptor; // try to find a widget adaptor @@ -2180,7 +2275,7 @@ void Interpreter::NewGUI(const std::string& boxname, { // int o = MessageManager::GetMessageLevel("debug"); // if (o<2) MessageManager::SetMessageLevel("debug",2); - mVirtualExecuter->GetFactory()->CheckPackages(); + mVirtualExecuter->GetFactory()->Check(); // MessageManager::SetMessageLevel("debug",o); } } @@ -2190,6 +2285,17 @@ void Interpreter::NewGUI(const std::string& boxname, } } //========================================================================== + + /* + //========================================================================== + // Adds a callback when 'break' command issued + void Interpreter::AddBreakObserver( BreakCallbackType c ) + { + mBreakSignal.connect(c); + } + //========================================================================== + */ + //========================================================================== std::string Interpreter::GetObjectName() const {