1 /*=========================================================================
3 Module: $RCSfile: bbtkInterpreter.cxx,v $
5 Date: $Date: 2010/09/18 22:31:40 $
6 Version: $Revision: 1.91 $
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 GetExecuter()->LoadPackage(packageName);
504 void Interpreter::commandUnload(const std::string &packageName) //virtual
506 GetExecuter()->UnLoadPackage(packageName);
509 void Interpreter::commandBreak() //virtual
512 std::cout << "BreakException("
515 <<line<<")"<<std::endl;
517 bbtkError("break");//,in_script,file,line);
518 // throw BreakException(in_script,file,line);
521 void Interpreter::commandQuit() //virtual
523 bbtkError("quit");//,in_script,file,line);
524 //throw QuitException(in_script,file,line);
527 void Interpreter::commandMessage() //virtual
529 mVirtualExecuter->HelpMessages();
532 void Interpreter::commandMessage(const std::string &kind,const std::string &levelstr) //virtual
535 sscanf(levelstr.c_str(),"%d",&level);
536 mVirtualExecuter->SetMessageLevel(kind,level);
542 //=======================================================================
543 void Interpreter::DoInterpretLine( const std::string& line ) //virtual
545 bbtkDebugMessage("interpreter",6,"==> Interpreter::DoInterpretLine(\""
546 <<line<<"\")"<<std::endl);
547 std::vector<std::string> words;
548 SplitLine(line,words);
553 bbtkDebugDecTab("interpreter",9);
557 // Single line comment : # or //
558 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
560 bbtkDebugDecTab("interpreter",9);
561 bbtkMessage("interpreter",9,"Comment"<<std::endl);
565 // Multi line comment ( / * ... * / ) -delimiters on different lines !- <<<<<<< / * * /
567 if (words[0][0]=='/' && words[0][1]=='*')
569 bbtkDebugDecTab("interpreter",9);
570 bbtkMessage("interpreter",9,"In multiline comment"<<std::endl);
571 mInsideComment = true;
575 if (words[0][0]=='*' && words[0][1]=='/')
577 bbtkDebugDecTab("interpreter",9);
578 bbtkMessage("interpreter",9,"Out multiline comment"<<std::endl);
579 if ( !mInsideComment ) {
580 bbtkDebugDecTab("interpreter",9);
581 bbtkMessage("interpreter",9,"Comment mismatch : '* /' with no matching '/ *'"<<std::endl); <<<<<<<<< * / / *
583 mInsideComment = false;
589 bbtkDebugDecTab("interpreter",9);
590 bbtkMessage("interpreter",9,"Multiline Comment"<<std::endl);
595 CommandInfoType command;
596 InterpretCommand(words,command);
597 //std::cout<<"JCP bbtkInterpreter command.keyword ="<<command.keyword<<std::endl;
598 bbtkDebugMessage("interpreter",9,
599 "Command='"<<command.keyword
600 <<"' code="<<command.code<<std::endl);
602 std::string left,right,left2,right2;
603 std::string filename;
607 if (command.code==cMessage)
612 //EED Borrame mVirtualExecuter->HelpMessages();
616 commandMessage(words[1],words[2]);
617 //EED Borrame sscanf(words[2].c_str(),"%d",&level);
618 //EED Borrame mVirtualExecuter->SetMessageLevel(words[1],level);
624 bbtkMessage("echo",2,line<<std::endl);
627 // break and quit commands
628 if ((command.code==cBreak) || (command.code==cQuit))
630 bool in_script = false;
631 std::string file("");
634 if (mFileName.size())
636 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
637 if (fs!=0) in_script = true;
638 file = mFileName.back();
641 if (command.code==cBreak)
643 // std::cout << "BreakException("
646 // <<line<<")"<<std::endl;
648 //EED Borrame bbtkError("break");//,in_script,file,line);
649 // throw BreakException(in_script,file,line);
654 //EED Borrame bbtkError("quit");//,in_script,file,line);
655 //throw QuitException(in_script,file,line);
659 //std::cout<<" mVirtualExecuter->Create(words[1],words[2]); "<<line<<std::endl;
662 switch (command.code)
665 commandNew(words[1],words[2]);
666 //EED Borrame mVirtualExecuter->Create(words[1],words[2]);
670 commandDelete(words[1]);
671 //EED Borrame mVirtualExecuter->Destroy(words[1]);
675 Utilities::SplitAroundFirstDot(words[1],left,right);
676 Utilities::SplitAroundFirstDot(words[2],left2,right2);
677 commandConnection(left,right,left2,right2);
678 //EED Borrame mVirtualExecuter->Connect(left,right,left2,right2);
682 commandPackage(words[1]);
683 //EED Borrame mVirtualExecuter->BeginPackage(words[1]);
688 //EED Borrame mVirtualExecuter->EndPackage();
692 if (mFileName.size()>0)
694 //??? commandDefine(????);
695 filename = mFileName.back(); //mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
699 commandDefine(words[1],"",filename);
700 //EED Borrame mVirtualExecuter->Define(words[1],"",filename);
704 commandDefine(words[1],words[2],filename);
705 //EED Borrame mVirtualExecuter->Define(words[1],words[2],filename);
711 //EED Borrame mVirtualExecuter->EndDefine();
715 commandKind(words[1]);
716 //EED Borrame mVirtualExecuter->Kind(words[1]);
720 commandPrint(words[1]);
721 //EED Borrame mVirtualExecuter->Print(words[1]);
725 commandExec(words[1]);
726 //EED Borrame if (words[1]=="freeze")
728 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
729 //EED Borrame mThrow = false;
731 //EED Borrame else if (words[1]=="freeze_no_error")
733 //EED Borrame mVirtualExecuter->SetNoExecMode(true);
734 //EED Borrame mVirtualExecuter->SetNoErrorMode(true);
735 //EED Borrame mThrow = false;
737 //EED Borrame else if (words[1]=="unfreeze")
739 //EED Borrame mVirtualExecuter->SetNoExecMode(false);
740 //EED Borrame mVirtualExecuter->SetNoErrorMode(false);
744 //EED Borrame mVirtualExecuter->Execute(words[1]);
750 Utilities::SplitAroundFirstDot(words[2],left,right);
751 commandInput(words[1],left,right,words[3]);
752 //EED Borrame mVirtualExecuter->DefineInput(words[1],left,right,words[3]);
756 Utilities::SplitAroundFirstDot(words[2],left,right);
757 commandOutput(words[1],left,right,words[3]);
758 //EED Borrame mVirtualExecuter->DefineOutput(words[1],left,right,words[3]);
762 Utilities::SplitAroundFirstDot(words[1],left,right);
763 commandSet(left,right,words[2]);
764 //EED Borrame mVirtualExecuter->Set(left,right,words[2]);
768 commandAuthor(words[1]);
769 //EED Borrame mVirtualExecuter->Author(words[1]);
773 commandNewGUI(words[1],words[2]);
777 commandCategory(words[1]);
778 //EED Borrame mVirtualExecuter->Category(words[1]);
783 commandIndex("tmp_index.html");
784 else if (words.size()==2)
785 commandIndex(words[1]);
786 else if (words.size()==3)
787 commandIndex(words[1],words[2]);
791 commandDescription(words[1]);
792 //EED Borrame mVirtualExecuter->Description(words[1]);
814 //EED Borrame mVirtualExecuter->Clear();
818 commandInclude( words[1] , (words.size()==3) );
819 //EED Borrame // if 'source' was given (words.size()==3) then tell to set the
820 //EED Borrame // source file name of the current complex box with the full file name included
821 //EED Borrame if (mCommandLine)
823 //EED Borrame InterpretFile(words[1],(words.size()==3));
824 //EED Borrame } else{
825 //EED Borrame SwitchToFile(words[1],(words.size()==3) );
830 commandLoad( words[1] );
831 //EED Borrame GetExecuter()->LoadPackage(words[1]);
835 commandUnload( words[1] );
836 //EED Borrame GetExecuter()->UnLoadPackage(words[1]);
840 if (words.size()==2) commandDebug(words[1]);
841 else commandDebug("");
846 // if (words.size() == 2)
848 // if (words[1]=="freeze") mVirtualExecuter->SetNoExecMode(true);
849 // else if (words[1]=="unfreeze") mVirtualExecuter->SetNoExecMode(false);
853 // mVirtualExecuter->SetWorkspaceName(words[2]);
858 bbtkInternalError("should not reach here !!!");
861 bbtkDebugMessage("interpreter",6,"<== Interpreter::DoInterpretLine(\""
862 <<line<<"\")"<<std::endl);
865 //=======================================================================
870 //=======================================================================
871 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
873 bbtkDebugMessage("interpreter",9,"==> Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
875 std::string delimiters = "\"";
876 std::vector<std::string> quote;
877 Utilities::SplitString(str,delimiters,quote);
880 std::vector<std::string>::iterator i;
881 for (i=quote.begin(); i!=quote.end(); )
883 Utilities::SplitString(*i,delimiters,tokens);
887 // bbtkDebugMessage("interpreter",0,"\""<<*i<<"\""<<std::endl);
888 tokens.push_back(*i);
893 for (i=tokens.begin(); i!=tokens.end(); ++i)
895 bbtkDebugMessage("interpreter",9,"--["<<*i<<"]"<<std::endl);
897 bbtkDebugMessage("interpreter",9,"<== Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
900 //=======================================================================
904 //=======================================================================
905 void Interpreter::commandReset() // virtual
907 // Cannot close all files if the reset command is read from a file !
909 mFileNameHistory.clear();
910 this->mVirtualExecuter->Reset();
912 //=======================================================================
914 //=======================================================================
919 void Interpreter::Print( const std::string& str)
921 if (mVirtualExecuter->GetNoExecMode()) return;
923 bbtkDebugMessageInc("interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
926 // InterpretLine ("load std")
927 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
928 // InterpretLine("new Print _P_")
929 // InterpretLine("connect _C_.Out _P_.In")
933 std::vector<std::string> chains;
934 std::string delimiters("$");
936 // Skip delimiters at beginning.
937 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
939 if (lastPos>0) is_text = false;
941 // Find first delimiter.
942 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
944 while (std::string::npos != pos || std::string::npos != lastPos)
948 // Found a text token, add it to the vector.
949 chains.push_back(str.substr(lastPos, pos - lastPos));
950 // std::string token = str.substr(lastPos, pos - lastPos)
951 // InterpretLine("set _C_.In%num% %token%")
957 // is an output (between $$) : decode
958 std::string tok,box,output;
959 tok = str.substr(lastPos, pos - lastPos);
960 Utilities::SplitAroundFirstDot(tok,box,output);
961 chains.push_back( mVirtualExecuter->Get(box,output) );
963 // InterpretLine("connect %tok% _C_.In%num%")
966 // Skip delimiters. Note the "not_of"
967 lastPos = str.find_first_not_of(delimiters, pos);
968 // Find next delimiter
969 pos = str.find_first_of(delimiters, lastPos);
974 // InterpretLine("exec _P_")
975 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
977 std::vector<std::string>::iterator i;
978 for (i= chains.begin(); i!=chains.end(); ++i)
981 Utilities::SubsBackslashN(*i);
984 std::cout << std::endl;
985 bbtkDebugDecTab("interpreter",9);
989 //=======================================================================
994 // =========================================================================
995 void Interpreter::SwitchToFile( const std::string& name , bool source )
997 // Note : in the following :
998 // name : the user supplied name
999 // - abreviated name e.g. scr scr.bbs
1000 // - relative full name e.g. ./scr.bbs ../../scr.bbs
1001 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
1002 // same for Windows, with c:, d: ...
1004 // use ./directory/subdir/scrname.bbs
1007 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToFile( \""
1008 <<name<<"\")"<<std::endl);
1010 std::vector<std::string> script_paths;
1011 std::string fullPathScriptName; // full path script name
1012 std::string pkgname; // e.g. <scriptname>.bbs
1013 std::vector<std::string> Filenames;
1015 // The following is *NOT* a debug time message :
1016 // It's a user intended message.
1017 // Please don't remove it.
1018 bbtkMessage("interpreter",1,
1019 "look for : [" << name
1020 << "]" << std::endl);
1024 pkgname = Utilities::ExtractScriptName(name,upath);
1026 bbtkMessage("interpreter",3,
1027 "package name:[" << pkgname
1028 << "] path:[" << upath << "]" << std::endl);
1029 bool fullnameGiven = false;
1030 bool foundFile = false;
1032 // ==== "*" provided : load all scripts in given path
1033 // relative (e.g. std/boxes/ *) or absolute <<<<<<<< / *
1037 std::stringstream* stream = new std::stringstream;
1038 //if (upath.size()!=0) // avoid troubles for "*"
1040 // ==== no path provided : look in root bbs path
1041 if (upath.size()==0)
1043 // bbtkMessage("interpreter",1,
1044 // LG : add all bbs path
1045 // script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1046 std::vector<std::string>::const_iterator i;
1047 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1048 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1051 script_paths.push_back(*i);
1054 // ==== absolute path provided
1055 else if (upath[0]=='/' || upath[1] == ':' )
1057 if ( Utilities::IsDirectory( upath ) )
1059 script_paths.push_back(upath);
1063 bbtkError("'"<<upath<<"' : directory does not exist");
1066 // ==== relative path provided : search all bbs path appended with
1067 // the relative path provided
1070 std::vector<std::string>::const_iterator i;
1071 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1072 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1075 std::string full_path(*i);
1076 // we *really* want '.' to be the current working directory
1077 if (full_path == ".")
1079 char buf[2048]; // for getcwd
1080 char * currentDir = getcwd(buf, 2048);
1081 std::string cwd(currentDir);
1082 full_path = currentDir;
1085 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1088 if ( Utilities::IsDirectory( full_path ) )
1090 script_paths.push_back(full_path);
1093 if (script_paths.empty())
1095 bbtkError("no '"<<upath<<"' subdir found in search paths"
1101 // === search paths list complete : now explore it
1103 // ==== relative name, iterate + load all .bbs/.bbp files
1104 std::vector<std::string>::iterator i;
1105 for (i=script_paths.begin();i!=script_paths.end();i++)
1107 bbtkMessage("interpreter",1,
1108 "--> Looking in '" << *i << "'" << std::endl);
1112 Utilities::Explore(*i, false, Filenames);
1114 for (std::vector<std::string>::iterator j = Filenames.begin();
1115 j!= Filenames.end(); ++j)
1117 int lgr = (*j).size();
1118 if (lgr < 5) continue;
1119 // ignore non .bbp file
1120 if ( (*j).substr(lgr-4, 4) != ".bbp") continue;
1122 (*stream) << "include \"" << *j << "\"\n";
1123 bbtkMessage("interpreter",2," --> Found '" << *j << "'" << std::endl);
1126 } // for (std::vector...
1127 } // for (i=script_...
1132 bbtkMessage("interpreter",1,
1133 " --> No .bbp found"<< std::endl);
1137 bbtkMessage("interpreter",1,
1138 " --> "<<nbBssFiles<<" .bbp found"<< std::endl);
1139 SwitchToStream(stream);
1143 //=============== end pkgname=="*" ===========
1146 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1147 // (not only a plain script name)
1148 // we trust him, and try to expland the directory name
1149 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1151 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1154 // ===========================================================check user supplied location
1155 fullnameGiven = true;
1157 fullPathScriptName = Utilities::ExpandLibName(name, false);
1159 // allow user to always forget ".bbs"
1160 int l = fullPathScriptName.size();
1164 if ((fullPathScriptName.substr(l-4, 4) != ".bbs")&&
1165 (fullPathScriptName.substr(l-4, 4) != ".bbp"))
1167 std::string tfullPathScriptName = fullPathScriptName + ".bbs";
1168 if ( Utilities::FileExists(tfullPathScriptName) )
1170 fullPathScriptName = tfullPathScriptName;
1175 tfullPathScriptName = fullPathScriptName + ".bbp";
1176 if ( Utilities::FileExists(tfullPathScriptName) )
1178 fullPathScriptName = tfullPathScriptName;
1185 if ( Utilities::FileExists(fullPathScriptName) )
1193 // =============================== iterate on the paths
1195 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1197 std::vector<std::string>::iterator i;
1198 for (i=script_paths.begin();i!=script_paths.end();++i)
1201 // we *really* want '.' to be the current working directory
1204 char buf[2048]; // for getcwd
1205 char * currentDir = getcwd(buf, 2048);
1206 std::string cwd(currentDir);
1210 std::string tfullPathScriptName = Utilities::MakePkgnameFromPath(path, name, false);
1211 //Addition JCP tfullPathScriptName.size()>=4
1212 if(tfullPathScriptName.size()>=4){
1213 if (tfullPathScriptName.substr(tfullPathScriptName.size()-4, 3)==".bb")
1215 fullPathScriptName = tfullPathScriptName;
1216 if ( ! Utilities::FileExists(fullPathScriptName) )
1218 // The following is *NOT* a debug time message :
1219 // It's a user intended message.
1220 // Please don't remove it.
1221 bbtkMessage("interpreter",2,
1222 " [" <<fullPathScriptName <<"] : does not exist"
1224 continue; // try next path
1226 bbtkMessage("interpreter",2,
1227 " [" <<fullPathScriptName
1228 <<"] : found" <<std::endl);
1230 break; // a script was found; we stop iterating
1234 fullPathScriptName = tfullPathScriptName + ".bbs";
1235 // Check if library exists
1236 if ( ! Utilities::FileExists(fullPathScriptName) )
1238 fullPathScriptName = tfullPathScriptName + ".bbp";
1239 if ( ! Utilities::FileExists(fullPathScriptName) )
1241 // The following is *NOT* a debug time message :
1242 // It's a user intended message.
1243 // Please don't remove it.
1244 bbtkMessage("interpreter",2,
1245 " [" <<tfullPathScriptName <<".bbs/.bbp] : do not exist"
1247 continue; // try next path
1250 bbtkMessage("interpreter",2,
1251 " [" <<fullPathScriptName
1252 <<"] : found" <<std::endl);
1254 break; // a script was found; we stop iterating
1257 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1263 if(fullPathScriptName == "")
1264 bbtkError("Path ["<<upath<<"] doesn't exist");
1266 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1268 bbtkError("No ["<<pkgname<<".bbs/.bbp] script found");
1273 LoadScript(fullPathScriptName,name);
1274 if (source) SetCurrentFileName(fullPathScriptName);
1279 //=======================================================================
1282 //=======================================================================
1283 void Interpreter::SetCurrentFileName(const std::string &fullPathScriptName) // virtual
1285 GetExecuter()->SetCurrentFileName(fullPathScriptName);
1287 //=======================================================================
1290 //=======================================================================
1291 void Interpreter::SwitchToStream( std::stringstream* stream )
1293 bbtkDebugMessage("interpreter",4,"==> Interpreter::SwitchToStream()"
1295 mFile.push_back(stream);
1296 std::ostringstream buffer_name;
1298 buffer_name << "buffer_" ;
1300 if (mFileName.size()>0 )
1302 buffer_name << mFileName.back() << "_" << mLine.back();
1304 mFileName.push_back(buffer_name.str());
1305 mIncludeFileName.push_back(buffer_name.str());
1308 //=======================================================================
1312 //=======================================================================
1313 void Interpreter::LoadScript( std::string fullPathScriptName,
1314 std::string includeScriptName)
1316 bbtkDebugMessage("interpreter",4,"==> Interpreter::LoadScript("
1317 <<fullPathScriptName<<")"
1320 Utilities::replace( fullPathScriptName ,
1321 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1323 if (find(mFileNameHistory.begin(),
1324 mFileNameHistory.end(),
1325 fullPathScriptName)!=mFileNameHistory.end())
1331 s = new std::ifstream;
1332 s->open(fullPathScriptName.c_str());
1335 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1339 bbtkMessage("interpreter",1," -->[" << fullPathScriptName
1340 << "] found" << std::endl);
1343 mFileName.push_back(fullPathScriptName);
1344 mFileNameHistory.push_back(fullPathScriptName);
1345 mIncludeFileName.push_back(includeScriptName);
1350 //=======================================================================
1354 //=======================================================================
1355 void Interpreter::CloseCurrentFile()
1357 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseCurrentFile()"
1360 if (mFile.size()==0)
1362 bbtkDebugMessage("interpreter",9," -> no file left open"<<std::endl);
1366 bbtkDebugMessage("interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1368 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1369 if (file!=0) file->close();
1371 delete mFile.back();
1373 mFileName.pop_back();
1374 mIncludeFileName.pop_back();
1377 bbtkDebugMessage("interpreter",9," Remains "
1379 <<" open"<<std::endl);
1380 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseCurrentFile()"
1383 //=======================================================================
1385 //=======================================================================
1386 void Interpreter::CloseAllFiles()
1388 bbtkDebugMessage("interpreter",9,"==> Interpreter::CloseAllFiles()"
1391 while (mFile.size() != 0)
1395 bbtkDebugMessage("interpreter",9,"<== Interpreter::CloseAllFiles()"
1398 //=======================================================================
1401 //=======================================================================
1402 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1403 CommandInfoType& info )
1405 bbtkDebugMessage("interpreter",9,"==> Interpreter::InterpretCommand(...)"<<std::endl);
1407 // searches the command keyword
1408 CommandDictType::iterator c;
1409 c = mCommandDict.find(words[0]);
1410 if ( c == mCommandDict.end() ) {
1411 bbtkError(words[0]<<" : unknown command");
1414 // tests the number of args
1415 if ( ( ((int)words.size())-1 < c->second.argmin ) ||
1416 ( ((int)words.size())-1 > c->second.argmax ) )
1418 commandHelp(words[0]);
1419 bbtkError(words[0]<<" : wrong number of arguments");
1421 //std::cout<<"Interpreter::InterpretCommand( const std::vector<std::string>& words,"<<std::endl;
1424 bbtkDebugMessage("interpreter",9,"<== Interpreter::InterpretCommand(...)"<<std::endl);
1427 //=======================================================================
1431 //=======================================================================
1432 /// Displays help on all the commands
1433 void Interpreter::commandHelp(const std::vector<std::string>& words)
1435 unsigned int nbarg = words.size()-1;
1443 if (words[1]=="packages")
1445 GetExecuter()->GetFactory()->PrintHelpListPackages(true);
1450 commandHelp(words[1]);
1452 catch (bbtk::Exception e)
1456 GetExecuter()->GetFactory()->PrintHelpPackage(words[1]);
1460 ConfigurationFile::GetInstance().Get_doc_path();
1461 url += "/bbdoc/" + words[1] + "/index.html";
1462 if (Utilities::FileExists(url))
1464 mUser->InterpreterUserViewHtmlPage(url);
1468 catch (bbtk::Exception f)
1472 std::string package;
1473 GetExecuter()->GetFactory()->PrintHelpDescriptor(words[1],
1478 ConfigurationFile::GetInstance().Get_doc_path();
1479 url += "/bbdoc/" + package + "/index.html";
1480 if (Utilities::FileExists(url))
1482 url += "#" + words[1];
1483 mUser->InterpreterUserViewHtmlPage(url);
1487 catch (bbtk::Exception g)
1491 GetExecuter()->PrintHelpBlackBox(words[1],"0","9999");
1493 catch (bbtk::Exception h){
1494 bbtkError("\""<<words[1].c_str()
1495 <<"\" is not a known command, package, black box type or black box name");
1503 if (words[2]=="all")
1505 if ( words[1]=="packages" )
1507 GetExecuter()->GetFactory()->PrintHelpListPackages(true,true);
1512 GetExecuter()->GetFactory()->PrintHelpPackage(words[1],true);
1514 catch (bbtk::Exception f)
1520 commandHelp(words[0]);
1521 bbtkError(words[0]<<" : syntax error");
1526 bbtkError("Should not reach here !!!");
1529 //=======================================================================
1531 //===================================================================
1532 /// Displays the Configuration
1533 void Interpreter::commandConfig() const
1535 ConfigurationFile::GetInstance().GetHelp(1);
1537 //===================================================================
1539 //=======================================================================
1540 /// Displays help on all the commands
1541 void Interpreter::HelpCommands()
1543 std::cout << "Available commands :" << std::endl;
1544 CommandDictType::iterator i;
1545 for ( i = mCommandDict.begin();
1546 i != mCommandDict.end();
1548 std::cout << " " << i->first << std::endl;
1549 // std::cout << " usage : " << i->second.syntax << std::endl;
1550 // std::cout << " " << i->second.help << std::endl;
1554 //=======================================================================
1558 //=======================================================================
1559 /// Displays help on a particular commands
1560 void Interpreter::commandHelp(const std::string& s)
1562 CommandDictType::iterator c;
1563 c = mCommandDict.find(s);
1564 if ( c == mCommandDict.end() ) {
1565 bbtkError(s<<" : Unknown command");
1567 // std::cout << " " << s << " : "<< std::endl;
1568 // CommandParamDictType::iterator i;
1569 // for ( i = c->second.begin();
1570 // i != c->second.end();
1572 std::cout << " usage : " << c->second.syntax << std::endl;
1573 std::cout << " " << c->second.help << std::endl;
1576 //=======================================================================
1579 //=======================================================================
1580 /// Fills the vector commands with the commands which
1581 /// have the first n chars of buf for prefix
1582 /// TODO : skip initial spaces in buf and also return the position of first
1583 /// non blank char in buf
1584 void Interpreter::FindCommandsWithPrefix( char* buf,
1586 std::vector<std::string>& commands )
1588 CommandDictType::const_iterator i;
1589 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1591 if ((i->first).find(buf,0,n) == 0)
1592 commands.push_back(i->first);
1595 //=======================================================================
1600 //=======================================================================
1601 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1603 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1604 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1606 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1607 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1608 // E.G. STORE THIS IN bbtk_config.xml
1609 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1610 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1611 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1612 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1613 #define BBTK_BACKSPACE_KBCODE 0x00000008
1614 #define BBTK_DEL_KBCODE 0x0000007F
1615 #define BBTK_SPACE_KBCODE 0x00000020
1617 //=======================================================================
1618 void Interpreter::GetLineFromPrompt(std::string& s)
1623 unsigned int MAX_LINE_SIZE = 160;
1624 unsigned int MAX_HISTORY_SIZE = 100;
1626 char* newline = new char[MAX_LINE_SIZE];
1627 memset(newline,0,MAX_LINE_SIZE);
1628 char* histline = new char[MAX_LINE_SIZE];
1629 memset(histline,0,MAX_LINE_SIZE);
1631 char* line = newline;
1632 unsigned int hist = mHistory.size();
1638 read ( STDIN_FILENO, &c, 4) ;
1640 bbtkDebugMessage("debug",9,"[0x"<<std::hex<<c<<"]\n");
1642 // Printable character
1643 if ( (ind<MAX_LINE_SIZE-1) &&
1644 ( c >= BBTK_SPACE_KBCODE ) &&
1645 ( c < BBTK_DEL_KBCODE ))
1653 // delete the unused line
1659 // empty lines are not stored in from history
1662 // if history too long : delete oldest command
1663 if (mHistory.size()>MAX_HISTORY_SIZE)
1665 delete mHistory.front();
1666 mHistory.pop_front();
1668 mHistory.push_back(line);
1673 else if ( (ind>0) &&
1674 ((c == BBTK_BACKSPACE_KBCODE) ||
1675 (c == BBTK_DEL_KBCODE)) )
1683 // TODO : Command completion
1684 std::vector<std::string> commands;
1685 FindCommandsWithPrefix( line,ind,commands);
1686 if (commands.size()==1)
1688 std::string com = *commands.begin();
1689 for (; ind<com.size(); ++ind)
1691 PrintChar(com[ind]);
1697 else if (commands.size()>1)
1699 std::vector<std::string>::iterator i;
1701 for (i=commands.begin();i!=commands.end();++i)
1703 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1706 write(STDOUT_FILENO,"\n> ",3);
1707 //for (int j=0;j<ind;++j)
1709 write(STDOUT_FILENO,line,ind);
1713 // Arrow up : back in history
1714 else if (c==BBTK_UP_ARROW_KBCODE)
1718 // erase current line
1719 while (ind--) BackSpace();
1723 strcpy(histline,mHistory[hist]);
1727 write(STDOUT_FILENO,line,ind);
1730 // Arrow down : down in history
1731 else if (c==BBTK_DOWN_ARROW_KBCODE)
1733 if (hist<mHistory.size()-1)
1735 // erase current line
1736 while (ind--) BackSpace();
1740 strcpy(histline,mHistory[hist]);
1744 write(STDOUT_FILENO,line,ind);
1746 // end of history : switch back to newline
1747 else if (hist==mHistory.size()-1)
1749 // erase current line
1750 while (ind--) BackSpace();
1757 write(STDOUT_FILENO,line,ind);
1761 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1763 PrintChar(line[ind]);
1768 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1776 write(STDOUT_FILENO,"\n\r",2);
1784 //=======================================================================
1785 void Interpreter::GetLineFromPrompt(std::string& s)
1811 //=======================================================================
1822 //=======================================================================
1823 void Interpreter::CommandLineInterpreter()
1825 bbtkDebugMessageInc("interpreter",9,
1826 "Interpreter::CommandLineInterpreter()"<<std::endl);
1828 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1829 // Initialise the tty in non canonical mode with no echo
1830 // oter remembers the previous settings to restore them after
1831 struct termios ter,oter;
1834 ter.c_lflag &= ~ECHO;
1835 ter.c_lflag &= ~ICANON;
1838 tcsetattr(0,TCSANOW,&ter);
1841 mCommandLine = true;
1843 // bool insideComment = false; // for multiline comment
1844 mInsideComment = false;
1850 GetLineFromPrompt(line);
1851 DoInterpretLine(line); //, insideComment);
1853 // catch (QuitException e)
1855 // bbtkMessage("interpreter",1,"Interpreter : Quit"<<std::endl);
1858 catch (bbtk::Exception e)
1862 catch (std::exception& e)
1864 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1868 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1873 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1874 tcsetattr(0,TCSANOW,&oter);
1877 std::cout << "Good bye !" << std::endl;
1879 bbtkDebugDecTab("interpreter",9);
1883 //=======================================================================
1884 void Interpreter::commandGraph(const std::vector<std::string>& words)
1887 bool system_display = true;
1889 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1890 system_display = false;
1892 if (words.size()==1)
1894 page = mVirtualExecuter->ShowGraph(".","0","0","","","",system_display);
1896 else if (words.size()==2)
1898 page = mVirtualExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1900 else if (words.size()==3)
1902 page = mVirtualExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1904 else if (words.size()==4)
1906 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1908 else if (words.size()==5)
1910 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1912 else if (words.size()==6)
1914 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1916 else if (words.size()==7)
1918 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1921 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1922 mUser->InterpreterUserViewHtmlPage(page);
1925 //=======================================================================
1928 //=======================================================================
1929 void Interpreter::commandIndex(const std::string& filename,
1930 const std::string& type)
1932 Factory::IndexEntryType t;
1933 if (type=="Initials") t = Factory::Initials;
1934 else if (type=="Categories") t = Factory::Categories;
1935 else if (type=="Packages") t = Factory::Packages;
1936 else if (type=="Adaptors") t = Factory::Adaptors;
1938 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1940 //=======================================================================
1943 //=======================================================================
1944 void Interpreter::commandNewGUI(const std::string& boxname,
1945 const std::string& instanceName)
1947 if (mRealExecuter.expired())
1949 bbtkError("command 'newgui' cannot be compiled yet");
1952 std::string typeName = instanceName+"Type";
1953 std::stringstream* s = new std::stringstream;
1954 // create the complex box
1955 (*s) << "define "<<typeName<<std::endl;
1956 // (*s) << " description 'Automatically generated user interface for the box "
1957 // << boxname << "'" <<std::endl;
1958 // create the Layout box
1959 (*s) << " load wx"<<std::endl;
1960 (*s) << " new LayoutLine layout"<<std::endl;
1961 // create the output 'Widget'
1962 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1963 // the box change output
1964 (*s) << " new MultipleInputs change"<<std::endl;
1965 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1967 // Browse the inputs of the box in order to find which ones are not
1968 // connected and can be adapted from a widget adaptor
1969 // vector which stores the list of inputs of the box which must be connected
1970 std::vector<std::string> in;
1972 Factory::Pointer F = mVirtualExecuter->GetFactory();
1974 Package::Pointer user = F->GetPackage("user");
1976 ComplexBlackBoxDescriptor::Pointer workspace =
1977 mRealExecuter.lock()->GetCurrentDescriptor();
1982 bbtkError("interpreter::CreateGUI : could not access the executer currently defined complex box");
1987 (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get());
1990 BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname);
1991 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
1993 BlackBox::InputConnectorMapType::iterator i;
1994 for (i=box->bbGetInputConnectorMap().begin();
1995 i!=box->bbGetInputConnectorMap().end();
1998 // If the input is connected : continue
1999 if (i->second->IsConnected()) continue;
2000 // Get the input descriptor
2001 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
2002 // If it is a "system" input : skip it
2003 #ifdef USE_WXWIDGETS
2004 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
2005 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
2008 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) )
2012 std::string widget,adaptor;
2013 // try to find a widget adaptor
2014 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
2018 // command to create the adaptor
2019 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2020 // Sets the label of the widget adaptor to the name of the input
2021 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
2022 // Sets the initial value of the widget to the value of the input
2023 (*s) << " set "<<i->first<<".In \" "
2024 <<box->bbGetInputAsString(i->first)<<"\""
2026 // store the input name
2027 in.push_back(i->first);
2028 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2029 //<i->first<<"'"<<std::endl;
2030 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2032 // try to find a two pieces adaptor
2033 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
2037 // command to create the widget
2038 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
2039 // command to create the adaptor
2040 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
2042 (*s) << " connect "<<i->first<<"Widget.Out "
2043 <<i->first<<".In"<<std::endl;
2044 // Sets the label of the widget adaptor to the name of the input
2045 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
2046 // Sets the initial value of the widget to the value of the input
2047 (*s) << " set "<<i->first<<"Widget.In \" "
2048 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2049 // store the input name
2050 in.push_back(i->first);
2051 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
2052 //<i->first<<"'"<<std::endl;
2053 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
2056 // try to find an adaptor from string
2057 // If found then can create a text input which
2058 // will be automatically adapted
2059 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
2063 // command to create the adaptor
2064 (*s) << " new InputText "<<i->first<<std::endl;
2065 // Sets the label of the widget adaptor to the name of the input
2066 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
2067 // Sets the initial value of the widget to the value of the input
2068 (*s) << " set "<<i->first<<".In \" "
2069 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2070 // store the input name
2071 in.push_back(i->first);
2072 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2073 //<i->first<<"'"<<std::endl;
2074 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2083 // command to create the output
2084 (*s) << " output "<<i->first<<" "
2085 <<i->first<<".Out "<<i->first<<std::endl;
2086 // <<" Output of the widget which allows to set "
2090 // Inputs for window properties
2091 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
2092 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
2093 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
2094 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
2095 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
2099 // Execute the box executes the layout
2100 (*s) << " exec layout" << std::endl;
2101 (*s) << "endefine" << std::endl;
2102 // (*s) << "help "<< typeName<< std::endl;
2103 // instanciate the box and connect it
2104 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2106 std::vector<std::string>::iterator j;
2107 for (j=in.begin();j!=in.end();++j)
2110 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2111 << boxname<<"."<<*j<<std::endl;
2113 // That's all folks ! now execute the commands :
2116 //=======================================================================
2120 //==========================================================================
2121 void Interpreter::commandDebug(const std::string& name)
2123 if ((name.length()==2)&&(name[0]=='-'))
2127 bbtk::StaticInitTime::PrintObjectListInfo = true;
2131 // int o = MessageManager::GetMessageLevel("debug");
2132 // if (o<2) MessageManager::SetMessageLevel("debug",2);
2133 mVirtualExecuter->GetFactory()->Check();
2134 // MessageManager::SetMessageLevel("debug",o);
2139 Object:: PrintObjectListInfo(name);
2142 //==========================================================================
2145 //==========================================================================
2146 // Adds a callback when 'break' command issued
2147 void Interpreter::AddBreakObserver( BreakCallbackType c )
2149 mBreakSignal.connect(c);
2151 //==========================================================================
2154 //==========================================================================
2155 std::string Interpreter::GetObjectName() const
2157 return std::string("Interpreter");
2159 //==========================================================================
2161 //==========================================================================
2162 std::string Interpreter::GetObjectInfo() const
2164 std::stringstream i;
2167 //==========================================================================
2169 //==========================================================================
2170 size_t Interpreter::GetObjectSize() const
2172 size_t s = Superclass::GetObjectSize();
2173 s += Interpreter::GetObjectInternalSize();
2176 //==========================================================================
2177 //==========================================================================
2178 size_t Interpreter::GetObjectInternalSize() const
2180 size_t s = sizeof(Interpreter);
2183 //==========================================================================
2184 //==========================================================================
2185 size_t Interpreter::GetObjectRecursiveSize() const
2187 size_t s = Superclass::GetObjectRecursiveSize();
2188 s += Interpreter::GetObjectInternalSize();
2189 s += mVirtualExecuter->GetObjectRecursiveSize();
2192 //==========================================================================