diff --git a/builtin.cpp b/builtin.cpp index 57cdde212..3c966860a 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -1456,8 +1456,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) int argc = builtin_count_args( argv ); int res=STATUS_BUILTIN_OK; wchar_t *desc=0; - array_list_t *events; - int i; + std::vector events; array_list_t *named_arguments=0; wchar_t *name = 0; int shadows = 1; @@ -1465,7 +1464,6 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) woptind=0; parser.push_block( FUNCTION_DEF ); - events=al_halloc( parser.current_block ); static const struct woption long_options[] = @@ -1562,7 +1560,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) e->type = EVENT_SIGNAL; e->param1.signal = sig; e->function_name=0; - al_push( events, e ); + events.push_back(e); break; } @@ -1585,7 +1583,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) e->type = EVENT_VARIABLE; e->param1.variable = halloc_wcsdup( parser.current_block, woptarg ); e->function_name=0; - al_push( events, e ); + events.push_back(e); break; } @@ -1599,7 +1597,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) e->type = EVENT_GENERIC; e->param1.param = halloc_wcsdup( parser.current_block, woptarg ); e->function_name=0; - al_push( events, e ); + events.push_back(e); break; } @@ -1675,7 +1673,7 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) else { e->function_name=0; - al_push( events, e ); + events.push_back(e); } break; } @@ -1800,15 +1798,15 @@ static int builtin_function( parser_t &parser, wchar_t **argv ) { function_data_t *d = new function_data_t(); - d->name=halloc_wcsdup( parser.current_block, name); + d->name=halloc_wcsdup( parser.current_block, name); d->description=desc?halloc_wcsdup( parser.current_block, desc):0; d->events = events; d->named_arguments = named_arguments; d->shadows = shadows; - for( i=0; ifunction_name = d->name; } diff --git a/event.h b/event.h index 766f37968..63009b744 100644 --- a/event.h +++ b/event.h @@ -13,6 +13,7 @@ #define FISH_EVENT_H #include "common.h" +#include "event.h" /** The signal number that is used to match any signal @@ -45,7 +46,7 @@ enum - When used as a parameter to event_add, it represents a class of events, and function_name is the name of the function which will be called whenever an event matching the specified class occurs. This is also how events are stored internally. - When used as a parameter to event_get, event_remove and event_fire, it represents a class of events, and if the function_name field is non-zero, only events which call the specified function will be returned. */ -typedef struct +struct event_t { /** Type of event @@ -93,8 +94,7 @@ typedef struct is ignored. */ wcstring_list_t *arguments; -} - event_t; +}; /** Add an event handler diff --git a/function.cpp b/function.cpp index 65ddd6492..c7bd0a33e 100644 --- a/function.cpp +++ b/function.cpp @@ -160,8 +160,6 @@ void function_init() void function_add( function_data_t *data, const parser_t &parser ) { - int i; - CHECK( data->name, ); CHECK( data->definition, ); scoped_lock lock(functions_lock); @@ -177,7 +175,7 @@ void function_add( function_data_t *data, const parser_t &parser ) if( data->named_arguments ) { - for( i=0; inamed_arguments ); i++ ) + for( size_t i=0; inamed_arguments ); i++ ) { info->named_arguments.push_back((wchar_t *)al_get( data->named_arguments, i )); } @@ -191,9 +189,9 @@ void function_add( function_data_t *data, const parser_t &parser ) info->shadows = data->shadows; - for( i=0; ievents ); i++ ) + for( size_t i=0; i< data->events.size(); i++ ) { - event_add_handler( (event_t *)al_get( data->events, i ) ); + event_add_handler( data->events.at(i) ); } } diff --git a/function.h b/function.h index 0e8ed8213..93f76b3c1 100644 --- a/function.h +++ b/function.h @@ -14,6 +14,7 @@ #include "util.h" #include "common.h" +#include "event.h" #include using std::tr1::shared_ptr; @@ -28,7 +29,7 @@ class env_vars; structure is used for that purpose. Parhaps these two should be merged. */ -typedef struct function_data +struct function_data_t { /** Name of function @@ -45,7 +46,7 @@ typedef struct function_data /** List of all event handlers for this function */ - array_list_t *events; + std::vector events; /** List of all named arguments for this function */ @@ -55,7 +56,7 @@ typedef struct function_data of the underlying function. */ int shadows; -} function_data_t; +}; class function_info_t { public: