load environment from the environment for mpw-shell compatibility.

This commit is contained in:
Kelvin Sherlock 2016-07-18 21:53:16 -04:00
parent 51a86117b8
commit c3b235ee95
2 changed files with 26 additions and 0 deletions

View File

@ -32,6 +32,9 @@
#include <sys/types.h>
#include <limits.h>
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)
{

View File

@ -181,6 +181,8 @@ namespace MPW
{
void EnvLoadFile(const std::string &envfile);
void EnvLoadArray(const std::vector<std::string> &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);