]> Creatis software - bbtk.git/blob - packages/std/src/bbstdExecBbiCommand.cxx
c496ca1602afc80a00d6fad38d55e53a482968df
[bbtk.git] / packages / std / src / bbstdExecBbiCommand.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbstdExecBbiCommand.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:26 $
6   Version:   $Revision: 1.10 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31
32 #include "bbstdExecBbiCommand.h"
33 #include "bbstdPackage.h"
34 #include "bbtkInterpreter.h"
35 #include "bbtkExecuter.h"
36
37 namespace bbstd
38 {
39
40   BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ExecBbiCommand);
41   BBTK_BLACK_BOX_IMPLEMENTATION(ExecBbiCommand,bbtk::AtomicBlackBox);
42
43   void ExecBbiCommand::bbUserConstructor() 
44   { 
45     bbSetInputIn("help");
46   }
47
48   void ExecBbiCommand::DoProcess()
49     {
50
51       // Look for the interpreter
52       bbtk::Interpreter::Pointer I;
53           bool delete_inter = false;
54           if (bbGetParent() != 0)
55           {
56           bbtk::Factory::Pointer f
57                 = ((bbtk::ComplexBlackBoxDescriptor*)bbGetParent()
58                   ->bbGetDescriptor().get())->GetFactory();
59           if ((f != 0)&&
60               (f->GetExecuter()))
61             {
62               I = f->GetExecuter()->GetInterpreter();
63             }
64           }
65       if (I==0)
66           {
67           //      bbtkError("ExecBbiCommand::DoProcess() : could not find interpreter");
68           I = bbtk::Interpreter::New();
69           delete_inter = true;
70           }
71
72       unsigned int i;
73
74       bool ok=true;
75       int pos1=0,pos2;
76       pos2 = bbGetInputIn().find(";",pos1);
77       std::string ccommand;
78       while (ok==true)
79             {
80           if (pos2==-1) 
81            {
82             ok=false;
83             ccommand=bbGetInputIn().substr(pos1,bbGetInputIn().length()-pos1 );
84            } else {
85             ccommand=bbGetInputIn().substr(pos1,pos2-pos1);
86           }
87           for ( i=0 ; i < ccommand.length() ; i++)
88           {
89             if (ccommand[i]==39)
90             {
91                   ccommand[i]=34;
92         }
93      }
94
95           I->InterpretLine( ccommand );
96           pos1=pos2+1;
97           pos2 = bbGetInputIn().find(";",pos2+1);
98
99         }
100       
101 //      if (delete_inter) delete I;
102
103    /*  Grrr  not works in windows
104         char * pch;
105         pch = strtok (bbGetInputIn(),";");
106         while (pch != NULL)
107         {
108                 std::string ccommand(pch);
109                 printf("EED  ExecBbiCommand::DoProcess 1.1  %s\n",ccommand.c_str());
110                 for ( i=0 ; i < ccommand.length() ; i++)
111                 {
112                         if (ccommand[i]==39)
113                         {
114                                 ccommand[i]=34;
115                         }
116                 }
117
118                 printf("EED  ExecBbiCommand::DoProcess 2  %s\n",ccommand.c_str());
119                 bbtk::Interpreter::mGlobalInterpreter->InterpretLine( ccommand );
120         pch = strtok (NULL, ";");
121         }
122   */
123   }
124 } // EO namespace bbstd
125
126