From 8232857d0785b5b2db8884d11680de5c2fe9b857 Mon Sep 17 00:00:00 2001 From: Siteshwar Vashisht Date: Fri, 24 Feb 2012 00:55:46 +0530 Subject: Modified env_get_string() to accept wcstring instead of wchar_t*. --- autoload.cpp | 2 +- builtin_set.cpp | 2 +- complete.cpp | 2 +- env.cpp | 13 ++++++------- env.h | 2 +- env_universal.cpp | 4 +--- env_universal.h | 2 +- env_universal_common.cpp | 2 +- env_universal_common.h | 2 +- 9 files changed, 14 insertions(+), 17 deletions(-) diff --git a/autoload.cpp b/autoload.cpp index dd3dafbf..e214acb0 100644 --- a/autoload.cpp +++ b/autoload.cpp @@ -75,7 +75,7 @@ int autoload_t::load( const wcstring &cmd, bool reload ) /* Do some work while locked, including determing the path variable */ { scoped_lock locker(lock); - path_var = env_get_string( env_var_name.c_str() ); + path_var = env_get_string( env_var_name ); /* Do we know where to look? diff --git a/builtin_set.cpp b/builtin_set.cpp index 1f64cb01..c46be8b1 100644 --- a/builtin_set.cpp +++ b/builtin_set.cpp @@ -316,7 +316,7 @@ static void print_variables(int include_values, int esc, int scope) if( include_values ) { - env_var_t value = env_get_string(key.c_str()); + env_var_t value = env_get_string(key); if( !value.missing() ) { int shorten = 0; diff --git a/complete.cpp b/complete.cpp index ee348d07..78282cc7 100644 --- a/complete.cpp +++ b/complete.cpp @@ -1422,7 +1422,7 @@ static int complete_variable( const wchar_t *whole_var, if( match || match_no_case ) { - const env_var_t value_unescaped = env_get_string( env_name.c_str() ); + const env_var_t value_unescaped = env_get_string( env_name ); if( !value_unescaped.missing() ) { wcstring comp; diff --git a/env.cpp b/env.cpp index e2e380a8..82547116 100644 --- a/env.cpp +++ b/env.cpp @@ -1076,12 +1076,11 @@ const wchar_t *env_var_t::c_str(void) const { return wcstring::c_str(); } -env_var_t env_get_string( const wchar_t *key ) +env_var_t env_get_string( const wcstring &key ) { scoped_lock lock(env_lock); - CHECK( key, 0 ); - if( wcscmp( key, L"history" ) == 0 ) + if( key == L"history" ) { wcstring result; const wchar_t *current; @@ -1113,19 +1112,19 @@ env_var_t env_get_string( const wchar_t *key ) return result; } - else if( wcscmp( key, L"COLUMNS" )==0 ) + else if( key == L"COLUMNS" ) { return format_val((long)common_get_width()); } - else if( wcscmp( key, L"LINES" )==0 ) + else if( key == L"LINES" ) { return format_val((long)common_get_width()); } - else if( wcscmp( key, L"status" )==0 ) + else if( key == L"status" ) { return format_val((long)proc_get_last_status()); } - else if( wcscmp( key, L"umask" )==0 ) + else if( key == L"umask" ) { return format_string(L"0%0.3o", get_umask() ); } diff --git a/env.h b/env.h index a5ac97b4..acef82a6 100644 --- a/env.h +++ b/env.h @@ -116,7 +116,7 @@ public: /** Gets the variable with the specified name, or an empty string if it does not exist. */ -env_var_t env_get_string( const wchar_t *key ); +env_var_t env_get_string( const wcstring &key ); /** Returns 1 if the specified key exists. This can't be reliably done diff --git a/env_universal.cpp b/env_universal.cpp index 94e592a1..fef32fe7 100644 --- a/env_universal.cpp +++ b/env_universal.cpp @@ -318,13 +318,11 @@ int env_universal_read_all() } } -wchar_t *env_universal_get( const wchar_t *name ) +wchar_t *env_universal_get( const wcstring &name ) { if( !init) return 0; - CHECK( name, 0 ); - return env_universal_common_get( name ); } diff --git a/env_universal.h b/env_universal.h index 435fc4b7..fc05741d 100644 --- a/env_universal.h +++ b/env_universal.h @@ -29,7 +29,7 @@ void env_universal_destroy(); /** Get the value of a universal variable */ -wchar_t *env_universal_get( const wchar_t *name ); +wchar_t *env_universal_get( const wcstring &name ); /** Get the export flag of the variable with the specified diff --git a/env_universal_common.cpp b/env_universal_common.cpp index d7dea877..9098121d 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -896,7 +896,7 @@ void env_universal_common_get_names( wcstring_list_t &lst, } -wchar_t *env_universal_common_get( const wchar_t *name ) +wchar_t *env_universal_common_get( const wcstring &name ) { std::map::const_iterator result = env_universal_var.find(name); diff --git a/env_universal_common.h b/env_universal_common.h index 908c5bae..c6c1d74e 100644 --- a/env_universal_common.h +++ b/env_universal_common.h @@ -181,7 +181,7 @@ void env_universal_common_remove( const wcstring &key ); This function operate agains the local copy of all universal variables, it does not communicate with any other process. */ -wchar_t *env_universal_common_get( const wchar_t *name ); +wchar_t *env_universal_common_get( const wcstring &name ); /** Get the export flag of the variable with the specified -- cgit v1.2.3