Permalink
Browse files

Clean up env_var_table_t. Switch from storing var_uni_entry_t* to var…

…_uni_entry_t. Various other cleanups.
  • Loading branch information...
1 parent be23c07 commit 2a7fc9c3a507de45e1aa723068fb373567b869a1 @ridiculousfish ridiculousfish committed Feb 12, 2013
Showing with 106 additions and 127 deletions.
  1. +6 −13 env.cpp
  2. +39 −7 env.h
  3. +19 −20 env_universal.cpp
  4. +4 −4 env_universal.h
  5. +16 −45 env_universal_common.cpp
  6. +1 −6 env_universal_common.h
  7. +12 −23 fishd.cpp
  8. +1 −1 reader.cpp
  9. +8 −8 reader.h
View
19 env.cpp
@@ -1029,13 +1029,6 @@ int env_remove(const wcstring &key, int var_mode)
return !erased;
}
-env_var_t env_var_t::missing_var(void)
-{
- env_var_t result(L"");
- result.is_missing = true;
- return result;
-}
-
const wchar_t *env_var_t::c_str(void) const
{
assert(! is_missing);
@@ -1119,7 +1112,7 @@ env_var_t env_get_string(const wcstring &key)
env_universal_barrier();
}
- wchar_t *item = env_universal_get(key);
+ const wchar_t *item = env_universal_get(key);
if (!item || (wcscmp(item, ENV_NULL)==0))
{
@@ -1135,7 +1128,7 @@ env_var_t env_get_string(const wcstring &key)
bool env_exist(const wchar_t *key, int mode)
{
env_node_t *env;
- wchar_t *item=0;
+ const wchar_t *item = NULL;
CHECK(key, false);
@@ -1387,9 +1380,9 @@ wcstring_list_t env_get_names(int flags)
{
wcstring_list_t uni_list;
- env_universal_get_names2(uni_list,
- show_exported,
- show_unexported);
+ env_universal_get_names(uni_list,
+ show_exported,
+ show_unexported);
names.insert(uni_list.begin(), uni_list.end());
}
@@ -1472,7 +1465,7 @@ static void update_export_array_if_necessary(bool recalc)
get_exported(top, vals);
wcstring_list_t uni;
- env_universal_get_names2(uni, 1, 0);
+ env_universal_get_names(uni, 1, 0);
for (i=0; i<uni.size(); i++)
{
const wcstring &key = uni.at(i);
View
46 env.h
@@ -108,20 +108,31 @@ class env_var_t : public wcstring
private:
bool is_missing;
public:
- static env_var_t missing_var(void);
+ static env_var_t missing_var(void)
+ {
+ env_var_t result(L"");
+ result.is_missing = true;
+ return result;
+
+ }
+
env_var_t(const env_var_t &x) : wcstring(x), is_missing(x.is_missing) { }
env_var_t(const wcstring & x) : wcstring(x), is_missing(false) { }
env_var_t(const wchar_t *x) : wcstring(x), is_missing(false) { }
env_var_t() : wcstring(L""), is_missing(false) { }
+
bool missing(void) const
{
return is_missing;
}
+
bool missing_or_empty(void) const
{
return missing() || empty();
}
+
const wchar_t *c_str(void) const;
+
env_var_t &operator=(const env_var_t &s)
{
is_missing = s.is_missing;
@@ -131,14 +142,35 @@ class env_var_t : public wcstring
bool operator==(const env_var_t &s) const
{
- if (is_missing && s.is_missing)
- return true;
- else if (s.is_missing || s.is_missing)
- return false;
- else
- return *static_cast<const wcstring *>(this) == *static_cast<const wcstring *>(&s);
+ return is_missing == s.is_missing && static_cast<const wcstring &>(*this) == static_cast<const wcstring &>(s);
+ }
+
+ bool operator==(const wcstring &s) const
+ {
+ return ! is_missing && static_cast<const wcstring &>(*this) == s;
+ }
+
+ bool operator!=(const env_var_t &s) const
+ {
+ return !(*this == s);
+ }
+
+ bool operator!=(const wcstring &s) const
+ {
+ return !(*this == s);
+ }
+
+ bool operator==(const wchar_t *s) const
+ {
+ return ! is_missing && static_cast<const wcstring &>(*this) == s;
+ }
+
+ bool operator!=(const wchar_t *s) const
+ {
+ return !(*this == s);
}
+
};
/**
Gets the variable with the specified name, or an empty string if it does not exist.
View
@@ -49,9 +49,9 @@
connection_t env_universal_server;
/**
- Set to 1 after initialization has been performed
+ Set to true after initialization has been performed
*/
-static int init = 0;
+static bool s_env_univeral_inited = false;
/**
The number of attempts to start fishd
@@ -207,7 +207,7 @@ static void callback(fish_message_type_t type, const wchar_t *name, const wchar_
*/
static void check_connection()
{
- if (!init)
+ if (! s_env_univeral_inited)
return;
if (env_universal_server.killme)
@@ -258,10 +258,10 @@ static void reconnect()
debug(3, L"Get new fishd connection");
- init = 0;
+ s_env_univeral_inited = false;
env_universal_server.buffer_consumed = env_universal_server.buffer_used = 0;
env_universal_server.fd = get_socket();
- init = 1;
+ s_env_univeral_inited = true;
if (env_universal_server.fd >= 0)
{
env_universal_remove_all();
@@ -285,7 +285,7 @@ void env_universal_init(wchar_t * p,
env_universal_server.fd = get_socket();
env_universal_common_init(&callback);
env_universal_read_all();
- init = 1;
+ s_env_univeral_inited = true;
if (env_universal_server.fd >= 0)
{
env_universal_barrier();
@@ -308,8 +308,7 @@ void env_universal_destroy()
connection_destroy(&env_universal_server);
env_universal_server.fd =-1;
- env_universal_common_destroy();
- init = 0;
+ s_env_univeral_inited = false;
}
@@ -318,7 +317,7 @@ void env_universal_destroy()
*/
int env_universal_read_all()
{
- if (!init)
+ if (! s_env_univeral_inited)
return 0;
if (env_universal_server.fd == -1)
@@ -341,17 +340,17 @@ int env_universal_read_all()
}
}
-wchar_t *env_universal_get(const wcstring &name)
+const wchar_t *env_universal_get(const wcstring &name)
{
- if (!init)
- return 0;
+ if (!s_env_univeral_inited)
+ return NULL;
return env_universal_common_get(name);
}
bool env_universal_get_export(const wcstring &name)
{
- if (!init)
+ if (!s_env_univeral_inited)
return false;
return env_universal_common_get_export(name);
@@ -363,7 +362,7 @@ void env_universal_barrier()
message_t *msg;
fd_set fds;
- if (!init || is_dead())
+ if (!s_env_univeral_inited || is_dead())
return;
barrier_reply = 0;
@@ -424,7 +423,7 @@ void env_universal_set(const wcstring &name, const wcstring &value, bool exportv
{
message_t *msg;
- if (!init)
+ if (!s_env_univeral_inited)
return;
debug(3, L"env_universal_set( \"%ls\", \"%ls\" )", name.c_str(), value.c_str());
@@ -456,7 +455,7 @@ int env_universal_remove(const wchar_t *name)
int res;
message_t *msg;
- if (!init)
+ if (!s_env_univeral_inited)
return 1;
CHECK(name, 1);
@@ -481,11 +480,11 @@ int env_universal_remove(const wchar_t *name)
return res;
}
-void env_universal_get_names2(wcstring_list_t &lst,
- bool show_exported,
- bool show_unexported)
+void env_universal_get_names(wcstring_list_t &lst,
+ bool show_exported,
+ bool show_unexported)
{
- if (!init)
+ if (!s_env_univeral_inited)
return;
env_universal_common_get_names(lst,
View
@@ -29,7 +29,7 @@ void env_universal_destroy();
/**
Get the value of a universal variable
*/
-wchar_t *env_universal_get(const wcstring &name);
+const wchar_t *env_universal_get(const wcstring &name);
/**
Get the export flag of the variable with the specified
@@ -60,9 +60,9 @@ int env_universal_read_all();
\param show_exported whether exported variables should be shown
\param show_unexported whether unexported variables should be shown
*/
-void env_universal_get_names2(wcstring_list_t &list,
- bool show_exported,
- bool show_unexported);
+void env_universal_get_names(wcstring_list_t &list,
+ bool show_exported,
+ bool show_unexported);
/**
Synchronize with fishd
Oops, something went wrong.

0 comments on commit 2a7fc9c

Please sign in to comment.