2016-10-30 18:24:19 +01:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2015-08-17 11:37:30 +02:00
|
|
|
#include "cmCLocaleEnvironmentScope.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
2016-10-30 18:24:19 +01:00
|
|
|
#include <utility>
|
2015-08-17 11:37:30 +02:00
|
|
|
|
2020-02-01 23:06:01 +01:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
2015-08-17 11:37:30 +02:00
|
|
|
cmCLocaleEnvironmentScope::cmCLocaleEnvironmentScope()
|
|
|
|
{
|
|
|
|
this->SetEnv("LANGUAGE", "");
|
|
|
|
this->SetEnv("LC_MESSAGES", "C");
|
|
|
|
|
|
|
|
std::string lcAll = this->GetEnv("LC_ALL");
|
|
|
|
|
2016-07-09 11:21:54 +02:00
|
|
|
if (!lcAll.empty()) {
|
2015-08-17 11:37:30 +02:00
|
|
|
this->SetEnv("LC_ALL", "");
|
|
|
|
this->SetEnv("LC_CTYPE", lcAll);
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2015-08-17 11:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmCLocaleEnvironmentScope::GetEnv(std::string const& key)
|
|
|
|
{
|
2016-10-30 18:24:19 +01:00
|
|
|
std::string value;
|
|
|
|
cmSystemTools::GetEnv(key, value);
|
|
|
|
return value;
|
2015-08-17 11:37:30 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 11:21:54 +02:00
|
|
|
void cmCLocaleEnvironmentScope::SetEnv(std::string const& key,
|
|
|
|
std::string const& value)
|
2015-08-17 11:37:30 +02:00
|
|
|
{
|
|
|
|
std::string oldValue = this->GetEnv(key);
|
|
|
|
|
|
|
|
this->EnvironmentBackup.insert(std::make_pair(key, oldValue));
|
|
|
|
|
2016-07-09 11:21:54 +02:00
|
|
|
if (value.empty()) {
|
2015-08-17 11:37:30 +02:00
|
|
|
cmSystemTools::UnsetEnv(key.c_str());
|
2016-07-09 11:21:54 +02:00
|
|
|
} else {
|
2016-10-30 18:24:19 +01:00
|
|
|
std::ostringstream tmp;
|
2015-08-17 11:37:30 +02:00
|
|
|
tmp << key << "=" << value;
|
|
|
|
cmSystemTools::PutEnv(tmp.str());
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2015-08-17 11:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cmCLocaleEnvironmentScope::~cmCLocaleEnvironmentScope()
|
|
|
|
{
|
2018-01-26 17:06:56 +01:00
|
|
|
for (auto const& envb : this->EnvironmentBackup) {
|
2016-10-30 18:24:19 +01:00
|
|
|
std::ostringstream tmp;
|
2018-01-26 17:06:56 +01:00
|
|
|
tmp << envb.first << "=" << envb.second;
|
2015-08-17 11:37:30 +02:00
|
|
|
cmSystemTools::PutEnv(tmp.str());
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2015-08-17 11:37:30 +02:00
|
|
|
}
|