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)
100 printf("EED Interpreter::Init Start\n");
103 mVirtualExecuter = e;
105 else if (cpp_file.size()!=0)
107 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(bbtk::Transcriptor::New(cpp_file));
111 printf("EED Interpreter::Init 1\n");
112 bbtk::Executer::Pointer exe = bbtk::Executer::New();
114 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(exe);
117 printf("EED Interpreter::Init 2\n");
120 // Lock this pointer or will auto-destruct !!
121 if (!e) mVirtualExecuter->SetInterpreter(MakePointer(this,true));
124 bbtk::InterpreterVirtual::Init();
125 printf("EED Interpreter::Init End\n");
127 //=======================================================================
131 //=======================================================================
135 Interpreter::~Interpreter()
137 bbtkDebugMessage("object",2,"==> ~Interpreter()" <<std::endl);
138 mVirtualExecuter = VirtualExec::Pointer();
139 bbtkDebugMessage("object",2,"<== ~Interpreter()" <<std::endl);
141 //=======================================================================
144 //=======================================================================
145 InterpreterException::InterpreterException( const std::string& message,
147 const std::string& script_file,
150 : Exception("interpreter",0,message),
151 mInScriptFile(in_script_file),
152 mScriptFile(script_file),
153 mScriptLine(script_line)
156 //=======================================================================
157 //=======================================================================
158 InterpreterException::InterpreterException( const Exception& excep,
160 const std::string& script_file,
164 mInScriptFile(in_script_file),
165 mScriptFile(script_file),
166 mScriptLine(script_line)
169 //=======================================================================
172 //=======================================================================
173 void Interpreter::CatchInterpreterException( const InterpreterException& e )
175 if (GetExecuter()->GetNoErrorMode())
177 bbtkWarning("ERROR :"<<e.GetErrorMessage()
178 <<" ("<<e.GetScriptFile()<<":"<<e.GetScriptLine()
184 bbtk::InterpreterVirtual::CatchInterpreterException( e );
186 //=======================================================================
188 //=======================================================================
189 void Interpreter::CatchBbtkException( const bbtk::Exception& e )
191 if (GetExecuter()->GetNoErrorMode())
193 std::string file("?");
195 if (mFileName.size()) {
196 file = mFileName.back();
199 bbtkWarning("ERROR '"<<e.GetErrorMessage()
200 <<"' ("<<file<<":"<<line<<") skipped");
205 bbtk::InterpreterVirtual::CatchBbtkException( e );
207 //=======================================================================
209 //=======================================================================
210 void Interpreter::CatchStdException( const std::exception& e )
212 if (GetExecuter()->GetNoErrorMode())
214 std::string file("?");
216 if (mFileName.size())
218 file = mFileName.back();
221 bbtkWarning("ERROR '"<<e.what() <<"' ("<<file<<":"<<line<<") skipped");
224 bbtk::InterpreterVirtual::CatchStdException( e );
226 //=======================================================================
228 //=======================================================================
229 void Interpreter::CatchUnknownException()
231 if (GetExecuter()->GetNoErrorMode())
233 std::string file("?");
235 if (mFileName.size())
237 file = mFileName.back();
240 bbtkWarning("UNDEFINED ERROR " <<"("<<file<<":"<<line<<") skipped");
244 bbtk::InterpreterVirtual::CatchUnknownException( );
246 //=======================================================================
248 //=======================================================================
250 #define CATCH_MACRO \
251 catch (InterpreterException e) \
253 CatchInterpreterException(e); \
255 catch (bbtk::Exception e) \
257 CatchBbtkException(e); \
259 catch (std::exception& e) \
261 CatchStdException(e); \
265 CatchUnknownException(); \
267 //=======================================================================
270 //=======================================================================
271 Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename, bool source )
273 bbtkDebugMessage("interpreter",4,"==> Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
275 bool exm = mCommandLine;
276 mCommandLine = false;
280 mStatus = Interpreter_OK;
281 SwitchToFile(filename,source);
282 mInsideComment = false;
283 InterpretCurrentStreams();
287 bbtkDebugMessage("interpreter",4,
288 "<== Interpreter::InterpretFile(\""
289 <<filename<<"\")"<<std::endl);
296 //=======================================================================
299 //=======================================================================
300 Interpreter::ExitStatus
301 Interpreter::InterpretBuffer( std::stringstream* buffer )
303 bbtkDebugMessage("interpreter",4,"==> Interpreter::InterpretBuffer()"<<std::endl);
305 bool exm = mCommandLine;
306 mCommandLine = false;
310 mStatus = Interpreter_OK;
311 SwitchToStream(buffer);
312 mInsideComment = false;
313 InterpretCurrentStreams();
318 bbtkDebugMessage("interpreter",4,"<== Interpreter::InterpretBuffer()"<<std::endl);
324 //=======================================================================
326 //=======================================================================
327 /// Interprets the currently open streams
328 Interpreter::ExitStatus Interpreter::InterpretCurrentStreams()
330 bbtkDebugMessage("interpreter",4,
331 "==> Interpreter::InterpretCurrentStreams()"<<std::endl);
333 while (mFile.size()>0)
335 while (!mFile.back()->eof()) {
338 mFile.back()->getline(buf,500);
339 std::string str(buf);
340 //size 0 JCP 21-09-2009
341 int size=str.length();
343 if ( str[ size-1 ]==13 )
349 DoInterpretLine(str);
357 bbtkDebugMessage("interpreter",4,
358 "<== Interpreter::InterpretCurrentStreams()"<<std::endl);
362 //=======================================================================
364 //=======================================================================
365 /// Runs the interpretation of a command
366 Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
368 bbtkDebugMessage("interpreter",5,"==> Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
372 mStatus = Interpreter_OK;
373 mInsideComment = false;
374 //std::cout<<"JCP bbtkInterpreter.cxx Interpreter::InterpretLine("<<std::endl;
375 DoInterpretLine(line );
380 bbtkDebugMessage("interpreter",5,"<== Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
384 //=======================================================================
388 void Interpreter::commandNew(const std::string &boxType,const std::string &boxName) //virtual
390 mVirtualExecuter->Create(boxType,boxName);
393 void Interpreter::commandDelete(const std::string &boxName) //virtual
395 mVirtualExecuter->Destroy(boxName);
398 void Interpreter::commandConnection(const std::string &nodeFrom,const std::string &outputLabel,const std::string &nodeTo,const std::string &inputLabel) //virtual
400 mVirtualExecuter->Connect(nodeFrom,outputLabel,nodeTo,inputLabel);
403 void Interpreter::commandPackage(const std::string &packageName) //virtual
405 mVirtualExecuter->BeginPackage(packageName);
408 void Interpreter::commandEndPackage() //virtual
410 mVirtualExecuter->EndPackage();
413 void Interpreter::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename) //virtual
415 mVirtualExecuter->Define(name,pack,scriptfilename);
418 void Interpreter::commandEndDefine() //virtual
420 mVirtualExecuter->EndDefine();
423 void Interpreter::commandKind(const std::string &kind) //virtual
425 mVirtualExecuter->Kind(kind);
428 void Interpreter::commandPrint(const std::string &value) //virtual
430 mVirtualExecuter->Print(value);
434 void Interpreter::commandExec(const std::string &word) //virtual
438 mVirtualExecuter->SetNoExecMode(true);
441 else if (word=="freeze_no_error")
443 mVirtualExecuter->SetNoExecMode(true);
444 mVirtualExecuter->SetNoErrorMode(true);
447 else if (word=="unfreeze")
449 mVirtualExecuter->SetNoExecMode(false);
450 mVirtualExecuter->SetNoErrorMode(false);
454 mVirtualExecuter->Execute(word);
459 void Interpreter::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string &help) //virtual
461 mVirtualExecuter->DefineInput(name,box,input,help);
464 void Interpreter::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string &help) //virtual
466 mVirtualExecuter->DefineOutput(name,box,output,help);
469 void Interpreter::commandSet(const std::string &box,const std::string &input,const std::string &value) //virtual
471 mVirtualExecuter->Set(box,input,value);
474 void Interpreter::commandAuthor(const std::string &author) //virtual
476 mVirtualExecuter->Author(author);
479 void Interpreter::commandCategory(const std::string &categorytype) //virtual
481 mVirtualExecuter->Category(categorytype);
484 void Interpreter::commandDescription(const std::string &description) //virtual
486 mVirtualExecuter->Description(description);
490 void Interpreter::commandClear() //virtual
492 mVirtualExecuter->Clear();
495 void Interpreter::commandInclude(const std::string &word, bool ok) //virtual
497 // if 'source' was given (words.size()==3) then tell to set the
498 // source file name of the current complex box with the full file name included
501 InterpretFile(word, ok );
505 SwitchToFile(word , ok );
510 void Interpreter::commandLoad(const std::string &packageName) //virtual
512 GetExecuter()->LoadPackage(packageName);
515 void Interpreter::commandUnload(const std::string &packageName) //virtual
517 GetExecuter()->UnLoadPackage(packageName);
520 void Interpreter::commandBreak() //virtual
523 std::cout << "BreakException("
526 <<line<<")"<<std::endl;
528 bbtkError("break");//,in_script,file,line);
529 // throw BreakException(in_script,file,line);
532 void Interpreter::commandQuit() //virtual
534 bbtkError("quit");//,in_script,file,line);
535 //throw QuitException(in_script,file,line);
538 void Interpreter::commandMessage() //virtual
540 mVirtualExecuter->HelpMessages();
543 void Interpreter::commandMessage(const std::string &kind,const std::string &levelstr) //virtual
546 sscanf(levelstr.c_str(),"%d",&level);
547 mVirtualExecuter->SetMessageLevel(kind,level);
553 //=======================================================================
554 void Interpreter::DoInterpretLine( const std::string& line ) //virtual
556 bbtkDebugMessage("interpreter",6,"==> Interpreter::DoInterpretLine(\""
557 <<line<<"\")"<<std::endl);
558 std::vector<std::string> words;
559 SplitLine(line,words);
564 bbtkDebugDecTab("interpreter",9);
568 // Single line comment : # or //
569 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
571 bbtkDebugDecTab("interpreter",9);
572 bbtkMessage("interpreter",9,"Comment"<<std::endl);
576 // Multi line comment ( / * ... * / ) -delimiters on different lines !- <<<<<<< / * * /
578 if (words[0][0]=='/' && words[0][1]=='*')
580 bbtkDebugDecTab("interpreter",9);
581 bbtkMessage("interpreter",9,"In multiline comment"<<std::endl);
582 mInsideComment = true;
586 if (words[0][0]=='*' && words[0][1]=='/')
588 bbtkDebugDecTab("interpreter",9);
589 bbtkMessage("interpreter",9,"Out multiline comment"<<std::endl);
590 if ( !mInsideComment ) {
591 bbtkDebugDecTab("interpreter",9);
592 bbtkMessage("interpreter",9,"Comment mismatch : '* /' with no matching '/ *'"<<std::endl); <<<<<<<<< * / / *
594 mInsideComment = false;
600 bbtkDebugDecTab("interpreter",9);
601 bbtkMessage("interpreter",9,"Multiline Comment"<<std::endl);
606 CommandInfoType command;
607 InterpretCommand(words,command);
608 //std::cout<<"JCP bbtkInterpreter command.keyword ="<<command.keyword<<std::endl;
609 bbtkDebugMessage("interpreter",9,
610 "Command='"<<command.keyword
611 <<"' code="<<command.code<<std::endl);
613 std::string left,right,left2,right2;
614 std::string filename;
618 if (command.code==cMessage)
623 //EED Borrame mVirtualExecuter->HelpMessages();
627 commandMessage(words[1],words[2]);
628 //EED Borrame sscanf(words[2].c_str(),"%d",&level);
629 //EED Borrame mVirtualExecuter->SetMessageLevel(words[1],level);
635 bbtkMessage("echo",2,line<<std::endl);
638 // break and quit commands
639 if ((command.code==cBreak) || (command.code==cQuit))
641 bool in_script = false;
642 std::string file("");
645 if (mFileName.size())
647 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
648 if (fs!=0) in_script = true;
649 file = mFileName.back();
652 if (command.code==cBreak)
654 // std::cout << "BreakException("
657 // <<line<<")"<<std::endl;
659 //EED Borrame bbtkError("break");//,in_script,file,line);
660 // throw BreakException(in_script,file,line);
665 //EED Borrame bbtkError("quit");//,in_script,file,line);
666 //throw QuitException(in_script,file,line);
670 //std::cout<<" mVirtualExecuter->Create(words[1],words[2]); "<<line<<std::endl;
673 switch (command.code)
676 commandNew(words[1],words[2]);
677 //EED Borrame mVirtualExecuter->Create(words[1],words[2]);
681 commandDelete(words[1]);
682 //EED Borrame mVirtualExecuter->Destroy(words[1]);
686 Utilities::SplitAroundFirstDot(words[1],left,right);
687 Utilities::SplitAroundFirstDot(words[2],left2,right2);
688 commandConnection(left,right,left2,right2);
689 //EED Borrame mVirtualExecuter->Connect(left,right,left2,right2);
693 commandPackage(words[1]);
694 //EED Borrame mVirtualExecuter->BeginPackage(words[1]);
699 //EED Borrame mVirtualExecuter->EndPackage();
703 if (mFileName.size()>0)
705 //??? commandDefine(????);
706 filename = mFileName.back(); //mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
710 commandDefine(words[1],"",filename);
711 //EED Borrame mVirtualExecuter->Define(words[1],"",filename);
715 commandDefine(words[1],words[2],filename);
716 //EED Borrame mVirtualExecuter->Define(words[1],words[2],filename);
722 //EED Borrame mVirtualExecuter->EndDefine();
726 commandKind(words[1]);
727 //EED Borrame mVirtualExecuter->Kind(words[1]);
731 commandPrint(words[1]);
732 //EED Borrame mVirtualExecuter->Print(words[1]);
736 commandExec(words[1]);
737 //EED Borrame if (words[1]=="freeze")
739 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
740 //EED Borrame mThrow = false;
742 //EED Borrame else if (words[1]=="freeze_no_error")
744 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
745 //EED Borrame mVirtualExecuter->SetNoErrorMode(true);
746 //EED Borrame mThrow = false;
748 //EED Borrame else if (words[1]=="unfreeze")
750 //EED Borrame mVirtualExecuter->SetNoExecMode(false);
751 //EED Borrame mVirtualExecuter->SetNoErrorMode(false);
755 //EED Borrame mVirtualExecuter->Execute(words[1]);
761 Utilities::SplitAroundFirstDot(words[2],left,right);
762 commandInput(words[1],left,right,words[3]);
763 //EED Borrame mVirtualExecuter->DefineInput(words[1],left,right,words[3]);
767 Utilities::SplitAroundFirstDot(words[2],left,right);
768 commandOutput(words[1],left,right,words[3]);
769 //EED Borrame mVirtualExecuter->DefineOutput(words[1],left,right,words[3]);
773 Utilities::SplitAroundFirstDot(words[1],left,right);
774 commandSet(left,right,words[2]);
775 //EED Borrame mVirtualExecuter->Set(left,right,words[2]);
779 commandAuthor(words[1]);
780 //EED Borrame mVirtualExecuter->Author(words[1]);
784 commandNewGUI(words[1],words[2]);
788 commandCategory(words[1]);
789 //EED Borrame mVirtualExecuter->Category(words[1]);
794 commandIndex("tmp_index.html");
795 else if (words.size()==2)
796 commandIndex(words[1]);
797 else if (words.size()==3)
798 commandIndex(words[1],words[2]);
802 commandDescription(words[1]);
803 //EED Borrame mVirtualExecuter->Description(words[1]);
825 //EED Borrame mVirtualExecuter->Clear();
829 commandInclude( words[1] , (words.size()==3) );
830 //EED Borrame // if 'source' was given (words.size()==3) then tell to set the
831 //EED Borrame // source file name of the current complex box with the full file name included
832 //EED Borrame if (mCommandLine)
834 //EED Borrame InterpretFile(words[1],(words.size()==3));
835 //EED Borrame } else{
836 //EED Borrame SwitchToFile(words[1],(words.size()==3) );
841 commandLoad( words[1] );
842 //EED Borrame GetExecuter()->LoadPackage(words[1]);
846 commandUnload( words[1] );
847 //EED Borrame GetExecuter()->UnLoadPackage(words[1]);
851 if (words.size()==2) commandDebug(words[1]);
852 else commandDebug("");
857 // if (words.size() == 2)
859 // if (words[1]=="freeze") mVirtualExecuter->SetNoExecMode(true);
860 // else if (words[1]=="unfreeze") mVirtualExecuter->SetNoExecMode(false);
864 // mVirtualExecuter->SetWorkspaceName(words[2]);
869 bbtkInternalError("should not reach here !!!");
872 bbtkDebugMessage("interpreter",6,"<== Interpreter::DoInterpretLine(\""
873 <<line<<"\")"<<std::endl);
876 //=======================================================================
881 //=======================================================================
882 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
884 bbtkDebugMessage("interpreter",9,"==> Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
886 std::string delimiters = "\"";
887 std::vector<std::string> quote;
888 Utilities::SplitString(str,delimiters,quote);
891 std::vector<std::string>::iterator i;
892 for (i=quote.begin(); i!=quote.end(); )
894 Utilities::SplitString(*i,delimiters,tokens);
898 // bbtkDebugMessage("interpreter",0,"\""<<*i<<"\""<<std::endl);
899 tokens.push_back(*i);
904 for (i=tokens.begin(); i!=tokens.end(); ++i)
906 bbtkDebugMessage("interpreter",9,"--["<<*i<<"]"<<std::endl);
908 bbtkDebugMessage("interpreter",9,"<== Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
911 //=======================================================================
915 //=======================================================================
916 void Interpreter::commandReset() // virtual
918 // Cannot close all files if the reset command is read from a file !
920 mFileNameHistory.clear();
921 this->mVirtualExecuter->Reset();
923 //=======================================================================
925 //=======================================================================
930 void Interpreter::Print( const std::string& str)
932 if (mVirtualExecuter->GetNoExecMode()) return;
934 bbtkDebugMessageInc("interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
937 // InterpretLine ("load std")
938 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
939 // InterpretLine("new Print _P_")
940 // InterpretLine("connect _C_.Out _P_.In")
944 std::vector<std::string> chains;
945 std::string delimiters("$");
947 // Skip delimiters at beginning.
948 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
950 if (lastPos>0) is_text = false;
952 // Find first delimiter.
953 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
955 while (std::string::npos != pos || std::string::npos != lastPos)
959 // Found a text token, add it to the vector.
960 chains.push_back(str.substr(lastPos, pos - lastPos));
961 // std::string token = str.substr(lastPos, pos - lastPos)
962 // InterpretLine("set _C_.In%num% %token%")
968 // is an output (between $$) : decode
969 std::string tok,box,output;
970 tok = str.substr(lastPos, pos - lastPos);
971 Utilities::SplitAroundFirstDot(tok,box,output);
972 chains.push_back( mVirtualExecuter->Get(box,output) );
974 // InterpretLine("connect %tok% _C_.In%num%")
977 // Skip delimiters. Note the "not_of"
978 lastPos = str.find_first_not_of(delimiters, pos);
979 // Find next delimiter
980 pos = str.find_first_of(delimiters, lastPos);
985 // InterpretLine("exec _P_")
986 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
988 std::vector<std::string>::iterator i;
989 for (i= chains.begin(); i!=chains.end(); ++i)
992 Utilities::SubsBackslashN(*i);
995 std::cout << std::endl;
996 bbtkDebugDecTab("interpreter",9);
1000 //=======================================================================
1005 // =========================================================================
1006 void Interpreter::SwitchToFile( const std::string& name , bool source )
1008 // Note : in the following :
1009 // name : the user supplied name
1010 // - abreviated name e.g. scr scr.bbs
1011 // - relative full name e.g. ./scr.bbs ../../scr.bbs
1012 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
1013 // same for Windows, with c:, d: ...
1015 // use ./directory/subdir/scrname.bbs
1018 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToFile( \""
1019 <<name<<"\")"<<std::endl);
1021 std::vector<std::string> script_paths;
1022 std::string fullPathScriptName; // full path script name
1023 std::string pkgname; // e.g. <scriptname>.bbs
1024 std::vector<std::string> Filenames;
1026 // The following is *NOT* a debug time message :
1027 // It's a user intended message.
1028 // Please don't remove it.
1029 bbtkMessage("interpreter",1,
1030 "look for : [" << name
1031 << "]" << std::endl);
1035 pkgname = Utilities::ExtractScriptName(name,upath);
1037 bbtkMessage("interpreter",3,
1038 "package name:[" << pkgname
1039 << "] path:[" << upath << "]" << std::endl);
1040 bool fullnameGiven = false;
1041 bool foundFile = false;
1043 // ==== "*" provided : load all scripts in given path
1044 // relative (e.g. std/boxes/ *) or absolute <<<<<<<< / *
1048 std::stringstream* stream = new std::stringstream;
1049 //if (upath.size()!=0) // avoid troubles for "*"
1051 // ==== no path provided : look in root bbs path
1052 if (upath.size()==0)
1054 // bbtkMessage("interpreter",1,
1055 // LG : add all bbs path
1056 // script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1057 std::vector<std::string>::const_iterator i;
1058 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1059 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1062 script_paths.push_back(*i);
1065 // ==== absolute path provided
1066 else if (upath[0]=='/' || upath[1] == ':' )
1068 if ( Utilities::IsDirectory( upath ) )
1070 script_paths.push_back(upath);
1074 bbtkError("'"<<upath<<"' : directory does not exist");
1077 // ==== relative path provided : search all bbs path appended with
1078 // the relative path provided
1081 std::vector<std::string>::const_iterator i;
1082 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1083 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1086 std::string full_path(*i);
1087 // we *really* want '.' to be the current working directory
1088 if (full_path == ".")
1090 char buf[2048]; // for getcwd
1091 char * currentDir = getcwd(buf, 2048);
1092 std::string cwd(currentDir);
1093 full_path = currentDir;
1096 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1099 if ( Utilities::IsDirectory( full_path ) )
1101 script_paths.push_back(full_path);
1104 if (script_paths.empty())
1106 bbtkError("no '"<<upath<<"' subdir found in search paths"
1112 // === search paths list complete : now explore it
1114 // ==== relative name, iterate + load all .bbs/.bbp files
1115 std::vector<std::string>::iterator i;
1116 for (i=script_paths.begin();i!=script_paths.end();i++)
1118 bbtkMessage("interpreter",1,
1119 "--> Looking in '" << *i << "'" << std::endl);
1123 Utilities::Explore(*i, false, Filenames);
1125 for (std::vector<std::string>::iterator j = Filenames.begin();
1126 j!= Filenames.end(); ++j)
1128 int lgr = (*j).size();
1129 if (lgr < 5) continue;
1130 // ignore non .bbp file
1131 if ( (*j).substr(lgr-4, 4) != ".bbp") continue;
1133 (*stream) << "include \"" << *j << "\"\n";
1134 bbtkMessage("interpreter",2," --> Found '" << *j << "'" << std::endl);
1137 } // for (std::vector...
1138 } // for (i=script_...
1143 bbtkMessage("interpreter",1,
1144 " --> No .bbp found"<< std::endl);
1148 bbtkMessage("interpreter",1,
1149 " --> "<<nbBssFiles<<" .bbp found"<< std::endl);
1150 SwitchToStream(stream);
1154 //=============== end pkgname=="*" ===========
1157 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1158 // (not only a plain script name)
1159 // we trust him, and try to expland the directory name
1160 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1162 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1165 // ===========================================================check user supplied location
1166 fullnameGiven = true;
1168 fullPathScriptName = Utilities::ExpandLibName(name, false);
1170 // allow user to always forget ".bbs"
1171 int l = fullPathScriptName.size();
1175 if ((fullPathScriptName.substr(l-4, 4) != ".bbs")&&
1176 (fullPathScriptName.substr(l-4, 4) != ".bbp"))
1178 std::string tfullPathScriptName = fullPathScriptName + ".bbs";
1179 if ( Utilities::FileExists(tfullPathScriptName) )
1181 fullPathScriptName = tfullPathScriptName;
1186 tfullPathScriptName = fullPathScriptName + ".bbp";
1187 if ( Utilities::FileExists(tfullPathScriptName) )
1189 fullPathScriptName = tfullPathScriptName;
1196 if ( Utilities::FileExists(fullPathScriptName) )
1204 // =============================== iterate on the paths
1206 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1208 std::vector<std::string>::iterator i;
1209 for (i=script_paths.begin();i!=script_paths.end();++i)
1212 // we *really* want '.' to be the current working directory
1215 char buf[2048]; // for getcwd
1216 char * currentDir = getcwd(buf, 2048);
1217 std::string cwd(currentDir);
1221 std::string tfullPathScriptName = Utilities::MakePkgnameFromPath(path, name, false);
1222 //Addition JCP tfullPathScriptName.size()>=4
1223 if(tfullPathScriptName.size()>=4){
1224 if (tfullPathScriptName.substr(tfullPathScriptName.size()-4, 3)==".bb")
1226 fullPathScriptName = tfullPathScriptName;
1227 if ( ! Utilities::FileExists(fullPathScriptName) )
1229 // The following is *NOT* a debug time message :
1230 // It's a user intended message.
1231 // Please don't remove it.
1232 bbtkMessage("interpreter",2,
1233 " [" <<fullPathScriptName <<"] : does not exist"
1235 continue; // try next path
1237 bbtkMessage("interpreter",2,
1238 " [" <<fullPathScriptName
1239 <<"] : found" <<std::endl);
1241 break; // a script was found; we stop iterating
1245 fullPathScriptName = tfullPathScriptName + ".bbs";
1246 // Check if library exists
1247 if ( ! Utilities::FileExists(fullPathScriptName) )
1249 fullPathScriptName = tfullPathScriptName + ".bbp";
1250 if ( ! Utilities::FileExists(fullPathScriptName) )
1252 // The following is *NOT* a debug time message :
1253 // It's a user intended message.
1254 // Please don't remove it.
1255 bbtkMessage("interpreter",2,
1256 " [" <<tfullPathScriptName <<".bbs/.bbp] : do not exist"
1258 continue; // try next path
1261 bbtkMessage("interpreter",2,
1262 " [" <<fullPathScriptName
1263 <<"] : found" <<std::endl);
1265 break; // a script was found; we stop iterating
1268 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1274 if(fullPathScriptName == "")
1275 bbtkError("Path ["<<upath<<"] doesn't exist");
1277 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1279 bbtkError("No ["<<pkgname<<".bbs/.bbp] script found");
1284 LoadScript(fullPathScriptName,name);
1285 if (source) SetCurrentFileName(fullPathScriptName);
1290 //=======================================================================
1293 //=======================================================================
1294 void Interpreter::SetCurrentFileName(const std::string &fullPathScriptName) // virtual
1296 GetExecuter()->SetCurrentFileName(fullPathScriptName);
1298 //=======================================================================
1301 void Interpreter::SetTypeOfScript_Application()
1303 GetExecuter()->SetTypeOfScript_Application();
1309 //=======================================================================
1310 void Interpreter::SwitchToStream( std::stringstream* stream )
1312 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToStream()"
1314 mFile.push_back(stream);
1315 std::ostringstream buffer_name;
1317 buffer_name << "buffer_" ;
1319 if (mFileName.size()>0 )
1321 buffer_name << mFileName.back() << "_" << mLine.back();
1323 mFileName.push_back(buffer_name.str());
1324 mIncludeFileName.push_back(buffer_name.str());
1327 //=======================================================================
1331 //=======================================================================
1332 void Interpreter::LoadScript( std::string fullPathScriptName,
1333 std::string includeScriptName)
1335 bbtkDebugMessage("interpreter",4,"==> Interpreter::LoadScript("
1336 <<fullPathScriptName<<")"
1339 Utilities::replace( fullPathScriptName ,
1340 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1342 if (find(mFileNameHistory.begin(),
1343 mFileNameHistory.end(),
1344 fullPathScriptName)!=mFileNameHistory.end())
1350 s = new std::ifstream;
1351 s->open(fullPathScriptName.c_str());
1354 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1358 bbtkMessage("interpreter",1," -->[" << fullPathScriptName
1359 << "] found" << std::endl);
1362 mFileName.push_back(fullPathScriptName);
1363 mFileNameHistory.push_back(fullPathScriptName);
1364 mIncludeFileName.push_back(includeScriptName);
1369 //=======================================================================
1373 //=======================================================================
1374 void Interpreter::CloseCurrentFile()
1376 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseCurrentFile()"
1379 if (mFile.size()==0)
1381 bbtkDebugMessage("interpreter",9," -> no file left open"<<std::endl);
1385 bbtkDebugMessage("interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1387 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1388 if (file!=0) file->close();
1390 delete mFile.back();
1392 mFileName.pop_back();
1393 mIncludeFileName.pop_back();
1396 bbtkDebugMessage("interpreter",9," Remains "
1398 <<" open"<<std::endl);
1399 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseCurrentFile()"
1402 //=======================================================================
1404 //=======================================================================
1405 void Interpreter::CloseAllFiles()
1407 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseAllFiles()"
1410 while (mFile.size() != 0)
1414 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseAllFiles()"
1417 //=======================================================================
1420 //=======================================================================
1421 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1422 CommandInfoType& info )
1424 bbtkDebugMessage("interpreter",9,"==> Interpreter::InterpretCommand(...)"<<std::endl);
1426 // searches the command keyword
1427 CommandDictType::iterator c;
1428 c = mCommandDict.find(words[0]);
1429 if ( c == mCommandDict.end() ) {
1430 bbtkError(words[0]<<" : unknown command");
1433 // tests the number of args
1434 if ( ( ((int)words.size())-1 < c->second.argmin ) ||
1435 ( ((int)words.size())-1 > c->second.argmax ) )
1437 commandHelp(words[0]);
1438 bbtkError(words[0]<<" : wrong number of arguments");
1440 //std::cout<<"Interpreter::InterpretCommand( const std::vector<std::string>& words,"<<std::endl;
1443 bbtkDebugMessage("interpreter",9,"<== Interpreter::InterpretCommand(...)"<<std::endl);
1446 //=======================================================================
1450 //=======================================================================
1451 /// Displays help on all the commands
1452 void Interpreter::commandHelp(const std::vector<std::string>& words)
1454 unsigned int nbarg = words.size()-1;
1462 if (words[1]=="packages")
1464 GetExecuter()->GetFactory()->PrintHelpListPackages(true);
1469 commandHelp(words[1]);
1471 catch (bbtk::Exception e)
1475 GetExecuter()->GetFactory()->PrintHelpPackage(words[1]);
1479 ConfigurationFile::GetInstance().Get_doc_path();
1480 url += "/bbdoc/" + words[1] + "/index.html";
1481 if (Utilities::FileExists(url))
1483 mUser->InterpreterUserViewHtmlPage(url);
1487 catch (bbtk::Exception f)
1491 std::string package;
1492 GetExecuter()->GetFactory()->PrintHelpDescriptor(words[1],
1497 ConfigurationFile::GetInstance().Get_doc_path();
1498 url += "/bbdoc/" + package + "/index.html";
1499 if (Utilities::FileExists(url))
1501 url += "#" + words[1];
1502 mUser->InterpreterUserViewHtmlPage(url);
1506 catch (bbtk::Exception g)
1510 GetExecuter()->PrintHelpBlackBox(words[1],"0","9999");
1512 catch (bbtk::Exception h){
1513 bbtkError("\""<<words[1].c_str()
1514 <<"\" is not a known command, package, black box type or black box name");
1522 if (words[2]=="all")
1524 if ( words[1]=="packages" )
1526 GetExecuter()->GetFactory()->PrintHelpListPackages(true,true);
1531 GetExecuter()->GetFactory()->PrintHelpPackage(words[1],true);
1533 catch (bbtk::Exception f)
1539 commandHelp(words[0]);
1540 bbtkError(words[0]<<" : syntax error");
1545 bbtkError("Should not reach here !!!");
1548 //=======================================================================
1550 //===================================================================
1551 /// Displays the Configuration
1552 void Interpreter::commandConfig() const
1554 ConfigurationFile::GetInstance().GetHelp(1);
1556 //===================================================================
1558 //=======================================================================
1559 /// Displays help on all the commands
1560 void Interpreter::HelpCommands()
1562 std::cout << "Available commands :" << std::endl;
1563 CommandDictType::iterator i;
1564 for ( i = mCommandDict.begin();
1565 i != mCommandDict.end();
1567 std::cout << " " << i->first << std::endl;
1568 // std::cout << " usage : " << i->second.syntax << std::endl;
1569 // std::cout << " " << i->second.help << std::endl;
1573 //=======================================================================
1577 //=======================================================================
1578 /// Displays help on a particular commands
1579 void Interpreter::commandHelp(const std::string& s)
1581 CommandDictType::iterator c;
1582 c = mCommandDict.find(s);
1583 if ( c == mCommandDict.end() ) {
1586 // bbtkError(s<<" : Unknown command");
1587 std::string tmpSS=s+" : Unknown command";
1590 // std::cout << " " << s << " : "<< std::endl;
1591 // CommandParamDictType::iterator i;
1592 // for ( i = c->second.begin();
1593 // i != c->second.end();
1595 std::cout << " usage : " << c->second.syntax << std::endl;
1596 std::cout << " " << c->second.help << std::endl;
1599 //=======================================================================
1602 //=======================================================================
1603 /// Fills the vector commands with the commands which
1604 /// have the first n chars of buf for prefix
1605 /// TODO : skip initial spaces in buf and also return the position of first
1606 /// non blank char in buf
1607 void Interpreter::FindCommandsWithPrefix( char* buf,
1609 std::vector<std::string>& commands )
1611 CommandDictType::const_iterator i;
1612 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1614 if ((i->first).find(buf,0,n) == 0)
1615 commands.push_back(i->first);
1618 //=======================================================================
1623 //=======================================================================
1624 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1626 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1627 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1629 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1630 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1631 // E.G. STORE THIS IN bbtk_config.xml
1632 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1633 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1634 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1635 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1636 #define BBTK_BACKSPACE_KBCODE 0x00000008
1637 #define BBTK_DEL_KBCODE 0x0000007F
1638 #define BBTK_SPACE_KBCODE 0x00000020
1640 //=======================================================================
1641 void Interpreter::GetLineFromPrompt(std::string& s)
1646 unsigned int MAX_LINE_SIZE = 160;
1647 unsigned int MAX_HISTORY_SIZE = 100;
1649 char* newline = new char[MAX_LINE_SIZE];
1650 memset(newline,0,MAX_LINE_SIZE);
1651 char* histline = new char[MAX_LINE_SIZE];
1652 memset(histline,0,MAX_LINE_SIZE);
1654 char* line = newline;
1655 unsigned int hist = mHistory.size();
1661 read ( STDIN_FILENO, &c, 4) ;
1663 bbtkDebugMessage("debug",9,"[0x"<<std::hex<<c<<"]\n");
1665 // Printable character
1666 if ( (ind<MAX_LINE_SIZE-1) &&
1667 ( c >= BBTK_SPACE_KBCODE ) &&
1668 ( c < BBTK_DEL_KBCODE ))
1676 // delete the unused line
1682 // empty lines are not stored in from history
1685 // if history too long : delete oldest command
1686 if (mHistory.size()>MAX_HISTORY_SIZE)
1688 delete mHistory.front();
1689 mHistory.pop_front();
1691 mHistory.push_back(line);
1696 else if ( (ind>0) &&
1697 ((c == BBTK_BACKSPACE_KBCODE) ||
1698 (c == BBTK_DEL_KBCODE)) )
1706 // TODO : Command completion
1707 std::vector<std::string> commands;
1708 FindCommandsWithPrefix( line,ind,commands);
1709 if (commands.size()==1)
1711 std::string com = *commands.begin();
1712 for (; ind<com.size(); ++ind)
1714 PrintChar(com[ind]);
1720 else if (commands.size()>1)
1722 std::vector<std::string>::iterator i;
1724 for (i=commands.begin();i!=commands.end();++i)
1726 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1729 write(STDOUT_FILENO,"\n> ",3);
1730 //for (int j=0;j<ind;++j)
1732 write(STDOUT_FILENO,line,ind);
1736 // Arrow up : back in history
1737 else if (c==BBTK_UP_ARROW_KBCODE)
1741 // erase current line
1742 while (ind--) BackSpace();
1746 strcpy(histline,mHistory[hist]);
1750 write(STDOUT_FILENO,line,ind);
1753 // Arrow down : down in history
1754 else if (c==BBTK_DOWN_ARROW_KBCODE)
1756 if (hist<mHistory.size()-1)
1758 // erase current line
1759 while (ind--) BackSpace();
1763 strcpy(histline,mHistory[hist]);
1767 write(STDOUT_FILENO,line,ind);
1769 // end of history : switch back to newline
1770 else if (hist==mHistory.size()-1)
1772 // erase current line
1773 while (ind--) BackSpace();
1780 write(STDOUT_FILENO,line,ind);
1784 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1786 PrintChar(line[ind]);
1791 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1799 write(STDOUT_FILENO,"\n\r",2);
1807 //=======================================================================
1808 void Interpreter::GetLineFromPrompt(std::string& s)
1834 //=======================================================================
1845 //=======================================================================
1846 void Interpreter::CommandLineInterpreter()
1848 bbtkDebugMessageInc("interpreter",9,
1849 "Interpreter::CommandLineInterpreter()"<<std::endl);
1851 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1852 // Initialise the tty in non canonical mode with no echo
1853 // oter remembers the previous settings to restore them after
1854 struct termios ter,oter;
1857 ter.c_lflag &= ~ECHO;
1858 ter.c_lflag &= ~ICANON;
1861 tcsetattr(0,TCSANOW,&ter);
1864 mCommandLine = true;
1866 // bool insideComment = false; // for multiline comment
1867 mInsideComment = false;
1873 GetLineFromPrompt(line);
1874 DoInterpretLine(line); //, insideComment);
1876 // catch (QuitException e)
1878 // bbtkMessage("interpreter",1,"Interpreter : Quit"<<std::endl);
1881 catch (bbtk::Exception e)
1885 catch (std::exception& e)
1887 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1891 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1896 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1897 tcsetattr(0,TCSANOW,&oter);
1900 std::cout << "Good bye !" << std::endl;
1902 bbtkDebugDecTab("interpreter",9);
1906 //=======================================================================
1907 void Interpreter::commandGraph(const std::vector<std::string>& words)
1910 bool system_display = true;
1912 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1913 system_display = false;
1915 if (words.size()==1)
1917 page = mVirtualExecuter->ShowGraph(".","0","0","","","",system_display);
1919 else if (words.size()==2)
1921 page = mVirtualExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1923 else if (words.size()==3)
1925 page = mVirtualExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1927 else if (words.size()==4)
1929 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1931 else if (words.size()==5)
1933 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1935 else if (words.size()==6)
1937 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1939 else if (words.size()==7)
1941 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1944 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1945 mUser->InterpreterUserViewHtmlPage(page);
1948 //=======================================================================
1951 //=======================================================================
1952 void Interpreter::commandIndex(const std::string& filename,
1953 const std::string& type)
1955 Factory::IndexEntryType t;
1956 if (type=="Initials") t = Factory::Initials;
1957 else if (type=="Categories") t = Factory::Categories;
1958 else if (type=="Packages") t = Factory::Packages;
1959 else if (type=="Adaptors") t = Factory::Adaptors;
1961 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1963 //=======================================================================
1966 //=======================================================================
1967 void Interpreter::commandNewGUI(const std::string& boxname,
1968 const std::string& instanceName)
1970 if (mRealExecuter.expired())
1972 bbtkError("command 'newgui' cannot be compiled yet");
1975 std::string typeName = instanceName+"Type";
1976 std::stringstream* s = new std::stringstream;
1977 // create the complex box
1978 (*s) << "define "<<typeName<<std::endl;
1979 // (*s) << " description 'Automatically generated user interface for the box "
1980 // << boxname << "'" <<std::endl;
1981 // create the Layout box
1982 (*s) << " load wx"<<std::endl;
1983 (*s) << " new LayoutLine layout"<<std::endl;
1984 // create the output 'Widget'
1985 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1986 // the box change output
1987 (*s) << " new MultipleInputs change"<<std::endl;
1988 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1990 // Browse the inputs of the box in order to find which ones are not
1991 // connected and can be adapted from a widget adaptor
1992 // vector which stores the list of inputs of the box which must be connected
1993 std::vector<std::string> in;
1995 Factory::Pointer F = mVirtualExecuter->GetFactory();
1997 Package::Pointer user = F->GetPackage("user");
1999 ComplexBlackBoxDescriptor::Pointer workspace =
2000 mRealExecuter.lock()->GetCurrentDescriptor();
2005 bbtkError("interpreter::CreateGUI : could not access the executer currently defined complex box");
2010 (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get());
2013 BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname);
2014 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
2016 BlackBox::InputConnectorMapType::iterator i;
2017 for (i=box->bbGetInputConnectorMap().begin();
2018 i!=box->bbGetInputConnectorMap().end();
2021 // If the input is connected : continue
2022 if (i->second->IsConnected()) continue;
2023 // Get the input descriptor
2024 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
2025 // If it is a "system" input : skip it
2026 #ifdef USE_WXWIDGETS
2027 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
2028 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
2031 // JFGA 12/12/2014 Adding WT options for compile with it.
2035 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
2036 ( d->GetCreatorTypeInfo() == typeid(WtBlackBoxDescriptor)) )
2042 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) )
2048 std::string widget,adaptor;
2049 // try to find a widget adaptor
2050 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
2054 // command to create the adaptor
2055 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2056 // Sets the label of the widget adaptor to the name of the input
2057 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
2058 // Sets the initial value of the widget to the value of the input
2059 (*s) << " set "<<i->first<<".In \" "
2060 <<box->bbGetInputAsString(i->first)<<"\""
2062 // store the input name
2063 in.push_back(i->first);
2064 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2065 //<i->first<<"'"<<std::endl;
2066 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2068 // try to find a two pieces adaptor
2069 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
2073 // command to create the widget
2074 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
2075 // command to create the adaptor
2076 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2078 (*s) << " connect "<<i->first<<"Widget.Out "
2079 <<i->first<<".In"<<std::endl;
2080 // Sets the label of the widget adaptor to the name of the input
2081 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
2082 // Sets the initial value of the widget to the value of the input
2083 (*s) << " set "<<i->first<<"Widget.In \" "
2084 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2085 // store the input name
2086 in.push_back(i->first);
2087 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
2088 //<i->first<<"'"<<std::endl;
2089 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
2092 // try to find an adaptor from string
2093 // If found then can create a text input which
2094 // will be automatically adapted
2095 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
2099 // command to create the adaptor
2100 (*s) << " new InputText "<<i->first<<std::endl;
2101 // Sets the label of the widget adaptor to the name of the input
2102 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
2103 // Sets the initial value of the widget to the value of the input
2104 (*s) << " set "<<i->first<<".In \" "
2105 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2106 // store the input name
2107 in.push_back(i->first);
2108 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2109 //<i->first<<"'"<<std::endl;
2110 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2119 // command to create the output
2120 (*s) << " output "<<i->first<<" "
2121 <<i->first<<".Out "<<i->first<<std::endl;
2122 // <<" Output of the widget which allows to set "
2126 // Inputs for window properties
2127 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
2128 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
2129 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
2130 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
2131 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
2135 // Execute the box executes the layout
2136 (*s) << " exec layout" << std::endl;
2137 (*s) << "endefine" << std::endl;
2138 // (*s) << "help "<< typeName<< std::endl;
2139 // instanciate the box and connect it
2140 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2142 std::vector<std::string>::iterator j;
2143 for (j=in.begin();j!=in.end();++j)
2146 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2147 << boxname<<"."<<*j<<std::endl;
2149 // That's all folks ! now execute the commands :
2152 //=======================================================================
2156 //==========================================================================
2157 void Interpreter::commandDebug(const std::string& name)
2159 if ((name.length()==2)&&(name[0]=='-'))
2163 bbtk::StaticInitTime::PrintObjectListInfo = true;
2167 // int o = MessageManager::GetMessageLevel("debug");
2168 // if (o<2) MessageManager::SetMessageLevel("debug",2);
2169 mVirtualExecuter->GetFactory()->Check();
2170 // MessageManager::SetMessageLevel("debug",o);
2175 Object:: PrintObjectListInfo(name);
2178 //==========================================================================
2181 //==========================================================================
2182 // Adds a callback when 'break' command issued
2183 void Interpreter::AddBreakObserver( BreakCallbackType c )
2185 mBreakSignal.connect(c);
2187 //==========================================================================
2190 //==========================================================================
2191 std::string Interpreter::GetObjectName() const
2193 return std::string("Interpreter");
2195 //==========================================================================
2197 //==========================================================================
2198 std::string Interpreter::GetObjectInfo() const
2200 std::stringstream i;
2203 //==========================================================================
2205 //==========================================================================
2206 size_t Interpreter::GetObjectSize() const
2208 size_t s = Superclass::GetObjectSize();
2209 s += Interpreter::GetObjectInternalSize();
2212 //==========================================================================
2213 //==========================================================================
2214 size_t Interpreter::GetObjectInternalSize() const
2216 size_t s = sizeof(Interpreter);
2219 //==========================================================================
2220 //==========================================================================
2221 size_t Interpreter::GetObjectRecursiveSize() const
2223 size_t s = Superclass::GetObjectRecursiveSize();
2224 s += Interpreter::GetObjectInternalSize();
2225 s += mVirtualExecuter->GetObjectRecursiveSize();
2228 //==========================================================================