Modified parse_util.cpp, parser.cpp, path.cpp to use env_get_string()

This commit is contained in:
Siteshwar Vashisht
2012-01-12 22:56:53 +05:30
parent 3bb4d0b276
commit 943cc68f54
3 changed files with 21 additions and 15 deletions

View File

@@ -800,7 +800,7 @@ int parse_util_load( const wcstring &cmd,
void (*on_load)(const wchar_t *cmd), void (*on_load)(const wchar_t *cmd),
int reload ) int reload )
{ {
wchar_t *path_var; wcstring path_var;
int res; int res;
int c, c2; int c, c2;
@@ -811,12 +811,12 @@ int parse_util_load( const wcstring &cmd,
// debug( 0, L"Autoload %ls in %ls", cmd, path_var_name ); // debug( 0, L"Autoload %ls in %ls", cmd, path_var_name );
parse_util_autounload( path_var_name.c_str(), cmd.c_str(), on_load ); parse_util_autounload( path_var_name.c_str(), cmd.c_str(), on_load );
path_var = env_get( path_var_name.c_str() ); path_var = env_get_string( path_var_name.c_str() );
/* /*
Do we know where to look? Do we know where to look?
*/ */
if( !path_var ) if( path_var.empty() )
{ {
return 0; return 0;
} }
@@ -856,9 +856,9 @@ int parse_util_load( const wcstring &cmd,
We have never tried to autoload using this path name before, We have never tried to autoload using this path name before,
set up initial data set up initial data
*/ */
// debug( 0, L"Create brand new autoload_t for %ls->%ls", path_var_name, path_var ); // debug( 0, L"Create brand new autoload_t for %ls->%ls", path_var_name, path_var.c_str() );
loaded = &all_loaded_map[path_var_name]; loaded = &all_loaded_map[path_var_name];
loaded->old_path = path_var; loaded->old_path = wcsdup(path_var.c_str());
} }
std::vector<wcstring> path_list; std::vector<wcstring> path_list;

View File

@@ -2043,7 +2043,9 @@ static int parse_job( process_t *p,
} }
else if(cmd[0]==L'$') else if(cmd[0]==L'$')
{ {
wchar_t *val = env_get( cmd+1 );
const wcstring val_wstr = env_get_string( cmd+1 );
const wchar_t *val = val_wstr.empty()?NULL:val_wstr.c_str();
if( val ) if( val )
{ {
debug( 0, debug( 0,

View File

@@ -130,7 +130,7 @@ bool path_get_path_string(const wcstring &cmd_str, wcstring &output, const env_v
wchar_t *path_get_path( void *context, const wchar_t *cmd ) wchar_t *path_get_path( void *context, const wchar_t *cmd )
{ {
wchar_t *path; const wchar_t *path;
int err = ENOENT; int err = ENOENT;
@@ -166,7 +166,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
} }
else else
{ {
path = env_get(L"PATH"); const wcstring path_wstr = env_get_string(L"PATH");
path = path_wstr.empty()?NULL:path_wstr.c_str();
if( path == 0 ) if( path == 0 )
{ {
if( contains( PREFIX L"/bin", L"/bin", L"/usr/bin" ) ) if( contains( PREFIX L"/bin", L"/bin", L"/usr/bin" ) )
@@ -189,7 +190,7 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
its arguments its arguments
*/ */
wchar_t *path_cpy = wcsdup( path ); wchar_t *path_cpy = wcsdup( path );
wchar_t *nxt_path = path; const wchar_t *nxt_path = path;
wchar_t *state; wchar_t *state;
if( (new_cmd==0) || (path_cpy==0) ) if( (new_cmd==0) || (path_cpy==0) )
@@ -356,20 +357,21 @@ wchar_t *path_get_cdpath( void *context, const wchar_t *dir )
} }
else else
{ {
wchar_t *path; const wchar_t *path;
wchar_t *path_cpy; wchar_t *path_cpy;
wchar_t *nxt_path; wchar_t *nxt_path;
wchar_t *state; wchar_t *state;
wchar_t *whole_path; wchar_t *whole_path;
path = env_get(L"CDPATH"); const wcstring path_wstr = env_get_string(L"CDPATH");
path = path_wstr.empty()?NULL:path_wstr.c_str();
if( !path || !wcslen(path) ) if( !path || !wcslen(path) )
{ {
path = L"."; path = L".";
} }
nxt_path = path; nxt_path = const_cast<wchar_t*>(path);
path_cpy = wcsdup( path ); path_cpy = wcsdup( path );
if( !path_cpy ) if( !path_cpy )
@@ -437,11 +439,12 @@ wchar_t *path_get_cdpath( void *context, const wchar_t *dir )
wchar_t *path_get_config( void *context) wchar_t *path_get_config( void *context)
{ {
wchar_t *xdg_dir, *home; const wchar_t *xdg_dir, *home;
int done = 0; int done = 0;
wchar_t *res = 0; wchar_t *res = 0;
xdg_dir = env_get( L"XDG_CONFIG_HOME" ); const wcstring xdg_dir_wstr = env_get_string( L"XDG_CONFIG_HOME" );
xdg_dir = xdg_dir_wstr.empty()?NULL:xdg_dir_wstr.c_str();
if( xdg_dir ) if( xdg_dir )
{ {
res = wcsdupcat( xdg_dir, L"/fish" ); res = wcsdupcat( xdg_dir, L"/fish" );
@@ -457,7 +460,8 @@ wchar_t *path_get_config( void *context)
} }
else else
{ {
home = env_get( L"HOME" ); const wcstring home_wstr = env_get_string( L"HOME" );
home = home_wstr.empty()?NULL:home_wstr.c_str();
if( home ) if( home )
{ {
res = wcsdupcat( home, L"/.config/fish" ); res = wcsdupcat( home, L"/.config/fish" );