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