mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Modified functions in function.h/.cpp to use wcstring instead wchar_t*, other files also modified to use wcstring.
This commit is contained in:
parent
d8a9991738
commit
74a7303c23
11 changed files with 44 additions and 50 deletions
21
builtin.cpp
21
builtin.cpp
|
@ -1074,7 +1074,7 @@ static int builtin_generic( parser_t &parser, wchar_t **argv )
|
|||
Output a definition of the specified function to the specified
|
||||
stringbuffer. Used by the functions builtin.
|
||||
*/
|
||||
static void functions_def( wchar_t *name, string_buffer_t *out )
|
||||
static void functions_def( const wcstring &name, string_buffer_t *out )
|
||||
{
|
||||
const wchar_t *desc = function_get_desc( name );
|
||||
const wchar_t *def = function_get_definition(name);
|
||||
|
@ -1088,7 +1088,7 @@ static void functions_def( wchar_t *name, string_buffer_t *out )
|
|||
|
||||
sb_append( out,
|
||||
L"function ",
|
||||
name,
|
||||
name.c_str(),
|
||||
NULL);
|
||||
|
||||
if( desc && wcslen(desc) )
|
||||
|
@ -1369,8 +1369,8 @@ static int builtin_functions( parser_t &parser, wchar_t **argv )
|
|||
}
|
||||
else if( copy )
|
||||
{
|
||||
wchar_t *current_func;
|
||||
wchar_t *new_func;
|
||||
wcstring current_func;
|
||||
wcstring new_func;
|
||||
|
||||
if( argc-woptind != 2 )
|
||||
{
|
||||
|
@ -1389,18 +1389,18 @@ static int builtin_functions( parser_t &parser, wchar_t **argv )
|
|||
sb_printf( sb_err,
|
||||
_( L"%ls: Function '%ls' does not exist\n" ),
|
||||
argv[0],
|
||||
current_func );
|
||||
current_func.c_str() );
|
||||
builtin_print_help( parser, argv[0], sb_err );
|
||||
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
if( (wcsfuncname( new_func ) != 0) || parser_keywords_is_reserved( new_func ) )
|
||||
if( (wcsfuncname( new_func.c_str() ) != 0) || parser_keywords_is_reserved( new_func ) )
|
||||
{
|
||||
sb_printf( sb_err,
|
||||
_( L"%ls: Illegal function name '%ls'\n"),
|
||||
argv[0],
|
||||
new_func );
|
||||
new_func.c_str());
|
||||
builtin_print_help( parser, argv[0], sb_err );
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
@ -1411,8 +1411,8 @@ static int builtin_functions( parser_t &parser, wchar_t **argv )
|
|||
sb_printf( sb_err,
|
||||
_( L"%ls: Function '%ls' already exists. Cannot create copy '%ls'\n" ),
|
||||
argv[0],
|
||||
new_func,
|
||||
current_func );
|
||||
new_func.c_str(),
|
||||
current_func.c_str() );
|
||||
builtin_print_help( parser, argv[0], sb_err );
|
||||
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
|
@ -3682,9 +3682,8 @@ void builtin_get_names(std::vector<completion_t> &list) {
|
|||
}
|
||||
}
|
||||
|
||||
const wchar_t *builtin_get_desc( const wchar_t *name )
|
||||
const wchar_t *builtin_get_desc( const wcstring &name )
|
||||
{
|
||||
CHECK( name, 0 );
|
||||
const builtin_data_t *builtin = builtin_lookup(name);
|
||||
return builtin ? _(builtin->desc) : NULL;
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ void builtin_pop_io(parser_t &parser);
|
|||
/**
|
||||
Return a one-line description of the specified builtin. This is usually a truly constant string, so we should not wrap it in a wcstring.
|
||||
*/
|
||||
const wchar_t *builtin_get_desc( const wchar_t *b );
|
||||
const wchar_t *builtin_get_desc( const wcstring &b );
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -711,7 +711,7 @@ int complete_is_valid_argument( const wchar_t *str,
|
|||
static void complete_strings( std::vector<completion_t> &comp_out,
|
||||
const wchar_t *wc_escaped,
|
||||
const wchar_t *desc,
|
||||
const wchar_t *(*desc_func)(const wchar_t *),
|
||||
const wchar_t *(*desc_func)(const wcstring &),
|
||||
std::vector<completion_t> &possible_comp,
|
||||
int flags )
|
||||
{
|
||||
|
@ -862,7 +862,7 @@ static void complete_cmd_desc( const wchar_t *cmd, std::vector<completion_t> &co
|
|||
/**
|
||||
Returns a description for the specified function
|
||||
*/
|
||||
static const wchar_t *complete_function_desc( const wchar_t *fn )
|
||||
static const wchar_t *complete_function_desc( const wcstring &fn )
|
||||
{
|
||||
const wchar_t *res = function_get_desc( fn );
|
||||
|
||||
|
|
2
exec.cpp
2
exec.cpp
|
@ -441,7 +441,7 @@ static int setup_child_process( job_t *j, process_t *p )
|
|||
call. Only use it in the execve error handler which calls exit
|
||||
right afterwards, anyway.
|
||||
*/
|
||||
static wchar_t *get_interpreter( const wchar_t *file )
|
||||
static wchar_t *get_interpreter( const wcstring &file )
|
||||
{
|
||||
string_buffer_t sb;
|
||||
FILE *fp = wfopen( file, "r" );
|
||||
|
|
27
function.cpp
27
function.cpp
|
@ -85,7 +85,7 @@ static int is_autoload = 0;
|
|||
Make sure that if the specified function is a dynamically loaded
|
||||
function, it has been fully loaded.
|
||||
*/
|
||||
static int load( const wchar_t *name )
|
||||
static int load( const wcstring &name )
|
||||
{
|
||||
ASSERT_IS_MAIN_THREAD();
|
||||
scoped_lock lock(functions_lock);
|
||||
|
@ -188,9 +188,8 @@ void function_add( function_data_t *data, const parser_t &parser )
|
|||
}
|
||||
}
|
||||
|
||||
int function_exists( const wchar_t *cmd )
|
||||
int function_exists( const wcstring &cmd )
|
||||
{
|
||||
CHECK( cmd, 0 );
|
||||
if( parser_keywords_is_reserved(cmd) )
|
||||
return 0;
|
||||
scoped_lock lock(functions_lock);
|
||||
|
@ -198,9 +197,8 @@ int function_exists( const wchar_t *cmd )
|
|||
return loaded_functions.find(cmd) != loaded_functions.end();
|
||||
}
|
||||
|
||||
int function_exists_no_autoload( const wchar_t *cmd, const env_vars &vars )
|
||||
int function_exists_no_autoload( const wcstring &cmd, const env_vars &vars )
|
||||
{
|
||||
CHECK( cmd, 0 );
|
||||
if( parser_keywords_is_reserved(cmd) )
|
||||
return 0;
|
||||
scoped_lock lock(functions_lock);
|
||||
|
@ -238,26 +236,26 @@ shared_ptr<function_info_t> function_get(const wcstring &name)
|
|||
}
|
||||
}
|
||||
|
||||
const wchar_t *function_get_definition( const wchar_t *name )
|
||||
const wchar_t *function_get_definition( const wcstring &name )
|
||||
{
|
||||
shared_ptr<function_info_t> func = function_get(name);
|
||||
return func ? func->definition.c_str() : NULL;
|
||||
}
|
||||
|
||||
wcstring_list_t function_get_named_arguments( const wchar_t *name )
|
||||
wcstring_list_t function_get_named_arguments( const wcstring &name )
|
||||
{
|
||||
shared_ptr<function_info_t> func = function_get(name);
|
||||
return func ? func->named_arguments : wcstring_list_t();
|
||||
}
|
||||
|
||||
int function_get_shadows( const wchar_t *name )
|
||||
int function_get_shadows( const wcstring &name )
|
||||
{
|
||||
shared_ptr<function_info_t> func = function_get(name);
|
||||
return func ? func->shadows : false;
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *function_get_desc( const wchar_t *name )
|
||||
const wchar_t *function_get_desc( const wcstring &name )
|
||||
{
|
||||
/* Empty length string goes to NULL */
|
||||
shared_ptr<function_info_t> func = function_get(name);
|
||||
|
@ -268,17 +266,14 @@ const wchar_t *function_get_desc( const wchar_t *name )
|
|||
}
|
||||
}
|
||||
|
||||
void function_set_desc( const wchar_t *name, const wchar_t *desc )
|
||||
void function_set_desc( const wcstring &name, const wcstring &desc )
|
||||
{
|
||||
CHECK( name, );
|
||||
CHECK( desc, );
|
||||
|
||||
load( name );
|
||||
shared_ptr<function_info_t> func = function_get(name);
|
||||
if (func) func->description = desc;
|
||||
}
|
||||
|
||||
int function_copy( const wchar_t *name, const wchar_t *new_name )
|
||||
int function_copy( const wcstring &name, const wcstring &new_name )
|
||||
{
|
||||
int result = 0;
|
||||
scoped_lock lock(functions_lock);
|
||||
|
@ -318,14 +313,14 @@ wcstring_list_t function_get_names( int get_hidden )
|
|||
return wcstring_list_t(names.begin(), names.end());
|
||||
}
|
||||
|
||||
const wchar_t *function_get_definition_file( const wchar_t *name )
|
||||
const wchar_t *function_get_definition_file( const wcstring &name )
|
||||
{
|
||||
shared_ptr<function_info_t> func = function_get(name);
|
||||
return func ? func->definition_file : NULL;
|
||||
}
|
||||
|
||||
|
||||
int function_get_definition_offset( const wchar_t *name )
|
||||
int function_get_definition_offset( const wcstring &name )
|
||||
{
|
||||
shared_ptr<function_info_t> func = function_get(name);
|
||||
return func ? func->definition_offset : -1;
|
||||
|
|
20
function.h
20
function.h
|
@ -118,27 +118,27 @@ shared_ptr<function_info_t> function_get(const wcstring &name);
|
|||
/**
|
||||
Returns the definition of the function with the name \c name.
|
||||
*/
|
||||
const wchar_t *function_get_definition( const wchar_t *name );
|
||||
const wchar_t *function_get_definition( const wcstring &name );
|
||||
|
||||
/**
|
||||
Returns the description of the function with the name \c name.
|
||||
*/
|
||||
const wchar_t *function_get_desc( const wchar_t *name );
|
||||
const wchar_t *function_get_desc( const wcstring &name );
|
||||
|
||||
/**
|
||||
Sets the description of the function with the name \c name.
|
||||
*/
|
||||
void function_set_desc( const wchar_t *name, const wchar_t *desc );
|
||||
void function_set_desc( const wcstring &name, const wcstring &desc );
|
||||
|
||||
/**
|
||||
Returns true if the function with the name name exists.
|
||||
*/
|
||||
int function_exists( const wchar_t *name );
|
||||
int function_exists( const wcstring &name );
|
||||
|
||||
/**
|
||||
Returns true if the function with the name name exists, without triggering autoload.
|
||||
*/
|
||||
int function_exists_no_autoload( const wchar_t *name, const env_vars &vars );
|
||||
int function_exists_no_autoload( const wcstring &name, const env_vars &vars );
|
||||
|
||||
/**
|
||||
Returns all function names.
|
||||
|
@ -154,7 +154,7 @@ wcstring_list_t function_get_names( int get_hidden );
|
|||
This function does not autoload functions, it will only work on
|
||||
functions that have already been defined.
|
||||
*/
|
||||
const wchar_t *function_get_definition_file( const wchar_t *name );
|
||||
const wchar_t *function_get_definition_file( const wcstring &name );
|
||||
|
||||
/**
|
||||
Returns the linenumber where the definition of the specified
|
||||
|
@ -163,23 +163,23 @@ const wchar_t *function_get_definition_file( const wchar_t *name );
|
|||
This function does not autoload functions, it will only work on
|
||||
functions that have already been defined.
|
||||
*/
|
||||
int function_get_definition_offset( const wchar_t *name );
|
||||
int function_get_definition_offset( const wcstring &name );
|
||||
|
||||
/**
|
||||
Returns a list of all named arguments of the specified function.
|
||||
*/
|
||||
wcstring_list_t function_get_named_arguments( const wchar_t *name );
|
||||
wcstring_list_t function_get_named_arguments( const wcstring &name );
|
||||
|
||||
/**
|
||||
Creates a new function using the same definition as the specified function.
|
||||
Returns non-zero if copy is successful.
|
||||
*/
|
||||
int function_copy( const wchar_t *name, const wchar_t *new_name );
|
||||
int function_copy( const wcstring &name, const wcstring &new_name );
|
||||
|
||||
|
||||
/**
|
||||
Returns whether this function shadows variables of the underlying function
|
||||
*/
|
||||
int function_get_shadows( const wchar_t *name );
|
||||
int function_get_shadows( const wcstring &name );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -855,7 +855,7 @@ static void tokenize( const wchar_t * const buff, int * const color, const int p
|
|||
is_cmd |= builtin_exists( cmd );
|
||||
|
||||
if( use_function )
|
||||
is_cmd |= function_exists_no_autoload( cmd.c_str(), vars );
|
||||
is_cmd |= function_exists_no_autoload( cmd, vars );
|
||||
|
||||
/*
|
||||
Moving on to expensive tests
|
||||
|
|
|
@ -1031,7 +1031,7 @@ const wchar_t *parser_t::current_filename() const
|
|||
if( b->type == FUNCTION_CALL )
|
||||
{
|
||||
wcstring function_call_name = b->state1<wcstring>();
|
||||
return function_get_definition_file(function_call_name.c_str());
|
||||
return function_get_definition_file(function_call_name);
|
||||
}
|
||||
b=b->outer;
|
||||
}
|
||||
|
@ -1862,7 +1862,7 @@ int parser_t::parse_job( process_t *p,
|
|||
nxt_forbidden = (forbid == nxt);
|
||||
}
|
||||
|
||||
if( !nxt_forbidden && has_nxt && function_exists( nxt.c_str() ) )
|
||||
if( !nxt_forbidden && has_nxt && function_exists( nxt ) )
|
||||
{
|
||||
/*
|
||||
Check if we have reached the maximum recursion depth
|
||||
|
|
6
path.cpp
6
path.cpp
|
@ -405,12 +405,12 @@ wchar_t *path_allocate_cdpath( const wchar_t *dir, const wchar_t *wd )
|
|||
|
||||
for (wcstring_list_t::const_iterator iter = paths.begin(); iter != paths.end(); iter++) {
|
||||
struct stat buf;
|
||||
const wchar_t *dir = iter->c_str();
|
||||
const wcstring &dir = *iter;
|
||||
if( wstat( dir, &buf ) == 0 )
|
||||
{
|
||||
if( S_ISDIR(buf.st_mode) )
|
||||
{
|
||||
res = wcsdup(dir);
|
||||
res = wcsdup(dir.c_str());
|
||||
break;
|
||||
}
|
||||
else
|
||||
|
@ -534,7 +534,7 @@ bool paths_are_same_file(const wcstring &path1, const wcstring &path2) {
|
|||
return true;
|
||||
|
||||
struct stat s1, s2;
|
||||
if (wstat(path1.c_str(), &s1) == 0 && wstat(path2.c_str(), &s2) == 0) {
|
||||
if (wstat(path1, &s1) == 0 && wstat(path2, &s2) == 0) {
|
||||
return s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -205,7 +205,7 @@ static int wildcard_complete_internal( const wchar_t *orig,
|
|||
const wchar_t *wc,
|
||||
int is_first,
|
||||
const wchar_t *desc,
|
||||
const wchar_t *(*desc_func)(const wchar_t *),
|
||||
const wchar_t *(*desc_func)(const wcstring &),
|
||||
std::vector<completion_t> &out,
|
||||
int flags )
|
||||
{
|
||||
|
@ -309,7 +309,7 @@ static int wildcard_complete_internal( const wchar_t *orig,
|
|||
int wildcard_complete( const wchar_t *str,
|
||||
const wchar_t *wc,
|
||||
const wchar_t *desc,
|
||||
const wchar_t *(*desc_func)(const wchar_t *),
|
||||
const wchar_t *(*desc_func)(const wcstring &),
|
||||
std::vector<completion_t> &out,
|
||||
int flags )
|
||||
{
|
||||
|
|
|
@ -93,7 +93,7 @@ int wildcard_has( const wchar_t *str, int internal );
|
|||
int wildcard_complete( const wchar_t *str,
|
||||
const wchar_t *wc,
|
||||
const wchar_t *desc,
|
||||
const wchar_t *(*desc_func)(const wchar_t *),
|
||||
const wchar_t *(*desc_func)(const wcstring &),
|
||||
std::vector<completion_t> &out,
|
||||
int flags );
|
||||
|
||||
|
|
Loading…
Reference in a new issue