remove EnableEnvVar function
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 06 Feb 2007 21:42:31 +0100
changeset 266 a451b8daa1e6
parent 265 fb0c531530f2
child 267 79efb83972b4
remove EnableEnvVar function
src/core/debug.cc
src/core/debug.h
--- a/src/core/debug.cc	Tue Feb 06 20:40:38 2007 +0100
+++ b/src/core/debug.cc	Tue Feb 06 21:42:31 2007 +0100
@@ -35,6 +35,48 @@
 typedef std::list<std::pair <std::string, DebugComponent *> >::iterator ComponentListI;
 
 static ComponentList g_components;
+static bool g_firstDebug = true;
+
+void
+DebugComponentEnableEnvVar (void)
+{
+#ifdef HAVE_GETENV
+  char *envVar = getenv("NS3_DEBUG");
+  if (envVar == 0)
+    {
+      return;
+    }
+  std::string env = envVar;
+  std::string::size_type cur = 0;
+  std::string::size_type next = 0;
+  while (true)
+    {
+      next = env.find_first_of (";", cur);
+      if (next == std::string::npos) 
+	{
+	  std::string tmp = env.substr (cur, next);
+          bool found = false;
+          for (ComponentListI i = g_components.begin ();
+               i != g_components.end ();
+               i++)
+            {
+              if (i->first.compare (tmp) == 0)
+                {
+                  found = true;
+                  i->second->Enable ();
+                  break;
+                }
+            }
+          if (!found)
+            {
+              std::cout << "No debug component named=\"" << tmp << "\"" << std::endl;
+            }
+	}
+      cur = next;
+    }
+#endif
+}
+
 
 DebugComponent::DebugComponent (std::string name)
   : m_isEnabled (false)
@@ -55,6 +97,10 @@
 void 
 DebugComponent::Enable (void)
 {
+  if (g_firstDebug) {
+    DebugComponentEnableEnvVar ();
+    g_firstDebug = false;
+  }
   m_isEnabled = true;
 }
 void 
@@ -92,30 +138,6 @@
     }  
 }
 
-void
-DebugComponentEnableEnvVar (void)
-{
-#ifdef HAVE_GETENV
-  char *envVar = getenv("NS3_DEBUG");
-  if (envVar == 0)
-    {
-      return;
-    }
-  std::string env = envVar;
-  std::string::size_type cur = 0;
-  std::string::size_type next = 0;
-  while (true)
-    {
-      next = env.find_first_of (";", cur);
-      if (next == std::string::npos) 
-	{
-	  std::string tmp = env.substr (cur, next);
-	  DebugComponentEnable (tmp.c_str ());
-	}
-      cur = next;
-    }
-#endif
-}
 
 void 
 DebugComponentPrintList (void)
--- a/src/core/debug.h	Tue Feb 06 20:40:38 2007 +0100
+++ b/src/core/debug.h	Tue Feb 06 21:42:31 2007 +0100
@@ -28,7 +28,6 @@
 
 void DebugComponentEnable (char const *name);
 void DebugComponentDisable (char const *name);
-void DebugComponentEnableEnvVar (void);
 void DebugComponentPrintList (void);
 
 class DebugComponent {