use a single $MPW environment for the root

This commit is contained in:
Kelvin Sherlock 2013-02-18 19:17:17 -05:00
parent 3300006953
commit 4e247a0c46
2 changed files with 132 additions and 5 deletions

View File

@ -652,14 +652,29 @@ bool file_exists(const std::string & name)
std::string find_exe(const std::string &name)
{
std::string path;
std::string subpath;
if (file_exists(name)) return name;
// if name is a path, then it doesn't exist.
if (name.find('/') != name.npos) return std::string();
const char *mpw = getenv("MPW");
if (!mpw || !*mpw) return std::string();
std::string path(mpw);
if (path.back() != '/') path.push_back('/');
path.append("Tools/");
path.append(name);
if (file_exists(path)) return path;
return std::string();
#if 0
std::string subpath;
// check in $MPW/name.
const char *cpath = getenv("mpw_path");
if (!cpath) return std::string();
@ -696,6 +711,7 @@ std::string find_exe(const std::string &name)
}
return std::string();
#endif
}
@ -808,9 +824,9 @@ int main(int argc, char **argv)
command = find_exe(command);
if (command.empty())
{
const char *path = getenv("mpw_path");
const char *mpw = getenv("MPW");
fprintf(stderr, "Unable to find command %s\n", argv[0]);
fprintf(stderr, "mpw_path = %s\n", path ? path : "<null>");
fprintf(stderr, "$MPW = %s\n", mpw ? mpw : "<null>");
exit(EX_USAGE);
}
argv[0] = ::strdup(command.c_str()); // hmm.. could setenv(mpw_command) instead.

View File

@ -164,6 +164,115 @@ namespace MPW
}
// environment,
// just use $MPW and synthesize the other ones.
{
std::deque<std::string> e;
{
// command name (includes path)
// asm iigs stores error text in the data fork,
// using {Command} to access it.
std::string tmp;
tmp.append("Command");
tmp.push_back(0);
tmp.append(command);
e.emplace_back(std::move(tmp));
}
const char *mpw = getenv("MPW");
if (mpw && *mpw)
{
std::string tmp;
std::string root(mpw);
std::replace(root.begin(), root.end(), '/', ':');
if (root.back() != ':') root.push_back(':');
tmp = "MPW";
tmp.push_back(0);
tmp.append(root);
e.emplace_back(std::move(tmp));
tmp = "AIIGSIncludes";
tmp.push_back(0);
tmp.append(root);
tmp.append("Interfaces:AIIGSIncludes:");
e.emplace_back(std::move(tmp));
tmp = "RIIGSIncludes";
tmp.append(root);
tmp.append("Interfaces:RIIGSIncludes:");
e.emplace_back(std::move(tmp));
tmp = "CIIGSIncludes";
tmp.push_back(0);
tmp.append(root);
tmp.append("Interfaces:CIIGSIncludes:");
e.emplace_back(std::move(tmp));
tmp = "CIIGSLibraries";
tmp.push_back(0);
tmp.append(root);
tmp.append("Libraries:CIIGSIncludes:");
e.emplace_back(std::move(tmp));
tmp = "PIIGSIncludes";
tmp.push_back(0);
tmp.append(root);
tmp.append("Interfaces:PIIGSIncludes:");
e.emplace_back(std::move(tmp));
tmp = "PIIGSLibraries";
tmp.push_back(0);
tmp.append(root);
tmp.append("Libraries:PIIGSIncludes:");
e.emplace_back(std::move(tmp));
}
uint32_t size = 0;
for(const std::string &s : e)
{
int l = s.length() + 1;
if (l & 0x01) l++;
size = size + l + 4;
}
size += 4; // space for null terminator.
error = MM::Native::NewPtr(size, true, envptr);
if (error) return error;
uint8_t *xptr = memoryPointer(envptr);
uint32_t offset = 0;
offset = 4 * (e.size() + 1);
unsigned i = 0;
for (const std::string &s : e)
{
// ptr
memoryWriteLong(envptr + offset, envptr + i * 4);
int l = s.length() + 1;
std::memcpy(xptr + offset, s.c_str(), l);
if (l & 0x01) l++;
offset += l;
++i;
}
// null-terminate it.
memoryWriteLong(0, envptr + 4 * e.size());
}
#if 0
// do the same for envp.
// mpw_* variables in the native environment are imported.
// values are stored as key\0value\0, not key=value\0
@ -238,6 +347,8 @@ namespace MPW
// null-terminate it.
memoryWriteLong(0, envptr + 4 * e.size());
}
#endif
// ftable
{