1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.cxx,v $ $
6 Date: $Date: 2008/07/01 07:58:28 $
7 Version: $Revision: 1.67 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
20 * \brief class Interpreter :
23 #include "bbtkInterpreter.h"
24 #include "bbtkExecuter.h"
25 #include "bbtkTranscriptor.h"
26 #include "bbtkMessageManager.h"
27 #include "bbtkConfigurationFile.h"
28 #include "bbtkUtilities.h"
29 #include "bbtkWxBlackBox.h"
32 #ifdef CMAKE_HAVE_TERMIOS_H
34 #define BBTK_USE_TERMIOS_BASED_PROMPT
42 //=======================================================================
43 Interpreter::Pointer Interpreter::New(const std::string& cpp_file)
45 bbtkDebugMessage("Kernel",9,"Interpreter::New('"<<cpp_file<<"')"<<std::endl);
46 return MakePointer(new Interpreter(cpp_file));
48 //=======================================================================
50 //=======================================================================
51 Interpreter::Pointer Interpreter::New(VirtualExec::Pointer e)
53 bbtkDebugMessage("Kernel",9,"Interpreter::New(VirtualExec)"<<std::endl);
54 return MakePointer(new Interpreter(e));
56 //=======================================================================
58 //=======================================================================
59 Interpreter::Interpreter(const std::string& cpp_file)
61 Init(VirtualExec::Pointer(), cpp_file);
63 //=======================================================================
65 //=======================================================================
66 Interpreter::Interpreter(VirtualExec::Pointer e)
70 //=======================================================================
72 //=======================================================================
73 void Interpreter::Init(VirtualExec::Pointer e, const std::string& cpp_file)
79 bbtk::MessageManager::RegisterMessageType("echo","Level>0 : Prints the output of the 'print' commands of the user.\n\tLevel>1 : Prints the command being interpreted",1);
80 bbtk::MessageManager::RegisterMessageType("Interpreter","Messages of the interpreter",0);
81 bbtkDebugMessageInc("Interpreter",9,"Interpreter::Interpreter()" <<std::endl);
86 else if (cpp_file.size()!=0)
88 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(bbtk::Transcriptor::New(cpp_file));
92 bbtk::Executer::Pointer exe = bbtk::Executer::New();
94 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(exe);
97 // Lock this pointer or will auto-destruct !!
98 if (!e) mVirtualExecuter->SetInterpreter(MakePointer(this,true));
100 // For the time being, comment out previous line, and
101 // uncomment next line to check Transcriptor
103 //mVirtualExecuter = new bbtk::Transcriptor("GeneratedProgram.txt");
105 // Builds the commands dict
106 CommandInfoType info;
108 info.keyword = "new";
112 info.syntax = "new <type> <name>";
113 info.help = "Creates a new black box of type <type> with name <name>";
114 mCommandDict[info.keyword] = info;
116 info.keyword = "delete";
120 info.syntax = "delete <box>";
121 info.help = "Deletes the black box of name <box>";
122 mCommandDict[info.keyword] = info;
124 info.keyword = "newgui";
128 info.syntax = "newgui <box> <name>";
129 info.help = "Automatically creates a graphical user interface with name <name> for the black box <box> and connects it to the box inputs";
130 mCommandDict[info.keyword] = info;
132 info.keyword = "connect";
135 info.code = cConnect;
136 info.syntax = "connect <box1.output> <box2.input>";
137 info.help = "Connects the ouput <output> of black box <box1> to the input <input> of black box <box2>";
138 mCommandDict[info.keyword] = info;
140 info.keyword = "print";
144 info.syntax = "print <string>";
145 info.help = "Prints the string. Substitutes any token of the form '$box.output$' by the string adaptation of the output of the box (requires the right adaptor). No carriage return is issued at the end, use '\\n' to add carriage returns. The level of 'echo' messages must be greater than 1 (see the command 'message').";
146 mCommandDict[info.keyword] = info;
148 info.keyword = "exec";
152 info.syntax = "exec <box | 'freeze' | 'unfreeze' >";
153 info.help = "Executes the black box of name <box> (and connected boxes if needed). If the special keyword 'freeze' is given then freezes any further execution command. 'unfreeze' reverts to normal execution mode.";
154 mCommandDict[info.keyword] = info;
156 info.keyword = "package";
159 info.code = cPackage;
160 info.syntax = "package <name>";
161 info.help = "Begins the definition of a package.";
162 mCommandDict[info.keyword] = info;
164 info.keyword = "endpackage";
167 info.code = cEndPackage;
168 info.syntax = "endpackage";
169 info.help = "Ends the definition of a package.";
170 mCommandDict[info.keyword] = info;
172 info.keyword = "define";
176 info.syntax = "define <type> [<package>]";
177 info.help = "Begins the definition of a new type of complex black box called <type>. If <package> if provided will create it in the given package.";
178 mCommandDict[info.keyword] = info;
180 info.keyword = "endefine";
183 info.code = cEndDefine;
184 info.syntax = "endefine";
185 info.help = "Ends the definition of a new type of complex black box";
186 mCommandDict[info.keyword] = info;
188 info.keyword = "kind";
192 info.syntax = "kind <ADAPTOR|DEFAULT_ADAPTOR|WIDGET_ADAPTOR|DEFAULT_WIDGET_ADAPTOR>";
193 info.help = "Sets the kind of the currently defined complex black box";
194 mCommandDict[info.keyword] = info;
196 info.keyword = "input";
200 info.syntax = "input <name> <box.input> <help>";
201 info.help = "Defines the input <name> of the current working black box as being an alias for the input <input> of the black box <box>. <help> defines the help string for the newly created input";
202 mCommandDict[info.keyword] = info;
204 info.keyword = "output";
208 info.syntax = "output <name> <box.output> <help>";
209 info.help = "Defines the output <name> of the current working black box as being an alias for the output <output> of the black box <box>. <help> defines the help string for the newly created output";
210 mCommandDict[info.keyword] = info;
212 info.keyword = "set";
216 info.syntax = "set <box.input> <value>";
217 info.help = "Sets the value of the input <input> of the black box <box> to <value>. There must exist a string to the value type adaptor";
218 mCommandDict[info.keyword] = info;
220 info.keyword = "config"; // JPR
224 info.syntax = "config";
225 info.help = "Prints the value of all configuration parameters";
226 mCommandDict[info.keyword] = info;
228 info.keyword = "index"; // LG
233 info.syntax = "index [<filename> ['Initials'(default)|'Packages'|'Categories'|'Adaptors']]";
234 info.help = "Creates an html index of known boxes. If filename is provided then save it to the file 'filename'. The default index entries are the initial letters of the names of the boxes. If 'Packages' or 'Categories' is provided then the entries are either the packages names or the categories. If 'Adaptors' is provided then an alphabetical index of all adaptors is created.";
235 mCommandDict[info.keyword] = info;
237 info.keyword = "reset";
241 info.syntax = "reset";
242 info.help = "Deletes all boxes and unloads all packages (reset to start state)";
243 mCommandDict[info.keyword] = info;
245 info.keyword = "author";
249 info.syntax = "author <string>";
250 info.help = "Adds the string <string> to the author information of the black box being defined";
251 mCommandDict[info.keyword] = info;
253 info.keyword = "category"; //JP
256 info.code = cCategory;
257 info.syntax = "category <list of items, separated by ;>";
258 info.help = "Adds the string <string> to the category information of the black box being defined";
259 mCommandDict[info.keyword] = info;
261 info.keyword = "description";
264 info.code = cDescription;
265 info.syntax = "description <string>";
266 info.help = "Adds the string <string> to the descriptive information of the black box being defined";
267 mCommandDict[info.keyword] = info;
269 info.keyword = "help";
273 info.syntax = "help";
274 info.syntax = "\n (1) help \n (2) help <command name> \n (3) help packages [all]\n (4) help <package name> [all]\n (5) help <black box type> \n (6) help <black box name>";
275 info.help = "Effect :\n (1) Lists all available commands;\n (2) Prints help on a particular command; \n (3) Lists the packages loaded and their black boxes.\n Add 'all' to list adaptors; \n (4) Prints short help on the black boxes of a package.\n Add 'all' to include adaptors; \n (5) Prints full help on a black box type; \n (6) Prints information on the inputs, outputs and connections of a black box instance.";
276 mCommandDict[info.keyword] = info;
278 info.keyword = "message";
281 info.code = cMessage;
282 info.syntax = "message <kind> <level>";
283 info.help = "Sets the level of the kind of messages <kind> to <level>.\n If kind='All' then sets the level for all kinds. If no kind nor level is passed then prints info on available kinds of messages and their current level."; mCommandDict[info.keyword] = info;
285 info.keyword = "include";
288 info.code = cInclude;
289 info.syntax = "include <filename> [source]";
290 info.help = "Includes the file <filename>.\n 'source' : If the keyword 'source' is provided then informs the interpreter that the included file is the source of the current box definition (Advanced; used to get the right 'Include' field in html doc of packages 'appli' scripts).";
291 mCommandDict[info.keyword] = info;
293 info.keyword = "quit";
297 info.syntax = "quit";
298 info.help = "Quits the program (during script execution it stops the complete execution)";
299 mCommandDict[info.keyword] = info;
301 info.keyword = "load";
305 info.syntax = "load <packagename>";
306 info.help = "Loads the black box package <packagename>";
307 mCommandDict[info.keyword] = info;
309 info.keyword = "unload";
313 info.syntax = "unload <packagename>";
314 info.help = "Unloads the black box package <packagename>";
315 mCommandDict[info.keyword] = info;
317 info.keyword = "graph";
321 info.syntax = "graph [ BlackBoxName [ Detail 0..1 [ Level 0..99999 [ Output html file [ Custom header [ Custom title ]]]]]] \n graph [ BlackBoxNameType [ Detail 0..1 [ Level 0..99999 [ Output html file [ Custom header [ Custom title ]]]]]]";
322 info.help = "Shows a graphical view of a bbtk pipeline.\n- BlackBoxName : name of the box to view. Default '.' : current box.\n- BlackBoxNameType : name of the type of box to view, ex : 'workspace')";
323 mCommandDict[info.keyword] = info;
325 info.keyword = "debug";
329 info.syntax = "debug [expr|-C|-D]";
330 info.help = "Prints debug info on living bbtk objects containing the string 'expr' (default expr=''). -C checks the factory integrity. -D turns on objects debug info after main ends";
331 mCommandDict[info.keyword] = info;
334 info.keyword = "workspace";
337 info.code = cWorkspace;
338 info.syntax = "workspace < ( freeze | unfreeze ) | ( rename <newname> ) >";
339 info.help = "Configures the workspace.\n 'freeze' allow to block execution commands while keeping definition commands active. 'unfreeze' turns back the worspace in 'normal' mode.\n 'rename' allow to set a new name to the workspace.";
340 mCommandDict[info.keyword] = info;
343 bbtkDebugDecTab("Interpreter",9);
346 //=======================================================================
350 //=======================================================================
354 Interpreter::~Interpreter()
356 bbtkDebugMessageInc("Interpreter",9,"==> Interpreter::~Interpreter()" <<std::endl);
357 mVirtualExecuter = VirtualExec::Pointer();
358 bbtkDebugMessageInc("Interpreter",9,"<== Interpreter::~Interpreter()" <<std::endl);
360 //=======================================================================
363 InterpreterError::InterpreterError( const std::string& message,
365 const std::string& script_file,
368 : Exception("Interpreter",0,message),
369 mInScriptFile(in_script_file),
370 mScriptFile(script_file),
371 mScriptLine(script_line)
374 InterpreterError::InterpreterError( const Exception& excep,
376 const std::string& script_file,
380 mInScriptFile(in_script_file),
381 mScriptFile(script_file),
382 mScriptLine(script_line)
385 //=======================================================================
386 void Interpreter::CatchBbtkException( const bbtk::Exception& e )
390 bool in_script = false;
391 std::string file("");
393 if (mFileName.size()) {
394 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
395 if (fs!=0) in_script = true;
396 file = mFileName.back();
400 throw InterpreterError(e,in_script,file,line);
404 std::stringstream mess;
405 mess << "* ERROR : "<<e.GetMessage()<<std::endl;
406 if (mFileName.size()) {
407 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
408 mess << "* LINE : "<<mLine.back()<<std::endl;
410 std::cerr << mess.str();
413 //=======================================================================
415 //=======================================================================
416 void Interpreter::CatchStdException( const std::exception& e )
420 bool in_script = false;
421 std::string file("");
423 if (mFileName.size()) {
424 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
425 if (fs!=0) in_script = true;
426 file = mFileName.back();
430 throw InterpreterError(e.what(),in_script,file,line);
434 std::stringstream mess;
435 mess << "* ERROR : "<<e.what()<<std::endl;
436 if (mFileName.size()) {
437 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
438 mess << "* LINE : "<<mLine.back()<<std::endl;
440 std::cerr << mess.str();
443 //=======================================================================
445 //=======================================================================
446 void Interpreter::CatchUnknownException()
450 bool in_script = false;
451 std::string file("");
453 if (mFileName.size()) {
454 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
455 if (fs!=0) in_script = true;
456 file = mFileName.back();
460 throw InterpreterError("Unknown exception caught",
461 in_script,file,line);
465 std::stringstream mess;
466 mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
468 if (mFileName.size()) {
469 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
470 mess << "* LINE : "<<mLine.back()<<std::endl;
472 std::cerr << mess.str();
475 //=======================================================================
477 //=======================================================================
479 #define CATCH_MACRO \
480 catch (QuitException e) \
482 status = Interpreter_QUIT; \
483 if (mThrow) throw QuitException(); \
485 catch (bbtk::Exception e) \
487 status = Interpreter_ERROR; \
488 CatchBbtkException(e); \
490 catch (std::exception& e) \
492 status = Interpreter_ERROR; \
493 CatchStdException(e); \
497 status = Interpreter_ERROR; \
498 CatchUnknownException(); \
500 //=======================================================================
503 //=======================================================================
507 Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename )
509 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
511 bool exm = mCommandLine;
512 mCommandLine = false;
514 ExitStatus status = Interpreter_OK;
518 SwitchToFile(filename);
520 bool insideComment = false; // for multiline comment
521 while (mFile.size()>0)
523 while (!mFile.back()->eof()) {
526 mFile.back()->getline(buf,500);
527 std::string str(buf);
528 int size=str.length();
529 if ( str[ size-1 ]==13 )
534 InterpretLine(str, insideComment);
543 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
544 bbtkDecTab("Interpreter",9);
550 //=======================================================================
553 //=======================================================================
557 Interpreter::ExitStatus
558 Interpreter::InterpretBuffer( std::stringstream* buffer )
560 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretBuffer()"<<std::endl);
562 bool exm = mCommandLine;
563 mCommandLine = false;
565 ExitStatus status = Interpreter_OK;
569 SwitchToStream(buffer);
570 bool insideComment = false; // for multiline comment
571 while (mFile.size()>0)
573 while (!mFile.back()->eof()) {
576 mFile.back()->getline(buf,500);
577 std::string str(buf);
579 int size=str.length();
580 if ( str[ size-1 ]==13 )
585 InterpretLine(str, insideComment);
595 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
596 bbtkDecTab("Interpreter",9);
601 //=======================================================================
603 //=======================================================================
604 /// Runs the interpretation of a command
605 Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
607 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
609 ExitStatus status = Interpreter_OK;
613 bool insideComment = false;
614 InterpretLine(line, insideComment);
619 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretLine()"
621 bbtkDecTab("Interpreter",9);
627 //=======================================================================
631 void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
633 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine(\""<<line<<"\")"<<std::endl);
634 bbtkMessage("echo",2,line<<std::endl);
636 std::vector<std::string> words;
637 SplitLine(line,words);
642 bbtkDebugDecTab("Interpreter",9);
646 // Single line comment : # or //
647 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
649 bbtkDebugDecTab("Interpreter",9);
650 bbtkMessage("Interpreter",9,"Comment"<<std::endl);
654 // Multi line comment ( /* ... */ ) -delimiters on different lines !-
656 if (words[0][0]=='/' && words[0][1]=='*')
658 bbtkDebugDecTab("Interpreter",9);
659 bbtkMessage("Interpreter",9,"In multiline comment"<<std::endl);
660 insideComment = true;
664 if (words[0][0]=='*' && words[0][1]=='/')
666 bbtkDebugDecTab("Interpreter",9);
667 bbtkMessage("Interpreter",9,"Out multiline comment"<<std::endl);
668 if ( !insideComment ) {
669 bbtkDebugDecTab("Interpreter",9);
670 bbtkMessage("Interpreter",9,"Comment mismatch : '*/' with no matching '/*'"<<std::endl);
672 insideComment = false;
678 bbtkDebugDecTab("Interpreter",9);
679 bbtkMessage("Interpreter",9,"Multiline Comment"<<std::endl);
684 CommandInfoType command;
685 InterpretCommand(words,command);
687 bbtkDebugMessage("Interpreter",9,
688 "Command='"<<command.keyword
689 <<"' code="<<command.code<<std::endl);
691 std::string left,right,left2,right2;
692 std::string filename;
693 switch (command.code)
696 mVirtualExecuter->Create(words[1],words[2]);
700 mVirtualExecuter->Destroy(words[1]);
704 Utilities::SplitAroundFirstDot(words[1],left,right);
705 Utilities::SplitAroundFirstDot(words[2],left2,right2);
706 mVirtualExecuter->Connect(left,right,left2,right2);
710 mVirtualExecuter->BeginPackage(words[1]);
714 mVirtualExecuter->EndPackage();
718 if (mFileName.size()>0)
720 filename = mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
724 mVirtualExecuter->Define(words[1],"",filename);
728 mVirtualExecuter->Define(words[1],words[2],filename);
733 mVirtualExecuter->EndDefine();
737 mVirtualExecuter->Kind(words[1]);
741 mVirtualExecuter->Print(words[1]);
745 if (words[1]=="freeze")
746 mVirtualExecuter->SetNoExecMode(true);
747 else if (words[1]=="unfreeze")
748 mVirtualExecuter->SetNoExecMode(false);
750 mVirtualExecuter->Execute(words[1]);
754 Utilities::SplitAroundFirstDot(words[2],left,right);
755 mVirtualExecuter->DefineInput(words[1],left,right,words[3]);
759 Utilities::SplitAroundFirstDot(words[2],left,right);
760 mVirtualExecuter->DefineOutput(words[1],left,right,words[3]);
764 Utilities::SplitAroundFirstDot(words[1],left,right);
765 mVirtualExecuter->Set(left,right,words[2]);
769 mVirtualExecuter->Author(words[1]);
773 NewGUI(words[1],words[2]);
777 mVirtualExecuter->Category(words[1]);
782 Index("tmp_index.html");
783 else if (words.size()==2)
785 else if (words.size()==3)
786 Index(words[1],words[2]);
790 mVirtualExecuter->Description(words[1]);
800 mVirtualExecuter->HelpMessages();
804 sscanf(words[2].c_str(),"%d",&level);
805 mVirtualExecuter->SetMessageLevel(words[1],level);
824 InterpretFile(words[1]);
828 SwitchToFile(words[1]);
830 // if 'source' was given
833 GetExecuter()->SetCurrentFileName(words[1]);
838 GetExecuter()->LoadPackage(words[1]);
842 GetExecuter()->UnLoadPackage(words[1]);
846 throw QuitException();
850 if (words.size()==2) Debug(words[1]);
855 if (words.size() == 2)
857 if (words[1]=="freeze") mVirtualExecuter->SetNoExecMode(true);
858 else if (words[1]=="unfreeze") mVirtualExecuter->SetNoExecMode(false);
862 mVirtualExecuter->SetWorkspaceName(words[2]);
867 bbtkInternalError("should not reach here !!!");
870 bbtkDecTab("Interpreter",9);
872 //=======================================================================
878 //=======================================================================
882 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
884 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
886 std::string delimiters = "\"";
887 std::vector<std::string> quote;
888 Utilities::SplitString(str,delimiters,quote);
891 std::vector<std::string>::iterator i;
892 for (i=quote.begin(); i!=quote.end(); )
894 Utilities::SplitString(*i,delimiters,tokens);
898 // bbtkDebugMessage("Interpreter",0,"\""<<*i<<"\""<<std::endl);
899 tokens.push_back(*i);
904 for (i=tokens.begin(); i!=tokens.end(); ++i)
906 bbtkDebugMessage("Interpreter",9,"["<<*i<<"] ");
908 bbtkDebugMessageCont("Interpreter",9,std::endl);
910 bbtkDebugDecTab("Interpreter",9);
912 //=======================================================================
915 //=======================================================================
916 void Interpreter::Reset()
918 // Cannot close all files if the reset command is read from a file !
920 mFileNameHistory.clear();
921 this->mVirtualExecuter->Reset();
923 //=======================================================================
925 //=======================================================================
930 void Interpreter::Print( const std::string& str)
932 if (mVirtualExecuter->GetNoExecMode()) return;
934 bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
937 // InterpretLine ("load std")
938 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
939 // InterpretLine("new Print _P_")
940 // InterpretLine("connect _C_.Out _P_.In")
944 std::vector<std::string> chains;
945 std::string delimiters("$");
947 // Skip delimiters at beginning.
948 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
950 if (lastPos>0) is_text = false;
952 // Find first delimiter.
953 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
955 while (std::string::npos != pos || std::string::npos != lastPos)
959 // Found a text token, add it to the vector.
960 chains.push_back(str.substr(lastPos, pos - lastPos));
961 // std::string token = str.substr(lastPos, pos - lastPos)
962 // InterpretLine("set _C_.In%num% %token%")
968 // is an output (between $$) : decode
969 std::string tok,box,output;
970 tok = str.substr(lastPos, pos - lastPos);
971 Utilities::SplitAroundFirstDot(tok,box,output);
972 chains.push_back( mVirtualExecuter->Get(box,output) );
974 // InterpretLine("connect %tok% _C_.In%num%")
977 // Skip delimiters. Note the "not_of"
978 lastPos = str.find_first_not_of(delimiters, pos);
979 // Find next delimiter
980 pos = str.find_first_of(delimiters, lastPos);
985 // InterpretLine("exec _P_")
986 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
988 std::vector<std::string>::iterator i;
989 for (i= chains.begin(); i!=chains.end(); ++i)
992 Utilities::SubsBackslashN(*i);
995 std::cout << std::endl;
996 bbtkDebugDecTab("Interpreter",9);
1000 //=======================================================================
1005 // =========================================================================
1006 void Interpreter::SwitchToFile( const std::string& name )
1008 // Note : in the following :
1009 // name : the user supplied name
1010 // - abreviated name e.g. scr scr.bbs
1011 // - relative full name e.g. ./scr.bbs ../../scr.bbs
1012 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
1013 // same for Windows, with c:, d: ...
1015 // use ./directory/subdir/scrname.bbs
1018 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SwitchToFile( \""
1019 <<name<<"\")"<<std::endl);
1021 std::vector<std::string> script_paths;
1022 std::string fullPathScriptName; // full path script name
1023 std::string pkgname; // e.g. <scriptname>.bbs
1024 std::vector<std::string> Filenames;
1026 // The following is *NOT* a debug time message :
1027 // It's a user intended message.
1028 // Please don't remove it.
1029 bbtkMessage("Interpreter",1,
1030 "look for : [" << name
1031 << "]" << std::endl);
1035 pkgname = Utilities::ExtractScriptName(name,upath);
1037 bbtkMessage("Interpreter",3,
1038 "extract : pkgname [" << pkgname
1039 << "] upath [" << upath << "]" << std::endl);
1040 bool fullnameGiven = false;
1041 bool foundFile = false;
1043 // ==== "*" provided : load all scripts in given path
1044 // relative (e.g. std/boxes/*) or absolute
1049 std::stringstream* stream = new std::stringstream;
1050 //if (upath.size()!=0) // avoid troubles for "*"
1052 // ==== no path provided : look in root bbs path
1053 if (upath.size()==0)
1055 // bbtkMessage("Interpreter",1,
1056 script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1058 // ==== absolute path provided
1059 else if (upath[0]=='/' || upath[1] == ':' )
1061 if ( Utilities::IsDirectory( upath ) )
1063 script_paths.push_back(upath);
1067 bbtkError("'"<<upath<<"' : directory does not exist");
1070 // ==== relative path provided : search all bbs path appended with
1071 // the relative path provided
1074 std::vector<std::string>::const_iterator i;
1075 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1076 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1079 std::string full_path(*i);
1080 // we *really* want '.' to be the current working directory
1081 if (full_path == ".") {
1082 char buf[2048]; // for getcwd
1083 char * currentDir = getcwd(buf, 2048);
1084 std::string cwd(currentDir);
1085 full_path = currentDir;
1088 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1091 if ( Utilities::IsDirectory( full_path ) )
1093 script_paths.push_back(full_path);
1096 if (script_paths.empty())
1098 bbtkError("no '"<<upath<<"' subdir found in search paths"
1103 // === search paths list complete : now explore it
1106 std::vector<std::string>::iterator i;
1107 for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
1109 bbtkMessage("Interpreter",1,
1110 "--> Looking in '" << *i << "'" << std::endl);
1114 int nbFiles = Utilities::Explore(*i, false, Filenames);
1117 for (std::vector<std::string>::iterator j = Filenames.begin();
1118 j!= Filenames.end(); ++j)
1120 int lgr = (*j).size();
1122 continue; // ignore non .bbs file
1123 if ((*j).substr(lgr-4, 4) != ".bbs")
1126 (*stream) << "include \"" << *j << "\"\n";
1127 bbtkMessage("Interpreter",2,
1128 " --> Found '" << *j << "'" << std::endl);
1135 bbtkMessage("Interpreter",1,
1136 " --> No .bbs found"<< std::endl);
1140 bbtkMessage("Interpreter",1,
1141 " --> "<<nbBssFiles<<" .bbs found"<< std::endl);
1142 SwitchToStream(stream);
1145 //break; // a directory was found; we stop iterating
1146 // LG : No! We want all files included !
1150 //=============== end pkgname=="*" ===========
1153 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1154 // (not only a plain script name)
1155 // we trust him, and try to expland the directory name
1156 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1158 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1161 // ===========================================================check user supplied location
1162 fullnameGiven = true;
1164 fullPathScriptName = Utilities::ExpandLibName(name, false);
1166 // allow user to always forget ".bbs"
1167 int l = fullPathScriptName.size();
1173 if (fullPathScriptName.substr(l-4, 4) != ".bbs")
1175 fullPathScriptName = fullPathScriptName + ".bbs";
1180 fullPathScriptName = fullPathScriptName + ".bbs";
1183 if ( Utilities::FileExists(fullPathScriptName))
1190 // =============================== iterate on the paths
1192 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1194 std::vector<std::string>::iterator i;
1195 for (i=script_paths.begin();i!=script_paths.end();++i)
1198 // we *really* want '.' to be the current working directory
1200 char buf[2048]; // for getcwd
1201 char * currentDir = getcwd(buf, 2048);
1202 std::string cwd(currentDir);
1206 fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
1208 // Check if library exists
1209 if ( ! Utilities::FileExists(fullPathScriptName) )
1211 // The following is *NOT* a debug time message :
1212 // It's a user intended message.
1213 // Please don't remove it.
1214 bbtkMessage("Interpreter",2,
1215 " [" <<fullPathScriptName <<"] : doesn't exist"
1217 continue; // try next path
1219 bbtkMessage("Interpreter",2,
1220 " [" <<fullPathScriptName
1221 <<"] : found" <<std::endl);
1223 break; // a script was found; we stop iterating
1225 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1231 if(fullPathScriptName == "")
1232 bbtkError("Path ["<<upath<<"] doesn't exist");
1234 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1236 bbtkError("No ["<<pkgname<<".bbs] script found");
1240 LoadScript(fullPathScriptName,name);
1244 //=======================================================================
1247 //=======================================================================
1248 void Interpreter::SwitchToStream( std::stringstream* stream )
1250 mFile.push_back(stream);
1251 std::ostringstream buffer_name;
1253 buffer_name << "buffer_" ;
1255 if (mFileName.size()>0 )
1257 buffer_name << mFileName.back() << "_" << mLine.back();
1259 mFileName.push_back(buffer_name.str());
1260 mIncludeFileName.push_back(buffer_name.str());
1263 //=======================================================================
1265 //=======================================================================
1267 void Interpreter::LoadScript( std::string fullPathScriptName,
1268 std::string includeScriptName)
1270 Utilities::replace( fullPathScriptName ,
1271 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1273 if (find(mFileNameHistory.begin(),
1274 mFileNameHistory.end(),
1275 fullPathScriptName)!=mFileNameHistory.end())
1281 s = new std::ifstream;
1282 s->open(fullPathScriptName.c_str());
1285 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1289 bbtkMessage("Interpreter",1," -->[" << fullPathScriptName
1290 << "] found" << std::endl);
1293 mFileName.push_back(fullPathScriptName);
1294 mFileNameHistory.push_back(fullPathScriptName);
1295 mIncludeFileName.push_back(includeScriptName);
1301 //=======================================================================
1305 void Interpreter::CloseCurrentFile()
1307 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseCurrentFile()"
1310 if (mFile.size()==0)
1312 bbtkDebugMessage("Interpreter",9," -> no file left open"<<std::endl);
1316 bbtkDebugMessage("Interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1318 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1319 if (file!=0) file->close();
1321 delete mFile.back();
1323 mFileName.pop_back();
1324 mIncludeFileName.pop_back();
1327 bbtkDebugMessage("Interpreter",9," Remains "
1329 <<" open"<<std::endl);
1330 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseCurrentFile()"
1333 //=======================================================================
1335 //=======================================================================
1339 void Interpreter::CloseAllFiles()
1341 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseAllFiles()"
1344 while (mFile.size() != 0)
1348 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()"
1351 //=======================================================================
1355 //=======================================================================
1359 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1360 CommandInfoType& info )
1362 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretCommand(...)"<<std::endl);
1364 // searches the command keyword
1365 CommandDictType::iterator c;
1366 c = mCommandDict.find(words[0]);
1367 if ( c == mCommandDict.end() ) {
1368 bbtkError(words[0]<<" : unknown command");
1371 // tests the number of args
1372 if ( ( words.size()-1 < c->second.argmin ) ||
1373 ( words.size()-1 > c->second.argmax ) )
1375 HelpCommand(words[0]);
1376 bbtkError(words[0]<<" : wrong number of arguments");
1380 bbtkDecTab("Interpreter",9);
1382 //=======================================================================
1385 //=======================================================================
1386 /// Displays help on all the commands
1387 void Interpreter::Help(const std::vector<std::string>& words)
1389 unsigned int nbarg = words.size()-1;
1397 if (words[1]=="packages")
1399 GetExecuter()->GetFactory()->PrintPackages(true);
1404 HelpCommand(words[1]);
1406 catch (bbtk::Exception e)
1410 GetExecuter()->GetFactory()->HelpPackage(words[1]);
1414 ConfigurationFile::GetInstance().Get_doc_path();
1415 url += "/bbdoc/" + words[1] + "/index.html";
1416 if (Utilities::FileExists(url))
1418 mUser->InterpreterUserViewHtmlPage(url);
1422 catch (bbtk::Exception f)
1426 std::string package;
1427 GetExecuter()->GetFactory()->HelpBlackBox(words[1],package);
1431 ConfigurationFile::GetInstance().Get_doc_path();
1432 url += "/bbdoc/" + package + "/index.html";
1433 if (Utilities::FileExists(url))
1435 url += "#" + words[1];
1436 mUser->InterpreterUserViewHtmlPage(url);
1440 catch (bbtk::Exception g)
1444 GetExecuter()->ShowRelations(words[1],"0","9999");
1446 catch (bbtk::Exception h){
1447 bbtkError("\""<<words[1].c_str()
1448 <<"\" is not a known command, package, black box type or black box name");
1456 if (words[2]=="all")
1458 if ( words[1]=="packages" )
1460 GetExecuter()->GetFactory()->PrintPackages(true,true);
1465 GetExecuter()->GetFactory()->HelpPackage(words[1],true);
1467 catch (bbtk::Exception f)
1473 HelpCommand(words[0]);
1474 bbtkError(words[0]<<" : syntax error");
1479 bbtkError("Should not reach here !!!");
1482 //=======================================================================
1484 //===================================================================
1485 /// Displays the Configuration
1486 void Interpreter::Config() const
1488 ConfigurationFile::GetInstance().GetHelp(1);
1490 //===================================================================
1492 //=======================================================================
1493 /// Displays help on all the commands
1494 void Interpreter::HelpCommands()
1496 std::cout << "Available commands :" << std::endl;
1497 CommandDictType::iterator i;
1498 for ( i = mCommandDict.begin();
1499 i != mCommandDict.end();
1501 std::cout << " " << i->first << std::endl;
1502 // std::cout << " usage : " << i->second.syntax << std::endl;
1503 // std::cout << " " << i->second.help << std::endl;
1507 //=======================================================================
1510 //=======================================================================
1511 /// Displays help on a particular commands
1512 void Interpreter::HelpCommand(const std::string& s)
1514 CommandDictType::iterator c;
1515 c = mCommandDict.find(s);
1516 if ( c == mCommandDict.end() ) {
1517 bbtkError(s<<" : Unknown command");
1519 // std::cout << " " << s << " : "<< std::endl;
1520 // CommandParamDictType::iterator i;
1521 // for ( i = c->second.begin();
1522 // i != c->second.end();
1524 std::cout << " usage : " << c->second.syntax << std::endl;
1525 std::cout << " " << c->second.help << std::endl;
1528 //=======================================================================
1531 //=======================================================================
1532 /// Fills the vector commands with the commands which
1533 /// have the first n chars of buf for prefix
1534 /// TODO : skip initial spaces in buf and also return the position of first
1535 /// non blank char in buf
1536 void Interpreter::FindCommandsWithPrefix( char* buf,
1538 std::vector<std::string>& commands )
1540 CommandDictType::const_iterator i;
1541 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1543 if ((i->first).find(buf,0,n) == 0)
1544 commands.push_back(i->first);
1547 //=======================================================================
1551 //=======================================================================
1552 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1554 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1555 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1557 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1558 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1559 // E.G. STORE THIS IN bbtk_config.xml
1560 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1561 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1562 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1563 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1564 #define BBTK_BACKSPACE_KBCODE 0x00000008
1565 #define BBTK_DEL_KBCODE 0x0000007F
1566 #define BBTK_SPACE_KBCODE 0x00000020
1568 //=======================================================================
1569 void Interpreter::GetLineFromPrompt(std::string& s)
1574 int MAX_LINE_SIZE = 160;
1575 int MAX_HISTORY_SIZE = 100;
1577 char* newline = new char[MAX_LINE_SIZE];
1578 memset(newline,0,MAX_LINE_SIZE);
1579 char* histline = new char[MAX_LINE_SIZE];
1580 memset(histline,0,MAX_LINE_SIZE);
1582 char* line = newline;
1583 int hist = mHistory.size();
1589 read ( STDIN_FILENO, &c, 4) ;
1591 bbtkDebugMessage("debug",9,"[0x"<<std::hex<<c<<"]\n");
1593 // Printable character
1594 if ( (ind<MAX_LINE_SIZE-1) &&
1595 ( c >= BBTK_SPACE_KBCODE ) &&
1596 ( c < BBTK_DEL_KBCODE ))
1604 // delete the unused line
1610 // empty lines are not stored in from history
1613 // if history too long : delete oldest command
1614 if (mHistory.size()>MAX_HISTORY_SIZE)
1616 delete mHistory.front();
1617 mHistory.pop_front();
1619 mHistory.push_back(line);
1624 else if ( (ind>0) &&
1625 ((c == BBTK_BACKSPACE_KBCODE) ||
1626 (c == BBTK_DEL_KBCODE)) )
1634 // TODO : Command completion
1635 std::vector<std::string> commands;
1636 FindCommandsWithPrefix( line,ind,commands);
1637 if (commands.size()==1)
1639 std::string com = *commands.begin();
1640 for (; ind<com.size(); ++ind)
1642 PrintChar(com[ind]);
1648 else if (commands.size()>1)
1650 std::vector<std::string>::iterator i;
1652 for (i=commands.begin();i!=commands.end();++i)
1654 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1657 write(STDOUT_FILENO,"\n> ",3);
1658 //for (int j=0;j<ind;++j)
1660 write(STDOUT_FILENO,line,ind);
1664 // Arrow up : back in history
1665 else if (c==BBTK_UP_ARROW_KBCODE)
1669 // erase current line
1670 while (ind--) BackSpace();
1674 strcpy(histline,mHistory[hist]);
1678 write(STDOUT_FILENO,line,ind);
1681 // Arrow down : down in history
1682 else if (c==BBTK_DOWN_ARROW_KBCODE)
1684 if (hist<mHistory.size()-1)
1686 // erase current line
1687 while (ind--) BackSpace();
1691 strcpy(histline,mHistory[hist]);
1695 write(STDOUT_FILENO,line,ind);
1697 // end of history : switch back to newline
1698 else if (hist==mHistory.size()-1)
1700 // erase current line
1701 while (ind--) BackSpace();
1708 write(STDOUT_FILENO,line,ind);
1712 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1714 PrintChar(line[ind]);
1719 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1727 write(STDOUT_FILENO,"\n\r",2);
1735 //=======================================================================
1736 void Interpreter::GetLineFromPrompt(std::string& s)
1762 //=======================================================================
1768 //=======================================================================
1769 void Interpreter::CommandLineInterpreter()
1771 bbtkDebugMessageInc("Interpreter",9,
1772 "Interpreter::CommandLineInterpreter()"<<std::endl);
1774 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1775 // Initialise the tty in non canonical mode with no echo
1776 // oter remembers the previous settings to restore them after
1777 struct termios ter,oter;
1780 ter.c_lflag &= ~ECHO;
1781 ter.c_lflag &= ~ICANON;
1784 tcsetattr(0,TCSANOW,&ter);
1787 mCommandLine = true;
1789 bool insideComment = false; // for multiline comment
1795 GetLineFromPrompt(line);
1796 InterpretLine(line, insideComment);
1798 catch (QuitException e)
1800 bbtkMessage("Interpreter",1,"Interpreter : Quit"<<std::endl);
1803 catch (bbtk::Exception e)
1807 catch (std::exception& e)
1809 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1813 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1818 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1819 tcsetattr(0,TCSANOW,&oter);
1822 std::cout << "Good bye !" << std::endl;
1824 bbtkDebugDecTab("Interpreter",9);
1827 //=======================================================================
1828 void Interpreter::Graph(const std::vector<std::string>& words)
1831 bool system_display = true;
1833 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1834 system_display = false;
1836 if (words.size()==1)
1838 page = mVirtualExecuter->ShowGraph(".","0","0","","","",system_display);
1840 else if (words.size()==2)
1842 page = mVirtualExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1844 else if (words.size()==3)
1846 page = mVirtualExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1848 else if (words.size()==4)
1850 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1852 else if (words.size()==5)
1854 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1856 else if (words.size()==6)
1858 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1860 else if (words.size()==7)
1862 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1865 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1866 mUser->InterpreterUserViewHtmlPage(page);
1869 //=======================================================================
1872 //=======================================================================
1873 void Interpreter::Index(const std::string& filename,
1874 const std::string& type)
1876 Factory::IndexEntryType t;
1877 if (type=="Initials") t = Factory::Initials;
1878 else if (type=="Categories") t = Factory::Categories;
1879 else if (type=="Packages") t = Factory::Packages;
1880 else if (type=="Adaptors") t = Factory::Adaptors;
1882 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1884 //=======================================================================
1887 //=======================================================================
1888 void Interpreter::NewGUI(const std::string& boxname,
1889 const std::string& instanceName)
1891 if (mRealExecuter.expired())
1893 bbtkError("command 'newgui' cannot be compiled yet");
1896 std::string typeName = instanceName+"Type";
1897 std::stringstream* s = new std::stringstream;
1898 // create the complex box
1899 (*s) << "define "<<typeName<<std::endl;
1900 // (*s) << " description 'Automatically generated user interface for the box "
1901 // << boxname << "'" <<std::endl;
1902 // create the Layout box
1903 (*s) << " load wx"<<std::endl;
1904 (*s) << " new LayoutLine layout"<<std::endl;
1905 // create the output 'Widget'
1906 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1907 // the box change output
1908 (*s) << " new MultipleInputs change"<<std::endl;
1909 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1911 // Browse the inputs of the box in order to find which ones are not
1912 // connected and can be adapted from a widget adaptor
1913 // vector which stores the list of inputs of the box which must be connected
1914 std::vector<std::string> in;
1916 Factory::Pointer F = mVirtualExecuter->GetFactory();
1918 Package::Pointer user = F->GetPackage("user");
1920 ComplexBlackBoxDescriptor::Pointer workspace =
1921 mRealExecuter.lock()->GetCurrentDescriptor();
1926 bbtkError("Interpreter::CreateGUI : could not access the executer currently defined complex box");
1931 (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get());
1934 BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname);
1935 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
1937 BlackBox::InputConnectorMapType::iterator i;
1938 for (i=box->bbGetInputConnectorMap().begin();
1939 i!=box->bbGetInputConnectorMap().end();
1942 // If the input is connected : continue
1943 if (i->second->IsConnected()) continue;
1944 // Get the input descriptor
1945 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
1946 // If it is a "system" input : skip it
1947 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
1948 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
1951 std::string widget,adaptor;
1952 // try to find a widget adaptor
1953 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
1957 // command to create the adaptor
1958 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1959 // Sets the label of the widget adaptor to the name of the input
1960 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
1961 // Sets the initial value of the widget to the value of the input
1962 (*s) << " set "<<i->first<<".In \" "
1963 <<box->bbGetInputAsString(i->first)<<"\""
1965 // store the input name
1966 in.push_back(i->first);
1967 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
1968 //<i->first<<"'"<<std::endl;
1969 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
1971 // try to find a two pieces adaptor
1972 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
1976 // command to create the widget
1977 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
1978 // command to create the adaptor
1979 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1981 (*s) << " connect "<<i->first<<"Widget.Out "
1982 <<i->first<<".In"<<std::endl;
1983 // Sets the label of the widget adaptor to the name of the input
1984 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
1985 // Sets the initial value of the widget to the value of the input
1986 (*s) << " set "<<i->first<<"Widget.In \" "
1987 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
1988 // store the input name
1989 in.push_back(i->first);
1990 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
1991 //<i->first<<"'"<<std::endl;
1992 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
1995 // try to find an adaptor from string
1996 // If found then can create a text input which
1997 // will be automatically adapted
1998 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
2002 // command to create the adaptor
2003 (*s) << " new InputText "<<i->first<<std::endl;
2004 // Sets the label of the widget adaptor to the name of the input
2005 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
2006 // Sets the initial value of the widget to the value of the input
2007 (*s) << " set "<<i->first<<".In \" "
2008 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
2009 // store the input name
2010 in.push_back(i->first);
2011 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
2012 //<i->first<<"'"<<std::endl;
2013 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2022 // command to create the output
2023 (*s) << " output "<<i->first<<" "
2024 <<i->first<<".Out "<<i->first<<std::endl;
2025 // <<" Output of the widget which allows to set "
2029 // Inputs for window properties
2030 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
2031 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
2032 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
2033 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
2034 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
2038 // Execute the box executes the layout
2039 (*s) << " exec layout" << std::endl;
2040 (*s) << "endefine" << std::endl;
2041 // (*s) << "help "<< typeName<< std::endl;
2042 // instanciate the box and connect it
2043 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2045 std::vector<std::string>::iterator j;
2046 for (j=in.begin();j!=in.end();++j)
2049 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2050 << boxname<<"."<<*j<<std::endl;
2052 // That's all folks ! now execute the commands :
2055 //=======================================================================
2059 //==========================================================================
2060 void Interpreter::Debug(const std::string& name)
2062 if ((name.length()==2)&&(name[0]=='-'))
2066 bbtk::StaticInitTime::PrintObjectListInfo = true;
2070 // int o = MessageManager::GetMessageLevel("debug");
2071 // if (o<2) MessageManager::SetMessageLevel("debug",2);
2072 mVirtualExecuter->GetFactory()->CheckPackages();
2073 // MessageManager::SetMessageLevel("debug",o);
2078 Object:: PrintObjectListInfo(name);
2081 //==========================================================================
2082 //==========================================================================
2083 std::string Interpreter::GetObjectName() const
2085 return std::string("Interpreter");
2087 //==========================================================================
2089 //==========================================================================
2090 std::string Interpreter::GetObjectInfo() const
2092 std::stringstream i;
2095 //==========================================================================
2097 //==========================================================================
2098 size_t Interpreter::GetObjectSize() const
2100 size_t s = Superclass::GetObjectSize();
2101 s += Interpreter::GetObjectInternalSize();
2104 //==========================================================================
2105 //==========================================================================
2106 size_t Interpreter::GetObjectInternalSize() const
2108 size_t s = sizeof(Interpreter);
2111 //==========================================================================
2112 //==========================================================================
2113 size_t Interpreter::GetObjectRecursiveSize() const
2115 size_t s = Superclass::GetObjectRecursiveSize();
2116 s += Interpreter::GetObjectInternalSize();
2117 s += mVirtualExecuter->GetObjectRecursiveSize();
2120 //==========================================================================