Merge branch 'Use_env_get_string' into CPlusPlus

Conflicts:
	function.cpp
This commit is contained in:
Siteshwar Vashisht 2012-01-14 11:59:48 +05:30
commit 3ba6e9db5d
17 changed files with 413 additions and 139 deletions

View file

@ -2007,7 +2007,7 @@ static int builtin_read( wchar_t **argv )
{
wchar_t *buff=0;
int i, argc = builtin_count_args( argv );
const wchar_t *ifs;
wcstring ifs;
int place = ENV_USER;
wchar_t *nxt;
const wchar_t *prompt = DEFAULT_READ_PROMPT;
@ -2292,11 +2292,11 @@ static int builtin_read( wchar_t **argv )
wchar_t *state;
ifs = env_get( L"IFS" );
if( ifs == 0 )
ifs = env_get_string( L"IFS" );
if( ifs.empty() )
ifs = L"";
nxt = wcstok( buff, (i<argc-1)?ifs:L"", &state );
nxt = wcstok( buff, (i<argc-1)?ifs.c_str():L"", &state );
while( i<argc )
{
@ -2304,7 +2304,7 @@ static int builtin_read( wchar_t **argv )
i++;
if( nxt != 0 )
nxt = wcstok( 0, (i<argc-1)?ifs:L"", &state);
nxt = wcstok( 0, (i<argc-1)?ifs.c_str():L"", &state);
}
}
@ -2613,7 +2613,7 @@ static int builtin_exit( wchar_t **argv )
*/
static int builtin_cd( wchar_t **argv )
{
wchar_t *dir_in;
wcstring dir_in;
wchar_t *dir;
int res=STATUS_BUILTIN_OK;
void *context = halloc( 0, 0 );
@ -2621,8 +2621,8 @@ static int builtin_cd( wchar_t **argv )
if( argv[1] == 0 )
{
dir_in = env_get( L"HOME" );
if( !dir_in )
dir_in = env_get_string( L"HOME" );
if( dir_in.empty() )
{
sb_printf( sb_err,
_( L"%ls: Could not find home directory\n" ),
@ -2632,7 +2632,7 @@ static int builtin_cd( wchar_t **argv )
else
dir_in = argv[1];
dir = path_get_cdpath( context, dir_in );
dir = path_get_cdpath( context, dir_in.empty()?0:dir_in.c_str() );
if( !dir )
{
@ -2641,21 +2641,21 @@ static int builtin_cd( wchar_t **argv )
sb_printf( sb_err,
_( L"%ls: '%ls' is not a directory\n" ),
argv[0],
dir_in );
dir_in.c_str() );
}
else if( errno == ENOENT )
{
sb_printf( sb_err,
_( L"%ls: The directory '%ls' does not exist\n" ),
argv[0],
dir_in );
dir_in.c_str() );
}
else if( errno == EROTTEN )
{
sb_printf( sb_err,
_( L"%ls: '%ls' is a rotten symlink\n" ),
argv[0],
dir_in );
dir_in.c_str() );
}
else
@ -2663,7 +2663,7 @@ static int builtin_cd( wchar_t **argv )
sb_printf( sb_err,
_( L"%ls: Unknown error trying to locate directory '%ls'\n" ),
argv[0],
dir_in );
dir_in.c_str() );
}

View file

@ -12,7 +12,8 @@ Functions used for implementing the set builtin.
#include <sys/types.h>
#include <termios.h>
#include <signal.h>
#include <vector>
#include <algorithm>
#include "fallback.h"
#include "util.h"
@ -72,7 +73,7 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
int show_hint = 0;
struct stat buff;
wchar_t *dir = (wchar_t *)al_get( val, i );
const wchar_t *dir = (wchar_t *)al_get( val, i );
if( wstat( dir, &buff ) )
{
@ -88,7 +89,7 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
if( error )
{
wchar_t *colon;
const wchar_t *colon;
sb_printf( sb_err,
_(BUILTIN_SET_PATH_ERROR),
@ -173,6 +174,126 @@ static int my_env_set( const wchar_t *key, array_list_t *val, int scope )
return retcode;
}
static int my_env_set2( const wchar_t *key, wcstring_list_t &val, int scope )
{
string_buffer_t sb;
int i;
int retcode = 0;
wchar_t *val_str=0;
if( is_path_variable( key ) )
{
int error = 0;
for( i=0; i< val.size() ; i++ )
{
int show_perror = 0;
int show_hint = 0;
struct stat buff;
const wchar_t *dir = val[ i ].c_str();
if( wstat( dir, &buff ) )
{
error = 1;
show_perror = 1;
}
if( !( S_ISDIR(buff.st_mode) ) )
{
error = 1;
}
if( error )
{
const wchar_t *colon;
sb_printf( sb_err,
_(BUILTIN_SET_PATH_ERROR),
L"set",
dir,
key );
colon = wcschr( dir, L':' );
if( colon && *(colon+1) )
{
show_hint = 1;
}
}
if( show_perror )
{
builtin_wperror( L"set" );
}
if( show_hint )
{
sb_printf( sb_err,
_(BUILTIN_SET_PATH_HINT),
L"set",
key,
key,
wcschr( dir, L':' )+1);
}
if( error )
{
break;
}
}
if( error )
{
return 1;
}
}
sb_init( &sb );
if( val.size() )
{
for( i=0; i< val.size() ; i++ )
{
const wchar_t *next = val[ i ].c_str();
sb_append( &sb, next?next:L"" );
if( i<val.size() - 1 )
{
sb_append( &sb, ARRAY_SEP_STR );
}
}
val_str = (wchar_t *)sb.buff;
}
switch( env_set( key, val_str, scope | ENV_USER ) )
{
case ENV_PERM:
{
sb_printf( sb_err, _(L"%ls: Tried to change the read-only variable '%ls'\n"), L"set", key );
retcode=1;
break;
}
case ENV_INVALID:
{
sb_printf( sb_err, _(L"%ls: Unknown error"), L"set" );
retcode=1;
break;
}
}
sb_destroy( &sb );
return retcode;
}
/**
Extract indexes from a destination argument of the form name[index1 index2...]
@ -260,6 +381,82 @@ static int parse_index( array_list_t *indexes,
}
static int parse_index2( std::vector<long> &indexes,
const wchar_t *src,
const wchar_t *name,
int var_count )
{
size_t len;
int count = 0;
const wchar_t *src_orig = src;
if (src == 0)
{
return 0;
}
while (*src != L'\0' && (iswalnum(*src) || *src == L'_'))
{
src++;
}
if (*src != L'[')
{
sb_printf( sb_err, _(BUILTIN_SET_ARG_COUNT), L"set" );
return 0;
}
len = src-src_orig;
if( (wcsncmp( src_orig, name, len )!=0) || (wcslen(name) != (len)) )
{
sb_printf( sb_err,
_(L"%ls: Multiple variable names specified in single call (%ls and %.*ls)\n"),
L"set",
name,
len,
src_orig);
return 0;
}
src++;
while (iswspace(*src))
{
src++;
}
while (*src != L']')
{
wchar_t *end;
long l_ind;
errno = 0;
l_ind = wcstol(src, &end, 10);
if( end==src || errno )
{
sb_printf(sb_err, _(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
return 0;
}
if( l_ind < 0 )
{
l_ind = var_count+l_ind+1;
}
indexes.push_back( l_ind );
src = end;
count++;
while (iswspace(*src)) src++;
}
return count;
}
/**
Update a list \c list by writing copies (using wcsdup) of the
values specified by \c values to the indexes specified by \c
@ -295,7 +492,32 @@ static int update_values( array_list_t *list,
return 0;
}
static int update_values2( wcstring_list_t &list,
std::vector<long> &indexes,
wcstring_list_t &values )
{
int i;
/* Replace values where needed */
for( i = 0; i < indexes.size(); i++ )
{
/*
The '- 1' below is because the indices in fish are
one-based, but the array_list_t uses zero-based indices
*/
long ind = indexes[i] - 1;
const wcstring newv = values[ i ];
if( ind < 0 )
{
return 1;
}
// free((void *) al_get(list, ind));
list[ ind ] = newv;
}
return 0;
}
/**
Return 1 if an array list of longs contains the specified
value, 0 otherwise
@ -345,6 +567,35 @@ static void erase_values(array_list_t *list, array_list_t *indexes)
al_destroy(&result);
}
/**
Erase from a list of wcstring values at specified indexes
*/
static void erase_values2 (wcstring_list_t &list, std::vector<long> &indexes)
{
long i;
wcstring_list_t result;
// al_init(&result);
for (i = 0; i < list.size(); i++)
{
if (std::find(indexes.begin(), indexes.end(), i + 1) != indexes.end())
{
result.push_back( list[ i ] );
}
else
{
// free( (void *)al_get(list, i));
}
}
// al_truncate(list,0);
list.clear();
copy(result.begin(),result.end(),back_inserter( list ) );
// al_destroy(&result);
}
/**
Print the names of all environment variables in the scope, with or without values,
@ -369,23 +620,23 @@ static void print_variables(int include_values, int esc, int scope)
if( include_values )
{
wchar_t *value = env_get(key);
wcstring value = env_get_string(key);
wchar_t *e_value;
if( value )
if( !value.empty() )
{
int shorten = 0;
if( wcslen( value ) > 64 )
if( value.length() > 64 )
{
shorten = 1;
value = wcsndup( value, 60 );
if( !value )
value = wcsndup( value.c_str(), 60 );
if( value.empty() )
{
DIE_MEM();
}
}
e_value = esc ? expand_escape_variable(value) : wcsdup(value);
e_value = esc ? expand_escape_variable(value.c_str()) : wcsdup(value.c_str());
sb_append(sb_out, L" ", e_value, NULL);
free(e_value);
@ -393,7 +644,7 @@ static void print_variables(int include_values, int esc, int scope)
if( shorten )
{
sb_append(sb_out, L"\u2026");
free( value );
// free( value );
}
}
@ -632,25 +883,25 @@ static int builtin_set( wchar_t **argv )
if( slice )
{
array_list_t indexes;
array_list_t result;
std::vector<long> indexes;
wcstring_list_t result;
int j;
al_init( &result );
al_init( &indexes );
// al_init( &result );
// al_init( &indexes );
tokenize_variable_array( env_get( dest ), &result );
tokenize_variable_array2( env_get_string( dest ), result );
if( !parse_index( &indexes, arg, dest, al_get_count( &result ) ) )
if( !parse_index2( indexes, arg, dest, result.size() ) )
{
builtin_print_help( argv[0], sb_err );
retcode = 1;
break;
}
for( j=0; j<al_get_count( &indexes ); j++ )
for( j=0; j < indexes.size() ; j++ )
{
long idx = al_get_long( &indexes, j );
if( idx < 1 || idx > al_get_count( &result ) )
long idx = indexes[j];
if( idx < 1 || idx > result.size() )
{
retcode++;
}
@ -747,19 +998,19 @@ static int builtin_set( wchar_t **argv )
Slice mode
*/
int idx_count, val_count;
array_list_t values;
array_list_t indexes;
array_list_t result;
wcstring_list_t values;
std::vector<long> indexes;
wcstring_list_t result;
al_init(&values);
al_init(&indexes);
al_init(&result);
// al_init(&values);
// al_init(&indexes);
// al_init(&result);
tokenize_variable_array( env_get(dest), &result );
tokenize_variable_array2( env_get_string(dest), result );
for( ; woptind<argc; woptind++ )
{
if( !parse_index( &indexes, argv[woptind], dest, al_get_count( &result ) ) )
if( !parse_index2( indexes, argv[woptind], dest, result.size() ) )
{
builtin_print_help( argv[0], sb_err );
retcode = 1;
@ -767,7 +1018,7 @@ static int builtin_set( wchar_t **argv )
}
val_count = argc-woptind-1;
idx_count = al_get_count( &indexes );
idx_count = indexes.size();
if( !erase )
{
@ -794,42 +1045,42 @@ static int builtin_set( wchar_t **argv )
if( erase )
{
erase_values(&result, &indexes);
my_env_set( dest, &result, scope);
erase_values2(result, indexes);
my_env_set2( dest, result, scope);
}
else
{
array_list_t value;
al_init(&value);
wcstring_list_t value;
// al_init(&value);
while( woptind < argc )
{
al_push(&value, argv[woptind++]);
value.push_back( argv[woptind++] );
}
if( update_values( &result,
&indexes,
&value ) )
if( update_values2( result,
indexes,
value ) )
{
sb_printf( sb_err, L"%ls: ", argv[0] );
sb_printf( sb_err, ARRAY_BOUNDS_ERR );
sb_append( sb_err, L"\n" );
}
my_env_set(dest,
&result,
my_env_set2(dest,
result,
scope);
al_destroy( &value );
// al_destroy( &value );
}
}
al_foreach( &result, &free );
al_destroy( &result );
// al_foreach( &result, &free );
// al_destroy( &result );
al_destroy(&indexes);
al_destroy(&values);
// al_destroy(&indexes);
// al_destroy(&values);
}
else

View file

@ -1080,15 +1080,16 @@ static void complete_cmd( const wchar_t *cmd,
int use_builtin,
int use_command )
{
wchar_t *path;
wcstring path;
wchar_t *path_cpy;
wchar_t *nxt_path;
wchar_t *state;
array_list_t possible_comp;
wchar_t *nxt_completion;
wchar_t *cdpath = env_get(L"CDPATH");
wchar_t *cdpath_cpy = wcsdup( cdpath?cdpath:L"." );
const wcstring cdpath = env_get_string(L"CDPATH");
// wchar_t *cdpath_cpy = wcsdup( cdpath?cdpath:L"." );
wchar_t *cdpath_cpy = wcsdup( !cdpath.empty()?cdpath.c_str():L"." );
if( (wcschr( cmd, L'/') != 0) || (cmd[0] == L'~' ) )
{
@ -1110,11 +1111,11 @@ static void complete_cmd( const wchar_t *cmd,
if( use_command )
{
path = env_get(L"PATH");
if( path )
path = env_get_string(L"PATH");
if( !path.empty() )
{
path_cpy = wcsdup( path );
path_cpy = wcsdup( path.c_str() );
for( nxt_path = wcstok( path_cpy, ARRAY_SEP_STR, &state );
nxt_path != 0;
@ -1650,10 +1651,11 @@ static int complete_variable( const wchar_t *whole_var,
if( match || match_no_case )
{
wchar_t *value_unescaped, *value;
wcstring value_unescaped;
wchar_t *value;
value_unescaped = env_get( name );
if( value_unescaped )
value_unescaped = env_get_string( name );
if( !value_unescaped.empty() )
{
string_buffer_t desc;
string_buffer_t comp;
@ -1673,7 +1675,7 @@ static int complete_variable( const wchar_t *whole_var,
flags = COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE;
}
value = expand_escape_variable( value_unescaped );
value = expand_escape_variable( value_unescaped.c_str() );
sb_init( &desc );
sb_printf( &desc, COMPLETE_VAR_DESC_VAL, value );

71
env.cpp
View file

@ -300,8 +300,8 @@ static int is_locale( const wchar_t *key )
*/
static void handle_locale()
{
const wchar_t *lc_all = env_get( L"LC_ALL" );
const wchar_t *lang;
const wcstring lc_all = env_get_string( L"LC_ALL" );
wcstring lang;
int i;
wchar_t *old = wcsdup(wsetlocale( LC_MESSAGES, NULL ));
@ -321,25 +321,25 @@ static void handle_locale()
}
;
if( lc_all )
if( !lc_all.empty() )
{
wsetlocale( LC_ALL, lc_all );
wsetlocale( LC_ALL, lc_all.c_str() );
}
else
{
lang = env_get( L"LANG" );
if( lang )
lang = env_get_string( L"LANG" );
if( !lang.empty() )
{
wsetlocale( LC_ALL, lang );
wsetlocale( LC_ALL, lang.c_str() );
}
for( i=2; locale_variable[i]; i++ )
{
const wchar_t *val = env_get( locale_variable[i] );
const wcstring val = env_get_string( locale_variable[i] );
if( val )
if( !val.empty() )
{
wsetlocale( cat[i], val );
wsetlocale( cat[i], val.c_str() );
}
}
}
@ -426,7 +426,7 @@ static void universal_callback( int type,
*/
static void setup_path()
{
wchar_t *path;
wcstring path;
size_t i;
int j;
@ -441,9 +441,9 @@ static void setup_path()
}
;
path = env_get( L"PATH" );
path = env_get_string( L"PATH" );
if( path )
if( !path.empty() )
{
tokenize_variable_array2( path, lst );
}
@ -476,18 +476,18 @@ static void setup_path()
debug( 3, L"directory %ls was missing", path_el[j] );
if( path )
if( !path.empty() )
{
buffer += path;
buffer += path;
}
buffer += ARRAY_SEP_STR;
buffer += path_el[j];
buffer += ARRAY_SEP_STR;
buffer += path_el[j];
env_set( L"PATH", buffer.c_str(), ENV_GLOBAL | ENV_EXPORT );
env_set( L"PATH", buffer.empty()?NULL:buffer.c_str(), ENV_GLOBAL | ENV_EXPORT );
path = env_get( L"PATH" );
lst.resize(0);
path = env_get_string( L"PATH" );
lst.resize(0);
tokenize_variable_array2( path, lst );
}
}
@ -511,7 +511,7 @@ int env_set_pwd()
static void env_set_defaults()
{
if( !env_get( L"USER" ) )
if( env_get_string( L"USER" ).empty() )
{
struct passwd *pw = getpwuid( getuid());
wchar_t *unam = str2wcs( pw->pw_name );
@ -519,10 +519,10 @@ static void env_set_defaults()
free( unam );
}
if( !env_get( L"HOME" ) )
if( env_get_string( L"HOME" ).empty() )
{
wchar_t *unam = env_get( L"USER" );
char *unam_narrow = wcs2str( unam );
const wcstring unam = env_get_string( L"USER" );
char *unam_narrow = wcs2str( unam.c_str() );
struct passwd *pw = getpwnam( unam_narrow );
wchar_t *dir = str2wcs( pw->pw_dir );
env_set( L"HOME", dir, ENV_GLOBAL );
@ -540,7 +540,6 @@ void env_init()
struct passwd *pw;
wchar_t *uname;
wchar_t *version;
wchar_t *shlvl;
sb_init( &dyn_var );
b_init( &export_buffer );
@ -657,15 +656,21 @@ void env_init()
env_set( L"version", version, ENV_GLOBAL );
free( version );
env_universal_init( env_get( L"FISHD_SOCKET_DIR"),
env_get( L"USER" ),
const wcstring fishd_dir_wstr = env_get_string( L"FISHD_SOCKET_DIR");
const wcstring user_dir_wstr = env_get_string( L"USER" );
wchar_t * fishd_dir = fishd_dir_wstr.empty()?NULL:const_cast<wchar_t*>(fishd_dir_wstr.c_str());
wchar_t * user_dir = user_dir_wstr.empty()?NULL:const_cast<wchar_t*>(user_dir_wstr.c_str());
env_universal_init(fishd_dir , user_dir ,
&start_fishd,
&universal_callback );
/*
Set up SHLVL variable
*/
shlvl = env_get( L"SHLVL" );
const wchar_t *shlvl = env_get_string( L"SHLVL" ).empty()?NULL:env_get_string( L"SHLVL" ).c_str();
if ( shlvl )
{
wchar_t *nshlvl, **end_nshlvl;
@ -1199,7 +1204,7 @@ wcstring env_get_string( const wchar_t *key )
{
if( wcscmp( res->val, ENV_NULL )==0)
{
return 0;
return wcstring(L"");
}
else
{
@ -1226,7 +1231,7 @@ wcstring env_get_string( const wchar_t *key )
if( !item || (wcscmp( item, ENV_NULL )==0))
{
return 0;
return wcstring(L"");
}
else
{
@ -1813,9 +1818,9 @@ env_vars::env_vars(const wchar_t * const *keys)
{
ASSERT_IS_MAIN_THREAD();
for (size_t i=0; keys[i]; i++) {
const wchar_t *val = env_get(keys[i]);
if (val) {
vars[keys[i]] = val;
const wcstring val = env_get_string(keys[i]);
if (!val.empty()) {
vars[keys[i]] = wcsdup(val.c_str());
}
}
}

View file

@ -1739,8 +1739,8 @@ int exec_subshell( const wchar_t *cmd,
char sep=0;
CHECK( cmd, -1 );
ifs = env_get(L"IFS");
// ifs = env_get(L"IFS");
ifs = env_get_string(L"IFS").empty()?NULL:env_get_string(L"IFS").c_str();
if( ifs && ifs[0] )
{

View file

@ -176,7 +176,7 @@ int expand_is_clean( const wchar_t *in )
/**
Return the environment variable value for the string starting at \c in.
*/
static wchar_t *expand_var( wchar_t *in )
static const wchar_t* expand_var( wchar_t *in )
{
if( !in )
return 0;
@ -958,7 +958,7 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
int start_pos = i+1;
int stop_pos;
int var_len, new_len;
wchar_t * var_val;
const wchar_t * var_val;
wchar_t * new_in;
int is_single = (c==VARIABLE_EXPAND_SINGLE);
int var_name_stop_pos;
@ -990,7 +990,6 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
}
sb_append_substring( var_tmp, &in[start_pos], var_len );
var_val = expand_var( (wchar_t *)var_tmp->buff );
if( var_val )

View file

@ -152,7 +152,9 @@ static void autoload_names( array_list_t *out, int get_hidden )
{
size_t i;
const wchar_t *path_var = env_get( L"fish_function_path" );
array_list_t path_list;
const wcstring path_var_wstr = env_get_string( L"fish_function_path" );
const wchar_t *path_var = path_var_wstr.empty()?NULL:path_var_wstr.c_str();
if( ! path_var )
return;

View file

@ -190,19 +190,24 @@ int highlight_get_color( int highlight )
}
}
wchar_t *val = env_get( highlight_var[idx]);
wcstring val_wstr = env_get_string( highlight_var[idx]);
const wchar_t *val = val_wstr.empty()?NULL:val_wstr.c_str();
// debug( 1, L"%d -> %d -> %ls", highlight, idx, val );
if( val == 0 )
val = env_get( highlight_var[0]);
if( val == 0 ) {
val_wstr = env_get_string( highlight_var[0]);
val = val_wstr.empty()?NULL:val_wstr.c_str();
}
if( val )
result = output_color_code( val );
if( highlight & HIGHLIGHT_VALID_PATH )
{
wchar_t *val2 = env_get( L"fish_color_valid_path" );
wcstring val2_wstr = env_get_string( L"fish_color_valid_path" );
const wchar_t *val2 = val2_wstr.empty()?NULL:val2_wstr.c_str();
int result2 = output_color_code( val2 );
if( result == FISH_COLOR_NORMAL )
result = result2;

View file

@ -324,7 +324,7 @@ int input_init()
debug( 0, _( L"Could not set up terminal" ) );
exit(1);
}
output_set_term( env_get( L"TERM" ) );
output_set_term( env_get_string( L"TERM" ).c_str() );
input_terminfo_init();

View file

@ -104,11 +104,13 @@ void kill_add( wchar_t *str )
I couldn't think of a safe way to allow overide of the echo
command too, so, the command used must accept the input via stdin.
*/
wchar_t *clipboard;
if( (clipboard = env_get(L"FISH_CLIPBOARD_CMD")) )
const wcstring clipboard_wstr = env_get_string(L"FISH_CLIPBOARD_CMD");
// const wchar_t *clipboard = clipboard_wstr.empty()?NULL:clipboard.c_str();
if( !clipboard_wstr.empty() )
{
escaped_str = escape( str, 1 );
cmd = wcsdupcat(L"echo -n ", escaped_str, clipboard);
cmd = wcsdupcat(L"echo -n ", escaped_str, clipboard_wstr.c_str());
}
else
{
@ -117,8 +119,9 @@ void kill_add( wchar_t *str )
return;
}
wchar_t *disp;
if( (disp = env_get( L"DISPLAY" )) )
const wcstring disp_wstr = env_get_string( L"DISPLAY" );
// wchar_t *disp = disp_wstr.empty()?NULL:disp_wstr.c_str();
if( !disp_wstr.empty() )
{
escaped_str = escape( str, 1 );
cmd = wcsdupcat(L"echo ", escaped_str, L"|xsel -b" );
@ -215,13 +218,13 @@ wchar_t *kill_yank_rotate()
*/
static void kill_check_x_buffer()
{
wchar_t *disp;
wcstring disp;
if( !has_xsel() )
return;
if( (disp = env_get( L"DISPLAY" )) )
if( (!(disp = env_get_string( L"DISPLAY" )).empty()) )
{
size_t i;
wcstring cmd = L"xsel -t 500 -b";

View file

@ -587,7 +587,7 @@ int output_color_code( const wchar_t *val )
}
void output_set_term( wchar_t *term )
void output_set_term( const wchar_t *term )
{
current_term = halloc_wcsdup(global_context, term);
}

View file

@ -154,7 +154,7 @@ int (*output_get_writer())(char) ;
/**
Set the terminal name
*/
void output_set_term( wchar_t *term );
void output_set_term( const wchar_t *term );
/**
Return the terminal name
*/

View file

@ -800,7 +800,7 @@ int parse_util_load( const wcstring &cmd,
void (*on_load)(const wchar_t *cmd),
int reload )
{
wchar_t *path_var;
wcstring path_var;
int res;
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 );
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?
*/
if( !path_var )
if( path_var.empty() )
{
return 0;
}
@ -856,9 +856,9 @@ int parse_util_load( const wcstring &cmd,
We have never tried to autoload using this path name before,
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->old_path = path_var;
loaded->old_path = wcsdup(path_var.c_str());
}
std::vector<wcstring> path_list;

View file

@ -2043,7 +2043,9 @@ static int parse_job( process_t *p,
}
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 )
{
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;
const wchar_t *path;
int err = ENOENT;
@ -166,7 +166,8 @@ wchar_t *path_get_path( void *context, const wchar_t *cmd )
}
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( 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
*/
wchar_t *path_cpy = wcsdup( path );
wchar_t *nxt_path = path;
const wchar_t *nxt_path = path;
wchar_t *state;
if( (new_cmd==0) || (path_cpy==0) )
@ -356,20 +357,21 @@ wchar_t *path_get_cdpath( void *context, const wchar_t *dir )
}
else
{
wchar_t *path;
const wchar_t *path;
wchar_t *path_cpy;
wchar_t *nxt_path;
wchar_t *state;
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) )
{
path = L".";
}
nxt_path = path;
nxt_path = const_cast<wchar_t*>(path);
path_cpy = wcsdup( path );
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 *xdg_dir, *home;
const wchar_t *xdg_dir, *home;
int done = 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 )
{
res = wcsdupcat( xdg_dir, L"/fish" );
@ -457,7 +460,8 @@ wchar_t *path_get_config( void *context)
}
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 )
{
res = wcsdupcat( home, L"/.config/fish" );

View file

@ -606,7 +606,8 @@ int reader_interrupted()
void reader_write_title()
{
const wchar_t *title;
wchar_t *term = env_get( L"TERM" );
const wcstring term_str = env_get_string( L"TERM" );
const wchar_t *term = term_str.empty()?NULL:term_str.c_str();
/*
This is a pretty lame heuristic for detecting terminals that do

View file

@ -204,8 +204,8 @@ static int calc_prompt_width( const wchar_t *prompt )
{
if( prompt[j+1] == L'k' )
{
wchar_t *term_name = env_get( L"TERM" );
if( term_name && wcsstr( term_name, L"screen" ) == term_name )
wcstring term_name = env_get_string( L"TERM" );
if( !term_name.empty() && wcsstr( term_name.c_str(), L"screen" ) == term_name )
{
const wchar_t *end;
j+=2;