]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Fri, 9 Jul 2010 16:05:42 +0000 (16:05 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Fri, 9 Jul 2010 16:05:42 +0000 (16:05 +0000)
kernel/appli/bbi/bbi.cxx

index 16cbb8f0b45565addc4cc3ed00180051f7e09380..812f115a63f68df3b3d64b2054ca56d4961437f0 100644 (file)
@@ -31,7 +31,7 @@ static const wxCmdLineEntryDesc cmdLineDesc[] =
 
 //==========================================================================
 // Processes the command line parsing result
-struct ProcessCmdLine
+struct WxProcessCmdLine
 {
   ProcessCmdLine() {}
   void Process(wxCmdLineParser& parser);
@@ -53,7 +53,7 @@ struct ProcessCmdLine
 //==========================================================================
 
 //==========================================================================
-void ProcessCmdLine::Process(wxCmdLineParser& parser)
+void WxProcessCmdLine::Process(wxCmdLineParser& parser)
 {
   proceed = true;
   if (parser.Found(_T("D"))) 
@@ -120,7 +120,7 @@ public:
   void OnInitCmdLine(wxCmdLineParser& parser);
   bool OnCmdLineParsed(wxCmdLineParser& parser);
 
-  ProcessCmdLine cmd;
+  WxProcessCmdLine cmd;
 };
 //==========================================================================
 
@@ -314,15 +314,112 @@ int main(int argc, char* argv[])
 //==========================================================================
 
 #include "bbtkInterpreter.h"
-//#include "bbtkWx.h"
 
-int main(int argc, char* argv[])
-{  
-  if (argc>2) 
+// Processes the command line parsing result
+struct ProcessCmdLine
+{
+  ProcessCmdLine() {}
+  void Process(int argc_, char *argv_[]);
+  bool Found(std::string value);
+
+  int  argc;
+  std::vector<std::string> argv;
+  bool console;
+  bool debug;
+  bool quiet;
+  bool help;
+  bool graphical_dialog;
+  bool text_dialog;
+  bool no_console;
+  bool proceed;
+  std::map<std::string,std::string> param_map;
+  std::vector<std::string> input_file;
+  
+};
+
+bool ProcessCmdLine::Found(std::string value)
+{
+       bool result=false;
+       for (int i=1; i<argc; ++i) 
+       {
+               if (value==argv[i]) 
+               {
+                       result = true;
+               } 
+       } // for
+       return result;
+}
+
+void ProcessCmdLine::Process(int argc_, char *argv_[])
+{
+   argc = argc_;
+   for (int i=0; i<argc; ++i) 
     {
-      std::cout << "usage : "<<argv[0]<<" [filename]"<<std::endl;
-      return 0;
+       argv.push_back(argv_[i]);
+    } // for
+
+//EED  proceed = true;
+  if (Found("D")) 
+    {
+      bbtk::StaticInitTime::PrintObjectListInfo = true;
     }
+  
+  debug                = ( Found("d") );  
+  quiet                        = ( Found("q") );
+  help                 = ( Found("h") );
+  graphical_dialog     = ( Found("g") );
+  text_dialog          = ( Found("t") );
+  no_console           = ( Found("N") );
+  
+  if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
+  if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
+
+  // parse the arguments and consider those which contain a "=" 
+  // as set input commands, other as files
+//EED  int pargc = parser.GetParamCount();
+  for (int i=1; i<argc; ++i) 
+    {
+      std::string s = argv[i];
+      std::string::size_type pos = s.find_first_of("=");
+      if (std::string::npos != pos) 
+       {
+         std::string left = s.substr(0,pos);
+         std::string right = s.substr(pos+1,s.size());
+         param_map[left]=right;
+       }
+      else 
+       {
+         input_file.push_back(s);
+       }
+    }// for
+
+  bool usage = (help && (input_file.size()==0));
+  if (usage) {
+    std::cout << "BBI (The Black Box Interpreter) - bbtk "
+             << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
+             << std::endl;
+//EED    parser.Usage();
+    proceed = false;
+  }
+
+  console = ( Found("c") || 
+             ((input_file.size() == 0) && 
+              (!no_console) &&
+              (!usage) ) );
+  
+}
+//==========================================================================
+
+
+
+int main(int argc, char* argv[])
+{  
+//EED
+//  if (argc>2) 
+//    {
+//      std::cout << "usage : "<<argv[0]<<" [filename]"<<std::endl;
+//      return 0;
+//    }
 
   std::cout << "BBI (Black Box Interpreter) - bbtk "
             << bbtk::GetVersion()<< " - (c) Creatis 2007"
@@ -330,15 +427,17 @@ int main(int argc, char* argv[])
 
   bbtk::Interpreter::Pointer I = bbtk::Interpreter::New();
   if (argc==1) 
-    {
-      I->CommandLineInterpreter();
-    }
-  else 
-
-    {
-      std::string f(argv[1]);
-      I->InterpretFile(f);
-    }
+  {
+       I->CommandLineInterpreter();
+  }  else     {
+        
+       ProcessCmdLine cmd;
+       cmd.Process(argc,argv);
+       I->SetInputs(cmd.param_map);
+
+       std::string f(argv[1]);
+       I->InterpretFile(f);
+  }
   
   //  bbtk::Wx::LoopUntilAllWindowsClose();