From Eric Sokolowsky, added writeEnvironmentSettings to help report what OSG

centric environment variables are used.
This commit is contained in:
Robert Osfield
2005-11-03 10:01:09 +00:00
parent 4c13328d98
commit eb28f9f587
2 changed files with 38 additions and 0 deletions

View File

@@ -84,6 +84,8 @@ class OSG_EXPORT ApplicationUsage
void write(std::ostream& output,unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80,bool showDefaults=false);
void writeEnvironmentSettings(std::ostream& output);
protected:
std::string _applicationName;

View File

@@ -209,3 +209,39 @@ void ApplicationUsage::write(std::ostream& output, unsigned int type, unsigned i
}
void ApplicationUsage::writeEnvironmentSettings(std::ostream& output)
{
output << "Current Environment Settings:"<<std::endl;
unsigned int maxNumCharsInOptions = 0;
ApplicationUsage::UsageMap::const_iterator citr;
for(citr=getEnvironmentalVariables().begin();
citr!=getEnvironmentalVariables().end();
++citr)
{
std::string::size_type len = citr->first.find_first_of("\n\r\t ");
if (len == std::string::npos) len = citr->first.size();
maxNumCharsInOptions = maximum(maxNumCharsInOptions,len);
}
unsigned int optionPos = 2;
std::string line;
for(citr=getEnvironmentalVariables().begin();
citr!=getEnvironmentalVariables().end();
++citr)
{
line.assign(optionPos+maxNumCharsInOptions+2,' ');
std::string::size_type len = citr->first.find_first_of("\n\r\t ");
if (len == std::string::npos) len = citr->first.size();
line.replace(optionPos,len,citr->first.substr(0,len));
char *cp = getenv(citr->first.substr(0, len).c_str());
if (!cp) cp = "[not set]";
else if (!*cp) cp = "[set]";
line += std::string(cp) + "\n";
output << line;
}
output << std::endl;
}