2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2015-04-09 21:56:43 +03:00
|
|
|
#include "cmCLocaleEnvironmentScope.h"
|
|
|
|
|
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
2016-08-18 01:24:24 +03:00
|
|
|
#include <utility>
|
2015-04-09 21:56:43 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-07-08 00:54:05 +03:00
|
|
|
std::string value;
|
|
|
|
cmSystemTools::GetEnv(key, value);
|
|
|
|
return value;
|
2015-04-09 21:56:43 +03:00
|
|
|
}
|
|
|
|
|
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 {
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream tmp;
|
2015-04-09 21:56:43 +03:00
|
|
|
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) {
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream tmp;
|
2015-04-09 21:56:43 +03:00
|
|
|
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
|
|
|
}
|