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