From fed6e9b17258ad7662645525ddcfd4de70ab8f73 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 4 Dec 2014 16:42:49 -0500 Subject: [PATCH] don't expand $[a-z]+ in filenames. This was preventing lcc from working properly as it created temporary files named $defout$, etc. --- mpw/environment.rl | 18 ++++++++++++------ mpw/mpw.h | 2 +- toolbox/pathnames.rl | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mpw/environment.rl b/mpw/environment.rl index 6e9a7d7..233889e 100644 --- a/mpw/environment.rl +++ b/mpw/environment.rl @@ -34,7 +34,7 @@ namespace MPW { extern std::unordered_map Environment; - std::string ExpandVariables(const std::string &s); + std::string ExpandVariables(const std::string &s, bool pathname = false); } namespace { @@ -102,11 +102,17 @@ namespace { }; # backwards compatibility. + # lcc generates temporary files named $xxx$ + # so don't replace in pathnames. '$' [A-Za-z0-9_]+ { - std::string name(ts + 1, te); - auto iter = Environment.find(name); - if (iter != Environment.end()) - rv.append(iter->second); + if (pathname) { + rv.append(ts, te); + } else { + std::string name(ts + 1, te); + auto iter = Environment.find(name); + if (iter != Environment.end()) + rv.append(iter->second); + } }; any { @@ -215,7 +221,7 @@ namespace MPW { return iter->second; } - std::string ExpandVariables(const std::string &s) + std::string ExpandVariables(const std::string &s, bool pathname) { if (s.find_first_of("{$") == s.npos) return s; diff --git a/mpw/mpw.h b/mpw/mpw.h index 2c3d306..94b0a6d 100644 --- a/mpw/mpw.h +++ b/mpw/mpw.h @@ -97,7 +97,7 @@ namespace MPW { std::string RootDirPathForFile(const std::string &file); std::string GetEnv(const std::string &); - std::string ExpandVariables(const std::string &s); + std::string ExpandVariables(const std::string &s, bool pathname = false); // should add argc/argv/envp... diff --git a/toolbox/pathnames.rl b/toolbox/pathnames.rl index 25630ae..96c9a5e 100644 --- a/toolbox/pathnames.rl +++ b/toolbox/pathnames.rl @@ -127,7 +127,7 @@ namespace ToolBox #ifndef TESTING if (path.find_first_of("${") != path.npos) { - path = MPW::ExpandVariables(path); + path = MPW::ExpandVariables(path, true); } #endif