]> Creatis software - bbtk.git/blob - packages/std/src/bbstdExecBbiCommand.cxx
903ea5db7e34e6a59c46f102b01f7703ed0afc86
[bbtk.git] / packages / std / src / bbstdExecBbiCommand.cxx
1 #include "bbstdExecBbiCommand.h"
2 #include "bbstdPackage.h"
3 #include "bbtkInterpreter.h"
4 #include "bbtkExecuter.h"
5
6 namespace bbstd
7 {
8
9   BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ExecBbiCommand);
10   BBTK_BLACK_BOX_IMPLEMENTATION(ExecBbiCommand,bbtk::AtomicBlackBox);
11
12   void ExecBbiCommand::bbUserConstructor() 
13   { 
14     bbSetInputIn("help");
15   }
16   
17
18   void ExecBbiCommand::DoProcess()
19     {
20      
21       // Look for the interpreter
22       bbtk::Interpreter::Pointer I;
23           bool delete_inter = false; 
24           if (bbGetParent() != 0) 
25         {
26           bbtk::Factory::Pointer f 
27                 = ((bbtk::ComplexBlackBoxDescriptor*)bbGetParent()
28                   ->bbGetDescriptor().get())->GetFactory();
29           if ((f != 0)&&
30               (f->GetExecuter()))
31             {
32               I = f->GetExecuter()->GetInterpreter();
33             }
34         }
35       if (I==0) 
36         {
37           //      bbtkError("ExecBbiCommand::DoProcess() : could not find interpreter");
38           I = bbtk::Interpreter::New();
39           delete_inter = true; 
40         }
41
42       unsigned int i;
43       
44       bool ok=true;
45       int pos1=0,pos2;
46       pos2 = bbGetInputIn().find(";",pos1);
47       std::string ccommand;
48       while (ok==true)
49         {
50           if (pos2==-1) 
51             {
52               ok=false;
53               ccommand=bbGetInputIn().substr(pos1,bbGetInputIn().length()-pos1 );
54             } else {
55             ccommand=bbGetInputIn().substr(pos1,pos2-pos1);
56           }
57           for ( i=0 ; i < ccommand.length() ; i++)
58             {
59               if (ccommand[i]==39)
60                 {
61                   ccommand[i]=34;
62                 }
63             }           
64         
65           I->InterpretLine( ccommand );
66           pos1=pos2+1;
67           pos2 = bbGetInputIn().find(";",pos2+1);
68           
69         }
70       
71 //      if (delete_inter) delete I;
72       
73       /*  Grrr  not works in windows
74         char * pch;
75         pch = strtok (bbGetInputIn(),";");
76         while (pch != NULL)
77         {
78                 std::string ccommand(pch);
79                 printf("EED  ExecBbiCommand::DoProcess 1.1  %s\n",ccommand.c_str());
80                 for ( i=0 ; i < ccommand.length() ; i++)
81                 {
82                         if (ccommand[i]==39)
83                         {
84                                 ccommand[i]=34;
85                         }
86                 }               
87
88                 printf("EED  ExecBbiCommand::DoProcess 2  %s\n",ccommand.c_str());
89                 bbtk::Interpreter::mGlobalInterpreter->InterpretLine( ccommand );
90         pch = strtok (NULL, ";");
91         }
92 */
93 }
94
95
96 } // EO namespace bbstd
97
98