]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Wed, 23 Apr 2008 08:34:06 +0000 (08:34 +0000)
committerguigues <guigues>
Wed, 23 Apr 2008 08:34:06 +0000 (08:34 +0000)
kernel/appli/bbi/bbi.cxx
kernel/src/bbtkMessageManager.cxx
kernel/src/bbtkMessageManager.h
kernel/src/bbtkSystem.cxx [new file with mode: 0644]
kernel/src/bbtkSystem.h

index 3c00bb8db477d4ed45b9990f03cd761bb9b87951..42d5ec54c25d2310b3aab45f5f92d610512bfebe 100644 (file)
 
 static const wxCmdLineEntryDesc cmdLineDesc[] =
 {
-  { wxCMD_LINE_SWITCH, _T("M"), _T("Memory debug"), _T("Display memory debug message on exit") },
-  { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("Debug messages on (message All 9)") },
-  { wxCMD_LINE_SWITCH, _T("c"), _T("command"), _T("turn to command line mode after file(s) processing") },
-  { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"),   _T("be quiet") },
-  { wxCMD_LINE_SWITCH, _T("h"), _T("help"),   _T("print help") },
-  { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"),   _T("prompts the user for the parameters values using dialog boxes") },
-  { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"),   _T("prompts the user for the parameters values in text mode") },
-  { wxCMD_LINE_SWITCH, _T("n"), _T("no-command"),   _T("do not show command window except on error") },
-  { wxCMD_LINE_SWITCH, _T("N"), _T("no-command-at-all"),   _T("do not show command window even on error") },
+  { wxCMD_LINE_SWITCH, _T("M"), _T("Memory debug"), _T("Display memory debug message on exit ('object -S')") },
+  { wxCMD_LINE_SWITCH, _T("d"), _T("debug"), _T("all messages on ('message all 9')") },
+  { wxCMD_LINE_SWITCH, _T("c"), _T("console"), _T("open a console") },
+  { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"),   _T("be quiet ('message max 0')") },
+  { wxCMD_LINE_SWITCH, _T("h"), _T("help"),   _T("print help on bbi or on workspace defined if any") },
+  { wxCMD_LINE_SWITCH, _T("g"), _T("graphical-dialog"),   _T("prompts the user for the parameter values using graphical dialog") },
+  { wxCMD_LINE_SWITCH, _T("t"), _T("text-dialog"),   _T("prompts the user for the parameter values in text mode") },
+  { wxCMD_LINE_SWITCH, _T("N"), _T("no-console"),   _T("do not show console (even on error)") },
   { wxCMD_LINE_PARAM,  NULL, NULL, _T("input_file"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE },
   { wxCMD_LINE_NONE }
 };
@@ -45,14 +44,13 @@ public:
   bbtk::Interpreter* I;
   int argc;
   std::vector<std::string> argv;
-  bool command;
+  bool console;
   bool debug;
   bool quiet;
   bool help;
   bool graphical_dialog;
   bool text_dialog;
-  bool no_command;
-  bool no_command_at_all;
+  bool no_console;
 
   std::map<std::string,std::string> param_map;
   std::vector<std::string> input_file;
@@ -79,9 +77,7 @@ bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
   help = ( parser.Found(_T("h")) );
   graphical_dialog = ( parser.Found(_T("g")) );
   text_dialog = ( parser.Found(_T("t")) );
-  no_command_at_all = ( parser.Found(_T("N")) );
-  no_command = ( parser.Found(_T("n")) || no_command_at_all );
-
+  no_console = ( parser.Found(_T("N")) );
 
   // parse the arguments and consider those which contain a "=" 
   // as set input commands, other as files
@@ -112,9 +108,9 @@ bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
     parser.Usage();
   }
 
-  command = ( parser.Found(_T("c")) || 
+  console = ( parser.Found(_T("c")) || 
              ((input_file.size() == 0) && 
-              (!no_command) &&
+              (!no_console) &&
               (!usage) ) );
 
 
@@ -124,6 +120,9 @@ bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
 
 
 
+
+
+
 // ----------------------------------------------------------------------------
 // The `main program' equivalent, creating the windows and returning the
 // main frame
@@ -136,13 +135,15 @@ bool wxBBIApp::OnInit( )
   setlocale(LC_NUMERIC, "C");
 #endif
   
-  if (quiet) bbtk::MessageManager::SetMessageLevel("All",0);
-  if (debug) bbtk::MessageManager::SetMessageLevel("All",9);
+
+  if (quiet) bbtk::MessageManager::SetMessageLevel("max",0);
+  if (debug) bbtk::MessageManager::SetMessageLevel("all",9);
   
 
   bbtk::WxGUIConsole *I = new bbtk::WxGUIConsole(0,_T("bbi"),wxSize(800,600));
   SetTopWindow(I);  
-  if (!no_command) I->Show(true);
+  if (console) I->Show(true);
+
 
   I->SetInputs(param_map);
 
@@ -160,7 +161,7 @@ bool wxBBIApp::OnInit( )
       error = ! I->InterpretFile(*i);
       if (error) break;
     }
-  bool show_on_error = error && ! no_command_at_all;
+  bool show_on_error = error && ! no_console;
   if (show_on_error) I->Show();
 
   I->SetNoExecMode(false);
@@ -171,7 +172,7 @@ bool wxBBIApp::OnInit( )
       I->GetInterpreter()->GetExecuter()->GetFactory()->HelpBlackBox("workspace",package,false);
     }
 
-  if (!(show_on_error || command || bbtk::Wx::IsSomeWindowShown() ))
+  if (!(show_on_error || console || bbtk::Wx::IsSomeWindowShown() ))
     {
       I->Close();
     }
index 31c486bb1fac0579a62944db1bb30849f195608b..56c3227e91326e1a8b52357d598b737d80dbb967 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkMessageManager.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/22 14:30:25 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2008/04/23 08:34:06 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -25,10 +25,18 @@ namespace bbtk
 {
 
   MessageManager::MessageManager() 
-    : mMaxMessageLength(8), mAllLevel(0) 
+    : mMaxMessageLength(8)//, mAllLevel(0), mMaxLevel(9)
     
   {
     std::string key;
+    key ="all";
+    mMessageLevel[key] = 0;
+    mMessageHelp[key] = "Minimum level for all kind of messages";
+    if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
+    key ="max";
+    mMessageLevel[key] = 9;
+    mMessageHelp[key] = "Maximum level for all kind of messages";
+    if (mMaxMessageLength<key.length()) mMaxMessageLength = key.length();
     key ="Kernel";
     mMessageLevel[key] = 0;
     mMessageHelp[key] = "Messages generated by the core classes of the lib";
@@ -120,37 +128,31 @@ namespace bbtk
                                              unsigned char level) 
   {
     std::map<std::string,int>::iterator i;
-    if (key==std::string("All")) {
-      GetInstance()->mAllLevel = level;
-      
-      for (i=GetInstance()->mMessageLevel.begin();
-          i!=GetInstance()->mMessageLevel.end();
-          ++i) 
-        (*i).second = level;
-      
-    }
-    else {
-      i = GetInstance()->mMessageLevel.find(key);
-      if (i!=GetInstance()->mMessageLevel.end()) {
+    i = GetInstance()->mMessageLevel.find(key);
+    if (i!=GetInstance()->mMessageLevel.end()) 
+      {
        (*i).second = level;
       }
-      else {
+    else 
+      {
        bbtkWarning("MessageManager::SetMessageLevel : message type=<"
                    <<key<<"> unregistered");
       }
-    }
+    
   }
-
-
-
+  
+  
+  
   int MessageManager::GetMessageLevel(std::string key) 
   {
-    int l = GetInstance()->mAllLevel;
+    int l = GetInstance()->mMessageLevel["all"];
     std::map<std::string,int>::iterator i = 
       GetInstance()->mMessageLevel.find(key);
     if (i!=GetInstance()->mMessageLevel.end()) {
       if ( (*i).second > l ) l = (*i).second;      
     }
+    int m = GetInstance()->mMessageLevel["max"];
+    if (l>m) l=m;
     return l;
   }
 
@@ -162,10 +164,11 @@ namespace bbtk
                << bbtkendl);
     bbtkMessage("Help",1, "Kind");
     for (int k=0;
-        k<(int)(GetInstance()->mMaxMessageLength-8);
-        k++) {
-      bbtkMessageCont("Help",1," "); 
-    }
+        k<(int)(GetInstance()->mMaxMessageLength-2);
+        k++) 
+      {
+       bbtkMessageCont("Help",1," "); 
+      }
     bbtkMessageCont("Help",1,"Level  Nature" << bbtkendl);
     std::map<std::string,int>::iterator i;
     std::map<std::string,std::string>::iterator j;  
index 0bf85d002ba9c7e3e788d1d17b89794522ff93c7..496a2258f8bf8538fc1c5a887ca83e9f385fb111 100644 (file)
@@ -413,7 +413,6 @@ namespace bbtk
     std::map<std::string,int> mMessageLevel;
     std::map<std::string,std::string> mMessageHelp;  
     unsigned int mMaxMessageLength;
-    int mAllLevel;
   };
   //===========================================================
   
diff --git a/kernel/src/bbtkSystem.cxx b/kernel/src/bbtkSystem.cxx
new file mode 100644 (file)
index 0000000..3b6da4b
--- /dev/null
@@ -0,0 +1,16 @@
+#include "bbtkSystem.h"
+
+namespace bbtk
+{
+
+#ifdef _WIN32
+  int System::HasTTY() { return false; }
+#else 
+#include <unistd.h>
+   int System::HasTTY() 
+   { 
+     return isatty(fileno(stdin));
+   }
+#endif
+
+} // namespace bbtk
index f59df062dbb904816577ecffd8f131674c4c7f34..f9f22ebb87e45763dc3e3cca1d09aaf82b23490e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkSystem.h,v $
   Language:  C++
-  Date:      $Date: 2008/03/11 18:46:47 $
-  Version:   $Revision: 1.3 $
+  Date:      $Date: 2008/04/23 08:34:06 $
+  Version:   $Revision: 1.4 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -71,7 +71,8 @@
 //-----------------------------------------------------------------------------
 // Micro$oft shared library related stuff
 //
-// all the classes should be defined as :
+// all the classes that must be visible outside the bbtk library 
+// should be defined as :
 // class BBTK_EXPORT ClassName 
 // instead of :
 // class ClassName
@@ -214,6 +215,21 @@ typedef  unsigned int        uint32_t;
 
 
 
+//-----------------------------------------------------------------------------
+
+
+//-----------------------------------------------------------------------------
+namespace bbtk
+{
+  /// System related stuff
+  struct System
+  {
+    /// returns true iff the program has a tty
+    static int HasTTY(); 
+  };
+
+} // namespace bbtk
 //-----------------------------------------------------------------------------
 
 #endif