mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
More migration to the STL
This commit is contained in:
parent
046c9b56f5
commit
b67eaa3abd
5 changed files with 33 additions and 45 deletions
20
event.cpp
20
event.cpp
|
@ -391,7 +391,7 @@ static void event_fire_internal( event_t *event )
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
string_buffer_t *b=0;
|
string_buffer_t *b=0;
|
||||||
array_list_t *fire=0;
|
event_list_t fire;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
First we free all events that have been removed
|
First we free all events that have been removed
|
||||||
|
@ -417,25 +417,23 @@ static void event_fire_internal( event_t *event )
|
||||||
*/
|
*/
|
||||||
if(event_match( criterion, event ) )
|
if(event_match( criterion, event ) )
|
||||||
{
|
{
|
||||||
if( !fire )
|
fire.push_back(criterion);
|
||||||
fire = al_new();
|
|
||||||
al_push( fire, criterion );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
No matches. Time to return.
|
No matches. Time to return.
|
||||||
*/
|
*/
|
||||||
if( !fire )
|
if( fire.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Iterate over our list of matching events
|
Iterate over our list of matching events
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for( i=0; i<al_get_count( fire ); i++ )
|
for( i=0; i<fire.size(); i++ )
|
||||||
{
|
{
|
||||||
event_t *criterion = (event_t *)al_get( fire, i );
|
event_t *criterion = fire.at(i);
|
||||||
int prev_status;
|
int prev_status;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -483,13 +481,7 @@ static void event_fire_internal( event_t *event )
|
||||||
sb_destroy( b );
|
sb_destroy( b );
|
||||||
free( b );
|
free( b );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fire )
|
|
||||||
{
|
|
||||||
al_destroy( fire );
|
|
||||||
free( fire );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Free killed events
|
Free killed events
|
||||||
*/
|
*/
|
||||||
|
|
1
expand.h
1
expand.h
|
@ -148,6 +148,7 @@ enum
|
||||||
__warn_unused int expand_string( void *context, wchar_t *in, array_list_t *out, int flag );
|
__warn_unused int expand_string( void *context, wchar_t *in, array_list_t *out, int flag );
|
||||||
__warn_unused int expand_string2( const wcstring &input, std::list<wcstring> &output, int flag );
|
__warn_unused int expand_string2( const wcstring &input, std::list<wcstring> &output, int flag );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
expand_one is identical to expand_string, except it will fail if in
|
expand_one is identical to expand_string, except it will fail if in
|
||||||
expands to more than one string. This is used for expanding command
|
expands to more than one string. This is used for expanding command
|
||||||
|
|
34
parser.cpp
34
parser.cpp
|
@ -383,7 +383,7 @@ static int current_tokenizer_pos;
|
||||||
block_t *current_block=0;
|
block_t *current_block=0;
|
||||||
|
|
||||||
/** List of called functions, used to help prevent infinite recursion */
|
/** List of called functions, used to help prevent infinite recursion */
|
||||||
static array_list_t *forbidden_function;
|
static std::vector<wcstring> forbidden_function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
String index where the current job started.
|
String index where the current job started.
|
||||||
|
@ -633,7 +633,7 @@ void parser_forbid_function( wchar_t *function )
|
||||||
debug( 2, L"Forbid %ls\n", function );
|
debug( 2, L"Forbid %ls\n", function );
|
||||||
*/
|
*/
|
||||||
CHECK( function, );
|
CHECK( function, );
|
||||||
al_push( forbidden_function, function?wcsdup(function):0 );
|
forbidden_function.push_back(wcstring(function));
|
||||||
}
|
}
|
||||||
|
|
||||||
void parser_allow_function()
|
void parser_allow_function()
|
||||||
|
@ -642,7 +642,7 @@ void parser_allow_function()
|
||||||
if( al_peek( &forbidden_function) )
|
if( al_peek( &forbidden_function) )
|
||||||
debug( 2, L"Allow %ls\n", al_peek( &forbidden_function) );
|
debug( 2, L"Allow %ls\n", al_peek( &forbidden_function) );
|
||||||
*/
|
*/
|
||||||
free( (void *) al_pop( forbidden_function ) );
|
forbidden_function.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void error( int ec, int p, const wchar_t *str, ... )
|
void error( int ec, int p, const wchar_t *str, ... )
|
||||||
|
@ -672,7 +672,6 @@ void parser_init()
|
||||||
{
|
{
|
||||||
al_init( &profile_data);
|
al_init( &profile_data);
|
||||||
}
|
}
|
||||||
forbidden_function = al_new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -790,8 +789,7 @@ void parser_destroy()
|
||||||
lineinfo = 0;
|
lineinfo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
al_destroy( forbidden_function );
|
forbidden_function.resize(0);
|
||||||
free( forbidden_function );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1901,7 +1899,7 @@ static int parse_job( process_t *p,
|
||||||
if( use_function && !current_block->skip )
|
if( use_function && !current_block->skip )
|
||||||
{
|
{
|
||||||
int nxt_forbidden=0;
|
int nxt_forbidden=0;
|
||||||
wchar_t *forbid;
|
wcstring forbid;
|
||||||
|
|
||||||
int is_function_call=0;
|
int is_function_call=0;
|
||||||
|
|
||||||
|
@ -1925,8 +1923,8 @@ static int parse_job( process_t *p,
|
||||||
*/
|
*/
|
||||||
if( is_function_call && !current_block->had_command )
|
if( is_function_call && !current_block->had_command )
|
||||||
{
|
{
|
||||||
forbid = (wchar_t *)(al_get_count( forbidden_function)?al_peek( forbidden_function ):0);
|
forbid = forbidden_function.empty() ? wcstring(L"") : forbidden_function.back();
|
||||||
nxt_forbidden = forbid && (wcscmp( forbid, nxt) == 0 );
|
nxt_forbidden = (forbid == nxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !nxt_forbidden && function_exists( nxt ) )
|
if( !nxt_forbidden && function_exists( nxt ) )
|
||||||
|
@ -1934,7 +1932,7 @@ static int parse_job( process_t *p,
|
||||||
/*
|
/*
|
||||||
Check if we have reached the maximum recursion depth
|
Check if we have reached the maximum recursion depth
|
||||||
*/
|
*/
|
||||||
if( al_get_count( forbidden_function ) > MAX_RECURSION_DEPTH )
|
if( forbidden_function.size() > MAX_RECURSION_DEPTH )
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
tok_get_pos( tok ),
|
tok_get_pos( tok ),
|
||||||
|
@ -2495,21 +2493,21 @@ static void eval_job( tokenizer *tok )
|
||||||
|
|
||||||
int eval( const wchar_t *cmd, io_data_t *io, int block_type )
|
int eval( const wchar_t *cmd, io_data_t *io, int block_type )
|
||||||
{
|
{
|
||||||
int forbid_count;
|
size_t forbid_count;
|
||||||
int code;
|
int code;
|
||||||
tokenizer *previous_tokenizer=current_tokenizer;
|
tokenizer *previous_tokenizer=current_tokenizer;
|
||||||
block_t *start_current_block = current_block;
|
block_t *start_current_block = current_block;
|
||||||
io_data_t *prev_io = block_io;
|
io_data_t *prev_io = block_io;
|
||||||
array_list_t *prev_forbidden = forbidden_function;
|
std::vector<wcstring> prev_forbidden = forbidden_function;
|
||||||
|
|
||||||
if( block_type == SUBST )
|
if( block_type == SUBST )
|
||||||
{
|
{
|
||||||
forbidden_function = al_new();
|
forbidden_function.resize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_BLOCK( 1 );
|
CHECK_BLOCK( 1 );
|
||||||
|
|
||||||
forbid_count = al_get_count( forbidden_function );
|
forbid_count = forbidden_function.size();
|
||||||
|
|
||||||
block_io = io;
|
block_io = io;
|
||||||
|
|
||||||
|
@ -2597,15 +2595,9 @@ int eval( const wchar_t *cmd, io_data_t *io, int block_type )
|
||||||
tok_destroy( current_tokenizer );
|
tok_destroy( current_tokenizer );
|
||||||
free( current_tokenizer );
|
free( current_tokenizer );
|
||||||
|
|
||||||
while( al_get_count( forbidden_function ) > forbid_count )
|
while (forbidden_function.size() > forbid_count)
|
||||||
parser_allow_function();
|
parser_allow_function();
|
||||||
|
|
||||||
if( block_type == SUBST )
|
|
||||||
{
|
|
||||||
al_destroy( forbidden_function );
|
|
||||||
free( forbidden_function );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Restore previous eval state
|
Restore previous eval state
|
||||||
*/
|
*/
|
||||||
|
|
5
util.cpp
5
util.cpp
|
@ -874,11 +874,6 @@ func_ptr_t al_peek_func( array_list_t *l )
|
||||||
return al_peek_generic(l).func_val;
|
return al_peek_generic(l).func_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
int al_empty( array_list_t *l )
|
|
||||||
{
|
|
||||||
CHECK( l, 1 );
|
|
||||||
return l->pos == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int al_get_count( array_list_t *l )
|
int al_get_count( array_list_t *l )
|
||||||
|
|
||||||
|
|
18
util.h
18
util.h
|
@ -458,11 +458,6 @@ long al_peek_long( array_list_t *l );
|
||||||
*/
|
*/
|
||||||
func_ptr_t al_peek_func( array_list_t *l );
|
func_ptr_t al_peek_func( array_list_t *l );
|
||||||
|
|
||||||
/**
|
|
||||||
Returns 1 if the list is empty, 0 otherwise
|
|
||||||
*/
|
|
||||||
int al_empty( array_list_t *l);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Call the function func for each entry in the list
|
Call the function func for each entry in the list
|
||||||
*/
|
*/
|
||||||
|
@ -474,6 +469,19 @@ void al_foreach( array_list_t *l, void (*func)( void * ));
|
||||||
*/
|
*/
|
||||||
void al_foreach2( array_list_t *l, void (*func)( void *, void *), void *aux);
|
void al_foreach2( array_list_t *l, void (*func)( void *, void *), void *aux);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T al_list_to(array_list_t *list)
|
||||||
|
{
|
||||||
|
T result;
|
||||||
|
int i, c = al_get_count(list);
|
||||||
|
for (i=0; i < c; i++) {
|
||||||
|
void *val = al_get(list, i);
|
||||||
|
result.push_back(val);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Compares two wide character strings with an (arguably) intuitive
|
Compares two wide character strings with an (arguably) intuitive
|
||||||
ordering.
|
ordering.
|
||||||
|
|
Loading…
Reference in a new issue