diff --git a/bin/debugger.cpp b/bin/debugger.cpp index 91016aa..7c18797 100644 --- a/bin/debugger.cpp +++ b/bin/debugger.cpp @@ -46,7 +46,7 @@ namespace { AddressMap wbrkMap; // write breaks. ToolMap tbrkMap; // tool breaks. - std::unordered_map toolMap; + std::unordered_map envMap; void hexdump(const uint8_t *data, ssize_t size, uint32_t address = 0) @@ -760,19 +760,13 @@ void SetXRegister(unsigned reg, uint32_t value) } -uint16_t TrapNumber(const std::string &s) +uint32_t EnvLookup(const std::string &s) { - auto iter = toolMap.find(s); - if (iter == toolMap.end()) return 0; + auto iter = envMap.find(s); + if (iter == envMap.end()) return 0; return iter->second; } -uint16_t TrapNumber(const char *cp) -{ - if (!cp || !*cp) return 0; - std::string s(cp); - return TrapNumber(s); -} // TODO -- RUN command - reload, re-initialize, re-execute @@ -783,12 +777,7 @@ void Shell() add_history("!Andy, it still has history!"); - { - // load the tool trap file. - std::string path = MPW::RootDir(); - path += "/Traps.text"; - toolMap = LoadTrapFile(path); - } + envMap = LoadTrapFile(MPW::RootDirPathForFile("Traps.text")); // start it up printf("MPW Debugger shell\n\n"); diff --git a/bin/debugger.h b/bin/debugger.h index 06852bc..06e9528 100644 --- a/bin/debugger.h +++ b/bin/debugger.h @@ -28,10 +28,9 @@ struct Command { bool ParseLine(const char *iter, Command *command); -std::unordered_map LoadTrapFile(const std::string &path); +std::unordered_map LoadTrapFile(const std::string &path); -uint16_t TrapNumber(const std::string &); -uint16_t TrapNumber(const char *); +uint32_t EnvLookup(const std::string &); void Shell(); diff --git a/mpw/mpw.cpp b/mpw/mpw.cpp index c66b37a..3858642 100644 --- a/mpw/mpw.cpp +++ b/mpw/mpw.cpp @@ -100,6 +100,15 @@ namespace MPW return S_ISDIR(st.st_mode); } + std::string RootDirPathForFile(const std::string &file) + { + std::string dir(RootDir()); + if (dir.length() && dir.back() != '/') dir.push_back('/'); + dir.append(file); + + return dir; + } + const std::string RootDir() { static bool initialized = false; @@ -305,10 +314,8 @@ namespace MPW void LoadEnvironment(std::string &envfile, std::unordered_map &env); - if (m.back() != '/') m.push_back('/'); - m.append("Environment"); - - LoadEnvironment(m, env); + std::string path(RootDirPathForFile("Environment.text")); + LoadEnvironment(path, env); } std::deque e; diff --git a/mpw/mpw.h b/mpw/mpw.h index 5a56611..9335c02 100644 --- a/mpw/mpw.h +++ b/mpw/mpw.h @@ -93,6 +93,7 @@ namespace MPW { const std::string RootDir(); + std::string RootDirPathForFile(const std::string &file); // should add argc/argv/envp... uint16_t Init(int argc, char **argv);