]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkInterpreter.cxx
Created a bbs editor : bbed
[bbtk.git] / kernel / src / bbtkInterpreter.cxx
index 468d41f0ab5909c6ed739b9ecc10fb20cefd1e38..2147d0ca35c1b84760ca57380c523ad77b85b89a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/03/17 07:04:08 $
-  Version:   $Revision: 1.45 $
+  Date:      $Date: 2008/03/18 12:51:26 $
+  Version:   $Revision: 1.46 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -388,6 +388,97 @@ bufferNb =0;
   //=======================================================================
 
 
+  //=======================================================================
+  /**
+   *  
+   */
+  void Interpreter::InterpretBuffer( std::stringstream* buffer )
+  {
+    bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretBuffer()"<<std::endl);
+  //  std::cout << "==========================================Entree InterpretFile ["<<filename<<"] try SwitchToFile "<<std::endl;
+    bool exm = mCommandLine;
+    mCommandLine = false;
+
+    try 
+    {
+      SwitchToStream(buffer);
+
+/*
+      for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
+      {
+         std::cout << "A=== [" << (*it) << "]" << std::endl;
+      }
+*/      
+      bool insideComment = false; // for multiline comment
+      while (mFile.size()>0) 
+      {
+/*
+         for( std::vector<std::string>::iterator it =mFileName.begin(); it!=mFileName.end(); ++it)
+         {
+            std::cout << "B=== [" << (*it) << "]" << std::endl;
+         }
+*/      
+
+         //while ((mFile.size()>0) && !mFile.back()->eof() ) 
+         //{
+//      std::cout << "mFile.size() "<< mFile.size() << " mFileName.back() [" << mFileName.back() << "]" <<  std::endl;
+        while (!mFile.back()->eof()) {
+                    mLine.back()++;
+            char buf[500];
+            mFile.back()->getline(buf,500);
+            std::string str(buf);
+// std::cout << " in InterpretFile mFile.back()->getline [" << str << "]" << std::endl;    
+            int size=str.length();
+            if ( str[ size-1 ]==13  )
+            {
+               str.erase(size-1,1);
+            }
+      
+               InterpretLine(str, insideComment);
+
+       }//while
+       //if (mFile.size()>0) 
+       CloseCurrentFile();
+      }
+    }
+    catch (QuitException e) 
+    { 
+      //      std::cout  << "**QuitException caught**"<<std::endl;
+    }
+    catch (bbtk::Exception e) 
+    {
+      std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
+      if (mFileName.size()) {
+         std::cerr << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
+         std::cerr << "* LINE  : "<<mLine.back()<<std::endl;
+      }    
+    }
+    catch (std::exception& e) 
+    {
+       std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
+       if (mFileName.size()) {
+          std::cerr << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
+          std::cerr << "* LINE  : "<<mLine.back()<<std::endl;
+       }    
+    }  
+    catch (...)
+    {
+       std::cout << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
+       if (mFileName.size()) {
+          std::cout << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
+          std::cout << "* LINE  : "<<mLine.back()<<std::endl;
+      }    
+    }
+
+    CloseAllFiles();
+    bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
+    bbtkDecTab("Interpreter",9);
+
+    mCommandLine = exm;
+  }
+  //=======================================================================
+
+
 
   //=======================================================================  
   /**