]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkInterpreter.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkInterpreter.cxx
index 694f97a74a64e2e0c59baf2a96aad56013b20ced..a6e4869da13ba3aa37898565273e3e165fe20cdc 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/02/05 13:23:46 $
-  Version:   $Revision: 1.25 $
+  Date:      $Date: 2008/02/14 10:47:51 $
+  Version:   $Revision: 1.30 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -54,6 +54,7 @@ Interpreter* Interpreter::mGlobalInterpreter = NULL;
 
     //    mFactory = new bbtk::Factory();
     mExecuter = new bbtk::Executer();
+    //mExecuter = new bbtk::Transcriptor("GeneratedProgram.txt");
     //mExecuter->SetFactory(mFactory);
 
     // Builds the commands dict
@@ -222,10 +223,10 @@ Interpreter* Interpreter::mGlobalInterpreter = NULL;
 
     info.category = "include";
     info.argmin = 1;
-    info.argmax = 1;
+    info.argmax = 2;
     info.code = cInclude;
-    info.syntax = "include <filename>";
-    info.help = "Includes the file <filename>";
+    info.syntax = "include <filename> [source]";
+    info.help = "Includes the file <filename>.\n  'source' : If the keyword 'source' is provided then informs bbi that the included file is the source of the current box definition (Advanced; used to get the right 'Include' field in html doc of packages 'appli' scripts).";
     mCommandDict[info.category] = info;
 
     info.category = "quit";
@@ -297,7 +298,7 @@ Interpreter* Interpreter::mGlobalInterpreter = NULL;
    *  
    */
   void Interpreter::InterpretFile( const std::string& filename,  
-                                  bool use_configuration_file)
+                                   bool use_configuration_file)
   {
     bbtkDebugMessageInc("Interpreter",9,"Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
 
@@ -463,7 +464,7 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
       case cDefine :
         if (mFileName.size()>0) 
         {
-           filename = Utilities::get_file_name(mFileName.back());
+         filename = mIncludeFileName.back(); //Utilities::get_file_name(mFileName.back());
         }
         if (words.size()==2) 
         {
@@ -564,6 +565,11 @@ void Interpreter::InterpretLine( const std::string& line, bool &insideComment )
         {
             SwitchToFile(words[1], true ); // true : better pass use_config_file
         }
+       // if 'source' was given
+       if (words.size()==3) 
+         {
+           this->mExecuter->SetCurrentFileName(words[1]);
+         }
         break;
         
       case cLoad:
@@ -744,7 +750,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
         // It's a user intended message.
         // Please don't remove it.
       bbtkMessage("Interpreter",1,
-                 "look for : [" << name 
+                 "look for : [" << name
                  << "] (use_configuration_file == TRUE)" << std::endl);
       script_paths = ConfigurationFile::GetInstance().Get_bbs_paths();
     }
@@ -766,7 +772,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
         {
            if ((*i).substr((*i).size()-4, 4) != ".bbs")
               continue;      // ignore non .bbs files
-           LoadScript(*i);
+           LoadScript(*i,name);
            nbBssFiles++;
         }
         if (nbBssFiles==0)
@@ -816,7 +822,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
 
            if ((*i).substr((*i).size()-4, 4) != ".bbs")
               continue;      // ignore non .bbs files
-           LoadScript(*i);
+           LoadScript(*i,name);
            nbBssFiles++;
         }
         if (nbBssFiles==0)
@@ -924,7 +930,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
        return;    
     }
     else
-       LoadScript(fullPathScriptName);
+      LoadScript(fullPathScriptName,name);
 
     return;
   }   
@@ -932,7 +938,8 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
 
   //=======================================================================
 
-  void Interpreter::LoadScript( std::string fullPathScriptName)
+  void Interpreter::LoadScript( std::string fullPathScriptName,
+                               std::string includeScriptName)
   {
     if (find(mFileName.begin(),mFileName.end(),fullPathScriptName)
        !=mFileName.end()) 
@@ -956,6 +963,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
 
     mFile.push_back(s);
     mFileName.push_back(fullPathScriptName);
+    mIncludeFileName.push_back(includeScriptName);
     mLine.push_back(0);
     return;  
   }
@@ -982,6 +990,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
                      " Closing file '"<<mFileName.back()<<"'"<<std::endl);
     
     mFileName.pop_back();
+    mIncludeFileName.pop_back();
     mLine.pop_back();
     bbtkDebugMessage("Interpreter",9," Remains "
                      <<mFile.size()
@@ -1008,6 +1017,7 @@ void Interpreter::SplitLine ( const std::string& str, std::vector<std::string>&
       bbtkDebugMessage("Interpreter",9,
                       " Closing file '"<<mFileName.back()<<"'"<<std::endl);
       mFileName.pop_back();
+      mIncludeFileName.pop_back();
       mLine.pop_back();
     }
     bbtkDebugMessage("Interpreter",9,"EO Interpreter::CloseAllFiles()"
@@ -1073,26 +1083,52 @@ void Interpreter::Help(const std::vector<std::string>& words)
          try 
          {
             HelpPackage(words[1]);
+#ifdef _USE_WXWIDGETS_
+           if ( WxConsole::GetInstance() != 0 )
+             {
+               std::string url = 
+                 ConfigurationFile::GetInstance().Get_doc_path();
+               url += "/bbdoc/" + words[1] + "/index.html";
+               if (Utilities::FileExists(url)) 
+                 {
+                   WxConsole::GetInstance()->ShowHtmlPage(url);
+                 }
+             }
+#endif     
          }
          catch (bbtk::Exception f) 
          {
             try 
             {
-               HelpBlackBox(words[1]);
-            }
-           catch (bbtk::Exception g) 
-           {
-              try
-              {
-                 this->mExecuter->ShowRelations(words[1],"0","9999");
-              }
-              catch (bbtk::Exception h){
-                bbtkError("\""<<words[1].c_str()
-                          <<"\" is not a known command, package, black box type or black box name");
-              }
-           }
+             std::string package;
+             HelpBlackBox(words[1],package);
+#ifdef _USE_WXWIDGETS_
+              if ( WxConsole::GetInstance() != 0 )
+                {
+                  std::string url = 
+                    ConfigurationFile::GetInstance().Get_doc_path();
+                  url += "/bbdoc/" + package + "/index.html";
+                  if (Utilities::FileExists(url)) 
+                    {
+                      url += "#" + words[1];
+                      WxConsole::GetInstance()->ShowHtmlPage(url);
+                    }
+                }
+#endif     
+           }
+           catch (bbtk::Exception g) 
+             {
+               try
+                 {
+                   this->mExecuter->ShowRelations(words[1],"0","9999");
+                 }
+               catch (bbtk::Exception h){
+                 bbtkError("\""<<words[1].c_str()
+                           <<"\" is not a known command, package, black box type or black box name");
+               }
+             }
          }
-       }
+      }
     }
     else if (nbarg==2) 
     {
@@ -1128,44 +1164,9 @@ void Interpreter::Help(const std::vector<std::string>& words)
   /// Displays the Configuration
   void Interpreter::Config() const
   {
-    bbtkDebugMessageInc("Kernel",9,"Factory::Config"<<std::endl);
-    
-    ConfigurationFile cf = ConfigurationFile::GetInstance();
-    
-    const std::string config_xml_full_path      = cf.Get_config_xml_full_path();    
-    const std::string description               = cf.Get_description();
-    const std::string url                       = cf.Get_url();
-    const std::string data_path                 = cf.Get_data_path();
-    const std::string default_doc_tmp           = cf.Get_default_doc_tmp();    
-    const std::string file_separator            = cf.Get_file_separator();    
-    const std::vector<std::string>bbs_paths     = cf.Get_bbs_paths();
-    const std::vector<std::string>package_paths = cf.Get_package_paths();
-    
-    bbtkMessage("Help",1, "============="   << std::endl);           
-    bbtkMessage("Help",1, "Configuration"   << std::endl);
-    bbtkMessage("Help",1, "============="   << std::endl);
-    bbtkMessage("Help",1, "bbtk_config.xml   : [" << config_xml_full_path  << "]" << std::endl); 
-    bbtkMessage("Help",1, "Documentation Url : [" << url             << "]" << std::endl);
-    bbtkMessage("Help",1, "Data Path         : [" << data_path       << "]" << std::endl);
-    bbtkMessage("Help",1, "Default Doc_tmp   : [" << default_doc_tmp << "]" << std::endl);
-    bbtkMessage("Help",1, "File Separator    : [" << file_separator  << "]" << std::endl);
-
-    std::vector<std::string>::const_iterator i;
-           
-    bbtkMessage("Help",1, "BBS Paths   " << std::endl);     
-    for (i = bbs_paths.begin(); i!=bbs_paths.end(); ++i )
-    {
-      bbtkMessage("Help",1,"--- ["<<*i<<"]"<<std::endl);
-    }    
-    
-    bbtkMessage("Help",1, "PACKAGE Paths : " << std::endl);     
-    for (i = package_paths.begin(); i!=package_paths.end(); ++i )
-    {
-      bbtkMessage("Help",1,"--- ["<<*i<<"]"<<std::endl);
-    }
-
-    bbtkDebugDecTab("Kernel",9);
+    ConfigurationFile::GetInstance().GetHelp(1);
   }  
+   //===================================================================    
 
   //=======================================================================
   /// Displays help on all the commands