diff options
Diffstat (limited to 'function.c')
-rw-r--r-- | function.c | 32 |
1 files changed, 10 insertions, 22 deletions
@@ -18,6 +18,7 @@ #include "intern.h" #include "event.h" #include "reader.h" +#include "parse_util.h" /** @@ -65,18 +66,6 @@ void function_destroy() hash_destroy( &function ); } -static int count_lineno( const wchar_t *str, int len ) -{ - int res = 0; - int i; - for( i=0; i<len; i++ ) - { - if( str[i] == L'\n' ) - res++; - } - return res; -} - void function_add( const wchar_t *name, const wchar_t *val, @@ -88,13 +77,12 @@ void function_add( const wchar_t *name, wchar_t *cmd_end; function_data_t *d; - if( function_exists( name ) ) - function_remove( name ); + function_remove( name ); d = malloc( sizeof( function_data_t ) ); - d->definition_offset = count_lineno( parser_get_buffer(), current_block->tok_pos ); + d->definition_offset = parse_util_lineno( parser_get_buffer(), current_block->tok_pos ); d->cmd = wcsdup( val ); - + cmd_end = d->cmd + wcslen(d->cmd)-1; while( (cmd_end>d->cmd) && wcschr( L"\n\r\t ", *cmd_end ) ) { @@ -103,7 +91,7 @@ void function_add( const wchar_t *name, d->desc = desc?wcsdup( desc ):0; d->is_binding = is_binding; - d->definition_file = reader_current_filename()?intern(reader_current_filename()):0; + d->definition_file = intern(reader_current_filename()); hash_put( &function, intern(name), d ); @@ -125,18 +113,18 @@ void function_remove( const wchar_t *name ) function_data_t *d; event_t ev; - ev.type=EVENT_ANY; - ev.function_name=name; - event_remove( &ev ); - hash_remove( &function, name, (const void **) &key, (const void **)&d ); - if( !d ) + if( !key ) return; + ev.type=EVENT_ANY; + ev.function_name=name; + event_remove( &ev ); + clear_function_entry( key, d ); } |