From c3b235ee95342880c7c538aa3c678353ec96f156 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 18 Jul 2016 21:53:16 -0400 Subject: [PATCH] load environment from the environment for mpw-shell compatibility. --- mpw/environment.rl | 22 ++++++++++++++++++++++ mpw/mpw.cpp | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/mpw/environment.rl b/mpw/environment.rl index ddc04dc..5797cab 100644 --- a/mpw/environment.rl +++ b/mpw/environment.rl @@ -32,6 +32,9 @@ #include #include +extern char **environ; + + namespace _env_rl { #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050 #define _GETDELIM_GROWBY 128 /* amount to grow line buffer by */ @@ -363,6 +366,25 @@ namespace MPW { } } + void EnvLoadEnv() { + /* load from environ */ + + for (unsigned i = 0; environ[i]; ++i) { + if (memcmp(environ[i], "mpw$", 4)) continue; + + std::string s(environ[i] + 4); + auto pos = s.find('='); + if (pos == 0) continue; + if (pos == s.npos) { + MPW::Environment.emplace(std::move(s), ""); + } else { + MPW::Environment.emplace(s.substr(0, pos), s.substr(pos+1)); + } + + } + + } + void EnvLoadFile(const std::string &envfile) { diff --git a/mpw/mpw.cpp b/mpw/mpw.cpp index 3659c55..a6f3a23 100644 --- a/mpw/mpw.cpp +++ b/mpw/mpw.cpp @@ -181,6 +181,8 @@ namespace MPW { void EnvLoadFile(const std::string &envfile); void EnvLoadArray(const std::vector &data); + void EnvLoadEnv(); + std::string m(RootDir()); if (!m.empty()) @@ -191,6 +193,8 @@ namespace MPW Environment.emplace(std::string("MPW"), mm); } + EnvLoadEnv(); // should do this first since it could set MPW?? + if (defines.size()) EnvLoadArray(defines);