00001 /*========================================================================= 00002 Program: bbtk 00003 Module: $RCSfile: bbstdExecBbiCommand.cxx,v $ 00004 Language: C++ 00005 Date: $Date: 2008/10/17 08:18:26 $ 00006 Version: $Revision: 1.10 $ 00007 =========================================================================*/ 00008 00009 /* --------------------------------------------------------------------- 00010 00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale) 00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux 00013 * 00014 * This software is governed by the CeCILL-B license under French law and 00015 * abiding by the rules of distribution of free software. You can use, 00016 * modify and/ or redistribute the software under the terms of the CeCILL-B 00017 * license as circulated by CEA, CNRS and INRIA at the following URL 00018 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 00019 * or in the file LICENSE.txt. 00020 * 00021 * As a counterpart to the access to the source code and rights to copy, 00022 * modify and redistribute granted by the license, users are provided only 00023 * with a limited warranty and the software's author, the holder of the 00024 * economic rights, and the successive licensors have only limited 00025 * liability. 00026 * 00027 * The fact that you are presently reading this means that you have had 00028 * knowledge of the CeCILL-B license and that you accept its terms. 00029 * ------------------------------------------------------------------------ */ 00030 00031 00032 #include "bbstdExecBbiCommand.h" 00033 #include "bbstdPackage.h" 00034 #include "bbtkInterpreter.h" 00035 #include "bbtkExecuter.h" 00036 00037 namespace bbstd 00038 { 00039 00040 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ExecBbiCommand); 00041 BBTK_BLACK_BOX_IMPLEMENTATION(ExecBbiCommand,bbtk::AtomicBlackBox); 00042 00043 void ExecBbiCommand::bbUserConstructor() 00044 { 00045 bbSetInputIn("help"); 00046 } 00047 00048 void ExecBbiCommand::DoProcess() 00049 { 00050 00051 // Look for the interpreter 00052 bbtk::Interpreter::Pointer I; 00053 bool delete_inter = false; 00054 if (bbGetParent() != 0) 00055 { 00056 bbtk::Factory::Pointer f 00057 = ((bbtk::ComplexBlackBoxDescriptor*)bbGetParent() 00058 ->bbGetDescriptor().get())->GetFactory(); 00059 if ((f != 0)&& 00060 (f->GetExecuter())) 00061 { 00062 I = f->GetExecuter()->GetInterpreter(); 00063 } 00064 } 00065 if (I==0) 00066 { 00067 // bbtkError("ExecBbiCommand::DoProcess() : could not find interpreter"); 00068 I = bbtk::Interpreter::New(); 00069 delete_inter = true; 00070 } 00071 00072 unsigned int i; 00073 00074 bool ok=true; 00075 int pos1=0,pos2; 00076 pos2 = bbGetInputIn().find(";",pos1); 00077 std::string ccommand; 00078 while (ok==true) 00079 { 00080 if (pos2==-1) 00081 { 00082 ok=false; 00083 ccommand=bbGetInputIn().substr(pos1,bbGetInputIn().length()-pos1 ); 00084 } else { 00085 ccommand=bbGetInputIn().substr(pos1,pos2-pos1); 00086 } 00087 for ( i=0 ; i < ccommand.length() ; i++) 00088 { 00089 if (ccommand[i]==39) 00090 { 00091 ccommand[i]=34; 00092 } 00093 } 00094 00095 I->InterpretLine( ccommand ); 00096 pos1=pos2+1; 00097 pos2 = bbGetInputIn().find(";",pos2+1); 00098 00099 } 00100 00101 // if (delete_inter) delete I; 00102 00103 /* Grrr not works in windows 00104 char * pch; 00105 pch = strtok (bbGetInputIn(),";"); 00106 while (pch != NULL) 00107 { 00108 std::string ccommand(pch); 00109 printf("EED ExecBbiCommand::DoProcess 1.1 %s\n",ccommand.c_str()); 00110 for ( i=0 ; i < ccommand.length() ; i++) 00111 { 00112 if (ccommand[i]==39) 00113 { 00114 ccommand[i]=34; 00115 } 00116 } 00117 00118 printf("EED ExecBbiCommand::DoProcess 2 %s\n",ccommand.c_str()); 00119 bbtk::Interpreter::mGlobalInterpreter->InterpretLine( ccommand ); 00120 pch = strtok (NULL, ";"); 00121 } 00122 */ 00123 } 00124 } // EO namespace bbstd 00125 00126