From 7a080045420f2c0dc6dc7f637b860a137f606f36 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 30 Jul 2013 00:57:29 -0400 Subject: [PATCH] MPW::GetEnvironment --- mpw/mpw.cpp | 21 ++++++++++++++++----- mpw/mpw.h | 3 +++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/mpw/mpw.cpp b/mpw/mpw.cpp index fd1e075..054c194 100644 --- a/mpw/mpw.cpp +++ b/mpw/mpw.cpp @@ -63,6 +63,8 @@ namespace MPW { namespace Internal { uint32_t MacProgramInfo = 0; + std::unordered_map 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) { @@ -323,7 +335,6 @@ namespace MPW // environment, // just use $MPW and synthesize the other ones. { - std::unordered_map env; std::string m(RootDir()); if (!m.empty()) @@ -331,9 +342,9 @@ namespace MPW std::string mm = ToolBox::UnixToMac(m); 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()) { @@ -341,12 +352,12 @@ namespace MPW void LoadEnvironment(std::string &envfile, std::unordered_map &env); std::string path(RootDirPathForFile("Environment.text")); - LoadEnvironment(path, env); + LoadEnvironment(path, Environment); } std::deque e; - for (const auto &iter : env) + for (const auto &iter : Environment) { std::string tmp; tmp.append(iter.first); diff --git a/mpw/mpw.h b/mpw/mpw.h index 9335c02..c64c719 100644 --- a/mpw/mpw.h +++ b/mpw/mpw.h @@ -95,6 +95,9 @@ namespace MPW { const std::string RootDir(); std::string RootDirPathForFile(const std::string &file); + std::string GetEnv(const std::string &); + + // should add argc/argv/envp... uint16_t Init(int argc, char **argv);