1 /*=========================================================================
3 Module: $RCSfile: bbtkInterpreter.cxx,v $
5 Date: $Date: 2012/05/30 17:17:00 $
6 Version: $Revision: 1.92 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief class Interpreter :
36 #include "bbtkInterpreter.h"
37 #include "bbtkExecuter.h"
38 #include "bbtkTranscriptor.h"
39 #include "bbtkMessageManager.h"
40 #include "bbtkConfigurationFile.h"
41 #include "bbtkUtilities.h"
42 #include "bbtkAtomicBlackBox.h"
43 #include "bbtkWxBlackBox.h"
46 #ifdef CMAKE_HAVE_TERMIOS_H
48 #define BBTK_USE_TERMIOS_BASED_PROMPT
56 //=======================================================================
57 Interpreter::Pointer Interpreter::New(const std::string& cpp_file)
59 bbtkDebugMessage("kernel",9,"Interpreter::New('"<<cpp_file<<"')"<<std::endl);
60 return MakePointer(new Interpreter(cpp_file));
62 //=======================================================================
64 //=======================================================================
65 Interpreter::Pointer Interpreter::New(VirtualExec::Pointer e)
67 bbtkDebugMessage("kernel",9,"Interpreter::New(VirtualExec)"<<std::endl);
68 return MakePointer(new Interpreter(e));
70 //=======================================================================
72 //=======================================================================
73 Interpreter::Interpreter(const std::string& cpp_file)
75 bbtkDebugMessage("object",2,"==> Interpreter("<<cpp_file<<")"<<std::endl);
76 Init(VirtualExec::Pointer(), cpp_file);
77 bbtkDebugMessage("object",2,"<== Interpreter("<<cpp_file<<")"<<std::endl);
79 //=======================================================================
81 //=======================================================================
82 Interpreter::Interpreter(VirtualExec::Pointer e)
84 bbtkDebugMessage("object",2,"==> Interpreter(VirtualExec)"<<std::endl);
86 bbtkDebugMessage("object",2,"<== Interpreter(VirtualExec)"<<std::endl);
88 //=======================================================================
90 //=======================================================================
91 void Interpreter::Init(VirtualExec::Pointer e, const std::string& cpp_file)
97 else if (cpp_file.size()!=0)
99 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(bbtk::Transcriptor::New(cpp_file));
103 bbtk::Executer::Pointer exe = bbtk::Executer::New();
105 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(exe);
110 // Lock this pointer or will auto-destruct !!
111 if (!e) mVirtualExecuter->SetInterpreter(MakePointer(this,true));
114 bbtk::InterpreterVirtual::Init();
116 //=======================================================================
120 //=======================================================================
124 Interpreter::~Interpreter()
126 bbtkDebugMessage("object",2,"==> ~Interpreter()" <<std::endl);
127 mVirtualExecuter = VirtualExec::Pointer();
128 bbtkDebugMessage("object",2,"<== ~Interpreter()" <<std::endl);
130 //=======================================================================
133 //=======================================================================
134 InterpreterException::InterpreterException( const std::string& message,
136 const std::string& script_file,
139 : Exception("interpreter",0,message),
140 mInScriptFile(in_script_file),
141 mScriptFile(script_file),
142 mScriptLine(script_line)
145 //=======================================================================
146 //=======================================================================
147 InterpreterException::InterpreterException( const Exception& excep,
149 const std::string& script_file,
153 mInScriptFile(in_script_file),
154 mScriptFile(script_file),
155 mScriptLine(script_line)
158 //=======================================================================
161 //=======================================================================
162 void Interpreter::CatchInterpreterException( const InterpreterException& e )
164 if (GetExecuter()->GetNoErrorMode())
166 bbtkWarning("ERROR :"<<e.GetErrorMessage()
167 <<" ("<<e.GetScriptFile()<<":"<<e.GetScriptLine()
173 bbtk::InterpreterVirtual::CatchInterpreterException( e );
175 //=======================================================================
177 //=======================================================================
178 void Interpreter::CatchBbtkException( const bbtk::Exception& e )
180 if (GetExecuter()->GetNoErrorMode())
182 std::string file("?");
184 if (mFileName.size()) {
185 file = mFileName.back();
188 bbtkWarning("ERROR '"<<e.GetErrorMessage()
189 <<"' ("<<file<<":"<<line<<") skipped");
194 bbtk::InterpreterVirtual::CatchBbtkException( e );
196 //=======================================================================
198 //=======================================================================
199 void Interpreter::CatchStdException( const std::exception& e )
201 if (GetExecuter()->GetNoErrorMode())
203 std::string file("?");
205 if (mFileName.size())
207 file = mFileName.back();
210 bbtkWarning("ERROR '"<<e.what() <<"' ("<<file<<":"<<line<<") skipped");
213 bbtk::InterpreterVirtual::CatchStdException( e );
215 //=======================================================================
217 //=======================================================================
218 void Interpreter::CatchUnknownException()
220 if (GetExecuter()->GetNoErrorMode())
222 std::string file("?");
224 if (mFileName.size())
226 file = mFileName.back();
229 bbtkWarning("UNDEFINED ERROR " <<"("<<file<<":"<<line<<") skipped");
233 bbtk::InterpreterVirtual::CatchUnknownException( );
235 //=======================================================================
237 //=======================================================================
239 #define CATCH_MACRO \
240 catch (InterpreterException e) \
242 CatchInterpreterException(e); \
244 catch (bbtk::Exception e) \
246 CatchBbtkException(e); \
248 catch (std::exception& e) \
250 CatchStdException(e); \
254 CatchUnknownException(); \
256 //=======================================================================
259 //=======================================================================
260 Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename, bool source )
262 bbtkDebugMessage("interpreter",4,"==> Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
264 bool exm = mCommandLine;
265 mCommandLine = false;
269 mStatus = Interpreter_OK;
270 SwitchToFile(filename,source);
271 mInsideComment = false;
272 InterpretCurrentStreams();
276 bbtkDebugMessage("interpreter",4,
277 "<== Interpreter::InterpretFile(\""
278 <<filename<<"\")"<<std::endl);
285 //=======================================================================
288 //=======================================================================
289 Interpreter::ExitStatus
290 Interpreter::InterpretBuffer( std::stringstream* buffer )
292 bbtkDebugMessage("interpreter",4,"==> Interpreter::InterpretBuffer()"<<std::endl);
294 bool exm = mCommandLine;
295 mCommandLine = false;
299 mStatus = Interpreter_OK;
300 SwitchToStream(buffer);
301 mInsideComment = false;
302 InterpretCurrentStreams();
307 bbtkDebugMessage("interpreter",4,"<== Interpreter::InterpretBuffer()"<<std::endl);
313 //=======================================================================
315 //=======================================================================
316 /// Interprets the currently open streams
317 Interpreter::ExitStatus Interpreter::InterpretCurrentStreams()
319 bbtkDebugMessage("interpreter",4,
320 "==> Interpreter::InterpretCurrentStreams()"<<std::endl);
322 while (mFile.size()>0)
324 while (!mFile.back()->eof()) {
327 mFile.back()->getline(buf,500);
328 std::string str(buf);
329 //size 0 JCP 21-09-2009
330 int size=str.length();
332 if ( str[ size-1 ]==13 )
338 DoInterpretLine(str);
346 bbtkDebugMessage("interpreter",4,
347 "<== Interpreter::InterpretCurrentStreams()"<<std::endl);
351 //=======================================================================
353 //=======================================================================
354 /// Runs the interpretation of a command
355 Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
357 bbtkDebugMessage("interpreter",5,"==> Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
361 mStatus = Interpreter_OK;
362 mInsideComment = false;
363 //std::cout<<"JCP bbtkInterpreter.cxx Interpreter::InterpretLine("<<std::endl;
364 DoInterpretLine(line );
369 bbtkDebugMessage("interpreter",5,"<== Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
373 //=======================================================================
377 void Interpreter::commandNew(const std::string &boxType,const std::string &boxName) //virtual
379 mVirtualExecuter->Create(boxType,boxName);
382 void Interpreter::commandDelete(const std::string &boxName) //virtual
384 mVirtualExecuter->Destroy(boxName);
387 void Interpreter::commandConnection(const std::string &nodeFrom,const std::string &outputLabel,const std::string &nodeTo,const std::string &inputLabel) //virtual
389 mVirtualExecuter->Connect(nodeFrom,outputLabel,nodeTo,inputLabel);
392 void Interpreter::commandPackage(const std::string &packageName) //virtual
394 mVirtualExecuter->BeginPackage(packageName);
397 void Interpreter::commandEndPackage() //virtual
399 mVirtualExecuter->EndPackage();
402 void Interpreter::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename) //virtual
404 mVirtualExecuter->Define(name,pack,scriptfilename);
407 void Interpreter::commandEndDefine() //virtual
409 mVirtualExecuter->EndDefine();
412 void Interpreter::commandKind(const std::string &kind) //virtual
414 mVirtualExecuter->Kind(kind);
417 void Interpreter::commandPrint(const std::string &value) //virtual
419 mVirtualExecuter->Print(value);
423 void Interpreter::commandExec(const std::string &word) //virtual
427 mVirtualExecuter->SetNoExecMode(true);
430 else if (word=="freeze_no_error")
432 mVirtualExecuter->SetNoExecMode(true);
433 mVirtualExecuter->SetNoErrorMode(true);
436 else if (word=="unfreeze")
438 mVirtualExecuter->SetNoExecMode(false);
439 mVirtualExecuter->SetNoErrorMode(false);
443 mVirtualExecuter->Execute(word);
448 void Interpreter::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string &help) //virtual
450 mVirtualExecuter->DefineInput(name,box,input,help);
453 void Interpreter::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string &help) //virtual
455 mVirtualExecuter->DefineOutput(name,box,output,help);
458 void Interpreter::commandSet(const std::string &box,const std::string &input,const std::string &value) //virtual
460 mVirtualExecuter->Set(box,input,value);
463 void Interpreter::commandAuthor(const std::string &author) //virtual
465 mVirtualExecuter->Author(author);
468 void Interpreter::commandCategory(const std::string &categorytype) //virtual
470 mVirtualExecuter->Category(categorytype);
473 void Interpreter::commandDescription(const std::string &description) //virtual
475 mVirtualExecuter->Description(description);
479 void Interpreter::commandClear() //virtual
481 mVirtualExecuter->Clear();
484 void Interpreter::commandInclude(const std::string &word, bool ok) //virtual
486 // if 'source' was given (words.size()==3) then tell to set the
487 // source file name of the current complex box with the full file name included
490 InterpretFile(word, ok );
494 SwitchToFile(word , ok );
499 void Interpreter::commandLoad(const std::string &packageName) //virtual
501 printf("EED Interpreter::commandLoad %s\n", packageName.c_str());
502 GetExecuter()->LoadPackage(packageName);
505 void Interpreter::commandUnload(const std::string &packageName) //virtual
507 GetExecuter()->UnLoadPackage(packageName);
510 void Interpreter::commandBreak() //virtual
513 std::cout << "BreakException("
516 <<line<<")"<<std::endl;
518 bbtkError("break");//,in_script,file,line);
519 // throw BreakException(in_script,file,line);
522 void Interpreter::commandQuit() //virtual
524 bbtkError("quit");//,in_script,file,line);
525 //throw QuitException(in_script,file,line);
528 void Interpreter::commandMessage() //virtual
530 mVirtualExecuter->HelpMessages();
533 void Interpreter::commandMessage(const std::string &kind,const std::string &levelstr) //virtual
536 sscanf(levelstr.c_str(),"%d",&level);
537 mVirtualExecuter->SetMessageLevel(kind,level);
543 //=======================================================================
544 void Interpreter::DoInterpretLine( const std::string& line ) //virtual
546 bbtkDebugMessage("interpreter",6,"==> Interpreter::DoInterpretLine(\""
547 <<line<<"\")"<<std::endl);
548 std::vector<std::string> words;
549 SplitLine(line,words);
554 bbtkDebugDecTab("interpreter",9);
558 // Single line comment : # or //
559 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
561 bbtkDebugDecTab("interpreter",9);
562 bbtkMessage("interpreter",9,"Comment"<<std::endl);
566 // Multi line comment ( / * ... * / ) -delimiters on different lines !- <<<<<<< / * * /
568 if (words[0][0]=='/' && words[0][1]=='*')
570 bbtkDebugDecTab("interpreter",9);
571 bbtkMessage("interpreter",9,"In multiline comment"<<std::endl);
572 mInsideComment = true;
576 if (words[0][0]=='*' && words[0][1]=='/')
578 bbtkDebugDecTab("interpreter",9);
579 bbtkMessage("interpreter",9,"Out multiline comment"<<std::endl);
580 if ( !mInsideComment ) {
581 bbtkDebugDecTab("interpreter",9);
582 bbtkMessage("interpreter",9,"Comment mismatch : '* /' with no matching '/ *'"<<std::endl); <<<<<<<<< * / / *
584 mInsideComment = false;
590 bbtkDebugDecTab("interpreter",9);
591 bbtkMessage("interpreter",9,"Multiline Comment"<<std::endl);
596 CommandInfoType command;
597 InterpretCommand(words,command);
598 //std::cout<<"JCP bbtkInterpreter command.keyword ="<<command.keyword<<std::endl;
599 bbtkDebugMessage("interpreter",9,
600 "Command='"<<command.keyword
601 <<"' code="<<command.code<<std::endl);
603 std::string left,right,left2,right2;
604 std::string filename;
608 if (command.code==cMessage)
613 //EED Borrame mVirtualExecuter->HelpMessages();
617 commandMessage(words[1],words[2]);
618 //EED Borrame sscanf(words[2].c_str(),"%d",&level);
619 //EED Borrame mVirtualExecuter->SetMessageLevel(words[1],level);
625 bbtkMessage("echo",2,line<<std::endl);
628 // break and quit commands
629 if ((command.code==cBreak) || (command.code==cQuit))
631 bool in_script = false;
632 std::string file("");
635 if (mFileName.size())
637 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
638 if (fs!=0) in_script = true;
639 file = mFileName.back();
642 if (command.code==cBreak)
644 // std::cout << "BreakException("
647 // <<line<<")"<<std::endl;
649 //EED Borrame bbtkError("break");//,in_script,file,line);
650 // throw BreakException(in_script,file,line);
655 //EED Borrame bbtkError("quit");//,in_script,file,line);
656 //throw QuitException(in_script,file,line);
660 //std::cout<<" mVirtualExecuter->Create(words[1],words[2]); "<<line<<std::endl;
663 switch (command.code)
666 commandNew(words[1],words[2]);
667 //EED Borrame mVirtualExecuter->Create(words[1],words[2]);
671 commandDelete(words[1]);
672 //EED Borrame mVirtualExecuter->Destroy(words[1]);
676 Utilities::SplitAroundFirstDot(words[1],left,right);
677 Utilities::SplitAroundFirstDot(words[2],left2,right2);
678 commandConnection(left,right,left2,right2);
679 //EED Borrame mVirtualExecuter->Connect(left,right,left2,right2);
683 commandPackage(words[1]);
684 //EED Borrame mVirtualExecuter->BeginPackage(words[1]);
689 //EED Borrame mVirtualExecuter->EndPackage();
693 if (mFileName.size()>0)
695 //??? commandDefine(????);
696 filename = mFileName.back(); //mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
700 commandDefine(words[1],"",filename);
701 //EED Borrame mVirtualExecuter->Define(words[1],"",filename);
705 commandDefine(words[1],words[2],filename);
706 //EED Borrame mVirtualExecuter->Define(words[1],words[2],filename);
712 //EED Borrame mVirtualExecuter->EndDefine();
716 commandKind(words[1]);
717 //EED Borrame mVirtualExecuter->Kind(words[1]);
721 commandPrint(words[1]);
722 //EED Borrame mVirtualExecuter->Print(words[1]);
726 commandExec(words[1]);
727 //EED Borrame if (words[1]=="freeze")
729 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
730 //EED Borrame mThrow = false;
732 //EED Borrame else if (words[1]=="freeze_no_error")
734 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
735 //EED Borrame mVirtualExecuter->SetNoErrorMode(true);
736 //EED Borrame mThrow = false;
738 //EED Borrame else if (words[1]=="unfreeze")
740 //EED Borrame mVirtualExecuter->SetNoExecMode(false);
741 //EED Borrame mVirtualExecuter->SetNoErrorMode(false);
745 //EED Borrame mVirtualExecuter->Execute(words[1]);
751 Utilities::SplitAroundFirstDot(words[2],left,right);
752 commandInput(words[1],left,right,words[3]);
753 //EED Borrame mVirtualExecuter->DefineInput(words[1],left,right,words[3]);
757 Utilities::SplitAroundFirstDot(words[2],left,right);
758 commandOutput(words[1],left,right,words[3]);
759 //EED Borrame mVirtualExecuter->DefineOutput(words[1],left,right,words[3]);
763 Utilities::SplitAroundFirstDot(words[1],left,right);
764 commandSet(left,right,words[2]);
765 //EED Borrame mVirtualExecuter->Set(left,right,words[2]);
769 commandAuthor(words[1]);
770 //EED Borrame mVirtualExecuter->Author(words[1]);
774 commandNewGUI(words[1],words[2]);
778 commandCategory(words[1]);
779 //EED Borrame mVirtualExecuter->Category(words[1]);
784 commandIndex("tmp_index.html");
785 else if (words.size()==2)
786 commandIndex(words[1]);
787 else if (words.size()==3)
788 commandIndex(words[1],words[2]);
792 commandDescription(words[1]);
793 //EED Borrame mVirtualExecuter->Description(words[1]);
815 //EED Borrame mVirtualExecuter->Clear();
819 commandInclude( words[1] , (words.size()==3) );
820 //EED Borrame // if 'source' was given (words.size()==3) then tell to set the
821 //EED Borrame // source file name of the current complex box with the full file name included
822 //EED Borrame if (mCommandLine)
824 //EED Borrame InterpretFile(words[1],(words.size()==3));
825 //EED Borrame } else{
826 //EED Borrame SwitchToFile(words[1],(words.size()==3) );
831 commandLoad( words[1] );
832 //EED Borrame GetExecuter()->LoadPackage(words[1]);
836 commandUnload( words[1] );
837 //EED Borrame GetExecuter()->UnLoadPackage(words[1]);
841 if (words.size()==2) commandDebug(words[1]);
842 else commandDebug("");
847 // if (words.size() == 2)
849 // if (words[1]=="freeze") mVirtualExecuter->SetNoExecMode(true);
850 // else if (words[1]=="unfreeze") mVirtualExecuter->SetNoExecMode(false);
854 // mVirtualExecuter->SetWorkspaceName(words[2]);
859 bbtkInternalError("should not reach here !!!");
862 bbtkDebugMessage("interpreter",6,"<== Interpreter::DoInterpretLine(\""
863 <<line<<"\")"<<std::endl);
866 //=======================================================================
871 //=======================================================================
872 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
874 bbtkDebugMessage("interpreter",9,"==> Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
876 std::string delimiters = "\"";
877 std::vector<std::string> quote;
878 Utilities::SplitString(str,delimiters,quote);
881 std::vector<std::string>::iterator i;
882 for (i=quote.begin(); i!=quote.end(); )
884 Utilities::SplitString(*i,delimiters,tokens);
888 // bbtkDebugMessage("interpreter",0,"\""<<*i<<"\""<<std::endl);
889 tokens.push_back(*i);
894 for (i=tokens.begin(); i!=tokens.end(); ++i)
896 bbtkDebugMessage("interpreter",9,"--["<<*i<<"]"<<std::endl);
898 bbtkDebugMessage("interpreter",9,"<== Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
901 //=======================================================================
905 //=======================================================================
906 void Interpreter::commandReset() // virtual
908 // Cannot close all files if the reset command is read from a file !
910 mFileNameHistory.clear();
911 this->mVirtualExecuter->Reset();
913 //=======================================================================
915 //=======================================================================
920 void Interpreter::Print( const std::string& str)
922 if (mVirtualExecuter->GetNoExecMode()) return;
924 bbtkDebugMessageInc("interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
927 // InterpretLine ("load std")
928 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
929 // InterpretLine("new Print _P_")
930 // InterpretLine("connect _C_.Out _P_.In")
934 std::vector<std::string> chains;
935 std::string delimiters("$");
937 // Skip delimiters at beginning.
938 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
940 if (lastPos>0) is_text = false;
942 // Find first delimiter.
943 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
945 while (std::string::npos != pos || std::string::npos != lastPos)
949 // Found a text token, add it to the vector.
950 chains.push_back(str.substr(lastPos, pos - lastPos));
951 // std::string token = str.substr(lastPos, pos - lastPos)
952 // InterpretLine("set _C_.In%num% %token%")
958 // is an output (between $$) : decode
959 std::string tok,box,output;
960 tok = str.substr(lastPos, pos - lastPos);
961 Utilities::SplitAroundFirstDot(tok,box,output);
962 chains.push_back( mVirtualExecuter->Get(box,output) );
964 // InterpretLine("connect %tok% _C_.In%num%")
967 // Skip delimiters. Note the "not_of"
968 lastPos = str.find_first_not_of(delimiters, pos);
969 // Find next delimiter
970 pos = str.find_first_of(delimiters, lastPos);
975 // InterpretLine("exec _P_")
976 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
978 std::vector<std::string>::iterator i;
979 for (i= chains.begin(); i!=chains.end(); ++i)
982 Utilities::SubsBackslashN(*i);
985 std::cout << std::endl;
986 bbtkDebugDecTab("interpreter",9);
990 //=======================================================================
995 // =========================================================================
996 void Interpreter::SwitchToFile( const std::string& name , bool source )
998 // Note : in the following :
999 // name : the user supplied name
1000 // - abreviated name e.g. scr scr.bbs
1001 // - relative full name e.g. ./scr.bbs ../../scr.bbs
1002 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
1003 // same for Windows, with c:, d: ...
1005 // use ./directory/subdir/scrname.bbs
1008 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToFile( \""
1009 <<name<<"\")"<<std::endl);
1011 std::vector<std::string> script_paths;
1012 std::string fullPathScriptName; // full path script name
1013 std::string pkgname; // e.g. <scriptname>.bbs
1014 std::vector<std::string> Filenames;
1016 // The following is *NOT* a debug time message :
1017 // It's a user intended message.
1018 // Please don't remove it.
1019 bbtkMessage("interpreter",1,
1020 "look for : [" << name
1021 << "]" << std::endl);
1025 pkgname = Utilities::ExtractScriptName(name,upath);
1027 bbtkMessage("interpreter",3,
1028 "package name:[" << pkgname
1029 << "] path:[" << upath << "]" << std::endl);
1030 bool fullnameGiven = false;
1031 bool foundFile = false;
1033 // ==== "*" provided : load all scripts in given path
1034 // relative (e.g. std/boxes/ *) or absolute <<<<<<<< / *
1038 std::stringstream* stream = new std::stringstream;
1039 //if (upath.size()!=0) // avoid troubles for "*"
1041 // ==== no path provided : look in root bbs path
1042 if (upath.size()==0)
1044 // bbtkMessage("interpreter",1,
1045 // LG : add all bbs path
1046 // script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1047 std::vector<std::string>::const_iterator i;
1048 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1049 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1052 script_paths.push_back(*i);
1055 // ==== absolute path provided
1056 else if (upath[0]=='/' || upath[1] == ':' )
1058 if ( Utilities::IsDirectory( upath ) )
1060 script_paths.push_back(upath);
1064 bbtkError("'"<<upath<<"' : directory does not exist");
1067 // ==== relative path provided : search all bbs path appended with
1068 // the relative path provided
1071 std::vector<std::string>::const_iterator i;
1072 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1073 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1076 std::string full_path(*i);
1077 // we *really* want '.' to be the current working directory
1078 if (full_path == ".")
1080 char buf[2048]; // for getcwd
1081 char * currentDir = getcwd(buf, 2048);
1082 std::string cwd(currentDir);
1083 full_path = currentDir;
1086 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1089 if ( Utilities::IsDirectory( full_path ) )
1091 script_paths.push_back(full_path);
1094 if (script_paths.empty())
1096 bbtkError("no '"<<upath<<"' subdir found in search paths"
1102 // === search paths list complete : now explore it
1104 // ==== relative name, iterate + load all .bbs/.bbp files
1105 std::vector<std::string>::iterator i;
1106 for (i=script_paths.begin();i!=script_paths.end();i++)
1108 bbtkMessage("interpreter",1,
1109 "--> Looking in '" << *i << "'" << std::endl);
1113 Utilities::Explore(*i, false, Filenames);
1115 for (std::vector<std::string>::iterator j = Filenames.begin();
1116 j!= Filenames.end(); ++j)
1118 int lgr = (*j).size();
1119 if (lgr < 5) continue;
1120 // ignore non .bbp file
1121 if ( (*j).substr(lgr-4, 4) != ".bbp") continue;
1123 (*stream) << "include \"" << *j << "\"\n";
1124 bbtkMessage("interpreter",2," --> Found '" << *j << "'" << std::endl);
1127 } // for (std::vector...
1128 } // for (i=script_...
1133 bbtkMessage("interpreter",1,
1134 " --> No .bbp found"<< std::endl);
1138 bbtkMessage("interpreter",1,
1139 " --> "<<nbBssFiles<<" .bbp found"<< std::endl);
1140 SwitchToStream(stream);
1144 //=============== end pkgname=="*" ===========
1147 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1148 // (not only a plain script name)
1149 // we trust him, and try to expland the directory name
1150 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1152 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1155 // ===========================================================check user supplied location
1156 fullnameGiven = true;
1158 fullPathScriptName = Utilities::ExpandLibName(name, false);
1160 // allow user to always forget ".bbs"
1161 int l = fullPathScriptName.size();
1165 if ((fullPathScriptName.substr(l-4, 4) != ".bbs")&&
1166 (fullPathScriptName.substr(l-4, 4) != ".bbp"))
1168 std::string tfullPathScriptName = fullPathScriptName + ".bbs";
1169 if ( Utilities::FileExists(tfullPathScriptName) )
1171 fullPathScriptName = tfullPathScriptName;
1176 tfullPathScriptName = fullPathScriptName + ".bbp";
1177 if ( Utilities::FileExists(tfullPathScriptName) )
1179 fullPathScriptName = tfullPathScriptName;
1186 if ( Utilities::FileExists(fullPathScriptName) )
1194 // =============================== iterate on the paths
1196 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1198 std::vector<std::string>::iterator i;
1199 for (i=script_paths.begin();i!=script_paths.end();++i)
1202 // we *really* want '.' to be the current working directory
1205 char buf[2048]; // for getcwd
1206 char * currentDir = getcwd(buf, 2048);
1207 std::string cwd(currentDir);
1211 std::string tfullPathScriptName = Utilities::MakePkgnameFromPath(path, name, false);
1212 //Addition JCP tfullPathScriptName.size()>=4
1213 if(tfullPathScriptName.size()>=4){
1214 if (tfullPathScriptName.substr(tfullPathScriptName.size()-4, 3)==".bb")
1216 fullPathScriptName = tfullPathScriptName;
1217 if ( ! Utilities::FileExists(fullPathScriptName) )
1219 // The following is *NOT* a debug time message :
1220 // It's a user intended message.
1221 // Please don't remove it.
1222 bbtkMessage("interpreter",2,
1223 " [" <<fullPathScriptName <<"] : does not exist"
1225 continue; // try next path
1227 bbtkMessage("interpreter",2,
1228 " [" <<fullPathScriptName
1229 <<"] : found" <<std::endl);
1231 break; // a script was found; we stop iterating
1235 fullPathScriptName = tfullPathScriptName + ".bbs";
1236 // Check if library exists
1237 if ( ! Utilities::FileExists(fullPathScriptName) )
1239 fullPathScriptName = tfullPathScriptName + ".bbp";
1240 if ( ! Utilities::FileExists(fullPathScriptName) )
1242 // The following is *NOT* a debug time message :
1243 // It's a user intended message.
1244 // Please don't remove it.
1245 bbtkMessage("interpreter",2,
1246 " [" <<tfullPathScriptName <<".bbs/.bbp] : do not exist"
1248 continue; // try next path
1251 bbtkMessage("interpreter",2,
1252 " [" <<fullPathScriptName
1253 <<"] : found" <<std::endl);
1255 break; // a script was found; we stop iterating
1258 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1264 if(fullPathScriptName == "")
1265 bbtkError("Path ["<<upath<<"] doesn't exist");
1267 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1269 bbtkError("No ["<<pkgname<<".bbs/.bbp] script found");
1274 LoadScript(fullPathScriptName,name);
1275 if (source) SetCurrentFileName(fullPathScriptName);
1280 //=======================================================================
1283 //=======================================================================
1284 void Interpreter::SetCurrentFileName(const std::string &fullPathScriptName) // virtual
1286 GetExecuter()->SetCurrentFileName(fullPathScriptName);
1288 //=======================================================================
1291 //=======================================================================
1292 void Interpreter::SwitchToStream( std::stringstream* stream )
1294 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToStream()"
1296 mFile.push_back(stream);
1297 std::ostringstream buffer_name;
1299 buffer_name << "buffer_" ;
1301 if (mFileName.size()>0 )
1303 buffer_name << mFileName.back() << "_" << mLine.back();
1305 mFileName.push_back(buffer_name.str());
1306 mIncludeFileName.push_back(buffer_name.str());
1309 //=======================================================================
1313 //=======================================================================
1314 void Interpreter::LoadScript( std::string fullPathScriptName,
1315 std::string includeScriptName)
1317 bbtkDebugMessage("interpreter",4,"==> Interpreter::LoadScript("
1318 <<fullPathScriptName<<")"
1321 Utilities::replace( fullPathScriptName ,
1322 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1324 if (find(mFileNameHistory.begin(),
1325 mFileNameHistory.end(),
1326 fullPathScriptName)!=mFileNameHistory.end())
1332 s = new std::ifstream;
1333 s->open(fullPathScriptName.c_str());
1336 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1340 bbtkMessage("interpreter",1," -->[" << fullPathScriptName
1341 << "] found" << std::endl);
1344 mFileName.push_back(fullPathScriptName);
1345 mFileNameHistory.push_back(fullPathScriptName);
1346 mIncludeFileName.push_back(includeScriptName);
1351 //=======================================================================
1355 //=======================================================================
1356 void Interpreter::CloseCurrentFile()
1358 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseCurrentFile()"
1361 if (mFile.size()==0)
1363 bbtkDebugMessage("interpreter",9," -> no file left open"<<std::endl);
1367 bbtkDebugMessage("interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1369 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1370 if (file!=0) file->close();
1372 delete mFile.back();
1374 mFileName.pop_back();
1375 mIncludeFileName.pop_back();
1378 bbtkDebugMessage("interpreter",9," Remains "
1380 <<" open"<<std::endl);
1381 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseCurrentFile()"
1384 //=======================================================================
1386 //=======================================================================
1387 void Interpreter::CloseAllFiles()
1389 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseAllFiles()"
1392 while (mFile.size() != 0)
1396 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseAllFiles()"
1399 //=======================================================================
1402 //=======================================================================
1403 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1404 CommandInfoType& info )
1406 bbtkDebugMessage("interpreter",9,"==> Interpreter::InterpretCommand(...)"<<std::endl);
1408 // searches the command keyword
1409 CommandDictType::iterator c;
1410 c = mCommandDict.find(words[0]);
1411 if ( c == mCommandDict.end() ) {
1412 bbtkError(words[0]<<" : unknown command");
1415 // tests the number of args
1416 if ( ( ((int)words.size())-1 < c->second.argmin ) ||
1417 ( ((int)words.size())-1 > c->second.argmax ) )
1419 commandHelp(words[0]);
1420 bbtkError(words[0]<<" : wrong number of arguments");
1422 //std::cout<<"Interpreter::InterpretCommand( const std::vector<std::string>& words,"<<std::endl;
1425 bbtkDebugMessage("interpreter",9,"<== Interpreter::InterpretCommand(...)"<<std::endl);
1428 //=======================================================================
1432 //=======================================================================
1433 /// Displays help on all the commands
1434 void Interpreter::commandHelp(const std::vector<std::string>& words)
1436 unsigned int nbarg = words.size()-1;
1444 if (words[1]=="packages")
1446 GetExecuter()->GetFactory()->PrintHelpListPackages(true);
1451 commandHelp(words[1]);
1453 catch (bbtk::Exception e)
1457 GetExecuter()->GetFactory()->PrintHelpPackage(words[1]);
1461 ConfigurationFile::GetInstance().Get_doc_path();
1462 url += "/bbdoc/" + words[1] + "/index.html";
1463 if (Utilities::FileExists(url))
1465 mUser->InterpreterUserViewHtmlPage(url);
1469 catch (bbtk::Exception f)
1473 std::string package;
1474 GetExecuter()->GetFactory()->PrintHelpDescriptor(words[1],
1479 ConfigurationFile::GetInstance().Get_doc_path();
1480 url += "/bbdoc/" + package + "/index.html";
1481 if (Utilities::FileExists(url))
1483 url += "#" + words[1];
1484 mUser->InterpreterUserViewHtmlPage(url);
1488 catch (bbtk::Exception g)
1492 GetExecuter()->PrintHelpBlackBox(words[1],"0","9999");
1494 catch (bbtk::Exception h){
1495 bbtkError("\""<<words[1].c_str()
1496 <<"\" is not a known command, package, black box type or black box name");
1504 if (words[2]=="all")
1506 if ( words[1]=="packages" )
1508 GetExecuter()->GetFactory()->PrintHelpListPackages(true,true);
1513 GetExecuter()->GetFactory()->PrintHelpPackage(words[1],true);
1515 catch (bbtk::Exception f)
1521 commandHelp(words[0]);
1522 bbtkError(words[0]<<" : syntax error");
1527 bbtkError("Should not reach here !!!");
1530 //=======================================================================
1532 //===================================================================
1533 /// Displays the Configuration
1534 void Interpreter::commandConfig() const
1536 ConfigurationFile::GetInstance().GetHelp(1);
1538 //===================================================================
1540 //=======================================================================
1541 /// Displays help on all the commands
1542 void Interpreter::HelpCommands()
1544 std::cout << "Available commands :" << std::endl;
1545 CommandDictType::iterator i;
1546 for ( i = mCommandDict.begin();
1547 i != mCommandDict.end();
1549 std::cout << " " << i->first << std::endl;
1550 // std::cout << " usage : " << i->second.syntax << std::endl;
1551 // std::cout << " " << i->second.help << std::endl;
1555 //=======================================================================
1559 //=======================================================================
1560 /// Displays help on a particular commands
1561 void Interpreter::commandHelp(const std::string& s)
1563 CommandDictType::iterator c;
1564 c = mCommandDict.find(s);
1565 if ( c == mCommandDict.end() ) {
1566 bbtkError(s<<" : Unknown command");
1568 // std::cout << " " << s << " : "<< std::endl;
1569 // CommandParamDictType::iterator i;
1570 // for ( i = c->second.begin();
1571 // i != c->second.end();
1573 std::cout << " usage : " << c->second.syntax << std::endl;
1574 std::cout << " " << c->second.help << std::endl;
1577 //=======================================================================
1580 //=======================================================================
1581 /// Fills the vector commands with the commands which
1582 /// have the first n chars of buf for prefix
1583 /// TODO : skip initial spaces in buf and also return the position of first
1584 /// non blank char in buf
1585 void Interpreter::FindCommandsWithPrefix( char* buf,
1587 std::vector<std::string>& commands )
1589 CommandDictType::const_iterator i;
1590 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1592 if ((i->first).find(buf,0,n) == 0)
1593 commands.push_back(i->first);
1596 //=======================================================================
1601 //=======================================================================
1602 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1604 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1605 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1607 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1608 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1609 // E.G. STORE THIS IN bbtk_config.xml
1610 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1611 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1612 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1613 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1614 #define BBTK_BACKSPACE_KBCODE 0x00000008
1615 #define BBTK_DEL_KBCODE 0x0000007F
1616 #define BBTK_SPACE_KBCODE 0x00000020
1618 //=======================================================================
1619 void Interpreter::GetLineFromPrompt(std::string& s)
1624 unsigned int MAX_LINE_SIZE = 160;
1625 unsigned int MAX_HISTORY_SIZE = 100;
1627 char* newline = new char[MAX_LINE_SIZE];
1628 memset(newline,0,MAX_LINE_SIZE);
1629 char* histline = new char[MAX_LINE_SIZE];
1630 memset(histline,0,MAX_LINE_SIZE);
1632 char* line = newline;
1633 unsigned int hist = mHistory.size();
1639 read ( STDIN_FILENO, &c, 4) ;
1641 bbtkDebugMessage("debug",9,"[0x"<<std::hex<<c<<"]\n");
1643 // Printable character
1644 if ( (ind<MAX_LINE_SIZE-1) &&
1645 ( c >= BBTK_SPACE_KBCODE ) &&
1646 ( c < BBTK_DEL_KBCODE ))
1654 // delete the unused line
1660 // empty lines are not stored in from history
1663 // if history too long : delete oldest command
1664 if (mHistory.size()>MAX_HISTORY_SIZE)
1666 delete mHistory.front();
1667 mHistory.pop_front();
1669 mHistory.push_back(line);
1674 else if ( (ind>0) &&
1675 ((c == BBTK_BACKSPACE_KBCODE) ||
1676 (c == BBTK_DEL_KBCODE)) )
1684 // TODO : Command completion
1685 std::vector<std::string> commands;
1686 FindCommandsWithPrefix( line,ind,commands);
1687 if (commands.size()==1)
1689 std::string com = *commands.begin();
1690 for (; ind<com.size(); ++ind)
1692 PrintChar(com[ind]);
1698 else if (commands.size()>1)
1700 std::vector<std::string>::iterator i;
1702 for (i=commands.begin();i!=commands.end();++i)
1704 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1707 write(STDOUT_FILENO,"\n> ",3);
1708 //for (int j=0;j<ind;++j)
1710 write(STDOUT_FILENO,line,ind);
1714 // Arrow up : back in history
1715 else if (c==BBTK_UP_ARROW_KBCODE)
1719 // erase current line
1720 while (ind--) BackSpace();
1724 strcpy(histline,mHistory[hist]);
1728 write(STDOUT_FILENO,line,ind);
1731 // Arrow down : down in history
1732 else if (c==BBTK_DOWN_ARROW_KBCODE)
1734 if (hist<mHistory.size()-1)
1736 // erase current line
1737 while (ind--) BackSpace();
1741 strcpy(histline,mHistory[hist]);
1745 write(STDOUT_FILENO,line,ind);
1747 // end of history : switch back to newline
1748 else if (hist==mHistory.size()-1)
1750 // erase current line
1751 while (ind--) BackSpace();
1758 write(STDOUT_FILENO,line,ind);
1762 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1764 PrintChar(line[ind]);
1769 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1777 write(STDOUT_FILENO,"\n\r",2);
1785 //=======================================================================
1786 void Interpreter::GetLineFromPrompt(std::string& s)
1812 //=======================================================================
1823 //=======================================================================
1824 void Interpreter::CommandLineInterpreter()
1826 bbtkDebugMessageInc("interpreter",9,
1827 "Interpreter::CommandLineInterpreter()"<<std::endl);
1829 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1830 // Initialise the tty in non canonical mode with no echo
1831 // oter remembers the previous settings to restore them after
1832 struct termios ter,oter;
1835 ter.c_lflag &= ~ECHO;
1836 ter.c_lflag &= ~ICANON;
1839 tcsetattr(0,TCSANOW,&ter);
1842 mCommandLine = true;
1844 // bool insideComment = false; // for multiline comment
1845 mInsideComment = false;
1851 GetLineFromPrompt(line);
1852 DoInterpretLine(line); //, insideComment);
1854 // catch (QuitException e)
1856 // bbtkMessage("interpreter",1,"Interpreter : Quit"<<std::endl);
1859 catch (bbtk::Exception e)
1863 catch (std::exception& e)
1865 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1869 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1874 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1875 tcsetattr(0,TCSANOW,&oter);
1878 std::cout << "Good bye !" << std::endl;
1880 bbtkDebugDecTab("interpreter",9);
1884 //=======================================================================
1885 void Interpreter::commandGraph(const std::vector<std::string>& words)
1888 bool system_display = true;
1890 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1891 system_display = false;
1893 if (words.size()==1)
1895 page = mVirtualExecuter->ShowGraph(".","0","0","","","",system_display);
1897 else if (words.size()==2)
1899 page = mVirtualExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1901 else if (words.size()==3)
1903 page = mVirtualExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1905 else if (words.size()==4)
1907 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1909 else if (words.size()==5)
1911 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1913 else if (words.size()==6)
1915 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1917 else if (words.size()==7)
1919 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1922 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1923 mUser->InterpreterUserViewHtmlPage(page);
1926 //=======================================================================
1929 //=======================================================================
1930 void Interpreter::commandIndex(const std::string& filename,
1931 const std::string& type)
1933 Factory::IndexEntryType t;
1934 if (type=="Initials") t = Factory::Initials;
1935 else if (type=="Categories") t = Factory::Categories;
1936 else if (type=="Packages") t = Factory::Packages;
1937 else if (type=="Adaptors") t = Factory::Adaptors;
1939 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1941 //=======================================================================
1944 //=======================================================================
1945 void Interpreter::commandNewGUI(const std::string& boxname,
1946 const std::string& instanceName)
1948 if (mRealExecuter.expired())
1950 bbtkError("command 'newgui' cannot be compiled yet");
1953 std::string typeName = instanceName+"Type";
1954 std::stringstream* s = new std::stringstream;
1955 // create the complex box
1956 (*s) << "define "<<typeName<<std::endl;
1957 // (*s) << " description 'Automatically generated user interface for the box "
1958 // << boxname << "'" <<std::endl;
1959 // create the Layout box
1960 (*s) << " load wx"<<std::endl;
1961 (*s) << " new LayoutLine layout"<<std::endl;
1962 // create the output 'Widget'
1963 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1964 // the box change output
1965 (*s) << " new MultipleInputs change"<<std::endl;
1966 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1968 // Browse the inputs of the box in order to find which ones are not
1969 // connected and can be adapted from a widget adaptor
1970 // vector which stores the list of inputs of the box which must be connected
1971 std::vector<std::string> in;
1973 Factory::Pointer F = mVirtualExecuter->GetFactory();
1975 Package::Pointer user = F->GetPackage("user");
1977 ComplexBlackBoxDescriptor::Pointer workspace =
1978 mRealExecuter.lock()->GetCurrentDescriptor();
1983 bbtkError("interpreter::CreateGUI : could not access the executer currently defined complex box");
1988 (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get());
1991 BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname);
1992 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
1994 BlackBox::InputConnectorMapType::iterator i;
1995 for (i=box->bbGetInputConnectorMap().begin();
1996 i!=box->bbGetInputConnectorMap().end();
1999 // If the input is connected : continue
2000 if (i->second->IsConnected()) continue;
2001 // Get the input descriptor
2002 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
2003 // If it is a "system" input : skip it
2004 #ifdef USE_WXWIDGETS
2005 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
2006 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
2009 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) )
2013 std::string widget,adaptor;
2014 // try to find a widget adaptor
2015 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
2019 // command to create the adaptor
2020 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2021 // Sets the label of the widget adaptor to the name of the input
2022 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
2023 // Sets the initial value of the widget to the value of the input
2024 (*s) << " set "<<i->first<<".In \" "
2025 <<box->bbGetInputAsString(i->first)<<"\""
2027 // store the input name
2028 in.push_back(i->first);
2029 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2030 //<i->first<<"'"<<std::endl;
2031 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2033 // try to find a two pieces adaptor
2034 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
2038 // command to create the widget
2039 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
2040 // command to create the adaptor
2041 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2043 (*s) << " connect "<<i->first<<"Widget.Out "
2044 <<i->first<<".In"<<std::endl;
2045 // Sets the label of the widget adaptor to the name of the input
2046 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
2047 // Sets the initial value of the widget to the value of the input
2048 (*s) << " set "<<i->first<<"Widget.In \" "
2049 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2050 // store the input name
2051 in.push_back(i->first);
2052 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
2053 //<i->first<<"'"<<std::endl;
2054 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
2057 // try to find an adaptor from string
2058 // If found then can create a text input which
2059 // will be automatically adapted
2060 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
2064 // command to create the adaptor
2065 (*s) << " new InputText "<<i->first<<std::endl;
2066 // Sets the label of the widget adaptor to the name of the input
2067 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
2068 // Sets the initial value of the widget to the value of the input
2069 (*s) << " set "<<i->first<<".In \" "
2070 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2071 // store the input name
2072 in.push_back(i->first);
2073 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2074 //<i->first<<"'"<<std::endl;
2075 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2084 // command to create the output
2085 (*s) << " output "<<i->first<<" "
2086 <<i->first<<".Out "<<i->first<<std::endl;
2087 // <<" Output of the widget which allows to set "
2091 // Inputs for window properties
2092 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
2093 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
2094 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
2095 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
2096 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
2100 // Execute the box executes the layout
2101 (*s) << " exec layout" << std::endl;
2102 (*s) << "endefine" << std::endl;
2103 // (*s) << "help "<< typeName<< std::endl;
2104 // instanciate the box and connect it
2105 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2107 std::vector<std::string>::iterator j;
2108 for (j=in.begin();j!=in.end();++j)
2111 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2112 << boxname<<"."<<*j<<std::endl;
2114 // That's all folks ! now execute the commands :
2117 //=======================================================================
2121 //==========================================================================
2122 void Interpreter::commandDebug(const std::string& name)
2124 if ((name.length()==2)&&(name[0]=='-'))
2128 bbtk::StaticInitTime::PrintObjectListInfo = true;
2132 // int o = MessageManager::GetMessageLevel("debug");
2133 // if (o<2) MessageManager::SetMessageLevel("debug",2);
2134 mVirtualExecuter->GetFactory()->Check();
2135 // MessageManager::SetMessageLevel("debug",o);
2140 Object:: PrintObjectListInfo(name);
2143 //==========================================================================
2146 //==========================================================================
2147 // Adds a callback when 'break' command issued
2148 void Interpreter::AddBreakObserver( BreakCallbackType c )
2150 mBreakSignal.connect(c);
2152 //==========================================================================
2155 //==========================================================================
2156 std::string Interpreter::GetObjectName() const
2158 return std::string("Interpreter");
2160 //==========================================================================
2162 //==========================================================================
2163 std::string Interpreter::GetObjectInfo() const
2165 std::stringstream i;
2168 //==========================================================================
2170 //==========================================================================
2171 size_t Interpreter::GetObjectSize() const
2173 size_t s = Superclass::GetObjectSize();
2174 s += Interpreter::GetObjectInternalSize();
2177 //==========================================================================
2178 //==========================================================================
2179 size_t Interpreter::GetObjectInternalSize() const
2181 size_t s = sizeof(Interpreter);
2184 //==========================================================================
2185 //==========================================================================
2186 size_t Interpreter::GetObjectRecursiveSize() const
2188 size_t s = Superclass::GetObjectRecursiveSize();
2189 s += Interpreter::GetObjectInternalSize();
2190 s += mVirtualExecuter->GetObjectRecursiveSize();
2193 //==========================================================================