2015-04-09 21:56:43 +03:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2015 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmCLocaleEnvironmentScope.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
cmCLocaleEnvironmentScope::cmCLocaleEnvironmentScope()
|
|
|
|
{
|
|
|
|
this->SetEnv("LANGUAGE", "");
|
|
|
|
this->SetEnv("LC_MESSAGES", "C");
|
|
|
|
|
|
|
|
std::string lcAll = this->GetEnv("LC_ALL");
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!lcAll.empty()) {
|
2015-04-09 21:56:43 +03:00
|
|
|
this->SetEnv("LC_ALL", "");
|
|
|
|
this->SetEnv("LC_CTYPE", lcAll);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-04-09 21:56:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCLocaleEnvironmentScope::GetEnv(std::string const& key)
|
|
|
|
{
|
|
|
|
const char* value = cmSystemTools::GetEnv(key);
|
|
|
|
return value ? value : std::string();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmCLocaleEnvironmentScope::SetEnv(std::string const& key,
|
|
|
|
std::string const& value)
|
2015-04-09 21:56:43 +03:00
|
|
|
{
|
|
|
|
std::string oldValue = this->GetEnv(key);
|
|
|
|
|
|
|
|
this->EnvironmentBackup.insert(std::make_pair(key, oldValue));
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (value.empty()) {
|
2015-04-09 21:56:43 +03:00
|
|
|
cmSystemTools::UnsetEnv(key.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-04-09 21:56:43 +03:00
|
|
|
std::stringstream tmp;
|
|
|
|
tmp << key << "=" << value;
|
|
|
|
cmSystemTools::PutEnv(tmp.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-04-09 21:56:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmCLocaleEnvironmentScope::~cmCLocaleEnvironmentScope()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
for (backup_map_t::const_iterator i = this->EnvironmentBackup.begin();
|
|
|
|
i != this->EnvironmentBackup.end(); ++i) {
|
2015-04-09 21:56:43 +03:00
|
|
|
std::stringstream tmp;
|
|
|
|
tmp << i->first << "=" << i->second;
|
|
|
|
cmSystemTools::PutEnv(tmp.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-04-09 21:56:43 +03:00
|
|
|
}
|