diff --git a/src/core/debug.cc b/src/core/debug.cc index 11892bc4b..f2764eb89 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -35,6 +35,48 @@ typedef std::list > ComponentList; typedef std::list >::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 @@ DebugComponent::IsEnabled (void) void DebugComponent::Enable (void) { + if (g_firstDebug) { + DebugComponentEnableEnvVar (); + g_firstDebug = false; + } m_isEnabled = true; } void @@ -92,30 +138,6 @@ DebugComponentDisable (char const *name) } } -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) diff --git a/src/core/debug.h b/src/core/debug.h index e1b241824..7dbddda5e 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -28,7 +28,6 @@ namespace ns3 { void DebugComponentEnable (char const *name); void DebugComponentDisable (char const *name); -void DebugComponentEnableEnvVar (void); void DebugComponentPrintList (void); class DebugComponent {