]> Creatis software - bbtk.git/blobdiff - kernel/appli/bbs2cpp/bbs2.cxx
Clean code for Python
[bbtk.git] / kernel / appli / bbs2cpp / bbs2.cxx
index 184b48c3f9d6de7d85f78a82b550f75eb80ca013..2b881d25ac5bf9d82e1745b3c1fccaf2ede4c15b 100644 (file)
@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
 {  
     if (argc<3)
     {
-        printf("bbs2 <filename.bbs> <cxx|py|js>\n");
+        printf("bbs2 <InputFile.bbs> <OutputFile.[cxx|py|js]> \n");
         return 1;
     }
 
@@ -66,12 +66,15 @@ int main(int argc, char* argv[])
     //    file = fileBase + std::string(".") + extention;
 
     std::string fileBase,path;
-    std::string extention( argv[2] );
-    fileBase = bbtk::Utilities::ExtractScriptName(argv[1],path);
-    std::string file(path+"/"+fileBase+"."+extention);
+//EED 2023-11-15
+//    std::string extention( argv[3] );
+//    fileBase = bbtk::Utilities::ExtractScriptName(argv[1],path);
+//    std::string file(path+"/"+fileBase+"."+extention);
+    std::string file( argv[2] );
     printf("file %s \n",file.c_str() );
 
-    if ( extention.compare("cxx")==0)
+    std::string extentionCxx = file.substr( file.length()-3, 3);
+    if ( extentionCxx.compare(".cxx")==0)
     {
         printf("bbs -> cxx\n");
         bbtk::Interpreter::Pointer I = bbtk::Interpreter::New(file);
@@ -84,7 +87,8 @@ int main(int argc, char* argv[])
         } // try
     } // if cxx
     
-    if ( extention.compare("py")==0)
+    std::string extentionPy = file.substr( file.length()-2, 2);
+    if ( extentionPy.compare("py")==0)
     {
         printf("bbs -> py\n");
          bbtk::InterpreterPython::Pointer I = bbtk::InterpreterPython::New();
@@ -94,28 +98,19 @@ int main(int argc, char* argv[])
              I->InterpretFile(argv[1]);
              std::vector<std::string> pythonBBTK=  ((bbtk::InterpreterPython*)(I.get()))->pythonBBTK  ;
              FILE *ff=fopen(file.c_str(),"w+");
-             fprintf(ff,"\n" );
-             fprintf(ff,"from bbtk.bbtkBlackBox import *\n" );
-             fprintf(ff,"\n" );
-             fprintf(ff,"class %s(ComplexBlackBox):\n",fileBase.c_str() );
-             fprintf(ff,"\n" );
-             fprintf(ff,"    def __init__(self, nameBox):\n" );
-             fprintf(ff,"        super().__init__(nameBox)\n" );
-             fprintf(ff,"\n" );
-             fprintf(ff,"    def Run(self):\n" );
              int i,size=pythonBBTK.size();
              for (i=0; i<size;i++)
              {
-                 fprintf(ff,"        self.%s\n", pythonBBTK[i].c_str() );
+                 fprintf(ff,"%s\n", pythonBBTK[i].c_str() );
              }// for i
-             fprintf(ff,"        self.Execute()\n" );
              fclose(ff);
          } catch (bbtk::Exception e) {
              e.Print();
          } // try
     } // if py
 
-    if ( extention.compare("js")==0)
+    std::string extentionJs = file.substr( file.length()-2, 2);
+    if ( extentionJs.compare("js")==0)
     {
                printf("bbs -> js\n");
         bbtk::InterpreterJavaScript::Pointer I = bbtk::InterpreterJavaScript::New();
@@ -126,9 +121,11 @@ int main(int argc, char* argv[])
             std::vector<std::string> javascriptBBTK=  ((bbtk::InterpreterJavaScript*)(I.get()))->javascriptBBTK  ;
             FILE *ff=fopen(file.c_str(),"w+");
             fprintf(ff,"import * as bbtk from './bbtk.js' \n" );
-            fprintf(ff,"export  class %s{\n",fileBase.c_str() );
+//clean this code
+//            fprintf(ff,"export  class %s{\n",fileBase.c_str() );
             fprintf(ff,"    Run(){\n" );
-            fprintf(ff,"        let mCBjs  = new bbtk.ComplexBlackBox('%s')\n",fileBase.c_str());
+//clean this code
+//            fprintf(ff,"        let mCBjs  = new bbtk.ComplexBlackBox('%s')\n",fileBase.c_str());
             int i,size=javascriptBBTK.size();
             for (i=0; i<size;i++)
             {