MPW::GetEnvironment

This commit is contained in:
Kelvin Sherlock 2013-07-30 00:57:29 -04:00
parent fc04a2b2cb
commit 7a08004542
2 changed files with 19 additions and 5 deletions

View File

@ -63,6 +63,8 @@ namespace MPW { namespace Internal {
uint32_t MacProgramInfo = 0; uint32_t MacProgramInfo = 0;
std::unordered_map<std::string, std::string> Environment;
} } } }
@ -221,6 +223,16 @@ namespace MPW
} }
std::string GetEnv(const std::string &name)
{
static std::string empty;
auto iter = Environment.find(name);
if (iter == Environment.end()) return empty;
return iter->second;
}
uint16_t Init(int argc, char **argv) uint16_t Init(int argc, char **argv)
{ {
@ -323,7 +335,6 @@ namespace MPW
// environment, // environment,
// just use $MPW and synthesize the other ones. // just use $MPW and synthesize the other ones.
{ {
std::unordered_map<std::string, std::string> env;
std::string m(RootDir()); std::string m(RootDir());
if (!m.empty()) if (!m.empty())
@ -331,9 +342,9 @@ namespace MPW
std::string mm = ToolBox::UnixToMac(m); std::string mm = ToolBox::UnixToMac(m);
if (mm.back() != ':') mm.push_back(':'); if (mm.back() != ':') mm.push_back(':');
env.emplace(std::string("MPW"), mm); Environment.emplace(std::string("MPW"), mm);
} }
env.emplace(std::string("Command"), command); Environment.emplace(std::string("Command"), command);
if (!m.empty()) if (!m.empty())
{ {
@ -341,12 +352,12 @@ namespace MPW
void LoadEnvironment(std::string &envfile, std::unordered_map<std::string, std::string> &env); void LoadEnvironment(std::string &envfile, std::unordered_map<std::string, std::string> &env);
std::string path(RootDirPathForFile("Environment.text")); std::string path(RootDirPathForFile("Environment.text"));
LoadEnvironment(path, env); LoadEnvironment(path, Environment);
} }
std::deque<std::string> e; std::deque<std::string> e;
for (const auto &iter : env) for (const auto &iter : Environment)
{ {
std::string tmp; std::string tmp;
tmp.append(iter.first); tmp.append(iter.first);

View File

@ -95,6 +95,9 @@ namespace MPW {
const std::string RootDir(); const std::string RootDir();
std::string RootDirPathForFile(const std::string &file); std::string RootDirPathForFile(const std::string &file);
std::string GetEnv(const std::string &);
// should add argc/argv/envp... // should add argc/argv/envp...
uint16_t Init(int argc, char **argv); uint16_t Init(int argc, char **argv);