aboutsummaryrefslogtreecommitdiffhomepage
path: root/env.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-20 22:11:05 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-20 22:11:05 -0700
commit261bf12c91286ffca9fcb0bf761d6d1666359dc7 (patch)
tree4b6d388843bad1aadae666fa8597c9f0d50488b0 /env.cpp
parentb08fb866378693d2e75f17fdfe5e60401a29136a (diff)
Lots of miscellaneous cleanup. Unified the path_get_cd_path, path_allocate_cd_path, etc. functions
Diffstat (limited to 'env.cpp')
-rw-r--r--env.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/env.cpp b/env.cpp
index 21e68228..fa168c60 100644
--- a/env.cpp
+++ b/env.cpp
@@ -1538,27 +1538,41 @@ void env_export_arr(bool recalc, null_terminated_array_t<char> &output)
env_vars_snapshot_t::env_vars_snapshot_t(const wchar_t * const *keys)
{
ASSERT_IS_MAIN_THREAD();
+ wcstring key;
for (size_t i=0; keys[i]; i++) {
- const env_var_t val = env_get_string(keys[i]);
- if (!val.missing()) {
- vars[keys[i]] = val;
+ key.assign(keys[i]);
+ const env_var_t val = env_get_string(key);
+ if (! val.missing()) {
+ vars[key] = val;
}
}
}
env_vars_snapshot_t::env_vars_snapshot_t() { }
-const wchar_t *env_vars_snapshot_t::get(const wchar_t *key) const
+/* The "current" variables are not a snapshot at all, but instead trampoline to env_get_string, etc. We identify the current snapshot based on pointer values. */
+static const env_vars_snapshot_t sCurrentSnapshot;
+const env_vars_snapshot_t &env_vars_snapshot_t::current()
{
- std::map<wcstring, wcstring>::const_iterator iter = vars.find(key);
- return (iter == vars.end() ? NULL : iter->second.c_str());
+ return sCurrentSnapshot;
}
-env_var_t env_vars_snapshot_t::get(const wcstring &key) const
+bool env_vars_snapshot_t::is_current() const
{
- std::map<wcstring, wcstring>::const_iterator iter = vars.find(key);
- return (iter == vars.end() ? env_var_t::missing_var() : env_var_t(iter->second));
+ return this == &sCurrentSnapshot;
}
-const wchar_t * const env_vars_snapshot_t::highlighting_keys[] = {L"PATH", L"CDPATH", L"HIGHLIGHT_DELAY", L"fish_function_path", NULL};
+env_var_t env_vars_snapshot_t::get(const wcstring &key) const
+{
+ /* If we represent the current state, bounce to env_get_string */
+ if (this->is_current())
+ {
+ return env_get_string(key);
+ }
+ else {
+ std::map<wcstring, wcstring>::const_iterator iter = vars.find(key);
+ return (iter == vars.end() ? env_var_t::missing_var() : env_var_t(iter->second));
+ }
+}
+const wchar_t * const env_vars_snapshot_t::highlighting_keys[] = {L"PATH", L"CDPATH", L"fish_function_path", NULL};