diff --git a/ml_util.cpp b/ml_util.cpp index 2d9924c..006daff 100644 --- a/ml_util.cpp +++ b/ml_util.cpp @@ -3,6 +3,7 @@ #include #include +#include const std::vector commands { "eval", "type", "parse", "do", "if", "for", "while", "scope", "quote", "defn", @@ -17,12 +18,11 @@ const std::vector commands { }; std::string get_history_file_dir() { - // TODO not portable and in function - std::string file{"/.ml_history.txt"}; + std::string filename{".ml_history.txt"}; const char *t = std::getenv("HOME"); - if (t == nullptr) return "/tmp/" + file; - else return std::string{t} + "/" + file; + if (t == nullptr) return std::filesystem::temp_directory_path() / filename; + else return std::filesystem::path(std::string{t}) /filename; } MlEnvironment * repl_env = nullptr; @@ -68,7 +68,7 @@ void completion(const char *buf, linenoiseCompletions *lc) { std::string token = str.substr(pos+1); std::string begining = str.substr(0, pos+1); - // TODO optimize not to get all lambdas, but those beginning with token + // PERF optimize not to get all lambdas, but those beginning with token std::vector lambdas = repl_env->get_lambdas_list(); lambdas.insert(end(lambdas), begin(commands), end(commands));