1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.cxx,v $ $
6 Date: $Date: 2008/04/25 08:05:23 $
7 Version: $Revision: 1.65 $
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()"<<std::endl);
46 return MakePointer(new Interpreter(cpp_file));
48 //=======================================================================
50 //=======================================================================
51 Interpreter::Interpreter(const std::string& cpp_file)
59 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);
60 bbtk::MessageManager::RegisterMessageType("Interpreter","Messages of the interpreter",0);
61 bbtkDebugMessageInc("Interpreter",9,"Interpreter::Interpreter()" <<std::endl);
63 if (cpp_file.size()!=0)
65 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(bbtk::Transcriptor::New(cpp_file));
69 bbtk::Executer::Pointer exe = bbtk::Executer::New();
71 mVirtualExecuter = boost::static_pointer_cast<VirtualExec>(exe);
74 // Lock this pointer or will auto-destruct !!
75 mVirtualExecuter->SetInterpreter(MakePointer(this,true));
77 // For the time being, comment out previous line, and
78 // uncomment next line to check Transcriptor
80 //mVirtualExecuter = new bbtk::Transcriptor("GeneratedProgram.txt");
82 // Builds the commands dict
89 info.syntax = "new <type> <name>";
90 info.help = "Creates a new black box of type <type> with name <name>";
91 mCommandDict[info.keyword] = info;
93 info.keyword = "delete";
97 info.syntax = "delete <box>";
98 info.help = "Deletes the black box of name <box>";
99 mCommandDict[info.keyword] = info;
101 info.keyword = "newgui";
105 info.syntax = "newgui <box> <name>";
106 info.help = "Automatically creates a graphical user interface with name <name> for the black box <box> and connects it to the box inputs";
107 mCommandDict[info.keyword] = info;
109 info.keyword = "connect";
112 info.code = cConnect;
113 info.syntax = "connect <box1.output> <box2.input>";
114 info.help = "Connects the ouput <output> of black box <box1> to the input <input> of black box <box2>";
115 mCommandDict[info.keyword] = info;
117 info.keyword = "print";
121 info.syntax = "print <string>";
122 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').";
123 mCommandDict[info.keyword] = info;
125 info.keyword = "exec";
129 info.syntax = "exec <box | 'freeze' | 'unfreeze' >";
130 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.";
131 mCommandDict[info.keyword] = info;
133 info.keyword = "package";
136 info.code = cPackage;
137 info.syntax = "package <name>";
138 info.help = "Begins the definition of a package.";
139 mCommandDict[info.keyword] = info;
141 info.keyword = "endpackage";
144 info.code = cEndPackage;
145 info.syntax = "endpackage";
146 info.help = "Ends the definition of a package.";
147 mCommandDict[info.keyword] = info;
149 info.keyword = "define";
153 info.syntax = "define <type> [<package>]";
154 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.";
155 mCommandDict[info.keyword] = info;
157 info.keyword = "endefine";
160 info.code = cEndDefine;
161 info.syntax = "endefine";
162 info.help = "Ends the definition of a new type of complex black box";
163 mCommandDict[info.keyword] = info;
165 info.keyword = "kind";
169 info.syntax = "kind <ADAPTOR|DEFAULT_ADAPTOR|WIDGET_ADAPTOR|DEFAULT_WIDGET_ADAPTOR>";
170 info.help = "Sets the kind of the currently defined complex black box";
171 mCommandDict[info.keyword] = info;
173 info.keyword = "input";
177 info.syntax = "input <name> <box.input> <help>";
178 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";
179 mCommandDict[info.keyword] = info;
181 info.keyword = "output";
185 info.syntax = "output <name> <box.output> <help>";
186 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";
187 mCommandDict[info.keyword] = info;
189 info.keyword = "set";
193 info.syntax = "set <box.input> <value>";
194 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";
195 mCommandDict[info.keyword] = info;
197 info.keyword = "config"; // JPR
201 info.syntax = "config";
202 info.help = "Prints the value of all configuration parameters";
203 mCommandDict[info.keyword] = info;
205 info.keyword = "index"; // LG
210 info.syntax = "index [<filename> ['Initials'(default)|'Packages'|'Categories'|'Adaptors']]";
211 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.";
212 mCommandDict[info.keyword] = info;
214 info.keyword = "reset";
218 info.syntax = "reset";
219 info.help = "Deletes all boxes and unloads all packages (bbi is reset to its start state)";
220 mCommandDict[info.keyword] = info;
222 info.keyword = "author";
226 info.syntax = "author <string>";
227 info.help = "Adds the string <string> to the author information of the black box being defined";
228 mCommandDict[info.keyword] = info;
230 info.keyword = "category"; //JP
233 info.code = cCategory;
234 info.syntax = "category <list of items, separated by ;>";
235 info.help = "Adds the string <string> to the category information of the black box being defined";
236 mCommandDict[info.keyword] = info;
238 info.keyword = "description";
241 info.code = cDescription;
242 info.syntax = "description <string>";
243 info.help = "Adds the string <string> to the descriptive information of the black box being defined";
244 mCommandDict[info.keyword] = info;
246 info.keyword = "help";
250 info.syntax = "help";
251 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>";
252 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.";
253 mCommandDict[info.keyword] = info;
255 info.keyword = "message";
258 info.code = cMessage;
259 info.syntax = "message <kind> <level>";
260 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;
262 info.keyword = "include";
265 info.code = cInclude;
266 info.syntax = "include <filename> [source]";
267 info.help = "Includes the file <filename>.\n 'source' : If the keyword 'source' is provided then informs bbi 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).";
268 mCommandDict[info.keyword] = info;
270 info.keyword = "quit";
274 info.syntax = "quit";
275 info.help = "Quits the program (during script execution it stops the complete execution)";
276 mCommandDict[info.keyword] = info;
278 info.keyword = "load";
282 info.syntax = "load <packagename>";
283 info.help = "Loads the black box package <packagename>";
284 mCommandDict[info.keyword] = info;
286 info.keyword = "unload";
290 info.syntax = "unload <packagename>";
291 info.help = "Unloads the black box package <packagename>";
292 mCommandDict[info.keyword] = info;
294 info.keyword = "graph";
298 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 ]]]]]]";
299 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')";
300 mCommandDict[info.keyword] = info;
302 info.keyword = "debug";
306 info.syntax = "debug [expr|-C|-D]";
307 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";
308 mCommandDict[info.keyword] = info;
311 info.keyword = "workspace";
314 info.code = cWorkspace;
315 info.syntax = "workspace < ( freeze | unfreeze ) | ( rename <newname> ) >";
316 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.";
317 mCommandDict[info.keyword] = info;
320 bbtkDebugDecTab("Interpreter",9);
323 //=======================================================================
327 //=======================================================================
331 Interpreter::~Interpreter()
333 bbtkDebugMessageInc("Interpreter",9,"==> Interpreter::~Interpreter()" <<std::endl);
334 mVirtualExecuter = VirtualExec::Pointer();
335 bbtkDebugMessageInc("Interpreter",9,"<== Interpreter::~Interpreter()" <<std::endl);
337 //=======================================================================
340 InterpreterError::InterpreterError( const std::string& message,
342 const std::string& script_file,
345 : Exception("Interpreter",0,message),
346 mInScriptFile(in_script_file),
347 mScriptFile(script_file),
348 mScriptLine(script_line)
351 InterpreterError::InterpreterError( const Exception& excep,
353 const std::string& script_file,
357 mInScriptFile(in_script_file),
358 mScriptFile(script_file),
359 mScriptLine(script_line)
362 //=======================================================================
363 void Interpreter::CatchBbtkException( const bbtk::Exception& e )
367 bool in_script = false;
368 std::string file("");
370 if (mFileName.size()) {
371 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
372 if (fs!=0) in_script = true;
373 file = mFileName.back();
377 throw InterpreterError(e,in_script,file,line);
381 std::stringstream mess;
382 mess << "* ERROR : "<<e.GetMessage()<<std::endl;
383 if (mFileName.size()) {
384 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
385 mess << "* LINE : "<<mLine.back()<<std::endl;
387 std::cerr << mess.str();
390 //=======================================================================
392 //=======================================================================
393 void Interpreter::CatchStdException( const std::exception& e )
397 bool in_script = false;
398 std::string file("");
400 if (mFileName.size()) {
401 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
402 if (fs!=0) in_script = true;
403 file = mFileName.back();
407 throw InterpreterError(e.what(),in_script,file,line);
411 std::stringstream mess;
412 mess << "* ERROR : "<<e.what()<<std::endl;
413 if (mFileName.size()) {
414 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
415 mess << "* LINE : "<<mLine.back()<<std::endl;
417 std::cerr << mess.str();
420 //=======================================================================
422 //=======================================================================
423 void Interpreter::CatchUnknownException()
427 bool in_script = false;
428 std::string file("");
430 if (mFileName.size()) {
431 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
432 if (fs!=0) in_script = true;
433 file = mFileName.back();
437 throw InterpreterError("Unknown exception caught",
438 in_script,file,line);
442 std::stringstream mess;
443 mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
445 if (mFileName.size()) {
446 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
447 mess << "* LINE : "<<mLine.back()<<std::endl;
449 std::cerr << mess.str();
452 //=======================================================================
454 //=======================================================================
456 #define CATCH_MACRO \
457 catch (QuitException e) \
459 status = Interpreter_QUIT; \
460 if (mThrow) throw QuitException(); \
462 catch (bbtk::Exception e) \
464 status = Interpreter_ERROR; \
465 CatchBbtkException(e); \
467 catch (std::exception& e) \
469 status = Interpreter_ERROR; \
470 CatchStdException(e); \
474 status = Interpreter_ERROR; \
475 CatchUnknownException(); \
477 //=======================================================================
480 //=======================================================================
484 Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename )
486 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
488 bool exm = mCommandLine;
489 mCommandLine = false;
491 ExitStatus status = Interpreter_OK;
495 SwitchToFile(filename);
497 bool insideComment = false; // for multiline comment
498 while (mFile.size()>0)
500 while (!mFile.back()->eof()) {
503 mFile.back()->getline(buf,500);
504 std::string str(buf);
505 int size=str.length();
506 if ( str[ size-1 ]==13 )
511 InterpretLine(str, insideComment);
520 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
521 bbtkDecTab("Interpreter",9);
527 //=======================================================================
530 //=======================================================================
534 Interpreter::ExitStatus
535 Interpreter::InterpretBuffer( std::stringstream* buffer )
537 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretBuffer()"<<std::endl);
539 bool exm = mCommandLine;
540 mCommandLine = false;
542 ExitStatus status = Interpreter_OK;
546 SwitchToStream(buffer);
547 bool insideComment = false; // for multiline comment
548 while (mFile.size()>0)
550 while (!mFile.back()->eof()) {
553 mFile.back()->getline(buf,500);
554 std::string str(buf);
556 int size=str.length();
557 if ( str[ size-1 ]==13 )
562 InterpretLine(str, insideComment);
572 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
573 bbtkDecTab("Interpreter",9);
578 //=======================================================================
580 //=======================================================================
581 /// Runs the interpretation of a command
582 Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
584 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
586 ExitStatus status = Interpreter_OK;
590 bool insideComment = false;
591 InterpretLine(line, insideComment);
596 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretLine()"
598 bbtkDecTab("Interpreter",9);
604 //=======================================================================
608 void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
610 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine(\""<<line<<"\")"<<std::endl);
611 bbtkMessage("echo",2,line<<std::endl);
613 std::vector<std::string> words;
614 SplitLine(line,words);
619 bbtkDebugDecTab("Interpreter",9);
623 // Single line comment : # or //
624 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
626 bbtkDebugDecTab("Interpreter",9);
627 bbtkMessage("Interpreter",9,"Comment"<<std::endl);
631 // Multi line comment ( /* ... */ ) -delimiters on different lines !-
633 if (words[0][0]=='/' && words[0][1]=='*')
635 bbtkDebugDecTab("Interpreter",9);
636 bbtkMessage("Interpreter",9,"In multiline comment"<<std::endl);
637 insideComment = true;
641 if (words[0][0]=='*' && words[0][1]=='/')
643 bbtkDebugDecTab("Interpreter",9);
644 bbtkMessage("Interpreter",9,"Out multiline comment"<<std::endl);
645 if ( !insideComment ) {
646 bbtkDebugDecTab("Interpreter",9);
647 bbtkMessage("Interpreter",9,"Comment mismatch : '*/' with no matching '/*'"<<std::endl);
649 insideComment = false;
655 bbtkDebugDecTab("Interpreter",9);
656 bbtkMessage("Interpreter",9,"Multiline Comment"<<std::endl);
661 CommandInfoType command;
662 InterpretCommand(words,command);
664 bbtkDebugMessage("Interpreter",9,
665 "Command='"<<command.keyword
666 <<"' code="<<command.code<<std::endl);
668 std::string left,right,left2,right2;
669 std::string filename;
670 switch (command.code)
673 mVirtualExecuter->Create(words[1],words[2]);
677 mVirtualExecuter->Destroy(words[1]);
681 Utilities::SplitAroundFirstDot(words[1],left,right);
682 Utilities::SplitAroundFirstDot(words[2],left2,right2);
683 mVirtualExecuter->Connect(left,right,left2,right2);
687 mVirtualExecuter->BeginPackage(words[1]);
691 mVirtualExecuter->EndPackage();
695 if (mFileName.size()>0)
697 filename = mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
701 mVirtualExecuter->Define(words[1],"",filename);
705 mVirtualExecuter->Define(words[1],words[2],filename);
710 mVirtualExecuter->EndDefine();
714 mVirtualExecuter->Kind(words[1]);
718 mVirtualExecuter->Print(words[1]);
722 if (words[1]=="freeze")
723 mVirtualExecuter->SetNoExecMode(true);
724 else if (words[1]=="unfreeze")
725 mVirtualExecuter->SetNoExecMode(false);
727 mVirtualExecuter->Execute(words[1]);
731 Utilities::SplitAroundFirstDot(words[2],left,right);
732 mVirtualExecuter->DefineInput(words[1],left,right,words[3]);
736 Utilities::SplitAroundFirstDot(words[2],left,right);
737 mVirtualExecuter->DefineOutput(words[1],left,right,words[3]);
741 Utilities::SplitAroundFirstDot(words[1],left,right);
742 mVirtualExecuter->Set(left,right,words[2]);
746 mVirtualExecuter->Author(words[1]);
750 NewGUI(words[1],words[2]);
754 mVirtualExecuter->Category(words[1]);
759 Index("tmp_index.html");
760 else if (words.size()==2)
762 else if (words.size()==3)
763 Index(words[1],words[2]);
767 mVirtualExecuter->Description(words[1]);
777 mVirtualExecuter->HelpMessages();
781 sscanf(words[2].c_str(),"%d",&level);
782 mVirtualExecuter->SetMessageLevel(words[1],level);
801 InterpretFile(words[1]);
805 SwitchToFile(words[1]);
807 // if 'source' was given
810 GetExecuter()->SetCurrentFileName(words[1]);
815 GetExecuter()->LoadPackage(words[1]);
819 GetExecuter()->UnLoadPackage(words[1]);
823 throw QuitException();
827 if (words.size()==2) Debug(words[1]);
832 if (words.size() == 2)
834 if (words[1]=="freeze") mVirtualExecuter->SetNoExecMode(true);
835 else if (words[1]=="unfreeze") mVirtualExecuter->SetNoExecMode(false);
839 mVirtualExecuter->SetWorkspaceName(words[2]);
844 bbtkInternalError("should not reach here !!!");
847 bbtkDecTab("Interpreter",9);
849 //=======================================================================
855 //=======================================================================
859 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
861 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
863 std::string delimiters = "\"";
864 std::vector<std::string> quote;
865 Utilities::SplitString(str,delimiters,quote);
868 std::vector<std::string>::iterator i;
869 for (i=quote.begin(); i!=quote.end(); )
871 Utilities::SplitString(*i,delimiters,tokens);
875 // bbtkDebugMessage("Interpreter",0,"\""<<*i<<"\""<<std::endl);
876 tokens.push_back(*i);
881 for (i=tokens.begin(); i!=tokens.end(); ++i)
883 bbtkDebugMessage("Interpreter",9,"["<<*i<<"] ");
885 bbtkDebugMessageCont("Interpreter",9,std::endl);
887 bbtkDebugDecTab("Interpreter",9);
889 //=======================================================================
892 //=======================================================================
893 void Interpreter::Reset()
895 // Cannot close all files if the reset command is read from a file !
897 mFileNameHistory.clear();
898 this->mVirtualExecuter->Reset();
900 //=======================================================================
902 //=======================================================================
907 void Interpreter::Print( const std::string& str)
909 if (mVirtualExecuter->GetNoExecMode()) return;
911 bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
914 // InterpretLine ("load std")
915 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
916 // InterpretLine("new Print _P_")
917 // InterpretLine("connect _C_.Out _P_.In")
921 std::vector<std::string> chains;
922 std::string delimiters("$");
924 // Skip delimiters at beginning.
925 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
927 if (lastPos>0) is_text = false;
929 // Find first delimiter.
930 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
932 while (std::string::npos != pos || std::string::npos != lastPos)
936 // Found a text token, add it to the vector.
937 chains.push_back(str.substr(lastPos, pos - lastPos));
938 // std::string token = str.substr(lastPos, pos - lastPos)
939 // InterpretLine("set _C_.In%num% %token%")
945 // is an output (between $$) : decode
946 std::string tok,box,output;
947 tok = str.substr(lastPos, pos - lastPos);
948 Utilities::SplitAroundFirstDot(tok,box,output);
949 chains.push_back( mVirtualExecuter->Get(box,output) );
951 // InterpretLine("connect %tok% _C_.In%num%")
954 // Skip delimiters. Note the "not_of"
955 lastPos = str.find_first_not_of(delimiters, pos);
956 // Find next delimiter
957 pos = str.find_first_of(delimiters, lastPos);
962 // InterpretLine("exec _P_")
963 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
965 std::vector<std::string>::iterator i;
966 for (i= chains.begin(); i!=chains.end(); ++i)
969 Utilities::SubsBackslashN(*i);
972 std::cout << std::endl;
973 bbtkDebugDecTab("Interpreter",9);
977 //=======================================================================
982 // =========================================================================
983 void Interpreter::SwitchToFile( const std::string& name )
985 // Note : in the following :
986 // name : the user supplied name
987 // - abreviated name e.g. scr scr.bbs
988 // - relative full name e.g. ./scr.bbs ../../scr.bbs
989 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
990 // same for Windows, with c:, d: ...
992 // use ./directory/subdir/scrname.bbs
995 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SwitchToFile( \""
996 <<name<<"\")"<<std::endl);
998 std::vector<std::string> script_paths;
999 std::string fullPathScriptName; // full path script name
1000 std::string pkgname; // e.g. <scriptname>.bbs
1001 std::vector<std::string> Filenames;
1003 // The following is *NOT* a debug time message :
1004 // It's a user intended message.
1005 // Please don't remove it.
1006 bbtkMessage("Interpreter",1,
1007 "look for : [" << name
1008 << "]" << std::endl);
1012 pkgname = Utilities::ExtractScriptName(name,upath);
1014 bbtkMessage("Interpreter",3,
1015 "extract : pkgname [" << pkgname
1016 << "] upath [" << upath << "]" << std::endl);
1017 bool fullnameGiven = false;
1018 bool foundFile = false;
1020 // ==== "*" provided : load all scripts in given path
1021 // relative (e.g. std/boxes/*) or absolute
1026 std::stringstream* stream = new std::stringstream;
1027 //if (upath.size()!=0) // avoid troubles for "*"
1029 // ==== no path provided : look in root bbs path
1030 if (upath.size()==0)
1032 // bbtkMessage("Interpreter",1,
1033 script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1035 // ==== absolute path provided
1036 else if (upath[0]=='/' || upath[1] == ':' )
1038 if ( Utilities::IsDirectory( upath ) )
1040 script_paths.push_back(upath);
1044 bbtkError("'"<<upath<<"' : directory does not exist");
1047 // ==== relative path provided : search all bbs path appended with
1048 // the relative path provided
1051 std::vector<std::string>::const_iterator i;
1052 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1053 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1056 std::string full_path(*i);
1057 // we *really* want '.' to be the current working directory
1058 if (full_path == ".") {
1059 char buf[2048]; // for getcwd
1060 char * currentDir = getcwd(buf, 2048);
1061 std::string cwd(currentDir);
1062 full_path = currentDir;
1065 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1068 if ( Utilities::IsDirectory( full_path ) )
1070 script_paths.push_back(full_path);
1073 if (script_paths.empty())
1075 bbtkError("no '"<<upath<<"' subdir found in search paths"
1080 // === search paths list complete : now explore it
1083 std::vector<std::string>::iterator i;
1084 for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
1086 bbtkMessage("Interpreter",1,
1087 "--> Looking in '" << *i << "'" << std::endl);
1091 int nbFiles = Utilities::Explore(*i, false, Filenames);
1094 for (std::vector<std::string>::iterator j = Filenames.begin();
1095 j!= Filenames.end(); ++j)
1097 int lgr = (*j).size();
1099 continue; // ignore non .bbs file
1100 if ((*j).substr(lgr-4, 4) != ".bbs")
1103 (*stream) << "include \"" << *j << "\"\n";
1104 bbtkMessage("Interpreter",2,
1105 " --> Found '" << *j << "'" << std::endl);
1112 bbtkMessage("Interpreter",1,
1113 " --> No .bbs found"<< std::endl);
1117 bbtkMessage("Interpreter",1,
1118 " --> "<<nbBssFiles<<" .bbs found"<< std::endl);
1119 SwitchToStream(stream);
1122 //break; // a directory was found; we stop iterating
1123 // LG : No! We want all files included !
1127 //=============== end pkgname=="*" ===========
1130 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1131 // (not only a plain script name)
1132 // we trust him, and try to expland the directory name
1133 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1135 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1138 // ===========================================================check user supplied location
1139 fullnameGiven = true;
1141 fullPathScriptName = Utilities::ExpandLibName(name, false);
1143 // allow user to always forget ".bbs"
1144 int l = fullPathScriptName.size();
1150 if (fullPathScriptName.substr(l-4, 4) != ".bbs")
1152 fullPathScriptName = fullPathScriptName + ".bbs";
1157 fullPathScriptName = fullPathScriptName + ".bbs";
1160 if ( Utilities::FileExists(fullPathScriptName))
1167 // =============================== iterate on the paths
1169 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1171 std::vector<std::string>::iterator i;
1172 for (i=script_paths.begin();i!=script_paths.end();++i)
1175 // we *really* want '.' to be the current working directory
1177 char buf[2048]; // for getcwd
1178 char * currentDir = getcwd(buf, 2048);
1179 std::string cwd(currentDir);
1183 fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
1185 // Check if library exists
1186 if ( ! Utilities::FileExists(fullPathScriptName) )
1188 // The following is *NOT* a debug time message :
1189 // It's a user intended message.
1190 // Please don't remove it.
1191 bbtkMessage("Interpreter",2,
1192 " [" <<fullPathScriptName <<"] : doesn't exist"
1194 continue; // try next path
1196 bbtkMessage("Interpreter",2,
1197 " [" <<fullPathScriptName
1198 <<"] : found" <<std::endl);
1200 break; // a script was found; we stop iterating
1202 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1208 if(fullPathScriptName == "")
1209 bbtkError("Path ["<<upath<<"] doesn't exist");
1211 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1213 bbtkError("No ["<<pkgname<<".bbs] script found");
1217 LoadScript(fullPathScriptName,name);
1221 //=======================================================================
1224 //=======================================================================
1225 void Interpreter::SwitchToStream( std::stringstream* stream )
1227 mFile.push_back(stream);
1228 std::ostringstream buffer_name;
1230 buffer_name << "buffer_" ;
1232 if (mFileName.size()>0 )
1234 buffer_name << mFileName.back() << "_" << mLine.back();
1236 mFileName.push_back(buffer_name.str());
1237 mIncludeFileName.push_back(buffer_name.str());
1240 //=======================================================================
1242 //=======================================================================
1244 void Interpreter::LoadScript( std::string fullPathScriptName,
1245 std::string includeScriptName)
1247 Utilities::replace( fullPathScriptName ,
1248 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1250 if (find(mFileNameHistory.begin(),
1251 mFileNameHistory.end(),
1252 fullPathScriptName)!=mFileNameHistory.end())
1258 s = new std::ifstream;
1259 s->open(fullPathScriptName.c_str());
1262 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1266 bbtkMessage("Interpreter",1," -->[" << fullPathScriptName
1267 << "] found" << std::endl);
1270 mFileName.push_back(fullPathScriptName);
1271 mFileNameHistory.push_back(fullPathScriptName);
1272 mIncludeFileName.push_back(includeScriptName);
1278 //=======================================================================
1282 void Interpreter::CloseCurrentFile()
1284 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseCurrentFile()"
1287 if (mFile.size()==0)
1289 bbtkDebugMessage("Interpreter",9," -> no file left open"<<std::endl);
1293 bbtkDebugMessage("Interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1295 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1296 if (file!=0) file->close();
1298 delete mFile.back();
1300 mFileName.pop_back();
1301 mIncludeFileName.pop_back();
1304 bbtkDebugMessage("Interpreter",9," Remains "
1306 <<" open"<<std::endl);
1307 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseCurrentFile()"
1310 //=======================================================================
1312 //=======================================================================
1316 void Interpreter::CloseAllFiles()
1318 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseAllFiles()"
1321 while (mFile.size() != 0)
1325 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()"
1328 //=======================================================================
1332 //=======================================================================
1336 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1337 CommandInfoType& info )
1339 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretCommand(...)"<<std::endl);
1341 // searches the command keyword
1342 CommandDictType::iterator c;
1343 c = mCommandDict.find(words[0]);
1344 if ( c == mCommandDict.end() ) {
1345 bbtkError(words[0]<<" : unknown command");
1348 // tests the number of args
1349 if ( ( words.size()-1 < c->second.argmin ) ||
1350 ( words.size()-1 > c->second.argmax ) )
1352 HelpCommand(words[0]);
1353 bbtkError(words[0]<<" : wrong number of arguments");
1357 bbtkDecTab("Interpreter",9);
1359 //=======================================================================
1362 //=======================================================================
1363 /// Displays help on all the commands
1364 void Interpreter::Help(const std::vector<std::string>& words)
1366 unsigned int nbarg = words.size()-1;
1374 if (words[1]=="packages")
1376 GetExecuter()->GetFactory()->PrintPackages(true);
1381 HelpCommand(words[1]);
1383 catch (bbtk::Exception e)
1387 GetExecuter()->GetFactory()->HelpPackage(words[1]);
1391 ConfigurationFile::GetInstance().Get_doc_path();
1392 url += "/bbdoc/" + words[1] + "/index.html";
1393 if (Utilities::FileExists(url))
1395 mUser->InterpreterUserViewHtmlPage(url);
1399 catch (bbtk::Exception f)
1403 std::string package;
1404 GetExecuter()->GetFactory()->HelpBlackBox(words[1],package);
1408 ConfigurationFile::GetInstance().Get_doc_path();
1409 url += "/bbdoc/" + package + "/index.html";
1410 if (Utilities::FileExists(url))
1412 url += "#" + words[1];
1413 mUser->InterpreterUserViewHtmlPage(url);
1417 catch (bbtk::Exception g)
1421 GetExecuter()->ShowRelations(words[1],"0","9999");
1423 catch (bbtk::Exception h){
1424 bbtkError("\""<<words[1].c_str()
1425 <<"\" is not a known command, package, black box type or black box name");
1433 if (words[2]=="all")
1435 if ( words[1]=="packages" )
1437 GetExecuter()->GetFactory()->PrintPackages(true,true);
1442 GetExecuter()->GetFactory()->HelpPackage(words[1],true);
1444 catch (bbtk::Exception f)
1450 HelpCommand(words[0]);
1451 bbtkError(words[0]<<" : syntax error");
1456 bbtkError("Should not reach here !!!");
1459 //=======================================================================
1461 //===================================================================
1462 /// Displays the Configuration
1463 void Interpreter::Config() const
1465 ConfigurationFile::GetInstance().GetHelp(1);
1467 //===================================================================
1469 //=======================================================================
1470 /// Displays help on all the commands
1471 void Interpreter::HelpCommands()
1473 std::cout << "Available commands :" << std::endl;
1474 CommandDictType::iterator i;
1475 for ( i = mCommandDict.begin();
1476 i != mCommandDict.end();
1478 std::cout << " " << i->first << std::endl;
1479 // std::cout << " usage : " << i->second.syntax << std::endl;
1480 // std::cout << " " << i->second.help << std::endl;
1484 //=======================================================================
1487 //=======================================================================
1488 /// Displays help on a particular commands
1489 void Interpreter::HelpCommand(const std::string& s)
1491 CommandDictType::iterator c;
1492 c = mCommandDict.find(s);
1493 if ( c == mCommandDict.end() ) {
1494 bbtkError(s<<" : Unknown command");
1496 // std::cout << " " << s << " : "<< std::endl;
1497 // CommandParamDictType::iterator i;
1498 // for ( i = c->second.begin();
1499 // i != c->second.end();
1501 std::cout << " usage : " << c->second.syntax << std::endl;
1502 std::cout << " " << c->second.help << std::endl;
1505 //=======================================================================
1508 //=======================================================================
1509 /// Fills the vector commands with the commands which
1510 /// have the first n chars of buf for prefix
1511 /// TODO : skip initial spaces in buf and also return the position of first
1512 /// non blank char in buf
1513 void Interpreter::FindCommandsWithPrefix( char* buf,
1515 std::vector<std::string>& commands )
1517 CommandDictType::const_iterator i;
1518 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1520 if ((i->first).find(buf,0,n) == 0)
1521 commands.push_back(i->first);
1524 //=======================================================================
1528 //=======================================================================
1529 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1531 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1532 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1534 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1535 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1536 // E.G. STORE THIS IN bbtk_config.xml
1537 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1538 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1539 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1540 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1541 #define BBTK_BACKSPACE_KBCODE 0x00000008
1542 #define BBTK_DEL_KBCODE 0x0000007F
1543 #define BBTK_SPACE_KBCODE 0x00000020
1545 //=======================================================================
1546 void Interpreter::GetLineFromPrompt(std::string& s)
1551 int MAX_LINE_SIZE = 160;
1552 int MAX_HISTORY_SIZE = 100;
1554 char* newline = new char[MAX_LINE_SIZE];
1555 memset(newline,0,MAX_LINE_SIZE);
1556 char* histline = new char[MAX_LINE_SIZE];
1557 memset(histline,0,MAX_LINE_SIZE);
1559 char* line = newline;
1560 int hist = mHistory.size();
1566 read ( STDIN_FILENO, &c, 4) ;
1568 bbtkDebugMessage("debug",9,"[0x"<<std::hex<<c<<"]\n");
1570 // Printable character
1571 if ( (ind<MAX_LINE_SIZE-1) &&
1572 ( c >= BBTK_SPACE_KBCODE ) &&
1573 ( c < BBTK_DEL_KBCODE ))
1581 // delete the unused line
1587 // empty lines are not stored in from history
1590 // if history too long : delete oldest command
1591 if (mHistory.size()>MAX_HISTORY_SIZE)
1593 delete mHistory.front();
1594 mHistory.pop_front();
1596 mHistory.push_back(line);
1601 else if ( (ind>0) &&
1602 ((c == BBTK_BACKSPACE_KBCODE) ||
1603 (c == BBTK_DEL_KBCODE)) )
1611 // TODO : Command completion
1612 std::vector<std::string> commands;
1613 FindCommandsWithPrefix( line,ind,commands);
1614 if (commands.size()==1)
1616 std::string com = *commands.begin();
1617 for (; ind<com.size(); ++ind)
1619 PrintChar(com[ind]);
1625 else if (commands.size()>1)
1627 std::vector<std::string>::iterator i;
1629 for (i=commands.begin();i!=commands.end();++i)
1631 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1634 write(STDOUT_FILENO,"\n> ",3);
1635 //for (int j=0;j<ind;++j)
1637 write(STDOUT_FILENO,line,ind);
1641 // Arrow up : back in history
1642 else if (c==BBTK_UP_ARROW_KBCODE)
1646 // erase current line
1647 while (ind--) BackSpace();
1651 strcpy(histline,mHistory[hist]);
1655 write(STDOUT_FILENO,line,ind);
1658 // Arrow down : down in history
1659 else if (c==BBTK_DOWN_ARROW_KBCODE)
1661 if (hist<mHistory.size()-1)
1663 // erase current line
1664 while (ind--) BackSpace();
1668 strcpy(histline,mHistory[hist]);
1672 write(STDOUT_FILENO,line,ind);
1674 // end of history : switch back to newline
1675 else if (hist==mHistory.size()-1)
1677 // erase current line
1678 while (ind--) BackSpace();
1685 write(STDOUT_FILENO,line,ind);
1689 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1691 PrintChar(line[ind]);
1696 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1704 write(STDOUT_FILENO,"\n\r",2);
1712 //=======================================================================
1713 void Interpreter::GetLineFromPrompt(std::string& s)
1739 //=======================================================================
1745 //=======================================================================
1746 void Interpreter::CommandLineInterpreter()
1748 bbtkDebugMessageInc("Interpreter",9,
1749 "Interpreter::CommandLineInterpreter()"<<std::endl);
1751 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1752 // Initialise the tty in non canonical mode with no echo
1753 // oter remembers the previous settings to restore them after
1754 struct termios ter,oter;
1757 ter.c_lflag &= ~ECHO;
1758 ter.c_lflag &= ~ICANON;
1761 tcsetattr(0,TCSANOW,&ter);
1764 mCommandLine = true;
1766 bool insideComment = false; // for multiline comment
1772 GetLineFromPrompt(line);
1773 InterpretLine(line, insideComment);
1775 catch (QuitException e)
1777 bbtkMessage("Interpreter",1,"Interpreter : Quit"<<std::endl);
1780 catch (bbtk::Exception e)
1784 catch (std::exception& e)
1786 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1790 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1795 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1796 tcsetattr(0,TCSANOW,&oter);
1799 std::cout << "Good bye !" << std::endl;
1801 bbtkDebugDecTab("Interpreter",9);
1804 //=======================================================================
1805 void Interpreter::Graph(const std::vector<std::string>& words)
1808 bool system_display = true;
1810 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1811 system_display = false;
1813 if (words.size()==1)
1815 page = mVirtualExecuter->ShowGraph(".","0","0","","","",system_display);
1817 else if (words.size()==2)
1819 page = mVirtualExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1821 else if (words.size()==3)
1823 page = mVirtualExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1825 else if (words.size()==4)
1827 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1829 else if (words.size()==5)
1831 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1833 else if (words.size()==6)
1835 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1837 else if (words.size()==7)
1839 page = mVirtualExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1842 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1843 mUser->InterpreterUserViewHtmlPage(page);
1846 //=======================================================================
1849 //=======================================================================
1850 void Interpreter::Index(const std::string& filename,
1851 const std::string& type)
1853 Factory::IndexEntryType t;
1854 if (type=="Initials") t = Factory::Initials;
1855 else if (type=="Categories") t = Factory::Categories;
1856 else if (type=="Packages") t = Factory::Packages;
1857 else if (type=="Adaptors") t = Factory::Adaptors;
1859 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1861 //=======================================================================
1864 //=======================================================================
1865 void Interpreter::NewGUI(const std::string& boxname,
1866 const std::string& instanceName)
1868 if (mRealExecuter.expired())
1870 bbtkError("command 'newgui' cannot be compiled yet");
1873 std::string typeName = instanceName+"Type";
1874 std::stringstream* s = new std::stringstream;
1875 // create the complex box
1876 (*s) << "define "<<typeName<<std::endl;
1877 // (*s) << " description 'Automatically generated user interface for the box "
1878 // << boxname << "'" <<std::endl;
1879 // create the Layout box
1880 (*s) << " load wx"<<std::endl;
1881 (*s) << " new LayoutLine layout"<<std::endl;
1882 // create the output 'Widget'
1883 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1884 // the box change output
1885 (*s) << " new MultipleInputs change"<<std::endl;
1886 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1888 // Browse the inputs of the box in order to find which ones are not
1889 // connected and can be adapted from a widget adaptor
1890 // vector which stores the list of inputs of the box which must be connected
1891 std::vector<std::string> in;
1893 Factory::Pointer F = mVirtualExecuter->GetFactory();
1895 Package::Pointer user = F->GetPackage("user");
1897 ComplexBlackBoxDescriptor::Pointer workspace =
1898 mRealExecuter.lock()->GetCurrentDescriptor();
1903 bbtkError("Interpreter::CreateGUI : could not access the executer currently defined complex box");
1908 (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get());
1911 BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname);
1912 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
1914 BlackBox::InputConnectorMapType::iterator i;
1915 for (i=box->bbGetInputConnectorMap().begin();
1916 i!=box->bbGetInputConnectorMap().end();
1919 // If the input is connected : continue
1920 if (i->second->IsConnected()) continue;
1921 // Get the input descriptor
1922 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
1923 // If it is a "system" input : skip it
1924 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
1925 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
1928 std::string widget,adaptor;
1929 // try to find a widget adaptor
1930 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
1934 // command to create the adaptor
1935 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1936 // Sets the label of the widget adaptor to the name of the input
1937 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
1938 // Sets the initial value of the widget to the value of the input
1939 (*s) << " set "<<i->first<<".In \" "
1940 <<box->bbGetInputAsString(i->first)<<"\""
1942 // store the input name
1943 in.push_back(i->first);
1944 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
1945 //<i->first<<"'"<<std::endl;
1946 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
1948 // try to find a two pieces adaptor
1949 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
1953 // command to create the widget
1954 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
1955 // command to create the adaptor
1956 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1958 (*s) << " connect "<<i->first<<"Widget.Out "
1959 <<i->first<<".In"<<std::endl;
1960 // Sets the label of the widget adaptor to the name of the input
1961 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
1962 // Sets the initial value of the widget to the value of the input
1963 (*s) << " set "<<i->first<<"Widget.In \" "
1964 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
1965 // store the input name
1966 in.push_back(i->first);
1967 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
1968 //<i->first<<"'"<<std::endl;
1969 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
1972 // try to find an adaptor from string
1973 // If found then can create a text input which
1974 // will be automatically adapted
1975 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
1979 // command to create the adaptor
1980 (*s) << " new InputText "<<i->first<<std::endl;
1981 // Sets the label of the widget adaptor to the name of the input
1982 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
1983 // Sets the initial value of the widget to the value of the input
1984 (*s) << " set "<<i->first<<".In \" "
1985 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
1986 // store the input name
1987 in.push_back(i->first);
1988 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
1989 //<i->first<<"'"<<std::endl;
1990 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
1999 // command to create the output
2000 (*s) << " output "<<i->first<<" "
2001 <<i->first<<".Out "<<i->first<<std::endl;
2002 // <<" Output of the widget which allows to set "
2006 // Inputs for window properties
2007 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
2008 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
2009 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
2010 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
2011 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
2015 // Execute the box executes the layout
2016 (*s) << " exec layout" << std::endl;
2017 (*s) << "endefine" << std::endl;
2018 // (*s) << "help "<< typeName<< std::endl;
2019 // instanciate the box and connect it
2020 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2022 std::vector<std::string>::iterator j;
2023 for (j=in.begin();j!=in.end();++j)
2026 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2027 << boxname<<"."<<*j<<std::endl;
2029 // That's all folks ! now execute the commands :
2032 //=======================================================================
2036 //==========================================================================
2037 void Interpreter::Debug(const std::string& name)
2039 if ((name.length()==2)&&(name[0]=='-'))
2043 bbtk::StaticInitTime::PrintObjectListInfo = true;
2047 // int o = MessageManager::GetMessageLevel("debug");
2048 // if (o<2) MessageManager::SetMessageLevel("debug",2);
2049 mVirtualExecuter->GetFactory()->CheckPackages();
2050 // MessageManager::SetMessageLevel("debug",o);
2055 Object:: PrintObjectListInfo(name);
2058 //==========================================================================
2059 //==========================================================================
2060 std::string Interpreter::GetObjectName() const
2062 return std::string("Interpreter");
2064 //==========================================================================
2066 //==========================================================================
2067 std::string Interpreter::GetObjectInfo() const
2069 std::stringstream i;
2072 //==========================================================================
2074 //==========================================================================
2075 size_t Interpreter::GetObjectSize() const
2077 size_t s = Superclass::GetObjectSize();
2078 s += Interpreter::GetObjectInternalSize();
2081 //==========================================================================
2082 //==========================================================================
2083 size_t Interpreter::GetObjectInternalSize() const
2085 size_t s = sizeof(Interpreter);
2088 //==========================================================================
2089 //==========================================================================
2090 size_t Interpreter::GetObjectRecursiveSize() const
2092 size_t s = Superclass::GetObjectRecursiveSize();
2093 s += Interpreter::GetObjectInternalSize();
2094 s += mVirtualExecuter->GetObjectRecursiveSize();
2097 //==========================================================================