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