2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkInterpreter.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.95 $
34 =========================================================================*/
40 * \brief class Interpreter :
43 #include "bbtkInterpreter.h"
44 #include "bbtkExecuter.h"
45 #include "bbtkTranscriptor.h"
46 #include "bbtkMessageManager.h"
47 #include "bbtkConfigurationFile.h"
48 #include "bbtkUtilities.h"
49 #include "bbtkAtomicBlackBox.h"
50 #include "bbtkWxBlackBox.h"
53 #ifdef CMAKE_HAVE_TERMIOS_H
55 #define BBTK_USE_TERMIOS_BASED_PROMPT
63 //=======================================================================
64 Interpreter::Pointer Interpreter::New(const std::string& cpp_file)
66 bbtkDebugMessage("kernel",9,"Interpreter::New('"<<cpp_file<<"')"<<std::endl);
67 return MakePointer(new Interpreter(cpp_file));
69 //=======================================================================
71 //=======================================================================
72 Interpreter::Pointer Interpreter::New(VirtualExec::Pointer e)
74 bbtkDebugMessage("kernel",9,"Interpreter::New(VirtualExec)"<<std::endl);
75 return MakePointer(new Interpreter(e));
77 //=======================================================================
79 //=======================================================================
80 Interpreter::Interpreter(const std::string& cpp_file)
82 bbtkDebugMessage("object",2,"==> Interpreter("<<cpp_file<<")"<<std::endl);
83 Init(VirtualExec::Pointer(), cpp_file);
84 bbtkDebugMessage("object",2,"<== Interpreter("<<cpp_file<<")"<<std::endl);
86 //=======================================================================
88 //=======================================================================
89 Interpreter::Interpreter(VirtualExec::Pointer e)
91 bbtkDebugMessage("object",2,"==> Interpreter(VirtualExec)"<<std::endl);
93 bbtkDebugMessage("object",2,"<== Interpreter(VirtualExec)"<<std::endl);
95 //=======================================================================
97 //=======================================================================
98 void Interpreter::Init(VirtualExec::Pointer e, const std::string& cpp_file)
102 mVirtualExecuter = e;
104 else if (cpp_file.size()!=0)
106 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(bbtk::Transcriptor::New(cpp_file));
110 bbtk::Executer::Pointer exe = bbtk::Executer::New();
112 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(exe);
117 // Lock this pointer or will auto-destruct !!
118 if (!e) mVirtualExecuter->SetInterpreter(MakePointer(this,true));
121 bbtk::InterpreterVirtual::Init();
123 //=======================================================================
127 //=======================================================================
131 Interpreter::~Interpreter()
133 bbtkDebugMessage("object",2,"==> ~Interpreter()" <<std::endl);
134 mVirtualExecuter = VirtualExec::Pointer();
135 bbtkDebugMessage("object",2,"<== ~Interpreter()" <<std::endl);
137 //=======================================================================
140 //=======================================================================
141 InterpreterException::InterpreterException( const std::string& message,
143 const std::string& script_file,
146 : Exception("interpreter",0,message),
147 mInScriptFile(in_script_file),
148 mScriptFile(script_file),
149 mScriptLine(script_line)
152 //=======================================================================
153 //=======================================================================
154 InterpreterException::InterpreterException( const Exception& excep,
156 const std::string& script_file,
160 mInScriptFile(in_script_file),
161 mScriptFile(script_file),
162 mScriptLine(script_line)
165 //=======================================================================
168 //=======================================================================
169 void Interpreter::CatchInterpreterException( const InterpreterException& e )
171 if (GetExecuter()->GetNoErrorMode())
173 bbtkWarning("ERROR :"<<e.GetErrorMessage()
174 <<" ("<<e.GetScriptFile()<<":"<<e.GetScriptLine()
180 bbtk::InterpreterVirtual::CatchInterpreterException( e );
182 //=======================================================================
184 //=======================================================================
185 void Interpreter::CatchBbtkException( const bbtk::Exception& e )
187 if (GetExecuter()->GetNoErrorMode())
189 std::string file("?");
191 if (mFileName.size()) {
192 file = mFileName.back();
195 bbtkWarning("ERROR '"<<e.GetErrorMessage()
196 <<"' ("<<file<<":"<<line<<") skipped");
201 bbtk::InterpreterVirtual::CatchBbtkException( e );
203 //=======================================================================
205 //=======================================================================
206 void Interpreter::CatchStdException( const std::exception& e )
208 if (GetExecuter()->GetNoErrorMode())
210 std::string file("?");
212 if (mFileName.size())
214 file = mFileName.back();
217 bbtkWarning("ERROR '"<<e.what() <<"' ("<<file<<":"<<line<<") skipped");
220 bbtk::InterpreterVirtual::CatchStdException( e );
222 //=======================================================================
224 //=======================================================================
225 void Interpreter::CatchUnknownException()
227 if (GetExecuter()->GetNoErrorMode())
229 std::string file("?");
231 if (mFileName.size())
233 file = mFileName.back();
236 bbtkWarning("UNDEFINED ERROR " <<"("<<file<<":"<<line<<") skipped");
240 bbtk::InterpreterVirtual::CatchUnknownException( );
242 //=======================================================================
244 //=======================================================================
246 #define CATCH_MACRO \
247 catch (InterpreterException e) \
249 CatchInterpreterException(e); \
251 catch (bbtk::Exception e) \
253 CatchBbtkException(e); \
255 catch (std::exception& e) \
257 CatchStdException(e); \
261 CatchUnknownException(); \
263 //=======================================================================
266 //=======================================================================
267 Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename, bool source )
269 bbtkDebugMessage("interpreter",4,"==> Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
271 bool exm = mCommandLine;
272 mCommandLine = false;
276 mStatus = Interpreter_OK;
277 SwitchToFile(filename,source);
278 mInsideComment = false;
279 InterpretCurrentStreams();
283 bbtkDebugMessage("interpreter",4,
284 "<== Interpreter::InterpretFile(\""
285 <<filename<<"\")"<<std::endl);
292 //=======================================================================
295 //=======================================================================
296 Interpreter::ExitStatus
297 Interpreter::InterpretBuffer( std::stringstream* buffer )
299 bbtkDebugMessage("interpreter",4,"==> Interpreter::InterpretBuffer()"<<std::endl);
301 bool exm = mCommandLine;
302 mCommandLine = false;
306 mStatus = Interpreter_OK;
307 SwitchToStream(buffer);
308 mInsideComment = false;
309 InterpretCurrentStreams();
314 bbtkDebugMessage("interpreter",4,"<== Interpreter::InterpretBuffer()"<<std::endl);
320 //=======================================================================
322 //=======================================================================
323 /// Interprets the currently open streams
324 Interpreter::ExitStatus Interpreter::InterpretCurrentStreams()
326 bbtkDebugMessage("interpreter",4,
327 "==> Interpreter::InterpretCurrentStreams()"<<std::endl);
329 while (mFile.size()>0)
331 while (!mFile.back()->eof()) {
334 mFile.back()->getline(buf,500);
335 std::string str(buf);
336 //size 0 JCP 21-09-2009
337 int size=str.length();
339 if ( str[ size-1 ]==13 )
345 DoInterpretLine(str);
353 bbtkDebugMessage("interpreter",4,
354 "<== Interpreter::InterpretCurrentStreams()"<<std::endl);
358 //=======================================================================
360 //=======================================================================
361 /// Runs the interpretation of a command
362 Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
364 bbtkDebugMessage("interpreter",5,"==> Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
368 mStatus = Interpreter_OK;
369 mInsideComment = false;
370 //std::cout<<"JCP bbtkInterpreter.cxx Interpreter::InterpretLine("<<std::endl;
371 DoInterpretLine(line );
376 bbtkDebugMessage("interpreter",5,"<== Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
380 //=======================================================================
384 void Interpreter::commandNew(const std::string &boxType,const std::string &boxName) //virtual
386 mVirtualExecuter->Create(boxType,boxName);
389 void Interpreter::commandDelete(const std::string &boxName) //virtual
391 mVirtualExecuter->Destroy(boxName);
394 void Interpreter::commandConnection(const std::string &nodeFrom,const std::string &outputLabel,const std::string &nodeTo,const std::string &inputLabel) //virtual
396 mVirtualExecuter->Connect(nodeFrom,outputLabel,nodeTo,inputLabel);
399 void Interpreter::commandPackage(const std::string &packageName) //virtual
401 mVirtualExecuter->BeginPackage(packageName);
404 void Interpreter::commandEndPackage() //virtual
406 mVirtualExecuter->EndPackage();
409 void Interpreter::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename) //virtual
411 mVirtualExecuter->Define(name,pack,scriptfilename);
414 void Interpreter::commandEndDefine() //virtual
416 mVirtualExecuter->EndDefine();
419 void Interpreter::commandKind(const std::string &kind) //virtual
421 mVirtualExecuter->Kind(kind);
424 void Interpreter::commandPrint(const std::string &value) //virtual
426 mVirtualExecuter->Print(value);
430 void Interpreter::commandExec(const std::string &word) //virtual
434 mVirtualExecuter->SetNoExecMode(true);
437 else if (word=="freeze_no_error")
439 mVirtualExecuter->SetNoExecMode(true);
440 mVirtualExecuter->SetNoErrorMode(true);
443 else if (word=="unfreeze")
445 mVirtualExecuter->SetNoExecMode(false);
446 mVirtualExecuter->SetNoErrorMode(false);
450 mVirtualExecuter->Execute(word);
455 void Interpreter::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string &help) //virtual
457 mVirtualExecuter->DefineInput(name,box,input,help);
460 void Interpreter::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string &help) //virtual
462 mVirtualExecuter->DefineOutput(name,box,output,help);
465 void Interpreter::commandSet(const std::string &box,const std::string &input,const std::string &value) //virtual
467 mVirtualExecuter->Set(box,input,value);
470 void Interpreter::commandAuthor(const std::string &author) //virtual
472 mVirtualExecuter->Author(author);
475 void Interpreter::commandCategory(const std::string &categorytype) //virtual
477 mVirtualExecuter->Category(categorytype);
480 void Interpreter::commandDescription(const std::string &description) //virtual
482 mVirtualExecuter->Description(description);
486 void Interpreter::commandClear() //virtual
488 mVirtualExecuter->Clear();
491 void Interpreter::commandInclude(const std::string &word, bool ok) //virtual
493 // if 'source' was given (words.size()==3) then tell to set the
494 // source file name of the current complex box with the full file name included
497 InterpretFile(word, ok );
501 SwitchToFile(word , ok );
506 void Interpreter::commandLoad(const std::string &packageName) //virtual
508 GetExecuter()->LoadPackage(packageName);
511 void Interpreter::commandUnload(const std::string &packageName) //virtual
513 GetExecuter()->UnLoadPackage(packageName);
516 void Interpreter::commandBreak() //virtual
519 std::cout << "BreakException("
522 <<line<<")"<<std::endl;
524 bbtkError("break");//,in_script,file,line);
525 // throw BreakException(in_script,file,line);
528 void Interpreter::commandQuit() //virtual
530 bbtkError("quit");//,in_script,file,line);
531 //throw QuitException(in_script,file,line);
534 void Interpreter::commandMessage() //virtual
536 mVirtualExecuter->HelpMessages();
539 void Interpreter::commandMessage(const std::string &kind,const std::string &levelstr) //virtual
542 sscanf(levelstr.c_str(),"%d",&level);
543 mVirtualExecuter->SetMessageLevel(kind,level);
549 //=======================================================================
550 void Interpreter::DoInterpretLine( const std::string& line ) //virtual
552 bbtkDebugMessage("interpreter",6,"==> Interpreter::DoInterpretLine(\""
553 <<line<<"\")"<<std::endl);
554 std::vector<std::string> words;
555 SplitLine(line,words);
560 bbtkDebugDecTab("interpreter",9);
564 // Single line comment : # or //
565 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
567 bbtkDebugDecTab("interpreter",9);
568 bbtkMessage("interpreter",9,"Comment"<<std::endl);
572 // Multi line comment ( / * ... * / ) -delimiters on different lines !- <<<<<<< / * * /
574 if (words[0][0]=='/' && words[0][1]=='*')
576 bbtkDebugDecTab("interpreter",9);
577 bbtkMessage("interpreter",9,"In multiline comment"<<std::endl);
578 mInsideComment = true;
582 if (words[0][0]=='*' && words[0][1]=='/')
584 bbtkDebugDecTab("interpreter",9);
585 bbtkMessage("interpreter",9,"Out multiline comment"<<std::endl);
586 if ( !mInsideComment ) {
587 bbtkDebugDecTab("interpreter",9);
588 bbtkMessage("interpreter",9,"Comment mismatch : '* /' with no matching '/ *'"<<std::endl); <<<<<<<<< * / / *
590 mInsideComment = false;
596 bbtkDebugDecTab("interpreter",9);
597 bbtkMessage("interpreter",9,"Multiline Comment"<<std::endl);
602 CommandInfoType command;
603 InterpretCommand(words,command);
604 //std::cout<<"JCP bbtkInterpreter command.keyword ="<<command.keyword<<std::endl;
605 bbtkDebugMessage("interpreter",9,
606 "Command='"<<command.keyword
607 <<"' code="<<command.code<<std::endl);
609 std::string left,right,left2,right2;
610 std::string filename;
614 if (command.code==cMessage)
619 //EED Borrame mVirtualExecuter->HelpMessages();
623 commandMessage(words[1],words[2]);
624 //EED Borrame sscanf(words[2].c_str(),"%d",&level);
625 //EED Borrame mVirtualExecuter->SetMessageLevel(words[1],level);
631 bbtkMessage("echo",2,line<<std::endl);
634 // break and quit commands
635 if ((command.code==cBreak) || (command.code==cQuit))
637 bool in_script = false;
638 std::string file("");
641 if (mFileName.size())
643 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
644 if (fs!=0) in_script = true;
645 file = mFileName.back();
648 if (command.code==cBreak)
650 // std::cout << "BreakException("
653 // <<line<<")"<<std::endl;
655 //EED Borrame bbtkError("break");//,in_script,file,line);
656 // throw BreakException(in_script,file,line);
661 //EED Borrame bbtkError("quit");//,in_script,file,line);
662 //throw QuitException(in_script,file,line);
666 //std::cout<<" mVirtualExecuter->Create(words[1],words[2]); "<<line<<std::endl;
669 switch (command.code)
672 commandNew(words[1],words[2]);
673 //EED Borrame mVirtualExecuter->Create(words[1],words[2]);
677 commandDelete(words[1]);
678 //EED Borrame mVirtualExecuter->Destroy(words[1]);
682 Utilities::SplitAroundFirstDot(words[1],left,right);
683 Utilities::SplitAroundFirstDot(words[2],left2,right2);
684 commandConnection(left,right,left2,right2);
685 //EED Borrame mVirtualExecuter->Connect(left,right,left2,right2);
689 commandPackage(words[1]);
690 //EED Borrame mVirtualExecuter->BeginPackage(words[1]);
695 //EED Borrame mVirtualExecuter->EndPackage();
699 if (mFileName.size()>0)
701 //??? commandDefine(????);
702 filename = mFileName.back(); //mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
706 commandDefine(words[1],"",filename);
707 //EED Borrame mVirtualExecuter->Define(words[1],"",filename);
711 commandDefine(words[1],words[2],filename);
712 //EED Borrame mVirtualExecuter->Define(words[1],words[2],filename);
718 //EED Borrame mVirtualExecuter->EndDefine();
722 commandKind(words[1]);
723 //EED Borrame mVirtualExecuter->Kind(words[1]);
727 commandPrint(words[1]);
728 //EED Borrame mVirtualExecuter->Print(words[1]);
732 commandExec(words[1]);
733 //EED Borrame if (words[1]=="freeze")
735 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
736 //EED Borrame mThrow = false;
738 //EED Borrame else if (words[1]=="freeze_no_error")
740 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
741 //EED Borrame mVirtualExecuter->SetNoErrorMode(true);
742 //EED Borrame mThrow = false;
744 //EED Borrame else if (words[1]=="unfreeze")
746 //EED Borrame mVirtualExecuter->SetNoExecMode(false);
747 //EED Borrame mVirtualExecuter->SetNoErrorMode(false);
751 //EED Borrame mVirtualExecuter->Execute(words[1]);
757 Utilities::SplitAroundFirstDot(words[2],left,right);
758 commandInput(words[1],left,right,words[3]);
759 //EED Borrame mVirtualExecuter->DefineInput(words[1],left,right,words[3]);
763 Utilities::SplitAroundFirstDot(words[2],left,right);
764 commandOutput(words[1],left,right,words[3]);
765 //EED Borrame mVirtualExecuter->DefineOutput(words[1],left,right,words[3]);
769 Utilities::SplitAroundFirstDot(words[1],left,right);
770 commandSet(left,right,words[2]);
771 //EED Borrame mVirtualExecuter->Set(left,right,words[2]);
775 commandAuthor(words[1]);
776 //EED Borrame mVirtualExecuter->Author(words[1]);
780 commandNewGUI(words[1],words[2]);
784 commandCategory(words[1]);
785 //EED Borrame mVirtualExecuter->Category(words[1]);
790 commandIndex("tmp_index.html");
791 else if (words.size()==2)
792 commandIndex(words[1]);
793 else if (words.size()==3)
794 commandIndex(words[1],words[2]);
798 commandDescription(words[1]);
799 //EED Borrame mVirtualExecuter->Description(words[1]);
821 //EED Borrame mVirtualExecuter->Clear();
825 commandInclude( words[1] , (words.size()==3) );
826 //EED Borrame // if 'source' was given (words.size()==3) then tell to set the
827 //EED Borrame // source file name of the current complex box with the full file name included
828 //EED Borrame if (mCommandLine)
830 //EED Borrame InterpretFile(words[1],(words.size()==3));
831 //EED Borrame } else{
832 //EED Borrame SwitchToFile(words[1],(words.size()==3) );
837 commandLoad( words[1] );
838 //EED Borrame GetExecuter()->LoadPackage(words[1]);
842 commandUnload( words[1] );
843 //EED Borrame GetExecuter()->UnLoadPackage(words[1]);
847 if (words.size()==2) commandDebug(words[1]);
848 else commandDebug("");
853 // if (words.size() == 2)
855 // if (words[1]=="freeze") mVirtualExecuter->SetNoExecMode(true);
856 // else if (words[1]=="unfreeze") mVirtualExecuter->SetNoExecMode(false);
860 // mVirtualExecuter->SetWorkspaceName(words[2]);
865 bbtkInternalError("should not reach here !!!");
868 bbtkDebugMessage("interpreter",6,"<== Interpreter::DoInterpretLine(\""
869 <<line<<"\")"<<std::endl);
872 //=======================================================================
877 //=======================================================================
878 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
880 bbtkDebugMessage("interpreter",9,"==> Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
882 std::string delimiters = "\"";
883 std::vector<std::string> quote;
884 Utilities::SplitString(str,delimiters,quote);
887 std::vector<std::string>::iterator i;
888 for (i=quote.begin(); i!=quote.end(); )
890 Utilities::SplitString(*i,delimiters,tokens);
894 // bbtkDebugMessage("interpreter",0,"\""<<*i<<"\""<<std::endl);
895 tokens.push_back(*i);
900 for (i=tokens.begin(); i!=tokens.end(); ++i)
902 bbtkDebugMessage("interpreter",9,"--["<<*i<<"]"<<std::endl);
904 bbtkDebugMessage("interpreter",9,"<== Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
907 //=======================================================================
911 //=======================================================================
912 void Interpreter::commandReset() // virtual
914 // Cannot close all files if the reset command is read from a file !
916 mFileNameHistory.clear();
917 this->mVirtualExecuter->Reset();
919 //=======================================================================
921 //=======================================================================
926 void Interpreter::Print( const std::string& str)
928 if (mVirtualExecuter->GetNoExecMode()) return;
930 bbtkDebugMessageInc("interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
933 // InterpretLine ("load std")
934 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
935 // InterpretLine("new Print _P_")
936 // InterpretLine("connect _C_.Out _P_.In")
940 std::vector<std::string> chains;
941 std::string delimiters("$");
943 // Skip delimiters at beginning.
944 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
946 if (lastPos>0) is_text = false;
948 // Find first delimiter.
949 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
951 while (std::string::npos != pos || std::string::npos != lastPos)
955 // Found a text token, add it to the vector.
956 chains.push_back(str.substr(lastPos, pos - lastPos));
957 // std::string token = str.substr(lastPos, pos - lastPos)
958 // InterpretLine("set _C_.In%num% %token%")
964 // is an output (between $$) : decode
965 std::string tok,box,output;
966 tok = str.substr(lastPos, pos - lastPos);
967 Utilities::SplitAroundFirstDot(tok,box,output);
968 chains.push_back( mVirtualExecuter->Get(box,output) );
970 // InterpretLine("connect %tok% _C_.In%num%")
973 // Skip delimiters. Note the "not_of"
974 lastPos = str.find_first_not_of(delimiters, pos);
975 // Find next delimiter
976 pos = str.find_first_of(delimiters, lastPos);
981 // InterpretLine("exec _P_")
982 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
984 std::vector<std::string>::iterator i;
985 for (i= chains.begin(); i!=chains.end(); ++i)
988 Utilities::SubsBackslashN(*i);
991 std::cout << std::endl;
992 bbtkDebugDecTab("interpreter",9);
996 //=======================================================================
1001 // =========================================================================
1002 void Interpreter::SwitchToFile( const std::string& name , bool source )
1004 // Note : in the following :
1005 // name : the user supplied name
1006 // - abreviated name e.g. scr scr.bbs
1007 // - relative full name e.g. ./scr.bbs ../../scr.bbs
1008 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
1009 // same for Windows, with c:, d: ...
1011 // use ./directory/subdir/scrname.bbs
1014 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToFile( \""
1015 <<name<<"\")"<<std::endl);
1017 std::vector<std::string> script_paths;
1018 std::string fullPathScriptName; // full path script name
1019 std::string pkgname; // e.g. <scriptname>.bbs
1020 std::vector<std::string> Filenames;
1022 // The following is *NOT* a debug time message :
1023 // It's a user intended message.
1024 // Please don't remove it.
1025 bbtkMessage("interpreter",1,
1026 "look for : [" << name
1027 << "]" << std::endl);
1031 pkgname = Utilities::ExtractScriptName(name,upath);
1033 bbtkMessage("interpreter",3,
1034 "package name:[" << pkgname
1035 << "] path:[" << upath << "]" << std::endl);
1036 bool fullnameGiven = false;
1037 bool foundFile = false;
1039 // ==== "*" provided : load all scripts in given path
1040 // relative (e.g. std/boxes/ *) or absolute <<<<<<<< / *
1044 std::stringstream* stream = new std::stringstream;
1045 //if (upath.size()!=0) // avoid troubles for "*"
1047 // ==== no path provided : look in root bbs path
1048 if (upath.size()==0)
1050 // bbtkMessage("interpreter",1,
1051 // LG : add all bbs path
1052 // script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1053 std::vector<std::string>::const_iterator i;
1054 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1055 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1058 script_paths.push_back(*i);
1061 // ==== absolute path provided
1062 else if (upath[0]=='/' || upath[1] == ':' )
1064 if ( Utilities::IsDirectory( upath ) )
1066 script_paths.push_back(upath);
1070 bbtkError("'"<<upath<<"' : directory does not exist");
1073 // ==== relative path provided : search all bbs path appended with
1074 // the relative path provided
1077 std::vector<std::string>::const_iterator i;
1078 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1079 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1082 std::string full_path(*i);
1083 // we *really* want '.' to be the current working directory
1084 if (full_path == ".")
1086 char buf[2048]; // for getcwd
1087 char * currentDir = getcwd(buf, 2048);
1088 std::string cwd(currentDir);
1089 full_path = currentDir;
1092 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1095 if ( Utilities::IsDirectory( full_path ) )
1097 script_paths.push_back(full_path);
1100 if (script_paths.empty())
1102 bbtkError("no '"<<upath<<"' subdir found in search paths"
1108 // === search paths list complete : now explore it
1110 // ==== relative name, iterate + load all .bbs/.bbp files
1111 std::vector<std::string>::iterator i;
1112 for (i=script_paths.begin();i!=script_paths.end();i++)
1114 bbtkMessage("interpreter",1,
1115 "--> Looking in '" << *i << "'" << std::endl);
1119 Utilities::Explore(*i, false, Filenames);
1121 for (std::vector<std::string>::iterator j = Filenames.begin();
1122 j!= Filenames.end(); ++j)
1124 int lgr = (*j).size();
1125 if (lgr < 5) continue;
1126 // ignore non .bbp file
1127 if ( (*j).substr(lgr-4, 4) != ".bbp") continue;
1129 (*stream) << "include \"" << *j << "\"\n";
1130 bbtkMessage("interpreter",2," --> Found '" << *j << "'" << std::endl);
1133 } // for (std::vector...
1134 } // for (i=script_...
1139 bbtkMessage("interpreter",1,
1140 " --> No .bbp found"<< std::endl);
1144 bbtkMessage("interpreter",1,
1145 " --> "<<nbBssFiles<<" .bbp found"<< std::endl);
1146 SwitchToStream(stream);
1150 //=============== end pkgname=="*" ===========
1153 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1154 // (not only a plain script name)
1155 // we trust him, and try to expland the directory name
1156 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1158 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1161 // ===========================================================check user supplied location
1162 fullnameGiven = true;
1164 fullPathScriptName = Utilities::ExpandLibName(name, false);
1166 // allow user to always forget ".bbs"
1167 int l = fullPathScriptName.size();
1171 if ((fullPathScriptName.substr(l-4, 4) != ".bbs")&&
1172 (fullPathScriptName.substr(l-4, 4) != ".bbp"))
1174 std::string tfullPathScriptName = fullPathScriptName + ".bbs";
1175 if ( Utilities::FileExists(tfullPathScriptName) )
1177 fullPathScriptName = tfullPathScriptName;
1182 tfullPathScriptName = fullPathScriptName + ".bbp";
1183 if ( Utilities::FileExists(tfullPathScriptName) )
1185 fullPathScriptName = tfullPathScriptName;
1192 if ( Utilities::FileExists(fullPathScriptName) )
1200 // =============================== iterate on the paths
1202 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1204 std::vector<std::string>::iterator i;
1205 for (i=script_paths.begin();i!=script_paths.end();++i)
1208 // we *really* want '.' to be the current working directory
1211 char buf[2048]; // for getcwd
1212 char * currentDir = getcwd(buf, 2048);
1213 std::string cwd(currentDir);
1217 std::string tfullPathScriptName = Utilities::MakePkgnameFromPath(path, name, false);
1218 //Addition JCP tfullPathScriptName.size()>=4
1219 if(tfullPathScriptName.size()>=4){
1220 if (tfullPathScriptName.substr(tfullPathScriptName.size()-4, 3)==".bb")
1222 fullPathScriptName = tfullPathScriptName;
1223 if ( ! Utilities::FileExists(fullPathScriptName) )
1225 // The following is *NOT* a debug time message :
1226 // It's a user intended message.
1227 // Please don't remove it.
1228 bbtkMessage("interpreter",2,
1229 " [" <<fullPathScriptName <<"] : does not exist"
1231 continue; // try next path
1233 bbtkMessage("interpreter",2,
1234 " [" <<fullPathScriptName
1235 <<"] : found" <<std::endl);
1237 break; // a script was found; we stop iterating
1241 fullPathScriptName = tfullPathScriptName + ".bbs";
1242 // Check if library exists
1243 if ( ! Utilities::FileExists(fullPathScriptName) )
1245 fullPathScriptName = tfullPathScriptName + ".bbp";
1246 if ( ! Utilities::FileExists(fullPathScriptName) )
1248 // The following is *NOT* a debug time message :
1249 // It's a user intended message.
1250 // Please don't remove it.
1251 bbtkMessage("interpreter",2,
1252 " [" <<tfullPathScriptName <<".bbs/.bbp] : do not exist"
1254 continue; // try next path
1257 bbtkMessage("interpreter",2,
1258 " [" <<fullPathScriptName
1259 <<"] : found" <<std::endl);
1261 break; // a script was found; we stop iterating
1264 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1270 if(fullPathScriptName == "")
1271 bbtkError("Path ["<<upath<<"] doesn't exist");
1273 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1275 bbtkError("No ["<<pkgname<<".bbs/.bbp] script found");
1280 LoadScript(fullPathScriptName,name);
1281 if (source) SetCurrentFileName(fullPathScriptName);
1286 //=======================================================================
1289 //=======================================================================
1290 void Interpreter::SetCurrentFileName(const std::string &fullPathScriptName) // virtual
1292 GetExecuter()->SetCurrentFileName(fullPathScriptName);
1294 //=======================================================================
1297 void Interpreter::SetTypeOfScript_Application()
1299 GetExecuter()->SetTypeOfScript_Application();
1305 //=======================================================================
1306 void Interpreter::SwitchToStream( std::stringstream* stream )
1308 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToStream()"
1310 mFile.push_back(stream);
1311 std::ostringstream buffer_name;
1313 buffer_name << "buffer_" ;
1315 if (mFileName.size()>0 )
1317 buffer_name << mFileName.back() << "_" << mLine.back();
1319 mFileName.push_back(buffer_name.str());
1320 mIncludeFileName.push_back(buffer_name.str());
1323 //=======================================================================
1327 //=======================================================================
1328 void Interpreter::LoadScript( std::string fullPathScriptName,
1329 std::string includeScriptName)
1331 bbtkDebugMessage("interpreter",4,"==> Interpreter::LoadScript("
1332 <<fullPathScriptName<<")"
1335 Utilities::replace( fullPathScriptName ,
1336 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1338 if (find(mFileNameHistory.begin(),
1339 mFileNameHistory.end(),
1340 fullPathScriptName)!=mFileNameHistory.end())
1346 s = new std::ifstream;
1347 s->open(fullPathScriptName.c_str());
1350 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1354 bbtkMessage("interpreter",1," -->[" << fullPathScriptName
1355 << "] found" << std::endl);
1358 mFileName.push_back(fullPathScriptName);
1359 mFileNameHistory.push_back(fullPathScriptName);
1360 mIncludeFileName.push_back(includeScriptName);
1365 //=======================================================================
1369 //=======================================================================
1370 void Interpreter::CloseCurrentFile()
1372 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseCurrentFile()"
1375 if (mFile.size()==0)
1377 bbtkDebugMessage("interpreter",9," -> no file left open"<<std::endl);
1381 bbtkDebugMessage("interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1383 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1384 if (file!=0) file->close();
1386 delete mFile.back();
1388 mFileName.pop_back();
1389 mIncludeFileName.pop_back();
1392 bbtkDebugMessage("interpreter",9," Remains "
1394 <<" open"<<std::endl);
1395 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseCurrentFile()"
1398 //=======================================================================
1400 //=======================================================================
1401 void Interpreter::CloseAllFiles()
1403 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseAllFiles()"
1406 while (mFile.size() != 0)
1410 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseAllFiles()"
1413 //=======================================================================
1416 //=======================================================================
1417 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1418 CommandInfoType& info )
1420 bbtkDebugMessage("interpreter",9,"==> Interpreter::InterpretCommand(...)"<<std::endl);
1422 // searches the command keyword
1423 CommandDictType::iterator c;
1424 c = mCommandDict.find(words[0]);
1425 if ( c == mCommandDict.end() ) {
1426 bbtkError(words[0]<<" : unknown command");
1429 // tests the number of args
1430 if ( ( ((int)words.size())-1 < c->second.argmin ) ||
1431 ( ((int)words.size())-1 > c->second.argmax ) )
1433 commandHelp(words[0]);
1434 bbtkError(words[0]<<" : wrong number of arguments");
1436 //std::cout<<"Interpreter::InterpretCommand( const std::vector<std::string>& words,"<<std::endl;
1439 bbtkDebugMessage("interpreter",9,"<== Interpreter::InterpretCommand(...)"<<std::endl);
1442 //=======================================================================
1446 //=======================================================================
1447 /// Displays help on all the commands
1448 void Interpreter::commandHelp(const std::vector<std::string>& words)
1450 unsigned int nbarg = words.size()-1;
1458 if (words[1]=="packages")
1460 GetExecuter()->GetFactory()->PrintHelpListPackages(true);
1465 commandHelp(words[1]);
1467 catch (bbtk::Exception e)
1471 GetExecuter()->GetFactory()->PrintHelpPackage(words[1]);
1475 ConfigurationFile::GetInstance().Get_doc_path();
1476 url += "/bbdoc/" + words[1] + "/index.html";
1477 if (Utilities::FileExists(url))
1479 mUser->InterpreterUserViewHtmlPage(url);
1483 catch (bbtk::Exception f)
1487 std::string package;
1488 GetExecuter()->GetFactory()->PrintHelpDescriptor(words[1],
1493 ConfigurationFile::GetInstance().Get_doc_path();
1494 url += "/bbdoc/" + package + "/index.html";
1495 if (Utilities::FileExists(url))
1497 url += "#" + words[1];
1498 mUser->InterpreterUserViewHtmlPage(url);
1502 catch (bbtk::Exception g)
1506 GetExecuter()->PrintHelpBlackBox(words[1],"0","9999");
1508 catch (bbtk::Exception h){
1509 bbtkError("\""<<words[1].c_str()
1510 <<"\" is not a known command, package, black box type or black box name");
1518 if (words[2]=="all")
1520 if ( words[1]=="packages" )
1522 GetExecuter()->GetFactory()->PrintHelpListPackages(true,true);
1527 GetExecuter()->GetFactory()->PrintHelpPackage(words[1],true);
1529 catch (bbtk::Exception f)
1535 commandHelp(words[0]);
1536 bbtkError(words[0]<<" : syntax error");
1541 bbtkError("Should not reach here !!!");
1544 //=======================================================================
1546 //===================================================================
1547 /// Displays the Configuration
1548 void Interpreter::commandConfig() const
1550 ConfigurationFile::GetInstance().GetHelp(1);
1552 //===================================================================
1554 //=======================================================================
1555 /// Displays help on all the commands
1556 void Interpreter::HelpCommands()
1558 std::cout << "Available commands :" << std::endl;
1559 CommandDictType::iterator i;
1560 for ( i = mCommandDict.begin();
1561 i != mCommandDict.end();
1563 std::cout << " " << i->first << std::endl;
1564 // std::cout << " usage : " << i->second.syntax << std::endl;
1565 // std::cout << " " << i->second.help << std::endl;
1569 //=======================================================================
1573 //=======================================================================
1574 /// Displays help on a particular commands
1575 void Interpreter::commandHelp(const std::string& s)
1577 CommandDictType::iterator c;
1578 c = mCommandDict.find(s);
1579 if ( c == mCommandDict.end() ) {
1580 bbtkError(s<<" : Unknown command");
1582 // std::cout << " " << s << " : "<< std::endl;
1583 // CommandParamDictType::iterator i;
1584 // for ( i = c->second.begin();
1585 // i != c->second.end();
1587 std::cout << " usage : " << c->second.syntax << std::endl;
1588 std::cout << " " << c->second.help << std::endl;
1591 //=======================================================================
1594 //=======================================================================
1595 /// Fills the vector commands with the commands which
1596 /// have the first n chars of buf for prefix
1597 /// TODO : skip initial spaces in buf and also return the position of first
1598 /// non blank char in buf
1599 void Interpreter::FindCommandsWithPrefix( char* buf,
1601 std::vector<std::string>& commands )
1603 CommandDictType::const_iterator i;
1604 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1606 if ((i->first).find(buf,0,n) == 0)
1607 commands.push_back(i->first);
1610 //=======================================================================
1615 //=======================================================================
1616 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1618 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1619 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1621 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1622 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1623 // E.G. STORE THIS IN bbtk_config.xml
1624 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1625 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1626 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1627 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1628 #define BBTK_BACKSPACE_KBCODE 0x00000008
1629 #define BBTK_DEL_KBCODE 0x0000007F
1630 #define BBTK_SPACE_KBCODE 0x00000020
1632 //=======================================================================
1633 void Interpreter::GetLineFromPrompt(std::string& s)
1638 unsigned int MAX_LINE_SIZE = 160;
1639 unsigned int MAX_HISTORY_SIZE = 100;
1641 char* newline = new char[MAX_LINE_SIZE];
1642 memset(newline,0,MAX_LINE_SIZE);
1643 char* histline = new char[MAX_LINE_SIZE];
1644 memset(histline,0,MAX_LINE_SIZE);
1646 char* line = newline;
1647 unsigned int hist = mHistory.size();
1653 read ( STDIN_FILENO, &c, 4) ;
1655 bbtkDebugMessage("debug",9,"[0x"<<std::hex<<c<<"]\n");
1657 // Printable character
1658 if ( (ind<MAX_LINE_SIZE-1) &&
1659 ( c >= BBTK_SPACE_KBCODE ) &&
1660 ( c < BBTK_DEL_KBCODE ))
1668 // delete the unused line
1674 // empty lines are not stored in from history
1677 // if history too long : delete oldest command
1678 if (mHistory.size()>MAX_HISTORY_SIZE)
1680 delete mHistory.front();
1681 mHistory.pop_front();
1683 mHistory.push_back(line);
1688 else if ( (ind>0) &&
1689 ((c == BBTK_BACKSPACE_KBCODE) ||
1690 (c == BBTK_DEL_KBCODE)) )
1698 // TODO : Command completion
1699 std::vector<std::string> commands;
1700 FindCommandsWithPrefix( line,ind,commands);
1701 if (commands.size()==1)
1703 std::string com = *commands.begin();
1704 for (; ind<com.size(); ++ind)
1706 PrintChar(com[ind]);
1712 else if (commands.size()>1)
1714 std::vector<std::string>::iterator i;
1716 for (i=commands.begin();i!=commands.end();++i)
1718 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1721 write(STDOUT_FILENO,"\n> ",3);
1722 //for (int j=0;j<ind;++j)
1724 write(STDOUT_FILENO,line,ind);
1728 // Arrow up : back in history
1729 else if (c==BBTK_UP_ARROW_KBCODE)
1733 // erase current line
1734 while (ind--) BackSpace();
1738 strcpy(histline,mHistory[hist]);
1742 write(STDOUT_FILENO,line,ind);
1745 // Arrow down : down in history
1746 else if (c==BBTK_DOWN_ARROW_KBCODE)
1748 if (hist<mHistory.size()-1)
1750 // erase current line
1751 while (ind--) BackSpace();
1755 strcpy(histline,mHistory[hist]);
1759 write(STDOUT_FILENO,line,ind);
1761 // end of history : switch back to newline
1762 else if (hist==mHistory.size()-1)
1764 // erase current line
1765 while (ind--) BackSpace();
1772 write(STDOUT_FILENO,line,ind);
1776 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1778 PrintChar(line[ind]);
1783 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1791 write(STDOUT_FILENO,"\n\r",2);
1799 //=======================================================================
1800 void Interpreter::GetLineFromPrompt(std::string& s)
1826 //=======================================================================
1837 //=======================================================================
1838 void Interpreter::CommandLineInterpreter()
1840 bbtkDebugMessageInc("interpreter",9,
1841 "Interpreter::CommandLineInterpreter()"<<std::endl);
1843 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1844 // Initialise the tty in non canonical mode with no echo
1845 // oter remembers the previous settings to restore them after
1846 struct termios ter,oter;
1849 ter.c_lflag &= ~ECHO;
1850 ter.c_lflag &= ~ICANON;
1853 tcsetattr(0,TCSANOW,&ter);
1856 mCommandLine = true;
1858 // bool insideComment = false; // for multiline comment
1859 mInsideComment = false;
1865 GetLineFromPrompt(line);
1866 DoInterpretLine(line); //, insideComment);
1868 // catch (QuitException e)
1870 // bbtkMessage("interpreter",1,"Interpreter : Quit"<<std::endl);
1873 catch (bbtk::Exception e)
1877 catch (std::exception& e)
1879 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1883 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1888 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1889 tcsetattr(0,TCSANOW,&oter);
1892 std::cout << "Good bye !" << std::endl;
1894 bbtkDebugDecTab("interpreter",9);
1898 //=======================================================================
1899 void Interpreter::commandGraph(const std::vector<std::string>& words)
1902 bool system_display = true;
1904 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1905 system_display = false;
1907 if (words.size()==1)
1909 page = mVirtualExecuter->ShowGraph(".","0","0","","","",system_display);
1911 else if (words.size()==2)
1913 page = mVirtualExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1915 else if (words.size()==3)
1917 page = mVirtualExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1919 else if (words.size()==4)
1921 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1923 else if (words.size()==5)
1925 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1927 else if (words.size()==6)
1929 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1931 else if (words.size()==7)
1933 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1936 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1937 mUser->InterpreterUserViewHtmlPage(page);
1940 //=======================================================================
1943 //=======================================================================
1944 void Interpreter::commandIndex(const std::string& filename,
1945 const std::string& type)
1947 Factory::IndexEntryType t;
1948 if (type=="Initials") t = Factory::Initials;
1949 else if (type=="Categories") t = Factory::Categories;
1950 else if (type=="Packages") t = Factory::Packages;
1951 else if (type=="Adaptors") t = Factory::Adaptors;
1953 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1955 //=======================================================================
1958 //=======================================================================
1959 void Interpreter::commandNewGUI(const std::string& boxname,
1960 const std::string& instanceName)
1962 if (mRealExecuter.expired())
1964 bbtkError("command 'newgui' cannot be compiled yet");
1967 std::string typeName = instanceName+"Type";
1968 std::stringstream* s = new std::stringstream;
1969 // create the complex box
1970 (*s) << "define "<<typeName<<std::endl;
1971 // (*s) << " description 'Automatically generated user interface for the box "
1972 // << boxname << "'" <<std::endl;
1973 // create the Layout box
1974 (*s) << " load wx"<<std::endl;
1975 (*s) << " new LayoutLine layout"<<std::endl;
1976 // create the output 'Widget'
1977 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1978 // the box change output
1979 (*s) << " new MultipleInputs change"<<std::endl;
1980 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1982 // Browse the inputs of the box in order to find which ones are not
1983 // connected and can be adapted from a widget adaptor
1984 // vector which stores the list of inputs of the box which must be connected
1985 std::vector<std::string> in;
1987 Factory::Pointer F = mVirtualExecuter->GetFactory();
1989 Package::Pointer user = F->GetPackage("user");
1991 ComplexBlackBoxDescriptor::Pointer workspace =
1992 mRealExecuter.lock()->GetCurrentDescriptor();
1997 bbtkError("interpreter::CreateGUI : could not access the executer currently defined complex box");
2002 (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get());
2005 BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname);
2006 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
2008 BlackBox::InputConnectorMapType::iterator i;
2009 for (i=box->bbGetInputConnectorMap().begin();
2010 i!=box->bbGetInputConnectorMap().end();
2013 // If the input is connected : continue
2014 if (i->second->IsConnected()) continue;
2015 // Get the input descriptor
2016 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
2017 // If it is a "system" input : skip it
2018 #ifdef USE_WXWIDGETS
2019 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
2020 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
2023 // JFGA 12/12/2014 Adding WT options for compile with it.
2027 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
2028 ( d->GetCreatorTypeInfo() == typeid(WtBlackBoxDescriptor)) )
2034 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) )
2040 std::string widget,adaptor;
2041 // try to find a widget adaptor
2042 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
2046 // command to create the adaptor
2047 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2048 // Sets the label of the widget adaptor to the name of the input
2049 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
2050 // Sets the initial value of the widget to the value of the input
2051 (*s) << " set "<<i->first<<".In \" "
2052 <<box->bbGetInputAsString(i->first)<<"\""
2054 // store the input name
2055 in.push_back(i->first);
2056 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2057 //<i->first<<"'"<<std::endl;
2058 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2060 // try to find a two pieces adaptor
2061 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
2065 // command to create the widget
2066 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
2067 // command to create the adaptor
2068 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2070 (*s) << " connect "<<i->first<<"Widget.Out "
2071 <<i->first<<".In"<<std::endl;
2072 // Sets the label of the widget adaptor to the name of the input
2073 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
2074 // Sets the initial value of the widget to the value of the input
2075 (*s) << " set "<<i->first<<"Widget.In \" "
2076 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2077 // store the input name
2078 in.push_back(i->first);
2079 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
2080 //<i->first<<"'"<<std::endl;
2081 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
2084 // try to find an adaptor from string
2085 // If found then can create a text input which
2086 // will be automatically adapted
2087 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
2091 // command to create the adaptor
2092 (*s) << " new InputText "<<i->first<<std::endl;
2093 // Sets the label of the widget adaptor to the name of the input
2094 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
2095 // Sets the initial value of the widget to the value of the input
2096 (*s) << " set "<<i->first<<".In \" "
2097 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2098 // store the input name
2099 in.push_back(i->first);
2100 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2101 //<i->first<<"'"<<std::endl;
2102 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2111 // command to create the output
2112 (*s) << " output "<<i->first<<" "
2113 <<i->first<<".Out "<<i->first<<std::endl;
2114 // <<" Output of the widget which allows to set "
2118 // Inputs for window properties
2119 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
2120 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
2121 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
2122 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
2123 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
2127 // Execute the box executes the layout
2128 (*s) << " exec layout" << std::endl;
2129 (*s) << "endefine" << std::endl;
2130 // (*s) << "help "<< typeName<< std::endl;
2131 // instanciate the box and connect it
2132 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2134 std::vector<std::string>::iterator j;
2135 for (j=in.begin();j!=in.end();++j)
2138 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2139 << boxname<<"."<<*j<<std::endl;
2141 // That's all folks ! now execute the commands :
2144 //=======================================================================
2148 //==========================================================================
2149 void Interpreter::commandDebug(const std::string& name)
2151 if ((name.length()==2)&&(name[0]=='-'))
2155 bbtk::StaticInitTime::PrintObjectListInfo = true;
2159 // int o = MessageManager::GetMessageLevel("debug");
2160 // if (o<2) MessageManager::SetMessageLevel("debug",2);
2161 mVirtualExecuter->GetFactory()->Check();
2162 // MessageManager::SetMessageLevel("debug",o);
2167 Object:: PrintObjectListInfo(name);
2170 //==========================================================================
2173 //==========================================================================
2174 // Adds a callback when 'break' command issued
2175 void Interpreter::AddBreakObserver( BreakCallbackType c )
2177 mBreakSignal.connect(c);
2179 //==========================================================================
2182 //==========================================================================
2183 std::string Interpreter::GetObjectName() const
2185 return std::string("Interpreter");
2187 //==========================================================================
2189 //==========================================================================
2190 std::string Interpreter::GetObjectInfo() const
2192 std::stringstream i;
2195 //==========================================================================
2197 //==========================================================================
2198 size_t Interpreter::GetObjectSize() const
2200 size_t s = Superclass::GetObjectSize();
2201 s += Interpreter::GetObjectInternalSize();
2204 //==========================================================================
2205 //==========================================================================
2206 size_t Interpreter::GetObjectInternalSize() const
2208 size_t s = sizeof(Interpreter);
2211 //==========================================================================
2212 //==========================================================================
2213 size_t Interpreter::GetObjectRecursiveSize() const
2215 size_t s = Superclass::GetObjectRecursiveSize();
2216 s += Interpreter::GetObjectInternalSize();
2217 s += mVirtualExecuter->GetObjectRecursiveSize();
2220 //==========================================================================