1 /*=========================================================================
4 Module: $RCSfile: bbtkInterpreter.cxx,v $ $
6 Date: $Date: 2008/04/09 11:16:57 $
7 Version: $Revision: 1.59 $
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 //Interpreter* Interpreter::mGlobalInterpreter = NULL;
44 //=======================================================================
48 Interpreter::Interpreter(const std::string& cpp_file)
55 bbtk::MessageManager::RegisterMessageType("Echo","Level>0 : Prints the 'echo' commands of the user.\n\tLevel>1 : Prints the command being interpreted",1);
56 bbtk::MessageManager::RegisterMessageType("Interpreter","Messages of the interpreter",0);
57 bbtkDebugMessageInc("Interpreter",9,"Interpreter::Interpreter()" <<std::endl);
59 if (cpp_file.size()!=0)
61 mExecuter = new bbtk::Transcriptor(cpp_file);
65 mExecuter = new bbtk::Executer();
67 mExecuter->SetInterpreter(this);
69 // For the time being, comment out previous line, and
70 // uncomment next line to check Transcriptor
72 //mExecuter = new bbtk::Transcriptor("GeneratedProgram.txt");
74 // Builds the commands dict
81 info.syntax = "new <type> <name>";
82 info.help = "Creates a new black box of type <type> with name <name>";
83 mCommandDict[info.keyword] = info;
85 info.keyword = "delete";
89 info.syntax = "delete <box>";
90 info.help = "Deletes the black box of name <box>";
91 mCommandDict[info.keyword] = info;
93 info.keyword = "newgui";
97 info.syntax = "newgui <box> <name>";
98 info.help = "Automatically creates a graphical user interface with name <name> for the black box <box> and connects it to the box inputs";
99 mCommandDict[info.keyword] = info;
101 info.keyword = "connect";
104 info.code = cConnect;
105 info.syntax = "connect <box1.output> <box2.input>";
106 info.help = "Connects the ouput <output> of black box <box1> to the input <input> of black box <box2>";
107 mCommandDict[info.keyword] = info;
109 info.keyword = "print";
113 info.syntax = "print <string>";
114 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').";
115 mCommandDict[info.keyword] = info;
117 info.keyword = "exec";
121 info.syntax = "exec <box | 'freeze' | 'unfreeze' >";
122 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.";
123 mCommandDict[info.keyword] = info;
125 info.keyword = "package";
128 info.code = cPackage;
129 info.syntax = "package <name>";
130 info.help = "Begins the definition of a package.";
131 mCommandDict[info.keyword] = info;
133 info.keyword = "endpackage";
136 info.code = cEndPackage;
137 info.syntax = "endpackage";
138 info.help = "Ends the definition of a package.";
139 mCommandDict[info.keyword] = info;
141 info.keyword = "define";
145 info.syntax = "define <type> [<package>]";
146 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.";
147 mCommandDict[info.keyword] = info;
149 info.keyword = "endefine";
152 info.code = cEndDefine;
153 info.syntax = "endefine";
154 info.help = "Ends the definition of a new type of complex black box";
155 mCommandDict[info.keyword] = info;
157 info.keyword = "kind";
161 info.syntax = "kind <ADAPTOR|DEFAULT_ADAPTOR|WIDGET_ADAPTOR|DEFAULT_WIDGET_ADAPTOR>";
162 info.help = "Sets the kind of the currently defined complex black box";
163 mCommandDict[info.keyword] = info;
165 info.keyword = "input";
169 info.syntax = "input <name> <box.input> <help>";
170 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";
171 mCommandDict[info.keyword] = info;
173 info.keyword = "output";
177 info.syntax = "output <name> <box.output> <help>";
178 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";
179 mCommandDict[info.keyword] = info;
181 info.keyword = "set";
185 info.syntax = "set <box.input> <value>";
186 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";
187 mCommandDict[info.keyword] = info;
189 info.keyword = "config"; // JPR
193 info.syntax = "config";
194 info.help = "Prints the value of all configuration parameters";
195 mCommandDict[info.keyword] = info;
197 info.keyword = "index"; // LG
202 info.syntax = "index [<filename> ['Initials'(default)|'Packages'|'Categories'|'Adaptors']]";
203 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.";
204 mCommandDict[info.keyword] = info;
206 info.keyword = "reset";
210 info.syntax = "reset";
211 info.help = "Deletes all boxes and unloads all packages (bbi is reset to its start state)";
212 mCommandDict[info.keyword] = info;
214 info.keyword = "author";
218 info.syntax = "author <string>";
219 info.help = "Adds the string <string> to the author information of the black box being defined";
220 mCommandDict[info.keyword] = info;
222 info.keyword = "category"; //JP
225 info.code = cCategory;
226 info.syntax = "category <list of items, separated by ;>";
227 info.help = "Adds the string <string> to the category information of the black box being defined";
228 mCommandDict[info.keyword] = info;
230 info.keyword = "description";
233 info.code = cDescription;
234 info.syntax = "description <string>";
235 info.help = "Adds the string <string> to the descriptive information of the black box being defined";
236 mCommandDict[info.keyword] = info;
238 info.keyword = "help";
242 info.syntax = "help";
243 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>";
244 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.";
245 mCommandDict[info.keyword] = info;
247 info.keyword = "message";
250 info.code = cMessage;
251 info.syntax = "message <kind> <level>";
252 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;
254 info.keyword = "include";
257 info.code = cInclude;
258 info.syntax = "include <filename> [source]";
259 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).";
260 mCommandDict[info.keyword] = info;
262 info.keyword = "quit";
266 info.syntax = "quit";
267 info.help = "Quits the program (during script execution it stops the complete execution)";
268 mCommandDict[info.keyword] = info;
270 info.keyword = "load";
274 info.syntax = "load <packagename>";
275 info.help = "Loads the black box package <packagename>";
276 mCommandDict[info.keyword] = info;
278 info.keyword = "unload";
282 info.syntax = "unload <packagename>";
283 info.help = "Unloads the black box package <packagename>";
284 mCommandDict[info.keyword] = info;
286 info.keyword = "graph";
290 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 ]]]]]]";
291 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')";
292 mCommandDict[info.keyword] = info;
295 info.keyword = "workspace";
298 info.code = cWorkspace;
299 info.syntax = "workspace < ( freeze | unfreeze ) | ( rename <newname> ) >";
300 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.";
301 mCommandDict[info.keyword] = info;
304 bbtkDebugDecTab("Interpreter",9);
307 //=======================================================================
311 //=======================================================================
315 Interpreter::~Interpreter()
317 bbtkDebugMessageInc("Interpreter",9,"Interpreter::~Interpreter()" <<std::endl);
320 bbtkDebugDecTab("Interpreter",9);
322 //=======================================================================
325 InterpreterError::InterpreterError( const std::string& message,
327 const std::string& script_file,
330 : Exception("Interpreter",0,message),
331 mInScriptFile(in_script_file),
332 mScriptFile(script_file),
333 mScriptLine(script_line)
336 InterpreterError::InterpreterError( const Exception& excep,
338 const std::string& script_file,
342 mInScriptFile(in_script_file),
343 mScriptFile(script_file),
344 mScriptLine(script_line)
347 //=======================================================================
348 void Interpreter::CatchBbtkException( const bbtk::Exception& e )
352 bool in_script = false;
353 std::string file("");
355 if (mFileName.size()) {
356 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
357 if (fs!=0) in_script = true;
358 file = mFileName.back();
362 throw InterpreterError(e,in_script,file,line);
366 std::stringstream mess;
367 mess << "* ERROR : "<<e.GetMessage()<<std::endl;
368 if (mFileName.size()) {
369 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
370 mess << "* LINE : "<<mLine.back()<<std::endl;
372 std::cerr << mess.str();
375 //=======================================================================
377 //=======================================================================
378 void Interpreter::CatchStdException( const std::exception& e )
382 bool in_script = false;
383 std::string file("");
385 if (mFileName.size()) {
386 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
387 if (fs!=0) in_script = true;
388 file = mFileName.back();
392 throw InterpreterError(e.what(),in_script,file,line);
396 std::stringstream mess;
397 mess << "* ERROR : "<<e.what()<<std::endl;
398 if (mFileName.size()) {
399 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
400 mess << "* LINE : "<<mLine.back()<<std::endl;
402 std::cerr << mess.str();
405 //=======================================================================
407 //=======================================================================
408 void Interpreter::CatchUnknownException()
412 bool in_script = false;
413 std::string file("");
415 if (mFileName.size()) {
416 std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
417 if (fs!=0) in_script = true;
418 file = mFileName.back();
422 throw InterpreterError("Unknown exception caught",
423 in_script,file,line);
427 std::stringstream mess;
428 mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
430 if (mFileName.size()) {
431 mess << "* FILE : \""<<mFileName.back()<<"\""<<std::endl;
432 mess << "* LINE : "<<mLine.back()<<std::endl;
434 std::cerr << mess.str();
437 //=======================================================================
439 //=======================================================================
441 #define CATCH_MACRO \
442 catch (QuitException e) \
444 status = Interpreter_QUIT; \
445 if (mThrow) throw QuitException(); \
447 catch (bbtk::Exception e) \
449 status = Interpreter_ERROR; \
450 CatchBbtkException(e); \
452 catch (std::exception& e) \
454 status = Interpreter_ERROR; \
455 CatchStdException(e); \
459 status = Interpreter_ERROR; \
460 CatchUnknownException(); \
462 //=======================================================================
465 //=======================================================================
469 Interpreter::ExitStatus Interpreter::InterpretFile( const std::string& filename )
471 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
473 bool exm = mCommandLine;
474 mCommandLine = false;
476 ExitStatus status = Interpreter_OK;
480 SwitchToFile(filename);
482 bool insideComment = false; // for multiline comment
483 while (mFile.size()>0)
485 while (!mFile.back()->eof()) {
488 mFile.back()->getline(buf,500);
489 std::string str(buf);
490 int size=str.length();
491 if ( str[ size-1 ]==13 )
496 InterpretLine(str, insideComment);
505 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
506 bbtkDecTab("Interpreter",9);
512 //=======================================================================
515 //=======================================================================
519 Interpreter::ExitStatus
520 Interpreter::InterpretBuffer( std::stringstream* buffer )
522 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretBuffer()"<<std::endl);
524 bool exm = mCommandLine;
525 mCommandLine = false;
527 ExitStatus status = Interpreter_OK;
531 SwitchToStream(buffer);
532 bool insideComment = false; // for multiline comment
533 while (mFile.size()>0)
535 while (!mFile.back()->eof()) {
538 mFile.back()->getline(buf,500);
539 std::string str(buf);
541 int size=str.length();
542 if ( str[ size-1 ]==13 )
547 InterpretLine(str, insideComment);
557 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
558 bbtkDecTab("Interpreter",9);
563 //=======================================================================
565 //=======================================================================
566 /// Runs the interpretation of a command
567 Interpreter::ExitStatus Interpreter::InterpretLine( const std::string& line )
569 printf("EED Interpreter::InterpretLine %s \n", line.c_str() );
570 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine('"<<line<<"')"<<std::endl);
572 ExitStatus status = Interpreter_OK;
576 bool insideComment = false;
577 InterpretLine(line, insideComment);
581 catch (QuitException e)
583 status = Interpreter_QUIT;
585 catch (bbtk::Exception e)
587 std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
588 status = Interpreter_ERROR;
590 catch (std::exception& e)
592 std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
593 status = Interpreter_ERROR;
598 << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
599 status = Interpreter_ERROR;
603 bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretLine()"
605 bbtkDecTab("Interpreter",9);
611 //=======================================================================
615 void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
617 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretLine(\""<<line<<"\")"<<std::endl);
618 bbtkMessage("Echo",2,line<<std::endl);
620 std::vector<std::string> words;
621 SplitLine(line,words);
626 bbtkDebugDecTab("Interpreter",9);
630 // Single line comment : # or //
631 if ( words[0][0]=='#' || (words[0][0]=='/' && words[0][1]=='/') )
633 bbtkDebugDecTab("Interpreter",9);
634 bbtkMessage("Interpreter",9,"Comment"<<std::endl);
638 // Multi line comment ( /* ... */ ) -delimiters on different lines !-
640 if (words[0][0]=='/' && words[0][1]=='*')
642 bbtkDebugDecTab("Interpreter",9);
643 bbtkMessage("Interpreter",9,"In multiline comment"<<std::endl);
644 insideComment = true;
648 if (words[0][0]=='*' && words[0][1]=='/')
650 bbtkDebugDecTab("Interpreter",9);
651 bbtkMessage("Interpreter",9,"Out multiline comment"<<std::endl);
652 if ( !insideComment ) {
653 bbtkDebugDecTab("Interpreter",9);
654 bbtkMessage("Interpreter",9,"Comment mismatch : '*/' with no matching '/*'"<<std::endl);
656 insideComment = false;
662 bbtkDebugDecTab("Interpreter",9);
663 bbtkMessage("Interpreter",9,"Multiline Comment"<<std::endl);
668 CommandInfoType command;
669 InterpretCommand(words,command);
671 bbtkDebugMessage("Interpreter",9,
672 "Command='"<<command.keyword
673 <<"' code="<<command.code<<std::endl);
675 std::string left,right,left2,right2;
676 std::string filename;
677 switch (command.code)
680 mExecuter->Create(words[1],words[2]);
684 mExecuter->Destroy(words[1]);
688 Utilities::SplitAroundFirstDot(words[1],left,right);
689 Utilities::SplitAroundFirstDot(words[2],left2,right2);
690 mExecuter->Connect(left,right,left2,right2);
694 mExecuter->BeginPackage(words[1]);
698 mExecuter->EndPackage();
702 if (mFileName.size()>0)
704 filename = mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
708 mExecuter->Define(words[1],"",filename);
712 mExecuter->Define(words[1],words[2],filename);
717 mExecuter->EndDefine();
721 mExecuter->Kind(words[1]);
725 mExecuter->Print(words[1]);
729 if (words[1]=="freeze")
730 mExecuter->SetNoExecMode(true);
731 else if (words[1]=="unfreeze")
732 mExecuter->SetNoExecMode(false);
734 mExecuter->Execute(words[1]);
738 Utilities::SplitAroundFirstDot(words[2],left,right);
739 mExecuter->DefineInput(words[1],left,right,words[3]);
743 Utilities::SplitAroundFirstDot(words[2],left,right);
744 mExecuter->DefineOutput(words[1],left,right,words[3]);
748 Utilities::SplitAroundFirstDot(words[1],left,right);
749 mExecuter->Set(left,right,words[2]);
753 mExecuter->Author(words[1]);
757 NewGUI(words[1],words[2]);
761 mExecuter->Category(words[1]);
766 Index("tmp_index.html");
767 else if (words.size()==2)
769 else if (words.size()==3)
770 Index(words[1],words[2]);
774 mExecuter->Description(words[1]);
784 mExecuter->HelpMessages();
788 sscanf(words[2].c_str(),"%d",&level);
789 mExecuter->SetMessageLevel(words[1],level);
802 this->mExecuter->Reset();
803 mFileNameHistory.clear();
809 InterpretFile(words[1]);
813 SwitchToFile(words[1]);
815 // if 'source' was given
818 GetExecuter()->SetCurrentFileName(words[1]);
823 GetExecuter()->LoadPackage(words[1]);
827 GetExecuter()->UnLoadPackage(words[1]);
832 throw QuitException();
836 if (words.size() == 2)
838 if (words[1]=="freeze") mExecuter->SetNoExecMode(true);
839 else if (words[1]=="unfreeze") mExecuter->SetNoExecMode(false);
843 mExecuter->SetWorkspaceName(words[2]);
848 bbtkInternalError("should not reach here !!!");
851 bbtkDecTab("Interpreter",9);
853 //=======================================================================
859 //=======================================================================
863 void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>& tokens)
865 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SplitLine(\""<<str<<"\")"<<std::endl);
867 std::string delimiters = "\"";
868 std::vector<std::string> quote;
869 Utilities::SplitString(str,delimiters,quote);
872 std::vector<std::string>::iterator i;
873 for (i=quote.begin(); i!=quote.end(); )
875 Utilities::SplitString(*i,delimiters,tokens);
879 // bbtkDebugMessage("Interpreter",0,"\""<<*i<<"\""<<std::endl);
880 tokens.push_back(*i);
885 for (i=tokens.begin(); i!=tokens.end(); ++i)
887 bbtkDebugMessage("Interpreter",9,"["<<*i<<"] ");
889 bbtkDebugMessageCont("Interpreter",9,std::endl);
891 bbtkDebugDecTab("Interpreter",9);
893 //=======================================================================
898 //=======================================================================
903 void Interpreter::Print( const std::string& str)
905 if (mExecuter->GetNoExecMode()) return;
907 bbtkDebugMessageInc("Interpreter",9,"Interpreter::Print(\""<<str<<"\")"<<std::endl);
910 // InterpretLine ("load std")
911 // InterpretLine("new ConcatStrings _C_ ") -> trouver un nom unique : # commande
912 // InterpretLine("new Print _P_")
913 // InterpretLine("connect _C_.Out _P_.In")
917 std::vector<std::string> chains;
918 std::string delimiters("$");
920 // Skip delimiters at beginning.
921 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
923 if (lastPos>0) is_text = false;
925 // Find first delimiter.
926 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
928 while (std::string::npos != pos || std::string::npos != lastPos)
932 // Found a text token, add it to the vector.
933 chains.push_back(str.substr(lastPos, pos - lastPos));
934 // std::string token = str.substr(lastPos, pos - lastPos)
935 // InterpretLine("set _C_.In%num% %token%")
941 // is an output (between $$) : decode
942 std::string tok,box,output;
943 tok = str.substr(lastPos, pos - lastPos);
944 Utilities::SplitAroundFirstDot(tok,box,output);
945 chains.push_back( mExecuter->Get(box,output) );
947 // InterpretLine("connect %tok% _C_.In%num%")
950 // Skip delimiters. Note the "not_of"
951 lastPos = str.find_first_not_of(delimiters, pos);
952 // Find next delimiter
953 pos = str.find_first_of(delimiters, lastPos);
958 // InterpretLine("exec _P_")
959 // if (IS_IN_WORKSPACE) InterpretLine("delete _C_; delete _P_");
961 std::vector<std::string>::iterator i;
962 for (i= chains.begin(); i!=chains.end(); ++i)
964 // bbtkMessage("Echo",1,*i);
965 Utilities::SubsBackslashN(*i);
968 std::cout << std::endl;
969 bbtkDebugDecTab("Interpreter",9);
973 //=======================================================================
978 // ===================================================================================
980 void Interpreter::SwitchToFile( const std::string& name )
982 // Note : in the following :
983 // name : the user supplied name
984 // - abreviated name e.g. scr scr.bbs
985 // - relative full name e.g. ./scr.bbs ../../scr.bbs
986 // - absolute full name e.g. /home/usrname/proj/dir/scr.bbs
987 // same for Windows, with c:, d: ...
989 // use ./directory/subdir/scrname.bbs
992 bbtkDebugMessageInc("Interpreter",9,"Interpreter::SwitchToFile( \""
993 <<name<<"\")"<<std::endl);
995 std::vector<std::string> script_paths;
996 std::string fullPathScriptName; // full path script name
997 std::string pkgname; // e.g. <scriptname>.bbs
998 std::vector<std::string> Filenames;
1000 // The following is *NOT* a debug time message :
1001 // It's a user intended message.
1002 // Please don't remove it.
1003 bbtkMessage("Interpreter",1,
1004 "look for : [" << name
1005 << "]" << std::endl);
1009 pkgname = Utilities::ExtractScriptName(name,upath);
1011 bbtkMessage("Interpreter",3,
1012 "extract : pkgname [" << pkgname
1013 << "] upath [" << upath << "]" << std::endl);
1014 bool fullnameGiven = false;
1015 bool foundFile = false;
1017 // ==== "*" provided : load all scripts in given path
1018 // relative (e.g. std/boxes/*) or absolute
1023 std::stringstream* stream = new std::stringstream;
1024 //if (upath.size()!=0) // avoid troubles for "*"
1026 // ==== no path provided : look in root bbs path
1027 if (upath.size()==0)
1029 // bbtkMessage("Interpreter",1,
1030 script_paths.push_back( ConfigurationFile::GetInstance().Get_root_bbs_path() );
1032 // ==== absolute path provided
1033 else if (upath[0]=='/' || upath[1] == ':' )
1035 if ( Utilities::IsDirectory( upath ) )
1037 script_paths.push_back(upath);
1041 bbtkError("'"<<upath<<"' : directory does not exist");
1044 // ==== relative path provided : search all bbs path appended with
1045 // the relative path provided
1048 std::vector<std::string>::const_iterator i;
1049 for (i=ConfigurationFile::GetInstance().Get_bbs_paths().begin();
1050 i!=ConfigurationFile::GetInstance().Get_bbs_paths().end();
1053 std::string full_path(*i);
1054 // we *really* want '.' to be the current working directory
1055 if (full_path == ".") {
1056 char buf[2048]; // for getcwd
1057 char * currentDir = getcwd(buf, 2048);
1058 std::string cwd(currentDir);
1059 full_path = currentDir;
1062 full_path += ConfigurationFile::GetInstance().Get_file_separator();
1065 if ( Utilities::IsDirectory( full_path ) )
1067 script_paths.push_back(full_path);
1070 if (script_paths.empty())
1072 bbtkError("no '"<<upath<<"' subdir found in search paths"
1077 // === search paths list complete : now explore it
1080 std::vector<std::string>::iterator i;
1081 for (i=script_paths.begin();i!=script_paths.end();i++)// ==== relative name, iterate + load all .bbs files
1083 bbtkMessage("Interpreter",1,
1084 "--> Looking in '" << *i << "'" << std::endl);
1088 int nbFiles = Utilities::Explore(*i, false, Filenames);
1091 for (std::vector<std::string>::iterator j = Filenames.begin();
1092 j!= Filenames.end(); ++j)
1094 int lgr = (*j).size();
1096 continue; // ignore non .bbs file
1097 if ((*j).substr(lgr-4, 4) != ".bbs")
1100 (*stream) << "include \"" << *j << "\"\n";
1101 bbtkMessage("Interpreter",2,
1102 " --> Found '" << *j << "'" << std::endl);
1109 bbtkMessage("Interpreter",1,
1110 " --> No .bbs found"<< std::endl);
1114 bbtkMessage("Interpreter",1,
1115 " --> "<<nbBssFiles<<" .bbs found"<< std::endl);
1116 SwitchToStream(stream);
1119 //break; // a directory was found; we stop iterating
1120 // LG : No! We want all files included !
1124 //=============== end pkgname=="*" ===========
1127 // if name starts with a / or a . or contains : user is assumed to have passed a relative/absolute name
1128 // (not only a plain script name)
1129 // we trust him, and try to expland the directory name
1130 // WARNING : starting from current local directory : ./whatYouWant (./ mandatory!)
1132 if (name[0]=='/' || name[1] == ':' || name[0]=='.') // absolute path (linux/windows) or relative path
1135 // ===========================================================check user supplied location
1136 fullnameGiven = true;
1138 fullPathScriptName = Utilities::ExpandLibName(name, false);
1140 // allow user to always forget ".bbs"
1141 int l = fullPathScriptName.size();
1147 if (fullPathScriptName.substr(l-4, 4) != ".bbs")
1149 fullPathScriptName = fullPathScriptName + ".bbs";
1154 fullPathScriptName = fullPathScriptName + ".bbs";
1157 if ( Utilities::FileExists(fullPathScriptName))
1164 // =============================== iterate on the paths
1166 script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
1168 std::vector<std::string>::iterator i;
1169 for (i=script_paths.begin();i!=script_paths.end();++i)
1172 // we *really* want '.' to be the current working directory
1174 char buf[2048]; // for getcwd
1175 char * currentDir = getcwd(buf, 2048);
1176 std::string cwd(currentDir);
1180 fullPathScriptName = Utilities::MakePkgnameFromPath(path, name, true);
1182 // Check if library exists
1183 if ( ! Utilities::FileExists(fullPathScriptName) )
1185 // The following is *NOT* a debug time message :
1186 // It's a user intended message.
1187 // Please don't remove it.
1188 bbtkMessage("Interpreter",2,
1189 " [" <<fullPathScriptName <<"] : doesn't exist"
1191 continue; // try next path
1193 bbtkMessage("Interpreter",2,
1194 " [" <<fullPathScriptName
1195 <<"] : found" <<std::endl);
1197 break; // a script was found; we stop iterating
1199 } //------------------ // end for ( package_paths.begin();i!=package_paths.end() )
1205 if(fullPathScriptName == "")
1206 bbtkError("Path ["<<upath<<"] doesn't exist");
1208 bbtkError("Script ["<<fullPathScriptName<<"] not found");
1210 bbtkError("No ["<<pkgname<<".bbs] script found");
1214 LoadScript(fullPathScriptName,name);
1218 //=======================================================================
1221 //=======================================================================
1222 void Interpreter::SwitchToStream( std::stringstream* stream )
1224 mFile.push_back(stream);
1225 std::ostringstream buffer_name;
1227 buffer_name << "buffer_" ;
1229 if (mFileName.size()>0 )
1231 buffer_name << mFileName.back() << "_" << mLine.back();
1233 mFileName.push_back(buffer_name.str());
1234 mIncludeFileName.push_back(buffer_name.str());
1237 //=======================================================================
1239 //=======================================================================
1241 void Interpreter::LoadScript( std::string fullPathScriptName,
1242 std::string includeScriptName)
1244 Utilities::replace( fullPathScriptName ,
1245 INVALID_FILE_SEPARATOR , VALID_FILE_SEPARATOR);
1247 if (find(mFileNameHistory.begin(),
1248 mFileNameHistory.end(),
1249 fullPathScriptName)!=mFileNameHistory.end())
1255 s = new std::ifstream;
1256 s->open(fullPathScriptName.c_str());
1259 bbtkError("Could not open file ["<<fullPathScriptName<<"]");
1263 bbtkMessage("Interpreter",1," -->[" << fullPathScriptName
1264 << "] found" << std::endl);
1267 mFileName.push_back(fullPathScriptName);
1268 mFileNameHistory.push_back(fullPathScriptName);
1269 mIncludeFileName.push_back(includeScriptName);
1275 //=======================================================================
1279 void Interpreter::CloseCurrentFile()
1281 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseCurrentFile()"
1284 if (mFile.size()==0)
1286 bbtkDebugMessage("Interpreter",9," -> no file left open"<<std::endl);
1290 bbtkDebugMessage("Interpreter",9," Closing file '"<<mFileName.back()<<"'"<<std::endl);
1292 std::ifstream* file = dynamic_cast<std::ifstream*>(mFile.back());
1293 if (file!=0) file->close();
1295 delete mFile.back();
1297 mFileName.pop_back();
1298 mIncludeFileName.pop_back();
1301 bbtkDebugMessage("Interpreter",9," Remains "
1303 <<" open"<<std::endl);
1304 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseCurrentFile()"
1307 //=======================================================================
1309 //=======================================================================
1313 void Interpreter::CloseAllFiles()
1315 bbtkDebugMessage("Interpreter",9,"Interpreter::CloseAllFiles()"
1318 while (mFile.size() != 0)
1322 bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()"
1325 //=======================================================================
1329 //=======================================================================
1333 void Interpreter::InterpretCommand( const std::vector<std::string>& words,
1334 CommandInfoType& info )
1336 bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretCommand(...)"<<std::endl);
1338 // searches the command keyword
1339 CommandDictType::iterator c;
1340 c = mCommandDict.find(words[0]);
1341 if ( c == mCommandDict.end() ) {
1342 bbtkError(words[0]<<" : unknown command");
1345 // tests the number of args
1346 if ( ( words.size()-1 < c->second.argmin ) ||
1347 ( words.size()-1 > c->second.argmax ) )
1349 HelpCommand(words[0]);
1350 bbtkError(words[0]<<" : wrong number of arguments");
1354 bbtkDecTab("Interpreter",9);
1356 //=======================================================================
1359 //=======================================================================
1360 /// Displays help on all the commands
1361 void Interpreter::Help(const std::vector<std::string>& words)
1363 unsigned int nbarg = words.size()-1;
1371 if (words[1]=="packages")
1373 GetExecuter()->GetFactory()->PrintPackages(true);
1378 HelpCommand(words[1]);
1380 catch (bbtk::Exception e)
1384 GetExecuter()->GetFactory()->HelpPackage(words[1]);
1388 ConfigurationFile::GetInstance().Get_doc_path();
1389 url += "/bbdoc/" + words[1] + "/index.html";
1390 if (Utilities::FileExists(url))
1392 mUser->InterpreterUserViewHtmlPage(url);
1396 catch (bbtk::Exception f)
1400 std::string package;
1401 GetExecuter()->GetFactory()->HelpBlackBox(words[1],package);
1405 ConfigurationFile::GetInstance().Get_doc_path();
1406 url += "/bbdoc/" + package + "/index.html";
1407 if (Utilities::FileExists(url))
1409 url += "#" + words[1];
1410 mUser->InterpreterUserViewHtmlPage(url);
1414 catch (bbtk::Exception g)
1418 GetExecuter()->ShowRelations(words[1],"0","9999");
1420 catch (bbtk::Exception h){
1421 bbtkError("\""<<words[1].c_str()
1422 <<"\" is not a known command, package, black box type or black box name");
1430 if (words[2]=="all")
1432 if ( words[1]=="packages" )
1434 GetExecuter()->GetFactory()->PrintPackages(true,true);
1439 GetExecuter()->GetFactory()->HelpPackage(words[1],true);
1441 catch (bbtk::Exception f)
1447 HelpCommand(words[0]);
1448 bbtkError(words[0]<<" : syntax error");
1453 bbtkError("Should not reach here !!!");
1456 //=======================================================================
1458 //===================================================================
1459 /// Displays the Configuration
1460 void Interpreter::Config() const
1462 ConfigurationFile::GetInstance().GetHelp(1);
1464 //===================================================================
1466 //=======================================================================
1467 /// Displays help on all the commands
1468 void Interpreter::HelpCommands()
1470 std::cout << "Available commands :" << std::endl;
1471 CommandDictType::iterator i;
1472 for ( i = mCommandDict.begin();
1473 i != mCommandDict.end();
1475 std::cout << " " << i->first << std::endl;
1476 // std::cout << " usage : " << i->second.syntax << std::endl;
1477 // std::cout << " " << i->second.help << std::endl;
1481 //=======================================================================
1484 //=======================================================================
1485 /// Displays help on a particular commands
1486 void Interpreter::HelpCommand(const std::string& s)
1488 CommandDictType::iterator c;
1489 c = mCommandDict.find(s);
1490 if ( c == mCommandDict.end() ) {
1491 bbtkError(s<<" : Unknown command");
1493 // std::cout << " " << s << " : "<< std::endl;
1494 // CommandParamDictType::iterator i;
1495 // for ( i = c->second.begin();
1496 // i != c->second.end();
1498 std::cout << " usage : " << c->second.syntax << std::endl;
1499 std::cout << " " << c->second.help << std::endl;
1502 //=======================================================================
1505 //=======================================================================
1506 /// Fills the vector commands with the commands which
1507 /// have the first n chars of buf for prefix
1508 /// TODO : skip initial spaces in buf and also return the position of first
1509 /// non blank char in buf
1510 void Interpreter::FindCommandsWithPrefix( char* buf,
1512 std::vector<std::string>& commands )
1514 CommandDictType::const_iterator i;
1515 for (i=mCommandDict.begin(); i!=mCommandDict.end(); ++i)
1517 if ((i->first).find(buf,0,n) == 0)
1518 commands.push_back(i->first);
1521 //=======================================================================
1525 //=======================================================================
1526 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1528 inline void PrintChar(char c) { write(STDOUT_FILENO,&c,1); }
1529 inline void BackSpace() { write(STDOUT_FILENO,"\b \b",3); }
1531 // LG : KEYBOARD CODES AS SCANNED ON MY TTY : UNIVERSAL ?
1532 // IF NOT THE USER SHOULD BE ABLE TO CONFIGURE IT
1533 // E.G. STORE THIS IN bbtk_config.xml
1534 #define BBTK_UP_ARROW_KBCODE 0x00415B1B
1535 #define BBTK_DOWN_ARROW_KBCODE 0x00425B1B
1536 #define BBTK_RIGHT_ARROW_KBCODE 0x00435B1B
1537 #define BBTK_LEFT_ARROW_KBCODE 0x00445B1B
1538 #define BBTK_BACKSPACE_KBCODE 0x00000008
1539 #define BBTK_DEL_KBCODE 0x0000007F
1540 #define BBTK_SPACE_KBCODE 0x00000020
1542 //=======================================================================
1543 void Interpreter::GetLineFromPrompt(std::string& s)
1548 int MAX_LINE_SIZE = 160;
1549 int MAX_HISTORY_SIZE = 100;
1551 char* newline = new char[MAX_LINE_SIZE];
1552 memset(newline,0,MAX_LINE_SIZE);
1553 char* histline = new char[MAX_LINE_SIZE];
1554 memset(histline,0,MAX_LINE_SIZE);
1556 char* line = newline;
1557 int hist = mHistory.size();
1563 read ( STDIN_FILENO, &c, 4) ;
1565 bbtkDebugMessage("Debug",9,"[0x"<<std::hex<<c<<"]\n");
1567 // Printable character
1568 if ( (ind<MAX_LINE_SIZE-1) &&
1569 ( c >= BBTK_SPACE_KBCODE ) &&
1570 ( c < BBTK_DEL_KBCODE ))
1578 // delete the unused line
1584 // empty lines are not stored in from history
1587 // if history too long : delete oldest command
1588 if (mHistory.size()>MAX_HISTORY_SIZE)
1590 delete mHistory.front();
1591 mHistory.pop_front();
1593 mHistory.push_back(line);
1598 else if ( (ind>0) &&
1599 ((c == BBTK_BACKSPACE_KBCODE) ||
1600 (c == BBTK_DEL_KBCODE)) )
1608 // TODO : Command completion
1609 std::vector<std::string> commands;
1610 FindCommandsWithPrefix( line,ind,commands);
1611 if (commands.size()==1)
1613 std::string com = *commands.begin();
1614 for (; ind<com.size(); ++ind)
1616 PrintChar(com[ind]);
1622 else if (commands.size()>1)
1624 std::vector<std::string>::iterator i;
1626 for (i=commands.begin();i!=commands.end();++i)
1628 write(STDOUT_FILENO,(*i).c_str(),strlen((*i).c_str()));
1631 write(STDOUT_FILENO,"\n> ",3);
1632 //for (int j=0;j<ind;++j)
1634 write(STDOUT_FILENO,line,ind);
1638 // Arrow up : back in history
1639 else if (c==BBTK_UP_ARROW_KBCODE)
1643 // erase current line
1644 while (ind--) BackSpace();
1648 strcpy(histline,mHistory[hist]);
1652 write(STDOUT_FILENO,line,ind);
1655 // Arrow down : down in history
1656 else if (c==BBTK_DOWN_ARROW_KBCODE)
1658 if (hist<mHistory.size()-1)
1660 // erase current line
1661 while (ind--) BackSpace();
1665 strcpy(histline,mHistory[hist]);
1669 write(STDOUT_FILENO,line,ind);
1671 // end of history : switch back to newline
1672 else if (hist==mHistory.size()-1)
1674 // erase current line
1675 while (ind--) BackSpace();
1682 write(STDOUT_FILENO,line,ind);
1686 else if (line[ind]!=0 && c==BBTK_RIGHT_ARROW_KBCODE)
1688 PrintChar(line[ind]);
1693 else if (ind>0 && c==BBTK_LEFT_ARROW_KBCODE)
1701 write(STDOUT_FILENO,"\n\r",2);
1709 //=======================================================================
1710 void Interpreter::GetLineFromPrompt(std::string& s)
1736 //=======================================================================
1742 //=======================================================================
1743 void Interpreter::CommandLineInterpreter()
1745 bbtkDebugMessageInc("Interpreter",9,
1746 "Interpreter::CommandLineInterpreter()"<<std::endl);
1748 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1749 // Initialise the tty in non canonical mode with no echo
1750 // oter remembers the previous settings to restore them after
1751 struct termios ter,oter;
1754 ter.c_lflag &= ~ECHO;
1755 ter.c_lflag &= ~ICANON;
1758 tcsetattr(0,TCSANOW,&ter);
1761 mCommandLine = true;
1763 bool insideComment = false; // for multiline comment
1769 GetLineFromPrompt(line);
1770 InterpretLine(line, insideComment);
1772 catch (QuitException e)
1774 bbtkMessage("Interpreter",1,"Interpreter : Quit"<<std::endl);
1777 catch (bbtk::Exception e)
1781 catch (std::exception& e)
1783 std::cerr << "* ERROR :: "<<e.what()<<" (not in bbtk)"<<std::endl;
1787 std::cerr << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
1792 #ifdef BBTK_USE_TERMIOS_BASED_PROMPT
1793 tcsetattr(0,TCSANOW,&oter);
1796 std::cout << "Good bye !" << std::endl;
1798 bbtkDebugDecTab("Interpreter",9);
1801 //=======================================================================
1802 void Interpreter::Graph(const std::vector<std::string>& words)
1805 bool system_display = true;
1807 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1808 system_display = false;
1810 if (words.size()==1)
1812 page = mExecuter->ShowGraph(".","0","0","","","",system_display);
1814 else if (words.size()==2)
1816 page = mExecuter->ShowGraph(words[1],"0","0","","","",system_display);
1818 else if (words.size()==3)
1820 page = mExecuter->ShowGraph(words[1],words[2],"0","","","",system_display);
1822 else if (words.size()==4)
1824 page = mExecuter->ShowGraph(words[1],words[2],words[3],"","","",system_display);
1826 else if (words.size()==5)
1828 page = mExecuter->ShowGraph(words[1],words[2],words[3],words[4],"","",system_display);
1830 else if (words.size()==6)
1832 page = mExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],"",system_display);
1834 else if (words.size()==7)
1836 page = mExecuter->ShowGraph(words[1],words[2],words[3],words[4],words[5],words[6],system_display);
1839 if ( ( mUser != 0 ) && ( mUser->InterpreterUserHasOwnHtmlPageViewer() ) )
1840 mUser->InterpreterUserViewHtmlPage(page);
1843 //=======================================================================
1846 //=======================================================================
1847 void Interpreter::Index(const std::string& filename,
1848 const std::string& type)
1850 Factory::IndexEntryType t;
1851 if (type=="Initials") t = Factory::Initials;
1852 else if (type=="Categories") t = Factory::Categories;
1853 else if (type=="Packages") t = Factory::Packages;
1854 else if (type=="Adaptors") t = Factory::Adaptors;
1856 GetExecuter()->GetFactory()->CreateHtmlIndex(t,filename);
1858 //=======================================================================
1861 //=======================================================================
1862 void Interpreter::NewGUI(const std::string& boxname,
1863 const std::string& instanceName)
1865 std::string typeName = instanceName+"Type";
1866 std::stringstream* s = new std::stringstream;
1867 // create the complex box
1868 (*s) << "define "<<typeName<<std::endl;
1869 // (*s) << " description 'Automatically generated user interface for the box "
1870 // << boxname << "'" <<std::endl;
1871 // create the Layout box
1872 (*s) << " load wx"<<std::endl;
1873 (*s) << " new LayoutLine layout"<<std::endl;
1874 // create the output 'Widget'
1875 (*s) << " output Widget layout.Widget Widget"<<std::endl;
1876 // the box change output
1877 (*s) << " new MultipleInputs change"<<std::endl;
1878 (*s) << " output BoxChange change.Out BoxChange"<<std::endl;
1880 // Browse the inputs of the box in order to find which ones are not
1881 // connected and can be adapted from a widget adaptor
1882 // vector which stores the list of inputs of the box which must be connected
1883 std::vector<std::string> in;
1884 Factory* F = mExecuter->GetFactory();
1888 bbtkError("Interpreter::CreateGUI : could not access the executer factory");
1890 Package* user = F->GetPackage("user");
1891 ComplexBlackBoxDescriptor* workspace
1892 = (ComplexBlackBoxDescriptor*)user->GetBlackBoxMap().find("workspace")->second;
1894 BlackBox* box = workspace->GetPrototype()->bbGetBlackBox(boxname);
1895 // BlackBox::InputConnectorMapType incm = box->bbGetInputConnectorMap();
1897 BlackBox::InputConnectorMapType::iterator i;
1898 for (i=box->bbGetInputConnectorMap().begin();
1899 i!=box->bbGetInputConnectorMap().end();
1902 // If the input is connected : continue
1903 if (i->second->IsConnected()) continue;
1904 // Get the input descriptor
1905 const BlackBoxInputDescriptor* d = box->bbGetDescriptor()->GetInputDescriptor(i->first);
1906 // If it is a "system" input : skip it
1907 if ( ( d->GetCreatorTypeInfo() == typeid(AtomicBlackBoxDescriptor)) ||
1908 ( d->GetCreatorTypeInfo() == typeid(WxBlackBoxDescriptor)) )
1911 std::string widget,adaptor;
1912 // try to find a widget adaptor
1913 if (F->FindWidgetAdaptor(DataInfo(d->GetTypeInfo(),""),
1917 // command to create the adaptor
1918 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1919 // Sets the label of the widget adaptor to the name of the input
1920 (*s) << " set "<<i->first<<".Label "<<i->first<<std::endl;
1921 // Sets the initial value of the widget to the value of the input
1922 (*s) << " set "<<i->first<<".In \""
1923 <<box->bbGetInputAsString(i->first)<<"\""
1925 // store the input name
1926 in.push_back(i->first);
1927 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
1928 //<i->first<<"'"<<std::endl;
1929 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
1931 // try to find a two pieces adaptor
1932 else if (F->FindWidgetAdaptor2(DataInfo(d->GetTypeInfo(),""),
1936 // command to create the widget
1937 (*s) << " new "<<widget<<" "<<i->first<<"Widget"<<std::endl;
1938 // command to create the adaptor
1939 (*s) << " new "<<adaptor<<" "<<i->first<<std::endl;
1941 (*s) << " connect "<<i->first<<"Widget.Out "
1942 <<i->first<<".In"<<std::endl;
1943 // Sets the label of the widget adaptor to the name of the input
1944 (*s) << " set "<<i->first<<"Widget.Label "<<i->first<<std::endl;
1945 // Sets the initial value of the widget to the value of the input
1946 (*s) << " set "<<i->first<<"Widget.In \""
1947 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
1948 // store the input name
1949 in.push_back(i->first);
1950 (*s) << " connect "<<i->first<<"Widget.Widget layout.Widget"<<in.size()<<std::endl;
1951 //<i->first<<"'"<<std::endl;
1952 (*s) << " connect "<<i->first<<"Widget.BoxChange change.In"<<in.size()<<std::endl;
1955 // try to find an adaptor from string
1956 // If found then can create a text input which
1957 // will be automatically adapted
1958 else if (F->FindAdaptor(DataInfo(typeid(std::string),""),
1962 // command to create the adaptor
1963 (*s) << " new InputText "<<i->first<<std::endl;
1964 // Sets the label of the widget adaptor to the name of the input
1965 (*s) << " set "<<i->first<<".Title "<<i->first<<std::endl;
1966 // Sets the initial value of the widget to the value of the input
1967 (*s) << " set "<<i->first<<".In \""
1968 <<box->bbGetInputAsString(i->first)<<"\""<< std::endl;
1969 // store the input name
1970 in.push_back(i->first);
1971 (*s) << " connect "<<i->first<<".Widget layout.Widget"<<in.size()<<std::endl;
1972 //<i->first<<"'"<<std::endl;
1973 (*s) << " connect "<<i->first<<".BoxChange change.In"<<in.size()<<std::endl;
1982 // command to create the output
1983 (*s) << " output "<<i->first<<" "
1984 <<i->first<<".Out "<<i->first<<std::endl;
1985 // <<" Output of the widget which allows to set "
1989 // Inputs for window properties
1990 (*s) << " input WinTitle layout.WinTitle Title"<<std::endl;
1991 (*s) << " input WinWidth layout.WinWidth Width"<<std::endl;
1992 (*s) << " input WinHeight layout.WinHeight Height"<<std::endl;
1993 (*s) << " input WinDialog layout.WinDialog Dialog"<<std::endl;
1994 (*s) << " input WinHide layout.WinHide Hide"<<std::endl;
1998 // Execute the box executes the layout
1999 (*s) << " exec layout" << std::endl;
2000 (*s) << "endefine" << std::endl;
2001 // (*s) << "help "<< typeName<< std::endl;
2002 // instanciate the box and connect it
2003 (*s) << "new "<<typeName<<" "<<instanceName<<std::endl;
2005 std::vector<std::string>::iterator j;
2006 for (j=in.begin();j!=in.end();++j)
2009 (*s) << "connect "<<instanceName<<"."<<*j<<" "
2010 << boxname<<"."<<*j<<std::endl;
2012 // That's all folks ! now execute the commands :
2015 //=======================================================================