1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.cxx,v $ $
6 Date: $Date: 2008/04/22 06:59:31 $
7 Version: $Revision: 1.61 $
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 'echo' 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 mExecuter = boost::static_pointer_cast<VirtualExec>(bbtk::Transcriptor::New(cpp_file));
69 mExecuter = boost::static_pointer_cast<VirtualExec>(bbtk::Executer::New());
72 // Lock this pointer or will auto-destruct !!
73 mExecuter->SetInterpreter(MakePointer(this,true));
75 // For the time being, comment out previous line, and
76 // uncomment next line to check Transcriptor
78 //mExecuter = new bbtk::Transcriptor("GeneratedProgram.txt");
80 // Builds the commands dict
87 info.syntax = "new <type> <name>";
88 info.help = "Creates a new black box of type <type> with name <name>";
89 mCommandDict[info.keyword] = info;
91 info.keyword = "delete";
95 info.syntax = "delete <box>";
96 info.help = "Deletes the black box of name <box>";
97 mCommandDict[info.keyword] = info;
99 info.keyword = "newgui";
103 info.syntax = "newgui <box> <name>";
104 info.help = "Automatically creates a graphical user interface with name <name> for the black box <box> and connects it to the box inputs";
105 mCommandDict[info.keyword] = info;
107 info.keyword = "connect";
110 info.code = cConnect;
111 info.syntax = "connect <box1.output> <box2.input>";
112 info.help = "Connects the ouput <output> of black box <box1> to the input <input> of black box <box2>";
113 mCommandDict[info.keyword] = info;
115 info.keyword = "print";
119 info.syntax = "print <string>";
120 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').";
121 mCommandDict[info.keyword] = info;
123 info.keyword = "exec";
127 info.syntax = "exec <box | 'freeze' | 'unfreeze' >";
128 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.";
129 mCommandDict[info.keyword] = info;
131 info.keyword = "package";
134 info.code = cPackage;
135 info.syntax = "package <name>";
136 info.help = "Begins the definition of a package.";
137 mCommandDict[info.keyword] = info;
139 info.keyword = "endpackage";
142 info.code = cEndPackage;
143 info.syntax = "endpackage";
144 info.help = "Ends the definition of a package.";
145 mCommandDict[info.keyword] = info;
147 info.keyword = "define";
151 info.syntax = "define <type> [<package>]";
152 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.";
153 mCommandDict[info.keyword] = info;
155 info.keyword = "endefine";
158 info.code = cEndDefine;
159 info.syntax = "endefine";
160 info.help = "Ends the definition of a new type of complex black box";
161 mCommandDict[info.keyword] = info;
163 info.keyword = "kind";
167 info.syntax = "kind <ADAPTOR|DEFAULT_ADAPTOR|WIDGET_ADAPTOR|DEFAULT_WIDGET_ADAPTOR>";
168 info.help = "Sets the kind of the currently defined complex black box";
169 mCommandDict[info.keyword] = info;
171 info.keyword = "input";
175 info.syntax = "input <name> <box.input> <help>";
176 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";
177 mCommandDict[info.keyword] = info;
179 info.keyword = "output";
183 info.syntax = "output <name> <box.output> <help>";
184 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";
185 mCommandDict[info.keyword] = info;
187 info.keyword = "set";
191 info.syntax = "set <box.input> <value>";
192 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";
193 mCommandDict[info.keyword] = info;
195 info.keyword = "config"; // JPR
199 info.syntax = "config";
200 info.help = "Prints the value of all configuration parameters";
201 mCommandDict[info.keyword] = info;
203 info.keyword = "index"; // LG
208 info.syntax = "index [<filename> ['Initials'(default)|'Packages'|'Categories'|'Adaptors']]";
209 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.";
210 mCommandDict[info.keyword] = info;
212 info.keyword = "reset";
216 info.syntax = "reset";
217 info.help = "Deletes all boxes and unloads all packages (bbi is reset to its start state)";
218 mCommandDict[info.keyword] = info;
220 info.keyword = "author";
224 info.syntax = "author <string>";
225 info.help = "Adds the string <string> to the author information of the black box being defined";
226 mCommandDict[info.keyword] = info;
228 info.keyword = "category"; //JP
231 info.code = cCategory;
232 info.syntax = "category <list of items, separated by ;>";
233 info.help = "Adds the string <string> to the category information of the black box being defined";
234 mCommandDict[info.keyword] = info;
236 info.keyword = "description";
239 info.code = cDescription;
240 info.syntax = "description <string>";
241 info.help = "Adds the string <string> to the descriptive information of the black box being defined";
242 mCommandDict[info.keyword] = info;
244 info.keyword = "help";
248 info.syntax = "help";
249 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>";
250 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.";
251 mCommandDict[info.keyword] = info;
253 info.keyword = "message";
256 info.code = cMessage;
257 info.syntax = "message <kind> <level>";
258 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;
260 info.keyword = "include";
263 info.code = cInclude;
264 info.syntax = "include <filename> [source]";
265 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).";
266 mCommandDict[info.keyword] = info;
268 info.keyword = "quit";
272 info.syntax = "quit";
273 info.help = "Quits the program (during script execution it stops the complete execution)";
274 mCommandDict[info.keyword] = info;
276 info.keyword = "load";
280 info.syntax = "load <packagename>";
281 info.help = "Loads the black box package <packagename>";
282 mCommandDict[info.keyword] = info;
284 info.keyword = "unload";
288 info.syntax = "unload <packagename>";
289 info.help = "Unloads the black box package <packagename>";
290 mCommandDict[info.keyword] = info;
292 info.keyword = "graph";
296 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 ]]]]]]";
297 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')";
298 mCommandDict[info.keyword] = info;
300 info.keyword = "object";
304 info.syntax = "object <object name>";
305 info.help = "Provides debug info on object <object name>";
306 mCommandDict[info.keyword] = info;
309 info.keyword = "workspace";
312 info.code = cWorkspace;
313 info.syntax = "workspace < ( freeze | unfreeze ) | ( rename <newname> ) >";
314 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.";
315 mCommandDict[info.keyword] = info;
318 bbtkDebugDecTab("Interpreter",9);
321 //=======================================================================
325 //=======================================================================
329 Interpreter::~Interpreter()
331 bbtkDebugMessageInc("Interpreter",9,"==> Interpreter::~Interpreter()" <<std::endl);
332 mExecuter = VirtualExec::Pointer();
333 bbtkDebugMessageInc("Interpreter",9,"<== Interpreter::~Interpreter()" <<std::endl);
335 //=======================================================================
338 InterpreterError::InterpreterError( const std::string& message,
340 const std::string& script_file,
343 : Exception("Interpreter",0,message),
344 mInScriptFile(in_script_file),
345 mScriptFile(script_file),
346 mScriptLine(script_line)
349 InterpreterError::InterpreterError( const Exception& excep,
351 const std::string& script_file,
355 mInScriptFile(in_script_file),
356 mScriptFile(script_file),
357 mScriptLine(script_line)
360 //=======================================================================
361 void Interpreter::CatchBbtkException( const bbtk::Exception& e )
365 bool in_script = false;
366 std::string file("");
368 if (mFileName.size()) {
369 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
370 if (fs!=0) in_script = true;
371 file = mFileName.back();
375 throw InterpreterError(e,in_script,file,line);
379 std::stringstream mess;
380 mess << "* ERROR : "<<e.GetMessage()<<std::endl;
381 if (mFileName.size()) {
382 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
383 mess << "* LINE : "<<mLine.back()<<std::endl;
385 std::cerr << mess.str();
388 //=======================================================================
390 //=======================================================================
391 void Interpreter::CatchStdException( const std::exception& e )
395 bool in_script = false;
396 std::string file("");
398 if (mFileName.size()) {
399 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
400 if (fs!=0) in_script = true;
401 file = mFileName.back();
405 throw InterpreterError(e.what(),in_script,file,line);
409 std::stringstream mess;
410 mess << "* ERROR : "<<e.what()<<std::endl;
411 if (mFileName.size()) {
412 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
413 mess << "* LINE : "<<mLine.back()<<std::endl;
415 std::cerr << mess.str();
418 //=======================================================================
420 //=======================================================================
421 void Interpreter::CatchUnknownException()
425 bool in_script = false;
426 std::string file("");
428 if (mFileName.size()) {
429 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
430 if (fs!=0) in_script = true;
431 file = mFileName.back();
435 throw InterpreterError("Unknown exception caught",
436 in_script,file,line);
440 std::stringstream mess;
441 mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
443 if (mFileName.size()) {
444 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
445 mess << "* LINE : "<<mLine.back()<<std::endl;
447 std::cerr << mess.str();
450 //=======================================================================
452 //=======================================================================
454 #define CATCH_MACRO \
455 catch (QuitException e) \
457 status = Interpreter_QUIT; \
458 if (mThrow) throw QuitException(); \
460 catch (bbtk::Exception e) \
462 status = Interpreter_ERROR; \
463 CatchBbtkException(e); \
465 catch (std::exception& e) \
467 status = Interpreter_ERROR; \
468 CatchStdException(e); \
472 status = Interpreter_ERROR; \
473 CatchUnknownException(); \
475 //=======================================================================
478 //=======================================================================
482 Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename )
484 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
486 bool exm = mCommandLine;
487 mCommandLine = false;
489 ExitStatus status = Interpreter_OK;
493 SwitchToFile(filename);
495 bool insideComment = false; // for multiline comment
496 while (mFile.size()>0)
498 while (!mFile.back()->eof()) {
501 mFile.back()->getline(buf,500);
502 std::string str(buf);
503 int size=str.length();
504 if ( str[ size-1 ]==13 )
509 InterpretLine(str, insideComment);
518 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
519 bbtkDecTab("Interpreter",9);
525 //=======================================================================
528 //=======================================================================
532 Interpreter::ExitStatus
533 Interpreter::InterpretBuffer( std::stringstream* buffer )
535 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretBuffer()"<<std::endl);
537 bool exm = mCommandLine;
538 mCommandLine = false;
540 ExitStatus status = Interpreter_OK;
544 SwitchToStream(buffer);
545 bool insideComment = false; // for multiline comment
546 while (mFile.size()>0)
548 while (!mFile.back()->eof()) {
551 mFile.back()->getline(buf,500);
552 std::string str(buf);
554 int size=str.length();
555 if ( str[ size-1 ]==13 )
560 InterpretLine(str, insideComment);
570 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
571 bbtkDecTab("Interpreter",9);
576 //=======================================================================
578 //=======================================================================
579 /// Runs the interpretation of a command
580 Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
582 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
584 ExitStatus status = Interpreter_OK;
588 bool insideComment = false;
589 InterpretLine(line, insideComment);
593 catch (QuitException e)
595 status = Interpreter_QUIT;
597 catch (bbtk::Exception e)
599 std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
600 status = Interpreter_ERROR;
602 catch (std::exception& e)
604 std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
605 status = Interpreter_ERROR;
610 << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
611 status = Interpreter_ERROR;
615 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretLine()"
617 bbtkDecTab("Interpreter",9);
623 //=======================================================================
627 void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
629 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine(\""<<line<<"\")"<<std::endl);
630 bbtkMessage("Echo",2,line<<std::endl);
632 std::vector<std::string> words;
633 SplitLine(line,words);
638 bbtkDebugDecTab("Interpreter",9);
642 // Single line comment : # or //
643 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
645 bbtkDebugDecTab("Interpreter",9);
646 bbtkMessage("Interpreter",9,"Comment"<<std::endl);
650 // Multi line comment ( /* ... */ ) -delimiters on different lines !-
652 if (words[0][0]=='/' && words[0][1]=='*')
654 bbtkDebugDecTab("Interpreter",9);
655 bbtkMessage("Interpreter",9,"In multiline comment"<<std::endl);
656 insideComment = true;
660 if (words[0][0]=='*' && words[0][1]=='/')
662 bbtkDebugDecTab("Interpreter",9);
663 bbtkMessage("Interpreter",9,"Out multiline comment"<<std::endl);
664 if ( !insideComment ) {
665 bbtkDebugDecTab("Interpreter",9);
666 bbtkMessage("Interpreter",9,"Comment mismatch : '*/' with no matching '/*'"<<std::endl);
668 insideComment = false;
674 bbtkDebugDecTab("Interpreter",9);
675 bbtkMessage("Interpreter",9,"Multiline Comment"<<std::endl);
680 CommandInfoType command;
681 InterpretCommand(words,command);
683 bbtkDebugMessage("Interpreter",9,
684 "Command='"<<command.keyword
685 <<"' code="<<command.code<<std::endl);
687 std::string left,right,left2,right2;
688 std::string filename;
689 switch (command.code)
692 mExecuter->Create(words[1],words[2]);
696 mExecuter->Destroy(words[1]);
700 Utilities::SplitAroundFirstDot(words[1],left,right);
701 Utilities::SplitAroundFirstDot(words[2],left2,right2);
702 mExecuter->Connect(left,right,left2,right2);
706 mExecuter->BeginPackage(words[1]);
710 mExecuter->EndPackage();
714 if (mFileName.size()>0)
716 filename = mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
720 mExecuter->Define(words[1],"",filename);
724 mExecuter->Define(words[1],words[2],filename);
729 mExecuter->EndDefine();
733 mExecuter->Kind(words[1]);
737 mExecuter->Print(words[1]);
741 if (words[1]=="freeze")
742 mExecuter->SetNoExecMode(true);
743 else if (words[1]=="unfreeze")
744 mExecuter->SetNoExecMode(false);
746 mExecuter->Execute(words[1]);
750 Utilities::SplitAroundFirstDot(words[2],left,right);
751 mExecuter->DefineInput(words[1],left,right,words[3]);
755 Utilities::SplitAroundFirstDot(words[2],left,right);
756 mExecuter->DefineOutput(words[1],left,right,words[3]);
760 Utilities::SplitAroundFirstDot(words[1],left,right);
761 mExecuter->Set(left,right,words[2]);
765 mExecuter->Author(words[1]);
769 NewGUI(words[1],words[2]);
773 mExecuter->Category(words[1]);
778 Index("tmp_index.html");
779 else if (words.size()==2)
781 else if (words.size()==3)
782 Index(words[1],words[2]);
786 mExecuter->Description(words[1]);
796 mExecuter->HelpMessages();
800 sscanf(words[2].c_str(),"%d",&level);
801 mExecuter->SetMessageLevel(words[1],level);
814 this->mExecuter->Reset();
815 mFileNameHistory.clear();
821 InterpretFile(words[1]);
825 SwitchToFile(words[1]);
827 // if 'source' was given
830 GetExecuter()->SetCurrentFileName(words[1]);
835 GetExecuter()->LoadPackage(words[1]);
839 GetExecuter()->UnLoadPackage(words[1]);
843 throw QuitException();
847 if (words.size()==2) ObjectInfo(words[1]);
852 if (words.size() == 2)
854 if (words[1]=="freeze") mExecuter->SetNoExecMode(true);
855 else if (words[1]=="unfreeze") mExecuter->SetNoExecMode(false);
859 mExecuter->SetWorkspaceName(words[2]);
864 bbtkInternalError("should not reach here !!!");
867 bbtkDecTab("Interpreter",9);
869 //=======================================================================
875 //=======================================================================
879 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
881 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
883 std::string delimiters = "\"";
884 std::vector<std::string> quote;
885 Utilities::SplitString(str,delimiters,quote);
888 std::vector<std::string>::iterator i;
889 for (i=quote.begin(); i!=quote.end(); )
891 Utilities::SplitString(*i,delimiters,tokens);
895 // bbtkDebugMessage("Interpreter",0,"\""<<*i<<"\""<<std::endl);
896 tokens.push_back(*i);
901 for (i=tokens.begin(); i!=tokens.end(); ++i)
903 bbtkDebugMessage("Interpreter",9,"["<<*i<<"] ");
905 bbtkDebugMessageCont("Interpreter",9,std::endl);
907 bbtkDebugDecTab("Interpreter",9);
909 //=======================================================================
914 //=======================================================================
919 void Interpreter::Print( const std::string& str)
921 if (mExecuter->GetNoExecMode()) return;
923 bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
926 // InterpretLine ("load std")
927 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
928 // InterpretLine("new Print _P_")
929 // InterpretLine("connect _C_.Out _P_.In")
933 std::vector<std::string> chains;
934 std::string delimiters("$");
936 // Skip delimiters at beginning.
937 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
939 if (lastPos>0) is_text = false;
941 // Find first delimiter.
942 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
944 while (std::string::npos != pos || std::string::npos != lastPos)
948 // Found a text token, add it to the vector.
949 chains.push_back(str.substr(lastPos, pos - lastPos));
950 // std::string token = str.substr(lastPos, pos - lastPos)
951 // InterpretLine("set _C_.In%num% %token%")
957 // is an output (between $$) : decode
958 std::string tok,box,output;
959 tok = str.substr(lastPos, pos - lastPos);
960 Utilities::SplitAroundFirstDot(tok,box,output);
961 chains.push_back( mExecuter->Get(box,output) );
963 // InterpretLine("connect %tok% _C_.In%num%")
966 // Skip delimiters. Note the "not_of"
967 lastPos = str.find_first_not_of(delimiters, pos);
968 // Find next delimiter
969 pos = str.find_first_of(delimiters, lastPos);
974 // InterpretLine("exec _P_")
975 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
977 std::vector<std::string>::iterator i;
978 for (i= chains.begin(); i!=chains.end(); ++i)
980 // bbtkMessage("Echo",1,*i);
981 Utilities::SubsBackslashN(*i);
984 std::cout << std::endl;
985 bbtkDebugDecTab("Interpreter",9);
989 //=======================================================================
994 // ===================================================================================
996 void Interpreter::SwitchToFile( const std::string& name )
998 // Note : in the following :
999 // name : the user supplied name
1000 // - abreviated name e.g. scr scr.bbs
1001 // - relative full name e.g. ./scr.bbs ../../scr.bbs
1002 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
1003 // same for Windows, with c:, d: ...
1005 // use ./directory/subdir/scrname.bbs
1008 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SwitchToFile( \""
1009 <<name<<"\")"<<std::endl);
1011 std::vector<std::string> script_paths;
1012 std::string fullPathScriptName; // full path script name
1013 std::string pkgname; // e.g. <scriptname>.bbs
1014 std::vector<std::string> Filenames;
1016 // The following is *NOT* a debug time message :
1017 // It's a user intended message.
1018 // Please don't remove it.
1019 bbtkMessage("Interpreter",1,
1020 "look for : [" << name
1021 << "]" << std::endl);
1025 pkgname = Utilities::ExtractScriptName(name,upath);
1027 bbtkMessage("Interpreter",3,
1028 "extract : pkgname [" << pkgname
1029 << "] upath [" << upath << "]" << std::endl);
1030 bool fullnameGiven = false;
1031 bool foundFile = false;
1033 // ==== "*" provided : load all scripts in given path
1034 // relative (e.g. std/boxes/*) or absolute
1039 std::stringstream* stream = new std::stringstream;
1040 //if (upath.size()!=0) // avoid troubles for "*"
1042 // ==== no path provided : look in root bbs path
1043 if (upath.size()==0)
1045 // bbtkMessage("Interpreter",1,
1046 script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1048 // ==== absolute path provided
1049 else if (upath[0]=='/' || upath[1] == ':' )
1051 if ( Utilities::IsDirectory( upath ) )
1053 script_paths.push_back(upath);
1057 bbtkError("'"<<upath<<"' : directory does not exist");
1060 // ==== relative path provided : search all bbs path appended with
1061 // the relative path provided
1064 std::vector<std::string>::const_iterator i;
1065 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1066 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1069 std::string full_path(*i);
1070 // we *really* want '.' to be the current working directory
1071 if (full_path == ".") {
1072 char buf[2048]; // for getcwd
1073 char * currentDir = getcwd(buf, 2048);
1074 std::string cwd(currentDir);
1075 full_path = currentDir;
1078 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1081 if ( Utilities::IsDirectory( full_path ) )
1083 script_paths.push_back(full_path);
1086 if (script_paths.empty())
1088 bbtkError("no '"<<upath<<"' subdir found in search paths"
1093 // === search paths list complete : now explore it
1096 std::vector<std::string>::iterator i;
1097 for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
1099 bbtkMessage("Interpreter",1,
1100 "--> Looking in '" << *i << "'" << std::endl);
1104 int nbFiles = Utilities::Explore(*i, false, Filenames);
1107 for (std::vector<std::string>::iterator j = Filenames.begin();
1108 j!= Filenames.end(); ++j)
1110 int lgr = (*j).size();
1112 continue; // ignore non .bbs file
1113 if ((*j).substr(lgr-4, 4) != ".bbs")
1116 (*stream) << "include \"" << *j << "\"\n";
1117 bbtkMessage("Interpreter",2,
1118 " --> Found '" << *j << "'" << std::endl);
1125 bbtkMessage("Interpreter",1,
1126 " --> No .bbs found"<< std::endl);
1130 bbtkMessage("Interpreter",1,
1131 " --> "<<nbBssFiles<<" .bbs found"<< std::endl);
1132 SwitchToStream(stream);
1135 //break; // a directory was found; we stop iterating
1136 // LG : No! We want all files included !
1140 //=============== end pkgname=="*" ===========
1143 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1144 // (not only a plain script name)
1145 // we trust him, and try to expland the directory name
1146 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1148 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1151 // ===========================================================check user supplied location
1152 fullnameGiven = true;
1154 fullPathScriptName = Utilities::ExpandLibName(name, false);
1156 // allow user to always forget ".bbs"
1157 int l = fullPathScriptName.size();
1163 if (fullPathScriptName.substr(l-4, 4) != ".bbs")
1165 fullPathScriptName = fullPathScriptName + ".bbs";
1170 fullPathScriptName = fullPathScriptName + ".bbs";
1173 if ( Utilities::FileExists(fullPathScriptName))
1180 // =============================== iterate on the paths
1182 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1184 std::vector<std::string>::iterator i;
1185 for (i=script_paths.begin();i!=script_paths.end();++i)
1188 // we *really* want '.' to be the current working directory
1190 char buf[2048]; // for getcwd
1191 char * currentDir = getcwd(buf, 2048);
1192 std::string cwd(currentDir);
1196 fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
1198 // Check if library exists
1199 if ( ! Utilities::FileExists(fullPathScriptName) )
1201 // The following is *NOT* a debug time message :
1202 // It's a user intended message.
1203 // Please don't remove it.
1204 bbtkMessage("Interpreter",2,
1205 " [" <<fullPathScriptName <<"] : doesn't exist"
1207 continue; // try next path
1209 bbtkMessage("Interpreter",2,
1210 " [" <<fullPathScriptName
1211 <<"] : found" <<std::endl);
1213 break; // a script was found; we stop iterating
1215 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1221 if(fullPathScriptName == "")
1222 bbtkError("Path ["<<upath<<"] doesn't exist");
1224 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1226 bbtkError("No ["<<pkgname<<".bbs] script found");
1230 LoadScript(fullPathScriptName,name);
1234 //=======================================================================
1237 //=======================================================================
1238 void Interpreter::SwitchToStream( std::stringstream* stream )
1240 mFile.push_back(stream);
1241 std::ostringstream buffer_name;
1243 buffer_name << "buffer_" ;
1245 if (mFileName.size()>0 )
1247 buffer_name << mFileName.back() << "_" << mLine.back();
1249 mFileName.push_back(buffer_name.str());
1250 mIncludeFileName.push_back(buffer_name.str());
1253 //=======================================================================
1255 //=======================================================================
1257 void Interpreter::LoadScript( std::string fullPathScriptName,
1258 std::string includeScriptName)
1260 Utilities::replace( fullPathScriptName ,
1261 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1263 if (find(mFileNameHistory.begin(),
1264 mFileNameHistory.end(),
1265 fullPathScriptName)!=mFileNameHistory.end())
1271 s = new std::ifstream;
1272 s->open(fullPathScriptName.c_str());
1275 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1279 bbtkMessage("Interpreter",1," -->[" << fullPathScriptName
1280 << "] found" << std::endl);
1283 mFileName.push_back(fullPathScriptName);
1284 mFileNameHistory.push_back(fullPathScriptName);
1285 mIncludeFileName.push_back(includeScriptName);
1291 //=======================================================================
1295 void Interpreter::CloseCurrentFile()
1297 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseCurrentFile()"
1300 if (mFile.size()==0)
1302 bbtkDebugMessage("Interpreter",9," -> no file left open"<<std::endl);
1306 bbtkDebugMessage("Interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1308 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1309 if (file!=0) file->close();
1311 delete mFile.back();
1313 mFileName.pop_back();
1314 mIncludeFileName.pop_back();
1317 bbtkDebugMessage("Interpreter",9," Remains "
1319 <<" open"<<std::endl);
1320 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseCurrentFile()"
1323 //=======================================================================
1325 //=======================================================================
1329 void Interpreter::CloseAllFiles()
1331 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseAllFiles()"
1334 while (mFile.size() != 0)
1338 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()"
1341 //=======================================================================
1345 //=======================================================================
1349 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1350 CommandInfoType& info )
1352 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretCommand(...)"<<std::endl);
1354 // searches the command keyword
1355 CommandDictType::iterator c;
1356 c = mCommandDict.find(words[0]);
1357 if ( c == mCommandDict.end() ) {
1358 bbtkError(words[0]<<" : unknown command");
1361 // tests the number of args
1362 if ( ( words.size()-1 < c->second.argmin ) ||
1363 ( words.size()-1 > c->second.argmax ) )
1365 HelpCommand(words[0]);
1366 bbtkError(words[0]<<" : wrong number of arguments");
1370 bbtkDecTab("Interpreter",9);
1372 //=======================================================================
1375 //=======================================================================
1376 /// Displays help on all the commands
1377 void Interpreter::Help(const std::vector<std::string>& words)
1379 unsigned int nbarg = words.size()-1;
1387 if (words[1]=="packages")
1389 GetExecuter()->GetFactory()->PrintPackages(true);
1394 HelpCommand(words[1]);
1396 catch (bbtk::Exception e)
1400 GetExecuter()->GetFactory()->HelpPackage(words[1]);
1404 ConfigurationFile::GetInstance().Get_doc_path();
1405 url += "/bbdoc/" + words[1] + "/index.html";
1406 if (Utilities::FileExists(url))
1408 mUser->InterpreterUserViewHtmlPage(url);
1412 catch (bbtk::Exception f)
1416 std::string package;
1417 GetExecuter()->GetFactory()->HelpBlackBox(words[1],package);
1421 ConfigurationFile::GetInstance().Get_doc_path();
1422 url += "/bbdoc/" + package + "/index.html";
1423 if (Utilities::FileExists(url))
1425 url += "#" + words[1];
1426 mUser->InterpreterUserViewHtmlPage(url);
1430 catch (bbtk::Exception g)
1434 GetExecuter()->ShowRelations(words[1],"0","9999");
1436 catch (bbtk::Exception h){
1437 bbtkError("\""<<words[1].c_str()
1438 <<"\" is not a known command, package, black box type or black box name");
1446 if (words[2]=="all")
1448 if ( words[1]=="packages" )
1450 GetExecuter()->GetFactory()->PrintPackages(true,true);
1455 GetExecuter()->GetFactory()->HelpPackage(words[1],true);
1457 catch (bbtk::Exception f)
1463 HelpCommand(words[0]);
1464 bbtkError(words[0]<<" : syntax error");
1469 bbtkError("Should not reach here !!!");
1472 //=======================================================================
1474 //===================================================================
1475 /// Displays the Configuration
1476 void Interpreter::Config() const
1478 ConfigurationFile::GetInstance().GetHelp(1);
1480 //===================================================================
1482 //=======================================================================
1483 /// Displays help on all the commands
1484 void Interpreter::HelpCommands()
1486 std::cout << "Available commands :" << std::endl;
1487 CommandDictType::iterator i;
1488 for ( i = mCommandDict.begin();
1489 i != mCommandDict.end();
1491 std::cout << " " << i->first << std::endl;
1492 // std::cout << " usage : " << i->second.syntax << std::endl;
1493 // std::cout << " " << i->second.help << std::endl;
1497 //=======================================================================
1500 //=======================================================================
1501 /// Displays help on a particular commands
1502 void Interpreter::HelpCommand(const std::string& s)
1504 CommandDictType::iterator c;
1505 c = mCommandDict.find(s);
1506 if ( c == mCommandDict.end() ) {
1507 bbtkError(s<<" : Unknown command");
1509 // std::cout << " " << s << " : "<< std::endl;
1510 // CommandParamDictType::iterator i;
1511 // for ( i = c->second.begin();
1512 // i != c->second.end();
1514 std::cout << " usage : " << c->second.syntax << std::endl;
1515 std::cout << " " << c->second.help << std::endl;
1518 //=======================================================================
1521 //=======================================================================
1522 /// Fills the vector commands with the commands which
1523 /// have the first n chars of buf for prefix
1524 /// TODO : skip initial spaces in buf and also return the position of first
1525 /// non blank char in buf
1526 void Interpreter::FindCommandsWithPrefix( char* buf,
1528 std::vector<std::string>& commands )
1530 CommandDictType::const_iterator i;
1531 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1533 if ((i->first).find(buf,0,n) == 0)
1534 commands.push_back(i->first);
1537 //=======================================================================
1541 //=======================================================================
1542 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1544 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1545 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1547 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1548 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1549 // E.G. STORE THIS IN bbtk_config.xml
1550 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1551 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1552 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1553 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1554 #define BBTK_BACKSPACE_KBCODE 0x00000008
1555 #define BBTK_DEL_KBCODE 0x0000007F
1556 #define BBTK_SPACE_KBCODE 0x00000020
1558 //=======================================================================
1559 void Interpreter::GetLineFromPrompt(std::string& s)
1564 int MAX_LINE_SIZE = 160;
1565 int MAX_HISTORY_SIZE = 100;
1567 char* newline = new char[MAX_LINE_SIZE];
1568 memset(newline,0,MAX_LINE_SIZE);
1569 char* histline = new char[MAX_LINE_SIZE];
1570 memset(histline,0,MAX_LINE_SIZE);
1572 char* line = newline;
1573 int hist = mHistory.size();
1579 read ( STDIN_FILENO, &c, 4) ;
1581 bbtkDebugMessage("Debug",9,"[0x"<<std::hex<<c<<"]\n");
1583 // Printable character
1584 if ( (ind<MAX_LINE_SIZE-1) &&
1585 ( c >= BBTK_SPACE_KBCODE ) &&
1586 ( c < BBTK_DEL_KBCODE ))
1594 // delete the unused line
1600 // empty lines are not stored in from history
1603 // if history too long : delete oldest command
1604 if (mHistory.size()>MAX_HISTORY_SIZE)
1606 delete mHistory.front();
1607 mHistory.pop_front();
1609 mHistory.push_back(line);
1614 else if ( (ind>0) &&
1615 ((c == BBTK_BACKSPACE_KBCODE) ||
1616 (c == BBTK_DEL_KBCODE)) )
1624 // TODO : Command completion
1625 std::vector<std::string> commands;
1626 FindCommandsWithPrefix( line,ind,commands);
1627 if (commands.size()==1)
1629 std::string com = *commands.begin();
1630 for (; ind<com.size(); ++ind)
1632 PrintChar(com[ind]);
1638 else if (commands.size()>1)
1640 std::vector<std::string>::iterator i;
1642 for (i=commands.begin();i!=commands.end();++i)
1644 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1647 write(STDOUT_FILENO,"\n> ",3);
1648 //for (int j=0;j<ind;++j)
1650 write(STDOUT_FILENO,line,ind);
1654 // Arrow up : back in history
1655 else if (c==BBTK_UP_ARROW_KBCODE)
1659 // erase current line
1660 while (ind--) BackSpace();
1664 strcpy(histline,mHistory[hist]);
1668 write(STDOUT_FILENO,line,ind);
1671 // Arrow down : down in history
1672 else if (c==BBTK_DOWN_ARROW_KBCODE)
1674 if (hist<mHistory.size()-1)
1676 // erase current line
1677 while (ind--) BackSpace();
1681 strcpy(histline,mHistory[hist]);
1685 write(STDOUT_FILENO,line,ind);
1687 // end of history : switch back to newline
1688 else if (hist==mHistory.size()-1)
1690 // erase current line
1691 while (ind--) BackSpace();
1698 write(STDOUT_FILENO,line,ind);
1702 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1704 PrintChar(line[ind]);
1709 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1717 write(STDOUT_FILENO,"\n\r",2);
1725 //=======================================================================
1726 void Interpreter::GetLineFromPrompt(std::string& s)
1752 //=======================================================================
1758 //=======================================================================
1759 void Interpreter::CommandLineInterpreter()
1761 bbtkDebugMessageInc("Interpreter",9,
1762 "Interpreter::CommandLineInterpreter()"<<std::endl);
1764 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1765 // Initialise the tty in non canonical mode with no echo
1766 // oter remembers the previous settings to restore them after
1767 struct termios ter,oter;
1770 ter.c_lflag &= ~ECHO;
1771 ter.c_lflag &= ~ICANON;
1774 tcsetattr(0,TCSANOW,&ter);
1777 mCommandLine = true;
1779 bool insideComment = false; // for multiline comment
1785 GetLineFromPrompt(line);
1786 InterpretLine(line, insideComment);
1788 catch (QuitException e)
1790 bbtkMessage("Interpreter",1,"Interpreter : Quit"<<std::endl);
1793 catch (bbtk::Exception e)
1797 catch (std::exception& e)
1799 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1803 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1808 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1809 tcsetattr(0,TCSANOW,&oter);
1812 std::cout << "Good bye !" << std::endl;
1814 bbtkDebugDecTab("Interpreter",9);
1817 //=======================================================================
1818 void Interpreter::Graph(const std::vector<std::string>& words)
1821 bool system_display = true;
1823 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1824 system_display = false;
1826 if (words.size()==1)
1828 page = mExecuter->ShowGraph(".","0","0","","","",system_display);
1830 else if (words.size()==2)
1832 page = mExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1834 else if (words.size()==3)
1836 page = mExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1838 else if (words.size()==4)
1840 page = mExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1842 else if (words.size()==5)
1844 page = mExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1846 else if (words.size()==6)
1848 page = mExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1850 else if (words.size()==7)
1852 page = mExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1855 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1856 mUser->InterpreterUserViewHtmlPage(page);
1859 //=======================================================================
1862 //=======================================================================
1863 void Interpreter::Index(const std::string& filename,
1864 const std::string& type)
1866 Factory::IndexEntryType t;
1867 if (type=="Initials") t = Factory::Initials;
1868 else if (type=="Categories") t = Factory::Categories;
1869 else if (type=="Packages") t = Factory::Packages;
1870 else if (type=="Adaptors") t = Factory::Adaptors;
1872 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1874 //=======================================================================
1877 //=======================================================================
1878 void Interpreter::NewGUI(const std::string& boxname,
1879 const std::string& instanceName)
1881 std::string typeName = instanceName+"Type";
1882 std::stringstream* s = new std::stringstream;
1883 // create the complex box
1884 (*s) << "define "<<typeName<<std::endl;
1885 // (*s) << " description 'Automatically generated user interface for the box "
1886 // << boxname << "'" <<std::endl;
1887 // create the Layout box
1888 (*s) << " load wx"<<std::endl;
1889 (*s) << " new LayoutLine layout"<<std::endl;
1890 // create the output 'Widget'
1891 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1892 // the box change output
1893 (*s) << " new MultipleInputs change"<<std::endl;
1894 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1896 // Browse the inputs of the box in order to find which ones are not
1897 // connected and can be adapted from a widget adaptor
1898 // vector which stores the list of inputs of the box which must be connected
1899 std::vector<std::string> in;
1901 Factory::Pointer F = mExecuter->GetFactory();
1903 Package::Pointer user = F->GetPackage("user");
1905 ComplexBlackBoxDescriptor::Pointer workspace = mExecuter->GetWorkspace();
1910 bbtkError("Interpreter::CreateGUI : could not access the executer workspace");
1915 (ComplexBlackBoxDescriptor::Pointer)(user->GetBlackBoxMap().find("workspace")->second.get());
1918 BlackBox::Pointer box = workspace->GetPrototype()->bbGetBlackBox(boxname);
1919 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
1921 BlackBox::InputConnectorMapType::iterator i;
1922 for (i=box->bbGetInputConnectorMap().begin();
1923 i!=box->bbGetInputConnectorMap().end();
1926 // If the input is connected : continue
1927 if (i->second->IsConnected()) continue;
1928 // Get the input descriptor
1929 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
1930 // If it is a "system" input : skip it
1931 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
1932 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
1935 std::string widget,adaptor;
1936 // try to find a widget adaptor
1937 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
1941 // command to create the adaptor
1942 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1943 // Sets the label of the widget adaptor to the name of the input
1944 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
1945 // Sets the initial value of the widget to the value of the input
1946 (*s) << " set "<<i->first<<".In \" "
1947 <<box->bbGetInputAsString(i->first)<<"\""
1949 // store the input name
1950 in.push_back(i->first);
1951 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
1952 //<i->first<<"'"<<std::endl;
1953 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
1955 // try to find a two pieces adaptor
1956 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
1960 // command to create the widget
1961 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
1962 // command to create the adaptor
1963 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1965 (*s) << " connect "<<i->first<<"Widget.Out "
1966 <<i->first<<".In"<<std::endl;
1967 // Sets the label of the widget adaptor to the name of the input
1968 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
1969 // Sets the initial value of the widget to the value of the input
1970 (*s) << " set "<<i->first<<"Widget.In \" "
1971 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
1972 // store the input name
1973 in.push_back(i->first);
1974 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
1975 //<i->first<<"'"<<std::endl;
1976 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
1979 // try to find an adaptor from string
1980 // If found then can create a text input which
1981 // will be automatically adapted
1982 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
1986 // command to create the adaptor
1987 (*s) << " new InputText "<<i->first<<std::endl;
1988 // Sets the label of the widget adaptor to the name of the input
1989 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
1990 // Sets the initial value of the widget to the value of the input
1991 (*s) << " set "<<i->first<<".In \" "
1992 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
1993 // store the input name
1994 in.push_back(i->first);
1995 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
1996 //<i->first<<"'"<<std::endl;
1997 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
2006 // command to create the output
2007 (*s) << " output "<<i->first<<" "
2008 <<i->first<<".Out "<<i->first<<std::endl;
2009 // <<" Output of the widget which allows to set "
2013 // Inputs for window properties
2014 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
2015 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
2016 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
2017 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
2018 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
2022 // Execute the box executes the layout
2023 (*s) << " exec layout" << std::endl;
2024 (*s) << "endefine" << std::endl;
2025 // (*s) << "help "<< typeName<< std::endl;
2026 // instanciate the box and connect it
2027 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2029 std::vector<std::string>::iterator j;
2030 for (j=in.begin();j!=in.end();++j)
2033 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2034 << boxname<<"."<<*j<<std::endl;
2036 // That's all folks ! now execute the commands :
2039 //=======================================================================
2043 //==========================================================================
2044 void Interpreter::ObjectInfo(const std::string& name)
2046 Object:: PrintObjectInfo(name);
2048 //==========================================================================
2049 //==========================================================================
2050 std::string Interpreter::GetObjectName() const
2052 return std::string("Interpreter");
2054 //==========================================================================
2056 //==========================================================================
2057 std::string Interpreter::GetObjectInfo() const
2059 std::stringstream i;
2062 //==========================================================================
2064 //==========================================================================
2065 size_t Interpreter::GetObjectSize() const
2067 size_t s = Superclass::GetObjectSize();
2068 s += Interpreter::GetObjectInternalSize();
2071 //==========================================================================
2072 //==========================================================================
2073 size_t Interpreter::GetObjectInternalSize() const
2075 size_t s = sizeof(Interpreter);
2078 //==========================================================================
2079 //==========================================================================
2080 size_t Interpreter::GetObjectRecursiveSize() const
2082 size_t s = Superclass::GetObjectRecursiveSize();
2083 s += Interpreter::GetObjectInternalSize();
2084 s += mExecuter->GetObjectRecursiveSize();
2087 //==========================================================================