]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkInterpreterVirtual.cxx
Merge branch 'wt-version'
[bbtk.git] / kernel / src / bbtkInterpreterVirtual.cxx
index 88e8f52e3d1dcabbb47e7271071910550ca543ce..8d27b3290dd51134d6cbe9c578ca4d5805942d3a 100644 (file)
@@ -1,4 +1,31 @@
-/*=========================================================================                                                                               
+/*
+ # ---------------------------------------------------------------------
+ #
+ # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+ #                        pour la SantÈ)
+ # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+ # Previous Authors : Laurent Guigues, Jean-Pierre Roux
+ # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+ #
+ #  This software is governed by the CeCILL-B license under French law and
+ #  abiding by the rules of distribution of free software. You can  use,
+ #  modify and/ or redistribute the software under the terms of the CeCILL-B
+ #  license as circulated by CEA, CNRS and INRIA at the following URL
+ #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+ #  or in the file LICENSE.txt.
+ #
+ #  As a counterpart to the access to the source code and  rights to copy,
+ #  modify and redistribute granted by the license, users are provided only
+ #  with a limited warranty  and the software's author,  the holder of the
+ #  economic rights,  and the successive licensors  have only  limited
+ #  liability.
+ #
+ #  The fact that you are presently reading this means that you have had
+ #  knowledge of the CeCILL-B license and that you accept its terms.
+ # ------------------------------------------------------------------------ */
+
+
+/*=========================================================================
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.cxx,v $
   Language:  C++
@@ -6,27 +33,7 @@
   Version:   $Revision: 1.88 $
 =========================================================================*/
 
-/* ---------------------------------------------------------------------
-
-* Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
-* Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
-*
-*  This software is governed by the CeCILL-B license under French law and 
-*  abiding by the rules of distribution of free software. You can  use, 
-*  modify and/ or redistribute the software under the terms of the CeCILL-B 
-*  license as circulated by CEA, CNRS and INRIA at the following URL 
-*  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
-*  or in the file LICENSE.txt.
-*
-*  As a counterpart to the access to the source code and  rights to copy,
-*  modify and redistribute granted by the license, users are provided only
-*  with a limited warranty  and the software's author,  the holder of the
-*  economic rights,  and the successive licensors  have only  limited
-*  liability. 
-*
-*  The fact that you are presently reading this means that you have had
-*  knowledge of the CeCILL-B license and that you accept its terms.
-* ------------------------------------------------------------------------ */                                                                         
+
 
 /**
  *  \file 
@@ -339,7 +346,6 @@ namespace bbtk
     */
 
 
-
   } 
   //=======================================================================
   
@@ -578,8 +584,6 @@ namespace bbtk
   //=======================================================================
   InterpreterVirtual::ExitStatus InterpreterVirtual::InterpretFile( const std::string& filename, bool source )
   {
-
-         printf("EED InterpreterVirtual::InterpretFile 1\n");
          bbtkDebugMessage("interpreter",4,"==> InterpreterVirtual::InterpretFile(\""<<filename<<"\")"<<std::endl);
 
     bool exm = mCommandLine;
@@ -601,8 +605,6 @@ namespace bbtk
 
     mCommandLine = exm;
 
-         printf("EED InterpreterVirtual::InterpretFile 2\n");
-
     return mStatus;
   }
   //=======================================================================
@@ -695,20 +697,19 @@ namespace bbtk
   }
   //=======================================================================  
   
-       void InterpreterVirtual::commandNew(std::string boxType, std::string boxName) // virtual 
+       void InterpreterVirtual::commandNew(const std::string &boxType, const std::string &boxName) // virtual 
     {
-               printf("EED %p InterpreterVirtual::commandNew 1  %s %s\n", this,  boxType.c_str(),boxName.c_str() );            
     }
        
-       void InterpreterVirtual::commandDelete(std::string boxName)
+       void InterpreterVirtual::commandDelete(const std::string &boxName)
     {
     }
 
-       void InterpreterVirtual::commandConnection(std::string nodeFrom, std::string outputLabel, std::string nodeTo, std::string inputLabel)
+       void InterpreterVirtual::commandConnection(const std::string &nodeFrom,const std::string &outputLabel,const std::string &nodeTo,const std::string &inputLabel)
     {
     }
                
-       void InterpreterVirtual::commandPackage(std::string packageName)
+       void InterpreterVirtual::commandPackage(const std::string &packageName)
     {
     }
        
@@ -716,7 +717,7 @@ namespace bbtk
     {
     }
        
-       void InterpreterVirtual::commandDefine(std::string name, std::string pack, std::string scriptfilename)
+       void InterpreterVirtual::commandDefine(const std::string &name,const std::string &pack,const std::string &scriptfilename)
     {
     }
 
@@ -724,43 +725,43 @@ namespace bbtk
     {
     }
 
-       void InterpreterVirtual::commandKind(std::string kind)
+       void InterpreterVirtual::commandKind(const std::string &kind)
     {
     }
        
-       void InterpreterVirtual::commandPrint(std::string value)
+       void InterpreterVirtual::commandPrint(const std::string &value)
     {
     }
        
        
-       void InterpreterVirtual::commandExec(std::string word)
+       void InterpreterVirtual::commandExec(const std::string &word)
     {
     }
        
        
-       void InterpreterVirtual::commandInput(std::string name, std::string box, std::string input,std::string  help)
+       void InterpreterVirtual::commandInput(const std::string &name,const std::string &box,const std::string &input,const std::string  &help)
     {
     }
        
-       void InterpreterVirtual::commandOutput(std::string name, std::string box, std::string output,std::string  help)
+       void InterpreterVirtual::commandOutput(const std::string &name,const std::string &box,const std::string &output,const std::string  &help)
     {
     }
        
-       void InterpreterVirtual::commandSet(std::string box, std::string input, std::string value)
+       void InterpreterVirtual::commandSet(const std::string &box,const std::string &input,const std::string &value)
     {
     }
 
-       void InterpreterVirtual::commandAuthor(std::string author)
+       void InterpreterVirtual::commandAuthor(const std::string &author)
     {
     }
 
-       void InterpreterVirtual::commandCategory(std::string categorytype)
+       void InterpreterVirtual::commandCategory(const std::string &categorytype)
     {
     }
        
        
        
-       void InterpreterVirtual::commandDescription(std::string description)
+       void InterpreterVirtual::commandDescription(const std::string &description)
     {
     }
 
@@ -769,16 +770,16 @@ namespace bbtk
     {
     }
        
-       void InterpreterVirtual::commandInclude(std::string word, bool ok)
+       void InterpreterVirtual::commandInclude(const std::string &word, bool ok)
     {
     }
        
        
-       void InterpreterVirtual::commandLoad(std::string packageName)
+       void InterpreterVirtual::commandLoad(const std::string &packageName)
     {
     }
 
-       void InterpreterVirtual::commandUnload(std::string packageName)
+       void InterpreterVirtual::commandUnload(const std::string &packageName)
     {
     }
        
@@ -794,8 +795,7 @@ namespace bbtk
     {
     }
        
-//ups2 EED Borrame     
-       void InterpreterVirtual::commandMessage(std::string kind, std::string levelstr)
+       void InterpreterVirtual::commandMessage(const std::string &kind,const std::string &levelstr)
     {
     }
        
@@ -803,16 +803,12 @@ namespace bbtk
        
   //=======================================================================  
   void InterpreterVirtual::DoInterpretLine( const std::string& line )
-  {
-         
-         printf("EED %p InterpreterVirtual::DoInterpretLine 0 \n", this);        
-         printf("EED %p InterpreterVirtual::DoInterpretLine line=%s \n", this, line.c_str() );   
+  {  
     bbtkDebugMessage("interpreter",6,"==> InterpreterVirtual::DoInterpretLine(\""
                     <<line<<"\")"<<std::endl);
     std::vector<std::string> words;
     SplitLine(line,words);
 
-printf("EED %p InterpreterVirtual::DoInterpretLine word.size %d \n", this, (int)words.size() );          
          
          
     // Empty line
@@ -859,7 +855,6 @@ printf("EED %p InterpreterVirtual::DoInterpretLine word.size %d \n", this, (int)
        return;
     }
          
-printf("EED %p InterpreterVirtual::DoInterpretLine word.size %d \n", this,  (int)words.size() );         
 
     // Command 
     CommandInfoType command;
@@ -872,7 +867,6 @@ printf("EED %p InterpreterVirtual::DoInterpretLine word.size %d \n", this,  (int
     std::string left,right,left2,right2;
     std::string filename;
 
-//ups1 EED borrame       
     // message command
     if (command.code==cMessage)
       {
@@ -896,19 +890,19 @@ printf("EED %p InterpreterVirtual::DoInterpretLine word.size %d \n", this,  (int
 
     // break and quit commands
     if ((command.code==cBreak) || (command.code==cQuit))
-      {
-       bool in_script = false;
-       std::string file("");
-       int line = 0;
-
-       if (mFileName.size()) 
-         {
-           std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
-           if (fs!=0) in_script = true;          
-           file = mFileName.back();
-           line = mLine.back();
-         } 
-       if (command.code==cBreak)
+    {
+//EED-Borrame  bool in_script = false;
+//EED-Borrame  std::string file("");
+//EED-Borrame  int line = 0;
+
+//EED-Borrame  if (mFileName.size()) 
+//EED-Borrame    {
+//EED-Borrame      std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
+//EED-Borrame      if (fs!=0) in_script = true;          
+//EED-Borrame      file = mFileName.back();
+//EED-Borrame      line = mLine.back();
+//EED-Borrame    } 
+         if (command.code==cBreak)
          {
            /*
            std::cout << "BreakException(" 
@@ -919,24 +913,20 @@ printf("EED %p InterpreterVirtual::DoInterpretLine word.size %d \n", this,  (int
                  commandBreak();
 //EED Borrame      bbtkError("break");//,in_script,file,line);
            //      throw BreakException(in_script,file,line);
-         }       
-       else 
-         {
+         } else {
                  commandQuit();
 //EED Borrame      bbtkError("quit");//,in_script,file,line);
              //throw QuitException(in_script,file,line);
-         }
-       return;
-      }   
+         } // cBreak
+         return;
+   } // cBreak  cQuit  
 //std::cout<<" mVirtualExecuter->Create(words[1],words[2]); "<<line<<std::endl;
     // other cammands
 
-printf("EED %p InterpreterVirtual::DoInterpretLine 4  command.code=%d\n", this, (int)command.code);      
          
     switch (command.code) 
       {
       case cNew :
-printf("EED %p InterpreterVirtual::DoInterpretLine 5  %s %s\n", this,  words[1].c_str() , words[2].c_str() );    
                commandNew(words[1],words[2]);
 //EED Borrame        mVirtualExecuter->Create(words[1],words[2]);
         break;
@@ -971,7 +961,8 @@ printf("EED %p InterpreterVirtual::DoInterpretLine 5  %s %s\n", this,  words[1].
         }
         if (words.size()==2) 
         {
-                       commandDefine(words[1],"",filename);
+                       std::string packTmp = "";
+                       commandDefine(words[1],packTmp,filename);
 //EED Borrame           mVirtualExecuter->Define(words[1],"",filename);
         }
         else
@@ -1135,10 +1126,7 @@ printf("EED %p InterpreterVirtual::DoInterpretLine 5  %s %s\n", this,  words[1].
 
     bbtkDebugMessage("interpreter",6,"<== InterpreterVirtual::DoInterpretLine(\""
                     <<line<<"\")"<<std::endl);
-    
-printf("EED %p InterpreterVirtual::DoInterpretLine 10\n", this);         
 
-         
   }
   //=======================================================================  
 
@@ -1268,9 +1256,6 @@ printf("EED %p InterpreterVirtual::DoInterpretLine 10\n", this);
   // =========================================================================
   void InterpreterVirtual::SwitchToFile( const std::string& name , bool source )
   {
-         printf("EED InterpreterVirtual::SwitchToFile 1\n");
-         printf("EED InterpreterVirtual::SwitchToFile name=%s\n", name.c_str() );
-         
   // Note : in the following :
   // name : the user supplied name 
   //      - abreviated name    e.g.       scr   scr.bbs
@@ -1288,7 +1273,8 @@ printf("EED %p InterpreterVirtual::DoInterpretLine 10\n", this);
     std::string fullPathScriptName;  // full path script name
     std::string pkgname;             // e.g. <scriptname>.bbs
     std::vector<std::string> Filenames;
-
+         std::string tmpFilenames;
+         
     // The following is *NOT* a debug time message :
     // It's a user intended message.
     // Please don't remove it.
@@ -1313,8 +1299,6 @@ printf("EED %p InterpreterVirtual::DoInterpretLine 10\n", this);
 
        std::stringstream* stream = new std::stringstream;
        //if (upath.size()!=0) // avoid troubles for "*"
-
-printf("EED InterpreterVirtual::SwitchToFile 2\n");
                  
        // ==== no path provided : look in root bbs path
        if (upath.size()==0)
@@ -1352,6 +1336,7 @@ printf("EED InterpreterVirtual::SwitchToFile 2\n");
                 i++)
              {
                std::string full_path(*i);
+printf("EED InterpreterVirtual::SwitchToFile 1. >>%s\n", full_path.c_str() );
                // we *really* want '.' to be the current working directory
                if (full_path == ".") 
                  {
@@ -1376,24 +1361,49 @@ printf("EED InterpreterVirtual::SwitchToFile 2\n");
              }
          }
        
-printf("EED InterpreterVirtual::SwitchToFile 3\n");
-
        // === search paths list complete : now explore it
        int nbBssFiles = 0;     
        // ==== relative name, iterate + load all .bbs/.bbp files
        std::vector<std::string>::iterator i;
        for (i=script_paths.begin();i!=script_paths.end();i++)
          {
+
+printf("EED InterpreterVirtual::SwitchToFile (1) >>  %s\n", (*i).c_str() );
+                 
            bbtkMessage("interpreter",1,
                        "--> Looking in '" << *i << "'" << std::endl);
            
            Filenames.clear();
            //int nbFiles = 
            Utilities::Explore(*i, false, Filenames);
-           
+
+                 int iFilesnames,jFilesnames,sizeFilenames;
+                 sizeFilenames=Filenames.size();
+                 
+                 
+                 // EEDd 30 sept 2012
+                 //Sorting list of files
+                 for (iFilesnames=0;iFilesnames<sizeFilenames; iFilesnames++)
+             {
+                         for (jFilesnames=iFilesnames;jFilesnames<sizeFilenames; jFilesnames++)
+                         {
+                                 if ( Filenames[iFilesnames] > Filenames[jFilesnames] )
+                                 {
+                                         tmpFilenames                          = Filenames[iFilesnames];
+                                         Filenames[iFilesnames]        = Filenames[jFilesnames];
+                                         Filenames[jFilesnames]        = tmpFilenames;
+                                 } // if Filesnames
+                         } // for iFilesnames
+             } // for iFilesnames
+                 
+                 
+                 
            for (std::vector<std::string>::iterator j = Filenames.begin(); 
                 j!= Filenames.end(); ++j)
              {
+                         
+printf("EED InterpreterVirtual::SwitchToFile (2)     >>  %s\n", (*j).c_str() );
+                         
                int lgr = (*j).size();
                if (lgr < 5) continue;  
                // ignore non .bbp file
@@ -1488,6 +1498,7 @@ printf("EED InterpreterVirtual::SwitchToFile 3\n");
                }
          
                std::string tfullPathScriptName = Utilities::MakePkgnameFromPath(path, name, false);
+                 
 //Addition JCP tfullPathScriptName.size()>=4 
                if(tfullPathScriptName.size()>=4){
                        if (tfullPathScriptName.substr(tfullPathScriptName.size()-4, 3)==".bb")
@@ -1548,29 +1559,38 @@ printf("EED InterpreterVirtual::SwitchToFile 3\n");
           bbtkError("No ["<<pkgname<<".bbs/.bbp] script found");
        return;
       } else {
+//EED printf("EED D. SwitchToFile %s\n", fullPathScriptName.c_str() );   
                LoadScript(fullPathScriptName,name);
 //EED Borrame    if (source) GetExecuter()->SetCurrentFileName(fullPathScriptName);
-               if (source) SetCurrentFileName(fullPathScriptName);
+                 if (source) 
+                 {
+                         // Over writing the fullpath of the bbp file.
+                         SetCurrentFileName( fullPathScriptName );
+                         SetTypeOfScript_Application();
+                 }
        }    
-         
-printf("EED InterpreterVirtual::SwitchToFile 4\n");
-         
+                 
     return;
   }
   //=======================================================================
 
        //=======================================================================
-       void InterpreterVirtual::SetCurrentFileName(std::string fullPathScriptName)  // virtual 
+       void InterpreterVirtual::SetCurrentFileName(const std::string &fullPathScriptName)  // virtual 
        {
-               printf("EED InterpreterVirtual::SetCurrentFileName 1\n");
        }       
        //=======================================================================
        
+       
+       //=======================================================================
+       void InterpreterVirtual::SetTypeOfScript_Application( )
+       {
+       }
+       //=======================================================================
+
+       
   //=======================================================================
 void InterpreterVirtual::SwitchToStream( std::stringstream* stream )
 {
-printf("EED InterpreterVirtual::SwitchToStream 1\n");
-       
   bbtkDebugMessage("interpreter",4,"==> InterpreterVirtual::SwitchToStream()"
                   <<std::endl);
    mFile.push_back(stream);
@@ -1682,14 +1702,12 @@ printf("EED InterpreterVirtual::SwitchToStream 1\n");
                                       CommandInfoType& info )
   {
          
-       printf("EED InterpreterVirtual::InterpretCommand  1 \n");
     bbtkDebugMessage("interpreter",9,"==> InterpreterVirtual::InterpretCommand(...)"<<std::endl);
 
     // searches the command keyword
     CommandDictType::iterator c;
     c = mCommandDict.find(words[0]);
     if ( c == mCommandDict.end() ) {
-printf("EED InterpreterVirtual::InterpretCommand  2 \n");
       bbtkError(words[0]<<" : unknown command");
     }
 
@@ -1700,14 +1718,10 @@ printf("EED InterpreterVirtual::InterpretCommand  2 \n");
                
 //EED       HelpCommand(words[0]);
                commandHelp(words[0]);
-printf("EED InterpreterVirtual::InterpretCommand  3 \n");
-               
        bbtkError(words[0]<<" : wrong number of arguments");
     }
 //std::cout<<"InterpreterVirtual::InterpretCommand( const std::vector<std::string>& words,"<<std::endl;
     info = c->second;
-
-printf("EED InterpreterVirtual::InterpretCommand  4 \n"  );
     bbtkDebugMessage("interpreter",9,"<== InterpreterVirtual::InterpretCommand(...)"<<std::endl);
 
   }
@@ -1720,7 +1734,7 @@ printf("EED InterpreterVirtual::InterpretCommand  4 \n"  );
   { 
   }
   //=======================================================================
-  void InterpreterVirtual::commandHelp(const std::string words) 
+  void InterpreterVirtual::commandHelp(const std::string &words) 
   {  
   }
        //=======================================================================
@@ -1989,7 +2003,7 @@ printf("EED InterpreterVirtual::InterpretCommand  4 \n"  );
     ter.c_cc[VTIME]=0;
     tcsetattr(0,TCSANOW,&ter);
 #endif
-    
+
     mCommandLine = true;
     bool again = true;
     // bool insideComment = false; // for multiline comment